From 30d72c7b3c0860c4488972dc88d1475b7e99cd28 Mon Sep 17 00:00:00 2001 From: titiger Date: Sun, 25 Oct 2015 00:06:29 +0200 Subject: [PATCH] backspace, tab extension and length calc should work now in chat manager --- source/glest_game/game/chat_manager.cpp | 32 +++++++++---------- .../menu/menu_state_masterserver.cpp | 4 +-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index b39a370c..b430ef9a 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -95,18 +95,15 @@ void ChatManager::keyUp(SDL_KeyboardEvent key) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } -bool ChatManager::textInput(std::string text) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] text [%s]\n",__FILE__,__FUNCTION__,__LINE__,text.c_str()); +bool ChatManager::textInput(std::string inputText) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] inputText [%s]\n",__FILE__,__FUNCTION__,__LINE__,inputText.c_str()); int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght); - if(editEnabled && (int)text.size() < maxTextLenAllowed) { + if(editEnabled && (int)textCharLength.size() < maxTextLenAllowed) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - //space is the first meaningful code - //wchar_t key = extractKeyPressedUnicode(c); - //wchar_t textAppend[] = { key, 0 }; - std::wstring widestr = std::wstring(text.begin(), text.end()); - const wchar_t *textAppend = widestr.c_str(); - appendText(textAppend); + textCharLength.push_back(inputText.length()); + this->text +=inputText; + updateAutoCompleteBuffer(); return true; } return false; @@ -351,14 +348,15 @@ void ChatManager::keyDown(SDL_KeyboardEvent key) { void ChatManager::keyPress(SDL_KeyboardEvent c) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c.keysym.sym,c.keysym.sym); - int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght); - if(editEnabled && (int)text.size() < maxTextLenAllowed) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c.keysym.sym,c.keysym.sym); - //space is the first meaningful code - wchar_t key = extractKeyPressedUnicode(c); - wchar_t textAppend[] = { key, 0 }; - appendText(textAppend); - } +// no more textinput with keyPress in SDL2! +// int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght); +// if(editEnabled && (int)text.size() < maxTextLenAllowed) { +// SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c.keysym.sym,c.keysym.sym); +// //space is the first meaningful code +// wchar_t key = extractKeyPressedUnicode(c); +// wchar_t textAppend[] = { key, 0 }; +// appendText(textAppend); +// } } void ChatManager::switchOnEdit(CustomInputCallbackInterface *customCB,int maxCustomTextLength) { diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 29a984d1..3abf0daf 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -1218,9 +1218,7 @@ void MenuStateMasterserver::keyDown(SDL_KeyboardEvent key) { ircClient->SendIRCCmdMessage(IRC_CHANNEL, chatManager.getText()); } } - if(isKeyPressed(SDLK_RETURN,key,false) == true){ - chatManager.keyDown(key); - } + chatManager.keyDown(key); } if(chatManager.getEditEnabled() == false) { //if(key == configKeys.getCharKey("ToggleMusic")) {