Try reusing one pick-spell dialog

This commit is contained in:
2025-05-03 15:06:48 -05:00
parent 31c5ae3b5b
commit d22cded163
2 changed files with 9 additions and 2 deletions

View File

@@ -35,6 +35,7 @@
#include "mathutil.hpp"
#include "fileio/fileio.hpp"
#include "fileio/resmgr/res_font.hpp"
#include "fileio/resmgr/res_dialog.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "dialogxml/dialogs/choicedlog.hpp"
#include "dialogxml/widgets/scrollbar.hpp"
@@ -351,11 +352,16 @@ static void init_buttons() {
init_btn(help_btn, BTN_HELP, {273,12});
}
// Spell dialog is slow to open on Windows, so keep it prepared and reuse it.
std::unique_ptr<cDialog> storeCastSpell;
// NOTE: this should possibly be moved to boe.ui.cpp at some point
static void init_ui() {
cDialog::init();
init_scrollbars();
init_buttons();
storeCastSpell.reset(new cDialog(*ResMgr::dialogs.get("cast-spell")));
}
extern bool record_verbose;
@@ -1270,6 +1276,7 @@ void handle_events() {
ResMgr::fonts.drain();
adjust_window_mode();
storeCastSpell.reset(new cDialog(*ResMgr::dialogs.get("cast-spell")));
init_mini_map();
}

View File

@@ -2060,8 +2060,8 @@ eSpell pick_spell(short pc_num,eSkill type) { // 70 - no spell OW spell num
set_cursor(sword_curs);
cDialog castSpell(*ResMgr::dialogs.get("cast-spell"));
extern std::unique_ptr<cDialog> storeCastSpell;
cDialog& castSpell = *storeCastSpell;
castSpell.attachClickHandlers(std::bind(pick_spell_caster, _1, _2, type, std::ref(dark), std::ref(former_spell)), {"caster1","caster2","caster3","caster4","caster5","caster6"});
castSpell.attachClickHandlers(std::bind(pick_spell_target,_1,_2, type, std::ref(dark), std::ref(former_spell)), {"target1","target2","target3","target4","target5","target6"});
castSpell.attachClickHandlers(std::bind(pick_spell_event_filter, _1, _2, type,std::ref(former_spell)), {"other", "help"});