2014-04-25 19:25:34 +02:00
|
|
|
/*****************************************************************************
|
2019-03-17 08:16:15 +01:00
|
|
|
* Copyright (c) 2014-2019 OpenRCT2 developers
|
2014-04-25 19:25:34 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2014-04-25 19:25:34 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-04-25 19:25:34 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-08-12 13:50:40 +02:00
|
|
|
#include <algorithm>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-09-06 16:09:35 +02:00
|
|
|
#include <openrct2/Context.h>
|
|
|
|
#include <openrct2/OpenRCT2.h>
|
|
|
|
#include <openrct2/audio/audio.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2018-01-05 22:01:16 +01:00
|
|
|
#include <openrct2/drawing/Font.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2016-09-03 15:22:03 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-10-05 03:51:17 +02:00
|
|
|
enum {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND
|
2014-10-05 03:51:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_error_widgets[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_IMGBTN, 0, 0, 199, 0, 41, 0xFFFFFFFF, STR_NONE },
|
|
|
|
{ WIDGETS_END }
|
2014-10-05 03:51:17 +02:00
|
|
|
};
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_error_unknown5(rct_window *w);
|
|
|
|
static void window_error_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
|
|
|
|
|
|
|
static rct_window_event_list window_error_events = {
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_error_unknown5,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_error_paint,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr
|
2014-10-05 03:51:17 +02:00
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-10-05 03:51:17 +02:00
|
|
|
|
|
|
|
static char _window_error_text[512];
|
2018-06-20 17:28:51 +02:00
|
|
|
static uint16_t _window_error_num_lines;
|
2014-10-05 03:51:17 +02:00
|
|
|
|
2014-04-25 19:25:34 +02:00
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-04-25 19:25:34 +02:00
|
|
|
* rct2: 0x0066792F
|
2014-10-05 03:51:17 +02:00
|
|
|
*
|
|
|
|
* bx: title
|
|
|
|
* dx: message
|
2014-04-25 19:25:34 +02:00
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_error_open(rct_string_id title, rct_string_id message)
|
2014-04-25 19:25:34 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
utf8* dst;
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t numLines, fontHeight, x, y, width, height, maxY;
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* w;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_close_by_class(WC_ERROR);
|
|
|
|
dst = _window_error_text;
|
|
|
|
|
|
|
|
// Format the title
|
|
|
|
dst = utf8_write_codepoint(dst, FORMAT_BLACK);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (title != STR_NONE)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
format_string(dst, 512 - (dst - _window_error_text), title, gCommonFormatArgs);
|
|
|
|
dst = get_string_end(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format the message
|
2018-06-22 23:21:44 +02:00
|
|
|
if (message != STR_NONE)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
dst = utf8_write_codepoint(dst, FORMAT_NEWLINE);
|
|
|
|
format_string(dst, 512 - (dst - _window_error_text), message, gCommonFormatArgs);
|
|
|
|
dst = get_string_end(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("show error, %s", _window_error_text + 1);
|
|
|
|
|
2017-06-12 11:52:04 +02:00
|
|
|
// Don't do unnecessary work in headless. Also saves checking if cursor state is null.
|
2018-06-22 23:21:44 +02:00
|
|
|
if (gOpenRCT2Headless)
|
|
|
|
{
|
2017-09-06 16:09:35 +02:00
|
|
|
return nullptr;
|
2017-06-12 11:52:04 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Check if there is any text to display
|
|
|
|
if (dst == _window_error_text + 1)
|
2017-09-06 16:09:35 +02:00
|
|
|
return nullptr;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
|
|
width = gfx_get_string_width_new_lined(_window_error_text);
|
2018-06-20 17:11:35 +02:00
|
|
|
width = std::min(196, width);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
|
|
gfx_wrap_string(_window_error_text, width + 1, &numLines, &fontHeight);
|
|
|
|
|
|
|
|
_window_error_num_lines = numLines;
|
|
|
|
width = width + 3;
|
2017-10-20 13:12:17 +02:00
|
|
|
height = (numLines + 1) * font_get_line_height(gCurrentFontSpriteBase) + 4;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_error_widgets[WIDX_BACKGROUND].right = width;
|
|
|
|
window_error_widgets[WIDX_BACKGROUND].bottom = height;
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t screenWidth = context_get_width();
|
|
|
|
int32_t screenHeight = context_get_height();
|
2018-06-22 23:21:44 +02:00
|
|
|
const CursorState* state = context_get_cursor_state();
|
2017-06-06 23:24:18 +02:00
|
|
|
x = state->x - (width / 2);
|
2018-08-12 13:50:40 +02:00
|
|
|
x = std::clamp(x, 0, screenWidth);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
y = state->y + 26;
|
2018-06-20 17:11:35 +02:00
|
|
|
y = std::max(22, y);
|
2017-06-06 23:24:18 +02:00
|
|
|
maxY = screenHeight - height;
|
2018-06-22 23:21:44 +02:00
|
|
|
if (y > maxY)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
y = y - height - 40;
|
2018-06-20 17:11:35 +02:00
|
|
|
y = std::min(y, maxY);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
w = window_create(x, y, width, height, &window_error_events, WC_ERROR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_RESIZABLE);
|
|
|
|
w->widgets = window_error_widgets;
|
|
|
|
w->error.var_480 = 0;
|
2018-06-22 23:21:44 +02:00
|
|
|
if (!gDisableErrorWindowSound)
|
|
|
|
{
|
2019-07-22 20:02:45 +02:00
|
|
|
audio_play_sound(SoundId::Error, 0, w->x + (w->width / 2));
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2017-09-06 16:09:35 +02:00
|
|
|
|
|
|
|
return w;
|
2014-10-05 03:51:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-05 03:51:17 +02:00
|
|
|
* rct2: 0x00667BFE
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_error_unknown5(rct_window* w)
|
2014-10-05 03:51:17 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
w->error.var_480++;
|
|
|
|
if (w->error.var_480 >= 8)
|
|
|
|
window_close(w);
|
2014-10-05 03:51:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-05 03:51:17 +02:00
|
|
|
* rct2: 0x00667AA3
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_error_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-10-05 03:51:17 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t t, l, r, b;
|
2014-10-05 03:51:17 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
l = w->x;
|
|
|
|
t = w->y;
|
|
|
|
r = w->x + w->width - 1;
|
|
|
|
b = w->y + w->height - 1;
|
2014-10-05 03:51:17 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_filter_rect(dpi, l + 1, t + 1, r - 1, b - 1, PALETTE_45);
|
|
|
|
gfx_filter_rect(dpi, l, t, r, b, PALETTE_GLASS_SATURATED_RED);
|
2016-11-09 21:44:25 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_filter_rect(dpi, l, t + 2, l, b - 2, PALETTE_DARKEN_3);
|
|
|
|
gfx_filter_rect(dpi, r, t + 2, r, b - 2, PALETTE_DARKEN_3);
|
|
|
|
gfx_filter_rect(dpi, l + 2, b, r - 2, b, PALETTE_DARKEN_3);
|
|
|
|
gfx_filter_rect(dpi, l + 2, t, r - 2, t, PALETTE_DARKEN_3);
|
2016-11-10 00:03:12 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_filter_rect(dpi, r + 1, t + 1, r + 1, t + 1, PALETTE_DARKEN_3);
|
|
|
|
gfx_filter_rect(dpi, r - 1, t + 1, r - 1, t + 1, PALETTE_DARKEN_3);
|
|
|
|
gfx_filter_rect(dpi, l + 1, b - 1, l + 1, b - 1, PALETTE_DARKEN_3);
|
|
|
|
gfx_filter_rect(dpi, r - 1, b - 1, r - 1, b - 1, PALETTE_DARKEN_3);
|
2014-10-05 03:51:17 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
l = w->x + (w->width + 1) / 2 - 1;
|
|
|
|
t = w->y + 1;
|
|
|
|
draw_string_centred_raw(dpi, l, t, _window_error_num_lines, _window_error_text);
|
2015-12-21 05:03:37 +01:00
|
|
|
}
|