From ffafd07c9023d3b3b8a22d668ff0ab78c8668623 Mon Sep 17 00:00:00 2001 From: anyc Date: Fri, 29 Jan 2016 18:40:42 +0100 Subject: [PATCH] use enum to specify file dialog type --- src/game.c | 6 +++--- src/platform/linux.c | 2 +- src/platform/osx.m | 6 +++--- src/platform/platform.h | 5 ++++- src/platform/windows.c | 10 +++++----- src/ride/track.c | 2 +- src/windows/editor_bottom_toolbar.c | 2 +- src/windows/loadsave.c | 12 ++++++------ 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/game.c b/src/game.c index 3917b22f7b..e5612c3c7b 100644 --- a/src/game.c +++ b/src/game.c @@ -624,7 +624,7 @@ static int open_landscape_file_dialog() safe_strcpy((char*)0x0141EF68, (char*)RCT2_ADDRESS_LANDSCAPES_PATH, MAX_PATH); format_string((char*)0x0141EE68, STR_RCT2_LANDSCAPE_FILE, 0); audio_pause_sounds(); - result = platform_open_common_file_dialog(1, (char*)RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, (char*)0x0141EF68, "*.SV6;*.SV4;*.SC6", (char*)0x0141EE68); + result = platform_open_common_file_dialog(FD_OPEN, (char*)RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, (char*)0x0141EF68, "*.SV6;*.SV4;*.SC6", (char*)0x0141EE68); audio_unpause_sounds(); // window_proc return result; @@ -641,7 +641,7 @@ static int open_load_game_dialog() safe_strcpy((char*)0x0141EF68, (char*)RCT2_ADDRESS_SAVED_GAMES_PATH, MAX_PATH); format_string((char*)0x0141EE68, STR_RCT2_SAVED_GAME, 0); audio_pause_sounds(); - result = platform_open_common_file_dialog(1, (char*)RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, (char*)0x0141EF68, "*.SV6", (char*)0x0141EE68); + result = platform_open_common_file_dialog(FD_OPEN, (char*)RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, (char*)0x0141EF68, "*.SV6", (char*)0x0141EE68); audio_unpause_sounds(); // window_proc return result; @@ -990,7 +990,7 @@ static int show_save_game_dialog(char *resultPath) format_string(filterName, STR_RCT2_SAVED_GAME, NULL); audio_pause_sounds(); - result = platform_open_common_file_dialog(0, title, filename, "*.SV6", filterName); + result = platform_open_common_file_dialog(FD_SAVE, title, filename, "*.SV6", filterName); audio_unpause_sounds(); if (result) diff --git a/src/platform/linux.c b/src/platform/linux.c index cd0fa82e59..c910f535e2 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -162,7 +162,7 @@ void platform_show_messagebox(char *message) * * rct2: 0x004080EA */ -int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) +int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) { STUB(); return 0; diff --git a/src/platform/osx.m b/src/platform/osx.m index a4e7cb5e05..fb2f7f9916 100644 --- a/src/platform/osx.m +++ b/src/platform/osx.m @@ -131,7 +131,7 @@ utf8 *platform_open_directory_browser(utf8 *title) } } -int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) +int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) { @autoreleasepool { @@ -144,12 +144,12 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 NSString *basename = filePath.lastPathComponent; NSSavePanel *panel; - if (type == 0) + if (type == FD_SAVE) { panel = [NSSavePanel savePanel]; panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject]; } - else if (type == 1) + else if (type == FD_OPEN) { NSOpenPanel *open = [NSOpenPanel openPanel]; open.canChooseDirectories = false; diff --git a/src/platform/platform.h b/src/platform/platform.h index 24717e007b..72fc7c7069 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -85,6 +85,9 @@ enum { CURSOR_PRESSED = CURSOR_DOWN | CURSOR_CHANGED, }; +typedef enum {FD_OPEN, FD_SAVE} filedialog_type; + + extern openrct2_cursor gCursorState; extern const unsigned char *gKeysState; extern unsigned char *gKeysPressed; @@ -158,7 +161,7 @@ void platform_resolve_openrct_data_path(); void platform_get_openrct_data_path(utf8 *outPath); void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory); void platform_show_messagebox(utf8 *message); -int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName); +int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName); utf8 *platform_open_directory_browser(utf8 *title); uint8 platform_get_locale_currency(); uint8 platform_get_currency_value(const char *currencyCode); diff --git a/src/platform/windows.c b/src/platform/windows.c index 8f0be894b3..b6ec169242 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -579,7 +579,7 @@ void platform_show_messagebox(char *message) * * rct2: 0x004080EA */ -int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) +int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) { wchar_t wctitle[256], wcfilename[MAX_PATH], wcfilterPattern[256], wcfilterName[256]; wchar_t initialDirectory[MAX_PATH], *dotAddress, *slashAddress; @@ -603,8 +603,8 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 } // Clear filename - if (type != 0) - wcfilename[0] = 0; + if (type != FD_SAVE) + wcfilename[0] = 0; // Set open file name options memset(&openFileName, 0, sizeof(OPENFILENAMEW)); @@ -633,10 +633,10 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 // Open dialog commonFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; - if (type == 0) { + if (type == FD_SAVE) { openFileName.Flags = commonFlags | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT; result = GetSaveFileNameW(&openFileName); - } else if (type == 1) { + } else if (type == FD_OPEN) { openFileName.Flags = commonFlags | OFN_NONETWORKBUTTON | OFN_FILEMUSTEXIST; result = GetOpenFileNameW(&openFileName); } diff --git a/src/ride/track.c b/src/ride/track.c index 3ef16ebc89..5c28d6ac4f 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -3086,7 +3086,7 @@ int save_track_design(uint8 rideIndex){ audio_pause_sounds(); int result = platform_open_common_file_dialog( - 0, + FD_SAVE, RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char), path, "*.TD?", diff --git a/src/windows/editor_bottom_toolbar.c b/src/windows/editor_bottom_toolbar.c index bc36612bda..261998c07b 100644 --- a/src/windows/editor_bottom_toolbar.c +++ b/src/windows/editor_bottom_toolbar.c @@ -338,7 +338,7 @@ static int show_save_scenario_dialog(char *resultPath) format_string(filterName, STR_RCT2_SCENARIO_FILE, NULL); audio_pause_sounds(); - result = platform_open_common_file_dialog(0, title, filename, "*.SC6", filterName); + result = platform_open_common_file_dialog(FD_SAVE, title, filename, "*.SC6", filterName); audio_unpause_sounds(); if (result) diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index b824a2d3ad..77f1464823 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -304,22 +304,22 @@ static void window_loadsave_mouseup(rct_window *w, int widgetIndex) switch (_type) { case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME) : - result = platform_open_common_file_dialog(1, (char*)language_get_string(STR_LOAD_GAME), path, filter, _extension); + result = platform_open_common_file_dialog(FD_OPEN, (char*)language_get_string(STR_LOAD_GAME), path, filter, _extension); break; case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME) : - result = platform_open_common_file_dialog(0, (char*)language_get_string(STR_SAVE_GAME), path, filter, _extension); + result = platform_open_common_file_dialog(FD_SAVE, (char*)language_get_string(STR_SAVE_GAME), path, filter, _extension); break; case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE) : - result = platform_open_common_file_dialog(1, (char*)language_get_string(STR_LOAD_LANDSCAPE), path, filter, _extension); + result = platform_open_common_file_dialog(FD_OPEN, (char*)language_get_string(STR_LOAD_LANDSCAPE), path, filter, _extension); break; case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE) : - result = platform_open_common_file_dialog(0, (char*)language_get_string(STR_SAVE_LANDSCAPE), path, filter, _extension); + result = platform_open_common_file_dialog(FD_SAVE, (char*)language_get_string(STR_SAVE_LANDSCAPE), path, filter, _extension); break; case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO) : - result = platform_open_common_file_dialog(0, (char*)language_get_string(STR_SAVE_SCENARIO), path, filter, _extension); + result = platform_open_common_file_dialog(FD_SAVE, (char*)language_get_string(STR_SAVE_SCENARIO), path, filter, _extension); break; case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK) : - result = platform_open_common_file_dialog(1, (char*)language_get_string(1039), path, filter, _extension); + result = platform_open_common_file_dialog(FD_OPEN, (char*)language_get_string(1039), path, filter, _extension); break; }