From 5ff0c24993c52546f1809e87a036d1e8f21d6e17 Mon Sep 17 00:00:00 2001 From: PeterN Date: Sat, 12 Jan 2019 23:23:23 +0000 Subject: Fix #6780: Some windows didn't get updated from OnTick() (#7048) --- src/ai/ai_gui.cpp | 9 +++++---- src/framerate_gui.cpp | 25 ++++++++++++++----------- src/network/network_gui.cpp | 9 ++++++++- src/widgets/dropdown.cpp | 8 +++++++- src/window.cpp | 2 +- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 101a97d0a..4b248f5ef 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -29,6 +29,7 @@ #include "../widgets/dropdown_func.h" #include "../hotkeys.h" #include "../core/geometry_func.hpp" +#include "../guitimer_func.h" #include "ai.hpp" #include "ai_gui.hpp" @@ -286,7 +287,7 @@ struct AISettingsWindow : public Window { bool clicked_increase; ///< Whether we clicked the increase or decrease button. bool clicked_dropdown; ///< Whether the dropdown is open. bool closing_dropdown; ///< True, if the dropdown list is currently closing. - int timeout; ///< Timeout for unclicking the button. + GUITimer timeout; ///< Timeout for unclicking the button. int clicked_row; ///< The clicked row of settings. int line_height; ///< Height of a row in the matrix widget. Scrollbar *vscroll; ///< Cache of the vertical scrollbar. @@ -505,7 +506,7 @@ struct AISettingsWindow : public Window { if (new_val != old_val) { this->ai_config->SetSetting(config_item.name, new_val); this->clicked_button = num; - this->timeout = 5; + this->timeout.SetInterval(150); } } else if (!bool_item && !config_item.complete_labels) { /* Display a query box so users can enter a custom value. */ @@ -568,9 +569,9 @@ struct AISettingsWindow : public Window { this->vscroll->SetCapacityFromWidget(this, WID_AIS_BACKGROUND); } - virtual void OnTick() + virtual void OnRealtimeTick(uint delta_ms) { - if (--this->timeout == 0) { + if (this->timeout.Elapsed(delta_ms)) { this->clicked_button = -1; this->SetDirty(); } diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp index 7e8e5f34f..908cf81c0 100644 --- a/src/framerate_gui.cpp +++ b/src/framerate_gui.cpp @@ -15,9 +15,9 @@ #include "window_gui.h" #include "table/sprites.h" #include "strings_func.h" -#include "debug.h" #include "console_func.h" #include "console_type.h" +#include "guitimer_func.h" #include "widgets/framerate_widget.h" @@ -295,7 +295,7 @@ static const NWidgetPart _framerate_window_widgets[] = { struct FramerateWindow : Window { bool small; - uint32 next_update; + GUITimer next_update; struct CachedDecimal { StringID strid; @@ -339,21 +339,24 @@ struct FramerateWindow : Window { this->InitNested(number); this->small = this->IsShaded(); this->UpdateData(); + this->next_update.SetInterval(100); } - virtual void OnTick() + virtual void OnRealtimeTick(uint delta_ms) { + bool elapsed = this->next_update.Elapsed(delta_ms); + /* Check if the shaded state has changed, switch caption text if it has */ if (this->small != this->IsShaded()) { this->small = this->IsShaded(); this->GetWidget(WID_FRW_CAPTION)->SetDataTip(this->small ? STR_FRAMERATE_CAPTION_SMALL : STR_FRAMERATE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); - this->next_update = 0; + elapsed = true; } - if (_realtime_tick >= this->next_update) { + if (elapsed) { this->UpdateData(); this->SetDirty(); - this->next_update = _realtime_tick + 100; + this->next_update.SetInterval(100); } } @@ -527,7 +530,7 @@ static const NWidgetPart _frametime_graph_window_widgets[] = { struct FrametimeGraphWindow : Window { int vertical_scale; ///< number of TIMESTAMP_PRECISION units vertically int horizontal_scale; ///< number of half-second units horizontally - uint32 next_scale_update; ///< realtime tick for next scale update + GUITimer next_scale_update; ///< interval for next scale update PerformanceElement element; ///< what element this window renders graph for Dimension graph_size; ///< size of the main graph area (excluding axis labels) @@ -537,7 +540,7 @@ struct FrametimeGraphWindow : Window { this->element = (PerformanceElement)number; this->horizontal_scale = 4; this->vertical_scale = TIMESTAMP_PRECISION / 10; - this->next_scale_update = 0; + this->next_scale_update.SetInterval(1); this->InitNested(number); } @@ -649,12 +652,12 @@ struct FrametimeGraphWindow : Window { this->SelectVerticalScale(peak_value); } - virtual void OnTick() + virtual void OnRealtimeTick(uint delta_ms) { this->SetDirty(); - if (this->next_scale_update < _realtime_tick) { - this->next_scale_update = _realtime_tick + 500; + if (this->next_scale_update.Elapsed(delta_ms)) { + this->next_scale_update.SetInterval(500); this->UpdateScale(); } } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 3e4a4b050..65ecb3b99 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -31,6 +31,7 @@ #include "../core/geometry_func.hpp" #include "../genworld.h" #include "../map_type.h" +#include "../guitimer_func.h" #include "../widgets/network_widget.h" @@ -234,6 +235,7 @@ protected: Scrollbar *vscroll; ///< vertical scrollbar of the list of servers QueryString name_editbox; ///< Client name editbox. QueryString filter_editbox; ///< Editbox for filter on servers + GUITimer requery_timer; ///< Timer for network requery int lock_offset; ///< Left offset for lock icon. int blot_offset; ///< Left offset for green/yellow/red compatibility icon. @@ -480,6 +482,8 @@ public: this->server = this->last_joined; if (this->last_joined != NULL) NetworkUDPQueryServer(this->last_joined->address); + this->requery_timer.SetInterval(MILLISECONDS_PER_TICK); + this->servers.SetListing(this->last_sorting); this->servers.SetSortFuncs(this->sorter_funcs); this->servers.SetFilterFuncs(this->filter_funcs); @@ -903,8 +907,11 @@ public: this->vscroll->SetCapacityFromWidget(this, WID_NG_MATRIX); } - virtual void OnTick() + virtual void OnRealtimeTick(uint delta_ms) { + if (!this->requery_timer.Elapsed(delta_ms)) return; + this->requery_timer.SetInterval(MILLISECONDS_PER_TICK); + NetworkGameListRequery(); } }; diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index f8ddf5569..816e981a1 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -14,6 +14,7 @@ #include "../string_func.h" #include "../strings_func.h" #include "../window_func.h" +#include "../guitimer_func.h" #include "dropdown_type.h" #include "dropdown_widget.h" @@ -97,6 +98,7 @@ struct DropdownWindow : Window { bool drag_mode; bool instant_close; ///< Close the window when the mouse button is raised. int scrolling; ///< If non-zero, auto-scroll the item list (one time). + GUITimer scrolling_timer; ///< Timer for auto-scroll of the item list. Point position; ///< Position of the topleft corner of the window. Scrollbar *vscroll; @@ -155,6 +157,7 @@ struct DropdownWindow : Window { this->click_delay = 0; this->drag_mode = true; this->instant_close = instant_close; + this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK); } ~DropdownWindow() @@ -254,8 +257,11 @@ struct DropdownWindow : Window { } } - virtual void OnTick() + virtual void OnRealtimeTick(uint delta_ms) { + if (!this->scrolling_timer.Elapsed(delta_ms)) return; + this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK); + if (this->scrolling != 0) { int pos = this->vscroll->GetPosition(); diff --git a/src/window.cpp b/src/window.cpp index 7a7a2a182..cd7511353 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -3304,7 +3304,7 @@ void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope) } /** - * Dispatch OnTick event over all windows + * Dispatch OnGameTick event over all windows */ void CallWindowGameTickEvent() { -- cgit v1.2.3-70-g09d2