From 20df0a0be72b83c5caf56e84a8ab7978519b79e7 Mon Sep 17 00:00:00 2001 From: Kyle Kirbatski Date: Sat, 12 Dec 2015 17:15:38 -0600 Subject: [PATCH 1/6] Add `.m` files --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23a0ab2da9..2fe7b08f38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG=${DEBUG_LEVEL}") include_directories("lib/") # add source files file(GLOB_RECURSE ORCT2_SOURCES "src/*.c" "src/*.cpp" "lib/argparse/*.c" "lib/cutest/*.c" "lib/lodepng/*.c") +if (APPLE) + file(GLOB_RECURSE ORCT2_MM_SOURCES "src/*.m") + set_source_files_properties(${ORCT2_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c -fmodules") +endif (APPLE) if (UNIX) # force 32bit build for now and set necessary flags to compile code as is @@ -95,7 +99,7 @@ if (WIN32) # build as library for now, replace with add_executable add_library(${PROJECT} SHARED ${ORCT2_SOURCES} ${SPEEX_SOURCES}) else (WIN32) - add_executable(${PROJECT} ${ORCT2_SOURCES}) + add_executable(${PROJECT} ${ORCT2_SOURCES} ${ORCT2_MM_SOURCES}) add_custom_command( OUTPUT g2.dat COMMAND ./openrct2 sprite build ${CMAKE_BINARY_DIR}/g2.dat ${CMAKE_CURRENT_SOURCE_DIR}/resources/g2/ From 39ae4e21541c7f55094bf7010f69ee9a89ed0fed Mon Sep 17 00:00:00 2001 From: Kyle Kirbatski Date: Sat, 12 Dec 2015 17:20:02 -0600 Subject: [PATCH 2/6] Extract dialog functions out of posix.c and into linux.c --- src/platform/linux.c | 22 ++++++++++++++++++++++ src/platform/posix.c | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/platform/linux.c b/src/platform/linux.c index b4d3304329..8070466dfa 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -112,4 +112,26 @@ void platform_posix_sub_user_data_path(char *buffer, const char *homedir, const strncat(buffer, separator, MAX_PATH - strnlen(buffer, MAX_PATH) - 1); } +utf8 *platform_open_directory_browser(utf8 *title) +{ + STUB(); + return NULL; +} + +void platform_show_messagebox(char *message) +{ + STUB(); + log_verbose(message); +} + +/** + * + * rct2: 0x004080EA + */ +int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) +{ + STUB(); + return 0; +} + #endif diff --git a/src/platform/posix.c b/src/platform/posix.c index 18eeef0851..c1271e529b 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -588,28 +588,6 @@ void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory) log_verbose("outPath + subDirectory = '%s'", buffer); } -void platform_show_messagebox(char *message) -{ - STUB(); - log_verbose(message); -} - -/** - * - * rct2: 0x004080EA - */ -int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) -{ - STUB(); - return 0; -} - -utf8 *platform_open_directory_browser(utf8 *title) -{ - STUB(); - return NULL; -} - uint16 platform_get_locale_language(){ const char *langString = setlocale(LC_MESSAGES, ""); if(langString != NULL){ From 17766c477236f808ec7e14127c9898465a69a1a4 Mon Sep 17 00:00:00 2001 From: Kyle Kirbatski Date: Sat, 12 Dec 2015 17:21:21 -0600 Subject: [PATCH 3/6] Rename osx.c to osx.m --- src/platform/{osx.c => osx.m} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/platform/{osx.c => osx.m} (100%) diff --git a/src/platform/osx.c b/src/platform/osx.m similarity index 100% rename from src/platform/osx.c rename to src/platform/osx.m From 2a8ed04eda9ce81b30e6ab90be57c3522b0e593b Mon Sep 17 00:00:00 2001 From: Kyle Kirbatski Date: Sat, 12 Dec 2015 17:22:14 -0600 Subject: [PATCH 4/6] Add platform dialog functions for OS X --- src/platform/osx.m | 86 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/src/platform/osx.m b/src/platform/osx.m index 6171af885b..3c530f8efe 100644 --- a/src/platform/osx.m +++ b/src/platform/osx.m @@ -20,11 +20,11 @@ #if defined(__APPLE__) && defined(__MACH__) +@import AppKit; +#include #include "platform.h" #include "../util/util.h" -#include - bool platform_check_steam_overlay_attached() { STUB(); return false; @@ -75,4 +75,86 @@ void platform_posix_sub_user_data_path(char *buffer, const char *homedir, const strncat(buffer, separator, MAX_PATH - strnlen(buffer, MAX_PATH) - 1); } +void platform_show_messagebox(char *message) +{ + @autoreleasepool + { + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:@"OK"]; + [alert setMessageText:[NSString stringWithUTF8String:message]]; + [alert setAlertStyle:NSWarningAlertStyle]; + [alert runModal]; + [alert release]; + } +} + +utf8 *platform_open_directory_browser(utf8 *title) +{ + @autoreleasepool + { + NSOpenPanel *panel = [NSOpenPanel openPanel]; + panel.canChooseFiles = false; + panel.canChooseDirectories = true; + panel.allowsMultipleSelection = false; + utf8 *url = NULL; + if ([panel runModal] == NSFileHandlingPanelOKButton) + { + NSString *selectedPath = [[[panel URLs] firstObject] path]; + const char *path = [selectedPath UTF8String]; + url = (utf8*)malloc(strlen(path) + 1); + strcpy(url,path); + } + return url; + } +} + +int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName) +{ + @autoreleasepool + { + NSArray *extensions = [ + [ + [NSString stringWithUTF8String:filterPattern] + stringByReplacingOccurrencesOfString:@"*." withString:@"" + ] + componentsSeparatedByString:@";" + ]; + NSString *filePath = [NSString stringWithUTF8String:filename]; + NSString *directory = [filePath stringByDeletingLastPathComponent]; + NSString *basename = [filePath lastPathComponent]; + if (type == 0) + { + NSSavePanel *panel = [NSSavePanel savePanel]; + panel.title = [NSString stringWithUTF8String:title]; + panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@",basename,[extensions firstObject]]; + panel.allowedFileTypes = extensions; + panel.directoryURL = [NSURL fileURLWithPath:directory]; + if ([panel runModal] == NSFileHandlingPanelCancelButton){ + return 0; + } else { + strcpy(filename,[[[panel URL] path] UTF8String]); + return 1; + } + } + else if (type == 1) + { + NSOpenPanel *panel = [NSOpenPanel openPanel]; + panel.title = [NSString stringWithUTF8String:title]; + panel.allowedFileTypes = extensions; + panel.canChooseDirectories = false; + panel.canChooseFiles = true; + panel.allowsMultipleSelection = false; + panel.directoryURL = [NSURL fileURLWithPath:filePath]; + if ([panel runModal] == NSFileHandlingPanelCancelButton){ + return 0; + } else { + strcpy(filename,[[[[panel URLs] firstObject] path] UTF8String]); + return 1; + } + } else { + return 0; + } + } +} + #endif From 88e67bbae0ef4483410f4cf3b84e24412cdba851 Mon Sep 17 00:00:00 2001 From: Kyle Kirbatski Date: Sat, 12 Dec 2015 18:15:38 -0600 Subject: [PATCH 5/6] Fix for Windows build --- projects/openrct2.vcxproj | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 901c0793c3..5470566dae 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -87,7 +87,6 @@ - From 8b63080aeb499b87f9a63c3c0717438a3719bba6 Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Thu, 17 Dec 2015 22:06:07 -0600 Subject: [PATCH 6/6] Some Objective-C Code Cleanup --- src/platform/osx.m | 69 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/src/platform/osx.m b/src/platform/osx.m index 3c530f8efe..60b76132d8 100644 --- a/src/platform/osx.m +++ b/src/platform/osx.m @@ -79,12 +79,11 @@ void platform_show_messagebox(char *message) { @autoreleasepool { - NSAlert *alert = [[NSAlert alloc] init]; + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; [alert addButtonWithTitle:@"OK"]; - [alert setMessageText:[NSString stringWithUTF8String:message]]; - [alert setAlertStyle:NSWarningAlertStyle]; + alert.messageText = [NSString stringWithUTF8String:message]; + alert.alertStyle = NSWarningAlertStyle; [alert runModal]; - [alert release]; } } @@ -99,8 +98,8 @@ utf8 *platform_open_directory_browser(utf8 *title) utf8 *url = NULL; if ([panel runModal] == NSFileHandlingPanelOKButton) { - NSString *selectedPath = [[[panel URLs] firstObject] path]; - const char *path = [selectedPath UTF8String]; + NSString *selectedPath = panel.URL.path; + const char *path = selectedPath.UTF8String; url = (utf8*)malloc(strlen(path) + 1); strcpy(url,path); } @@ -112,48 +111,40 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 { @autoreleasepool { - NSArray *extensions = [ - [ - [NSString stringWithUTF8String:filterPattern] - stringByReplacingOccurrencesOfString:@"*." withString:@"" - ] - componentsSeparatedByString:@";" - ]; + NSString *fillPatternNS = [NSString stringWithUTF8String:filterPattern]; + fillPatternNS = [fillPatternNS stringByReplacingOccurrencesOfString:@"*." withString:@""]; + NSArray *extensions = [fillPatternNS componentsSeparatedByString:@";"]; + NSString *filePath = [NSString stringWithUTF8String:filename]; - NSString *directory = [filePath stringByDeletingLastPathComponent]; - NSString *basename = [filePath lastPathComponent]; + NSString *directory = filePath.stringByDeletingLastPathComponent; + NSString *basename = filePath.lastPathComponent; + + NSSavePanel *panel; if (type == 0) { - NSSavePanel *panel = [NSSavePanel savePanel]; - panel.title = [NSString stringWithUTF8String:title]; - panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@",basename,[extensions firstObject]]; - panel.allowedFileTypes = extensions; - panel.directoryURL = [NSURL fileURLWithPath:directory]; - if ([panel runModal] == NSFileHandlingPanelCancelButton){ - return 0; - } else { - strcpy(filename,[[[panel URL] path] UTF8String]); - return 1; - } + panel = [NSSavePanel savePanel]; + panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject]; } else if (type == 1) { - NSOpenPanel *panel = [NSOpenPanel openPanel]; - panel.title = [NSString stringWithUTF8String:title]; - panel.allowedFileTypes = extensions; - panel.canChooseDirectories = false; - panel.canChooseFiles = true; - panel.allowsMultipleSelection = false; - panel.directoryURL = [NSURL fileURLWithPath:filePath]; - if ([panel runModal] == NSFileHandlingPanelCancelButton){ - return 0; - } else { - strcpy(filename,[[[[panel URLs] firstObject] path] UTF8String]); - return 1; - } + NSOpenPanel *open = [NSOpenPanel openPanel]; + open.canChooseDirectories = false; + open.canChooseFiles = true; + open.allowsMultipleSelection = false; + panel = open; } else { return 0; } + + panel.title = [NSString stringWithUTF8String:title]; + panel.allowedFileTypes = extensions; + panel.directoryURL = [NSURL fileURLWithPath:directory]; + if ([panel runModal] == NSFileHandlingPanelCancelButton){ + return 0; + } else { + strcpy(filename, panel.URL.path.UTF8String); + return 1; + } } }