From 6a24ca3ad0f322abae4c2f21bd7de320aa747d21 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 9 Sep 2010 21:07:39 +0000 Subject: [PATCH] - completed screen UI work. F11 will save current menu UI config to ini file, F5 will cause a reload of INI realtime --- mk/linux/glestkeys.ini | 2 + source/glest_game/facilities/components.cpp | 76 ++++++++++++++++++- source/glest_game/facilities/components.h | 5 +- source/glest_game/global/config.cpp | 76 +++++++++++++++++++ source/glest_game/global/config.h | 6 +- source/glest_game/main/main.cpp | 4 + source/glest_game/menu/main_menu.cpp | 3 +- source/glest_game/menu/main_menu.h | 2 + source/glest_game/menu/menu_state_about.cpp | 17 ++++- source/glest_game/menu/menu_state_about.h | 2 +- .../menu/menu_state_connected_game.cpp | 14 ++-- .../menu/menu_state_connected_game.h | 1 - .../menu/menu_state_custom_game.cpp | 17 +++-- .../glest_game/menu/menu_state_custom_game.h | 3 - .../menu/menu_state_graphic_info.cpp | 14 +++- .../glest_game/menu/menu_state_graphic_info.h | 2 +- .../glest_game/menu/menu_state_join_game.cpp | 33 +++++--- source/glest_game/menu/menu_state_join_game.h | 1 - .../menu/menu_state_masterserver.cpp | 12 ++- .../glest_game/menu/menu_state_masterserver.h | 4 +- .../glest_game/menu/menu_state_new_game.cpp | 12 ++- source/glest_game/menu/menu_state_new_game.h | 2 +- source/glest_game/menu/menu_state_options.cpp | 12 ++- source/glest_game/menu/menu_state_options.h | 1 - source/glest_game/menu/menu_state_root.cpp | 9 ++- source/glest_game/menu/menu_state_root.h | 3 - .../glest_game/menu/menu_state_scenario.cpp | 20 +++++ source/glest_game/menu/menu_state_scenario.h | 2 + .../shared_lib/include/platform/sdl/window.h | 12 +++ .../sources/platform/sdl/window.cpp | 41 ++++++++++ 30 files changed, 350 insertions(+), 58 deletions(-) diff --git a/mk/linux/glestkeys.ini b/mk/linux/glestkeys.ini index 8d8c04720..ee6b2c289 100644 --- a/mk/linux/glestkeys.ini +++ b/mk/linux/glestkeys.ini @@ -41,6 +41,8 @@ HotKeySelectedUnitsStop=S HotKeyToggleOSMouseEnabled=/ ChatTeamMode=H ToggleMusic=K +SaveGUILayout=vkF11 +ReloadINI=vkF5 ; === propertyMap File === diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 048f9e16f..e34d87b6c 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -46,13 +46,20 @@ GraphicComponent::GraphicComponent(std::string containerName, std::string objNam editable= true; } -void GraphicComponent::clearRegisteredComponents() { - GraphicComponent::registeredGraphicComponentList.clear(); +void GraphicComponent::clearRegisteredComponents(std::string containerName) { + if(containerName == "") { + GraphicComponent::registeredGraphicComponentList.clear(); + } + else { + GraphicComponent::registeredGraphicComponentList[containerName].clear(); + } } void GraphicComponent::registerGraphicComponent(std::string containerName, std::string objName) { instanceName = objName; registeredGraphicComponentList[containerName][objName] = this; + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] registered [%s] [%s] count = %d\n",__FILE__,__FUNCTION__,__LINE__,containerName.c_str(),instanceName.c_str(),registeredGraphicComponentList[containerName].size()); } GraphicComponent * GraphicComponent::findRegisteredComponent(std::string containerName, std::string objName) { @@ -109,6 +116,71 @@ void GraphicComponent::applyCustomProperties(std::string containerName) { } } +bool GraphicComponent::saveAllCustomProperties(std::string containerName) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] registered [%s] count = %d\n",__FILE__,__FUNCTION__,__LINE__,containerName.c_str(),registeredGraphicComponentList[containerName].size()); + + bool foundPropertiesToSave = false; + std::map >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName); + if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) { + for(std::map::iterator iterFind2 = iterFind1->second.begin(); + iterFind2 != iterFind1->second.end(); iterFind2++) { + bool saved = iterFind2->second->saveCustomProperties(containerName); + foundPropertiesToSave = (saved || foundPropertiesToSave); + } + } + + if(foundPropertiesToSave == true) { + Config &config = Config::getInstance(); + config.save(); + } + + return foundPropertiesToSave; +} + +bool GraphicComponent::saveCustomProperties(std::string containerName) { + bool savedChange = false; + if(instanceName != "") { + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for [%s] [%s]\n",__FILE__,__FUNCTION__,__LINE__,containerName.c_str(),instanceName.c_str()); + + std::map >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName); + if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) { + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for [%s]\n",__FILE__,__FUNCTION__,__LINE__,instanceName.c_str()); + + std::map::iterator iterFind2 = iterFind1->second.find(instanceName); + if(iterFind2 != iterFind1->second.end()) { + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] FOUND [%s]\n",__FILE__,__FUNCTION__,__LINE__,instanceName.c_str()); + + Config &config = Config::getInstance(); + + //string languageToken = config.getString("Lang"); + + //if(dynamic_cast(iterFind2->second) != NULL) { + GraphicComponent *ctl = dynamic_cast(iterFind2->second); + + // First check default overrides + config.setInt(containerName + "_" + iterFind2->first + "_x",ctl->x); + config.setInt(containerName + "_" + iterFind2->first + "_y",ctl->y); + config.setInt(containerName + "_" + iterFind2->first + "_w",ctl->w); + config.setInt(containerName + "_" + iterFind2->first + "_h",ctl->h); + + savedChange = true; + // Now check language specific overrides + //ctl->x = config.getInt(containerName + "_" + iterFind2->first + "_x_" + languageToken, intToStr(ctl->x).c_str()); + //ctl->y = config.getInt(containerName + "_" + iterFind2->first + "_y_" + languageToken, intToStr(ctl->y).c_str()); + //ctl->w = config.getInt(containerName + "_" + iterFind2->first + "_w_" + languageToken, intToStr(ctl->w).c_str()); + //ctl->h = config.getInt(containerName + "_" + iterFind2->first + "_h_" + languageToken, intToStr(ctl->h).c_str()); + + //} + } + } + } + + return savedChange; +} + void GraphicComponent::init(int x, int y, int w, int h) { this->x= x; this->y= y; diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index 9f255b7de..0543b7a9f 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -57,12 +57,15 @@ public: GraphicComponent(std::string containerName="", std::string objName=""); virtual ~GraphicComponent(){} - static void clearRegisteredComponents(); + static void clearRegisteredComponents(std::string containerName=""); void registerGraphicComponent(std::string containerName, std::string objName); static GraphicComponent * findRegisteredComponent(std::string containerName, std::string objName); static void applyAllCustomProperties(std::string containerName); void applyCustomProperties(std::string containerName); + static bool saveAllCustomProperties(std::string containerName); + bool saveCustomProperties(std::string containerName); + void init(int x, int y, int w, int h); int getX() const {return x;} diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index e425966d5..a39542381 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -52,6 +52,17 @@ const string defaultNotFoundValue = "~~NOT FOUND~~"; map Config::configList; +Config::Config() { + fileLoaded.first = false; + fileLoaded.second = false; + cfgType.first = cfgMainGame; + cfgType.second = cfgUserGame; + fileName.first = ""; + fileName.second = ""; + fileLoaded.first = false; + fileLoaded.second = false; +} + Config::Config(std::pair type, std::pair file, std::pair fileMustExist) { fileLoaded.first = false; fileLoaded.second = false; @@ -106,13 +117,42 @@ Config::Config(std::pair type, std::pair f Config &Config::getInstance(std::pair type, std::pair file, std::pair fileMustExist) { if(configList.find(type.first) == configList.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + Config config(type, file, fileMustExist); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + configList.insert(map::value_type(type.first,config)); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } return configList.find(type.first)->second; } +void Config::CopyAll(Config *src, Config *dest) { + + dest->properties = src->properties; + dest->cfgType = src->cfgType; + dest->fileName = src->fileName; + dest->fileLoaded = src->fileLoaded; +} + +void Config::reload() { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + std::pair type = std::make_pair(cfgMainGame,cfgUserGame); + Config newconfig(type, std::make_pair("glest.ini","glestuser.ini"), std::make_pair(true,false)); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + Config &oldconfig = configList.find(type.first)->second; + CopyAll(&newconfig, &oldconfig); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + void Config::save(const string &path){ if(fileLoaded.second == true) { if(path != "") { @@ -227,6 +267,42 @@ char Config::translateStringToCharKey(const string &value) const { else if(value == "vkEscape") { result = vkEscape; } + else if(value == "vkF1") { + result = vkF1; + } + else if(value == "vkF2") { + result = vkF2; + } + else if(value == "vkF3") { + result = vkF3; + } + else if(value == "vkF4") { + result = vkF4; + } + else if(value == "vkF5") { + result = vkF5; + } + else if(value == "vkF6") { + result = vkF6; + } + else if(value == "vkF7") { + result = vkF7; + } + else if(value == "vkF8") { + result = vkF8; + } + else if(value == "vkF9") { + result = vkF9; + } + else if(value == "vkF10") { + result = vkF10; + } + else if(value == "vkF11") { + result = vkF11; + } + else if(value == "vkF12") { + result = vkF12; + } else { string sError = "Unsupported key translation" + value; throw runtime_error(sError.c_str()); diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index 829530291..eba3bc6eb 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -44,16 +44,20 @@ private: static map configList; -private: +protected: + Config(); Config(std::pair type, std::pair file, std::pair fileMustExist); char translateStringToCharKey(const string &value) const; + static void CopyAll(Config *src,Config *dest); + public: static Config &getInstance(std::pair type = std::make_pair(cfgMainGame,cfgUserGame) , std::pair file = std::make_pair("glest.ini","glestuser.ini") , std::pair fileMustExist = std::make_pair(true,false) ); void save(const string &path=""); + void reload(); int getInt(const string &key,const char *defaultValueIfNotFound=NULL) const; bool getBool(const string &key,const char *defaultValueIfNotFound=NULL) const; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 6f53a41f4..3621a1678 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -357,6 +357,10 @@ void MainWindow::eventKeyDown(char key){ bool showDebugUI = renderer.getShowDebugUI(); renderer.setShowDebugUI(!showDebugUI); } + else if(key == configKeys.getCharKey("ReloadINI")) { + Config &config = Config::getInstance(); + config.reload(); + } } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 3816bd186..eb3cc2268 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -189,6 +189,7 @@ bool MainMenu::isInSpecialKeyCaptureEvent() { MenuState::MenuState(Program *program, MainMenu *mainMenu, const string &stateName){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + this->containerName=""; this->program= program; this->mainMenu= mainMenu; @@ -233,7 +234,7 @@ MenuState::MenuState(Program *program, MainMenu *mainMenu, const string &stateNa MenuState::~MenuState() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); - GraphicComponent::clearRegisteredComponents(); + GraphicComponent::clearRegisteredComponents(this->containerName); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/main_menu.h b/source/glest_game/menu/main_menu.h index 5eb738bd3..c002e61c5 100644 --- a/source/glest_game/menu/main_menu.h +++ b/source/glest_game/menu/main_menu.h @@ -119,6 +119,8 @@ protected: MainMenu *mainMenu; Camera camera; + const char *containerName; + public: MenuState(Program *program, MainMenu *mainMenu, const string &stateName); virtual ~MenuState(); diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index 52862e3cf..df52b4cfe 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -15,6 +15,7 @@ #include "menu_state_root.h" #include "sound_renderer.h" #include "core_data.h" +#include "config.h" #include "menu_state_options.h" #include "leak_dumper.h" @@ -25,11 +26,10 @@ namespace Glest{ namespace Game{ // class MenuStateAbout // ===================================================== -const char *MenuStateAbout::containerName = "About"; +MenuStateAbout::MenuStateAbout(Program *program, MainMenu *mainMenu) : + MenuState(program, mainMenu, "about") { -MenuStateAbout::MenuStateAbout(Program *program, MainMenu *mainMenu): - MenuState(program, mainMenu, "about") -{ + containerName = "About"; Lang &lang= Lang::getInstance(); //init @@ -105,4 +105,13 @@ void MenuStateAbout::render(){ } +void MenuStateAbout::keyDown(char key) { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } +} + }}//end namespace diff --git a/source/glest_game/menu/menu_state_about.h b/source/glest_game/menu/menu_state_about.h index 16ac231e5..6ef70f7f2 100644 --- a/source/glest_game/menu/menu_state_about.h +++ b/source/glest_game/menu/menu_state_about.h @@ -23,7 +23,6 @@ namespace Glest{ namespace Game{ class MenuStateAbout: public MenuState{ public: - static const char *containerName; static const int aboutStringCount1= 3; static const int aboutStringCount2= 3; static const int teammateCount= 9; @@ -41,6 +40,7 @@ public: void mouseClick(int x, int y, MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); void render(); + virtual void keyDown(char key); }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index f4eb16932..e4557ef3d 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -45,11 +45,10 @@ struct FormatString { // class MenuStateConnectedGame // ===================================================== -const char *MenuStateConnectedGame::containerName = "ClientConnectedGame"; - MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots): - MenuState(program, mainMenu, "connected-game") //← set on connected-game + MenuState(program, mainMenu, "connected-game") { + containerName = "ClientConnectedGame"; switchSetupRequestFlagType |= ssrft_NetworkPlayerName; updateDataSynchDetailText = false; @@ -1081,7 +1080,7 @@ bool MenuStateConnectedGame::hasNetworkGameSettings() void MenuStateConnectedGame::keyDown(char key) { if(activeInputLabel!=NULL) { - if(key==vkBack){ + if(key==vkBack) { string text= activeInputLabel->getText(); if(text.size()>1){ text.erase(text.end()-2); @@ -1096,12 +1095,17 @@ void MenuStateConnectedGame::keyDown(char key) { else { //send key to the chat manager chatManager.keyDown(key); - if(!chatManager.getEditEnabled()){ + if(chatManager.getEditEnabled() == false) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); if(key == configKeys.getCharKey("ShowFullConsole")) { showFullConsole= true; } + else if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + Lang &lang= Lang::getInstance(); + console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } } } } diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 78cb51953..ceeb12b54 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -32,7 +32,6 @@ enum JoinMenu{ class MenuStateConnectedGame: public MenuState { private: - static const char *containerName; GraphicButton buttonDisconnect; GraphicButton buttonPlayNow; GraphicLabel labelControl; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 5e03ace98..77ceeda2e 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -45,13 +45,12 @@ struct FormatString { // class MenuStateCustomGame // ===================================================== -const char *MenuStateCustomGame::containerName = "CustomGame"; - -MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver): - MenuState(program, mainMenu, "new-game") +MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver) : + MenuState(program, mainMenu, "new-game") { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + containerName = "CustomGame"; activeInputLabel=NULL; showGeneralError = false; generalErrorToShow = "---"; @@ -2151,7 +2150,7 @@ void MenuStateCustomGame::keyDown(char key) { else { //send key to the chat manager chatManager.keyDown(key); - if(!chatManager.getEditEnabled()) { + if(chatManager.getEditEnabled() == false) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); if(key == configKeys.getCharKey("ShowFullConsole")) { @@ -2175,7 +2174,11 @@ void MenuStateCustomGame::keyDown(char key) { console.addLine(lang.get("GameMusic")); } } - + else if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + Lang &lang= Lang::getInstance(); + console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } } } } @@ -2213,7 +2216,7 @@ void MenuStateCustomGame::keyUp(char key) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); - if(chatManager.getEditEnabled()){ + if(chatManager.getEditEnabled()) { //send key to the chat manager chatManager.keyUp(key); } diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 49e4e56fb..d0e2d6c9d 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -24,9 +24,6 @@ namespace Glest{ namespace Game{ class MenuStateCustomGame : public MenuState, public SimpleTaskCallbackInterface { private: - - static const char *containerName; - GraphicButton buttonReturn; GraphicButton buttonPlayNow; GraphicButton buttonRestoreLastSettings; diff --git a/source/glest_game/menu/menu_state_graphic_info.cpp b/source/glest_game/menu/menu_state_graphic_info.cpp index 1cd6784be..0789765e8 100644 --- a/source/glest_game/menu/menu_state_graphic_info.cpp +++ b/source/glest_game/menu/menu_state_graphic_info.cpp @@ -15,7 +15,7 @@ #include "sound_renderer.h" #include "core_data.h" #include "menu_state_options.h" - +#include "config.h" #include "leak_dumper.h" namespace Glest{ namespace Game{ @@ -24,11 +24,10 @@ namespace Glest{ namespace Game{ // class MenuStateGraphicInfo // ===================================================== -const char *MenuStateGraphicInfo::containerName = "GraphicInfo"; - MenuStateGraphicInfo::MenuStateGraphicInfo(Program *program, MainMenu *mainMenu): MenuState(program, mainMenu, "info") { + containerName = "GraphicInfo"; buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); buttonReturn.init(387, 70, 125); @@ -74,4 +73,13 @@ void MenuStateGraphicInfo::render(){ renderer.renderLabel(&labelMoreInfo); } +void MenuStateGraphicInfo::keyDown(char key) { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } +} + }}//end namespace diff --git a/source/glest_game/menu/menu_state_graphic_info.h b/source/glest_game/menu/menu_state_graphic_info.h index 4e7f80b04..cd5d2dac4 100644 --- a/source/glest_game/menu/menu_state_graphic_info.h +++ b/source/glest_game/menu/menu_state_graphic_info.h @@ -23,7 +23,6 @@ namespace Glest{ namespace Game{ class MenuStateGraphicInfo: public MenuState { private: - static const char *containerName; GraphicButton buttonReturn; GraphicLabel labelInfo; GraphicLabel labelMoreInfo; @@ -36,6 +35,7 @@ public: void mouseClick(int x, int y, MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); void render(); + virtual void keyDown(char key); }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index e67bf7706..c990b0797 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -41,11 +41,10 @@ const int MenuStateJoinGame::foundServersIndex= 2; const string MenuStateJoinGame::serverFileName= "servers.ini"; -const char *MenuStateJoinGame::containerName = "JoinGame"; - MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect, Ip serverIp): MenuState(program, mainMenu, "join-game") { + containerName = "JoinGame"; abortAutoFind = false; autoConnectToServer = false; Lang &lang= Lang::getInstance(); @@ -468,10 +467,12 @@ void MenuStateJoinGame::keyDown(char key){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c][%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface(); - if(!clientInterface->isConnected()) - { + if(clientInterface->isConnected() == false) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(key==vkBack) { + + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + + if(key == vkBack) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); string text= labelServerIp.getText(); @@ -481,23 +482,37 @@ void MenuStateJoinGame::keyDown(char key){ labelServerIp.setText(text); } + else if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + Lang &lang= Lang::getInstance(); + console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } } - else - { + else { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //send key to the chat manager chatManager.keyDown(key); + + if(chatManager.getEditEnabled() == false) { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + Lang &lang= Lang::getInstance(); + console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } + } } } void MenuStateJoinGame::keyPress(char c){ ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface(); - if(!clientInterface->isConnected()) - { + if(clientInterface->isConnected() == false) { int maxTextSize= 16; + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(c>='0' && c<='9'){ if(labelServerIp.getText().size()setVolume(strToInt(listBoxVolumeMusic.getSelectedItem())/100.f); diff --git a/source/glest_game/menu/menu_state_masterserver.h b/source/glest_game/menu/menu_state_masterserver.h index bd5980d34..7271e62e6 100644 --- a/source/glest_game/menu/menu_state_masterserver.h +++ b/source/glest_game/menu/menu_state_masterserver.h @@ -50,7 +50,7 @@ private: GraphicLabel externalConnectPort; public: - ServerLine( MasterServerInfo *mServerInfo, int lineIndex); + ServerLine( MasterServerInfo *mServerInfo, int lineIndex, const char *containerName); virtual ~ServerLine(); MasterServerInfo *getMasterServerInfo() const {return masterServerInfo;} const int getIndex() const {return index;} @@ -70,8 +70,6 @@ typedef vector ServerLines; typedef vector MasterServerInfos; class MenuStateMasterserver : public MenuState, public SimpleTaskCallbackInterface { -public: - static const char *containerName; private: diff --git a/source/glest_game/menu/menu_state_new_game.cpp b/source/glest_game/menu/menu_state_new_game.cpp index bd04c173d..3d709fdfa 100644 --- a/source/glest_game/menu/menu_state_new_game.cpp +++ b/source/glest_game/menu/menu_state_new_game.cpp @@ -32,11 +32,10 @@ namespace Glest{ namespace Game{ // class MenuStateNewGame // ===================================================== -const char *MenuStateNewGame::containerName = "NewGame"; - MenuStateNewGame::MenuStateNewGame(Program *program, MainMenu *mainMenu): MenuState(program, mainMenu, "root") { + containerName = "NewGame"; Lang &lang= Lang::getInstance(); buttonCustomGame.registerGraphicComponent(containerName,"buttonCustomGame"); @@ -105,4 +104,13 @@ void MenuStateNewGame::update(){ } } +void MenuStateNewGame::keyDown(char key) { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } +} + }}//end namespace diff --git a/source/glest_game/menu/menu_state_new_game.h b/source/glest_game/menu/menu_state_new_game.h index 8446e874a..b85394f53 100644 --- a/source/glest_game/menu/menu_state_new_game.h +++ b/source/glest_game/menu/menu_state_new_game.h @@ -23,7 +23,6 @@ namespace Glest{ namespace Game{ class MenuStateNewGame: public MenuState{ private: - static const char *containerName; GraphicButton buttonCustomGame; GraphicButton buttonScenario; GraphicButton buttonTutorial; @@ -36,6 +35,7 @@ public: void mouseMove(int x, int y, const MouseState *mouseState); void update(); void render(); + virtual void keyDown(char key); }; diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index cb2fc4245..ce2c3e90a 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -28,11 +28,10 @@ namespace Glest{ namespace Game{ // ===================================================== // class MenuStateOptions // ===================================================== -const char *MenuStateOptions::containerName = "Options"; - MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): MenuState(program, mainMenu, "config") { + containerName = "Options"; Lang &lang= Lang::getInstance(); Config &config= Config::getInstance(); //modeinfos=list (); @@ -456,6 +455,15 @@ void MenuStateOptions::keyPress(char c){ } } } + else { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(c == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } + } + } void MenuStateOptions::render(){ diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index 53d2b54f6..cbd7216ff 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -23,7 +23,6 @@ namespace Glest{ namespace Game{ class MenuStateOptions: public MenuState{ private: - static const char *containerName; GraphicButton buttonOk; GraphicButton buttonAbort; diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index 166e8a37a..be5cff09c 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -34,11 +34,10 @@ namespace Glest{ namespace Game{ // class MenuStateRoot // ===================================================== -const char *MenuStateRoot::containerName = "MainMenu"; - MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu): MenuState(program, mainMenu, "root") { + containerName = "MainMenu"; Lang &lang= Lang::getInstance(); int i=375; @@ -203,6 +202,12 @@ void MenuStateRoot::keyDown(char key) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); program->exit(); } + else if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } + } void MenuStateRoot::showMessageBox(const string &text, const string &header, bool toggle){ diff --git a/source/glest_game/menu/menu_state_root.h b/source/glest_game/menu/menu_state_root.h index 6365801b6..e322d0bba 100644 --- a/source/glest_game/menu/menu_state_root.h +++ b/source/glest_game/menu/menu_state_root.h @@ -25,9 +25,6 @@ class GraphicMessageBox; class MenuStateRoot: public MenuState{ private: - - static const char *containerName; - GraphicButton buttonNewGame; GraphicButton buttonJoinGame; GraphicButton buttonMasterserverGame; diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index e3fb0f80b..ac4a58d0e 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -34,9 +34,11 @@ using namespace Shared::Xml; MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const vector &dirList, string autoloadScenarioName): MenuState(program, mainMenu, "scenario") { + containerName = "Scenario"; Lang &lang= Lang::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); + mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox"); mainMessageBox.init(lang.get("Ok")); mainMessageBox.setEnabled(false); mainMessageBoxState=0; @@ -46,13 +48,20 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const this->dirList = dirList; + labelInfo.registerGraphicComponent(containerName,"labelInfo"); labelInfo.init(350, 350); labelInfo.setFont(CoreData::getInstance().getMenuFontNormal()); + buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); buttonReturn.init(350, 200, 125); + + buttonPlayNow.registerGraphicComponent(containerName,"buttonPlayNow"); buttonPlayNow.init(525, 200, 125); + listBoxScenario.registerGraphicComponent(containerName,"listBoxScenario"); listBoxScenario.init(350, 400, 190); + + labelScenario.registerGraphicComponent(containerName,"labelScenario"); labelScenario.init(350, 430); buttonReturn.setText(lang.get("Return")); @@ -74,6 +83,8 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo ); labelInfo.setText(scenarioInfo.desc); + GraphicComponent::applyAllCustomProperties(containerName); + networkManager.init(nrServer); } @@ -324,4 +335,13 @@ void MenuStateScenario::showMessageBox(const string &text, const string &header, } } +void MenuStateScenario::keyDown(char key) { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(key == configKeys.getCharKey("SaveGUILayout")) { + bool saved = GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } +} + }}//end namespace diff --git a/source/glest_game/menu/menu_state_scenario.h b/source/glest_game/menu/menu_state_scenario.h index 7f8370ee3..836f8b4fd 100644 --- a/source/glest_game/menu/menu_state_scenario.h +++ b/source/glest_game/menu/menu_state_scenario.h @@ -61,6 +61,8 @@ public: void setScenario(int i); int getScenarioCount() const { return listBoxScenario.getItemCount(); } + virtual void keyDown(char key); + private: void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index ec58c402a..9c102057f 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -95,6 +95,18 @@ const char vkDown = -10; const char vkReturn = -11; const char vkBack = -12; const char vkTab = -13; +const char vkF1 = -14; +const char vkF2 = -15; +const char vkF3 = -16; +const char vkF4 = -17; +const char vkF5 = -18; +const char vkF6 = -19; +const char vkF7 = -20; +const char vkF8 = -21; +const char vkF9 = -22; +const char vkF10 = -23; +const char vkF11 = -24; +const char vkF12 = -25; enum WindowStyle{ wsFullscreen, diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index e5b78fcca..61efc5d82 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -184,6 +184,7 @@ bool Window::handleEvent() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } break; + case SDL_KEYUP: //printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__); @@ -192,6 +193,8 @@ bool Window::handleEvent() { Window::isKeyPressedDown = false; keystate = event.key.keysym; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] KEY_UP, Raw SDL key [%d] mod [%d] unicode [%d] scancode [%d]\n",__FILE__,__FUNCTION__,__LINE__,event.key.keysym.sym,event.key.keysym.mod,event.key.keysym.unicode,event.key.keysym.scancode); + if(global_window) { global_window->eventKeyUp(getKey(event.key.keysym,true)); } @@ -569,6 +572,8 @@ MouseButton Window::getMouseButton(int sdlButton) { } char Window::getKey(SDL_keysym keysym,bool skipSpecialKeys) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keysym.sym [%d] skipSpecialKeys = %d.\n",__FILE__,__FUNCTION__,__LINE__,keysym.sym,skipSpecialKeys); + if(skipSpecialKeys == false) { switch(keysym.sym) { case SDLK_LALT: @@ -615,6 +620,42 @@ char Window::getKey(SDL_keysym keysym,bool skipSpecialKeys) { return vkTab; case SDLK_BACKSPACE: return vkBack; + case SDLK_F1: + return vkF1; + break; + case SDLK_F2: + return vkF2; + break; + case SDLK_F3: + return vkF3; + break; + case SDLK_F4: + return vkF4; + break; + case SDLK_F5: + return vkF5; + break; + case SDLK_F6: + return vkF6; + break; + case SDLK_F7: + return vkF7; + break; + case SDLK_F8: + return vkF8; + break; + case SDLK_F9: + return vkF9; + break; + case SDLK_F10: + return vkF10; + break; + case SDLK_F11: + return vkF11; + break; + case SDLK_F12: + return vkF12; + break; case SDLK_0: return '0'; case SDLK_1: