2
0
Эх сурвалжийг харах

Fix Status Bar & In-game console activation

Ivan Savenko 2 жил өмнө
parent
commit
b373c4a2b6

+ 2 - 1
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();
 }

+ 20 - 2
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)

+ 2 - 0
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<IStatusBar> currentStatusBar;
 public:
 	std::string enteredText;
 	void show(SDL_Surface * to) override;

+ 6 - 9
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<void()> handler)
-{
-	onClick = handler;
-	addUsedEvents(LCLICK);
-}
-
 Point CGStatusBar::getBorderSize()
 {
 	//Width of borders where text should not be printed

+ 0 - 2
client/widgets/TextControls.h

@@ -149,8 +149,6 @@ public:
 		return ret;
 	}
 
-	void setOnClick(std::function<void()> handler);
-
 	void show(SDL_Surface * to) override;
 	void deactivate() override;
 

+ 0 - 5
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()