2016-05-04 19:24:41 +02:00
|
|
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
2014-04-25 19:25:34 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
2016-05-04 19:24:41 +02:00
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
2014-04-25 19:25:34 +02:00
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
2014-04-25 19:25:34 +02:00
|
|
|
*****************************************************************************/
|
2016-05-04 19:24:41 +02:00
|
|
|
#pragma endregion
|
2014-04-25 19:25:34 +02:00
|
|
|
|
2014-10-06 18:36:58 +02:00
|
|
|
#include "../audio/audio.h"
|
|
|
|
#include "../interface/widget.h"
|
|
|
|
#include "../interface/window.h"
|
2017-02-18 16:45:10 +01:00
|
|
|
#include "../localisation/localisation.h"
|
|
|
|
#include "../platform/platform.h"
|
2016-11-30 12:07:10 +01:00
|
|
|
#include "../rct2.h"
|
2014-10-06 18:36:58 +02:00
|
|
|
#include "error.h"
|
2014-04-25 19:25:34 +02:00
|
|
|
|
2016-09-03 15:22:03 +02:00
|
|
|
bool gDisableErrorWindowSound = false;
|
|
|
|
|
2014-10-05 03:51:17 +02:00
|
|
|
enum {
|
|
|
|
WIDX_BACKGROUND
|
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_error_widgets[] = {
|
|
|
|
{ WWT_IMGBTN, 0, 0, 199, 0, 41, 0xFFFFFFFF, STR_NONE },
|
|
|
|
{ WIDGETS_END }
|
|
|
|
};
|
|
|
|
|
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 = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
window_error_unknown5,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
window_error_paint,
|
|
|
|
NULL
|
2014-10-05 03:51:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static char _window_error_text[512];
|
|
|
|
static uint16 _window_error_num_lines;
|
|
|
|
|
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
|
|
|
*/
|
2014-10-05 03:51:17 +02:00
|
|
|
void window_error_open(rct_string_id title, rct_string_id message)
|
2014-04-25 19:25:34 +02:00
|
|
|
{
|
2015-07-29 03:03:34 +02:00
|
|
|
utf8 *dst;
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 numLines, fontHeight, x, y, width, height, maxY;
|
2014-10-05 03:51:17 +02:00
|
|
|
rct_window *w;
|
|
|
|
|
2014-10-16 03:02:43 +02:00
|
|
|
window_close_by_class(WC_ERROR);
|
2014-10-05 03:51:17 +02:00
|
|
|
dst = _window_error_text;
|
|
|
|
|
|
|
|
// Format the title
|
2015-07-29 03:03:34 +02:00
|
|
|
dst = utf8_write_codepoint(dst, FORMAT_BLACK);
|
2016-01-07 23:14:53 +01:00
|
|
|
if (title != STR_NONE) {
|
2016-09-26 04:24:29 +02:00
|
|
|
format_string(dst, 512 - (dst - _window_error_text), title, gCommonFormatArgs);
|
2015-07-29 03:03:34 +02:00
|
|
|
dst = get_string_end(dst);
|
2014-10-05 03:51:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Format the message
|
2016-01-07 23:14:53 +01:00
|
|
|
if (message != STR_NONE) {
|
2015-07-29 03:03:34 +02:00
|
|
|
dst = utf8_write_codepoint(dst, FORMAT_NEWLINE);
|
2016-09-26 04:24:29 +02:00
|
|
|
format_string(dst, 512 - (dst - _window_error_text), message, gCommonFormatArgs);
|
2015-07-29 03:03:34 +02:00
|
|
|
dst = get_string_end(dst);
|
2014-10-05 03:51:17 +02:00
|
|
|
}
|
|
|
|
|
2014-11-25 03:05:48 +01:00
|
|
|
log_verbose("show error, %s", _window_error_text + 1);
|
2014-11-20 20:02:27 +01:00
|
|
|
|
2014-10-05 03:51:17 +02:00
|
|
|
// Check if there is any text to display
|
|
|
|
if (dst == _window_error_text + 1)
|
|
|
|
return;
|
|
|
|
|
2016-04-26 00:00:58 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
2014-11-01 14:10:14 +01:00
|
|
|
width = gfx_get_string_width_new_lined(_window_error_text);
|
2014-10-05 03:51:17 +02:00
|
|
|
width = min(196, width);
|
|
|
|
|
2016-04-26 00:00:58 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
2014-10-05 03:51:17 +02:00
|
|
|
gfx_wrap_string(_window_error_text, width + 1, &numLines, &fontHeight);
|
|
|
|
|
|
|
|
_window_error_num_lines = numLines;
|
|
|
|
width = width + 3;
|
|
|
|
height = (numLines + 1) * 10 + 4;
|
|
|
|
|
|
|
|
window_error_widgets[WIDX_BACKGROUND].right = width;
|
|
|
|
window_error_widgets[WIDX_BACKGROUND].bottom = height;
|
|
|
|
|
2016-09-05 23:37:57 +02:00
|
|
|
x = gCursorState.x - (width / 2);
|
2016-04-24 01:36:39 +02:00
|
|
|
x = clamp(0, x, gScreenWidth);
|
2014-10-05 03:51:17 +02:00
|
|
|
|
2016-09-05 23:37:57 +02:00
|
|
|
y = gCursorState.y + 26;
|
2014-10-05 03:51:17 +02:00
|
|
|
y = max(22, y);
|
2016-04-24 01:36:39 +02:00
|
|
|
maxY = gScreenHeight - height;
|
2014-10-05 03:51:17 +02:00
|
|
|
if (y > maxY) {
|
|
|
|
y = y - height - 40;
|
|
|
|
y = min(y, maxY);
|
|
|
|
}
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
w = window_create(x, y, width, height, &window_error_events, WC_ERROR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_RESIZABLE);
|
2014-10-05 03:51:17 +02:00
|
|
|
w->widgets = window_error_widgets;
|
|
|
|
w->error.var_480 = 0;
|
2016-09-03 15:22:03 +02:00
|
|
|
if (!gDisableErrorWindowSound) {
|
2015-11-18 00:05:24 +01:00
|
|
|
audio_play_sound_panned(SOUND_ERROR, 0, w->x + (w->width / 2), 0, 0);
|
2016-09-03 15:22:03 +02:00
|
|
|
}
|
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
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_error_unknown5(rct_window *w)
|
2014-10-05 03:51:17 +02:00
|
|
|
{
|
|
|
|
w->error.var_480++;
|
|
|
|
if (w->error.var_480 >= 8)
|
|
|
|
window_close(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-10-05 03:51:17 +02:00
|
|
|
* rct2: 0x00667AA3
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_error_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2014-10-05 03:51:17 +02:00
|
|
|
{
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 t, l, r, b;
|
2014-10-05 03:51:17 +02:00
|
|
|
|
|
|
|
l = w->x;
|
|
|
|
t = w->y;
|
|
|
|
r = w->x + w->width - 1;
|
|
|
|
b = w->y + w->height - 1;
|
|
|
|
|
2016-11-09 21:44:25 +01:00
|
|
|
gfx_filter_rect(dpi, l + 1, t + 1, r - 1, b - 1, PALETTE_45);
|
2016-11-09 23:40:13 +01:00
|
|
|
gfx_filter_rect(dpi, l, t, r, b, PALETTE_GLASS_SATURATED_RED);
|
2016-11-09 21:44:25 +01:00
|
|
|
|
2016-11-10 00:03:12 +01: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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|