Scenarios can now be opened in the editor by double-clicking them.
- Character editor also supports dropping saved games on the app icon
This commit is contained in:
64
src/scenedit/scen.appleevents.mm
Normal file
64
src/scenedit/scen.appleevents.mm
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// boe.appleevents.mm
|
||||
// BoE
|
||||
//
|
||||
// Created by Celtic Minstrel on 14-03-26.
|
||||
//
|
||||
//
|
||||
|
||||
#include "scenario.h" // Include before Cocoa because the Cocoa header defines things that cause compilation errors in here
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "fileio.hpp"
|
||||
#include "scen.actions.h"
|
||||
|
||||
//extern bool ae_loading, startup_loaded, All_Done, party_in_memory, finished_init;
|
||||
extern cScenario scenario;
|
||||
extern cTown* town;
|
||||
extern cOutdoors* current_terrain;
|
||||
extern short cur_town;
|
||||
extern location cur_out;
|
||||
extern bool change_made, ae_loading;
|
||||
|
||||
@interface AppleEventHandler : NSObject<NSApplicationDelegate>
|
||||
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file;
|
||||
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender;
|
||||
@end
|
||||
|
||||
void set_up_apple_events(); // Suppress "no prototype" warning
|
||||
void set_up_apple_events() {
|
||||
AppleEventHandler* aeHandler = [[AppleEventHandler alloc] init];
|
||||
[[NSApplication sharedApplication] setDelegate: aeHandler];
|
||||
}
|
||||
|
||||
// TODO: What if they're already in a scenario? It should ask for confirmation, right?
|
||||
// (Need to figure out cChoiceDlog bug first, though, as it would crash here just like it does on the quit event.)
|
||||
@implementation AppleEventHandler
|
||||
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file {
|
||||
(void) app; // Suppress "unused parameter" warning
|
||||
if(file == nil) {
|
||||
std::cerr << "Error: filename was nil" << std::endl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
unsigned long len = [file length], sz = len + 1;
|
||||
auto msg = std::shared_ptr<unichar>(new unichar[sz], std::default_delete<unichar[]>());
|
||||
std::fill(msg.get(), msg.get() + sz, 0);
|
||||
[file getCharacters: msg.get() range: (NSRange){0, len}];
|
||||
std::string fileName;
|
||||
std::copy(msg.get(), msg.get() + len, std::inserter(fileName, fileName.begin()));
|
||||
|
||||
if(load_scenario(fileName, scenario)) {
|
||||
cur_town = scenario.last_town_edited;
|
||||
town = scenario.towns[cur_town];
|
||||
cur_out = scenario.last_out_edited;
|
||||
current_terrain = scenario.outdoors[cur_out.x][cur_out.y];
|
||||
change_made = false;
|
||||
ae_loading = true;
|
||||
set_up_main_screen();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user