Codechange: migrate all Window-related timers to the new framework
This means we also say goodbye to GUITimers.
This commit is contained in:

committed by
Patric Stout

parent
5e1bcee39b
commit
1ba4dcc924
@@ -21,6 +21,8 @@
|
||||
#include "window_func.h"
|
||||
#include "console_func.h"
|
||||
#include "window_gui.h"
|
||||
#include "timer/timer.h"
|
||||
#include "timer/timer_window.h"
|
||||
|
||||
#include "widgets/error_widget.h"
|
||||
|
||||
@@ -71,7 +73,7 @@ static WindowDesc _errmsg_face_desc(
|
||||
* @param data The data to copy.
|
||||
*/
|
||||
ErrorMessageData::ErrorMessageData(const ErrorMessageData &data) :
|
||||
display_timer(data.display_timer), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size),
|
||||
is_critical(data.is_critical), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size),
|
||||
summary_msg(data.summary_msg), detailed_msg(data.detailed_msg), extra_msg(data.extra_msg), position(data.position), face(data.face)
|
||||
{
|
||||
memcpy(this->textref_stack, data.textref_stack, sizeof(this->textref_stack));
|
||||
@@ -95,7 +97,7 @@ ErrorMessageData::~ErrorMessageData()
|
||||
* Display an error message in a window.
|
||||
* @param summary_msg General error message showed in first line. Must be valid.
|
||||
* @param detailed_msg Detailed error message showed in second line. Can be INVALID_STRING_ID.
|
||||
* @param duration The amount of time to show this error message.
|
||||
* @param is_critical Whether the error is critical. Critical messages never go away on their own.
|
||||
* @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
|
||||
* @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
|
||||
* @param textref_stack_grffile NewGRF that provides the #TextRefStack for the error message.
|
||||
@@ -103,7 +105,8 @@ ErrorMessageData::~ErrorMessageData()
|
||||
* @param textref_stack Values to put on the #TextRefStack.
|
||||
* @param extra_msg Extra error message showed in third line. Can be INVALID_STRING_ID.
|
||||
*/
|
||||
ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration, int x, int y, const GRFFile *textref_stack_grffile, uint textref_stack_size, const uint32 *textref_stack, StringID extra_msg) :
|
||||
ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg, bool is_critical, int x, int y, const GRFFile *textref_stack_grffile, uint textref_stack_size, const uint32 *textref_stack, StringID extra_msg) :
|
||||
is_critical(is_critical),
|
||||
textref_stack_grffile(textref_stack_grffile),
|
||||
textref_stack_size(textref_stack_size),
|
||||
summary_msg(summary_msg),
|
||||
@@ -120,8 +123,6 @@ ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg,
|
||||
if (textref_stack_size > 0) MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
|
||||
|
||||
assert(summary_msg != INVALID_STRING_ID);
|
||||
|
||||
this->display_timer.SetInterval(duration * 3000);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,11 +188,22 @@ private:
|
||||
uint height_summary; ///< Height of the #summary_msg string in pixels in the #WID_EM_MESSAGE widget.
|
||||
uint height_detailed; ///< Height of the #detailed_msg string in pixels in the #WID_EM_MESSAGE widget.
|
||||
uint height_extra; ///< Height of the #extra_msg string in pixels in the #WID_EM_MESSAGE widget.
|
||||
TimeoutTimer<TimerWindow> display_timeout;
|
||||
|
||||
public:
|
||||
ErrmsgWindow(const ErrorMessageData &data) : Window(data.HasFace() ? &_errmsg_face_desc : &_errmsg_desc), ErrorMessageData(data)
|
||||
ErrmsgWindow(const ErrorMessageData &data) :
|
||||
Window(data.HasFace() ? &_errmsg_face_desc : &_errmsg_desc),
|
||||
ErrorMessageData(data),
|
||||
display_timeout(std::chrono::seconds(3 * _settings_client.gui.errmsg_duration), [this]() {
|
||||
this->Close();
|
||||
})
|
||||
{
|
||||
this->InitNested();
|
||||
|
||||
/* Only start the timeout if the message is not critical. */
|
||||
if (!this->is_critical) {
|
||||
this->display_timeout.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
||||
@@ -316,14 +328,7 @@ public:
|
||||
void OnMouseLoop() override
|
||||
{
|
||||
/* Disallow closing the window too easily, if timeout is disabled */
|
||||
if (_right_button_down && !this->display_timer.HasElapsed()) this->Close();
|
||||
}
|
||||
|
||||
void OnRealtimeTick(uint delta_ms) override
|
||||
{
|
||||
if (this->display_timer.CountElapsed(delta_ms) == 0) return;
|
||||
|
||||
this->Close();
|
||||
if (_right_button_down && !this->is_critical) this->Close();
|
||||
}
|
||||
|
||||
void Close() override
|
||||
@@ -339,7 +344,7 @@ public:
|
||||
*/
|
||||
bool IsCritical()
|
||||
{
|
||||
return this->display_timer.HasElapsed();
|
||||
return this->is_critical;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -428,12 +433,12 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
|
||||
IConsolePrint(wl == WL_WARNING ? CC_WARNING : CC_ERROR, buf);
|
||||
}
|
||||
|
||||
bool no_timeout = wl == WL_CRITICAL;
|
||||
bool is_critical = wl == WL_CRITICAL;
|
||||
|
||||
if (_game_mode == GM_BOOTSTRAP) return;
|
||||
if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return;
|
||||
if (_settings_client.gui.errmsg_duration == 0 && !is_critical) return;
|
||||
|
||||
ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_grffile, textref_stack_size, textref_stack, extra_msg);
|
||||
ErrorMessageData data(summary_msg, detailed_msg, is_critical, x, y, textref_stack_grffile, textref_stack_size, textref_stack, extra_msg);
|
||||
data.CopyOutDParams();
|
||||
|
||||
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
|
||||
|
Reference in New Issue
Block a user