Change: Split up Window::OnTick into OnGameTick and OnRealtimeTick. Adjust timers to work with milliseconds instead of ticks.

This commit is contained in:
Peter Nelson
2018-05-04 21:29:22 +01:00
committed by PeterN
parent 916e911806
commit 2a8fa5fef9
21 changed files with 144 additions and 64 deletions

View File

@@ -1978,6 +1978,8 @@ enum MainToolbarHotkeys {
/** Main toolbar. */
struct MainToolbarWindow : Window {
int timer;
MainToolbarWindow(WindowDesc *desc) : Window(desc)
{
this->InitNested(0);
@@ -1988,6 +1990,8 @@ struct MainToolbarWindow : Window {
this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
PositionMainToolbar(this);
DoZoomInOutWindow(ZOOM_NONE, this);
this->timer = MILLISECONDS_PER_TICK;
}
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
@@ -2092,8 +2096,11 @@ struct MainToolbarWindow : Window {
_last_started_action = CBF_NONE;
}
virtual void OnTick()
virtual void OnRealtimeTick(uint delta_ms)
{
if (!TimerElapsed(this->timer, delta_ms)) return;
this->timer = MILLISECONDS_PER_TICK;
if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
this->ToggleWidgetLoweredState(WID_TN_PAUSE);
this->SetWidgetDirty(WID_TN_PAUSE);
@@ -2310,6 +2317,8 @@ enum MainToolbarEditorHotkeys {
};
struct ScenarioEditorToolbarWindow : Window {
int timer;
ScenarioEditorToolbarWindow(WindowDesc *desc) : Window(desc)
{
this->InitNested(0);
@@ -2318,6 +2327,8 @@ struct ScenarioEditorToolbarWindow : Window {
CLRBITS(this->flags, WF_WHITE_BORDER);
PositionMainToolbar(this);
DoZoomInOutWindow(ZOOM_NONE, this);
this->timer = MILLISECONDS_PER_TICK;
}
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
@@ -2445,8 +2456,11 @@ struct ScenarioEditorToolbarWindow : Window {
this->SetWidgetDirty(WID_TE_DATE_FORWARD);
}
virtual void OnTick()
virtual void OnRealtimeTick(uint delta_ms)
{
if (!TimerElapsed(this->timer, delta_ms)) return;
this->timer = MILLISECONDS_PER_TICK;
if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
this->ToggleWidgetLoweredState(WID_TE_PAUSE);
this->SetDirty();