1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-10 15:59:53 +00:00

bool dialogs

This commit is contained in:
Zeno Rogue 2024-05-27 15:21:31 +02:00
parent 502469a54a
commit 8db11dc683
2 changed files with 74 additions and 4 deletions

View File

@ -20,6 +20,8 @@ EX void add_to_changed(struct parameter *f);
EX bool return_false() { return false; } EX bool return_false() { return false; }
EX bool use_bool_dialog;
EX string param_esc(string s); EX string param_esc(string s);
EX void non_editable_reaction() { EX void non_editable_reaction() {
@ -330,6 +332,10 @@ struct bool_parameter : public val_parameter<bool> {
menu_item_name_modified = true; menu_item_name_modified = true;
return this; return this;
} }
bool_parameter* help(string help) {
help_text = help;
return this;
}
void show_edit_option(int key) override; void show_edit_option(int key) override;
void load_from_raw(const string& s) 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) { void bool_parameter::show_edit_option(int key) {
dialog::addBoolItem(XLAT(menu_item_name), *value, key); dialog::addBoolItem(XLAT(menu_item_name), *value, key);
dialog::add_action([this] () { dialog::add_action([this] () {
add_to_changed(this); if(use_bool_dialog || hiliteclick) {
switcher(); if(sets) sets(); auto& bd = dialog::editBool(*value, dft, XLAT(menu_item_name), XLAT(help_text), switcher);
if(reaction) reaction(); 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(menu_darkening);
add_edit(centered_menus); add_edit(centered_menus);
add_edit(startanims::enabled); add_edit(startanims::enabled);
add_edit(use_bool_dialog);
dialog::addBreak(50); dialog::addBreak(50);
dialog::addBack(); dialog::addBack();

View File

@ -70,12 +70,20 @@ EX namespace dialog {
scaler sc; scaler sc;
int *intval; ld intbuf; int *intval; ld intbuf;
bool animatable; bool animatable;
bool *boolval;
void draw() override; void draw() override;
void apply_edit(); void apply_edit();
void apply_slider(); void apply_slider();
string disp(ld x); string disp(ld x);
void reset_str() { s = disp(*editwhat); } void reset_str() { s = disp(*editwhat); }
}; };
/** bool dialog */
struct bool_dialog : extdialog {
bool *editwhat, dft;
reaction_t switcher;
void draw() override;
};
#endif #endif
EX number_dialog& get_ne() { EX number_dialog& get_ne() {
@ -1488,6 +1496,42 @@ EX namespace dialog {
}; };
} }
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 nlpage = 1;
int wheelshift = 0; int wheelshift = 0;
@ -1567,6 +1611,17 @@ EX namespace dialog {
return get_ne(); 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) { EX number_dialog& editNumber(int& x, int vmin, int vmax, ld step, int dft, string title, string help) {
ld tmp; ld tmp;
auto& ne = editNumber(tmp, vmin, vmax, step, dft, title, help); auto& ne = editNumber(tmp, vmin, vmax, step, dft, title, help);