diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/console_gui.cpp | 7 | ||||
-rw-r--r-- | src/error.h | 3 | ||||
-rw-r--r-- | src/error_gui.cpp | 19 |
3 files changed, 17 insertions, 12 deletions
diff --git a/src/console_gui.cpp b/src/console_gui.cpp index c8ad5fbdb..731073866 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -12,6 +12,7 @@ #include "window_gui.h" #include "console_gui.h" #include "console_internal.h" +#include "guitimer_func.h" #include "window_func.h" #include "string_func.h" #include "strings_func.h" @@ -171,6 +172,7 @@ struct IConsoleWindow : Window static int scroll; int line_height; ///< Height of one line of text in the console. int line_offset; + GUITimer truncate_timer; IConsoleWindow() : Window(&_console_window_desc) { @@ -179,6 +181,7 @@ struct IConsoleWindow : Window this->line_offset = GetStringBoundingBox("] ").width + 5; this->InitNested(0); + this->truncate_timer.SetInterval(3000); ResizeWindow(this, _screen.width, _screen.height / 3); } @@ -227,8 +230,10 @@ struct IConsoleWindow : Window } } - void OnHundredthTick() override + void OnRealtimeTick(uint delta_ms) override { + if (this->truncate_timer.CountElapsed(delta_ms) == 0) return; + if (IConsoleLine::Truncate() && (IConsoleWindow::scroll > IConsoleLine::size)) { IConsoleWindow::scroll = std::max(0, IConsoleLine::size - (this->height / this->line_height) + 1); diff --git a/src/error.h b/src/error.h index 8aa8ac225..6dd4b0234 100644 --- a/src/error.h +++ b/src/error.h @@ -13,6 +13,7 @@ #include "strings_type.h" #include "company_type.h" #include "core/geometry_type.hpp" +#include "guitimer_func.h" struct GRFFile; @@ -27,7 +28,7 @@ enum WarningLevel { /** The data of the error message. */ class ErrorMessageData { protected: - uint duration; ///< Length of display of the message. 0 means forever, + GUITimer display_timer; ///< Timer before closing the message. uint64 decode_params[20]; ///< Parameters of the message strings. const char *strings[20]; ///< Copies of raw strings that were used. const GRFFile *textref_stack_grffile; ///< NewGRF that filled the #TextRefStack for the error message. diff --git a/src/error_gui.cpp b/src/error_gui.cpp index f9d88a199..c8594e34a 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -71,7 +71,7 @@ static WindowDesc _errmsg_face_desc( * @param data The data to copy. */ ErrorMessageData::ErrorMessageData(const ErrorMessageData &data) : - duration(data.duration), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size), + display_timer(data.display_timer), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size), summary_msg(data.summary_msg), detailed_msg(data.detailed_msg), position(data.position), face(data.face) { memcpy(this->textref_stack, data.textref_stack, sizeof(this->textref_stack)); @@ -103,7 +103,6 @@ ErrorMessageData::~ErrorMessageData() * @param textref_stack Values to put on the #TextRefStack. */ 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) : - duration(duration), textref_stack_grffile(textref_stack_grffile), textref_stack_size(textref_stack_size), summary_msg(summary_msg), @@ -119,6 +118,8 @@ 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); } /** @@ -297,16 +298,14 @@ public: void OnMouseLoop() override { /* Disallow closing the window too easily, if timeout is disabled */ - if (_right_button_down && this->duration != 0) delete this; + if (_right_button_down && !this->display_timer.HasElapsed()) delete this; } - void OnHundredthTick() override + void OnRealtimeTick(uint delta_ms) override { - /* Timeout enabled? */ - if (this->duration != 0) { - this->duration--; - if (this->duration == 0) delete this; - } + if (this->display_timer.CountElapsed(delta_ms) == 0) return; + + delete this; } ~ErrmsgWindow() @@ -321,7 +320,7 @@ public: */ bool IsCritical() { - return this->duration == 0; + return this->display_timer.HasElapsed(); } }; |