use enum to specify file dialog type

This commit is contained in:
anyc 2016-01-29 18:40:42 +01:00
parent d193e9f3b3
commit ffafd07c90
8 changed files with 24 additions and 21 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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?",

View File

@ -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)

View File

@ -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;
}