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

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

View File

@@ -15,16 +15,12 @@
#include "scen.actions.hpp"
#include "scen.townout.hpp"
//extern bool ae_loading, startup_loaded, All_Done, party_in_memory, finished_init;
extern cScenario scenario;
extern cOutdoors* current_terrain;
extern location cur_out;
extern bool change_made, ae_loading;
extern bool pending_quit, change_made, All_Done;
extern fs::path pending_file_to_load;
@interface AppleEventHandler : NSObject<NSApplicationDelegate>
-(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
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?
// (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;
return NO;
}
std::string fileName=file.fileSystemRepresentation;
pending_file_to_load=file.fileSystemRepresentation;
return YES;
}
if(load_scenario(fileName, scenario)) {
set_current_town(scenario.last_town_edited);
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();
-(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender {
// 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 (!change_made) {
All_Done = true;
return NSTerminateNow;
}
return TRUE;
pending_quit=true;
return NSTerminateCancel;
}
@end

View File

@@ -82,9 +82,6 @@ rectangle terrain_rect = {0,0,340,272};
std::string current_string[2];
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){
short icon = -1;
auto const &ter_type=scenario.get_terrain(ter);
@@ -930,37 +927,50 @@ void draw_terrain(){
}
clip_rect(mainPtr, terrain_rect);
small_any_drawn = false;
//if(cur_viewing_mode == 0)
// draw_frames();
}
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]);
frame_rect(mainPtr, terrain_rect, sf::Color::Black);
// 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
short size = mini_map_scales[cur_viewing_mode - 1];
int max_dim = (editing_town ? town->max_dim : 48);
int xMin = 0, yMin = 0, xMax = max_dim, yMax = max_dim;
if(cen_x + 5 > 256 / size) {
xMin = cen_x + 5 - (256 / size);
xMax = cen_x + 5;
} else xMax = std::min(xMax, 256 / size);
if(cen_y + 5 > 324 / size) {
yMin = cen_y + 5 - (324 / size);
yMax = cen_y + 5;
} else yMax = std::min(yMax, 324 / size);
// std::cout << "Drawing map for x = " << xMin << "..." << xMax << " and y = " << yMin << "..." << yMax << std::endl;
short const size = cur_viewing_mode<3 ? mini_map_scales[cur_viewing_mode - 1] : 12;
int const max_dim = (editing_town ? town->max_dim : 48);
int const xNumTiles=(256 / size);
int xMin = cen_x-(xNumTiles/2), xMax = xMin+xNumTiles;
if (xMin<0) {
xMin=0;
xMax=std::min(xNumTiles, max_dim);
cen_x=(xNumTiles/2);
}
else if (xMax>max_dim) {
xMax=max_dim;
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 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;
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));
small_what_drawn[q][r] = t_to_draw;
}
small_any_drawn = true;
}
}

View File

@@ -36,8 +36,11 @@
#ifdef __APPLE__
short menuChoiceId=-1;
bool pending_quit=false;
#endif
fs::path pending_file_to_load=fs::path();
/* Globals */
bool All_Done = false;
bool changed_display_mode = false;
@@ -249,6 +252,29 @@ 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() && 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) {
need_redraw = true;
handle_menu_choice(eMenu(menuChoiceId));