Editing town entrance, allow Create/Edit
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<button name='okay' type='regular' top='181' left='278'>OK</button>
|
||||
<pict type='dlog' num='16' top='8' left='8'/>
|
||||
<text size='large' top='6' left='50' width='175' height='17'>Importing a town</text>
|
||||
<text name='prompt' top='143' left='50' width='162' height='27'>What town do you wish to import?</text>
|
||||
<text name='prompt' top='143' left='50' width='162' height='27'>What town do you wish to import? (0 - {{max-num}})</text>
|
||||
<text top='27' left='50' width='301' height='54'>
|
||||
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.
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<pict type='dlog' num='16' top='8' left='8'/>
|
||||
<text size='large' top='6' left='50' width='167' height='17'>Pick Town to Edit:</text>
|
||||
<text name='prompt' top='25' left='50' width='185' height='28'>
|
||||
Enter the number of the town you want to edit next:
|
||||
Enter the number of the town you want to edit next: (0 - {{max-num}})
|
||||
</text>
|
||||
<button name='choose' type='regular' top='56' left='169'>Choose</button>
|
||||
</dialog>
|
||||
|
@@ -2,14 +2,16 @@
|
||||
<!-- NOTE: This file should be updated to use relative positioning the next time it changes. -->
|
||||
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
|
||||
<dialog defbtn='okay' escbtn='cancel'>
|
||||
<!-- OK button -->
|
||||
<field type='uint' name='town' top='71' left='119' width='62' height='16'/>
|
||||
<button name='okay' type='regular' top='95' left='206'>OK</button>
|
||||
<button name='cancel' type='regular' top='95' left='140'>Cancel</button>
|
||||
<pict type='dlog' num='16' top='8' left='8'/>
|
||||
<text size='large' top='6' left='50' width='207' height='17'>Entrance to what town?</text>
|
||||
<text name='prompt' top='25' left='50' width='213' height='42'>
|
||||
What town do you want the party to end up in when they walk into this space?
|
||||
What town do you want the party to end up in when they walk into this space? (0 - {{max-num}} for existing, {{next-num}} for new.)
|
||||
</text>
|
||||
<field type='uint' name='town' top='71' left='119' width='62' height='16'/>
|
||||
<button name='choose' type='regular' top='69' left='186'>Choose</button>
|
||||
|
||||
<button name='cancel' type='regular' top='95' left='5'>Cancel</button>
|
||||
|
||||
<button name='edit' type='large' top='95' left='100'>Create/Edit</button>
|
||||
<button name='okay' type='regular' top='95' left='206'>OK</button>
|
||||
</dialog>
|
||||
|
@@ -2456,6 +2456,7 @@ void town_entry(location spot_hit) {
|
||||
}
|
||||
}
|
||||
auto iter = std::find(current_terrain->city_locs.begin(), current_terrain->city_locs.end(), spot_hit);
|
||||
// Edit existing town entrance
|
||||
if(iter != current_terrain->city_locs.end()) {
|
||||
int town = pick_town_num("select-town-enter",iter->spec,scenario);
|
||||
if(town >= 0) iter->spec = town;
|
||||
@@ -2463,13 +2464,16 @@ void town_entry(location spot_hit) {
|
||||
iter = std::find_if(current_terrain->city_locs.begin(), current_terrain->city_locs.end(), [](const spec_loc_t& loc) {
|
||||
return loc.spec < 0;
|
||||
});
|
||||
// Find unused town entrance and fill it
|
||||
if(iter != current_terrain->city_locs.end()) {
|
||||
int town = pick_town_num("select-town-enter",0,scenario);
|
||||
if(town >= 0) {
|
||||
*iter = spot_hit;
|
||||
iter->spec = town;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// Add new town entrance at the back of list
|
||||
else {
|
||||
int town = pick_town_num("select-town-enter",0,scenario);
|
||||
if(town >= 0) {
|
||||
current_terrain->city_locs.emplace_back(spot_hit);
|
||||
|
@@ -453,17 +453,43 @@ void edit_sign(sign_loc_t& which_sign,short num,short picture) {
|
||||
}
|
||||
|
||||
static bool save_town_num(cDialog& me, std::string, eKeyMod) {
|
||||
using namespace std::placeholders;
|
||||
me["town"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.towns.size() - 1, "Town number"));
|
||||
if(me.toast(true)) me.setResult<short>(me["town"].getTextAsNum());
|
||||
return true;
|
||||
}
|
||||
|
||||
short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
|
||||
static bool create_town_num(cDialog& me, std::string, eKeyMod) {
|
||||
using namespace std::placeholders;
|
||||
me["town"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, scenario.towns.size(), "Town number"));
|
||||
if(me.toast(true)){
|
||||
int i = me["town"].getTextAsNum();
|
||||
if(i == scenario.towns.size()){
|
||||
// create town
|
||||
if(scenario.towns.size() >= 200) {
|
||||
showError("You have reached the limit of 200 towns you can have in one scenario.");
|
||||
return true;
|
||||
}
|
||||
if(!new_town()){
|
||||
// Create town canceled -- don't store the number because it is out of range
|
||||
return true;
|
||||
}
|
||||
}
|
||||
cur_town = i;
|
||||
town = scenario.towns[cur_town];
|
||||
start_town_edit();
|
||||
me.setResult<short>(i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
|
||||
|
||||
cDialog town_dlg(*ResMgr::dialogs.get(which_dlog));
|
||||
town_dlg["prompt"].replaceText("{{max-num}}", std::to_string(scenario.towns.size() - 1));
|
||||
town_dlg["prompt"].replaceText("{{next-num}}", std::to_string(scenario.towns.size()));
|
||||
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.towns.size() - 1, "Town number"));
|
||||
town_dlg["choose"].attachClickHandler([&scenario](cDialog& me, std::string, eKeyMod) -> bool {
|
||||
int i = me["town"].getTextAsNum();
|
||||
if(&scenario != &::scenario)
|
||||
@@ -474,11 +500,11 @@ short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
|
||||
me["town"].setTextToNum(i);
|
||||
return true;
|
||||
});
|
||||
if(town_dlg.hasControl("edit")){
|
||||
town_dlg["edit"].attachClickHandler(create_town_num);
|
||||
}
|
||||
|
||||
town_dlg["town"].setTextToNum(def);
|
||||
std::string prompt = town_dlg["prompt"].getText();
|
||||
prompt += " (0 - " + std::to_string(scenario.towns.size() - 1) + ')';
|
||||
town_dlg["prompt"].setText(prompt);
|
||||
|
||||
town_dlg.setResult<short>(-1);
|
||||
town_dlg.run();
|
||||
|
Reference in New Issue
Block a user