1
0
Fork 0

Fix #6780: Some windows didn't get updated from OnTick() (#7048)

pull/7053/head
PeterN 2019-01-12 23:23:23 +00:00 committed by Charles Pigott
parent 9aecbac2b4
commit 5ff0c24993
5 changed files with 35 additions and 18 deletions

View File

@ -29,6 +29,7 @@
#include "../widgets/dropdown_func.h" #include "../widgets/dropdown_func.h"
#include "../hotkeys.h" #include "../hotkeys.h"
#include "../core/geometry_func.hpp" #include "../core/geometry_func.hpp"
#include "../guitimer_func.h"
#include "ai.hpp" #include "ai.hpp"
#include "ai_gui.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_increase; ///< Whether we clicked the increase or decrease button.
bool clicked_dropdown; ///< Whether the dropdown is open. bool clicked_dropdown; ///< Whether the dropdown is open.
bool closing_dropdown; ///< True, if the dropdown list is currently closing. 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 clicked_row; ///< The clicked row of settings.
int line_height; ///< Height of a row in the matrix widget. int line_height; ///< Height of a row in the matrix widget.
Scrollbar *vscroll; ///< Cache of the vertical scrollbar. Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
@ -505,7 +506,7 @@ struct AISettingsWindow : public Window {
if (new_val != old_val) { if (new_val != old_val) {
this->ai_config->SetSetting(config_item.name, new_val); this->ai_config->SetSetting(config_item.name, new_val);
this->clicked_button = num; this->clicked_button = num;
this->timeout = 5; this->timeout.SetInterval(150);
} }
} else if (!bool_item && !config_item.complete_labels) { } else if (!bool_item && !config_item.complete_labels) {
/* Display a query box so users can enter a custom value. */ /* 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); 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->clicked_button = -1;
this->SetDirty(); this->SetDirty();
} }

View File

@ -15,9 +15,9 @@
#include "window_gui.h" #include "window_gui.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "strings_func.h" #include "strings_func.h"
#include "debug.h"
#include "console_func.h" #include "console_func.h"
#include "console_type.h" #include "console_type.h"
#include "guitimer_func.h"
#include "widgets/framerate_widget.h" #include "widgets/framerate_widget.h"
@ -295,7 +295,7 @@ static const NWidgetPart _framerate_window_widgets[] = {
struct FramerateWindow : Window { struct FramerateWindow : Window {
bool small; bool small;
uint32 next_update; GUITimer next_update;
struct CachedDecimal { struct CachedDecimal {
StringID strid; StringID strid;
@ -339,21 +339,24 @@ struct FramerateWindow : Window {
this->InitNested(number); this->InitNested(number);
this->small = this->IsShaded(); this->small = this->IsShaded();
this->UpdateData(); 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 */ /* Check if the shaded state has changed, switch caption text if it has */
if (this->small != this->IsShaded()) { if (this->small != this->IsShaded()) {
this->small = this->IsShaded(); this->small = this->IsShaded();
this->GetWidget<NWidgetLeaf>(WID_FRW_CAPTION)->SetDataTip(this->small ? STR_FRAMERATE_CAPTION_SMALL : STR_FRAMERATE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); this->GetWidget<NWidgetLeaf>(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->UpdateData();
this->SetDirty(); 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 { struct FrametimeGraphWindow : Window {
int vertical_scale; ///< number of TIMESTAMP_PRECISION units vertically int vertical_scale; ///< number of TIMESTAMP_PRECISION units vertically
int horizontal_scale; ///< number of half-second units horizontally 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 PerformanceElement element; ///< what element this window renders graph for
Dimension graph_size; ///< size of the main graph area (excluding axis labels) Dimension graph_size; ///< size of the main graph area (excluding axis labels)
@ -537,7 +540,7 @@ struct FrametimeGraphWindow : Window {
this->element = (PerformanceElement)number; this->element = (PerformanceElement)number;
this->horizontal_scale = 4; this->horizontal_scale = 4;
this->vertical_scale = TIMESTAMP_PRECISION / 10; this->vertical_scale = TIMESTAMP_PRECISION / 10;
this->next_scale_update = 0; this->next_scale_update.SetInterval(1);
this->InitNested(number); this->InitNested(number);
} }
@ -649,12 +652,12 @@ struct FrametimeGraphWindow : Window {
this->SelectVerticalScale(peak_value); this->SelectVerticalScale(peak_value);
} }
virtual void OnTick() virtual void OnRealtimeTick(uint delta_ms)
{ {
this->SetDirty(); this->SetDirty();
if (this->next_scale_update < _realtime_tick) { if (this->next_scale_update.Elapsed(delta_ms)) {
this->next_scale_update = _realtime_tick + 500; this->next_scale_update.SetInterval(500);
this->UpdateScale(); this->UpdateScale();
} }
} }

View File

@ -31,6 +31,7 @@
#include "../core/geometry_func.hpp" #include "../core/geometry_func.hpp"
#include "../genworld.h" #include "../genworld.h"
#include "../map_type.h" #include "../map_type.h"
#include "../guitimer_func.h"
#include "../widgets/network_widget.h" #include "../widgets/network_widget.h"
@ -234,6 +235,7 @@ protected:
Scrollbar *vscroll; ///< vertical scrollbar of the list of servers Scrollbar *vscroll; ///< vertical scrollbar of the list of servers
QueryString name_editbox; ///< Client name editbox. QueryString name_editbox; ///< Client name editbox.
QueryString filter_editbox; ///< Editbox for filter on servers QueryString filter_editbox; ///< Editbox for filter on servers
GUITimer requery_timer; ///< Timer for network requery
int lock_offset; ///< Left offset for lock icon. int lock_offset; ///< Left offset for lock icon.
int blot_offset; ///< Left offset for green/yellow/red compatibility icon. int blot_offset; ///< Left offset for green/yellow/red compatibility icon.
@ -480,6 +482,8 @@ public:
this->server = this->last_joined; this->server = this->last_joined;
if (this->last_joined != NULL) NetworkUDPQueryServer(this->last_joined->address); 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.SetListing(this->last_sorting);
this->servers.SetSortFuncs(this->sorter_funcs); this->servers.SetSortFuncs(this->sorter_funcs);
this->servers.SetFilterFuncs(this->filter_funcs); this->servers.SetFilterFuncs(this->filter_funcs);
@ -903,8 +907,11 @@ public:
this->vscroll->SetCapacityFromWidget(this, WID_NG_MATRIX); 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(); NetworkGameListRequery();
} }
}; };

