Scenario Editor: try to correct a problem when displaying terrain in zoom out mode,

Mac: add hack to avoid crashing when receiving an apple event,
+ various minor modifications
This commit is contained in:
ALONSO Laurent
2021-10-26 10:31:06 +02:00
committed by Celtic Minstrel
parent c20878ecd6
commit 2106f45840
23 changed files with 159 additions and 60 deletions

View File

@@ -8,15 +8,15 @@
#include "universe.hpp" // Include before Cocoa because the Cocoa header defines things that cause compilation errors in here
#include <Cocoa/Cocoa.h>
#include <iostream>
#include <string>
#include "fileio.hpp"
#include "pc.menus.hpp"
#include "pc.fileio.hpp"
extern bool verify_restore_quit(std::string dlog);
extern bool All_Done, party_in_scen, scen_items_loaded;
extern cUniverse univ;
extern fs::path file_in_mem;
extern bool All_Done, party_in_scen;
extern bool pending_quit;
extern fs::path pending_file_to_load;
@interface AppleEventHandler : NSObject<NSApplicationDelegate>
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file;
@@ -33,22 +33,30 @@ void set_up_apple_events(int, char*[]) {
@implementation AppleEventHandler
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file {
(void) app; // Suppress "unused parameter" warning
std::string fileName=file.fileSystemRepresentation;
if(load_party(fileName, univ)) {
file_in_mem = fileName;
party_in_scen = !univ.party.scen_name.empty();
if(!party_in_scen) load_base_item_defs();
scen_items_loaded = true;
menu_activate();
if(file == nil) {
std::cerr << "Error: filename was nil" << std::endl;
return NO;
}
return TRUE;
pending_file_to_load=file.fileSystemRepresentation;
return YES;
}
-(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender {
(void) sender; // Suppress "unused parameter" warning
// REMOVEME when we solve the causes of the crash
// note: this is actually very bad because we will cancel a shutdown,
// and this does not work if a dialog is opened, ...
// but at least this does not lead to a crash
if (!party_in_scen) {
All_Done = true;
return NSTerminateNow;
}
pending_quit=true;
return NSTerminateCancel;
#if 0
All_Done = verify_restore_quit("save-quit");
return All_Done ? NSTerminateNow : NSTerminateCancel;
#endif
}
@end

View File

@@ -29,8 +29,11 @@
#ifdef __APPLE__
short menuChoiceId=-1;
bool pending_quit=false;
#endif
fs::path pending_file_to_load=fs::path();
cUniverse univ;
rectangle pc_area_buttons[6][4] ; // 0 - whole 1 - pic 2 - name 3 - stat strs 4,5 - later
@@ -190,6 +193,25 @@ void handle_events() {
}
#ifdef __APPLE__
if (pending_quit) {
pending_quit=false;
handle_menu_choice(eMenu::QUIT);
if (All_Done)
break;
}
if (!pending_file_to_load.empty()) {
if (verify_restore_quit("save-open")) {
// FIXME: do not dupplicate this code
if (load_party(pending_file_to_load, univ)) {
file_in_mem = pending_file_to_load;
party_in_scen = !univ.party.scen_name.empty();
if(!party_in_scen) load_base_item_defs();
scen_items_loaded = true;
}
menu_activate();
}
pending_file_to_load.clear();
}
if (menuChoiceId>=0) {
need_redraw=true;
handle_menu_choice(eMenu(menuChoiceId));