Skip to content

Commit

Permalink
New feature: dialogs with pictures can animate
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Mar 3, 2025
1 parent 5b25f0e commit 2a6f76f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
15 changes: 13 additions & 2 deletions src/game/boe.items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,17 @@ 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) {
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++) {
Expand Down Expand Up @@ -620,9 +623,17 @@ void custom_pic_dialog(std::string title, pic_num_t bigpic) {
pic_dlg.run();
}

void story_dialog(std::string title, str_num_t first, str_num_t last, eSpecCtxType which_str_type, pic_num_t pic, ePicType pt) {
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);
setup_dialog_pict_anim(story_dlg, "pict", anim_loops, anim_fps);
str_num_t cur = first;
story_dlg.attachClickHandlers([&cur,first,last,which_str_type](cDialog& me, std::string clicked, eKeyMod) -> bool {
if(clicked == "left") {
Expand Down
5 changes: 3 additions & 2 deletions src/game/boe.items.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ 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) ;
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 story_dialog(std::string title, str_num_t first, str_num_t last, eSpecCtxType which_str_type, pic_num_t pic, ePicType pt);
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();
void draw_help_dialog_item_buttons(cDialog& dialog,short item);
Expand Down
12 changes: 6 additions & 6 deletions src/game/boe.specials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,7 @@ void general_spec(const runtime_state& ctx) {
break;
case eSpecType::STORY_DIALOG:
get_str(str1,ctx.cur_spec_type,spec.m1);
story_dialog(str1, spec.m2, spec.m3, ctx.cur_spec_type, spec.pic, ePicType(spec.pictype));
story_dialog(str1, spec.m2, spec.m3, ctx.cur_spec_type, spec.pic, ePicType(spec.pictype), spec.ex1c, spec.ex2c);
break;
case eSpecType::CLEAR_BUF:
univ.get_buf().clear();
Expand Down Expand Up @@ -2582,7 +2582,7 @@ void oneshot_spec(const runtime_state& ctx) {
showError("Dialog box ended up with no buttons.");
break;
}
dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons);
dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons, true, spec.ex1c, spec.ex2c);
if(spec.m3 > 0) {
if(dlg_res == 1) {
if((spec.ex1a >= 0) || (spec.ex2a >= 0)) {
Expand All @@ -2602,7 +2602,7 @@ void oneshot_spec(const runtime_state& ctx) {
break;
get_strs(strs, ctx.cur_spec_type, spec.m1);
buttons[0] = 20; buttons[1] = 19;
dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons);
dlg_res = custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons, true, spec.ex1c, spec.ex2c);
if(dlg_res == 1) {set_sd = false; ctx.next_spec = -1;}
else {
store_i = univ.scenario.get_stored_item(spec.ex1a);
Expand Down Expand Up @@ -2642,7 +2642,7 @@ void oneshot_spec(const runtime_state& ctx) {
if((spec.m1 >= 0) || (spec.m2 >= 0)) {
get_strs(strs[0],strs[1], ctx.cur_spec_type, spec.m1, spec.m2);
buttons[0] = 3; buttons[1] = 2;
dlg_res = custom_choice_dialog(strs,spec.pic,ePicType(spec.pictype),buttons);
dlg_res = custom_choice_dialog(strs,spec.pic,ePicType(spec.pictype),buttons, true, spec.ex1c, spec.ex2c);
// TODO: Make custom_choice_dialog return string?
}
else dlg_res = cChoiceDlog("basic-trap",{"yes","no"}).show() == "no";
Expand Down Expand Up @@ -3968,7 +3968,7 @@ void townmode_spec(const runtime_state& ctx) {
else {
get_strs(strs,ctx.cur_spec_type, spec.m1);
buttons[0] = 9; buttons[1] = 35;
if(custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons) == 1)
if(custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons, true, spec.ex1c, spec.ex2c) == 1)
ctx.next_spec = -1;
else {
int x = univ.party.get_ptr(10), y = univ.party.get_ptr(11);
Expand Down Expand Up @@ -3999,7 +3999,7 @@ void townmode_spec(const runtime_state& ctx) {
else {
get_strs(strs, ctx.cur_spec_type,spec.m1);
buttons[0] = 9; buttons[1] = 8;
if(custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons) == 1) {
if(custom_choice_dialog(strs, spec.pic, ePicType(spec.pictype), buttons, true, spec.ex1c, spec.ex2c) == 1) {
ctx.next_spec = -1;
if(ctx.which_mode == eSpecCtx::OUT_MOVE || ctx.which_mode == eSpecCtx::TOWN_MOVE || ctx.which_mode == eSpecCtx::COMBAT_MOVE)
*ctx.ret_a = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/scenedit/scen.core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,7 @@ bool edit_make_scen_2(short& out_w, short& out_h, short& town_l, short& town_m,

extern fs::path progDir;
extern eScenMode overall_mode;

bool build_scenario() {
short width, height, lg, med, sm;
bool default_town, grass;
Expand Down Expand Up @@ -3092,7 +3093,6 @@ bool build_scenario() {
scenario.shops.push_back(cShop(SHOP_HEALING));

overall_mode = MODE_MAIN_SCREEN;

editing_town = false;
scenario.outdoors.resize(width, height);
for(int x = 0; x < width; x++) {
Expand Down

0 comments on commit 2a6f76f

Please sign in to comment.