mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Fix Status Bar & In-game console activation
This commit is contained in:
		| @@ -27,6 +27,7 @@ | |||||||
| #include "../gui/Canvas.h" | #include "../gui/Canvas.h" | ||||||
| #include "../gui/CCursorHandler.h" | #include "../gui/CCursorHandler.h" | ||||||
| #include "../gui/CGuiHandler.h" | #include "../gui/CGuiHandler.h" | ||||||
|  | #include "../widgets/AdventureMapClasses.h" | ||||||
| #include "../widgets/Buttons.h" | #include "../widgets/Buttons.h" | ||||||
| #include "../widgets/Images.h" | #include "../widgets/Images.h" | ||||||
| #include "../widgets/TextControls.h" | #include "../widgets/TextControls.h" | ||||||
| @@ -116,7 +117,7 @@ BattleConsole::BattleConsole(const Rect & position) | |||||||
| void BattleConsole::deactivate() | void BattleConsole::deactivate() | ||||||
| { | { | ||||||
| 	if (enteringText) | 	if (enteringText) | ||||||
| 		setEnteringMode(false); | 		LOCPLINT->cingconsole->endEnteringText(false); | ||||||
|  |  | ||||||
| 	CIntObject::deactivate(); | 	CIntObject::deactivate(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1126,10 +1126,17 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event) | |||||||
|  |  | ||||||
| void CInGameConsole::startEnteringText() | void CInGameConsole::startEnteringText() | ||||||
| { | { | ||||||
|  | 	if (!active) | ||||||
|  | 		return; | ||||||
|  |  | ||||||
| 	if (captureAllKeys) | 	if (captureAllKeys) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	assert(GH.statusbar); | 	assert(GH.statusbar); | ||||||
|  | 	assert(currentStatusBar.expired());//effectively, nullptr check | ||||||
|  |  | ||||||
|  | 	currentStatusBar = GH.statusbar; | ||||||
|  |  | ||||||
| 	captureAllKeys = true; | 	captureAllKeys = true; | ||||||
| 	enteredText = "_"; | 	enteredText = "_"; | ||||||
|  |  | ||||||
| @@ -1148,12 +1155,23 @@ void CInGameConsole::endEnteringText(bool printEnteredText) | |||||||
| 		previouslyEntered.push_back(txt); | 		previouslyEntered.push_back(txt); | ||||||
| 	} | 	} | ||||||
| 	enteredText.clear(); | 	enteredText.clear(); | ||||||
| 	GH.statusbar->setEnteringMode(false); |  | ||||||
|  | 	auto statusbar = currentStatusBar.lock(); | ||||||
|  | 	assert(statusbar); | ||||||
|  |  | ||||||
|  | 	if (statusbar) | ||||||
|  | 		statusbar->setEnteringMode(false); | ||||||
|  |  | ||||||
|  | 	currentStatusBar.reset(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void CInGameConsole::refreshEnteredText() | 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) | CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position) | ||||||
|   | |||||||
| @@ -412,6 +412,8 @@ private: | |||||||
| 	int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1 | 	int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1 | ||||||
| 	int defaultTimeout; //timeout for new texts (in ms) | 	int defaultTimeout; //timeout for new texts (in ms) | ||||||
| 	int maxDisplayedTexts; //hiw many texts can be displayed simultaneously | 	int maxDisplayedTexts; //hiw many texts can be displayed simultaneously | ||||||
|  |  | ||||||
|  | 	std::weak_ptr<IStatusBar> currentStatusBar; | ||||||
| public: | public: | ||||||
| 	std::string enteredText; | 	std::string enteredText; | ||||||
| 	void show(SDL_Surface * to) override; | 	void show(SDL_Surface * to) override; | ||||||
|   | |||||||
| @@ -14,7 +14,9 @@ | |||||||
| #include "Images.h" | #include "Images.h" | ||||||
|  |  | ||||||
| #include "../CMessage.h" | #include "../CMessage.h" | ||||||
|  | #include "../CPlayerInterface.h" | ||||||
| #include "../gui/CGuiHandler.h" | #include "../gui/CGuiHandler.h" | ||||||
|  | #include "../widgets/AdventureMapClasses.h" | ||||||
|  |  | ||||||
| #include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff | #include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff | ||||||
|  |  | ||||||
| @@ -426,26 +428,21 @@ void CGStatusBar::init() | |||||||
|  |  | ||||||
| void CGStatusBar::clickLeft(tribool down, bool previousState) | 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() | void CGStatusBar::deactivate() | ||||||
| { | { | ||||||
| 	if (enteringText) | 	if (enteringText) | ||||||
| 		setEnteringMode(false); | 		LOCPLINT->cingconsole->endEnteringText(false); | ||||||
|  |  | ||||||
| 	CIntObject::deactivate(); | 	CIntObject::deactivate(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void CGStatusBar::setOnClick(std::function<void()> handler) |  | ||||||
| { |  | ||||||
| 	onClick = handler; |  | ||||||
| 	addUsedEvents(LCLICK); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| Point CGStatusBar::getBorderSize() | Point CGStatusBar::getBorderSize() | ||||||
| { | { | ||||||
| 	//Width of borders where text should not be printed | 	//Width of borders where text should not be printed | ||||||
|   | |||||||
| @@ -149,8 +149,6 @@ public: | |||||||
| 		return ret; | 		return ret; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void setOnClick(std::function<void()> handler); |  | ||||||
|  |  | ||||||
| 	void show(SDL_Surface * to) override; | 	void show(SDL_Surface * to) override; | ||||||
| 	void deactivate() override; | 	void deactivate() override; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -716,11 +716,6 @@ CAdvMapInt::CAdvMapInt(): | |||||||
| 	worldViewUnderground->block(!CGI->mh->map->twoLevel); | 	worldViewUnderground->block(!CGI->mh->map->twoLevel); | ||||||
|  |  | ||||||
| 	addUsedEvents(MOVE); | 	addUsedEvents(MOVE); | ||||||
|  |  | ||||||
| 	statusbar->setOnClick([&] |  | ||||||
| 		{ |  | ||||||
| 			if(LOCPLINT) LOCPLINT->cingconsole->startEnteringText(); |  | ||||||
| 		}); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| CAdvMapInt::~CAdvMapInt() | CAdvMapInt::~CAdvMapInt() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user