From b6238de2ec746ded9d1979883d7cb6a2276a8db9 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 26 Aug 2025 13:53:32 -0500 Subject: [PATCH] preview for IF_TEXT_RESPONSE --- src/dialogxml/dialogs/dialog.cpp | 25 +++++++++++++++++++++++++ src/dialogxml/dialogs/dialog.hpp | 1 + src/game/boe.items.cpp | 24 ------------------------ src/game/boe.items.hpp | 1 - src/scenario/special-condition.cpp | 4 +--- src/scenedit/scen.keydlgs.cpp | 4 ++++ 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index 65aec660..3b5f7ed8 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "dialog.hpp" #include "gfx/tiling.hpp" // for bg #include "fileio/resmgr/res_dialog.hpp" @@ -1374,3 +1375,27 @@ void custom_pic_dialog(std::string title, pic_num_t bigpic, pic_num_t icon) { pic_dlg.recalcRect(); pic_dlg.run(); } + +static bool get_text_response_event_filter(cDialog& me, std::string item_hit, eKeyMod) { + me.toast(true); + if(item_hit == "cancel") me.setResult(std::string {""}); + else me.setResult(me["response"].getText()); + return true; +} + +std::string get_text_response(std::string prompt, pic_num_t pic) { + set_cursor(sword_curs); + + cDialog strPanel(*ResMgr::dialogs.get("get-response")); + strPanel.attachClickHandlers(get_text_response_event_filter, {"okay", "cancel"}); + if(!prompt.empty()) { + dynamic_cast(strPanel["pic"]).setPict(pic); + strPanel["prompt"].setText(prompt); + } + + strPanel.run(); + // Note: Originally it only changed the first 15 characters. + std::string result = strPanel.getResult(); + boost::algorithm::to_lower(result); + return result; +} diff --git a/src/dialogxml/dialogs/dialog.hpp b/src/dialogxml/dialogs/dialog.hpp index 29771755..12a3a412 100644 --- a/src/dialogxml/dialogs/dialog.hpp +++ b/src/dialogxml/dialogs/dialog.hpp @@ -397,6 +397,7 @@ void setup_dialog_pict_anim(cDialog& dialog, std::string pict_id, short anim_loo void story_dialog(cUniverse& univ, 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); void custom_pic_dialog(std::string title, pic_num_t bigpic, pic_num_t icon); +std::string get_text_response(std::string prompt = "", pic_num_t pic = 16); // 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 04cb3a91..a8c536be 100644 --- a/src/game/boe.items.cpp +++ b/src/game/boe.items.cpp @@ -811,30 +811,6 @@ void place_treasure(location where,short level,short loot,short mode) { } } -static bool get_text_response_event_filter(cDialog& me, std::string item_hit, eKeyMod) { - me.toast(true); - if(item_hit == "cancel") me.setResult(std::string {""}); - else me.setResult(me["response"].getText()); - return true; -} - -std::string get_text_response(std::string prompt, pic_num_t pic) { - set_cursor(sword_curs); - - cDialog strPanel(*ResMgr::dialogs.get("get-response")); - strPanel.attachClickHandlers(get_text_response_event_filter, {"okay", "cancel"}); - if(!prompt.empty()) { - dynamic_cast(strPanel["pic"]).setPict(pic); - strPanel["prompt"].setText(prompt); - } - - strPanel.run(); - // Note: Originally it only changed the first 15 characters. - std::string result = strPanel.getResult(); - std::transform(result.begin(), result.end(), result.begin(), tolower); - return result; -} - static bool select_pc_event_filter (cDialog& me, std::string item_hit, eKeyMod) { me.toast(true); if(item_hit == "pick-all"){ diff --git a/src/game/boe.items.hpp b/src/game/boe.items.hpp index 16068b58..9ae7fb26 100644 --- a/src/game/boe.items.hpp +++ b/src/game/boe.items.hpp @@ -32,7 +32,6 @@ void place_glands(location where,mon_num_t m_type); void reset_item_max(); short item_val(cItem item); void place_treasure(location where,short level,short loot,short mode); -std::string get_text_response(std::string prompt = "", pic_num_t pic = 16); enum class eSelectPC { ANY, diff --git a/src/scenario/special-condition.cpp b/src/scenario/special-condition.cpp index 637bfa1e..dd11e652 100644 --- a/src/scenario/special-condition.cpp +++ b/src/scenario/special-condition.cpp @@ -120,14 +120,12 @@ namespace { .ex2a(STRT_SKILL_CHECK) .ex2b(STRT_ACCUM) .no_preview(); - // TODO implement preview node_properties_t S_TEXT = node_builder_t(eSpecType::IF_TEXT_RESPONSE) .msg1(+eSpecPicker::MSG_SINGLE) .ex1a(+eSpecPicker::MSG_SINGLE) .ex1b(eSpecPicker::NODE) .ex2a(+eSpecPicker::MSG_SINGLE) - .ex2b(eSpecPicker::NODE) - .no_preview(); + .ex2b(eSpecPicker::NODE); node_properties_t S_SDFEQ = node_builder_t(eSpecType::IF_SDF_EQ) .sdf() .ex1b(eSpecPicker::NODE) diff --git a/src/scenedit/scen.keydlgs.cpp b/src/scenedit/scen.keydlgs.cpp index 1dd3791c..223617d9 100644 --- a/src/scenedit/scen.keydlgs.cpp +++ b/src/scenedit/scen.keydlgs.cpp @@ -879,6 +879,10 @@ static bool preview_spec_enc_dlog(cDialog& me, std::string, cSpecial& special, s cDialog::defaultBackground = cDialog::BG_DARK; switch(special.type){ + case eSpecType::IF_TEXT_RESPONSE: + univ.get_str(title,eSpecCtxType::SCEN,special.m1); + get_text_response(title); + break; case eSpecType::DISPLAY_PICTURE: univ.get_str(title, cur_type, special.m1); custom_pic_dialog(title, special.ex1a, special.ex1b);