From 5686e8657ce2ba41152380998a76dfe46edd3978 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 29 Jul 2010 15:49:06 +0000 Subject: [PATCH] - fixed special keys to be ignored also in menus when in chat mode --- source/glest_game/game/chat_manager.cpp | 24 ++++++++++++++++--- source/glest_game/main/main.cpp | 32 +++++++++++++++---------- source/glest_game/main/program.h | 2 +- source/glest_game/menu/main_menu.cpp | 3 +++ source/glest_game/menu/main_menu.h | 3 +++ 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index d17f980b..356728df 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -52,6 +52,8 @@ void ChatManager::keyUp(char key){ try { if(editEnabled){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + if(key==vkEscape) { text.clear(); @@ -83,6 +85,8 @@ void ChatManager::keyDown(char key){ //toggle team mode if(editEnabled == false && disableTeamMode == false && key=='H') { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + if(teamMode){ teamMode= false; console->addLine(lang.get("ChatMode") + ": " + lang.get("All")); @@ -94,13 +98,20 @@ void ChatManager::keyDown(char key){ } if(key==vkReturn){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + SDL_keysym keystate = Window::getKeystate(); if(keystate.mod & (KMOD_LALT | KMOD_RALT)){ // alt+enter is ignored + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); } else { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + if(editEnabled){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); if(!text.empty()) { console->addLine(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": " + text); @@ -114,14 +125,18 @@ void ChatManager::keyDown(char key){ } text.clear(); } - else{ + else { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + editEnabled= true; text.clear(); } } } - else if(key==vkBack){ - if(!text.empty()){ + else if(key==vkBack) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + + if(!text.empty()) { text.erase(text.end() -1); } } @@ -137,7 +152,10 @@ void ChatManager::keyDown(char key){ } void ChatManager::keyPress(char c){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c,c); + if(editEnabled && text.size()=' '){ text+= c; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 898ba24f..44948e68 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -318,20 +318,26 @@ void MainWindow::eventKeyPress(char c){ program->keyPress(c); - Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); - if(c == configKeys.getCharKey("HotKeyToggleOSMouseEnabled")) { - bool showCursorState = false; - int state = SDL_ShowCursor(SDL_QUERY); - if(state == SDL_DISABLE) { - showCursorState = true; + if(program != NULL && program->isInSpecialKeyCaptureEvent() == false) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(c == configKeys.getCharKey("HotKeyToggleOSMouseEnabled")) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + bool showCursorState = false; + int state = SDL_ShowCursor(SDL_QUERY); + if(state == SDL_DISABLE) { + showCursorState = true; + } + + showCursor(showCursorState); + Renderer &renderer= Renderer::getInstance(); + renderer.setNo2DMouseRendering(showCursorState); + + Window::lastShowMouseState = SDL_ShowCursor(SDL_QUERY); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::lastShowMouseState = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::lastShowMouseState); } - - showCursor(showCursorState); - Renderer &renderer= Renderer::getInstance(); - renderer.setNo2DMouseRendering(showCursorState); - - Window::lastShowMouseState = SDL_ShowCursor(SDL_QUERY); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::lastShowMouseState = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::lastShowMouseState); } } diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index f257b16e..bec02b54 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -152,7 +152,7 @@ public: void eventMouseMove(int x, int y, const MouseState *ms); void renderProgramMsgBox(); - bool isInSpecialKeyCaptureEvent() { return (programState != NULL ? programState->isInSpecialKeyCaptureEvent() : false); } + bool isInSpecialKeyCaptureEvent() { return programState->isInSpecialKeyCaptureEvent(); } private: diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 8803a59d..c8d77716 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -178,6 +178,9 @@ void MainMenu::setState(MenuState *state){ menuBackground.setTargetCamera(state->getCamera()); } +bool MainMenu::isInSpecialKeyCaptureEvent() { + return state->isInSpecialKeyCaptureEvent(); +} // ===================================================== // class MenuState diff --git a/source/glest_game/menu/main_menu.h b/source/glest_game/menu/main_menu.h index 4b4232a1..8499b16b 100644 --- a/source/glest_game/menu/main_menu.h +++ b/source/glest_game/menu/main_menu.h @@ -95,6 +95,7 @@ public: virtual void keyPress(char key); void setState(MenuState *state); + virtual bool isInSpecialKeyCaptureEvent(); }; @@ -121,6 +122,8 @@ public: virtual void keyUp(char key){}; const Camera *getCamera() const {return &camera;} + + virtual bool isInSpecialKeyCaptureEvent() { return false; } }; }}//end namespace