From 8db11dc683398f5a3147855e887d8515d029c6a2 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 27 May 2024 15:21:31 +0200 Subject: [PATCH] bool dialogs --- config.cpp | 21 +++++++++++++++++--- dialogs.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/config.cpp b/config.cpp index 67912cf6..f59e341a 100644 --- a/config.cpp +++ b/config.cpp @@ -20,6 +20,8 @@ EX void add_to_changed(struct parameter *f); EX bool return_false() { return false; } +EX bool use_bool_dialog; + EX string param_esc(string s); EX void non_editable_reaction() { @@ -330,6 +332,10 @@ struct bool_parameter : public val_parameter { menu_item_name_modified = true; return this; } + bool_parameter* help(string help) { + help_text = help; + return this; + } void show_edit_option(int key) override; void load_from_raw(const string& s) override { @@ -512,9 +518,17 @@ void int_parameter::show_edit_option(int key) { void bool_parameter::show_edit_option(int key) { dialog::addBoolItem(XLAT(menu_item_name), *value, key); dialog::add_action([this] () { - add_to_changed(this); - switcher(); if(sets) sets(); - if(reaction) reaction(); + if(use_bool_dialog || hiliteclick) { + auto& bd = dialog::editBool(*value, dft, XLAT(menu_item_name), XLAT(help_text), switcher); + if(sets) sets(); + if(reaction) bd.reaction = reaction; + if(!is_editable) bd.extra_options = non_editable; + } + else { + add_to_changed(this); + switcher(); if(sets) sets(); + if(reaction) reaction(); + } }); } @@ -2353,6 +2367,7 @@ EX void configureInterface() { add_edit(menu_darkening); add_edit(centered_menus); add_edit(startanims::enabled); + add_edit(use_bool_dialog); dialog::addBreak(50); dialog::addBack(); diff --git a/dialogs.cpp b/dialogs.cpp index 3f318819..6df0aabe 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -70,12 +70,20 @@ EX namespace dialog { scaler sc; int *intval; ld intbuf; bool animatable; + bool *boolval; void draw() override; void apply_edit(); void apply_slider(); string disp(ld x); void reset_str() { s = disp(*editwhat); } }; + + /** bool dialog */ + struct bool_dialog : extdialog { + bool *editwhat, dft; + reaction_t switcher; + void draw() override; + }; #endif EX number_dialog& get_ne() { @@ -1486,7 +1494,43 @@ EX namespace dialog { } else if(doexiton(sym, uni)) ne.popfinal(); }; - } + } + + void bool_dialog::draw() { + cmode = dialogflags; + gamescreen(); + init(title); + + dialog::addBreak(100); + + auto switch_to = [this] (bool b) { + bool do_switch = (*editwhat != b); + auto sw = switcher; + auto re = reaction; + popScreen(); + if(do_switch) { sw(); if(re) re(); } + }; + + dialog::addBoolItem(XLAT("disable"), false, '0'); + dialog::add_action([switch_to] { switch_to(false); }); + + dialog::addBoolItem(XLAT("enable"), true, '1'); + dialog::add_action([switch_to] { switch_to(true); }); + + dialog::addBoolItem(XLAT("switch"), !*editwhat, 's'); + dialog::add_action([switch_to, this] { switch_to(!*editwhat); }); + + dialog::addBoolItem(XLAT("set default"), dft, 'd'); + dialog::add_action([switch_to, this] { switch_to(dft); }); + + dialog::addBreak(100); + + if(help != "") addHelp(help); + + if(extra_options) extra_options(); + + display(); + } int nlpage = 1; int wheelshift = 0; @@ -1567,6 +1611,17 @@ EX namespace dialog { return get_ne(); } + EX extdialog& editBool(bool& b, bool dft, string title, string help, const reaction_t& switcher) { + bool_dialog be; + be.editwhat = &b; + be.dft = dft; + be.title = title; + be.help = help; + be.switcher = switcher; + pushScreen(be); + return get_di(); + } + EX number_dialog& editNumber(int& x, int vmin, int vmax, ld step, int dft, string title, string help) { ld tmp; auto& ne = editNumber(tmp, vmin, vmax, step, dft, title, help);