Lots of little tweaks and fixes to various things, mostly dialog stuff.

- LED groups now trigger their own click handler in addition to the clicked LED's click handler (provided the latter returns true). If the handler returns false, the click has no effect.
- LED groups now cancel the selection change if their focus handler returns false; this mimics the behaviour when an individual LED's focus handler returns false.
- Move the dialog getResult() definitions inline - since there's only two of them now that I'm using boost::any, having them in a separate file is pointless.
- Changed how the pict choice dialog returns its result - now it returns only whether the user clicked cancel and provides getters to obtain the number and type.
- Pict and string choice dialogs now hide the arrow buttons when there is only one page of options.
- Fix pict choice dialog always returning the initially selected value (similar to how the string choice dialog did before I fixed it)
- When passed an invalid starting selection, the pict choice dialog now always starts with the first icon selected
- Fix wrong bounds for several typs of custom graphics in dialogs
- Fix wrong /source/ bounds for custom 28x36 graphics /everywhere in the game/.
- Fix select PC graphic dialog having a second page with an invalid graphic that can be selected.
This commit is contained in:
2014-12-05 23:48:07 -05:00
parent 4db81f1403
commit 56f73cb156
15 changed files with 128 additions and 107 deletions

View File

@@ -220,6 +220,7 @@ static bool check_range(cDialog& me,std::string id,bool losing,long min_val,long
return check_range_msg(me, id, losing, min_val, max_val, fld_name, "");
}
// TODO: I have two functions that do this. (The other one is choose_graphic.)
static bool pick_picture(ePicType type, cDialog& parent, std::string result_fld, std::string pic_fld, pic_num_t modifier){
pic_num_t cur_sel = 0;
if(result_fld != ""){
@@ -232,7 +233,7 @@ static bool pick_picture(ePicType type, cDialog& parent, std::string result_fld,
cur_sel = pic_ctrl.getPicNum();
}
pic_num_t pic = choose_graphic(cur_sel, type, &parent);
if(pic < NO_PIC){
if(pic != NO_PIC){
if(result_fld != ""){
cTextField& fld_ctrl = dynamic_cast<cTextField&>(parent[result_fld]);
fld_ctrl.setTextToNum(pic + modifier);
@@ -254,7 +255,7 @@ static bool pick_string(std::string from_file, cDialog& parent, std::string resu
StringRsrc strings = *ResMgr::get<StringRsrc>(from_file);
// TODO: Does it need a title?
cStringChoice str_dlg(strings, "", &parent);
size_t result = str_dlg.show(strings[cur_sel]);
size_t result = str_dlg.show(cur_sel);
if(result < strings.size()){
if(result_fld != ""){
cTextField& fld_ctrl = dynamic_cast<cTextField&>(parent[result_fld]);

View File

@@ -517,7 +517,7 @@ void set_up_terrain_buttons() {
pic = scenario.ter_types[i].picture;
if (pic >= 1000) {
sf::Texture* source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
rect_draw_some_item(*source_gworld,
ter_from,terrain_buttons_gworld,terrain_rects[i]);
}

View File

@@ -106,15 +106,17 @@ bool cre(short val,short min,short max,const char *text1,const char *text2,cDial
return false;
}
// TODO: I have two functions that do this. (The other one is pick_picture.)
pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) {
pic_num_t item_hit = 0;
int i = 0;
std::vector<std::pair<pic_num_t,ePicType>> pics;
cPictChoice* pic_dlg = nullptr;
switch(g_type) {
case PIC_TER: // TODO: Increase upper limit to allow picking of the added graphics
item_hit = cPictChoice(0, 252, PIC_TER, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 252, PIC_TER, parent);
break;
case PIC_TER_ANIM: // TODO: Increase to allow picking of the added graphics
item_hit = cPictChoice(0, 13, PIC_TER_ANIM, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 13, PIC_TER_ANIM, parent);
break;
case PIC_MONST:
case PIC_MONST_WIDE:
@@ -125,51 +127,51 @@ pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) {
ePicType type = PIC_MONST;
if(m_pic.x == 2) type += PIC_WIDE;
if(m_pic.y == 2) type += PIC_TALL;
pics.push_back({item_hit++, type});
pics.push_back({i++, type});
}
item_hit = cPictChoice(pics, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(pics, parent);
break;
case PIC_DLOG: // TODO: Increase upper limit to allow picking of the added graphics
item_hit = cPictChoice(0, 31, PIC_DLOG, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 31, PIC_DLOG, parent);
break;
case PIC_TALK:
item_hit = cPictChoice(0, 83, PIC_TALK, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 83, PIC_TALK, parent);
break;
case PIC_SCEN:
item_hit = cPictChoice(0, 29, PIC_SCEN, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 29, PIC_SCEN, parent);
break;
case PIC_ITEM:
item_hit = cPictChoice(0, 122, PIC_ITEM, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 122, PIC_ITEM, parent);
break;
case PIC_PC:
item_hit = cPictChoice(0, 35, PIC_PC, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 35, PIC_PC, parent);
break;
case PIC_FIELD:
item_hit = cPictChoice(field_pics, PIC_FIELD, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(field_pics, PIC_FIELD, parent);
break;
case PIC_BOOM:
item_hit = cPictChoice(boom_pics, PIC_BOOM, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(boom_pics, PIC_BOOM, parent);
break;
case PIC_DLOG_LG:
item_hit = cPictChoice(lgdlog_pics, PIC_DLOG_LG, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(lgdlog_pics, PIC_DLOG_LG, parent);
break;
case PIC_FULL:
// TODO: Should this be handled at all?
break;
case PIC_MISSILE:
item_hit = cPictChoice(0, 15, PIC_MISSILE, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 15, PIC_MISSILE, parent);
break;
case PIC_STATUS:
item_hit = cPictChoice(0, 17, PIC_STATUS, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 17, PIC_STATUS, parent);
break;
case PIC_SCEN_LG:
item_hit = cPictChoice(0, 3, PIC_SCEN_LG, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 3, PIC_SCEN_LG, parent);
break;
case PIC_TER_MAP:
item_hit = cPictChoice(0, 418, PIC_TER_MAP, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, 418, PIC_TER_MAP, parent);
break;
default: // Custom or party; assume custom, since this is the scenario editor and the party sheet isn't available
if(g_type & PIC_PARTY) return NO_PIC;
if(g_type & PIC_PARTY) break;
ePicType g_base_type = g_type - PIC_CUSTOM;
pic_num_t totalPics = spec_scen_g.count();
pic_num_t last;
@@ -182,9 +184,13 @@ pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) {
else if(g_base_type == PIC_MONST_LG) last = totalPics - 16;
else if(g_base_type == PIC_TER_MAP) last = totalPics * 6 - 1; // TODO: Check this formula
else last = totalPics = 1;
item_hit = cPictChoice(0, last, g_type, parent).show(NO_PIC, cur_choice);
pic_dlg = new cPictChoice(0, last, g_type, parent);
}
return item_hit;
if(!pic_dlg) return cur_choice;
bool made_choice = pic_dlg->show(cur_choice);
pic_num_t item_hit = pic_dlg->getPicChosen();
delete pic_dlg;
return made_choice ? item_hit : NO_PIC;
}
short choose_text_res(std::string res_list,short first_t,short last_t,unsigned short cur_choice,cDialog* parent,const char *title) {
@@ -642,7 +648,7 @@ static bool edit_spec_enc_event_filter(cDialog& me, std::string item_hit, short&
i = choose_graphic(store_spec_node.pic,PIC_MONST,&me);
break;
}
if(i < NO_PIC) {
if(i != NO_PIC) {
store_spec_node.pic = i;
put_spec_enc_in_dlog(me, which_node);
}
@@ -1057,9 +1063,9 @@ static bool edit_scen_intro_event_filter(cDialog& me, std::string item_hit, eKey
} else if(item_hit == "cancel") {
me.toast(false);
} else if(item_hit == "choose") {
i = me["picnum"].getTextAsNum();
i = choose_graphic(i,PIC_SCEN,&me);
if(i < NO_PIC) {
pic_num_t pic = me["picnum"].getTextAsNum();
i = choose_graphic(pic,PIC_SCEN,&me);
if(i != NO_PIC) {
me["picnum"].setTextToNum(i);
dynamic_cast<cPict&>(me["pic"]).setPict(i);
}