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/ 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 @@ - 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/osx.c b/src/platform/osx.m similarity index 55% rename from src/platform/osx.c rename to src/platform/osx.m index 6171af885b..60b76132d8 100644 --- a/src/platform/osx.c +++ 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,77 @@ 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] autorelease]; + [alert addButtonWithTitle:@"OK"]; + alert.messageText = [NSString stringWithUTF8String:message]; + alert.alertStyle = NSWarningAlertStyle; + [alert runModal]; + } +} + +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.URL.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 + { + 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; + + NSSavePanel *panel; + if (type == 0) + { + panel = [NSSavePanel savePanel]; + panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject]; + } + else if (type == 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; + } + } +} + #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){