game[mac]: try to make openFile's apple event works...

This commit is contained in:
ALONSO Laurent
2021-10-25 10:37:51 +02:00
committed by Celtic Minstrel
parent 66ad6bdefa
commit c20878ecd6
4 changed files with 13 additions and 17 deletions

View File

@@ -2180,8 +2180,9 @@ bool handle_scroll(const sf::Event& event) {
return true;
}
void do_load() {
fs::path file_to_load = nav_get_party();
void do_load(fs::path const &file_name) {
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(!load_party(file_to_load, univ))
return;

View File

@@ -14,7 +14,7 @@ void handle_menu_spell(short spell_picked,short spell_type) ;
void initiate_outdoor_combat(short i);
bool handle_keystroke(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 do_save(short mode);
void increase_age();

View File

@@ -7,6 +7,7 @@
//
#include "universe.hpp" // Include before Cocoa because the Cocoa header defines things that cause compilation errors in here
#include <Cocoa/Cocoa.h>
#include <memory>
#include <algorithm>
@@ -22,6 +23,7 @@ extern void post_load();
extern bool ae_loading, All_Done, party_in_memory, finished_init;
extern eGameMode overall_mode;
extern cUniverse univ;
extern fs::path pending_file_to_load;
typedef NSAppleEventDescriptor AEDescr;
@@ -37,8 +39,6 @@ void set_up_apple_events(int, char*[]) {
[[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
@@ -46,18 +46,7 @@ void set_up_apple_events(int, char*[]) {
std::cerr << "Error: filename was nil" << std::endl;
return NO;
}
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();
pending_file_to_load=file.fileSystemRepresentation;
return YES;
}

View File

@@ -111,6 +111,7 @@ static void showWelcome();
#ifdef __APPLE__
eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
short menuChoiceId=-1;
fs::path pending_file_to_load=fs::path();
#endif
int main(int argc, char* argv[]) {
@@ -268,6 +269,11 @@ void handle_events() {
while(!All_Done) {
bool need_redraw=false;
#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) {
eMenuChoice aMenuChoice=menuChoice;
menuChoice=eMenuChoice::MENU_CHOICE_NONE;