example preview button for ONCE_DIALOG
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "mathutil.hpp"
|
#include "mathutil.hpp"
|
||||||
#include "dialogxml/widgets/message.hpp"
|
#include "dialogxml/widgets/message.hpp"
|
||||||
#include "dialogxml/widgets/pict.hpp"
|
#include "dialogxml/widgets/pict.hpp"
|
||||||
|
#include "dialogxml/dialogs/strdlog.hpp"
|
||||||
#include "tools/cursors.hpp"
|
#include "tools/cursors.hpp"
|
||||||
|
|
||||||
cThreeChoice::cThreeChoice
|
cThreeChoice::cThreeChoice
|
||||||
@@ -193,3 +194,31 @@ short custom_choice_dialog(std::array<std::string, 6>& strs,short pic_num,ePicTy
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short once_dialog(cUniverse& univ, cSpecial& spec, eSpecCtxType cur_type) {
|
||||||
|
std::array<std::string, 6> strs;
|
||||||
|
std::array<short, 3> buttons = {-1,-1,-1};
|
||||||
|
|
||||||
|
if(spec.m1 < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
univ.get_strs(strs, cur_type, spec.m1);
|
||||||
|
if(spec.m3 > 0) {
|
||||||
|
// The first button defaults to OK if toggle is on
|
||||||
|
buttons[0] = 1;
|
||||||
|
buttons[1] = spec.ex1a;
|
||||||
|
buttons[2] = spec.ex2a;
|
||||||
|
// If button 2 and/or button 3 are provided, the first button becomes a Leave button!
|
||||||
|
if((spec.ex1a >= 0) || (spec.ex2a >= 0))
|
||||||
|
buttons[0] = 9;
|
||||||
|
}
|
||||||
|
if(spec.m3 <= 0) {
|
||||||
|
buttons[1] = spec.ex1a;
|
||||||
|
buttons[2] = spec.ex2a;
|
||||||
|
}
|
||||||
|
if((buttons[0] < 0) && (buttons[1] < 0)) {
|
||||||
|
showError("Dialog box ended up with no buttons.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons, true, spec.ex1c, spec.ex2c);
|
||||||
|
}
|
@@ -18,6 +18,8 @@
|
|||||||
#include "dialogxml/dialogs/choicedlog.hpp"
|
#include "dialogxml/dialogs/choicedlog.hpp"
|
||||||
#include "dialogxml/widgets/button.hpp"
|
#include "dialogxml/widgets/button.hpp"
|
||||||
#include "dialogxml/widgets/pictypes.hpp"
|
#include "dialogxml/widgets/pictypes.hpp"
|
||||||
|
#include "universe/universe.hpp"
|
||||||
|
#include "scenario/special.hpp"
|
||||||
|
|
||||||
/// Basic button type template
|
/// Basic button type template
|
||||||
struct bbtt {
|
struct bbtt {
|
||||||
@@ -74,5 +76,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
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);
|
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);
|
||||||
|
short once_dialog(cUniverse& univ, cSpecial& spec, eSpecCtxType cur_type);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -2564,27 +2564,8 @@ void oneshot_spec(const runtime_state& ctx) {
|
|||||||
break;
|
break;
|
||||||
case eSpecType::ONCE_DIALOG:
|
case eSpecType::ONCE_DIALOG:
|
||||||
check_mess = false;
|
check_mess = false;
|
||||||
if(spec.m1 < 0)
|
dlg_res = once_dialog(univ, spec, ctx.cur_spec_type);
|
||||||
break;
|
if(dlg_res < 0) break;
|
||||||
univ.get_strs(strs, ctx.cur_spec_type, spec.m1);
|
|
||||||
if(spec.m3 > 0) {
|
|
||||||
// The first button defaults to OK if toggle is on
|
|
||||||
buttons[0] = 1;
|
|
||||||
buttons[1] = spec.ex1a;
|
|
||||||
buttons[2] = spec.ex2a;
|
|
||||||
// If button 2 and/or button 3 are provided, the first button becomes a Leave button!
|
|
||||||
if((spec.ex1a >= 0) || (spec.ex2a >= 0))
|
|
||||||
buttons[0] = 9;
|
|
||||||
}
|
|
||||||
if(spec.m3 <= 0) {
|
|
||||||
buttons[1] = spec.ex1a;
|
|
||||||
buttons[2] = spec.ex2a;
|
|
||||||
}
|
|
||||||
if((buttons[0] < 0) && (buttons[1] < 0)) {
|
|
||||||
showError("Dialog box ended up with no buttons.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons, true, spec.ex1c, spec.ex2c);
|
|
||||||
if(spec.m3 > 0) {
|
if(spec.m3 > 0) {
|
||||||
if(dlg_res == 1) {
|
if(dlg_res == 1) {
|
||||||
if((spec.ex1a >= 0) || (spec.ex2a >= 0)) {
|
if((spec.ex1a >= 0) || (spec.ex2a >= 0)) {
|
||||||
|
@@ -37,8 +37,18 @@ extern cScenario scenario;
|
|||||||
extern cOutdoors* current_terrain;
|
extern cOutdoors* current_terrain;
|
||||||
extern cCustomGraphics spec_scen_g;
|
extern cCustomGraphics spec_scen_g;
|
||||||
|
|
||||||
static bool preview_spec_enc_dlog(cDialog& me, std::string item_hit, cSpecial& special) {
|
static bool preview_spec_enc_dlog(cDialog& me, std::string item_hit, cSpecial& special, short mode) {
|
||||||
LOG("Preview clicked!");
|
eSpecCtxType cur_type = static_cast<eSpecCtxType>(mode);
|
||||||
|
cUniverse univ;
|
||||||
|
univ.scenario = scenario;
|
||||||
|
|
||||||
|
switch(special.type){
|
||||||
|
case eSpecType::ONCE_DIALOG:
|
||||||
|
once_dialog(univ, special, cur_type);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -802,8 +812,6 @@ static void put_spec_enc_in_dlog(cDialog& me, node_stack_t& edit_stack) {
|
|||||||
setup_node_field(me, "jump", spec.jumpto, info.jump(spec));
|
setup_node_field(me, "jump", spec.jumpto, info.jump(spec));
|
||||||
|
|
||||||
if(info.can_preview){
|
if(info.can_preview){
|
||||||
using namespace std::placeholders;
|
|
||||||
me["preview-dialog"].attachClickHandler(std::bind(preview_spec_enc_dlog, _1, _2, std::ref(spec)));
|
|
||||||
me["preview-dialog"].show();
|
me["preview-dialog"].show();
|
||||||
}else{
|
}else{
|
||||||
me["preview-dialog"].hide();
|
me["preview-dialog"].hide();
|
||||||
@@ -1401,8 +1409,11 @@ bool edit_spec_enc(short which_node,short mode,cDialog* parent) {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
special["back"].hide();
|
special["back"].hide();
|
||||||
edit_stack.push({which_node,mode,the_node});
|
edit_stack.push({which_node,mode,the_node});
|
||||||
|
special["preview-dialog"].attachClickHandler(std::bind(preview_spec_enc_dlog, _1, _2, std::ref(edit_stack.top().node), mode));
|
||||||
|
|
||||||
put_spec_enc_in_dlog(special, edit_stack);
|
put_spec_enc_in_dlog(special, edit_stack);
|
||||||
|
|
||||||
special.setResult(false);
|
special.setResult(false);
|
||||||
|
Reference in New Issue
Block a user