- fix backspace deleting in options menu when changing playername and playername has _ in part of it

This commit is contained in:
Mark Vejvoda 2012-07-25 16:49:58 +00:00
parent f3165b2548
commit 96ade03a27
2 changed files with 21 additions and 11 deletions

View File

@ -527,13 +527,17 @@ void MenuStateJoinGame::keyDown(SDL_KeyboardEvent key) {
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(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);

View File

@ -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);
}
}