Scenario Editor: display town's name when selecting a town...

This commit is contained in:
Laurent alonso
2021-11-07 09:23:30 +01:00
committed by Celtic Minstrel
parent 2ad286b12d
commit baa0bf81c4
4 changed files with 24 additions and 7 deletions

View File

@@ -3,12 +3,13 @@
<dialog defbtn='okay'> <dialog defbtn='okay'>
<!-- OK button --> <!-- OK button -->
<field type='uint' name='town' top='58' left='102' width='62' height='16'/> <field type='uint' name='town' top='58' left='102' width='62' height='16'/>
<button name='okay' type='regular' top='82' left='177'>OK</button> <button name='okay' type='regular' top='114' left='177'>OK</button>
<button name='cancel' type='regular' top='82' left='111'>Cancel</button> <button name='cancel' type='regular' top='114' left='111'>Cancel</button>
<pict type='dlog' num='16' top='8' left='8'/> <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 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'> <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:
</text> </text>
<button name='choose' type='regular' top='56' left='169'>Choose</button> <button name='choose' type='regular' top='56' left='169'>Choose</button>
<text name='name' framed='true' top='87' left='50' width='213' height='20'/>
</dialog> </dialog>

View File

@@ -3,12 +3,13 @@
<dialog defbtn='okay'> <dialog defbtn='okay'>
<!-- OK button --> <!-- OK button -->
<field type='uint' name='town' top='71' left='119' width='62' height='16'/> <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='okay' type='regular' top='127' left='206'>OK</button>
<button name='cancel' type='regular' top='95' left='140'>Cancel</button> <button name='cancel' type='regular' top='127' left='140'>Cancel</button>
<pict type='dlog' num='16' top='8' left='8'/> <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 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'> <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?
</text> </text>
<button name='choose' type='regular' top='69' left='186'>Choose</button> <button name='choose' type='regular' top='69' left='186'>Choose</button>
<text name='name' framed='true' top='100' left='50' width='213' height='20'/>
</dialog> </dialog>

View File

@@ -814,12 +814,13 @@ void draw_terrain(short mode) {
if((can_draw != 0) && (overall_mode != MODE_RESTING)) { // if can see, not a pit, and not resting if((can_draw != 0) && (overall_mode != MODE_RESTING)) { // if can see, not a pit, and not resting
if(is_combat()) anim_ticks = 0; if(is_combat()) anim_ticks = 0;
eTrimType trim = univ.get_terrain(spec_terrain).trim_type; auto const &terrain=univ.get_terrain(spec_terrain);
eTrimType trim = terrain.trim_type;
// Finally, draw this terrain spot // Finally, draw this terrain spot
if(trim == eTrimType::WALKWAY){ if(trim == eTrimType::WALKWAY){
int trim = -1; int trim = -1;
unsigned short ground_t = univ.get_terrain(spec_terrain).trim_ter; unsigned short ground_t = terrain.trim_ter;
ter_num_t ground_ter = univ.scenario.get_ter_from_ground(ground_t); ter_num_t ground_ter = univ.scenario.get_ter_from_ground(ground_t);
if(!loc_off_act_area(where_draw)) { if(!loc_off_act_area(where_draw)) {
if(is_nature(where_draw.x - 1,where_draw.y,ground_t)){ // check left if(is_nature(where_draw.x - 1,where_draw.y,ground_t)){ // check left

View File

@@ -381,13 +381,24 @@ static bool save_town_num(cDialog& me, std::string, eKeyMod) {
return true; return true;
} }
static bool check_range_and_update_town_name(cDialog& me,std::string id,bool losing,std::vector<cTown*> const &towns)
{
if (!check_range_msg(me, id, losing, 0, long(towns.size())-1, "Town number", "")) {
me["name"].setText("");
return false;
}
int i = me["town"].getTextAsNum();
me["name"].setText((i>=0 && i<towns.size()) ? towns[i]->name : "");
return true;
}
short pick_town_num(std::string which_dlog,short def,cScenario& scenario) { short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
using namespace std::placeholders; using namespace std::placeholders;
cDialog town_dlg(which_dlog); cDialog town_dlg(which_dlog);
town_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &town_dlg, false)); town_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &town_dlg, false));
town_dlg["okay"].attachClickHandler(save_town_num); 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["town"].attachFocusHandler(std::bind(check_range_and_update_town_name, _1, _2, _3, scenario.towns));
town_dlg["choose"].attachClickHandler([&scenario](cDialog& me, std::string, eKeyMod) -> bool { town_dlg["choose"].attachClickHandler([&scenario](cDialog& me, std::string, eKeyMod) -> bool {
int i = me["town"].getTextAsNum(); int i = me["town"].getTextAsNum();
if(&scenario != &::scenario) if(&scenario != &::scenario)
@@ -396,10 +407,13 @@ short pick_town_num(std::string which_dlog,short def,cScenario& scenario) {
if(&scenario != &::scenario) if(&scenario != &::scenario)
scenario.towns.swap(::scenario.towns); scenario.towns.swap(::scenario.towns);
me["town"].setTextToNum(i); me["town"].setTextToNum(i);
me["name"].setText((i>=0 && i<scenario.towns.size()) ? scenario.towns[i]->name : "");
return true; return true;
}); });
town_dlg["town"].setTextToNum(def); town_dlg["town"].setTextToNum(def);
if (def>=0 && def<scenario.towns.size())
town_dlg["name"].setText(scenario.towns[def]->name);
std::string prompt = town_dlg["prompt"].getText(); std::string prompt = town_dlg["prompt"].getText();
prompt += " (0 - " + std::to_string(scenario.towns.size() - 1) + ')'; prompt += " (0 - " + std::to_string(scenario.towns.size() - 1) + ')';
town_dlg["prompt"].setText(prompt); town_dlg["prompt"].setText(prompt);