mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Code review tweaks
This commit is contained in:
@@ -58,7 +58,14 @@ OptionsTab::OptionsTab() : humanPlayers(0)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
auto parseTimerString = [](const std::string & str){
|
//helper function to parse string containing time to integer reflecting time in seconds
|
||||||
|
//assumed that input string can be modified by user, function shall support user's intention
|
||||||
|
// normal: 2:00, 12:30
|
||||||
|
// adding symbol: 2:005 -> 2:05, 2:305 -> 23:05,
|
||||||
|
// adding symbol (>60 seconds): 12:095 -> 129:05
|
||||||
|
// removing symbol: 129:0 -> 12:09, 2:0 -> 0:20, 0:2 -> 0:02
|
||||||
|
auto parseTimerString = [](const std::string & str) -> int
|
||||||
|
{
|
||||||
auto sc = str.find(":");
|
auto sc = str.find(":");
|
||||||
if(sc == std::string::npos)
|
if(sc == std::string::npos)
|
||||||
return str.empty() ? 0 : std::stoi(str);
|
return str.empty() ? 0 : std::stoi(str);
|
||||||
|
@@ -607,7 +607,7 @@ void CTextInput::keyPressed(EShortcut key)
|
|||||||
|
|
||||||
void CTextInput::showPopupWindow(const Point & cursorPosition)
|
void CTextInput::showPopupWindow(const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
if(helpBox.size()) //there is no point to show window with nothing inside...
|
if(!helpBox.empty()) //there is no point to show window with nothing inside...
|
||||||
CRClickPopup::createAndPush(helpBox);
|
CRClickPopup::createAndPush(helpBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,6 +624,11 @@ void CTextInput::setText(const std::string & nText, bool callCb)
|
|||||||
cb(text);
|
cb(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTextInput::setHelpText(const std::string & text)
|
||||||
|
{
|
||||||
|
helpBox = text;
|
||||||
|
}
|
||||||
|
|
||||||
void CTextInput::textInputed(const std::string & enteredText)
|
void CTextInput::textInputed(const std::string & enteredText)
|
||||||
{
|
{
|
||||||
if(!focus)
|
if(!focus)
|
||||||
|
@@ -209,16 +209,16 @@ public:
|
|||||||
class CTextInput : public CLabel, public CFocusable
|
class CTextInput : public CLabel, public CFocusable
|
||||||
{
|
{
|
||||||
std::string newText;
|
std::string newText;
|
||||||
|
std::string helpBox; //for right-click help
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string visibleText() override;
|
std::string visibleText() override;
|
||||||
|
|
||||||
public:
|
|
||||||
std::string helpBox; //for right-click help
|
|
||||||
|
|
||||||
CFunctionList<void(const std::string &)> cb;
|
CFunctionList<void(const std::string &)> cb;
|
||||||
CFunctionList<void(std::string &, const std::string &)> filters;
|
CFunctionList<void(std::string &, const std::string &)> filters;
|
||||||
void setText(const std::string & nText) override;
|
void setText(const std::string & nText) override;
|
||||||
void setText(const std::string & nText, bool callCb);
|
void setText(const std::string & nText, bool callCb);
|
||||||
|
void setHelpText(const std::string &);
|
||||||
|
|
||||||
CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(const std::string &)> & CB);
|
CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(const std::string &)> & CB);
|
||||||
CTextInput(const Rect & Pos, const Point & bgOffset, const std::string & bgName, const CFunctionList<void(const std::string &)> & CB);
|
CTextInput(const Rect & Pos, const Point & bgOffset, const std::string & bgName, const CFunctionList<void(const std::string &)> & CB);
|
||||||
|
Reference in New Issue
Block a user