1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Converted timer event into tick event that is called every frame

This commit is contained in:
Ivan Savenko
2023-03-22 23:09:43 +02:00
parent 8af76947cb
commit a8fe8c0f3b
8 changed files with 113 additions and 86 deletions

View File

@@ -254,11 +254,21 @@ void CInfoBar::showSelection()
showGameStatus();//FIXME: may be incorrect but shouldn't happen in general
}
void CInfoBar::tick()
void CInfoBar::tick(uint32_t msPassed)
{
removeUsedEvents(TIME);
if(GH.topInt() == adventureInt)
popComponents(true);
assert(timerCounter > 0);
if (msPassed >= timerCounter)
{
timerCounter = 0;
removeUsedEvents(TIME);
if(GH.topInt() == adventureInt)
popComponents(true);
}
else
{
timerCounter -= msPassed;
}
}
void CInfoBar::clickLeft(tribool down, bool previousState)
@@ -290,6 +300,7 @@ void CInfoBar::hover(bool on)
CInfoBar::CInfoBar(const Rect & position)
: CIntObject(LCLICK | RCLICK | HOVER, position.topLeft()),
timerCounter(0),
state(EMPTY)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@@ -302,6 +313,14 @@ CInfoBar::CInfoBar(const Point & position): CInfoBar(Rect(position.x, position.y
{
}
void CInfoBar::setTimer(uint32_t msToTrigger)
{
if (!(active & TIME))
addUsedEvents(TIME);
timerCounter = msToTrigger;
}
void CInfoBar::showDate()
{
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
@@ -312,7 +331,6 @@ void CInfoBar::showDate()
redraw();
}
void CInfoBar::pushComponents(const std::vector<Component> & components, std::string message, int timer)
{
auto actualPush = [&](const std::vector<Component> & components, std::string message, int timer, size_t max){