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:
@@ -14,6 +14,7 @@
|
||||
#include <array>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "global.hpp"
|
||||
#include "keycodes.hpp"
|
||||
#include "choicedlog.hpp"
|
||||
#include "button.hpp"
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "global.hpp"
|
||||
#include "dialog.hpp"
|
||||
#include "ledgroup.hpp"
|
||||
#include "pictypes.hpp"
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "global.hpp"
|
||||
#include "control.hpp"
|
||||
#include "pictypes.hpp"
|
||||
#include "texture.hpp"
|
||||
|
@@ -15,6 +15,8 @@
|
||||
#include <SFML/System/InputStream.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
class cScenario;
|
||||
class cUniverse;
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "strdlog.hpp"
|
||||
#include "gzstream.h"
|
||||
#include "gzstream/gzstream.h"
|
||||
|
||||
#include "universe.hpp"
|
||||
#include "gfxsheets.hpp"
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include "special_parse.hpp"
|
||||
#include "gfxsheets.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "gzstream.h"
|
||||
#include "gzstream/gzstream.h"
|
||||
#include "tarball.hpp"
|
||||
|
||||
#include "porting.hpp"
|
||||
|
@@ -16,6 +16,8 @@
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
namespace ResMgr {
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
@@ -23,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 bool pending_quit;
|
||||
extern fs::path pending_file_to_load;
|
||||
|
||||
typedef NSAppleEventDescriptor AEDescr;
|
||||
@@ -57,7 +58,13 @@ void set_up_apple_events(int, char*[]) {
|
||||
All_Done = true;
|
||||
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)) {
|
||||
std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show();
|
||||
if(choice == "cancel") return NSTerminateCancel;
|
||||
@@ -70,5 +77,6 @@ void set_up_apple_events(int, char*[]) {
|
||||
|
||||
All_Done = true;
|
||||
return NSTerminateNow;
|
||||
#endif
|
||||
}
|
||||
@end
|
||||
|
@@ -105,13 +105,15 @@ cDrawableManager drawable_mgr;
|
||||
sf::Clock animTimer;
|
||||
extern long anim_ticks;
|
||||
|
||||
fs::path pending_file_to_load=fs::path();
|
||||
|
||||
static void init_boe(int, char*[]);
|
||||
static void showWelcome();
|
||||
|
||||
#ifdef __APPLE__
|
||||
eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
|
||||
short menuChoiceId=-1;
|
||||
fs::path pending_file_to_load=fs::path();
|
||||
bool pending_quit=false;
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -124,7 +126,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if(!get_bool_pref("GameRunBefore"))
|
||||
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();
|
||||
set_pref("GameRunBefore", true);
|
||||
finished_init = true;
|
||||
@@ -213,7 +215,9 @@ static void init_ui() {
|
||||
}
|
||||
|
||||
void init_boe(int argc, char* argv[]) {
|
||||
#ifdef __APPLE__
|
||||
set_up_apple_events(argc, argv);
|
||||
#endif
|
||||
init_directories(argv[0]);
|
||||
#ifdef __APPLE__
|
||||
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) {
|
||||
bool need_redraw=false;
|
||||
#ifdef __APPLE__
|
||||
if (pending_quit) {
|
||||
pending_quit=false;
|
||||
handle_menu_choice(eMenu::QUIT);
|
||||
if (All_Done) break;
|
||||
}
|
||||
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);
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include "global.hpp"
|
||||
#include "location.hpp"
|
||||
#include "texture.hpp"
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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));
|
||||
|
@@ -13,6 +13,8 @@
|
||||
#include <string>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "vector2d.hpp"
|
||||
#include "location.hpp"
|
||||
#include "special.hpp"
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
|
||||
#include "global.hpp"
|
||||
#include "location.hpp"
|
||||
#include "item_abilities.hpp"
|
||||
#include "item_variety.hpp"
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#ifndef BoE_DATA_MONSTER_ABILITIES_HPP
|
||||
#define BoE_DATA_MONSTER_ABILITIES_HPP
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "damage.hpp"
|
||||
#include "fields.hpp"
|
||||
#include "spell.hpp"
|
||||
|
@@ -12,6 +12,8 @@
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "global.hpp"
|
||||
#include "location.hpp"
|
||||
|
||||
namespace legacy { struct special_node_type; };
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
pending_file_to_load=file.fileSystemRepresentation;
|
||||
return YES;
|
||||
}
|
||||
|
||||
std::string fileName=file.fileSystemRepresentation;
|
||||
|
||||
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
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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));
|
||||
|
@@ -12,6 +12,8 @@
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
void init_snd_tool();
|
||||
bool sound_going(snd_num_t which_s);
|
||||
void play_sound(snd_num_t which, sf::Time delay = sf::Time());
|
||||
|
@@ -12,6 +12,8 @@
|
||||
#include <string>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
enum cursor_type {
|
||||
wand_curs = 0,
|
||||
eyedropper_curs = 1,
|
||||
|
@@ -13,6 +13,8 @@
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
char keyToChar(sf::Keyboard::Key key, bool isShift);
|
||||
|
||||
void makeFrontWindow(sf::Window& win);
|
||||
|
Reference in New Issue
Block a user