move custom_choice_dialog into shared code

This commit is contained in:
2025-04-30 11:22:15 -05:00
parent 203edc46f1
commit fe57c10173
8 changed files with 34 additions and 38 deletions

View File

@@ -14,6 +14,7 @@
#include "mathutil.hpp"
#include "dialogxml/widgets/message.hpp"
#include "dialogxml/widgets/pict.hpp"
#include "tools/cursors.hpp"
cThreeChoice::cThreeChoice
(std::vector<std::string>& strings, cBasicButtonType button, pic_num_t pic, ePicType t, cDialog* parent)
@@ -171,3 +172,24 @@ std::string cThreeChoice::show(){
else if(result == "btn3") return btns[2]->label;
return "**ERROR**"; // shouldn't be reached
}
short custom_choice_dialog(std::array<std::string, 6>& strs,short pic_num,ePicType pic_type,std::array<short, 3>& buttons,bool anim_pict,short anim_loops, int anim_fps) {
set_cursor(sword_curs);
std::vector<std::string> vec(strs.begin(), strs.end());
// Strip off trailing empty strings
while(!vec.empty() && vec.back().empty())
vec.pop_back();
cThreeChoice customDialog(vec, buttons, pic_num, pic_type);
if(anim_pict)
setup_dialog_pict_anim(*(customDialog.operator->()), "pict", anim_loops, anim_fps);
std::string item_hit = customDialog.show();
for(int i = 0; i < 3; i++) {
auto& btn = basic_buttons[buttons[i]];
if(item_hit == btn.label)
return i + 1;
}
return -1;
}

View File

@@ -73,4 +73,6 @@ public:
std::string show();
};
short custom_choice_dialog(std::array<std::string, 6>& strs,short pic_num,ePicType pic_type,std::array<short, 3>& buttons, bool anim_pict = false, short anim_loops = -1, int anim_fps = -1);
#endif

View File

@@ -1279,3 +1279,10 @@ void preview_dialog_xml(fs::path dialog_xml) {
sf::Color cParentless::getDefTextClr() const {
return cDialog::defaultBackground == cDialog::BG_DARK ? sf::Color::White : sf::Color::Black;
}
void setup_dialog_pict_anim(cDialog& dialog, std::string pict_id, short anim_loops, short anim_fps) {
cPict& pict = dynamic_cast<cPict&>(dialog[pict_id]);
pict.setAnimLoops(anim_loops);
dialog.setAnimPictFPS(anim_fps);
dialog.setDoAnimations(true);
}

View File

@@ -381,14 +381,7 @@ public:
const char* what() const throw();
};
//// This needs cControl to be complete.
///// @note You need to include control.hpp to use this.
//template<eDlogEvt t> void cDialog::attachEventHandlers(typename event_fcn<t>::type handler, const std::vector<std::string>& controls) {
// cDialog& me = *this;
// for(std::string control : controls) {
// me[control].attachEventHandler<t>(handler);
// }
//}
void setup_dialog_pict_anim(cDialog& dialog, std::string pict_id, short anim_loops, short anim_fps);
// For development/debugging only.
void preview_dialog_xml(fs::path dialog_xml);