Browse Source

Clickable status bar to send messages with on mobile

Andrii Danylchenko 2 years ago
parent
commit
d6ca8017bf

+ 4 - 3
client/widgets/AdventureMapClasses.cpp

@@ -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;

+ 14 - 0
client/widgets/TextControls.cpp

@@ -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

+ 7 - 0
client/widgets/TextControls.h

@@ -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;

+ 6 - 0
client/windows/CAdvmapInterface.cpp

@@ -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
 	}
 	}