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_MENUSTATEMASTERSERVER_H_ 13 #define _GLEST_GAME_MENUSTATEMASTERSERVER_H_ 14 15 #include "main_menu.h" 16 #include "server_line.h" 17 #include "masterserver_info.h" 18 #include "simple_threads.h" 19 #include "network_interface.h" 20 #include "ircclient.h" 21 #include "chat_manager.h" 22 #include "leak_dumper.h" 23 24 namespace Glest{ namespace Game{ 25 26 // =============================== 27 // class MenuStateMasterserver 28 // =============================== 29 typedef vector<ServerLine*> ServerLines; 30 typedef vector<GraphicButton*> UserButtons; 31 typedef vector<MasterServerInfo*> MasterServerInfos; 32 33 class MenuStateMasterserver : public MenuState, public SimpleTaskCallbackInterface, public IRCCallbackInterface { 34 35 private: 36 37 GraphicButton buttonRefresh; 38 GraphicButton buttonReturn; 39 GraphicButton buttonCreateGame; 40 GraphicLabel labelAutoRefresh; 41 GraphicListBox listBoxAutoRefresh; 42 GraphicLabel labelTitle; 43 44 GraphicLabel announcementLabel; 45 GraphicLabel versionInfoLabel; 46 47 GraphicLine lines[3]; 48 49 GraphicLabel glestVersionLabel; 50 GraphicLabel platformLabel; 51 //GraphicLabel binaryCompileDateLabel; 52 53 //game info: 54 GraphicLabel serverTitleLabel; 55 GraphicLabel countryLabel; 56 GraphicLabel statusLabel; 57 58 GraphicLabel ipAddressLabel; 59 60 //game setup info: 61 GraphicLabel techLabel; 62 GraphicLabel mapLabel; 63 GraphicLabel tilesetLabel; 64 GraphicLabel activeSlotsLabel; 65 66 GraphicLabel externalConnectPort; 67 68 GraphicLabel selectButton; 69 70 GraphicMessageBox mainMessageBox; 71 int mainMessageBoxState; 72 73 GraphicLabel ircOnlinePeopleLabel; 74 GraphicLabel ircOnlinePeopleStatusLabel; 75 76 bool announcementLoaded; 77 bool needUpdateFromServer; 78 int autoRefreshTime; 79 time_t lastRefreshTimer; 80 SimpleTaskThread *updateFromMasterserverThread; 81 bool playServerFoundSound; 82 ServerLines serverLines; 83 string serverInfoString; 84 int serverLinesToRender; 85 int serverLinesYBase; 86 int serverLinesLineHeight; 87 GraphicScrollBar userScrollBar; 88 GraphicScrollBar serverScrollBar; 89 UserButtons userButtons; 90 UserButtons userButtonsToRemove; 91 int userButtonsToRender; 92 int userButtonsYBase; 93 int userButtonsXBase; 94 int userButtonsLineHeight; 95 int userButtonsHeight; 96 int userButtonsWidth; 97 string currentIrcNick; 98 99 100 //Console console; 101 102 static DisplayMessageFunction pCB_DisplayMessage; 103 std::string threadedErrorMsg; 104 105 std::vector<string> ircArgs; 106 Mutex *mutexIRCClient; 107 IRCThread *ircClient; 108 std::vector<string> oldNickList; 109 110 Console consoleIRC; 111 ChatManager chatManager; 112 113 bool masterserverParseErrorShown; 114 115 public: 116 MenuStateMasterserver(Program *program, MainMenu *mainMenu); 117 ~MenuStateMasterserver(); 118 119 void mouseClick(int x, int y, MouseButton mouseButton); 120 void mouseUp(int x, int y, const MouseButton mouseButton); 121 void mouseMove(int x, int y, const MouseState *mouseState); 122 void update(); 123 void render(); 124 125 virtual bool textInput(std::string text); 126 virtual void keyDown(SDL_KeyboardEvent key); 127 128 virtual void simpleTask(BaseThread *callingThread,void *userdata); isInSpecialKeyCaptureEvent()129 virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } 130 setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage)131 static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; } 132 133 virtual void reloadUI(); 134 135 private: 136 void showMessageBox(const string &text, const string &header, bool toggle); 137 bool connectToServer(string ipString, int port); 138 void setConsolePos(int yPos); 139 void setButtonLinePosition(int pos); 140 void clearServerLines(); 141 void clearUserButtons(); 142 void rebuildServerLines(const string &serverInfo); 143 void cleanup(); 144 virtual void IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count); 145 146 }; 147 148 149 }}//end namespace 150 151 #endif 152