From d6ca8017bf7ab36d6a43688b2a79bdae0c5076d7 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sun, 20 Nov 2022 11:53:46 +0200 Subject: [PATCH] Clickable status bar to send messages with on mobile --- client/widgets/AdventureMapClasses.cpp | 7 ++++--- client/widgets/TextControls.cpp | 14 ++++++++++++++ client/widgets/TextControls.h | 7 +++++++ client/windows/CAdvmapInterface.cpp | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index 1a4be8d59..ae16aabce 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -1038,12 +1038,10 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) { if(captureAllKeys) { - captureAllKeys = false; endEnteringText(false); } else if(SDLK_TAB == key.keysym.sym) { - captureAllKeys = true; startEnteringText(); } break; @@ -1052,7 +1050,6 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) { if(enteredText.size() > 0 && captureAllKeys) { - captureAllKeys = false; endEnteringText(true); CCS->soundh->playSound("CHAT"); } @@ -1129,6 +1126,8 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event) void CInGameConsole::startEnteringText() { + captureAllKeys = true; + CSDL_Ext::startTextInput(&GH.statusbar->pos); enteredText = "_"; @@ -1148,6 +1147,8 @@ void CInGameConsole::startEnteringText() void CInGameConsole::endEnteringText(bool printEnteredText) { + captureAllKeys = false; + CSDL_Ext::stopTextInput(); prevEntDisp = -1; diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index 96a0ec71c..3fdf070e3 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -388,6 +388,20 @@ void CGStatusBar::init() GH.statusbar = shared_from_this(); } +void CGStatusBar::clickLeft(tribool down, bool previousState) +{ + if(!down && onClick) + { + onClick(); + } +} + +void CGStatusBar::setOnClick(std::function handler) +{ + onClick = handler; + addUsedEvents(LCLICK); +} + Point CGStatusBar::getBorderSize() { //Width of borders where text should not be printed diff --git a/client/widgets/TextControls.h b/client/widgets/TextControls.h index 6dbfef0be..335d9c1c4 100644 --- a/client/widgets/TextControls.h +++ b/client/widgets/TextControls.h @@ -124,6 +124,11 @@ class CGStatusBar : public CLabel, public std::enable_shared_from_this onClick; + public: template static std::shared_ptr create(Args... args) @@ -138,6 +143,8 @@ public: void show(SDL_Surface * to) override; //shows statusbar (with current text) void lock(bool shouldLock); //If true, current text cannot be changed until lock(false) is called + + void setOnClick(std::function handler); }; class CFocusable; diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index 92d9da39c..3b5f9ed7b 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -716,6 +716,11 @@ CAdvMapInt::CAdvMapInt(): worldViewUnderground->block(!CGI->mh->map->twoLevel); addUsedEvents(MOVE); + + statusbar->setOnClick([&] + { + if(LOCPLINT) LOCPLINT->cingconsole->startEnteringText(); + }); } CAdvMapInt::~CAdvMapInt() @@ -949,6 +954,7 @@ void CAdvMapInt::activate() } minimap.activate(); terrain.activate(); + statusbar->activate(); GH.fakeMouseMove(); //to restore the cursor }