From 76d41dfc09733296e172636b19396f07c7abd99e Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sat, 24 Oct 2015 09:02:23 -0700 Subject: [PATCH] - attempt to see if IRC chat works better with sdl2 textinput --- source/glest_game/game/chat_manager.cpp | 17 +++++++++++++++++ source/glest_game/game/chat_manager.h | 1 + source/glest_game/main/main.cpp | 14 ++++++++++++++ source/glest_game/main/main.h | 1 + source/glest_game/main/program.cpp | 8 ++++++++ source/glest_game/main/program.h | 2 ++ source/glest_game/menu/main_menu.cpp | 3 +++ source/glest_game/menu/main_menu.h | 3 +++ .../glest_game/menu/menu_state_masterserver.cpp | 12 ++++++++++++ .../glest_game/menu/menu_state_masterserver.h | 1 + source/shared_lib/include/platform/sdl/window.h | 1 + .../shared_lib/sources/platform/sdl/window.cpp | 13 ++++++------- 12 files changed, 69 insertions(+), 7 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index aaae327fc..b39a370ce 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -95,6 +95,23 @@ 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()); + + int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght); + if(editEnabled && (int)text.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); + return true; + } + return false; +} + void ChatManager::keyDown(SDL_KeyboardEvent key) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym); diff --git a/source/glest_game/game/chat_manager.h b/source/glest_game/game/chat_manager.h index d808a6afd..11afc4ac1 100644 --- a/source/glest_game/game/chat_manager.h +++ b/source/glest_game/game/chat_manager.h @@ -77,6 +77,7 @@ public: ChatManager(); void init(Console* console, int thisTeamIndex, const bool inMenu=false, string manualPlayerNameOverride=""); + bool textInput(std::string text); void keyDown(SDL_KeyboardEvent key); void keyUp(SDL_KeyboardEvent key); void keyPress(SDL_KeyboardEvent c); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 339df62b3..1147525e6 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -1090,6 +1090,20 @@ void MainWindow::toggleLanguage(string language) { } } +bool MainWindow::eventTextInput(std::string text) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,text.c_str()); + + if(program == NULL) { + throw megaglest_runtime_error("In [MainWindow::eventKeyDown] ERROR, program == NULL!"); + } + + bool result = program->textInput(text); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] result = %d\n",__FILE__,__FUNCTION__,__LINE__,result); + + return result; +} + void MainWindow::eventKeyDown(SDL_KeyboardEvent key) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym); diff --git a/source/glest_game/main/main.h b/source/glest_game/main/main.h index 9c326648d..485606306 100644 --- a/source/glest_game/main/main.h +++ b/source/glest_game/main/main.h @@ -48,6 +48,7 @@ public: virtual void eventMouseUp(int x, int y, MouseButton mouseButton); virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton); virtual void eventMouseMove(int x, int y, const MouseState *mouseState); + virtual bool eventTextInput(std::string text); virtual void eventKeyDown(SDL_KeyboardEvent key); virtual void eventMouseWheel(int x, int y, int zDelta); virtual void eventKeyUp(SDL_KeyboardEvent key); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 7e9913182..8956e78c3 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -321,6 +321,14 @@ void Program::restoreStateFromSystemError() { } } +bool Program::textInput(std::string text) { + if(msgBox.getEnabled()) { + return false; + } + //delegate event + return programState->textInput(text); +} + void Program::keyDown(SDL_KeyboardEvent key) { if(msgBox.getEnabled()) { //SDL_keysym keystate = Window::getKeystate(); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 6b390cd9d..a6ea9dd76 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -94,6 +94,7 @@ public: virtual void mouseDoubleClickCenter(int x, int y){} virtual void eventMouseWheel(int x, int y, int zDelta){} virtual void mouseMove(int x, int y, const MouseState *mouseState); + virtual bool textInput(std::string text){ return false; }; virtual void keyDown(SDL_KeyboardEvent key){}; virtual void keyUp(SDL_KeyboardEvent key){}; virtual void keyPress(SDL_KeyboardEvent c){}; @@ -192,6 +193,7 @@ public: void initScenario(WindowGl *window, string autoloadScenarioName); //main + bool textInput(std::string text); void keyDown(SDL_KeyboardEvent key); void keyUp(SDL_KeyboardEvent key); void keyPress(SDL_KeyboardEvent c); diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index c26003792..b77ba02ef 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -233,6 +233,9 @@ void MainMenu::mouseUpLeft(int x, int y){ state->mouseUp(x, y, mbLeft); } +bool MainMenu::textInput(std::string text) { + return state->textInput(text); +} void MainMenu::keyDown(SDL_KeyboardEvent key) { state->keyDown(key); } diff --git a/source/glest_game/menu/main_menu.h b/source/glest_game/menu/main_menu.h index e1cbc775c..ad40a4b07 100644 --- a/source/glest_game/menu/main_menu.h +++ b/source/glest_game/menu/main_menu.h @@ -75,6 +75,7 @@ public: virtual void mouseDownLeft(int x, int y); virtual void mouseDownRight(int x, int y); virtual void mouseUpLeft(int x, int y); + virtual bool textInput(std::string text); virtual void keyDown(SDL_KeyboardEvent key); virtual void keyUp(SDL_KeyboardEvent key); virtual void keyPress(SDL_KeyboardEvent key); @@ -120,6 +121,8 @@ public: virtual void mouseMove(int x, int y, const MouseState *mouseState)=0; virtual void render()=0; virtual void update(){}; + + virtual bool textInput(std::string text) {return false; } virtual void keyDown(SDL_KeyboardEvent key){}; virtual void keyPress(SDL_KeyboardEvent c){}; virtual void keyUp(SDL_KeyboardEvent key){}; diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 42bfe2b58..7b4c0989c 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -1194,7 +1194,19 @@ void MenuStateMasterserver::showMessageBox(const string &text, const string &hea } +bool MenuStateMasterserver::textInput(std::string text) { + //printf("In [%s::%s Line: %d] text [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,text.c_str()); + + if (ircClient != NULL && ircClient->isConnected() == true + && ircClient->getHasJoinedChannel() == true) { + return chatManager.textInput(text); + } + return false; +} + void MenuStateMasterserver::keyDown(SDL_KeyboardEvent key) { + //printf("In [%s::%s Line: %d] key [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,key.keysym.sym); + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); if (ircClient != NULL && ircClient->isConnected() == true diff --git a/source/glest_game/menu/menu_state_masterserver.h b/source/glest_game/menu/menu_state_masterserver.h index 708b05d0e..9b77b9a87 100644 --- a/source/glest_game/menu/menu_state_masterserver.h +++ b/source/glest_game/menu/menu_state_masterserver.h @@ -122,6 +122,7 @@ public: void update(); void render(); + virtual bool textInput(std::string text); virtual void keyDown(SDL_KeyboardEvent key); virtual void keyPress(SDL_KeyboardEvent c); virtual void keyUp(SDL_KeyboardEvent key); diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 8669cefa4..44c385587 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -204,6 +204,7 @@ protected: virtual void eventKeyDown(SDL_KeyboardEvent key) {} virtual void eventKeyUp(SDL_KeyboardEvent key) {} virtual void eventKeyPress(SDL_KeyboardEvent c) {} + virtual bool eventTextInput(std::string text) { return false; } virtual void eventResize() {}; virtual void eventPaint() {} virtual void eventTimer(int timerId) {} diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index dd47405a6..ac80cd7dc 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -321,11 +321,11 @@ bool Window::handleEvent() { //if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("******************* key [%d]\n",key); //event.key.keysym.mod = SDL_GetModState(); - - event.key.keysym.sym = event.text.text[0]; - - global_window->eventKeyDown(event.key); - global_window->eventKeyPress(event.key); + if(global_window->eventTextInput(event.text.text) == false) { + event.key.keysym.sym = event.text.text[0]; + global_window->eventKeyDown(event.key); + global_window->eventKeyPress(event.key); + } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } @@ -338,10 +338,9 @@ bool Window::handleEvent() { break; case SDL_KEYDOWN: - //printf("In [%s::%s] Line :%d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); { - + //printf("In SDL_KEYDOWN\n"); if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] =================================== START OF SDL SDL_KEYDOWN ================================\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); // if(SDL_GetModState() == 0 && event.key.keysym.sym != SDLK_BACKSPACE) {