game[mac]: try to make openFile's apple event works...
This commit is contained in:
@@ -2180,8 +2180,9 @@ bool handle_scroll(const sf::Event& event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_load() {
|
void do_load(fs::path const &file_name) {
|
||||||
fs::path file_to_load = nav_get_party();
|
fs::path file_to_load = file_name;
|
||||||
|
if (file_to_load.empty()) file_to_load=nav_get_party();
|
||||||
if(file_to_load.empty()) return;
|
if(file_to_load.empty()) return;
|
||||||
if(!load_party(file_to_load, univ))
|
if(!load_party(file_to_load, univ))
|
||||||
return;
|
return;
|
||||||
|
@@ -14,7 +14,7 @@ void handle_menu_spell(short spell_picked,short spell_type) ;
|
|||||||
void initiate_outdoor_combat(short i);
|
void initiate_outdoor_combat(short i);
|
||||||
bool handle_keystroke(const sf::Event& event);
|
bool handle_keystroke(const sf::Event& event);
|
||||||
bool handle_scroll(const sf::Event& event);
|
bool handle_scroll(const sf::Event& event);
|
||||||
void do_load();
|
void do_load(fs::path const &file_name=fs::path());
|
||||||
void post_load();
|
void post_load();
|
||||||
void do_save(short mode);
|
void do_save(short mode);
|
||||||
void increase_age();
|
void increase_age();
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "universe.hpp" // Include before Cocoa because the Cocoa header defines things that cause compilation errors in here
|
#include "universe.hpp" // Include before Cocoa because the Cocoa header defines things that cause compilation errors in here
|
||||||
|
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -22,6 +23,7 @@ extern void post_load();
|
|||||||
extern bool ae_loading, All_Done, party_in_memory, finished_init;
|
extern bool ae_loading, All_Done, party_in_memory, finished_init;
|
||||||
extern eGameMode overall_mode;
|
extern eGameMode overall_mode;
|
||||||
extern cUniverse univ;
|
extern cUniverse univ;
|
||||||
|
extern fs::path pending_file_to_load;
|
||||||
|
|
||||||
typedef NSAppleEventDescriptor AEDescr;
|
typedef NSAppleEventDescriptor AEDescr;
|
||||||
|
|
||||||
@@ -37,8 +39,6 @@ void set_up_apple_events(int, char*[]) {
|
|||||||
[[NSApplication sharedApplication] setDelegate: aeHandler];
|
[[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
|
@implementation AppleEventHandler
|
||||||
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file {
|
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file {
|
||||||
(void) app; // Suppress "unused parameter" warning
|
(void) app; // Suppress "unused parameter" warning
|
||||||
@@ -46,18 +46,7 @@ void set_up_apple_events(int, char*[]) {
|
|||||||
std::cerr << "Error: filename was nil" << std::endl;
|
std::cerr << "Error: filename was nil" << std::endl;
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
pending_file_to_load=file.fileSystemRepresentation;
|
||||||
if(!load_party(file.fileSystemRepresentation, univ))
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
if(!finished_init) {
|
|
||||||
ae_loading = true;
|
|
||||||
overall_mode = MODE_STARTUP;
|
|
||||||
} else finish_load_party();
|
|
||||||
if(overall_mode != MODE_STARTUP)
|
|
||||||
end_startup();
|
|
||||||
if(overall_mode != MODE_STARTUP)
|
|
||||||
post_load();
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -111,6 +111,7 @@ static void showWelcome();
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
|
eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
|
||||||
short menuChoiceId=-1;
|
short menuChoiceId=-1;
|
||||||
|
fs::path pending_file_to_load=fs::path();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@@ -268,6 +269,11 @@ void handle_events() {
|
|||||||
while(!All_Done) {
|
while(!All_Done) {
|
||||||
bool need_redraw=false;
|
bool need_redraw=false;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
if (!pending_file_to_load.empty()) {
|
||||||
|
// TODO: What if they're already in a scenario? It should ask for confirmation, right?
|
||||||
|
do_load(pending_file_to_load);
|
||||||
|
pending_file_to_load.clear();
|
||||||
|
}
|
||||||
if (menuChoiceId>=0) {
|
if (menuChoiceId>=0) {
|
||||||
eMenuChoice aMenuChoice=menuChoice;
|
eMenuChoice aMenuChoice=menuChoice;
|
||||||
menuChoice=eMenuChoice::MENU_CHOICE_NONE;
|
menuChoice=eMenuChoice::MENU_CHOICE_NONE;
|
||||||
|
Reference in New Issue
Block a user