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