1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-14 12:47:10 +00:00

param_matrix

This commit is contained in:
Zeno Rogue
2023-08-08 17:20:39 +02:00
parent c914bf86e0
commit a13ba9bdbe
5 changed files with 139 additions and 22 deletions

View File

@@ -204,6 +204,28 @@ struct color_setting : public setting {
}
};
struct matrix_setting : public setting {
trans23 *value;
trans23 dft;
trans23 last_value_matrix;
supersaver *make_saver() override;
bool affects(void *v) override { return v == value; }
void show_edit_option(int key) override;
cld get_cld() override { return 0; }
void set_cld(cld x) override { }
matrix_setting *editable(string menu_item_name, string help_text, char key) {
this->is_editable = true;
this->menu_item_name = menu_item_name;
this->help_text = help_text;
default_key = key;
return this;
}
void load_from(const string& s) override {
*value = parsematrix23(s);
}
};
struct char_setting : public setting {
char *value;
char dft;
@@ -362,6 +384,34 @@ template<> struct saver<string> : dsaver<string> {
virtual void swap_with(supersaver *s) { swap(val, ((saver<string>*)s)->val); }
};
template<> struct saver<trans23> : supersaver {
trans23& val;
trans23 dft;
explicit saver(trans23& _val) : val(_val) { }
void reset() override { val = dft; }
bool affects(void* v) override { return v == &val; }
void set_default() override { dft = val; }
bool dosave() override { return !eqmatrix(val.v2, dft.v2) || !eqmatrix(val.v3, dft.v3); }
string save() override {
shstream ss;
for(int a=0; a<4; a++) for(int b=0; b<4; b++) print(ss, val.v2[a][b], " ");
for(int a=0; a<4; a++) for(int b=0; b<4; b++) print(ss, val.v3[a][b], " ");
return ss.s;
}
void load(const string& s) override {
shstream ss;
ss.s = s;
for(int a=0; a<4; a++) for(int b=0; b<4; b++) scan(ss, val.v2[a][b]);
for(int a=0; a<4; a++) for(int b=0; b<4; b++) scan(ss, val.v3[a][b]);
}
virtual void clone(struct local_parameter_set& lps, void *value) override { addsaver(*(trans23*) value, lps.label + name); }
virtual void swap_with(supersaver *s) override { swap(val, ((saver<trans23>*)s)->val); }
};
template<> struct saver<ld> : dsaver<ld> {
explicit saver(ld& val) : dsaver<ld>(val) { }
string save() override { return fts(val, 10); }
@@ -399,6 +449,14 @@ supersaver* color_setting::make_saver() {
#endif
}
supersaver* matrix_setting::make_saver() {
#if CAP_CONFIG
return addsaver(*value, config_name, dft);
#else
return nullptr;
#endif
}
supersaver *char_setting::make_saver() {
#if CAP_CONFIG
return addsaver(*value, config_name, dft);
@@ -488,6 +546,13 @@ void color_setting::show_edit_option(int key) {
});
}
void matrix_setting::show_edit_option(int key) {
dialog::addMatrixItem(XLAT(menu_item_name), *value, key);
dialog::add_action([this] () {
dialog::editMatrix(*value, XLAT(menu_item_name), help_text);
});
}
void char_setting::show_edit_option(int key) {
string s = s0; s += value;
dialog::addSelItem(XLAT(menu_item_name), s, key);
@@ -602,6 +667,20 @@ EX color_setting *param_color(color_t& val, const string s, bool has_alpha, colo
return f;
}
EX matrix_setting *param_matrix(trans23& val, const string s) {
unique_ptr<matrix_setting> u ( new matrix_setting );
u->parameter_name = param_esc(s);
u->config_name = s;
u->menu_item_name = s;
u->value = &val;
u->last_value_matrix = val;
u->dft = val;
u->register_saver();
auto f = &*u;
params[u->parameter_name] = std::move(u);
return f;
}
EX char_setting *param_char(char& val, const string s, char dft) {
unique_ptr<char_setting> u ( new char_setting );
u->parameter_name = param_esc(s);