From a75b437fef447b5faf6fbf8005f8936f58bbd104 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 19 Dec 2022 22:06:01 +0200 Subject: [PATCH] Disable text input on window deactivation --- client/battle/BattleInterfaceClasses.cpp | 4 +++- client/battle/BattleInterfaceClasses.h | 5 +++-- client/widgets/TextControls.cpp | 8 ++++++++ client/widgets/TextControls.h | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 9413133c9..b1bc867fc 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -113,10 +113,12 @@ BattleConsole::BattleConsole(const Rect & position) pos.h = position.h; } -BattleConsole::~BattleConsole() +void BattleConsole::deactivate() { if (enteringText) setEnteringMode(false); + + CIntObject::deactivate(); } void BattleConsole::setEnteringMode(bool on) diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index 9014ee784..e6e0cc929 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -55,12 +55,13 @@ private: /// current text entered via in-game console, takes priority over both log entries and hover text std::string consoleText; - /// if true then we are currently entering console text + /// if true then we are currently entering console tex bool enteringText; public: BattleConsole(const Rect & position); - ~BattleConsole(); + void showAll(SDL_Surface * to) override; + void deactivate() override; bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index d9fb7d9a1..d1d79dc2d 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -432,6 +432,14 @@ void CGStatusBar::clickLeft(tribool down, bool previousState) } } +void CGStatusBar::deactivate() +{ + if (enteringText) + setEnteringMode(false); + + CIntObject::deactivate(); +} + void CGStatusBar::setOnClick(std::function handler) { onClick = handler; diff --git a/client/widgets/TextControls.h b/client/widgets/TextControls.h index c251913bb..f64adf3c5 100644 --- a/client/widgets/TextControls.h +++ b/client/widgets/TextControls.h @@ -152,6 +152,7 @@ public: void setOnClick(std::function handler); void show(SDL_Surface * to) override; + void deactivate() override; // IStatusBar interface void write(const std::string & Text) override;