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

@@ -14,6 +14,7 @@
#include <array> #include <array>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include "global.hpp"
#include "keycodes.hpp" #include "keycodes.hpp"
#include "choicedlog.hpp" #include "choicedlog.hpp"
#include "button.hpp" #include "button.hpp"

View File

@@ -13,6 +13,7 @@
#include <functional> #include <functional>
#include <utility> #include <utility>
#include "global.hpp"
#include "dialog.hpp" #include "dialog.hpp"
#include "ledgroup.hpp" #include "ledgroup.hpp"
#include "pictypes.hpp" #include "pictypes.hpp"

View File

@@ -16,6 +16,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include "global.hpp"
#include "control.hpp" #include "control.hpp"
#include "pictypes.hpp" #include "pictypes.hpp"
#include "texture.hpp" #include "texture.hpp"

View File

@@ -15,6 +15,8 @@
#include <SFML/System/InputStream.hpp> #include <SFML/System/InputStream.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include "global.hpp"
class cScenario; class cScenario;
class cUniverse; class cUniverse;

View File

@@ -12,7 +12,7 @@
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include "strdlog.hpp" #include "strdlog.hpp"
#include "gzstream.h" #include "gzstream/gzstream.h"
#include "universe.hpp" #include "universe.hpp"
#include "gfxsheets.hpp" #include "gfxsheets.hpp"

View File

@@ -20,7 +20,7 @@
#include "special_parse.hpp" #include "special_parse.hpp"
#include "gfxsheets.hpp" #include "gfxsheets.hpp"
#include "mathutil.hpp" #include "mathutil.hpp"
#include "gzstream.h" #include "gzstream/gzstream.h"
#include "tarball.hpp" #include "tarball.hpp"
#include "porting.hpp" #include "porting.hpp"

View File

