previewing dialogs, don't crash the game

This commit is contained in:
2025-02-26 21:36:09 -06:00
committed by Celtic Minstrel
parent ad43e8ab81
commit aa36b6cefb

View File

@@ -50,6 +50,7 @@ std::mt19937 cDialog::ui_rand;
extern std::map<std::string,sf::Color> colour_map; extern std::map<std::string,sf::Color> colour_map;
extern bool check_for_interrupt(std::string); extern bool check_for_interrupt(std::string);
extern void showError(std::string str1, cDialog* parent = nullptr);
std::string cDialog::generateRandomString(){ std::string cDialog::generateRandomString(){
// Not bothering to seed, because it doesn't actually matter if it's truly random. // Not bothering to seed, because it doesn't actually matter if it's truly random.
@@ -1170,16 +1171,23 @@ void cDialogIterator::increment() {
} }
void preview_dialog_xml(fs::path dialog_xml) { void preview_dialog_xml(fs::path dialog_xml) {
std::unique_ptr<DialogDefn> defn(load_dialog_defn(dialog_xml)); try{
cDialog dialog(*defn); std::unique_ptr<DialogDefn> defn(load_dialog_defn(dialog_xml));
// Make every clickable control's click event close the dialog cDialog dialog(*defn);
for (auto control : dialog){
try{ // Make every clickable control's click event close the dialog
control.second->attachClickHandler([](cDialog& me, std::string item_hit, eKeyMod mod) -> bool { for (auto control : dialog){
me.toast(false); try{
return true; control.second->attachClickHandler([](cDialog& me, std::string item_hit, eKeyMod mod) -> bool {
}); me.toast(false);
}catch(...){} return true;
});
}catch(...){}
}
dialog.run();
}catch(std::exception& x) {
showError(x.what());
}catch(std::string& x){
showError(x);
} }
dialog.run();
} }