From e2e7907e1aa1447d8154f264c9d2989314dda05b Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 30 Apr 2025 12:40:46 -0500 Subject: [PATCH] example preview button for ONCE_DIALOG --- src/dialogxml/dialogs/3choice.cpp | 29 +++++++++++++++++++++++++++++ src/dialogxml/dialogs/3choice.hpp | 3 +++ src/game/boe.specials.cpp | 23 ++--------------------- src/scenedit/scen.keydlgs.cpp | 19 +++++++++++++++---- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/dialogxml/dialogs/3choice.cpp b/src/dialogxml/dialogs/3choice.cpp index 80ea1184..07529ddd 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 "dialogxml/dialogs/strdlog.hpp" #include "tools/cursors.hpp" cThreeChoice::cThreeChoice @@ -192,4 +193,32 @@ short custom_choice_dialog(std::array& strs,short pic_num,ePicTy return i + 1; } return -1; +} + +short once_dialog(cUniverse& univ, cSpecial& spec, eSpecCtxType cur_type) { + std::array strs; + std::array 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); } \ No newline at end of file diff --git a/src/dialogxml/dialogs/3choice.hpp b/src/dialogxml/dialogs/3choice.hpp index 584f1193..5c5bb283 100644 --- a/src/dialogxml/dialogs/3choice.hpp +++ b/src/dialogxml/dialogs/3choice.hpp @@ -18,6 +18,8 @@ #include "dialogxml/dialogs/choicedlog.hpp" #include "dialogxml/widgets/button.hpp" #include "dialogxml/widgets/pictypes.hpp" +#include "universe/universe.hpp" +#include "scenario/special.hpp" /// Basic button type template struct bbtt { @@ -74,5 +76,6 @@ public: }; 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); +short once_dialog(cUniverse& univ, cSpecial& spec, eSpecCtxType cur_type); #endif diff --git a/src/game/boe.specials.cpp b/src/game/boe.specials.cpp index 48c5636e..07be94f4 100644 --- a/src/game/boe.specials.cpp +++ b/src/game/boe.specials.cpp @@ -2564,27 +2564,8 @@ void oneshot_spec(const runtime_state& ctx) { break; case eSpecType::ONCE_DIALOG: check_mess = false; - if(spec.m1 < 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); + dlg_res = once_dialog(univ, spec, ctx.cur_spec_type); + if(dlg_res < 0) break; if(spec.m3 > 0) { if(dlg_res == 1) { if((spec.ex1a >= 0) || (spec.ex2a >= 0)) { diff --git a/src/scenedit/scen.keydlgs.cpp b/src/scenedit/scen.keydlgs.cpp index afd8448e..52e4be9c 100644 --- a/src/scenedit/scen.keydlgs.cpp +++ b/src/scenedit/scen.keydlgs.cpp @@ -37,8 +37,18 @@ extern cScenario scenario; extern cOutdoors* current_terrain; extern cCustomGraphics spec_scen_g; -static bool preview_spec_enc_dlog(cDialog& me, std::string item_hit, cSpecial& special) { - LOG("Preview clicked!"); +static bool preview_spec_enc_dlog(cDialog& me, std::string item_hit, cSpecial& special, short mode) { + eSpecCtxType cur_type = static_cast(mode); + cUniverse univ; + univ.scenario = scenario; + + switch(special.type){ + case eSpecType::ONCE_DIALOG: + once_dialog(univ, special, cur_type); + break; + default: + break; + } 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)); 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(); }else{ me["preview-dialog"].hide(); @@ -1401,8 +1409,11 @@ bool edit_spec_enc(short which_node,short mode,cDialog* parent) { return true; }); + special["back"].hide(); 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); special.setResult(false);