mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: Use realtime for error message and console backlog timeouts
This commit is contained in:
parent
c0d7949d7c
commit
1fb4ed8eef
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue