preview for IF_TEXT_RESPONSE

This commit is contained in:
2025-08-26 13:53:32 -05:00
parent ab063791e8
commit b6238de2ec
6 changed files with 31 additions and 28 deletions

View File

@@ -12,6 +12,7 @@
#include <sstream>
#include <string>
#include <map>
#include <boost/algorithm/string/case_conv.hpp>
#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<cPict&>(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::string>();
boost::algorithm::to_lower(result);
return result;
}

View File

@@ -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);

View File

@@ -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<cPict&>(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::string>();
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"){

View File

@@ -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,

View File

@@ -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)

View File

@@ -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);