1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Merge pull request #2473 from kkirby/feature/dialogs

Add message dialog and directory open dialog on OS X
This commit is contained in:
Ted John
2015-12-18 20:37:57 +00:00
5 changed files with 102 additions and 26 deletions

View File

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

View File

@@ -87,7 +87,6 @@
<ClCompile Include="..\src\platform\linux.c" />
<ClCompile Include="..\src\platform\posix.c" />
<ClCompile Include="..\src\platform\shared.c" />
<ClCompile Include="..\src\platform\osx.c" />
<ClCompile Include="..\src\platform\windows.c" />
<ClCompile Include="..\src\rct1.c" />
<ClCompile Include="..\src\rct2.c" />

View File

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

View File

@@ -20,11 +20,11 @@
#if defined(__APPLE__) && defined(__MACH__)
@import AppKit;
#include <mach-o/dyld.h>
#include "platform.h"
#include "../util/util.h"
#include <mach-o/dyld.h>
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

View File

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