2015-06-13 14:30:50 +02:00
|
|
|
#include "../addresses.h"
|
|
|
|
#include "../localisation/localisation.h"
|
2016-01-30 15:00:41 +01:00
|
|
|
#include "../interface/themes.h"
|
2015-06-13 14:30:50 +02:00
|
|
|
#include "../interface/widget.h"
|
|
|
|
#include "../interface/window.h"
|
|
|
|
#include "../interface/viewport.h"
|
2015-06-16 05:34:52 +02:00
|
|
|
#include "../openrct2.h"
|
|
|
|
#include "../platform/platform.h"
|
2016-01-30 15:00:41 +01:00
|
|
|
#include "../util/util.h"
|
|
|
|
#include "../world/footpath.h"
|
|
|
|
#include "../world/map.h"
|
|
|
|
#include "../world/scenery.h"
|
2015-06-13 14:30:50 +02:00
|
|
|
|
|
|
|
enum {
|
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_CONTENT_PANEL,
|
|
|
|
WIDX_SCROLL
|
|
|
|
};
|
|
|
|
|
|
|
|
#define WW 500
|
|
|
|
#define WH 400
|
|
|
|
#define MIN_WW 300
|
|
|
|
#define MIN_WH 200
|
|
|
|
|
|
|
|
rct_widget window_changelog_widgets[] = {
|
|
|
|
{ WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, 0x0FFFFFFFF, STR_NONE }, // panel / background
|
|
|
|
{ WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_CHANGELOG_TITLE, STR_WINDOW_TITLE_TIP }, // title bar
|
|
|
|
{ WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button
|
|
|
|
{ WWT_RESIZE, 1, 0, WW - 1, 14, WH - 1, 0x0FFFFFFFF, STR_NONE }, // content panel
|
|
|
|
{ WWT_SCROLL, 1, 3, WW - 3, 16, WH - 15, 3, STR_NONE }, // scroll area
|
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_close(rct_window *w);
|
|
|
|
static void window_changelog_mouseup(rct_window *w, int widgetIndex);
|
|
|
|
static void window_changelog_resize(rct_window *w);
|
|
|
|
static void window_changelog_scrollgetsize(rct_window *w, int scrollIndex, int *width, int *height);
|
|
|
|
static void window_changelog_invalidate(rct_window *w);
|
|
|
|
static void window_changelog_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
|
|
|
static void window_changelog_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrollIndex);
|
|
|
|
|
|
|
|
static rct_window_event_list window_changelog_events = {
|
2015-06-13 14:30:50 +02:00
|
|
|
window_changelog_close,
|
|
|
|
window_changelog_mouseup,
|
|
|
|
window_changelog_resize,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-06-13 14:30:50 +02:00
|
|
|
window_changelog_scrollgetsize,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-06-13 14:30:50 +02:00
|
|
|
window_changelog_invalidate,
|
|
|
|
window_changelog_paint,
|
|
|
|
window_changelog_scrollpaint
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool window_changelog_read_file();
|
|
|
|
static void window_changelog_dispose_file();
|
|
|
|
|
|
|
|
static char *_changelogText = NULL;
|
|
|
|
static long _changelogTextSize = 0;
|
|
|
|
static char **_changelogLines = NULL;
|
|
|
|
static int _changelogNumLines = 0;
|
|
|
|
static int _changelogLongestLineWidth = 0;
|
|
|
|
|
|
|
|
rct_window *window_changelog_open()
|
|
|
|
{
|
|
|
|
rct_window* window;
|
|
|
|
|
|
|
|
window = window_bring_to_front_by_class(WC_CHANGELOG);
|
|
|
|
if (window != NULL)
|
|
|
|
return window;
|
|
|
|
|
|
|
|
if (!window_changelog_read_file())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int screenWidth = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
|
|
|
int screenHeight = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
|
|
|
|
|
|
|
window = window_create_centred(
|
|
|
|
screenWidth * 4 / 5,
|
|
|
|
screenHeight * 4 / 5,
|
2015-07-10 02:39:16 +02:00
|
|
|
&window_changelog_events,
|
2015-06-13 14:30:50 +02:00
|
|
|
WC_CHANGELOG,
|
2015-06-13 23:16:14 +02:00
|
|
|
WF_RESIZABLE
|
2015-06-13 14:30:50 +02:00
|
|
|
);
|
|
|
|
window->widgets = window_changelog_widgets;
|
|
|
|
window->enabled_widgets = (1 << WIDX_CLOSE);
|
|
|
|
|
|
|
|
window_init_scroll_widgets(window);
|
|
|
|
window->min_width = MIN_WW;
|
|
|
|
window->min_height = MIN_WH;
|
|
|
|
window->max_width = MIN_WW;
|
|
|
|
window->max_height = MIN_WH;
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_close(rct_window *w)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
|
|
|
window_changelog_dispose_file();
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_mouseup(rct_window *w, int widgetIndex)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
|
|
|
switch (widgetIndex) {
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_resize(rct_window *w)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
|
|
|
int screenWidth = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
|
|
|
int screenHeight = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
|
|
|
|
|
|
|
w->max_width = (screenWidth * 4) / 5;
|
|
|
|
w->max_height = (screenHeight * 4) / 5;
|
|
|
|
|
|
|
|
w->min_width = MIN_WW;
|
|
|
|
w->min_height = MIN_WH;
|
|
|
|
if (w->width < w->min_width) {
|
|
|
|
window_invalidate(w);
|
|
|
|
w->width = w->min_width;
|
|
|
|
}
|
|
|
|
if (w->height < w->min_height) {
|
|
|
|
window_invalidate(w);
|
|
|
|
w->height = w->min_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_scrollgetsize(rct_window *w, int scrollIndex, int *width, int *height)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
2015-07-10 02:39:16 +02:00
|
|
|
*width = _changelogLongestLineWidth + 4;
|
|
|
|
*height = _changelogNumLines * 11;
|
2015-06-13 14:30:50 +02:00
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_invalidate(rct_window *w)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
2016-01-30 15:00:41 +01:00
|
|
|
colour_scheme_update(w);
|
|
|
|
|
2015-06-13 14:30:50 +02:00
|
|
|
window_changelog_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
|
|
|
window_changelog_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
|
|
|
|
window_changelog_widgets[WIDX_TITLE].right = w->width - 2;
|
|
|
|
window_changelog_widgets[WIDX_CLOSE].left = w->width - 13;
|
|
|
|
window_changelog_widgets[WIDX_CLOSE].right = w->width - 3;
|
|
|
|
window_changelog_widgets[WIDX_CONTENT_PANEL].right = w->width - 1;
|
|
|
|
window_changelog_widgets[WIDX_CONTENT_PANEL].bottom = w->height - 1;
|
|
|
|
window_changelog_widgets[WIDX_SCROLL].right = w->width - 3;
|
|
|
|
window_changelog_widgets[WIDX_SCROLL].bottom = w->height - 15;
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_changelog_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrollIndex)
|
2015-06-13 14:30:50 +02:00
|
|
|
{
|
|
|
|
uint16 *currentFontFlags = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16);
|
|
|
|
sint16 *currentFontSpriteBase = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, sint16);
|
|
|
|
*currentFontFlags = 0;
|
|
|
|
*currentFontSpriteBase = 224;
|
|
|
|
gfx_draw_string(dpi, (char*)0x009C383D, 1, dpi->x, dpi->y);
|
|
|
|
|
|
|
|
int x = 3;
|
|
|
|
int y = 3;
|
|
|
|
for (int i = 0; i < _changelogNumLines; i++) {
|
|
|
|
gfx_draw_string(dpi, _changelogLines[i], 254, x, y);
|
|
|
|
y += 11;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool window_changelog_read_file()
|
|
|
|
{
|
|
|
|
window_changelog_dispose_file();
|
2015-08-29 14:12:52 +02:00
|
|
|
utf8 path[MAX_PATH];
|
2015-06-16 05:34:52 +02:00
|
|
|
sprintf(path, "%s%cchangelog.txt", gExePath, platform_get_path_separator());
|
2015-09-07 14:57:39 +02:00
|
|
|
if (!readentirefile(path, (void**)&_changelogText, (int*)&_changelogTextSize)) {
|
2015-06-13 14:30:50 +02:00
|
|
|
log_error("Unable to read changelog.txt");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_changelogText = realloc(_changelogText, _changelogTextSize + 1);
|
|
|
|
_changelogText[_changelogTextSize++] = 0;
|
|
|
|
|
|
|
|
char *start = _changelogText;
|
|
|
|
if (_changelogTextSize >= 3 && utf8_is_bom(_changelogText))
|
|
|
|
start += 3;
|
|
|
|
|
|
|
|
int changelogLinesCapacity = 8;
|
|
|
|
_changelogLines = malloc(changelogLinesCapacity * sizeof(char*));
|
|
|
|
_changelogLines[0] = start;
|
|
|
|
_changelogNumLines = 1;
|
|
|
|
|
|
|
|
char *ch = start;
|
|
|
|
while (*ch != 0) {
|
|
|
|
unsigned char c = *ch;
|
|
|
|
if (c == '\n') {
|
2015-06-17 00:27:22 +02:00
|
|
|
*ch++ = 0;
|
2015-06-13 14:30:50 +02:00
|
|
|
_changelogNumLines++;
|
|
|
|
if (_changelogNumLines > changelogLinesCapacity) {
|
|
|
|
changelogLinesCapacity *= 2;
|
|
|
|
_changelogLines = realloc(_changelogLines, changelogLinesCapacity * sizeof(char*));
|
|
|
|
}
|
|
|
|
_changelogLines[_changelogNumLines - 1] = ch;
|
|
|
|
} else if (c < 32 || c > 122) {
|
|
|
|
// A character that won't be drawn or change state.
|
2015-06-17 00:27:22 +02:00
|
|
|
*ch++ = FORMAT_OUTLINE_OFF;
|
|
|
|
} else {
|
|
|
|
ch++;
|
2015-06-13 14:30:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_changelogLines = realloc(_changelogLines, _changelogNumLines * sizeof(char*));
|
|
|
|
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
|
|
|
|
_changelogLongestLineWidth = 0;
|
|
|
|
for (int i = 0; i < _changelogNumLines; i++) {
|
|
|
|
int width = gfx_get_string_width(_changelogLines[i]);
|
|
|
|
_changelogLongestLineWidth = max(width, _changelogLongestLineWidth);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void window_changelog_dispose_file()
|
|
|
|
{
|
|
|
|
SafeFree(_changelogText);
|
|
|
|
SafeFree(_changelogLines);
|
|
|
|
_changelogTextSize = 0;
|
|
|
|
_changelogNumLines = 0;
|
2015-09-07 14:57:39 +02:00
|
|
|
}
|