diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 58f0f36b7..b245b6e48 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -456,8 +456,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ } if(labelPlayerNames[i].mouseClick(x, y) && ( activeInputLabel != &labelPlayerNames[i] )){ - if(clientInterface->getGameSettings() != NULL && - i == clientInterface->getGameSettings()->getThisFactionIndex()) { + if(i == clientInterface->getPlayerIndex()) { setActiveInputLabel(&labelPlayerNames[i]); } } @@ -1018,7 +1017,7 @@ void MenuStateConnectedGame::update() { if( initialSettingsReceivedFromServer == true && clientInterface->getIntroDone() == true && (switchSetupRequestFlagType & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] getHumanPlayerName() = [%s], clientInterface->getGameSettings()->getThisFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,getHumanPlayerName().c_str(),clientInterface->getGameSettings()->getThisFactionIndex()); //needToSetChangedGameSettings = false; //lastSetChangedGameSettings = time(NULL); clientInterface->sendSwitchSetupRequest("",clientInterface->getPlayerIndex(),-1,-1,getHumanPlayerName(),switchSetupRequestFlagType); @@ -1182,12 +1181,16 @@ bool MenuStateConnectedGame::hasNetworkGameSettings() } void MenuStateConnectedGame::keyDown(char key) { - if(activeInputLabel!=NULL) { - if(key==vkBack) { + if(activeInputLabel != NULL) { + if(key == vkBack) { string text= activeInputLabel->getText(); - if(text.size()>1){ - text.erase(text.end()-2); + if(text.size() > 1) { + text.erase(text.end() - 2); } + if(text.size() == 1) { + text.erase(text.end() - 1); + } + activeInputLabel->setText(text); switchSetupRequestFlagType |= ssrft_NetworkPlayerName; @@ -1214,15 +1217,15 @@ void MenuStateConnectedGame::keyDown(char key) { } void MenuStateConnectedGame::keyPress(char c) { - if(activeInputLabel!=NULL) { + if(activeInputLabel != NULL) { int maxTextSize= 16; - for(int i=0; i='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')|| - (c=='-')||(c=='(')||(c==')')){ - if(activeInputLabel->getText().size()='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || + (c=='-') || (c=='(') || (c==')')) { + if(activeInputLabel->getText().size() < maxTextSize) { string text= activeInputLabel->getText(); - text.insert(text.end()-1, c); + text.insert(text.end() -1, c); activeInputLabel->setText(text); switchSetupRequestFlagType |= ssrft_NetworkPlayerName; @@ -1255,25 +1258,23 @@ void MenuStateConnectedGame::keyUp(char key) { } void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable) { - if(newLable!=NULL) { + if(newLable != NULL) { string text= newLable->getText(); - size_t found; - found=text.find_last_of("_"); - if (found==string::npos) { - text=text+"_"; + size_t found = text.find_last_of("_"); + if (found == string::npos) { + text += "_"; } newLable->setText(text); } - if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()) { + if(activeInputLabel != NULL && activeInputLabel->getText().empty() == false) { string text= activeInputLabel->getText(); - size_t found; - found=text.find_last_of("_"); - if (found!=string::npos) { - text=text.substr(0,found); + size_t found = text.find_last_of("_"); + if (found != string::npos) { + text = text.substr(0,found); } activeInputLabel->setText(text); } - activeInputLabel=newLable; + activeInputLabel = newLable; } string MenuStateConnectedGame::getHumanPlayerName() { @@ -1283,8 +1284,7 @@ string MenuStateConnectedGame::getHumanPlayerName() { ClientInterface* clientInterface= networkManager.getClientInterface(); for(int j=0; jgetGameSettings() != NULL && - j == clientInterface->getGameSettings()->getThisFactionIndex() && + j == clientInterface->getPlayerIndex() && labelPlayerNames[j].getText() != "") { result = labelPlayerNames[j].getText(); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 4873d0132..dbd6e12d9 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -813,11 +813,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ lastSetChangedGameSettings = time(NULL);; } } - else if(labelPlayerNames[i].mouseClick(x, y) && ( activeInputLabel != &labelPlayerNames[i] )){ - ControlType ct= static_cast(listBoxControls[i].getSelectedItemIndex()); - if(ct == ctHuman) { - setActiveInputLabel(&labelPlayerNames[i]); - } + else if(labelPlayerNames[i].mouseClick(x, y)) { + SetActivePlayerNameEditor(); } } } @@ -825,6 +822,16 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MenuStateCustomGame::SetActivePlayerNameEditor() { + for(int i = 0; i < mapInfo.players; ++i) { + ControlType ct= static_cast(listBoxControls[i].getSelectedItemIndex()); + if(ct == ctHuman) { + setActiveInputLabel(&labelPlayerNames[i]); + break; + } + } +} + void MenuStateCustomGame::RestoreLastGameSettings() { // Ensure we have set the gamesettings at least once GameSettings gameSettings = loadGameSettingsFromFile("lastCustomGamSettings.mgg"); @@ -997,7 +1004,7 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){ buttonRestoreLastSettings.mouseMove(x, y); bool editingPlayerName = false; - for(int i=0; igetSwitchFlags() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getSwitchFlags()); if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getToFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getToFactionIndex()); //printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str()); //printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam()); @@ -1235,6 +1242,7 @@ void MenuStateCustomGame::update() { if(switchSetupRequests[i]->getNetworkPlayerName() != "") { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[newFactionIdx].getText().c_str(),switchSetupRequests[i]->getNetworkPlayerName().c_str()); labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName()); + SetActivePlayerNameEditor(); } } catch(const runtime_error &e) { @@ -1260,6 +1268,7 @@ void MenuStateCustomGame::update() { else { labelPlayerNames[i].setText(""); } + SetActivePlayerNameEditor(); //switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName); } } @@ -1754,11 +1763,10 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { gameSettings->setThisFactionIndex(slotIndex); gameSettings->setNetworkPlayerName(slotIndex, getHumanPlayerName(i)); - labelPlayerNames[i].setText(getHumanPlayerName(i)); + //labelPlayerNames[i].setText(getHumanPlayerName(i)); + //SetActivePlayerNameEditor(); } - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,factionFiles[listBoxFactions[i].getSelectedItemIndex()].c_str()); gameSettings->setFactionTypeName(slotIndex, factionFiles[listBoxFactions[i].getSelectedItemIndex()]); if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME)) { @@ -1802,6 +1810,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { labelPlayerNames[i].setText(""); } } + // Next save closed slots int closedCount = 0; for(int i = 0; i < GameConstants::maxPlayers; ++i) { @@ -2016,6 +2025,8 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) labelPlayerNames[i].setText(gameSettings.getNetworkPlayerName(i)); } + SetActivePlayerNameEditor(); + updateControlers(); updateNetworkSlots(); needToRepublishToMasterserver = true; @@ -2256,12 +2267,16 @@ void MenuStateCustomGame::updateNetworkSlots() { } void MenuStateCustomGame::keyDown(char key) { - if(activeInputLabel!=NULL) { - if(key==vkBack) { - string text= activeInputLabel->getText(); - if(text.size()>1){ - text.erase(text.end()-2); + if(activeInputLabel != NULL) { + if(key == vkBack) { + string text = activeInputLabel->getText(); + if(text.size() > 1) { + text.erase(text.end() - 2); } + if(text.size() == 1) { + text.erase(text.end() - 1); + } + activeInputLabel->setText(text); MutexSafeWrapper safeMutex(&masterServerThreadAccessor); @@ -2308,13 +2323,13 @@ void MenuStateCustomGame::keyDown(char key) { } void MenuStateCustomGame::keyPress(char c) { - if(activeInputLabel!=NULL) { + if(activeInputLabel != NULL) { int maxTextSize= 16; - for(int i=0; i='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')|| - (c=='-')||(c=='(')||(c==')')){ - if(activeInputLabel->getText().size()='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || + (c=='-') || (c=='(') || (c==')')) { + if(activeInputLabel->getText().size() < maxTextSize) { string text= activeInputLabel->getText(); text.insert(text.end()-1, c); activeInputLabel->setText(text); @@ -2388,27 +2403,23 @@ string MenuStateCustomGame::getCurrentMapFile(){ } void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) { - if(newLable!=NULL) { + if(newLable != NULL) { string text= newLable->getText(); - size_t found; - found=text.find_last_of("_"); - if (found==string::npos) - { - text=text+"_"; + size_t found = text.find_last_of("_"); + if (found == string::npos) { + text += "_"; } newLable->setText(text); } - if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()){ + if(activeInputLabel != NULL && activeInputLabel->getText().empty() == false) { string text= activeInputLabel->getText(); - size_t found; - found=text.find_last_of("_"); - if (found!=string::npos) - { - text=text.substr(0,found); + size_t found = text.find_last_of("_"); + if (found != string::npos) { + text = text.substr(0,found); } activeInputLabel->setText(text); } - activeInputLabel=newLable; + activeInputLabel = newLable; } string MenuStateCustomGame::getHumanPlayerName(int index) { diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 3ba0e24e7..5a9c99249 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -176,6 +176,8 @@ private: void RestoreLastGameSettings(); void PlayNow(); + + void SetActivePlayerNameEditor(); }; }}//end namespace diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index e71297284..d1c21e357 100755 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -460,6 +460,7 @@ void ClientInterface::updateLobby() { networkMessageLaunch.buildGameSettings(&gameSettings); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); //replace server player by network for(int i= 0; i