make give_help()'s force_help a bool arg

This commit is contained in:
2025-02-15 07:51:56 -06:00
committed by Celtic Minstrel
parent 18a425be0d
commit 46c102257b
14 changed files with 44 additions and 48 deletions

View File

@@ -533,11 +533,10 @@ void cDialog::run(std::function<void(cDialog&)> onopen){
makeFrontWindow(*parentWin);
}
void cDialog::runWithHelp(short help1, short help2) {
extern void give_help(short help1, short help2, cDialog& parent);
run([help1, help2](cDialog& me) -> void {
give_help(help1, help2, me);
});
void cDialog::runWithHelp(short help1, short help2, bool help_forced) {
using namespace std::placeholders;
extern void give_help(short help1, short help2, cDialog& parent, bool help_forced);
run(std::bind(&give_help,help1, help2, _1, help_forced));
}
// This method is a main event event loop of the dialog.

View File

@@ -116,7 +116,7 @@ public:
/// @param onopen A function to be called after the dialog is displayed but before the event loop starts.
void run(std::function<void(cDialog&)> onopen = nullptr); // cd_run_dialog
/// Show this dialog. Before starting its event loop, show a help window if it hasn't been shown before.
void runWithHelp(short help1, short help2);
void runWithHelp(short help1, short help2, bool help_forced = false);
/// Get the result of the dialog.
/// @tparam type The result type.
/// @throw boost::bad_any_cast if the provided result type is different from the type set by setResult().

View File

@@ -124,14 +124,9 @@ void showFatalError(std::string str1, std::string str2, cDialog* parent) {
}
// Call this anywhere, but don't forget parent!!!
static void give_help(short help1,short help2,cDialog* parent) {
bool help_forced = false;
static void give_help(short help1,short help2,cDialog* parent,bool help_forced) {
std::string str1,str2;
if(help1 >= 200) {
help_forced = true;
help1 -= 200;
}
if(!help_forced && (!get_bool_pref("ShowInstantHelp", true) || get_iarray_pref_contains("ReceivedHelp", help1)))
return;
append_iarray_pref("ReceivedHelp", help1);
@@ -144,10 +139,10 @@ static void give_help(short help1,short help2,cDialog* parent) {
display_strings.show();
}
void give_help(short help1, short help2) {
give_help(help1, help2, nullptr);
void give_help(short help1, short help2, bool help_forced) {
give_help(help1, help2, nullptr, help_forced);
}
void give_help(short help1, short help2, cDialog& parent) {
give_help(help1, help2, &parent);
void give_help(short help1, short help2, cDialog& parent, bool help_forced) {
give_help(help1, help2, &parent, help_forced);
}

View File

@@ -88,7 +88,7 @@ void showWarning(std::string str1, std::string str2, cDialog* parent = nullptr);
void showWarning(std::string str1, cDialog* parent = nullptr);
// Show a help window with the given messages from rsrc/strings/help.txt:
void give_help(short help1, short help2);
void give_help(short help1, short help2, cDialog& parent);
void give_help(short help1, short help2, bool help_forced = false);
void give_help(short help1, short help2, cDialog& parent, bool help_forced = false);
#endif

View File

@@ -30,6 +30,7 @@
#include "fileio/resmgr/res_dialog.hpp"
#include "dialogxml/dialogs/choicedlog.hpp"
#include "dialogxml/dialogs/dialog.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "dialogxml/widgets/scrollbar.hpp"
#include "boe.menus.hpp"
#include "tools/keymods.hpp"
@@ -1934,14 +1935,15 @@ void show_inventory() {
// Most give_help() calls don't need to be recorded, because
// they are triggered incidentally by other recorded actions.
void give_help_and_record(short help1, short help2) {
void give_help_and_record(short help1, short help2, bool help_forced) {
if(recording){
std::map<std::string,std::string> info;
info["help1"] = boost::lexical_cast<std::string>(help1);
info["help2"] = boost::lexical_cast<std::string>(help2);
info["help_forced"] = bool_to_str(help_forced);
record_action("give_help", info);
}
give_help(help1, help2);
give_help(help1, help2, help_forced);
}
void toggle_debug_mode() {

View File

@@ -109,7 +109,7 @@ void handle_print_pc_sp(int which_pc, bool& need_reprint);
void handle_trade_places(int which_pc, bool& need_reprint);
void handle_begin_talk(bool& need_reprint);
void handle_talk(location destination, bool& did_something, bool& need_redraw, bool& need_reprint);
void give_help_and_record(short help1, short help2);
void give_help_and_record(short help1, short help2, bool help_forced = false);
void show_item_info(short item_hit);
void close_map(bool record = false);
void cancel_item_target(bool& did_something, bool& need_redraw, bool& need_reprint);

View File

@@ -21,6 +21,7 @@
#include "boe.ui.hpp"
#include "mathutil.hpp"
#include "dialogxml/dialogs/choicedlog.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "boe.menus.hpp"
#include "spell.hpp"
#include "tools/prefs.hpp"

View File

@@ -59,7 +59,7 @@ extern sf::RenderWindow mini_map;
extern cUniverse univ;
extern sf::Texture pc_gworld;
extern std::map<eSkill,short> skill_max;
extern void give_help_and_record(short help1, short help2);
extern void give_help_and_record(short help1, short help2, bool help_forced = false);
short sign_mode,person_graphic,store_person_graphic,store_sign_mode;
long num_talk_entries;
@@ -1136,7 +1136,7 @@ void handle_talk_node(int which_talk_entry) {
bool handle_talk_event(location p, cFramerateLimiter& fps_limiter) {
if(p.in(talk_help_rect)) {
if(help_btn->handleClick(p, fps_limiter))
give_help_and_record(205,6);
give_help_and_record(5,6,true);
return true;
}
@@ -1403,11 +1403,9 @@ void pick_preferences(bool record) {
} else {
uiMapScale["other"].hide();
}
void (*give_help)(short,short,cDialog&) = ::give_help;
int store_display_mode = get_int_pref("DisplayMode");
prefsDlog.run(std::bind(give_help, 55, 0, std::ref(prefsDlog)));
prefsDlog.runWithHelp(55, 0);
// Suppress the float comparison warning.
// We know it's safe here - we're just comparing static values.
@@ -1451,7 +1449,7 @@ static bool edit_party_event_filter(cDialog& me, std::string item_hit, eKeyMod)
if(item_hit == "done") {
me.toast(true);
} else if(item_hit == "help") {
give_help(222,23,me);
give_help(22,23,me,true);
} else {
short which_pc = item_hit[item_hit.length()-1] - '1';
item_hit = item_hit.substr(0, item_hit.length() - 1);
@@ -1507,9 +1505,8 @@ void edit_party() {
pcDialog.attachClickHandlers(edit_party_event_filter, buttons);
put_party_stats(pcDialog);
void (*give_help)(short,short,cDialog&) = ::give_help;
pcDialog.run(std::bind(give_help, 22, 23, std::ref(pcDialog)));
pcDialog.runWithHelp(22, 23);
if(univ.current_pc().main_status != eMainStatus::ALIVE)
univ.cur_pc = first_active_pc();

View File

@@ -20,8 +20,6 @@ void put_talk();
void talk_notes();
void journal();
void add_to_journal(short event);
void give_help(short help1,short help2,class cDialog& parent_num);
void give_help(short help1,short help2);
void put_spec_item_info (short which_i);
void put_quest_info(short which_i);

View File

@@ -576,11 +576,9 @@ bool show_get_items(std::string titleText, std::vector<cItem*>& itemRefs, short
itemDialog[sout.str()].attachClickHandler(handler);
}
put_item_graphics(itemDialog, first_item, pc_getting, itemRefs);
void (*give_help)(short,short,cDialog&) = ::give_help;
itemDialog.setResult(false); // The result is set to true if the player steals something
itemDialog.run(std::bind(give_help, 36, 37, _1));
itemDialog.runWithHelp(36, 37);
return itemDialog.getResult<bool>();

View File

@@ -752,7 +752,16 @@ static void replay_action(Element& action) {
auto info = info_from_action(action);
short help1 = boost::lexical_cast<short>(info["help1"]);
short help2 = boost::lexical_cast<short>(info["help2"]);
give_help(help1, help2);
bool help_forced;
// Legacy replays may have the text indices offset by 200 to indicate
// help_forced true.
if(info.find("help_forced") == info.end()){
help_forced = help1 >= 200;
help1 -= 200;
}else{
help_forced = str_to_bool(info["help_forced"]);
}
give_help(help1, help2, help_forced);
}else if(t == "toggle_debug_mode"){
toggle_debug_mode();
return;
@@ -1334,7 +1343,7 @@ void menu_give_help(short help1){
if(recording){
record_action("menu_give_help", boost::lexical_cast<std::string>(help1));
}
give_help(help1, 0);
give_help(help1, 0, true);
}
void handle_menu_choice(eMenu item_hit) {
@@ -1453,10 +1462,10 @@ void handle_menu_choice(eMenu item_hit) {
break;
case eMenu::ABOUT_MAGE:
case eMenu::ABOUT_PRIEST:
menu_give_help(209);
menu_give_help(9);
break;
case eMenu::ABOUT_MONSTERS:
menu_give_help(212);
menu_give_help(12);
break;
}
if(!dialogToShow.empty()) {

View File

@@ -1863,7 +1863,7 @@ static bool pick_spell_event_filter(cDialog& me, std::string item_hit, const eSk
put_spell_list(me, store_situation);
put_spell_led_buttons(me, store_situation, store_spell);
} else if(item_hit == "help") {
give_help(207,8,me);
give_help(7,8,me,true);
}
return true;
}
@@ -2083,9 +2083,7 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num
draw_caster_buttons(castSpell, type);
put_spell_led_buttons(castSpell, type, former_spell);
void (*give_help)(short,short,cDialog&) = ::give_help;
castSpell.run(std::bind(give_help, 7, 8, _1));
castSpell.runWithHelp(7, 8);
return cSpell::fromNum(type, castSpell.getResult<short>());
}
@@ -2180,7 +2178,7 @@ void do_alchemy() {
static bool alch_choice_event_filter(cDialog& me, std::string item_hit, eKeyMod) {
if(item_hit == "help") {
give_help(220,21,me);
give_help(20,21,me,true);
return true;
}
if(item_hit == "cancel")
@@ -2211,9 +2209,7 @@ eAlchemy alch_choice(short pc_num) {
sout << " (skill " << univ.party[pc_num].skill(eSkill::ALCHEMY) << ")";
chooseAlchemy["mixer"].setText(sout.str());
void (*give_help)(short,short,cDialog&) = ::give_help;
chooseAlchemy.run(std::bind(give_help, 20, 21, std::ref(chooseAlchemy)));
chooseAlchemy.runWithHelp(20, 21);
return chooseAlchemy.getResult<eAlchemy>();
}

View File

@@ -18,6 +18,7 @@ const int TEXT_BUF_LEN = 70;
#include "gfx/tiling.hpp"
#include "utility.hpp"
#include "dialogxml/widgets/scrollbar.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "fileio/resmgr/res_image.hpp"
#include "fileio/resmgr/res_font.hpp"
#include "spell.hpp"

View File

@@ -365,7 +365,7 @@ static bool spend_xp_navigate_filter(cDialog& me, std::string item_hit,xp_dlog_s
me.setResult(false);
me.toast(false);
} else if(item_hit == "help") {
give_help(210,11,me);
give_help(10,11,me,true);
} else if(item_hit == "keep") {
do_xp_keep(save);
me.setResult(true);