1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Clickable status bar to send messages with on mobile

This commit is contained in:
Andrii Danylchenko
2022-11-20 11:53:46 +02:00
parent 3b072b80d5
commit d6ca8017bf
4 changed files with 31 additions and 3 deletions

View File

@@ -1038,12 +1038,10 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
{
if(captureAllKeys)
{
captureAllKeys = false;
endEnteringText(false);
}
else if(SDLK_TAB == key.keysym.sym)
{
captureAllKeys = true;
startEnteringText();
}
break;
@@ -1052,7 +1050,6 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
{
if(enteredText.size() > 0 && captureAllKeys)
{
captureAllKeys = false;
endEnteringText(true);
CCS->soundh->playSound("CHAT");
}
@@ -1129,6 +1126,8 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event)
void CInGameConsole::startEnteringText()
{
captureAllKeys = true;
CSDL_Ext::startTextInput(&GH.statusbar->pos);
enteredText = "_";
@@ -1148,6 +1147,8 @@ void CInGameConsole::startEnteringText()
void CInGameConsole::endEnteringText(bool printEnteredText)
{
captureAllKeys = false;
CSDL_Ext::stopTextInput();
prevEntDisp = -1;

View File

@@ -388,6 +388,20 @@ void CGStatusBar::init()
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()
{
//Width of borders where text should not be printed

View File

@@ -124,6 +124,11 @@ class CGStatusBar : public CLabel, public std::enable_shared_from_this<CGStatusB
protected:
Point getBorderSize() override;
void clickLeft(tribool down, bool previousState) override;
private:
std::function<void()> onClick;
public:
template<typename ...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 lock(bool shouldLock); //If true, current text cannot be changed until lock(false) is called
void setOnClick(std::function<void()> handler);
};
class CFocusable;

View File

@@ -716,6 +716,11 @@ CAdvMapInt::CAdvMapInt():
worldViewUnderground->block(!CGI->mh->map->twoLevel);
addUsedEvents(MOVE);
statusbar->setOnClick([&]
{
if(LOCPLINT) LOCPLINT->cingconsole->startEnteringText();
});
}
CAdvMapInt::~CAdvMapInt()
@@ -949,6 +954,7 @@ void CAdvMapInt::activate()
}
minimap.activate();
terrain.activate();
statusbar->activate();
GH.fakeMouseMove(); //to restore the cursor
}