@@ -16,6 +16,8 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include "global.hpp"
namespace ResMgr { namespace ResMgr {
namespace fs = boost::filesystem; namespace fs = boost::filesystem;

View File

@@ -23,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 bool pending_quit;
extern fs::path pending_file_to_load; extern fs::path pending_file_to_load;
typedef NSAppleEventDescriptor AEDescr; typedef NSAppleEventDescriptor AEDescr;
@@ -57,7 +58,13 @@ void set_up_apple_events(int, char*[]) {
All_Done = true; All_Done = true;
return NSTerminateNow; return NSTerminateNow;
} }
// 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
pending_quit=true;
return NSTerminateCancel;
#if 0
if(overall_mode == MODE_TOWN || overall_mode == MODE_OUTDOORS || (overall_mode == MODE_STARTUP && party_in_memory)) { if(overall_mode == MODE_TOWN || overall_mode == MODE_OUTDOORS || (overall_mode == MODE_STARTUP && party_in_memory)) {
std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show(); std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show();
if(choice == "cancel") return NSTerminateCancel; if(choice == "cancel") return NSTerminateCancel;
@@ -70,5 +77,6 @@ void set_up_apple_events(int, char*[]) {
All_Done = true; All_Done = true;
return NSTerminateNow; return NSTerminateNow;
#endif
} }
@end @end

View File

@@ -105,13 +105,15 @@ cDrawableManager drawable_mgr;
sf::Clock animTimer; sf::Clock animTimer;
extern long anim_ticks; extern long anim_ticks;
fs::path pending_file_to_load=fs::path();
static void init_boe(int, char*[]); static void init_boe(int, char*[]);
static void showWelcome(); 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(); bool pending_quit=false;
#endif #endif
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@@ -124,7 +126,7 @@ int main(int argc, char* argv[]) {
if(!get_bool_pref("GameRunBefore")) if(!get_bool_pref("GameRunBefore"))
showWelcome(); showWelcome();
else if(get_bool_pref("GiveIntroHint", true)) else if(!ae_loading && pending_file_to_load.empty() && get_bool_pref("GiveIntroHint", true))
tip_of_day(); tip_of_day();
set_pref("GameRunBefore", true); set_pref("GameRunBefore", true);
finished_init = true; finished_init = true;
@@ -213,7 +215,9 @@ static void init_ui() {
} }
void init_boe(int argc, char* argv[]) { void init_boe(int argc, char* argv[]) {
#ifdef __APPLE__
set_up_apple_events(argc, argv); set_up_apple_events(argc, argv);
#endif
init_directories(argv[0]); init_directories(argv[0]);
#ifdef __APPLE__ #ifdef __APPLE__
init_menubar(); // Do this first of all because otherwise a default File and Window menu will be seen init_menubar(); // Do this first of all because otherwise a default File and Window menu will be seen
@@ -269,6 +273,11 @@ void handle_events() {
while(!All_Done) { while(!All_Done) {
bool need_redraw=false; bool need_redraw=false;
#ifdef __APPLE__ #ifdef __APPLE__
if (pending_quit) {
pending_quit=false;
handle_menu_choice(eMenu::QUIT);
if (All_Done) break;
}
if (!pending_file_to_load.empty()) { if (!pending_file_to_load.empty()) {
// TODO: What if they're already in a scenario? It should ask for confirmation, right? // TODO: What if they're already in a scenario? It should ask for confirmation, right?
do_load(pending_file_to_load); do_load(pending_file_to_load);

View File

@@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <SFML/Graphics/Texture.hpp> #include <SFML/Graphics/Texture.hpp>
#include "global.hpp"
#include "location.hpp" #include "location.hpp"
#include "texture.hpp" #include "texture.hpp"

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 "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 <iostream>
#include <string> #include <string>
#include "fileio.hpp" #include "fileio.hpp"
#include "pc.menus.hpp" #include "pc.menus.hpp"
#include "pc.fileio.hpp" #include "pc.fileio.hpp"
extern bool verify_restore_quit(std::string dlog); extern bool All_Done, party_in_scen;
extern bool All_Done, party_in_scen, scen_items_loaded; extern bool pending_quit;
extern cUniverse univ; extern fs::path pending_file_to_load;
extern fs::path file_in_mem;
@interface AppleEventHandler : NSObject<NSApplicationDelegate> @interface AppleEventHandler : NSObject<NSApplicationDelegate>
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file; -(BOOL)application:(NSApplication*) app openFile:(NSString*) file;
@@ -33,22 +33,30 @@ void set_up_apple_events(int, char*[]) {
@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
if(file == nil) {
std::string fileName=file.fileSystemRepresentation; std::cerr << "Error: filename was nil" << std::endl;
if(load_party(fileName, univ)) { return NO;
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();
} }
return TRUE; pending_file_to_load=file.fileSystemRepresentation;
return YES;
} }
-(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender { -(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender {
(void) sender; // Suppress "unused parameter" warning (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"); All_Done = verify_restore_quit("save-quit");
return All_Done ? NSTerminateNow : NSTerminateCancel; return All_Done ? NSTerminateNow : NSTerminateCancel;
#endif
} }
@end @end

View File

@@ -29,8 +29,11 @@
#ifdef __APPLE__ #ifdef __APPLE__
short menuChoiceId=-1; short menuChoiceId=-1;
bool pending_quit=false;
#endif #endif
fs::path pending_file_to_load=fs::path();
cUniverse univ; cUniverse univ;
rectangle pc_area_buttons[6][4] ; // 0 - whole 1 - pic 2 - name 3 - stat strs 4,5 - later 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__ #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) { if (menuChoiceId>=0) {
need_redraw=true; need_redraw=true;
handle_menu_choice(eMenu(menuChoiceId)); handle_menu_choice(eMenu(menuChoiceId));

View File

@@ -13,6 +13,8 @@
#include <string> #include <string>
#include <boost/dynamic_bitset.hpp> #include <boost/dynamic_bitset.hpp>
#include "global.hpp"
#include "vector2d.hpp" #include "vector2d.hpp"
#include "location.hpp" #include "location.hpp"
#include "special.hpp" #include "special.hpp"

View File

@@ -12,6 +12,7 @@
#include <string> #include <string>
#include <iosfwd> #include <iosfwd>
#include "global.hpp"
#include "location.hpp" #include "location.hpp"
#include "item_abilities.hpp" #include "item_abilities.hpp"
#include "item_variety.hpp" #include "item_variety.hpp"

View File

@@ -9,6 +9,8 @@
#ifndef BoE_DATA_MONSTER_ABILITIES_HPP #ifndef BoE_DATA_MONSTER_ABILITIES_HPP
#define BoE_DATA_MONSTER_ABILITIES_HPP #define BoE_DATA_MONSTER_ABILITIES_HPP
#include "global.hpp"
#include "damage.hpp" #include "damage.hpp"
#include "fields.hpp" #include "fields.hpp"
#include "spell.hpp" #include "spell.hpp"

View File

@@ -12,6 +12,8 @@
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
#include <functional> #include <functional>
#include "global.hpp"
#include "location.hpp" #include "location.hpp"
namespace legacy { struct special_node_type; }; namespace legacy { struct special_node_type; };

View File

@@ -59,7 +59,6 @@ extern std::shared_ptr<cScrollbar> right_sbar, pal_sbar;
extern cOutdoors* current_terrain; extern cOutdoors* current_terrain;
extern location cur_out; extern location cur_out;
extern sf::RenderWindow mainPtr; extern sf::RenderWindow mainPtr;
bool small_any_drawn = false;
extern bool change_made; extern bool change_made;
rectangle left_buttons[NLS][2]; // 0 - whole, 1 - blue button rectangle left_buttons[NLS][2]; // 0 - whole, 1 - blue button
@@ -2321,7 +2320,6 @@ void set_up_main_screen() {
void start_town_edit() { void start_town_edit() {
std::ostringstream strb; std::ostringstream strb;
small_any_drawn = false;
cen_x = town->max_dim / 2; cen_x = town->max_dim / 2;
cen_y = town->max_dim / 2; cen_y = town->max_dim / 2;
reset_lb(); reset_lb();
@@ -2351,7 +2349,6 @@ void start_town_edit() {
void start_out_edit() { void start_out_edit() {
std::ostringstream strb; std::ostringstream strb;
small_any_drawn = false;
cen_x = 24; cen_x = 24;
cen_y = 24; cen_y = 24;
reset_lb(); reset_lb();

View File

@@ -15,16 +15,12 @@
#include "scen.actions.hpp" #include "scen.actions.hpp"
#include "scen.townout.hpp" #include "scen.townout.hpp"
//extern bool ae_loading, startup_loaded, All_Done, party_in_memory, finished_init; extern bool pending_quit, change_made, All_Done;
extern cScenario scenario; extern fs::path pending_file_to_load;
extern cOutdoors* current_terrain;
extern location cur_out;
extern bool change_made, ae_loading;
@interface AppleEventHandler : NSObject<NSApplicationDelegate> @interface AppleEventHandler : NSObject<NSApplicationDelegate>
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file; -(BOOL)application:(NSApplication*) app openFile:(NSString*) file;
// TODO: Handle quit event by putting up quit dialog -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender;
//-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender;
@end @end
void set_up_apple_events(int argc, char* argv[]); // Suppress "no prototype" warning void set_up_apple_events(int argc, char* argv[]); // Suppress "no prototype" warning
@@ -35,25 +31,27 @@ void set_up_apple_events(int, char*[]) {
} }
// TODO: What if they're already in a scenario? It should ask for confirmation, right? // 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
if(file == nil) { if(file == nil) {
std::cerr << "Error: filename was nil" << std::endl; std::cerr << "Error: filename was nil" << std::endl;
return FALSE; return NO;
} }
pending_file_to_load=file.fileSystemRepresentation;
std::string fileName=file.fileSystemRepresentation; return YES;
}
if(load_scenario(fileName, scenario)) { -(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender {
set_current_town(scenario.last_town_edited); // REMOVEME when we solve the causes of the crash
cur_out = scenario.last_out_edited; // note: this is actually very bad because we will cancel a shutdown,
current_terrain = scenario.outdoors[cur_out.x][cur_out.y]; // and this does not work if a dialog is opened, ...
change_made = false; // but at least this does not lead to a crash
ae_loading = true; if (!change_made) {
set_up_main_screen(); All_Done = true;
return NSTerminateNow;
} }
return TRUE; pending_quit=true;
return NSTerminateCancel;
} }
@end @end

View File

@@ -82,9 +82,6 @@ rectangle terrain_rect = {0,0,340,272};
std::string current_string[2]; std::string current_string[2];
extern rectangle terrain_rects[256]; extern rectangle terrain_rects[256];
unsigned char small_what_drawn[64][64];
extern bool small_any_drawn;
static short get_small_icon(ter_num_t ter){ static short get_small_icon(ter_num_t ter){
short icon = -1; short icon = -1;
auto const &ter_type=scenario.get_terrain(ter); auto const &ter_type=scenario.get_terrain(ter);
@@ -930,37 +927,50 @@ void draw_terrain(){
} }
clip_rect(mainPtr, terrain_rect); clip_rect(mainPtr, terrain_rect);
small_any_drawn = false;
//if(cur_viewing_mode == 0) //if(cur_viewing_mode == 0)
// draw_frames(); // draw_frames();
} }
else { else {
// fixme: the bounds are now correct and the scrolling must be fluid,
// however, the procedure which displays is still bad
tileImage(mainPtr, terrain_rect,bg[17]); tileImage(mainPtr, terrain_rect,bg[17]);
frame_rect(mainPtr, terrain_rect, sf::Color::Black); frame_rect(mainPtr, terrain_rect, sf::Color::Black);
// Width available: 64 4x4 tiles, 42 6x6 tiles, or 21 12x12 tiles -- 256 pixels // Width available: 64 4x4 tiles, 42 6x6 tiles, or 21 12x12 tiles -- 256 pixels
// Height available: 81 4x4 tiles, 54 6x6 tiles, or 27 12x12 tiles -- 324 pixels // Height available: 81 4x4 tiles, 54 6x6 tiles, or 27 12x12 tiles -- 324 pixels
short size = mini_map_scales[cur_viewing_mode - 1]; short const size = cur_viewing_mode<3 ? mini_map_scales[cur_viewing_mode - 1] : 12;
int max_dim = (editing_town ? town->max_dim : 48); int const max_dim = (editing_town ? town->max_dim : 48);
int xMin = 0, yMin = 0, xMax = max_dim, yMax = max_dim; int const xNumTiles=(256 / size);
if(cen_x + 5 > 256 / size) { int xMin = cen_x-(xNumTiles/2), xMax = xMin+xNumTiles;
xMin = cen_x + 5 - (256 / size); if (xMin<0) {
xMax = cen_x + 5; xMin=0;
} else xMax = std::min(xMax, 256 / size); xMax=std::min(xNumTiles, max_dim);
if(cen_y + 5 > 324 / size) { cen_x=(xNumTiles/2);
yMin = cen_y + 5 - (324 / size); }
yMax = cen_y + 5; else if (xMax>max_dim) {
} else yMax = std::min(yMax, 324 / size); xMax=max_dim;
// std::cout << "Drawing map for x = " << xMin << "..." << xMax << " and y = " << yMin << "..." << yMax << std::endl; xMin=std::max(0, xMax-xNumTiles);
cen_x=xMin+(xNumTiles/2);
}
int const yNumTiles=(324 / size);
int yMin = cen_y-(yNumTiles/2), yMax = yMin+yNumTiles;
if (yMin<0) {
yMin=0;
yMax=std::min(yNumTiles, max_dim);
cen_y=(yNumTiles/2);
}
else if (yMax>max_dim) {
yMax=max_dim;
yMin=std::max(0, yMax-yNumTiles);
cen_y=yMin+(yNumTiles/2);
}
for(short q = xMin; q < xMax; q++) for(short q = xMin; q < xMax; q++)
for(short r = yMin; r < yMax; r++) { for(short r = yMin; r < yMax; r++) {
if(q - xMin < 0 || q - xMin >= max_dim || r - yMin < 0 || r - yMin >= max_dim) if(q < 0 || q >= max_dim || r < 0 || r >= max_dim)
t_to_draw = 90; t_to_draw = 90;
else t_to_draw = editing_town ? town->terrain(q,r) : current_terrain->terrain[q][r]; else t_to_draw = editing_town ? town->terrain(q,r) : current_terrain->terrain(q,r);
draw_one_tiny_terrain_spot(q-xMin,r-yMin,t_to_draw,size,is_road(q,r)); draw_one_tiny_terrain_spot(q-xMin,r-yMin,t_to_draw,size,is_road(q,r));
small_what_drawn[q][r] = t_to_draw;
} }
small_any_drawn = true;
} }
} }

View File

@@ -36,8 +36,11 @@
#ifdef __APPLE__ #ifdef __APPLE__
short menuChoiceId=-1; short menuChoiceId=-1;
bool pending_quit=false;
#endif #endif
fs::path pending_file_to_load=fs::path();
/* Globals */ /* Globals */
bool All_Done = false; bool All_Done = false;
bool changed_display_mode = false; bool changed_display_mode = false;
@@ -249,6 +252,29 @@ void handle_events() {
} }
#ifdef __APPLE__ #ifdef __APPLE__
if (pending_quit) {
pending_quit=false;
handle_menu_choice(eMenu::QUIT);
if (All_Done)
break;
}
if (!pending_file_to_load.empty() && save_check("save-before-load")) {
// FIXME: do not dupplicate this code another time
if(load_scenario(pending_file_to_load, 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];
overall_mode = MODE_MAIN_SCREEN;
change_made = false;
set_up_main_screen();
} else
set_up_start_screen(); // Failed to load file, dump to start
extern cUndoList undo_list;
undo_list.clear();
update_edit_menu();
pending_file_to_load.clear();
}
if (menuChoiceId>=0) { if (menuChoiceId>=0) {
need_redraw = true; need_redraw = true;
handle_menu_choice(eMenu(menuChoiceId)); handle_menu_choice(eMenu(menuChoiceId));

View File

@@ -12,6 +12,8 @@
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <string> #include <string>
#include "global.hpp"
void init_snd_tool(); void init_snd_tool();
bool sound_going(snd_num_t which_s); bool sound_going(snd_num_t which_s);
void play_sound(snd_num_t which, sf::Time delay = sf::Time()); void play_sound(snd_num_t which, sf::Time delay = sf::Time());

View File

@@ -12,6 +12,8 @@
#include <string> #include <string>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include "global.hpp"
enum cursor_type { enum cursor_type {
wand_curs = 0, wand_curs = 0,
eyedropper_curs = 1, eyedropper_curs = 1,

View File

@@ -13,6 +13,8 @@
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/Graphics/Image.hpp> #include <SFML/Graphics/Image.hpp>
#include "global.hpp"
char keyToChar(sf::Keyboard::Key key, bool isShift); char keyToChar(sf::Keyboard::Key key, bool isShift);
void makeFrontWindow(sf::Window& win); void makeFrontWindow(sf::Window& win);