2015-02-14 03:16:03 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (c) 2014 Ted John
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* This file is part of OpenRCT2.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-10-20 20:16:30 +02:00
|
|
|
#include <time.h>
|
2015-02-14 03:16:03 +01:00
|
|
|
#include "../addresses.h"
|
|
|
|
#include "../config.h"
|
|
|
|
#include "../game.h"
|
|
|
|
#include "../editor.h"
|
|
|
|
#include "../interface/widget.h"
|
|
|
|
#include "../interface/window.h"
|
|
|
|
#include "../localisation/localisation.h"
|
2015-08-16 18:29:47 +02:00
|
|
|
#include "../network/network.h"
|
2015-02-14 03:16:03 +01:00
|
|
|
#include "../scenario.h"
|
|
|
|
#include "../title.h"
|
|
|
|
#include "../windows/error.h"
|
2015-06-01 17:02:09 +02:00
|
|
|
#include "../interface/themes.h"
|
2015-06-24 18:22:12 +02:00
|
|
|
#include "../interface/title_sequences.h"
|
2015-06-07 00:59:46 +02:00
|
|
|
#include "../util/util.h"
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
#pragma region Widgets
|
|
|
|
|
|
|
|
#define WW 340
|
|
|
|
#define WH 400
|
|
|
|
|
|
|
|
enum {
|
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
2015-11-09 05:35:13 +01:00
|
|
|
WIDX_UP,
|
|
|
|
WIDX_NEW,
|
2015-06-22 13:49:35 +02:00
|
|
|
WIDX_SORT_NAME,
|
|
|
|
WIDX_SORT_DATE,
|
2015-02-14 23:22:44 +01:00
|
|
|
WIDX_SCROLL,
|
2015-02-15 19:48:25 +01:00
|
|
|
WIDX_BROWSE,
|
2015-02-14 03:16:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// 0x9DE48C
|
|
|
|
static rct_widget window_loadsave_widgets[] = {
|
2015-06-22 13:49:35 +02:00
|
|
|
{ WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE },
|
|
|
|
{ WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_NONE, STR_WINDOW_TITLE_TIP },
|
2015-11-09 05:35:13 +01:00
|
|
|
{ WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, //Window close button
|
|
|
|
{ WWT_CLOSEBOX, 0, 4, 104, 36, 47, 2718, STR_NONE}, // Up
|
|
|
|
{ WWT_CLOSEBOX, 0, 105, 205, 36, 47, 2719, STR_NONE}, // New
|
|
|
|
{ WWT_CLOSEBOX, 0, 4, (WW - 5) / 2, 50, 61, STR_NONE, STR_NONE }, // Name
|
|
|
|
{ WWT_CLOSEBOX, 0, (WW - 5) / 2 + 1, WW - 5 - 1, 50, 61, STR_NONE, STR_NONE }, // Date
|
|
|
|
{ WWT_SCROLL, 0, 4, WW - 5, 61, WH - 40, 2, STR_NONE }, // File list
|
2015-06-22 13:49:35 +02:00
|
|
|
{ WWT_CLOSEBOX, 0, 4, 200, WH - 36, WH - 18, 2707, STR_NONE }, // Use native browser
|
2015-02-14 03:16:03 +01:00
|
|
|
{ WIDGETS_END }
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region Events
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_close(rct_window *w);
|
|
|
|
static void window_loadsave_mouseup(rct_window *w, int widgetIndex);
|
2015-02-14 03:16:03 +01:00
|
|
|
static void window_loadsave_update(rct_window *w);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_scrollgetsize(rct_window *w, int scrollIndex, int *width, int *height);
|
|
|
|
static void window_loadsave_scrollmousedown(rct_window *w, int scrollIndex, int x, int y);
|
|
|
|
static void window_loadsave_scrollmouseover(rct_window *w, int scrollIndex, int x, int y);
|
|
|
|
static void window_loadsave_textinput(rct_window *w, int widgetIndex, char *text);
|
|
|
|
static void window_loadsave_tooltip(rct_window* w, int widgetIndex, rct_string_id *stringId);
|
|
|
|
static void window_loadsave_invalidate(rct_window *w);
|
|
|
|
static void window_loadsave_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
|
|
|
static void window_loadsave_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrollIndex);
|
|
|
|
|
|
|
|
static rct_window_event_list window_loadsave_events = {
|
2015-02-14 03:16:03 +01:00
|
|
|
window_loadsave_close,
|
|
|
|
window_loadsave_mouseup,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-02-14 03:16:03 +01:00
|
|
|
window_loadsave_scrollgetsize,
|
|
|
|
window_loadsave_scrollmousedown,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
2015-02-14 03:16:03 +01:00
|
|
|
window_loadsave_scrollmouseover,
|
|
|
|
window_loadsave_textinput,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-02-14 03:16:03 +01:00
|
|
|
window_loadsave_tooltip,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-05-29 18:04:53 +02:00
|
|
|
window_loadsave_invalidate,
|
2015-02-14 03:16:03 +01:00
|
|
|
window_loadsave_paint,
|
|
|
|
window_loadsave_scrollpaint
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2015-06-22 13:49:35 +02:00
|
|
|
enum {
|
|
|
|
TYPE_DIRECTORY,
|
|
|
|
TYPE_FILE,
|
|
|
|
};
|
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
typedef struct {
|
|
|
|
char name[256];
|
|
|
|
char path[MAX_PATH];
|
2015-06-22 13:49:35 +02:00
|
|
|
time_t date_modified;
|
|
|
|
uint8 type;
|
2015-02-14 03:16:03 +01:00
|
|
|
} loadsave_list_item;
|
|
|
|
|
2015-11-02 21:43:55 +01:00
|
|
|
modal_callback gLoadSaveCallback;
|
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
int _listItemsCount = 0;
|
|
|
|
loadsave_list_item *_listItems = NULL;
|
|
|
|
char _directory[MAX_PATH];
|
2015-06-20 16:31:06 +02:00
|
|
|
char _shortenedDirectory[MAX_PATH];
|
2015-11-09 05:35:13 +01:00
|
|
|
static char _parentDirectory[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
char _extension[32];
|
2015-11-11 22:37:26 +01:00
|
|
|
char _defaultName[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
int _loadsaveType;
|
2015-02-14 22:59:58 +01:00
|
|
|
int _type;
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension);
|
2015-02-14 03:16:03 +01:00
|
|
|
static void window_loadsave_select(rct_window *w, const char *path);
|
2015-06-22 13:49:35 +02:00
|
|
|
static void window_loadsave_sort_list(int index, int endIndex);
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-06-14 13:03:32 +02:00
|
|
|
static int has_extension(char *path, char *extension);
|
2015-02-15 19:48:25 +01:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
static rct_window *window_overwrite_prompt_open(const char *name, const char *path);
|
|
|
|
|
2015-06-08 00:12:17 +02:00
|
|
|
rct_window *window_loadsave_open(int type, char *defaultName)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-11-02 21:43:55 +01:00
|
|
|
gLoadSaveCallback = NULL;
|
2015-06-24 18:22:12 +02:00
|
|
|
gLoadSaveTitleSequenceSave = false;
|
2015-02-14 03:16:03 +01:00
|
|
|
char path[MAX_PATH], *ch;
|
|
|
|
int includeNewItem;
|
|
|
|
rct_window* w;
|
2015-02-14 22:59:58 +01:00
|
|
|
_type = type;
|
2016-01-04 23:41:18 +01:00
|
|
|
_defaultName[0] = '\0';
|
2015-11-11 22:37:26 +01:00
|
|
|
|
|
|
|
if (!str_is_null_or_empty(defaultName)) {
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(_defaultName, defaultName, sizeof(_defaultName));
|
2015-11-11 22:37:26 +01:00
|
|
|
}
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
w = window_bring_to_front_by_class(WC_LOADSAVE);
|
|
|
|
if (w == NULL) {
|
2015-07-10 02:39:16 +02:00
|
|
|
w = window_create_centred(WW, WH, &window_loadsave_events, WC_LOADSAVE, WF_STICK_TO_FRONT);
|
2015-02-14 03:16:03 +01:00
|
|
|
w->widgets = window_loadsave_widgets;
|
2015-11-09 05:35:13 +01:00
|
|
|
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_UP) | (1 << WIDX_NEW) | (1 << WIDX_SORT_NAME) | (1 << WIDX_SORT_DATE) | (1 << WIDX_BROWSE);
|
2015-02-14 03:16:03 +01:00
|
|
|
w->colours[0] = 7;
|
|
|
|
w->colours[1] = 7;
|
|
|
|
w->colours[2] = 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadsaveType = type;
|
2015-08-16 17:36:57 +02:00
|
|
|
switch (type & 0x0F) {
|
2015-02-14 03:16:03 +01:00
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME):
|
|
|
|
w->widgets[WIDX_TITLE].image = STR_LOAD_GAME;
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME) :
|
|
|
|
w->widgets[WIDX_TITLE].image = STR_SAVE_GAME;
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE) :
|
|
|
|
w->widgets[WIDX_TITLE].image = STR_LOAD_LANDSCAPE;
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE) :
|
|
|
|
w->widgets[WIDX_TITLE].image = STR_SAVE_LANDSCAPE;
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO) :
|
|
|
|
w->widgets[WIDX_TITLE].image = STR_SAVE_SCENARIO;
|
|
|
|
break;
|
2015-04-02 23:00:59 +02:00
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK) :
|
|
|
|
w->widgets[WIDX_TITLE].image = 1039;
|
|
|
|
break;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-02-14 22:59:58 +01:00
|
|
|
w->no_list_items = 0;
|
|
|
|
w->selected_list_item = -1;
|
|
|
|
|
2015-08-16 17:36:57 +02:00
|
|
|
includeNewItem = (type & 0x01) == LOADSAVETYPE_SAVE;
|
|
|
|
switch (type & 0x0E) {
|
2015-02-14 03:16:03 +01:00
|
|
|
case LOADSAVETYPE_GAME:
|
|
|
|
platform_get_user_directory(path, "save");
|
|
|
|
if (!platform_ensure_directory_exists(path)) {
|
2015-06-14 13:03:32 +02:00
|
|
|
log_error("Unable to create save directory.");
|
2015-02-14 03:16:03 +01:00
|
|
|
window_close(w);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
window_loadsave_populate_list(w, includeNewItem, path, ".sv6");
|
2015-02-14 03:16:03 +01:00
|
|
|
break;
|
|
|
|
case LOADSAVETYPE_LANDSCAPE:
|
|
|
|
platform_get_user_directory(path, "landscape");
|
|
|
|
if (!platform_ensure_directory_exists(path)) {
|
2015-06-14 13:03:32 +02:00
|
|
|
log_error("Unable to create landscapes directory.");
|
2015-02-14 03:16:03 +01:00
|
|
|
window_close(w);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
window_loadsave_populate_list(w, includeNewItem, path, ".sc6");
|
2015-02-14 03:16:03 +01:00
|
|
|
break;
|
|
|
|
case LOADSAVETYPE_SCENARIO:
|
|
|
|
platform_get_user_directory(path, "scenario");
|
|
|
|
if (!platform_ensure_directory_exists(path)) {
|
2016-01-01 03:18:06 +01:00
|
|
|
log_error("Unable to create scenarios directory.");
|
|
|
|
window_close(w);
|
|
|
|
return NULL;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
window_loadsave_populate_list(w, includeNewItem, path, ".sc6");
|
2015-02-14 03:16:03 +01:00
|
|
|
break;
|
2015-04-02 23:00:59 +02:00
|
|
|
case LOADSAVETYPE_TRACK:
|
|
|
|
/*
|
|
|
|
Uncomment when user tracks are separated
|
|
|
|
|
|
|
|
platform_get_user_directory(path, "tracks");
|
|
|
|
if (!platform_ensure_directory_exists(path)) {
|
2015-06-14 13:03:32 +02:00
|
|
|
log_error("Unable to create tracks directory.");
|
2015-04-02 23:00:59 +02:00
|
|
|
window_close(w);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(path, RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), MAX_PATH);
|
2015-04-02 23:00:59 +02:00
|
|
|
ch = strchr(path, '*');
|
|
|
|
if (ch != NULL)
|
|
|
|
*ch = 0;
|
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
window_loadsave_populate_list(w, includeNewItem, path, ".td?");
|
2015-04-02 23:00:59 +02:00
|
|
|
break;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
w->no_list_items = _listItemsCount;
|
2015-02-15 16:35:30 +01:00
|
|
|
window_init_scroll_widgets(w);
|
2015-02-14 03:16:03 +01:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_close(rct_window *w)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
|
|
|
if (_listItems != NULL) {
|
|
|
|
free(_listItems);
|
|
|
|
_listItems = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_close_by_class(WC_LOADSAVE_OVERWRITE_PROMPT);
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_mouseup(rct_window *w, int widgetIndex)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-06-14 13:03:32 +02:00
|
|
|
int result;
|
2015-11-29 19:59:15 +01:00
|
|
|
char path[MAX_PATH], filter[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
switch (widgetIndex){
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
2015-11-09 05:35:13 +01:00
|
|
|
case WIDX_UP:
|
|
|
|
{
|
|
|
|
char directory[MAX_PATH];
|
|
|
|
int includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE;
|
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(directory, _parentDirectory, sizeof(directory));
|
2015-11-09 05:35:13 +01:00
|
|
|
window_loadsave_populate_list(w, includeNewItem, directory, _extension);
|
|
|
|
window_init_scroll_widgets(w);
|
|
|
|
w->no_list_items = _listItemsCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIDX_NEW:
|
|
|
|
{
|
|
|
|
rct_string_id templateStringId = 3165;
|
|
|
|
char *templateString;
|
|
|
|
|
|
|
|
templateString = (char *)language_get_string(templateStringId);
|
|
|
|
strcpy(templateString, _defaultName);
|
|
|
|
window_text_input_open(w, WIDX_NEW, STR_NONE, 2710, templateStringId, 0, 64);
|
|
|
|
break;
|
|
|
|
}
|
2015-02-15 19:48:25 +01:00
|
|
|
case WIDX_BROWSE:
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(path, _directory, MAX_PATH);
|
2016-01-02 23:41:35 +01:00
|
|
|
if (_type & LOADSAVETYPE_SAVE) {
|
|
|
|
strcat(path, _defaultName);
|
|
|
|
}
|
2015-06-14 13:03:32 +02:00
|
|
|
|
2015-02-15 19:48:25 +01:00
|
|
|
memset(filter, '\0', MAX_PATH);
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(filter, "*", MAX_PATH);
|
2015-12-31 09:16:44 +01:00
|
|
|
strncat(filter, _extension, MAX_PATH - strnlen(filter, MAX_PATH) - 1);
|
2015-02-15 19:48:25 +01:00
|
|
|
|
|
|
|
switch (_type) {
|
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME) :
|
2016-01-29 18:40:42 +01:00
|
|
|
result = platform_open_common_file_dialog(FD_OPEN, (char*)language_get_string(STR_LOAD_GAME), path, filter, _extension);
|
2015-02-15 19:48:25 +01:00
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME) :
|
2016-01-29 18:40:42 +01:00
|
|
|
result = platform_open_common_file_dialog(FD_SAVE, (char*)language_get_string(STR_SAVE_GAME), path, filter, _extension);
|
2015-02-15 19:48:25 +01:00
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE) :
|
2016-01-29 18:40:42 +01:00
|
|
|
result = platform_open_common_file_dialog(FD_OPEN, (char*)language_get_string(STR_LOAD_LANDSCAPE), path, filter, _extension);
|
2015-02-15 19:48:25 +01:00
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE) :
|
2016-01-29 18:40:42 +01:00
|
|
|
result = platform_open_common_file_dialog(FD_SAVE, (char*)language_get_string(STR_SAVE_LANDSCAPE), path, filter, _extension);
|
2015-02-15 19:48:25 +01:00
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO) :
|
2016-01-29 18:40:42 +01:00
|
|
|
result = platform_open_common_file_dialog(FD_SAVE, (char*)language_get_string(STR_SAVE_SCENARIO), path, filter, _extension);
|
2015-02-15 19:48:25 +01:00
|
|
|
break;
|
2015-04-02 23:00:59 +02:00
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK) :
|
2016-01-29 18:40:42 +01:00
|
|
|
result = platform_open_common_file_dialog(FD_OPEN, (char*)language_get_string(1039), path, filter, _extension);
|
2015-04-02 23:00:59 +02:00
|
|
|
break;
|
2015-02-15 19:48:25 +01:00
|
|
|
}
|
2015-06-14 13:03:32 +02:00
|
|
|
|
|
|
|
if (result) {
|
2015-11-29 19:59:15 +01:00
|
|
|
window_loadsave_select(w, path);
|
2015-02-15 19:48:25 +01:00
|
|
|
}
|
|
|
|
break;
|
2015-06-22 13:49:35 +02:00
|
|
|
case WIDX_SORT_NAME:
|
|
|
|
if (gConfigGeneral.load_save_sort == SORT_NAME_ASCENDING){
|
|
|
|
gConfigGeneral.load_save_sort = SORT_NAME_DESCENDING;
|
|
|
|
} else {
|
|
|
|
gConfigGeneral.load_save_sort = SORT_NAME_ASCENDING;
|
|
|
|
}
|
|
|
|
config_save_default();
|
|
|
|
window_loadsave_sort_list(0, _listItemsCount - 1);
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
|
|
|
case WIDX_SORT_DATE:
|
|
|
|
if (gConfigGeneral.load_save_sort == SORT_DATE_DESCENDING){
|
|
|
|
gConfigGeneral.load_save_sort = SORT_DATE_ASCENDING;
|
|
|
|
} else {
|
|
|
|
gConfigGeneral.load_save_sort = SORT_DATE_DESCENDING;
|
|
|
|
}
|
|
|
|
config_save_default();
|
|
|
|
window_loadsave_sort_list(0, _listItemsCount - 1);
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
2015-02-15 19:48:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-14 13:03:32 +02:00
|
|
|
static int has_extension(char *path, char *extension)
|
2015-02-15 19:48:25 +01:00
|
|
|
{
|
|
|
|
int extensionLength = strlen(extension);
|
|
|
|
int pathLength = strlen(path);
|
2015-06-14 13:03:32 +02:00
|
|
|
for (int u = 0; u < extensionLength; u++) {
|
2015-02-15 19:48:25 +01:00
|
|
|
if (tolower(path[pathLength - extensionLength + u]) != tolower(extension[u]))
|
|
|
|
return 0;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
2015-02-15 19:48:25 +01:00
|
|
|
return 1;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_scrollgetsize(rct_window *w, int scrollIndex, int *width, int *height)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-07-10 02:39:16 +02:00
|
|
|
*height = w->no_list_items * 10;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_scrollmousedown(rct_window *w, int scrollIndex, int x, int y)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
|
|
|
int selectedItem;
|
|
|
|
|
|
|
|
selectedItem = y / 10;
|
|
|
|
if (selectedItem >= w->no_list_items)
|
|
|
|
return;
|
2015-11-09 05:35:13 +01:00
|
|
|
if (_listItems[selectedItem].type == TYPE_DIRECTORY){
|
|
|
|
// The selected item is a folder
|
|
|
|
int includeNewItem;
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
w->no_list_items = 0;
|
|
|
|
w->selected_list_item = -1;
|
|
|
|
includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE;
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
char directory[MAX_PATH];
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(directory, _listItems[selectedItem].path, sizeof(directory));
|
2015-02-14 23:22:44 +01:00
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
window_loadsave_populate_list(w, includeNewItem, directory, _extension);
|
|
|
|
window_init_scroll_widgets(w);
|
2015-02-14 23:22:44 +01:00
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
w->no_list_items = _listItemsCount;
|
|
|
|
} else {
|
|
|
|
// TYPE_FILE
|
|
|
|
// Load or overwrite
|
|
|
|
if ((_loadsaveType & 0x01) == LOADSAVETYPE_SAVE)
|
|
|
|
window_overwrite_prompt_open(_listItems[selectedItem].name, _listItems[selectedItem].path);
|
|
|
|
else
|
|
|
|
window_loadsave_select(w, _listItems[selectedItem].path);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_scrollmouseover(rct_window *w, int scrollIndex, int x, int y)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
|
|
|
int selectedItem;
|
|
|
|
|
|
|
|
selectedItem = y / 10;
|
|
|
|
if (selectedItem >= w->no_list_items)
|
|
|
|
return;
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
w->selected_list_item = selectedItem;
|
|
|
|
|
|
|
|
window_invalidate(w);
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_textinput(rct_window *w, int widgetIndex, char *text)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-07-10 02:39:16 +02:00
|
|
|
char path[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
int i, overwrite;
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
if (text == NULL || text[0] == 0)
|
2015-02-14 03:16:03 +01:00
|
|
|
return;
|
|
|
|
|
2015-06-24 18:22:12 +02:00
|
|
|
if (gLoadSaveTitleSequenceSave) {
|
|
|
|
if (filename_valid_characters(text)) {
|
|
|
|
if (!title_sequence_save_exists(gCurrentTitleSequence, text)) {
|
|
|
|
title_sequence_add_save(gCurrentTitleSequence, path, text);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
window_error_open(5404, STR_NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
window_error_open(5243, STR_NONE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(path, _directory, sizeof(path));
|
2015-09-07 00:46:54 +02:00
|
|
|
strncat(path, text, sizeof(path) - strnlen(path, MAX_PATH) - 1);
|
|
|
|
strncat(path, _extension, sizeof(path) - strnlen(path, MAX_PATH) - 1);
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
overwrite = 0;
|
|
|
|
for (i = 0; i < _listItemsCount; i++) {
|
|
|
|
if (_stricmp(_listItems[i].path, path) == 0) {
|
|
|
|
overwrite = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (overwrite)
|
|
|
|
window_overwrite_prompt_open(text, path);
|
|
|
|
else
|
|
|
|
window_loadsave_select(w, path);
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_tooltip(rct_window* w, int widgetIndex, rct_string_id *stringId)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-10-28 11:44:08 +01:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = STR_LIST;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_invalidate(rct_window *w)
|
2015-05-29 18:04:53 +02:00
|
|
|
{
|
|
|
|
colour_scheme_update(w);
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
|
|
|
window_draw_widgets(w, dpi);
|
2015-02-15 15:20:19 +01:00
|
|
|
|
2016-01-02 23:41:35 +01:00
|
|
|
if (_shortenedDirectory[0] == '\0') {
|
|
|
|
shorten_path(_shortenedDirectory, sizeof(_shortenedDirectory), _directory, w->width - 8);
|
|
|
|
}
|
2015-06-20 16:31:06 +02:00
|
|
|
|
2015-07-31 02:15:35 +02:00
|
|
|
utf8 buffer[256];
|
|
|
|
|
2015-02-15 15:20:19 +01:00
|
|
|
// Format text
|
2015-07-31 02:15:35 +02:00
|
|
|
utf8 *ch = buffer;
|
|
|
|
ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT);
|
|
|
|
ch = utf8_write_codepoint(ch, FORMAT_BLACK);
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(ch, _shortenedDirectory, sizeof(buffer) - (ch - buffer));
|
2015-07-31 02:15:35 +02:00
|
|
|
|
2015-02-15 15:20:19 +01:00
|
|
|
// Draw shadow
|
|
|
|
gfx_draw_string(dpi, buffer, 0, w->x + 4, w->y + 20);
|
2015-06-22 13:49:35 +02:00
|
|
|
rct_string_id id = STR_NONE;
|
2015-11-09 05:35:13 +01:00
|
|
|
// Name button text
|
2015-06-22 13:49:35 +02:00
|
|
|
if (gConfigGeneral.load_save_sort == SORT_NAME_ASCENDING)
|
|
|
|
id = STR_UP;
|
|
|
|
else if (gConfigGeneral.load_save_sort == SORT_NAME_DESCENDING)
|
|
|
|
id = STR_DOWN;
|
2015-11-09 05:35:13 +01:00
|
|
|
gfx_draw_string_centred_clipped(dpi, STR_NAME, &id, 1, w->x + 4 + (w->width - 8) / 4, w->y + 50, (w->width - 8) / 2);
|
|
|
|
// Date button text
|
2015-06-22 13:49:35 +02:00
|
|
|
if (gConfigGeneral.load_save_sort == SORT_DATE_ASCENDING)
|
|
|
|
id = STR_UP;
|
|
|
|
else if (gConfigGeneral.load_save_sort == SORT_DATE_DESCENDING)
|
|
|
|
id = STR_DOWN;
|
|
|
|
else
|
|
|
|
id = STR_NONE;
|
2015-11-09 05:35:13 +01:00
|
|
|
gfx_draw_string_centred_clipped(dpi, STR_DATE, &id, 1, w->x + 4 + (w->width - 8) * 3 / 4, w->y + 50, (w->width - 8) / 2);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_loadsave_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrollIndex)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
|
|
|
int i, y;
|
|
|
|
rct_string_id stringId, templateStringId = 3165;
|
|
|
|
char *templateString;
|
|
|
|
|
2015-11-08 19:55:32 +01:00
|
|
|
gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, ColourMapA[w->colours[1]].mid_light);
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
templateString = (char*)language_get_string(templateStringId);
|
|
|
|
for (i = 0; i < w->no_list_items; i++) {
|
|
|
|
y = i * 10;
|
|
|
|
if (y > dpi->y + dpi->height)
|
|
|
|
break;
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
if (y + 10 < dpi->y)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stringId = STR_BLACK_STRING;
|
|
|
|
if (i == w->selected_list_item) {
|
|
|
|
stringId = STR_WINDOW_COLOUR_2_STRING;
|
|
|
|
gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(templateString, _listItems[i].name);
|
|
|
|
gfx_draw_string_left(dpi, stringId, &templateStringId, 0, 0, y - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-15 16:35:30 +01:00
|
|
|
static int list_item_sort(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const loadsave_list_item *itemA = (loadsave_list_item*)a;
|
|
|
|
const loadsave_list_item *itemB = (loadsave_list_item*)b;
|
|
|
|
|
2015-06-22 13:49:35 +02:00
|
|
|
if (itemA->type != itemB->type)
|
|
|
|
return itemA->type - itemB->type;
|
|
|
|
|
|
|
|
switch (gConfigGeneral.load_save_sort){
|
|
|
|
case SORT_NAME_ASCENDING:
|
2015-12-01 12:03:34 +01:00
|
|
|
return strcicmp(itemA->name, itemB->name);
|
2015-06-22 13:49:35 +02:00
|
|
|
case SORT_NAME_DESCENDING:
|
2015-12-01 12:03:34 +01:00
|
|
|
return -strcicmp(itemA->name, itemB->name);
|
2015-06-22 13:49:35 +02:00
|
|
|
case SORT_DATE_DESCENDING:
|
|
|
|
return (int) -difftime(itemA->date_modified, itemB->date_modified);
|
|
|
|
case SORT_DATE_ASCENDING:
|
|
|
|
return (int) difftime(itemA->date_modified, itemB->date_modified);
|
|
|
|
default:
|
2015-12-01 12:03:34 +01:00
|
|
|
return strcicmp(itemA->name, itemB->name);
|
2015-06-22 13:49:35 +02:00
|
|
|
}
|
2015-02-15 16:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void window_loadsave_sort_list(int index, int endIndex)
|
|
|
|
{
|
|
|
|
int count = endIndex - index + 1;
|
|
|
|
if (count < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
qsort(_listItems + index, count, sizeof(loadsave_list_item), list_item_sort);
|
|
|
|
}
|
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-11-09 05:35:13 +01:00
|
|
|
int i;
|
|
|
|
int sortStartIndex = 0;
|
|
|
|
int listItemCapacity = 8;
|
2015-02-14 03:16:03 +01:00
|
|
|
loadsave_list_item *listItem;
|
2015-11-09 05:35:13 +01:00
|
|
|
char filter[MAX_PATH];
|
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(_directory, directory, sizeof(_directory));
|
2015-10-23 17:22:31 +02:00
|
|
|
if (_extension != extension) {
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(_extension, extension, sizeof(_extension));
|
2015-10-24 23:52:12 +02:00
|
|
|
_extension[sizeof(_extension) - 1] = '\0';
|
2015-10-23 17:22:31 +02:00
|
|
|
}
|
2015-06-20 16:31:06 +02:00
|
|
|
_shortenedDirectory[0] = '\0';
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(filter, directory, sizeof(filter));
|
2015-09-07 00:46:54 +02:00
|
|
|
strncat(filter, "*", sizeof(filter) - strnlen(filter, MAX_PATH) - 1);
|
|
|
|
strncat(filter, extension, sizeof(filter) - strnlen(filter, MAX_PATH) - 1);
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
if (_listItems != NULL)
|
|
|
|
free(_listItems);
|
|
|
|
_listItems = (loadsave_list_item*)malloc(listItemCapacity * sizeof(loadsave_list_item));
|
|
|
|
_listItemsCount = 0;
|
2015-11-09 05:35:13 +01:00
|
|
|
|
|
|
|
window_loadsave_widgets[WIDX_NEW].type = includeNewItem?WWT_CLOSEBOX:WWT_EMPTY; // Hide/Show "new" button
|
|
|
|
if(directory[0]=='\0' && platform_get_drives()!=0) // List Windows drives
|
|
|
|
{
|
|
|
|
w->disabled_widgets |= (1<<WIDX_NEW) | (1<<WIDX_UP);
|
|
|
|
for (int x = 0; x < 32; x++){
|
|
|
|
if (listItemCapacity <= _listItemsCount) {
|
|
|
|
listItemCapacity *= 2;
|
|
|
|
_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
|
|
|
|
}
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-11-09 05:35:13 +01:00
|
|
|
if (platform_get_drives() & (1 << (x))){
|
|
|
|
listItem = &_listItems[_listItemsCount];
|
|
|
|
memset(listItem->path, '\0', MAX_PATH);
|
|
|
|
listItem->path[0] = 'A' + x;
|
|
|
|
listItem->path[1] = ':';
|
|
|
|
listItem->path[2] = platform_get_path_separator();
|
|
|
|
strcpy(listItem->name, listItem->path);
|
|
|
|
listItem->type = TYPE_DIRECTORY;
|
|
|
|
_listItemsCount++;
|
2015-02-14 22:59:58 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
2015-11-09 05:35:13 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//Get parent directory
|
|
|
|
int directoryLength = strlen(directory);
|
|
|
|
char separator = platform_get_path_separator();
|
|
|
|
for(i = directoryLength-2; i>=0; i--)
|
|
|
|
{
|
|
|
|
if(directory[i]==separator)
|
|
|
|
break;
|
|
|
|
}
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(_parentDirectory, directory, sizeof(_parentDirectory));
|
2015-11-09 05:35:13 +01:00
|
|
|
_parentDirectory[i+1] = '\0';
|
|
|
|
if(_parentDirectory[0]=='\0' && platform_get_drives()==0)
|
|
|
|
w->disabled_widgets |= (1<<WIDX_UP);
|
|
|
|
else
|
|
|
|
w->disabled_widgets &= ~(1<<WIDX_UP);
|
|
|
|
w->disabled_widgets &= ~(1<<WIDX_NEW);
|
|
|
|
file_info fileInfo;
|
|
|
|
int fileEnumHandle;
|
|
|
|
const char *src;
|
|
|
|
char *dst;
|
|
|
|
char *last_dot_in_filename;
|
|
|
|
char subDir[MAX_PATH];
|
|
|
|
|
2015-06-22 15:55:57 +02:00
|
|
|
fileEnumHandle = platform_enumerate_directories_begin(directory);
|
|
|
|
while (platform_enumerate_directories_next(fileEnumHandle, subDir)){
|
|
|
|
if (listItemCapacity <= _listItemsCount) {
|
|
|
|
listItemCapacity *= 2;
|
|
|
|
_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
|
|
|
|
}
|
2015-02-14 22:59:58 +01:00
|
|
|
|
2015-06-22 15:55:57 +02:00
|
|
|
listItem = &_listItems[_listItemsCount];
|
|
|
|
memset(listItem->path, '\0', MAX_PATH);
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(listItem->path, directory, MAX_PATH);
|
2015-12-31 09:16:44 +01:00
|
|
|
strncat(listItem->path, subDir, MAX_PATH - strnlen(listItem->path, MAX_PATH) - 1);
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(listItem->name, subDir, sizeof(listItem->name));
|
2015-06-22 15:55:57 +02:00
|
|
|
listItem->type = TYPE_DIRECTORY;
|
|
|
|
_listItemsCount++;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
2015-06-22 15:55:57 +02:00
|
|
|
platform_enumerate_files_end(fileEnumHandle);
|
|
|
|
|
|
|
|
fileEnumHandle = platform_enumerate_files_begin(filter);
|
|
|
|
while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) {
|
|
|
|
if (listItemCapacity <= _listItemsCount) {
|
|
|
|
listItemCapacity *= 2;
|
|
|
|
_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
|
|
|
|
}
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-06-22 15:55:57 +02:00
|
|
|
listItem = &_listItems[_listItemsCount];
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(listItem->path, directory, sizeof(listItem->path));
|
2015-12-31 09:16:44 +01:00
|
|
|
strncat(listItem->path, fileInfo.path, sizeof(listItem->path) - strnlen(listItem->path, MAX_PATH) - 1);
|
2015-06-22 15:55:57 +02:00
|
|
|
listItem->type = TYPE_FILE;
|
|
|
|
listItem->date_modified = platform_file_get_modified_time(listItem->path);
|
|
|
|
|
|
|
|
src = fileInfo.path;
|
|
|
|
dst = listItem->name;
|
2015-11-08 18:21:55 +01:00
|
|
|
last_dot_in_filename = strrchr(fileInfo.path, '.');
|
|
|
|
assert(last_dot_in_filename != NULL);
|
2015-06-22 15:55:57 +02:00
|
|
|
i = 0;
|
2015-11-08 18:21:55 +01:00
|
|
|
while (src < last_dot_in_filename && i < sizeof(listItem->name) - 1) {
|
2015-06-22 15:55:57 +02:00
|
|
|
*dst++ = *src++;
|
|
|
|
i++;
|
|
|
|
}
|
2015-11-08 18:21:55 +01:00
|
|
|
*dst = '\0';
|
2015-06-22 15:55:57 +02:00
|
|
|
|
|
|
|
_listItemsCount++;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
2015-06-22 15:55:57 +02:00
|
|
|
platform_enumerate_files_end(fileEnumHandle);
|
2015-12-17 22:53:40 +01:00
|
|
|
window_loadsave_sort_list(sortStartIndex, _listItemsCount - 1);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:43:55 +01:00
|
|
|
static void window_loadsave_invoke_callback(int result)
|
|
|
|
{
|
|
|
|
if (gLoadSaveCallback != NULL) {
|
|
|
|
gLoadSaveCallback(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
static void window_loadsave_select(rct_window *w, const char *path)
|
|
|
|
{
|
2015-07-05 06:36:25 +02:00
|
|
|
SDL_RWops* rw;
|
2015-08-16 19:42:30 +02:00
|
|
|
switch (_loadsaveType & 0x0F) {
|
2015-02-14 23:22:44 +01:00
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME) :
|
2015-08-16 17:36:57 +02:00
|
|
|
if (gLoadSaveTitleSequenceSave) {
|
|
|
|
utf8 newName[MAX_PATH];
|
2015-11-29 19:41:06 +01:00
|
|
|
char *extension = (char*)path_get_extension(path);
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(newName, path_get_filename(path), MAX_PATH);
|
2015-08-16 17:36:57 +02:00
|
|
|
if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0)
|
|
|
|
strcat(newName, ".sv6");
|
|
|
|
if (title_sequence_save_exists(gCurrentTitleSequence, newName)) {
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint32) = (uint32)&_listItems[w->selected_list_item].name;
|
|
|
|
window_text_input_open(w, WIDX_SCROLL, 5435, 5404, 1170, (uint32)_listItems[w->selected_list_item].name, TITLE_SEQUENCE_MAX_SAVE_LENGTH - 1);
|
2015-02-14 22:59:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-08-16 17:36:57 +02:00
|
|
|
title_sequence_add_save(gCurrentTitleSequence, path, newName);
|
|
|
|
window_close(w);
|
2015-02-14 22:59:58 +01:00
|
|
|
}
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2016-01-09 01:25:09 +01:00
|
|
|
} else if (game_load_save(path)) {
|
2015-08-16 18:29:47 +02:00
|
|
|
if (_loadsaveType & LOADSAVETYPE_NETWORK) {
|
|
|
|
network_begin_server(gConfigNetwork.default_port);
|
|
|
|
}
|
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(gScenarioSavePath, path, MAX_PATH);
|
2015-08-19 21:54:25 +02:00
|
|
|
gFirstTimeSave = 0;
|
|
|
|
|
2015-08-16 17:36:57 +02:00
|
|
|
window_close(w);
|
|
|
|
gfx_invalidate_screen();
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2016-01-09 01:25:09 +01:00
|
|
|
} else {
|
2015-08-16 17:36:57 +02:00
|
|
|
// 1050, not the best message...
|
|
|
|
window_error_open(STR_LOAD_GAME, 1050);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-08-16 17:36:57 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME) :
|
2015-08-29 14:12:52 +02:00
|
|
|
rw = SDL_RWFromFile(path, "wb+");
|
2015-08-16 17:36:57 +02:00
|
|
|
if (rw != NULL) {
|
|
|
|
int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 1 : 0);
|
|
|
|
SDL_RWclose(rw);
|
|
|
|
if (success) {
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(gScenarioSavePath, path, MAX_PATH);
|
2015-08-19 21:54:25 +02:00
|
|
|
gFirstTimeSave = 0;
|
|
|
|
|
2015-08-16 17:36:57 +02:00
|
|
|
window_close_by_class(WC_LOADSAVE);
|
2015-02-14 22:59:58 +01:00
|
|
|
gfx_invalidate_screen();
|
2015-11-02 21:43:55 +01:00
|
|
|
|
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2015-07-05 06:36:25 +02:00
|
|
|
} else {
|
2015-08-16 17:36:57 +02:00
|
|
|
window_error_open(STR_SAVE_GAME, 1047);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-07-05 06:36:25 +02:00
|
|
|
}
|
2015-08-16 17:36:57 +02:00
|
|
|
} else {
|
|
|
|
window_error_open(STR_SAVE_GAME, 1047);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-08-16 17:36:57 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE) :
|
2016-01-09 01:25:09 +01:00
|
|
|
if (editor_load_landscape(path)) {
|
2015-08-16 17:36:57 +02:00
|
|
|
gfx_invalidate_screen();
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2016-01-09 01:25:09 +01:00
|
|
|
} else {
|
2015-08-16 17:36:57 +02:00
|
|
|
// 1050, not the best message...
|
|
|
|
window_error_open(STR_LOAD_LANDSCAPE, 1050);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-08-16 17:36:57 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE) :
|
2015-08-29 14:12:52 +02:00
|
|
|
rw = SDL_RWFromFile(path, "wb+");
|
2015-08-16 17:36:57 +02:00
|
|
|
if (rw != NULL) {
|
2015-09-05 21:06:58 +02:00
|
|
|
scenario_set_filename(path);
|
2015-08-16 17:36:57 +02:00
|
|
|
int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 3 : 2);
|
|
|
|
SDL_RWclose(rw);
|
2015-02-14 03:16:03 +01:00
|
|
|
if (success) {
|
2015-07-20 21:49:56 +02:00
|
|
|
window_close_by_class(WC_LOADSAVE);
|
2015-08-16 17:36:57 +02:00
|
|
|
gfx_invalidate_screen();
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2015-07-05 06:36:25 +02:00
|
|
|
} else {
|
2015-08-16 17:36:57 +02:00
|
|
|
window_error_open(STR_SAVE_LANDSCAPE, 1049);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
2015-08-16 17:36:57 +02:00
|
|
|
} else {
|
|
|
|
window_error_open(STR_SAVE_LANDSCAPE, 1049);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
break;
|
2015-08-16 17:36:57 +02:00
|
|
|
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO) :
|
|
|
|
{
|
|
|
|
rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;
|
|
|
|
int parkFlagsBackup = RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32);
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) &= ~PARK_FLAGS_18;
|
2015-10-15 23:16:27 +02:00
|
|
|
s6Info->editor_step = 255;
|
2015-08-29 14:12:52 +02:00
|
|
|
rw = SDL_RWFromFile(path, "wb+");
|
2015-08-16 17:36:57 +02:00
|
|
|
int success = 0;
|
|
|
|
if (rw != NULL) {
|
2015-09-05 21:06:58 +02:00
|
|
|
scenario_set_filename(path);
|
2015-08-16 17:36:57 +02:00
|
|
|
success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 3 : 2);
|
|
|
|
SDL_RWclose(rw);
|
|
|
|
}
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) = parkFlagsBackup;
|
|
|
|
|
|
|
|
if (success) {
|
2015-04-02 23:00:59 +02:00
|
|
|
window_close_by_class(WC_LOADSAVE);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2015-08-16 17:36:57 +02:00
|
|
|
title_load();
|
|
|
|
} else {
|
|
|
|
window_error_open(STR_SAVE_SCENARIO, STR_SCENARIO_SAVE_FAILED);
|
2015-10-15 23:16:27 +02:00
|
|
|
s6Info->editor_step = EDITOR_STEP_OBJECTIVE_SELECTION;
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
|
2015-02-14 22:59:58 +01:00
|
|
|
}
|
2015-08-16 17:36:57 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK) :
|
|
|
|
window_install_track_open(path);
|
|
|
|
window_close_by_class(WC_LOADSAVE);
|
2015-11-02 21:43:55 +01:00
|
|
|
window_loadsave_invoke_callback(MODAL_RESULT_OK);
|
2015-08-16 17:36:57 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma region Overwrite prompt
|
|
|
|
|
|
|
|
#define OVERWRITE_WW 200
|
|
|
|
#define OVERWRITE_WH 100
|
|
|
|
|
|
|
|
enum {
|
|
|
|
WIDX_OVERWRITE_BACKGROUND,
|
|
|
|
WIDX_OVERWRITE_TITLE,
|
|
|
|
WIDX_OVERWRITE_CLOSE,
|
|
|
|
WIDX_OVERWRITE_OVERWRITE,
|
|
|
|
WIDX_OVERWRITE_CANCEL
|
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_overwrite_prompt_widgets[] = {
|
|
|
|
{ WWT_FRAME, 0, 0, OVERWRITE_WW - 1, 0, OVERWRITE_WH - 1, STR_NONE, STR_NONE },
|
|
|
|
{ WWT_CAPTION, 0, 1, OVERWRITE_WW - 2, 1, 14, 2709, STR_WINDOW_TITLE_TIP },
|
|
|
|
{ WWT_CLOSEBOX, 0, OVERWRITE_WW - 13, OVERWRITE_WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP },
|
|
|
|
{ WWT_DROPDOWN_BUTTON, 0, 10, 94, OVERWRITE_WH - 20, OVERWRITE_WH - 9, 2709, STR_NONE },
|
|
|
|
{ WWT_DROPDOWN_BUTTON, 0, OVERWRITE_WW - 95, OVERWRITE_WW - 11, OVERWRITE_WH - 20, OVERWRITE_WH - 9, STR_SAVE_PROMPT_CANCEL, STR_NONE },
|
|
|
|
{ WIDGETS_END }
|
|
|
|
};
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_overwrite_prompt_mouseup(rct_window *w, int widgetIndex);
|
|
|
|
static void window_overwrite_prompt_invalidate(rct_window *w);
|
|
|
|
static void window_overwrite_prompt_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static rct_window_event_list window_overwrite_prompt_events = {
|
|
|
|
NULL,
|
2015-02-14 03:16:03 +01:00
|
|
|
window_overwrite_prompt_mouseup,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-05-29 18:04:53 +02:00
|
|
|
window_overwrite_prompt_invalidate,
|
2015-02-14 03:16:03 +01:00
|
|
|
window_overwrite_prompt_paint,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL
|
2015-02-14 03:16:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static char _window_overwrite_prompt_name[256];
|
|
|
|
static char _window_overwrite_prompt_path[MAX_PATH];
|
|
|
|
|
|
|
|
static rct_window *window_overwrite_prompt_open(const char *name, const char *path)
|
|
|
|
{
|
|
|
|
rct_window *w;
|
|
|
|
|
|
|
|
window_close_by_class(WC_LOADSAVE_OVERWRITE_PROMPT);
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
w = window_create_centred(OVERWRITE_WW, OVERWRITE_WH, &window_overwrite_prompt_events, WC_LOADSAVE_OVERWRITE_PROMPT, WF_STICK_TO_FRONT);
|
2015-02-14 03:16:03 +01:00
|
|
|
w->widgets = window_overwrite_prompt_widgets;
|
|
|
|
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_OVERWRITE_CANCEL) | (1 << WIDX_OVERWRITE_OVERWRITE);
|
|
|
|
window_init_scroll_widgets(w);
|
|
|
|
w->flags |= WF_TRANSPARENT;
|
|
|
|
w->colours[0] = 154;
|
|
|
|
|
2016-01-18 20:49:52 +01:00
|
|
|
safe_strcpy(_window_overwrite_prompt_name, name, sizeof(_window_overwrite_prompt_name));
|
|
|
|
safe_strcpy(_window_overwrite_prompt_path, path, sizeof(_window_overwrite_prompt_path));
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_overwrite_prompt_mouseup(rct_window *w, int widgetIndex)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-07-10 02:39:16 +02:00
|
|
|
rct_window *loadsaveWindow;
|
2015-02-14 03:16:03 +01:00
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
switch (widgetIndex) {
|
2015-02-14 03:16:03 +01:00
|
|
|
case WIDX_OVERWRITE_OVERWRITE:
|
|
|
|
loadsaveWindow = window_find_by_class(WC_LOADSAVE);
|
|
|
|
if (loadsaveWindow != NULL)
|
|
|
|
window_loadsave_select(loadsaveWindow, _window_overwrite_prompt_path);
|
2015-07-20 21:49:56 +02:00
|
|
|
// As the window_loadsave_select function can change the order of the
|
|
|
|
// windows we can't use window_close(w).
|
|
|
|
window_close_by_class(WC_LOADSAVE_OVERWRITE_PROMPT);
|
2015-02-14 03:16:03 +01:00
|
|
|
break;
|
|
|
|
case WIDX_OVERWRITE_CANCEL:
|
|
|
|
case WIDX_OVERWRITE_CLOSE:
|
|
|
|
window_close(w);
|
2015-07-10 02:39:16 +02:00
|
|
|
break;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_overwrite_prompt_invalidate(rct_window *w)
|
2015-05-29 18:04:53 +02:00
|
|
|
{
|
|
|
|
colour_scheme_update(w);
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_overwrite_prompt_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
|
|
|
|
rct_string_id templateStringId = 3165;
|
|
|
|
char *templateString;
|
|
|
|
|
|
|
|
templateString = (char*)language_get_string(templateStringId);
|
|
|
|
strcpy(templateString, _window_overwrite_prompt_name);
|
|
|
|
|
|
|
|
int x = w->x + w->width / 2;
|
|
|
|
int y = w->y + (w->height / 2) - 3;
|
|
|
|
gfx_draw_string_centred_wrapped(dpi, &templateStringId, x, y, w->width - 4, 2708, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-27 10:46:12 +01:00
|
|
|
#pragma endregion
|