1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-10-01 15:30:40 +00:00

config:: custom parameters now have custom_do_save

This commit is contained in:
Zeno Rogue 2024-05-26 20:51:33 +02:00
parent 57691737f0
commit ff8bb20a55
2 changed files with 12 additions and 6 deletions

View File

@ -408,6 +408,7 @@ struct custom_parameter : public parameter {
function<bool(void*)> custom_affect;
function<void(const string&)> custom_load;
function<string()> custom_save;
function<bool()> custom_do_save;
function<shared_ptr<parameter>(struct local_parameter_set& lps, void *value)> custom_clone;
virtual shared_ptr<parameter> clone(struct local_parameter_set& lps, void *value) {
@ -449,7 +450,7 @@ struct custom_parameter : public parameter {
virtual cld get_cld() override { return custom_value(); }
virtual string save() override { if(custom_save) return custom_save(); else return "not saveable"; }
virtual bool dosave() override { return false; }
virtual bool dosave() override { if(custom_do_save) return custom_do_save(); else return false; }
virtual void reset() override {}
virtual void set_default() override {}
virtual void swap_with(parameter*) override {}
@ -725,12 +726,14 @@ template<class T>
shared_ptr<custom_parameter> param_custom_int(T& val, const parameter_names& n, function<void(char)> menuitem, char key) {
shared_ptr<custom_parameter> u ( new custom_parameter );
u->setup(n);
u->last_value = (int) val;
int dft = (int) val;
u->last_value = dft;
u->custom_viewer = menuitem;
u->custom_value = [&val] () { return (int) val; };
u->custom_affect = [&val] (void *v) { return &val == v; };
u->custom_load = [&val] (const string& s) { val = (T) parseint(s); };
u->custom_save = [&val] { return its(int(val)); };
u->custom_do_save = [dft, &val] { return int(val) != dft; };
u->custom_clone = [u] (struct local_parameter_set& lps, void *value) { auto val = (int*) value; return param_i(*val, lps.mod(&*u), *val); };
u->default_key = key;
u->is_editable = true;
@ -741,12 +744,14 @@ shared_ptr<custom_parameter> param_custom_int(T& val, const parameter_names& n,
EX shared_ptr<custom_parameter> param_custom_ld(ld& val, const parameter_names& n, function<void(char)> menuitem, char key) {
shared_ptr<custom_parameter> u ( new custom_parameter );
u->setup(n);
u->last_value = (int) val;
ld dft = val;
u->last_value = dft;
u->custom_viewer = menuitem;
u->custom_value = [&val] () { return val; };
u->custom_affect = [&val] (void *v) { return &val == v; };
u->custom_load = [&val] (const string& s) { val = parseld(s); };
u->custom_save = [&val] { return fts(val, 10); };
u->custom_do_save = [dft, &val] { return val != dft; };
u->custom_clone = [u] (struct local_parameter_set& lps, void *value) { auto val = (ld*) value; return param_f(*val, lps.mod(&*u), *val); };
u->default_key = key;

View File

@ -949,8 +949,9 @@ EX namespace models {
dynamicval<function<bool()>> ds(auto_restrict);
auto_restrict = [&p] { return &vpconf == &p; };
param_enum(p.model, parameter_names(pp+"used_model", pp+"used model"), mdDisk);
if(&p.model == &pmodel) param_custom_int(pmodel, "projection|Poincare|Klein|half-plane|perspective", menuitem_projection, '1');
if(&p.model == &pmodel)
param_custom_int(pmodel, "projection|Poincare|Klein|half-plane|perspective", menuitem_projection, '1');
else param_enum(p.model, parameter_names(pp+"used_model", pp+"used model"), mdDisk);
param_matrix(p.mori().v2, pp+"mori", 2)
-> editable("model orientation", "", 'o');
@ -1063,9 +1064,9 @@ EX namespace models {
param_i(p.back_and_front, sp+"backandfront", 0);
if(&p.model == &pmodel) {
p.alpha = 1;
auto proj = param_custom_ld(p.alpha, sp+"projection", menuitem_projection_distance, 'p');
proj->help_text = "projection distance|Gans Klein Poincare orthographic stereographic";
p.alpha = 1;
}
else {
param_f(p.alpha, sp+"projection", 1);