move custom_choice_dialog into shared code
This commit is contained in:
@@ -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;
|
||||
}
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -579,27 +579,6 @@ bool show_get_items(std::string titleText, std::vector<cItem*>& itemRefs, short
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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<cPict&>(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<cPict&>(story_dlg["pict"]).setPict(pic, pt);
|
||||
|
@@ -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<cItem*>& 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<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);
|
||||
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();
|
||||
|
@@ -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"
|
||||
|
@@ -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 <array>
|
||||
#include "spell.hpp"
|
||||
|
Reference in New Issue
Block a user