From b373c4a2b68b80a1985bdaa379129a23da8eaf15 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 19 Dec 2022 22:53:31 +0200 Subject: [PATCH] Fix Status Bar & In-game console activation --- client/battle/BattleInterfaceClasses.cpp | 3 ++- client/widgets/AdventureMapClasses.cpp | 22 ++++++++++++++++++++-- client/widgets/AdventureMapClasses.h | 2 ++ client/widgets/TextControls.cpp | 15 ++++++--------- client/widgets/TextControls.h | 2 -- client/windows/CAdvmapInterface.cpp | 5 ----- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index b1bc867fc..3df6ac532 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -27,6 +27,7 @@ #include "../gui/Canvas.h" #include "../gui/CCursorHandler.h" #include "../gui/CGuiHandler.h" +#include "../widgets/AdventureMapClasses.h" #include "../widgets/Buttons.h" #include "../widgets/Images.h" #include "../widgets/TextControls.h" @@ -116,7 +117,7 @@ BattleConsole::BattleConsole(const Rect & position) void BattleConsole::deactivate() { if (enteringText) - setEnteringMode(false); + LOCPLINT->cingconsole->endEnteringText(false); CIntObject::deactivate(); } diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index 474c80af6..292a6baf1 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -1126,10 +1126,17 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event) void CInGameConsole::startEnteringText() { + if (!active) + return; + if (captureAllKeys) return; assert(GH.statusbar); + assert(currentStatusBar.expired());//effectively, nullptr check + + currentStatusBar = GH.statusbar; + captureAllKeys = true; enteredText = "_"; @@ -1148,12 +1155,23 @@ void CInGameConsole::endEnteringText(bool printEnteredText) previouslyEntered.push_back(txt); } enteredText.clear(); - GH.statusbar->setEnteringMode(false); + + auto statusbar = currentStatusBar.lock(); + assert(statusbar); + + if (statusbar) + statusbar->setEnteringMode(false); + + currentStatusBar.reset(); } void CInGameConsole::refreshEnteredText() { - GH.statusbar->setEnteredText(enteredText); + auto statusbar = currentStatusBar.lock(); + assert(statusbar); + + if (statusbar) + statusbar->setEnteredText(enteredText); } CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position) diff --git a/client/widgets/AdventureMapClasses.h b/client/widgets/AdventureMapClasses.h index 9eb592c3c..1c7ef5b50 100644 --- a/client/widgets/AdventureMapClasses.h +++ b/client/widgets/AdventureMapClasses.h @@ -412,6 +412,8 @@ private: int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1 int defaultTimeout; //timeout for new texts (in ms) int maxDisplayedTexts; //hiw many texts can be displayed simultaneously + + std::weak_ptr currentStatusBar; public: std::string enteredText; void show(SDL_Surface * to) override; diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index d1d79dc2d..601a4f80e 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -14,7 +14,9 @@ #include "Images.h" #include "../CMessage.h" +#include "../CPlayerInterface.h" #include "../gui/CGuiHandler.h" +#include "../widgets/AdventureMapClasses.h" #include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff @@ -426,26 +428,21 @@ void CGStatusBar::init() void CGStatusBar::clickLeft(tribool down, bool previousState) { - if(!down && onClick) + if(!down && onClick ) { - onClick(); + if(LOCPLINT && LOCPLINT->cingconsole->active) + LOCPLINT->cingconsole->startEnteringText(); } } void CGStatusBar::deactivate() { if (enteringText) - setEnteringMode(false); + LOCPLINT->cingconsole->endEnteringText(false); CIntObject::deactivate(); } -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 f64adf3c5..5e9a49aef 100644 --- a/client/widgets/TextControls.h +++ b/client/widgets/TextControls.h @@ -149,8 +149,6 @@ public: return ret; } - void setOnClick(std::function handler); - void show(SDL_Surface * to) override; void deactivate() override; diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index f7e3ba609..8242d1882 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -716,11 +716,6 @@ CAdvMapInt::CAdvMapInt(): worldViewUnderground->block(!CGI->mh->map->twoLevel); addUsedEvents(MOVE); - - statusbar->setOnClick([&] - { - if(LOCPLINT) LOCPLINT->cingconsole->startEnteringText(); - }); } CAdvMapInt::~CAdvMapInt()