diff --git a/osx/scenedit/scen.actions.cpp b/osx/scenedit/scen.actions.cpp index ba0bd974..4f723581 100644 --- a/osx/scenedit/scen.actions.cpp +++ b/osx/scenedit/scen.actions.cpp @@ -250,7 +250,7 @@ bool handle_action(location the_point,sf::Event /*event*/) { if(!save_check("save-section-confirm")) break; } - x = pick_town_num("select-town-edit",cur_town); + x = pick_town_num("select-town-edit",cur_town,scenario); if(x >= 0){ cur_town = x; town = scenario.towns[cur_town]; @@ -2998,13 +2998,13 @@ void town_entry(location spot_hit) { y = -2; for(x = 0; x < 8; x++) if((current_terrain->exit_locs[x].x == spot_hit.x) && (current_terrain->exit_locs[x].y == spot_hit.y)) { - y = pick_town_num("select-town-enter",current_terrain->exit_dests[x]); + y = pick_town_num("select-town-enter",current_terrain->exit_dests[x],scenario); if(y >= 0) current_terrain->exit_dests[x] = y; } if(y == -2) { for(x = 0; x < 8; x++) if(current_terrain->exit_locs[x].x == 100) { - y = pick_town_num("select-town-enter",0); + y = pick_town_num("select-town-enter",0,scenario); if(y >= 0) { current_terrain->exit_dests[x] = y; current_terrain->exit_locs[x] = spot_hit; diff --git a/osx/scenedit/scen.main.cpp b/osx/scenedit/scen.main.cpp index 0a465f73..a71ba44f 100644 --- a/osx/scenedit/scen.main.cpp +++ b/osx/scenedit/scen.main.cpp @@ -229,6 +229,8 @@ void handle_file_menu(int item_hit) { fs::path file_to_load; switch(item_hit) { case 1: // open + if(change_made && !save_check("save-before-load")) + break; file_to_load = nav_get_scenario(); if(!file_to_load.empty() && load_scenario(file_to_load, scenario)) { cur_town = scenario.last_town_edited; diff --git a/osx/scenedit/scen.townout.cpp b/osx/scenedit/scen.townout.cpp index 1960b958..4df50140 100644 --- a/osx/scenedit/scen.townout.cpp +++ b/osx/scenedit/scen.townout.cpp @@ -15,6 +15,7 @@ #include "dlogutil.hpp" #include "winutil.h" #include "stack.hpp" +#include "fileio.h" extern short cen_x, cen_y, overall_mode;//,user_given_password; extern bool mouse_button_held,editing_town; @@ -361,16 +362,20 @@ static bool save_town_num(cDialog& me, std::string, eKeyMod) { return true; } -short pick_town_num(std::string which_dlog,short def) { +short pick_town_num(std::string which_dlog,short def,cScenario& scenario) { using namespace std::placeholders; cDialog town_dlg(which_dlog); town_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &town_dlg, false)); town_dlg["okay"].attachClickHandler(save_town_num); town_dlg["town"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.num_towns - 1, "Town number")); - town_dlg["choose"].attachClickHandler([](cDialog& me, std::string, eKeyMod) -> bool { + town_dlg["choose"].attachClickHandler([&scenario](cDialog& me, std::string, eKeyMod) -> bool { int i = me["town"].getTextAsNum(); + if(&scenario != &::scenario) + scenario.towns.swap(::scenario.towns); i = choose_text(STRT_TOWN, i, &me, "Which town?"); + if(&scenario != &::scenario) + scenario.towns.swap(::scenario.towns); me["town"].setTextToNum(i); return true; }); @@ -954,7 +959,6 @@ static void put_talk_node_in_dlog(cDialog& me, std::stack& talk_edit_stac static bool talk_node_back(cDialog& me, std::stack& talk_edit_stack) { if(!save_talk_node(me, "back", talk_edit_stack)) return true; - auto& talk_node = town->talking.talk_nodes[talk_edit_stack.top()]; talk_edit_stack.pop(); put_talk_node_in_dlog(me, talk_edit_stack); return true; @@ -1102,80 +1106,44 @@ location pick_out(location default_loc) { return default_loc; } -void new_town_event_filter (short item_hit) { -#if 0 - switch(item_hit) { - case 3: - dialog_answer = 1; - toast_dialog(); - break; - case 23: - dialog_answer = -1; - toast_dialog(); - break; - default: - cd_hit_led_range(830,11,13,item_hit); - cd_hit_led_range(830,18,20,item_hit); - break; - } -#endif -} - bool new_town(short which_town) { // ignore parent in Mac version printf("Town creation currently disabled.\n"); -// short basic_dlog_hit,i,j,store_dialog_answer; -// char temp_str[256]; -// short size = 0,preset = 0; -// -// -// cd_create_dialog_parent_num(830,0); -// -// cdsin(830,22,which_town); -// cd_set_led(830,12,1); -// cd_set_led(830,18,1); -// sprintf((char *) temp_str,"Town name"); -// CDST(830,2,(char *) temp_str); -// -// basic_dlog_hit = cd_run_dialog(); -// -// size = cd_get_led_range(830,11,13); -// preset = cd_get_led_range(830,18,20); -// CDGT(830,2,(char *) temp_str); -// temp_str[30] = 0; -// cd_kill_dialog(830,0); -// if(dialog_answer < 0) -// return false; -// -// scenario.num_towns++; -// scenario.town_size[which_town] = size; -// scenario.town_hidden[which_town] = 0; -// cur_town = which_town; -// scenario.last_town_edited = cur_town; -// init_town(size); -// strcpy(town->town_strs(0),(char *) temp_str); -// -// for(i = 0; i < max_dim[size]; i++) -// for(j = 0; j < max_dim[size]; j++) -// switch(preset) { -// case 0: -// town->terrain(i,j) = 0; -// break; -// case 1: -// town->terrain(i,j) = 2; -// break; -// case 2: -// town->terrain(i,j) = 2; -// if(get_ran(1,0,8) == 0) -// town->terrain(i,j) = 3; -// else if(get_ran(1,0,10) == 0) -// town->terrain(i,j) = 4; -// break; -// } -// -// reset_pwd(); -// return true; - return false; + short basic_dlog_hit,i,j,store_dialog_answer; + + cChoiceDlog new_dlg("new-town", {"okay", "cancel"}); + new_dlg->getControl("num").setTextToNum(which_town); + if(new_dlg.show() == "cancel") return false; + + std::string size = dynamic_cast(new_dlg->getControl("size")).getSelected(); + std::string preset = dynamic_cast(new_dlg->getControl("preset")).getSelected(); + + scenario.num_towns++; + if(size == "lg") scenario.towns.push_back(new cBigTown(scenario)); + else if(size == "med") scenario.towns.push_back(new cMedTown(scenario)); + else if(size == "sm") scenario.towns.push_back(new cTinyTown(scenario)); + + scenario.town_hidden[which_town] = 0; + cur_town = which_town; + town = scenario.towns[cur_town]; + scenario.last_town_edited = cur_town; + town->town_name = new_dlg->getControl("name").getText().substr(0,30); + + for(i = 0; i < town->max_dim(); i++) + for(j = 0; j < town->max_dim(); j++) + if(preset == "cave") { + town->terrain(i,j) = 0; + } else { + town->terrain(i,j) = 2; + if(preset == "flowers") { + if(get_ran(1,0,8) == 0) + town->terrain(i,j) = 3; + else if(get_ran(1,0,10) == 0) + town->terrain(i,j) = 4; + } + } + + return true; } // before calling this, be sure to do all checks to make sure it's safe. @@ -1188,60 +1156,13 @@ void delete_last_town() { scenario.town_data_size[scenario.num_towns][2] = 0; scenario.town_data_size[scenario.num_towns][3] = 0; scenario.town_data_size[scenario.num_towns][4] = 0; - //scenario.flag_a = 41942 /*sizeof(scenario_data_type)*/ + get_ran(1,-1000,1000); - //scenario.flag_b = town_s(user_given_password); - //scenario.flag_c = out_s(user_given_password); - //scenario.flag_e = str_size_1(user_given_password); - //scenario.flag_f = str_size_2(user_given_password); - //scenario.flag_h = str_size_3(user_given_password); - //scenario.flag_g = 10000 + get_ran(1,0,5000); - //scenario.flag_d = init_data(user_given_password); save_scenario(); } -void pick_import_town_event_filter (short item_hit) { -#if 0 - switch(item_hit) { - case 3: - dialog_answer = CDGN(841,2); - if(dialog_answer < 0) { - give_error("This number is out of the correct range. It must be at least 0.","",841); - break; - } - toast_dialog(); - break; - case 8: - dialog_answer = -1; - toast_dialog(); - break; - - } -#endif -} - short pick_import_town(short def, fs::path& temp_file_to_load) { -#if 0 - // ignore parent in Mac version - short town_strs_hit; - NavReplyRecord s_reply; - - NavChooseFile(NULL,&s_reply,NULL,NULL,NULL,NULL,NULL,NULL); - - if(!s_reply.validRecord) - return -1; - AEKeyword keyword; - DescType descType; - Size actualSize; - - AEGetNthPtr(&s_reply.selection,1,typeFSS,&keyword,&descType,&temp_file_to_load,sizeof(FSSpec),&actualSize); - - cd_create_dialog_parent_num(841,0); - - CDSN(841,2,0); - - town_strs_hit = cd_run_dialog(); - - cd_kill_dialog(841); -#endif - return 0;//dialog_answer; + cScenario temp_scenario; + temp_file_to_load = nav_get_scenario(); + load_scenario(temp_file_to_load, temp_scenario); + short town = pick_town_num("select-import-town", def, temp_scenario); + return town; } diff --git a/osx/scenedit/scen.townout.h b/osx/scenedit/scen.townout.h index f4c18366..fe036c2c 100644 --- a/osx/scenedit/scen.townout.h +++ b/osx/scenedit/scen.townout.h @@ -3,7 +3,7 @@ void edit_placed_monst(short which_m); cCreature edit_placed_monst_adv(cCreature monst_record, class cDialog& parent); void edit_sign(short which_sign,short picture); void edit_roomdescs(bool town); -short pick_town_num(std::string which_dlog,short def); +short pick_town_num(std::string which_dlog,short def,cScenario& scenario); bool change_ter(short& change_from,short& change_to,short& chance); void edit_out_wand(short mode); void outdoor_details(); diff --git a/rsrc/dialogs/new-town.xml b/rsrc/dialogs/new-town.xml new file mode 100644 index 00000000..2e15edc0 --- /dev/null +++ b/rsrc/dialogs/new-town.xml @@ -0,0 +1,40 @@ + + + + + Town name + + + Create New Town + Town name: + Town size: + + Large (64x64) + Medium (48x48) + Small (32x32) + + + + + + Preset terrain: + + Just cave floor + Plain Grass + Grass with flowers + + + + + + Creating town number: + + + + Note: Your new town will be tacked onto the end of your current town list. + + \ No newline at end of file diff --git a/rsrc/dialogs/save-before-load.xml b/rsrc/dialogs/save-before-load.xml new file mode 100644 index 00000000..5198774e --- /dev/null +++ b/rsrc/dialogs/save-before-load.xml @@ -0,0 +1,11 @@ + + + + + + + + + Save changes to your scenario before loading a new one? + + \ No newline at end of file diff --git a/rsrc/dialogs/select-import-town.xml b/rsrc/dialogs/select-import-town.xml new file mode 100644 index 00000000..aab23d91 --- /dev/null +++ b/rsrc/dialogs/select-import-town.xml @@ -0,0 +1,20 @@ + + + + + + + + Importing a town + What town do you wish to import? + + Enter a town number and hit OK, and you will be asked to select a scenario file. + The town with that number in the selected scenario will then be loaded in over the current town. + + + + Warning: This will write over the town currently in memory. + Also, the town you select must be the same size (large/medium/small) as the town currently in memory. + + + \ No newline at end of file