From fe57c10173142012a6c40bc4776330454c505486 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 30 Apr 2025 11:22:15 -0500 Subject: [PATCH] move custom_choice_dialog into shared code --- src/dialogxml/dialogs/3choice.cpp | 22 ++++++++++++++++++++++ src/dialogxml/dialogs/3choice.hpp | 2 ++ src/dialogxml/dialogs/dialog.cpp | 7 +++++++ src/dialogxml/dialogs/dialog.hpp | 9 +-------- src/game/boe.items.cpp | 28 ---------------------------- src/game/boe.items.hpp | 2 -- src/game/boe.party.cpp | 1 + src/game/boe.specials.cpp | 1 + 8 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/dialogxml/dialogs/3choice.cpp b/src/dialogxml/dialogs/3choice.cpp index 1dbfbcbc..80ea1184 100644 --- a/src/dialogxml/dialogs/3choice.cpp +++ b/src/dialogxml/dialogs/3choice.cpp @@ -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& 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& strs,short pic_num,ePicType pic_type,std::array& buttons,bool anim_pict,short anim_loops, int anim_fps) { + set_cursor(sword_curs); + + std::vector 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; +} \ No newline at end of file diff --git a/src/dialogxml/dialogs/3choice.hpp b/src/dialogxml/dialogs/3choice.hpp index c03ff05f..584f1193 100644 --- a/src/dialogxml/dialogs/3choice.hpp +++ b/src/dialogxml/dialogs/3choice.hpp @@ -73,4 +73,6 @@ public: std::string show(); }; +short custom_choice_dialog(std::array& strs,short pic_num,ePicType pic_type,std::array& buttons, bool anim_pict = false, short anim_loops = -1, int anim_fps = -1); + #endif diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index 9479b5b9..968af75d 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -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(dialog[pict_id]); + pict.setAnimLoops(anim_loops); + dialog.setAnimPictFPS(anim_fps); + dialog.setDoAnimations(true); +} diff --git a/src/dialogxml/dialogs/dialog.hpp b/src/dialogxml/dialogs/dialog.hpp index 482aa84f..df3bf2af 100644 --- a/src/dialogxml/dialogs/dialog.hpp +++ b/src/dialogxml/dialogs/dialog.hpp @@ -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 void cDialog::attachEventHandlers(typename event_fcn::type handler, const std::vector& controls) { -// cDialog& me = *this; -// for(std::string control : controls) { -// me[control].attachEventHandler(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); diff --git a/src/game/boe.items.cpp b/src/game/boe.items.cpp index b0cb68e8..42a36b26 100644 --- a/src/game/boe.items.cpp +++ b/src/game/boe.items.cpp @@ -579,27 +579,6 @@ bool show_get_items(std::string titleText, std::vector& itemRefs, short } -short custom_choice_dialog(std::array& strs,short pic_num,ePicType pic_type,std::array& buttons,bool anim_pict,short anim_loops, int anim_fps) { - set_cursor(sword_curs); - - std::vector 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; -} - void custom_pic_dialog(std::string title, pic_num_t bigpic) { cDialog pic_dlg(*ResMgr::dialogs.get("show-map")); cControl& okay = pic_dlg["okay"]; @@ -623,13 +602,6 @@ void custom_pic_dialog(std::string title, pic_num_t bigpic) { pic_dlg.run(); } -void setup_dialog_pict_anim(cDialog& dialog, std::string pict_id, short anim_loops, short anim_fps) { - cPict& pict = dynamic_cast(dialog[pict_id]); - pict.setAnimLoops(anim_loops); - dialog.setAnimPictFPS(anim_fps); - dialog.setDoAnimations(true); -} - void story_dialog(std::string title, str_num_t first, str_num_t last, eSpecCtxType which_str_type, pic_num_t pic, ePicType pt, short anim_loops, int anim_fps) { cDialog story_dlg(*ResMgr::dialogs.get("many-str")); dynamic_cast(story_dlg["pict"]).setPict(pic, pt); diff --git a/src/game/boe.items.hpp b/src/game/boe.items.hpp index b4a060d1..23eee8db 100644 --- a/src/game/boe.items.hpp +++ b/src/game/boe.items.hpp @@ -24,9 +24,7 @@ void make_town_hostile(); void set_town_attitude(short lo,short hi,eAttitude att); bool show_get_items(std::string titleText, std::vector& itemRefs, short pc_getting, bool overload = false); bool display_item(location from_loc,short pc_num,short mode, bool check_container); -short custom_choice_dialog(std::array& strs,short pic_num,ePicType pic_type,std::array& buttons, bool anim_pict = false, short anim_loops = -1, int anim_fps = -1); void custom_pic_dialog(std::string title, pic_num_t bigpic); -void setup_dialog_pict_anim(cDialog& dialog, std::string pict_id, short anim_loops, short anim_fps); void story_dialog(std::string title, str_num_t first, str_num_t last, eSpecCtxType which_str_type, pic_num_t pic, ePicType pt, short anim_loops, int anim_fps); short get_num_of_items(short max_num); void init_mini_map(); diff --git a/src/game/boe.party.cpp b/src/game/boe.party.cpp index 93dc6a24..b99f951c 100644 --- a/src/game/boe.party.cpp +++ b/src/game/boe.party.cpp @@ -32,6 +32,7 @@ #include "dialogxml/dialogs/strdlog.hpp" #include "dialogxml/dialogs/choicedlog.hpp" #include "dialogxml/dialogs/pictchoice.hpp" +#include "dialogxml/dialogs/3choice.hpp" #include "tools/winutil.hpp" #include "fileio/fileio.hpp" #include "fileio/resmgr/res_dialog.hpp" diff --git a/src/game/boe.specials.cpp b/src/game/boe.specials.cpp index ba965745..434794cf 100644 --- a/src/game/boe.specials.cpp +++ b/src/game/boe.specials.cpp @@ -27,6 +27,7 @@ #include "boe.main.hpp" #include "dialogxml/dialogs/strdlog.hpp" #include "dialogxml/dialogs/choicedlog.hpp" +#include "dialogxml/dialogs/3choice.hpp" #include "fileio/fileio.hpp" #include #include "spell.hpp"