View File

@ -14,6 +14,7 @@
#include "../string_func.h" #include "../string_func.h"
#include "../strings_func.h" #include "../strings_func.h"
#include "../window_func.h" #include "../window_func.h"
#include "../guitimer_func.h"
#include "dropdown_type.h" #include "dropdown_type.h"
#include "dropdown_widget.h" #include "dropdown_widget.h"
@ -97,6 +98,7 @@ struct DropdownWindow : Window {
bool drag_mode; bool drag_mode;
bool instant_close; ///< Close the window when the mouse button is raised. bool instant_close; ///< Close the window when the mouse button is raised.
int scrolling; ///< If non-zero, auto-scroll the item list (one time). 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. Point position; ///< Position of the topleft corner of the window.
Scrollbar *vscroll; Scrollbar *vscroll;
@ -155,6 +157,7 @@ struct DropdownWindow : Window {
this->click_delay = 0; this->click_delay = 0;
this->drag_mode = true; this->drag_mode = true;
this->instant_close = instant_close; this->instant_close = instant_close;
this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
} }
~DropdownWindow() ~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) { if (this->scrolling != 0) {
int pos = this->vscroll->GetPosition(); int pos = this->vscroll->GetPosition();

View File

@ -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() void CallWindowGameTickEvent()
{ {