From 96ade03a27481d2ca233fb8d1a809b645fe295e8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 25 Jul 2012 16:49:58 +0000 Subject: [PATCH] - fix backspace deleting in options menu when changing playername and playername has _ in part of it --- source/glest_game/menu/menu_state_join_game.cpp | 16 ++++++++++------ source/glest_game/menu/menu_state_options.cpp | 16 +++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index b1ce7061..cc40bc8b 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -527,13 +527,17 @@ void MenuStateJoinGame::keyDown(SDL_KeyboardEvent key) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); - //if(key == vkBack) { - if(isKeyPressed(SDLK_BACKSPACE,key) == true) { + string text = labelServerIp.getText(); + if(isKeyPressed(SDLK_BACKSPACE,key) == true && text.length() > 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - string text= labelServerIp.getText(); - - if(text.size() > 1) { - text.erase(text.end()-2); + size_t found = text.find_last_of("_"); + if (found == string::npos) { + text.erase(text.end() - 1); + } + else { + if(text.size() > 1) { + text.erase(text.end() - 2); + } } labelServerIp.setText(text); diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index dee16902..c6f17cae 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -941,12 +941,18 @@ bool MenuStateOptions::isInSpecialKeyCaptureEvent() { void MenuStateOptions::keyDown(SDL_KeyboardEvent key) { if(activeInputLabel != NULL) { - //if(key == vkBack) { - if(isKeyPressed(SDLK_BACKSPACE,key) == true) { - string text= activeInputLabel->getText(); - if(text.size() > 1) { - text.erase(text.end()-2); + string text= activeInputLabel->getText(); + if(isKeyPressed(SDLK_BACKSPACE,key) == true && text.length() > 0) { + size_t found = text.find_last_of("_"); + if (found == string::npos) { + text.erase(text.end() - 1); } + else { + if(text.size() > 1) { + text.erase(text.end() - 2); + } + } + activeInputLabel->setText(text); } }