Browse Source

Fixed auto-enabling of status bar on windows activations

Ivan Savenko 2 years ago
parent
commit
c24ccf663b

+ 14 - 4
client/widgets/TextControls.cpp

@@ -432,14 +432,16 @@ CGStatusBar::CGStatusBar(int x, int y, std::string name, int maxw)
 	autoRedraw = false;
 }
 
-void CGStatusBar::show(SDL_Surface * to)
+CGStatusBar::~CGStatusBar()
 {
-	showAll(to);
+	assert(GH.statusbar.get() != this || GH.statusbar == nullptr);
+	if (GH.statusbar.get() == this)
+		GH.statusbar = nullptr;
 }
 
-void CGStatusBar::init()
+void CGStatusBar::show(SDL_Surface * to)
 {
-	GH.statusbar = shared_from_this();
+	showAll(to);
 }
 
 void CGStatusBar::clickLeft(tribool down, bool previousState)
@@ -451,8 +453,16 @@ void CGStatusBar::clickLeft(tribool down, bool previousState)
 	}
 }
 
+void CGStatusBar::activate()
+{
+	GH.statusbar = shared_from_this();
+	CIntObject::deactivate();
+}
+
 void CGStatusBar::deactivate()
 {
+	assert(GH.statusbar.get() == this);
+
 	if (enteringText)
 		LOCPLINT->cingconsole->endEnteringText(false);
 

+ 3 - 3
client/widgets/TextControls.h

@@ -125,8 +125,6 @@ class CGStatusBar : public CLabel, public std::enable_shared_from_this<CGStatusB
 	std::string consoleText;
 	bool enteringText;
 
-	void init();
-
 	CGStatusBar(std::shared_ptr<CIntObject> background_, EFonts Font = FONT_SMALL, ETextAlignment Align = ETextAlignment::CENTER, const SDL_Color & Color = Colors::WHITE);
 	CGStatusBar(int x, int y, std::string name, int maxw = -1);
 
@@ -143,15 +141,17 @@ protected:
 	void clickLeft(tribool down, bool previousState) override;
 
 public:
+	~CGStatusBar();
+
 	template<typename ...Args>
 	static std::shared_ptr<CGStatusBar> create(Args... args)
 	{
 		std::shared_ptr<CGStatusBar> ret{new CGStatusBar{args...}};
-		ret->init();
 		return ret;
 	}
 
 	void show(SDL_Surface * to) override;
+	void activate() override;
 	void deactivate() override;
 
 	// IStatusBar interface

+ 0 - 6
client/windows/CWindowObject.cpp

@@ -248,9 +248,3 @@ CStatusbarWindow::CStatusbarWindow(int options, std::string imageName, Point cen
 CStatusbarWindow::CStatusbarWindow(int options, std::string imageName) : CWindowObject(options, imageName)
 {
 }
-
-void CStatusbarWindow::activate()
-{
-	CIntObject::activate();
-	GH.statusbar = statusbar;
-}

+ 0 - 1
client/windows/CWindowObject.h

@@ -58,7 +58,6 @@ class CStatusbarWindow : public CWindowObject
 public:
 	CStatusbarWindow(int options, std::string imageName, Point centerAt);
 	CStatusbarWindow(int options, std::string imageName = "");
-	void activate() override;
 protected:
 	std::shared_ptr<CGStatusBar> statusbar;
 };