- final bugfix for 3.3.7, playernames got mixed up when first slot was closed. Also fixed editing when typing playername

This commit is contained in:
Mark Vejvoda 2010-10-08 01:41:53 +00:00
parent cb5f5e55eb
commit f345835fc4
7 changed files with 81 additions and 61 deletions

View File

@ -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<GameConstants::maxPlayers; ++i){
if(&labelPlayerNames[i] == activeInputLabel){
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
(c=='-')||(c=='(')||(c==')')){
if(activeInputLabel->getText().size()<maxTextSize) {
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
if(&labelPlayerNames[i] == activeInputLabel) {
if((c>='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; j<GameConstants::maxPlayers; ++j) {
if( clientInterface != NULL &&
clientInterface->getGameSettings() != NULL &&
j == clientInterface->getGameSettings()->getThisFactionIndex() &&
j == clientInterface->getPlayerIndex() &&
labelPlayerNames[j].getText() != "") {
result = labelPlayerNames[j].getText();

View File

@ -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<ControlType>(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<ControlType>(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; i<GameConstants::maxPlayers; ++i){
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
listBoxControls[i].mouseMove(x, y);
listBoxFactions[i].mouseMove(x, y);
listBoxTeams[i].mouseMove(x, y);
@ -1207,7 +1214,7 @@ void MenuStateCustomGame::update() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %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<GameConstants::maxPlayers; ++i) {
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
if(&labelPlayerNames[i] == activeInputLabel) {
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
(c=='-')||(c=='(')||(c==')')){
if(activeInputLabel->getText().size()<maxTextSize) {
if((c>='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) {

View File

@ -176,6 +176,8 @@ private:
void RestoreLastGameSettings();
void PlayNow();
void SetActivePlayerNameEditor();
};
}}//end namespace

View File

@ -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<gameSettings.getFactionCount(); ++i) {
//replace by network
@ -468,8 +469,9 @@ void ClientInterface::updateLobby() {
}
//set the faction index
if(gameSettings.getStartLocationIndex(i)==playerIndex) {
if(gameSettings.getStartLocationIndex(i) == playerIndex) {
gameSettings.setThisFactionIndex(i);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] gameSettings.getThisFactionIndex(i) = %d, playerIndex = %d, i = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getThisFactionIndex(),playerIndex,i);
}
}

View File

@ -107,6 +107,7 @@ const char vkF9 = -22;
const char vkF10 = -23;
const char vkF11 = -24;
const char vkF12 = -25;
const char vkDelete = -26;
enum WindowStyle{
wsFullscreen,

View File

@ -904,6 +904,8 @@ bool isKeyDown(int virtualKey) {
return keystate[SDLK_RETURN] | keystate[SDLK_KP_ENTER];
case vkBack:
return keystate[SDLK_BACKSPACE];
case vkDelete:
return keystate[SDLK_DELETE];
default:
std::cerr << "isKeyDown called with unknown key.\n";
break;

View File

@ -620,6 +620,8 @@ char Window::getKey(SDL_keysym keysym,bool skipSpecialKeys) {
return vkTab;
case SDLK_BACKSPACE:
return vkBack;
case SDLK_DELETE:
return vkDelete;
case SDLK_F1:
return vkF1;
break;