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
|
@@ -35,7 +35,7 @@ short mode_count = 0;
|
||||
cOutdoors* current_terrain;
|
||||
short pixel_depth,old_depth = 8;
|
||||
|
||||
bool change_made = false;
|
||||
bool change_made = false, ae_loading = false;
|
||||
|
||||
// Numbers of current areas being edited
|
||||
short cur_town;
|
||||
@@ -54,6 +54,8 @@ cScenario scenario;
|
||||
rectangle right_sbar_rect;
|
||||
extern rectangle terrain_buttons_rect;
|
||||
|
||||
extern void set_up_apple_events();
|
||||
|
||||
//Changed to ISO C specified argument and return type.
|
||||
int main(int, char* argv[]) {
|
||||
try {
|
||||
@@ -72,6 +74,9 @@ int main(int, char* argv[]) {
|
||||
cDialog::doAnimations = true;
|
||||
init_graph_tool();
|
||||
|
||||
check_for_intel();
|
||||
set_up_apple_events();
|
||||
|
||||
cen_x = 18;
|
||||
cen_y = 18;
|
||||
|
||||
@@ -84,11 +89,13 @@ int main(int, char* argv[]) {
|
||||
Set_up_win();
|
||||
init_screen_locs();
|
||||
|
||||
shut_down_menus(0);
|
||||
if(ae_loading)
|
||||
set_up_main_screen();
|
||||
else {
|
||||
shut_down_menus(0);
|
||||
set_up_start_screen();
|
||||
}
|
||||
|
||||
set_up_start_screen();
|
||||
|
||||
check_for_intel();
|
||||
redraw_screen();
|
||||
|
||||
while(!All_Done)
|
||||
@@ -149,6 +156,7 @@ void Initialize(void) {
|
||||
}
|
||||
|
||||
void Handle_One_Event() {
|
||||
ae_loading = false;
|
||||
Handle_Update();
|
||||
|
||||
if(!mainPtr.waitEvent(event)) return;
|
||||
|
Reference in New Issue
Block a user