1 // ============================================================== 2 // This file is part of Glest (www.glest.org) 3 // 4 // Copyright (C) 2001-2008 Martiño Figueroa 5 // 6 // You can redistribute this code and/or modify it under 7 // the terms of the GNU General Public License as published 8 // by the Free Software Foundation; either version 2 of the 9 // License, or (at your option) any later version 10 // ============================================================== 11 12 #ifndef _GLEST_GAME_MENUSTATECUSTOMGAME_H_ 13 #define _GLEST_GAME_MENUSTATECUSTOMGAME_H_ 14 15 #include "main_menu.h" 16 #include "chat_manager.h" 17 #include "simple_threads.h" 18 #include "map_preview.h" 19 #include "common_scoped_ptr.h" 20 #include "leak_dumper.h" 21 22 using namespace Shared::Map; 23 24 namespace Shared { namespace Graphics { 25 class VideoPlayer; 26 }} 27 28 namespace Glest { namespace Game { 29 30 class SwitchSetupRequest; 31 class ServerInterface; 32 class TechTree; 33 34 enum ParentMenuState { 35 pNewGame, 36 pMasterServer, 37 pLanGame 38 }; 39 40 // =============================== 41 // class MenuStateCustomGame 42 // =============================== 43 44 class MenuStateCustomGame : public MenuState, public SimpleTaskCallbackInterface { 45 private: 46 GraphicButton buttonReturn; 47 GraphicButton buttonPlayNow; 48 GraphicButton buttonRestoreLastSettings; 49 GraphicLabel labelControl; 50 GraphicLabel labelRMultiplier; 51 GraphicLabel labelFaction; 52 GraphicLabel labelTeam; 53 GraphicLabel labelMap; 54 GraphicLabel labelFogOfWar; 55 GraphicLabel labelTechTree; 56 GraphicLabel labelTileset; 57 GraphicLabel labelMapInfo; 58 GraphicLabel labelLocalGameVersion; 59 GraphicLabel labelLocalIP; 60 GraphicLabel labelGameName; 61 62 GraphicListBox listBoxMap; 63 GraphicListBox listBoxFogOfWar; 64 GraphicListBox listBoxTechTree; 65 GraphicListBox listBoxTileset; 66 67 vector<string> mapFiles; 68 vector<string> playerSortedMaps[GameConstants::maxPlayers+1]; 69 vector<string> formattedPlayerSortedMaps[GameConstants::maxPlayers+1]; 70 vector<string> techTreeFiles; 71 vector<string> tilesetFiles; 72 vector<string> factionFiles; 73 GraphicLabel labelPlayers[GameConstants::maxPlayers]; 74 GraphicLabel labelPlayerNames[GameConstants::maxPlayers]; 75 GraphicListBox listBoxControls[GameConstants::maxPlayers]; 76 GraphicButton buttonBlockPlayers[GameConstants::maxPlayers]; 77 GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers]; 78 GraphicListBox listBoxFactions[GameConstants::maxPlayers]; 79 GraphicListBox listBoxTeams[GameConstants::maxPlayers]; 80 GraphicLabel labelNetStatus[GameConstants::maxPlayers]; 81 MapInfo mapInfo; 82 83 GraphicButton buttonClearBlockedPlayers; 84 85 GraphicLabel labelPublishServer; 86 GraphicCheckBox checkBoxPublishServer; 87 88 GraphicMessageBox mainMessageBox; 89 int mainMessageBoxState; 90 91 GraphicLabel labelNetworkPauseGameForLaggedClients; 92 GraphicCheckBox checkBoxNetworkPauseGameForLaggedClients; 93 94 GraphicLabel labelMapFilter; 95 GraphicListBox listBoxMapFilter; 96 97 GraphicLabel labelAdvanced; 98 GraphicCheckBox checkBoxAdvanced; 99 100 GraphicLabel labelAllowObservers; 101 GraphicCheckBox checkBoxAllowObservers; 102 103 GraphicLabel *activeInputLabel; 104 105 GraphicLabel labelPlayerStatus[GameConstants::maxPlayers]; 106 GraphicListBox listBoxPlayerStatus; 107 108 GraphicLabel labelEnableSwitchTeamMode; 109 GraphicCheckBox checkBoxEnableSwitchTeamMode; 110 111 GraphicLabel labelAISwitchTeamAcceptPercent; 112 GraphicListBox listBoxAISwitchTeamAcceptPercent; 113 GraphicLabel labelFallbackCpuMultiplier; 114 GraphicListBox listBoxFallbackCpuMultiplier; 115 116 GraphicLabel labelAllowInGameJoinPlayer; 117 GraphicCheckBox checkBoxAllowInGameJoinPlayer; 118 119 GraphicLabel labelAllowTeamUnitSharing; 120 GraphicCheckBox checkBoxAllowTeamUnitSharing; 121 122 GraphicLabel labelAllowTeamResourceSharing; 123 GraphicCheckBox checkBoxAllowTeamResourceSharing; 124 125 126 GraphicLabel labelAllowNativeLanguageTechtree; 127 GraphicCheckBox checkBoxAllowNativeLanguageTechtree; 128 129 GraphicCheckBox checkBoxScenario; 130 GraphicLabel labelScenario; 131 GraphicListBox listBoxScenario; 132 133 vector<string> scenarioFiles; 134 ScenarioInfo scenarioInfo; 135 vector<string> dirList; 136 string autoloadScenarioName; 137 time_t previewLoadDelayTimer; 138 bool needToLoadTextures; 139 bool enableScenarioTexturePreview; 140 Texture2D *scenarioLogoTexture; 141 142 bool needToSetChangedGameSettings; 143 time_t lastSetChangedGameSettings; 144 time_t lastMasterserverPublishing; 145 time_t lastNetworkPing; 146 time_t mapPublishingDelayTimer; 147 bool needToPublishDelayed; 148 149 bool headlessHasConnectedPlayer; 150 151 bool needToRepublishToMasterserver; 152 bool needToBroadcastServerSettings; 153 std::map<string,string> publishToServerInfo; 154 SimpleTaskThread *publishToMasterserverThread; 155 SimpleTaskThread *publishToClientsThread; 156 157 ParentMenuState parentMenuState; 158 int soundConnectionCount; 159 160 time_t tMasterserverErrorElapsed; 161 bool showMasterserverError; 162 string masterServererErrorToShow; 163 164 bool showGeneralError; 165 string generalErrorToShow; 166 bool serverInitError; 167 168 //Console console; 169 ChatManager chatManager; 170 bool showFullConsole; 171 172 string lastMapDataSynchError; 173 string lastTileDataSynchError; 174 string lastTechtreeDataSynchError; 175 176 string defaultPlayerName; 177 int8 switchSetupRequestFlagType; 178 179 bool enableFactionTexturePreview; 180 bool enableMapPreview; 181 182 string currentTechName_factionPreview; 183 string currentFactionName_factionPreview; 184 string currentFactionLogo; 185 Texture2D *factionTexture; 186 ::Shared::Graphics::VideoPlayer *factionVideo; 187 bool factionVideoSwitchedOffVolume; 188 189 MapPreview mapPreview; 190 Texture2D *mapPreviewTexture; 191 bool zoomedMap; 192 int render_mapPreviewTexture_X; 193 int render_mapPreviewTexture_Y; 194 int render_mapPreviewTexture_W; 195 int render_mapPreviewTexture_H; 196 197 bool autostart; 198 GameSettings *autoStartSettings; 199 200 std::map<int,int> lastSelectedTeamIndex; 201 float rMultiplierOffset; 202 bool hasCheckedForUPNP; 203 204 string lastCheckedCRCTilesetName; 205 string lastCheckedCRCTechtreeName; 206 string lastCheckedCRCMapName; 207 208 string last_Forced_CheckedCRCTilesetName; 209 string last_Forced_CheckedCRCTechtreeName; 210 string last_Forced_CheckedCRCMapName; 211 212 uint32 lastCheckedCRCTilesetValue; 213 uint32 lastCheckedCRCTechtreeValue; 214 uint32 lastCheckedCRCMapValue; 215 vector<pair<string,uint32> > factionCRCList; 216 217 bool forceWaitForShutdown; 218 bool headlessServerMode; 219 bool masterserverModeMinimalResources; 220 int lastMasterServerSettingsUpdateCount; 221 222 auto_ptr<TechTree> techTree; 223 224 string gameUUID; 225 226 int lastGameSettingsreceivedCount; 227 228 public: 229 MenuStateCustomGame(Program *program, MainMenu *mainMenu , 230 bool openNetworkSlots= false, ParentMenuState parentMenuState=pNewGame, 231 bool autostart=false,GameSettings *settings=NULL,bool masterserverMode=false, 232 string autoloadScenarioName=""); 233 virtual ~MenuStateCustomGame(); 234 235 void mouseClick(int x, int y, MouseButton mouseButton); 236 void mouseMove(int x, int y, const MouseState *mouseState); 237 void render(); 238 void update(); 239 240 virtual bool textInput(std::string text); 241 virtual void keyDown(SDL_KeyboardEvent key); 242 virtual void keyPress(SDL_KeyboardEvent c); 243 virtual void keyUp(SDL_KeyboardEvent key); 244 245 246 virtual void simpleTask(BaseThread *callingThread,void *userdata); 247 virtual void setupTask(BaseThread *callingThread,void *userdata); 248 virtual void shutdownTask(BaseThread *callingThread,void *userdata); 249 static void setupTaskStatic(BaseThread *callingThread); 250 static void shutdownTaskStatic(BaseThread *callingThread); 251 252 virtual bool isInSpecialKeyCaptureEvent(); 253 virtual bool isMasterserverMode() const; 254 255 virtual bool isVideoPlaying(); 256 private: 257 258 void lastPlayerDisconnected(); 259 bool hasNetworkGameSettings(); 260 void loadGameSettings(GameSettings *gameSettings, bool forceCloseUnusedSlots=false); 261 void loadMapInfo(string file, MapInfo *mapInfo,bool loadMapPreview); 262 void cleanupMapPreviewTexture(); 263 264 void updateControlers(); 265 void closeUnusedSlots(); 266 void updateNetworkSlots(); 267 void publishToMasterserver(); 268 void returnToParentMenu(); 269 void showMessageBox(const string &text, const string &header, bool toggle); 270 271 void saveGameSettingsToFile(std::string fileName); 272 void switchToNextMapGroup(const int direction); 273 void updateAllResourceMultiplier(); 274 void updateResourceMultiplier(const int index); 275 string getCurrentMapFile(); 276 void setActiveInputLabel(GraphicLabel *newLable); 277 string getHumanPlayerName(int index=-1); 278 279 void loadFactionTexture(string filepath); 280 281 GameSettings loadGameSettingsFromFile(std::string fileName); 282 void loadGameSettings(std::string fileName); 283 void RestoreLastGameSettings(); 284 void PlayNow(bool saveGame); 285 286 void SetActivePlayerNameEditor(); 287 void cleanup(); 288 289 int32 getNetworkPlayerStatus(); 290 void setupUIFromGameSettings(const GameSettings &gameSettings); 291 292 void switchSetupForSlots(SwitchSetupRequest **switchSetupRequests, 293 ServerInterface *& serverInterface, int startIndex, int endIndex, 294 bool onlyNetworkUnassigned); 295 296 string createGameName(string controllingPlayer=""); 297 void reloadUI(); 298 void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); 299 void processScenario(); 300 void SetupUIForScenarios(); 301 int setupMapList(string scenario); 302 int setupTechList(string scenario, bool forceLoad=false); 303 void reloadFactions(bool keepExistingSelectedItem, string scenario); 304 void setupTilesetList(string scenario); 305 void setSlotHuman(int i); 306 307 void initFactionPreview(const GameSettings *gameSettings); 308 309 bool checkNetworkPlayerDataSynch(bool checkMapCRC,bool checkTileSetCRC, bool checkTechTreeCRC); 310 311 void cleanupThread(SimpleTaskThread **thread); 312 void simpleTaskForMasterServer(BaseThread *callingThread); 313 void simpleTaskForClients(BaseThread *callingThread); 314 void KeepCurrentHumanPlayerSlots(GameSettings &gameSettings); 315 }; 316 317 }}//end namespace 318 319 #endif 320