diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index b63a4c56..2155cd4b 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -450,23 +450,50 @@ bool GraphicListBox::mouseMove(int x, int y){ graphButton2.mouseMove(x, y); } -bool GraphicListBox::mouseClick(int x, int y){ +bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) { if(this->getVisible() == false) { return false; } - if(!items.empty()){ + if(!items.empty()) { bool b1= graphButton1.mouseClick(x, y); bool b2= graphButton2.mouseClick(x, y); - if(b1){ - selectedItemIndex--; + if(b1) { + bool bFound = false; + if(advanceToItemStartingWith != "") { + for(unsigned int i = 0; i < items.size(); ++i) { + string item = items[i]; + if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) { + bFound = true; + selectedItemIndex = i; + break; + } + } + } + if(bFound == false) { + selectedItemIndex--; + } if(selectedItemIndex<0){ selectedItemIndex=items.size()-1; } } - else if(b2){ - selectedItemIndex++; + else if(b2) { + bool bFound = false; + if(advanceToItemStartingWith != "") { + for(unsigned int i = 0; i < items.size(); ++i) { + string item = items[i]; + //printf("Trying to match [%s] with item [%s]\n",advanceToItemStartingWith.c_str(),item.c_str()); + if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) { + bFound = true; + selectedItemIndex = i; + break; + } + } + } + if(bFound == false) { + selectedItemIndex++; + } if(selectedItemIndex>=items.size()){ selectedItemIndex=0; } diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index cf7ad265..b538026c 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -249,7 +249,7 @@ public: virtual void setY(int y); virtual bool mouseMove(int x, int y); - virtual bool mouseClick(int x, int y); + virtual bool mouseClick(int x, int y, string advanceToItemStartingWith=""); }; // =========================================================== diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 688df299..567265b1 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -2052,17 +2052,21 @@ void MenuStateConnectedGame::update() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); clientInterface->updateLobby(); - MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); - if(fileFTPProgressList.empty() == true) { - Lang &lang= Lang::getInstance(); - const vector languageList = clientInterface->getGameSettings()->getUniqueNetworkPlayerLanguages(); - for(unsigned int i = 0; i < languageList.size(); ++i) { - //string playerNameStr = getHumanPlayerName(); - clientInterface->sendTextMessage(lang.get("ConnectionTimedOut",languageList[i]),-1,false,languageList[i]); - sleep(1); - clientInterface->close(); + + if(clientInterface->isConnected() && + pingCount >= 3 && clientInterface->getLastPingLag() >= (GameConstants::networkPingInterval * 3)) { + MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); + if(fileFTPProgressList.empty() == true) { + Lang &lang= Lang::getInstance(); + const vector languageList = clientInterface->getGameSettings()->getUniqueNetworkPlayerLanguages(); + for(unsigned int i = 0; i < languageList.size(); ++i) { + //string playerNameStr = getHumanPlayerName(); + clientInterface->sendTextMessage(lang.get("ConnectionTimedOut",languageList[i]),-1,false,languageList[i]); + sleep(1); + clientInterface->close(); + } } - } + } } pingCount++; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 7b812151..b1b2b364 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1026,7 +1026,13 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { } } else { - if(activeInputLabel!=NULL && !(activeInputLabel->mouseClick(x,y))){ + string advanceToItemStartingWith = ""; + if(Shared::Platform::Window::isKeyStateModPressed(KMOD_SHIFT) == true) { + wchar_t lastKey = Shared::Platform::Window::extractLastKeyPressed(); + //printf("lastKey = %d [%c]\n",lastKey,lastKey); + advanceToItemStartingWith = lastKey; + } + if(activeInputLabel!=NULL && !(activeInputLabel->mouseClick(x,y))){ setActiveInputLabel(NULL); } if(buttonReturn.mouseClick(x,y) || serverInitError == true) { @@ -1054,7 +1060,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) { RestoreLastGameSettings(); } - else if(listBoxMap.mouseClick(x, y)){ + else if(listBoxMap.mouseClick(x, y,advanceToItemStartingWith)){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str()); MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); @@ -1169,7 +1175,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { else if (listBoxAdvanced.mouseClick(x, y)) { //TODO } - else if(listBoxTileset.mouseClick(x, y)) { + else if(listBoxTileset.mouseClick(x, y,advanceToItemStartingWith)) { MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); if(listBoxPublishServer.getSelectedItemIndex() == 0) { @@ -1204,7 +1210,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { lastSetChangedGameSettings = time(NULL); } } - else if(listBoxTechTree.mouseClick(x, y)){ + else if(listBoxTechTree.mouseClick(x, y,advanceToItemStartingWith)){ reloadFactions(false,(checkBoxScenario.getValue() == true ? scenarioFiles[listBoxScenario.getSelectedItemIndex()] : "")); MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 3688dfae..3438267b 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -138,6 +138,7 @@ public: static void setIsFullScreen(bool value) { isFullScreen = value; } //static SDL_keysym getKeystate() { return keystate; } static bool isKeyStateModPressed(int mod); + static wchar_t extractLastKeyPressed(); Window(); virtual ~Window(); diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 7b5a7c57..7d66e35d 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -1131,4 +1131,44 @@ bool Window::isKeyStateModPressed(int mod) { return false; } +wchar_t Window::extractLastKeyPressed() { + wchar_t c = SDLK_UNKNOWN; + //if(input.keysym.unicode > 0 && input.keysym.unicode < 0x80) { + if(keystate.unicode > 0) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] input.keysym.unicode = %d input.keysym.mod = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,keystate.unicode,keystate.mod); + + c = keystate.unicode; +// if(c <= SDLK_UNKNOWN || c >= SDLK_LAST) { +// c = SDLKey(c & 0xFF); +// } + + //c = toupper(c); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] #1 (c & 0xFF) [%d] c = [%lc]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF),c); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] #1 (c & 0xFF) [%d] c = [%lc]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF),c); + } + if(c == SDLK_UNKNOWN) { + c = keystate.sym; + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %u] c = [%d][%lc]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c); + + //c = (SDLKey)(c & 0xFF); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] returning key [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] returning key [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c); + + string pressKeyName = SDL_GetKeyName((SDLKey)c); + string inputKeyName = SDL_GetKeyName(keystate.sym); + + //printf ("PRESS pressed key [%d - %s] input.keysym.sym [%d] input.keysym.unicode [%d] mod = %d\n", + // c,pressKeyName.c_str(),input.keysym.sym,input.keysym.unicode,input.keysym.mod); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] pressed key [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c,pressKeyName.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] pressed key [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c,pressKeyName.c_str()); + + return c; +} + + + }}//end namespace