mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Clickable status bar to send messages with on mobile
This commit is contained in:
		| @@ -1038,12 +1038,10 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) | |||||||
| 		{ | 		{ | ||||||
| 			if(captureAllKeys) | 			if(captureAllKeys) | ||||||
| 			{ | 			{ | ||||||
| 				captureAllKeys = false; |  | ||||||
| 				endEnteringText(false); | 				endEnteringText(false); | ||||||
| 			} | 			} | ||||||
| 			else if(SDLK_TAB == key.keysym.sym) | 			else if(SDLK_TAB == key.keysym.sym) | ||||||
| 			{ | 			{ | ||||||
| 				captureAllKeys = true; |  | ||||||
| 				startEnteringText(); | 				startEnteringText(); | ||||||
| 			} | 			} | ||||||
| 			break; | 			break; | ||||||
| @@ -1052,7 +1050,6 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) | |||||||
| 		{ | 		{ | ||||||
| 			if(enteredText.size() > 0  &&  captureAllKeys) | 			if(enteredText.size() > 0  &&  captureAllKeys) | ||||||
| 			{ | 			{ | ||||||
| 				captureAllKeys = false; |  | ||||||
| 				endEnteringText(true); | 				endEnteringText(true); | ||||||
| 				CCS->soundh->playSound("CHAT"); | 				CCS->soundh->playSound("CHAT"); | ||||||
| 			} | 			} | ||||||
| @@ -1129,6 +1126,8 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event) | |||||||
|  |  | ||||||
| void CInGameConsole::startEnteringText() | void CInGameConsole::startEnteringText() | ||||||
| { | { | ||||||
|  | 	captureAllKeys = true; | ||||||
|  |  | ||||||
| 	CSDL_Ext::startTextInput(&GH.statusbar->pos); | 	CSDL_Ext::startTextInput(&GH.statusbar->pos); | ||||||
|  |  | ||||||
| 	enteredText = "_"; | 	enteredText = "_"; | ||||||
| @@ -1148,6 +1147,8 @@ void CInGameConsole::startEnteringText() | |||||||
|  |  | ||||||
| void CInGameConsole::endEnteringText(bool printEnteredText) | void CInGameConsole::endEnteringText(bool printEnteredText) | ||||||
| { | { | ||||||
|  | 	captureAllKeys = false; | ||||||
|  |  | ||||||
| 	CSDL_Ext::stopTextInput(); | 	CSDL_Ext::stopTextInput(); | ||||||
|  |  | ||||||
| 	prevEntDisp = -1; | 	prevEntDisp = -1; | ||||||
|   | |||||||
| @@ -388,6 +388,20 @@ void CGStatusBar::init() | |||||||
| 	GH.statusbar = shared_from_this(); | 	GH.statusbar = shared_from_this(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void CGStatusBar::clickLeft(tribool down, bool previousState) | ||||||
|  | { | ||||||
|  | 	if(!down && onClick) | ||||||
|  | 	{ | ||||||
|  | 		onClick(); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | 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 | ||||||
|   | |||||||
| @@ -124,6 +124,11 @@ class CGStatusBar : public CLabel, public std::enable_shared_from_this<CGStatusB | |||||||
| protected: | protected: | ||||||
| 	Point getBorderSize() override; | 	Point getBorderSize() override; | ||||||
|  |  | ||||||
|  | 	void clickLeft(tribool down, bool previousState) override; | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	std::function<void()> onClick; | ||||||
|  |  | ||||||
| public: | public: | ||||||
| 	template<typename ...Args> | 	template<typename ...Args> | ||||||
| 	static std::shared_ptr<CGStatusBar> create(Args... args) | 	static std::shared_ptr<CGStatusBar> create(Args... args) | ||||||
| @@ -138,6 +143,8 @@ public: | |||||||
| 	void show(SDL_Surface * to) override; //shows statusbar (with current text) | 	void show(SDL_Surface * to) override; //shows statusbar (with current text) | ||||||
|  |  | ||||||
| 	void lock(bool shouldLock); //If true, current text cannot be changed until lock(false) is called | 	void lock(bool shouldLock); //If true, current text cannot be changed until lock(false) is called | ||||||
|  |  | ||||||
|  | 	void setOnClick(std::function<void()> handler); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| class CFocusable; | class CFocusable; | ||||||
|   | |||||||
| @@ -716,6 +716,11 @@ 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() | ||||||
| @@ -949,6 +954,7 @@ void CAdvMapInt::activate() | |||||||
| 		} | 		} | ||||||
| 		minimap.activate(); | 		minimap.activate(); | ||||||
| 		terrain.activate(); | 		terrain.activate(); | ||||||
|  | 		statusbar->activate(); | ||||||
|  |  | ||||||
| 		GH.fakeMouseMove(); //to restore the cursor | 		GH.fakeMouseMove(); //to restore the cursor | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user