Title sequence now maintains central position from script if window size changes.
This commit is contained in:
IntelOrca 2015-11-03 19:20:13 +00:00
parent d5688cdc4e
commit 025f36ec28
3 changed files with 42 additions and 12 deletions

View File

@ -31,6 +31,7 @@
#include "../input.h"
#include "../localisation/localisation.h"
#include "../openrct2.h"
#include "../title.h"
#include "../util/util.h"
#include "platform.h"
@ -312,12 +313,14 @@ static void platform_resize(int width, int height)
window_relocate_windows(width, height);
}
title_fix_location();
gfx_invalidate_screen();
// Check if the window has been resized in windowed mode and update the config file accordingly
// This is called in rct2_update_2 and is only called after resizing a window has finished
if ((flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED |
SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)) == 0) {
const int nonWindowFlags =
SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP;
if (!(flags & nonWindowFlags)) {
if (width != gConfigGeneral.window_width || height != gConfigGeneral.window_height) {
gConfigGeneral.window_width = width;
gConfigGeneral.window_height = height;

View File

@ -53,6 +53,7 @@ sint32 gTitleScriptCommand = -1;
uint8 gTitleScriptSave = 0xFF;
sint32 gTitleScriptSkipTo = -1;
sint32 gTitleScriptSkipLoad = -1;
rct_xy16 _titleScriptCurrentCentralPosition = { -1, -1 };
#pragma region Showcase script
@ -222,6 +223,39 @@ static int title_load_park(const char *path)
return 1;
}
/**
* Sets the map location to the given tile coordinates. Z is automatic.
* @param x X position in map tiles.
* @param y Y position in map tiles.
*/
static void title_set_location(int x, int y)
{
int z = map_element_height(x, y);
// Update viewport
rct_window* w = window_get_main();
if (w != NULL) {
window_scroll_to_location(w, x, y, z);
w->flags &= ~WF_SCROLLING_TO_LOCATION;
viewport_update_position(w);
}
// Save known tile position in case of window resize
_titleScriptCurrentCentralPosition.x = (sint16)x;
_titleScriptCurrentCentralPosition.y = (sint16)y;
}
/**
* Re-centres the map location to the last scripted tile position.
*/
void title_fix_location()
{
rct_xy16 position = _titleScriptCurrentCentralPosition;
if (position.x != -1) {
title_set_location(position.x, position.y);
}
}
static void title_skip_opcode()
{
uint8 script_opcode;
@ -255,7 +289,7 @@ static void title_skip_opcode()
static void title_do_next_script_opcode()
{
int i;
short x, y, z;
short x, y;
uint8 script_opcode, script_operand;
rct_window* w;
gTitleScriptCommand++;
@ -295,15 +329,7 @@ static void title_do_next_script_opcode()
case TITLE_SCRIPT_LOCATION:
x = (*_currentScript++) * 32 + 16;
y = (*_currentScript++) * 32 + 16;
z = map_element_height(x, y);
// Update viewport
w = window_get_main();
if (w != NULL) {
window_scroll_to_location(w, x, y, z);
w->flags &= ~WF_SCROLLING_TO_LOCATION;
viewport_update_position(w);
}
title_set_location(x, y);
break;
case TITLE_SCRIPT_ROTATE:
script_operand = (*_currentScript++);

View File

@ -47,6 +47,7 @@ void title_update();
void title_skip_from_beginning();
void title_script_get_line(SDL_RWops *file, char *parts);
bool title_refresh_sequence();
void title_fix_location();
void DrawOpenRCT2(int x, int y);
#endif