mirror of
https://github.com/vcmi/vcmi.git
synced 2025-12-01 23:12:49 +02:00
changes to status bar according to review comments:
- renamed IStatusBar API to more clear names - removed "locking" of status bar - added comments for IStatusBar API - removed dynamic_casts to CGStatusBar, now IStatusBar API is fully sufficient
This commit is contained in:
@@ -1126,54 +1126,31 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event)
|
||||
|
||||
void CInGameConsole::startEnteringText()
|
||||
{
|
||||
auto statusBar = std::dynamic_pointer_cast<CGStatusBar>(GH.statusbar);
|
||||
assert(GH.statusbar);
|
||||
captureAllKeys = true;
|
||||
enteredText = "_";
|
||||
|
||||
if (statusBar)
|
||||
{
|
||||
captureAllKeys = true;
|
||||
|
||||
CSDL_Ext::startTextInput(&statusBar->pos);
|
||||
|
||||
enteredText = "_";
|
||||
|
||||
statusBar->alignment = ETextAlignment::TOPLEFT;
|
||||
statusBar->write(enteredText);
|
||||
statusBar->lock(true);
|
||||
}
|
||||
GH.statusbar->setEnteringMode(true);
|
||||
GH.statusbar->setEnteredText(enteredText);
|
||||
}
|
||||
|
||||
void CInGameConsole::endEnteringText(bool printEnteredText)
|
||||
{
|
||||
captureAllKeys = false;
|
||||
|
||||
CSDL_Ext::stopTextInput();
|
||||
|
||||
prevEntDisp = -1;
|
||||
if(printEnteredText)
|
||||
{
|
||||
std::string txt = enteredText.substr(0, enteredText.size()-1);
|
||||
LOCPLINT->cb->sendMessage(txt, LOCPLINT->getSelection());
|
||||
previouslyEntered.push_back(txt);
|
||||
//print(txt);
|
||||
}
|
||||
enteredText.clear();
|
||||
|
||||
auto statusBar = std::dynamic_pointer_cast<CGStatusBar>(GH.statusbar);
|
||||
|
||||
if(statusBar)
|
||||
{
|
||||
statusBar->alignment = ETextAlignment::CENTER;
|
||||
}
|
||||
GH.statusbar->lock(false);
|
||||
GH.statusbar->clear();
|
||||
GH.statusbar->setEnteringMode(false);
|
||||
}
|
||||
|
||||
void CInGameConsole::refreshEnteredText()
|
||||
{
|
||||
GH.statusbar->lock(false);
|
||||
GH.statusbar->clear();
|
||||
GH.statusbar->write(enteredText);
|
||||
GH.statusbar->lock(true);
|
||||
GH.statusbar->setEnteredText(enteredText);
|
||||
}
|
||||
|
||||
CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position)
|
||||
|
||||
@@ -339,36 +339,67 @@ void CTextBox::setText(const std::string & text)
|
||||
}
|
||||
}
|
||||
|
||||
void CGStatusBar::setEnteringMode(bool on)
|
||||
{
|
||||
consoleText.clear();
|
||||
|
||||
if (on)
|
||||
{
|
||||
assert(enteringText == false);
|
||||
alignment = ETextAlignment::TOPLEFT;
|
||||
CSDL_Ext::startTextInput(&pos);
|
||||
setText(consoleText);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(enteringText == true);
|
||||
alignment = ETextAlignment::CENTER;
|
||||
CSDL_Ext::stopTextInput();
|
||||
setText(hoverText);
|
||||
}
|
||||
enteringText = on;
|
||||
}
|
||||
|
||||
void CGStatusBar::setEnteredText(const std::string & text)
|
||||
{
|
||||
assert(enteringText == true);
|
||||
consoleText = text;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
void CGStatusBar::write(const std::string & Text)
|
||||
{
|
||||
if(!textLock)
|
||||
CLabel::setText(Text);
|
||||
hoverText = Text;
|
||||
|
||||
if (enteringText == false)
|
||||
setText(hoverText);
|
||||
}
|
||||
|
||||
void CGStatusBar::clearIfMatching(const std::string & Text)
|
||||
{
|
||||
if (getText() == Text)
|
||||
if (hoverText == Text)
|
||||
clear();
|
||||
}
|
||||
|
||||
void CGStatusBar::clear()
|
||||
{
|
||||
setText("");
|
||||
write({});
|
||||
}
|
||||
|
||||
CGStatusBar::CGStatusBar(std::shared_ptr<CPicture> background_, EFonts Font, ETextAlignment Align, const SDL_Color & Color)
|
||||
: CLabel(background_->pos.x, background_->pos.y, Font, Align, Color, "")
|
||||
, enteringText(false)
|
||||
{
|
||||
background = background_;
|
||||
addChild(background.get());
|
||||
pos = background->pos;
|
||||
getBorderSize();
|
||||
textLock = false;
|
||||
autoRedraw = false;
|
||||
}
|
||||
|
||||
CGStatusBar::CGStatusBar(int x, int y, std::string name, int maxw)
|
||||
: CLabel(x, y, FONT_SMALL, ETextAlignment::CENTER)
|
||||
, enteringText(false)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
background = std::make_shared<CPicture>(name);
|
||||
@@ -380,7 +411,6 @@ CGStatusBar::CGStatusBar(int x, int y, std::string name, int maxw)
|
||||
vstd::amin(pos.w, maxw);
|
||||
background->srcRect = new Rect(0, 0, maxw, pos.h);
|
||||
}
|
||||
textLock = false;
|
||||
autoRedraw = false;
|
||||
}
|
||||
|
||||
@@ -423,11 +453,6 @@ Point CGStatusBar::getBorderSize()
|
||||
return Point();
|
||||
}
|
||||
|
||||
void CGStatusBar::lock(bool shouldLock)
|
||||
{
|
||||
textLock = shouldLock;
|
||||
}
|
||||
|
||||
CTextInput::CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(const std::string &)> & CB)
|
||||
: CLabel(Pos.x, Pos.y, font, ETextAlignment::CENTER),
|
||||
cb(CB),
|
||||
|
||||
@@ -116,7 +116,10 @@ public:
|
||||
/// Status bar which is shown at the bottom of the in-game screens
|
||||
class CGStatusBar : public CLabel, public std::enable_shared_from_this<CGStatusBar>, public IStatusBar
|
||||
{
|
||||
bool textLock; //Used for blocking changes to the text
|
||||
std::string hoverText;
|
||||
std::string consoleText;
|
||||
bool enteringText;
|
||||
|
||||
void init();
|
||||
|
||||
CGStatusBar(std::shared_ptr<CPicture> background_, EFonts Font = FONT_SMALL, ETextAlignment Align = ETextAlignment::CENTER, const SDL_Color & Color = Colors::WHITE);
|
||||
@@ -138,14 +141,17 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void clearIfMatching(const std::string & Text) override;
|
||||
void clear() override;//clears statusbar and refreshes
|
||||
void write(const std::string & Text) override; //prints text and refreshes statusbar
|
||||
|
||||
void show(SDL_Surface * to) override; //shows statusbar (with current text)
|
||||
|
||||
void lock(bool shouldLock) override; //If true, current text cannot be changed until lock(false) is called
|
||||
void setOnClick(std::function<void()> handler);
|
||||
|
||||
void show(SDL_Surface * to) override;
|
||||
|
||||
// IStatusBar interface
|
||||
void write(const std::string & Text) override;
|
||||
void clearIfMatching(const std::string & Text) override;
|
||||
void clear() override;
|
||||
void setEnteringMode(bool on) override;
|
||||
void setEnteredText(const std::string & text) override;
|
||||
|
||||
};
|
||||
|
||||
class CFocusable;
|
||||
|
||||
Reference in New Issue
Block a user