1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-09 23:49:53 +00:00

dialog items now use key_type for key, not int -- this fixes the bugs where char was used, causing search to fail

This commit is contained in:
Zeno Rogue 2024-06-18 01:04:48 +02:00
parent c22aeedde9
commit 6728484cf7
4 changed files with 51 additions and 48 deletions

View File

@ -29,6 +29,8 @@ EX void non_editable_post() { if(!delayed_start) start_game(); };
#if HDR #if HDR
using key_type = int;
struct param_exception : hr_exception { struct param_exception : hr_exception {
struct parameter *which; struct parameter *which;
param_exception() : hr_exception("param_exception"), which(nullptr) {} param_exception() : hr_exception("param_exception"), which(nullptr) {}
@ -57,7 +59,7 @@ struct parameter : public std::enable_shared_from_this<parameter> {
virtual bool available() { if(restrict) return restrict(); return true; } virtual bool available() { if(restrict) return restrict(); return true; }
virtual bool affects(void *v) { return false; } virtual bool affects(void *v) { return false; }
void show_edit_option() { show_edit_option(default_key); } void show_edit_option() { show_edit_option(default_key); }
virtual void show_edit_option(int key) { virtual void show_edit_option(key_type key) {
println(hlog, "warning: no edit option defined for ", name); println(hlog, "warning: no edit option defined for ", name);
} }
virtual string search_key() { virtual string search_key() {
@ -142,7 +144,7 @@ struct list_parameter : parameter {
default_key = key; default_key = key;
return this; return this;
} }
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
}; };
namespace anims { namespace anims {
@ -262,7 +264,7 @@ struct float_parameter : public val_parameter<ld> {
} }
function<void(float_parameter*)> modify_me; function<void(float_parameter*)> modify_me;
float_parameter *modif(const function<void(float_parameter*)>& r) { modify_me = r; return this; } float_parameter *modif(const function<void(float_parameter*)>& r) { modify_me = r; return this; }
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
void load_from_raw(const string& s) override { *value = parseld(s); } void load_from_raw(const string& s) override { *value = parseld(s); }
cld get_cld() override { return *value; } cld get_cld() override { return *value; }
void set_cld_raw(cld x) override { *value = real(x); } void set_cld_raw(cld x) override { *value = real(x); }
@ -271,7 +273,7 @@ struct float_parameter : public val_parameter<ld> {
}; };
struct float_parameter_dft : public float_parameter { struct float_parameter_dft : public float_parameter {
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
function<ld()> get_hint; function<ld()> get_hint;
float_parameter_dft* set_hint(const function<ld()>& f) { get_hint = f; return this; } float_parameter_dft* set_hint(const function<ld()>& f) { get_hint = f; return this; }
}; };
@ -281,7 +283,7 @@ struct int_parameter : public val_parameter<int> {
ld step; ld step;
function<void(int_parameter*)> modify_me; function<void(int_parameter*)> modify_me;
int_parameter *modif(const function<void(int_parameter*)>& r) { modify_me = r; return this; } int_parameter *modif(const function<void(int_parameter*)>& r) { modify_me = r; return this; }
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
int_parameter *editable(int min_value, int max_value, ld step, string menu_item_name, string help_text, char key) { int_parameter *editable(int min_value, int max_value, ld step, string menu_item_name, string help_text, char key) {
this->is_editable = true; this->is_editable = true;
this->min_value = min_value; this->min_value = min_value;
@ -314,7 +316,7 @@ struct string_parameter: public val_parameter<string> {
reaction_t editor; reaction_t editor;
string save() override { return *value; } string save() override { return *value; }
void load_from_raw(const string& s) override { *value = s; } void load_from_raw(const string& s) override { *value = s; }
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
string_parameter* set_standard_editor(bool direct); string_parameter* set_standard_editor(bool direct);
string_parameter* set_file_editor(string ext); string_parameter* set_file_editor(string ext);
string_parameter* editable(string cap, string help, char key ) { string_parameter* editable(string cap, string help, char key ) {
@ -329,7 +331,7 @@ struct string_parameter: public val_parameter<string> {
struct char_parameter : public val_parameter<char> { struct char_parameter : public val_parameter<char> {
string save() override { return "\\" + its(*value); } string save() override { return "\\" + its(*value); }
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
void load_from_raw(const string& s) override { void load_from_raw(const string& s) override {
if(s[0] == '\\' && s.size() > 1) *value = parseint(s.substr(1)); if(s[0] == '\\' && s.size() > 1) *value = parseint(s.substr(1));
else sscanf(s.c_str(), "%c", value); else sscanf(s.c_str(), "%c", value);
@ -349,7 +351,7 @@ struct bool_parameter : public val_parameter<bool> {
help_text = help; help_text = help;
return this; return this;
} }
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
void load_from_raw(const string& s) override { void load_from_raw(const string& s) override {
if(s == "yes") *value = true; if(s == "yes") *value = true;
@ -363,7 +365,7 @@ struct bool_parameter : public val_parameter<bool> {
struct color_parameter : public val_parameter<color_t> { struct color_parameter : public val_parameter<color_t> {
bool has_alpha; bool has_alpha;
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
color_parameter *editable(string menu_item_name, string help_text, char key) { color_parameter *editable(string menu_item_name, string help_text, char key) {
this->is_editable = true; this->is_editable = true;
this->menu_item_name = menu_item_name; this->menu_item_name = menu_item_name;
@ -402,7 +404,7 @@ struct matrix_parameter : public val_parameter<matrix_eq> {
bool dosave() override { return !eqmatrix(*value, dft); } bool dosave() override { return !eqmatrix(*value, dft); }
int dim; int dim;
void show_edit_option(int key) override; void show_edit_option(key_type key) override;
matrix_parameter *editable(string menu_item_name, string help_text, char key) { matrix_parameter *editable(string menu_item_name, string help_text, char key) {
this->is_editable = true; this->is_editable = true;
this->menu_item_name = menu_item_name; this->menu_item_name = menu_item_name;
@ -432,7 +434,7 @@ struct matrix_parameter : public val_parameter<matrix_eq> {
struct custom_parameter : public parameter { struct custom_parameter : public parameter {
cld last_value, anim_value; cld last_value, anim_value;
function<void(char)> custom_viewer; function<void(key_type)> custom_viewer;
function<cld()> custom_value; function<cld()> custom_value;
function<bool(void*)> custom_affect; function<bool(void*)> custom_affect;
function<void(const string&)> custom_load; function<void(const string&)> custom_load;
@ -446,7 +448,7 @@ struct custom_parameter : public parameter {
return parameter::clone(lps, value); return parameter::clone(lps, value);
} }
void show_edit_option(int key) override { custom_viewer(key); } void show_edit_option(key_type key) override { custom_viewer(key); }
bool affects(void *v) override { return custom_affect(v); } bool affects(void *v) override { return custom_affect(v); }
void check_change() override { void check_change() override {
if(custom_value() != last_value) { if(custom_value() != last_value) {
@ -489,7 +491,7 @@ void non_editable() {
dialog::addHelp("Warning: editing this value through this menu may not work correctly"); dialog::addHelp("Warning: editing this value through this menu may not work correctly");
} }
void float_parameter::show_edit_option(int key) { void float_parameter::show_edit_option(key_type key) {
if(modify_me) modify_me(this); if(modify_me) modify_me(this);
dialog::addSelItem(XLAT(menu_item_name), fts(*value) + unit, key); dialog::addSelItem(XLAT(menu_item_name), fts(*value) + unit, key);
if(*value == use_the_default_value) dialog::lastItem().value = XLAT("default"); if(*value == use_the_default_value) dialog::lastItem().value = XLAT("default");
@ -502,7 +504,7 @@ void float_parameter::show_edit_option(int key) {
}); });
} }
void float_parameter_dft::show_edit_option(int key) { void float_parameter_dft::show_edit_option(key_type key) {
if(modify_me) modify_me(this); if(modify_me) modify_me(this);
dialog::addSelItem(XLAT(menu_item_name), fts(*value) + unit, key); dialog::addSelItem(XLAT(menu_item_name), fts(*value) + unit, key);
if(*value == use_the_default_value) dialog::lastItem().value = XLAT("default: ") + fts(get_hint()); if(*value == use_the_default_value) dialog::lastItem().value = XLAT("default: ") + fts(get_hint());
@ -522,7 +524,7 @@ void float_parameter_dft::show_edit_option(int key) {
}); });
} }
void int_parameter::show_edit_option(int key) { void int_parameter::show_edit_option(key_type key) {
if(modify_me) modify_me(this); if(modify_me) modify_me(this);
dialog::addSelItem(XLAT(menu_item_name), its(*value), key); dialog::addSelItem(XLAT(menu_item_name), its(*value), key);
dialog::add_action([this] () { dialog::add_action([this] () {
@ -534,7 +536,7 @@ void int_parameter::show_edit_option(int key) {
}); });
} }
void bool_parameter::show_edit_option(int key) { void bool_parameter::show_edit_option(key_type key) {
dialog::addBoolItem(XLAT(menu_item_name), *value, key); dialog::addBoolItem(XLAT(menu_item_name), *value, key);
if(is_highlight(dialog::items.back()) && help_text != menu_item_name) mouseovers = XLAT(help_text); if(is_highlight(dialog::items.back()) && help_text != menu_item_name) mouseovers = XLAT(help_text);
dialog::add_action([this] () { dialog::add_action([this] () {
@ -552,7 +554,7 @@ void bool_parameter::show_edit_option(int key) {
}); });
} }
void color_parameter::show_edit_option(int key) { void color_parameter::show_edit_option(key_type key) {
dialog::addColorItem(XLAT(menu_item_name), has_alpha ? *value : addalpha(*value), key); dialog::addColorItem(XLAT(menu_item_name), has_alpha ? *value : addalpha(*value), key);
dialog::add_action([this] () { dialog::add_action([this] () {
dialog::openColorDialog(*value); dialog::openColorDialog(*value);
@ -561,7 +563,7 @@ void color_parameter::show_edit_option(int key) {
}); });
} }
void matrix_parameter::show_edit_option(int key) { void matrix_parameter::show_edit_option(key_type key) {
dialog::addMatrixItem(XLAT(menu_item_name), *value, key, dim); dialog::addMatrixItem(XLAT(menu_item_name), *value, key, dim);
dialog::add_action([this] () { dialog::add_action([this] () {
dialog::editMatrix(*value, XLAT(menu_item_name), help_text, dim); dialog::editMatrix(*value, XLAT(menu_item_name), help_text, dim);
@ -570,12 +572,12 @@ void matrix_parameter::show_edit_option(int key) {
}); });
} }
void char_parameter::show_edit_option(int key) { void char_parameter::show_edit_option(key_type key) {
string s = s0; s += *(value); string s = s0; s += *(value);
dialog::addSelItem(XLAT(menu_item_name), s, key); dialog::addSelItem(XLAT(menu_item_name), s, key);
} }
void string_parameter::show_edit_option(int key) { void string_parameter::show_edit_option(key_type key) {
dialog::addSelItem(XLAT(menu_item_name), *value, key); dialog::addSelItem(XLAT(menu_item_name), *value, key);
if(!editor) { if(!editor) {
if(is_highlight(dialog::items.back())) mouseovers = XLAT("not editable"); if(is_highlight(dialog::items.back())) mouseovers = XLAT("not editable");
@ -790,7 +792,7 @@ shared_ptr<parameter> float_parameter::clone(struct local_parameter_set& lps, vo
#if HDR #if HDR
template<class T> 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> param_custom_int(T& val, const parameter_names& n, function<void(key_type)> menuitem, char key) {
shared_ptr<custom_parameter> u ( new custom_parameter ); shared_ptr<custom_parameter> u ( new custom_parameter );
u->setup(n); u->setup(n);
int dft = (int) val; int dft = (int) val;
@ -809,7 +811,7 @@ shared_ptr<custom_parameter> param_custom_int(T& val, const parameter_names& n,
} }
#endif #endif
EX shared_ptr<custom_parameter> param_custom_ld(ld& val, const parameter_names& n, function<void(char)> menuitem, char key) { EX shared_ptr<custom_parameter> param_custom_ld(ld& val, const parameter_names& n, function<void(key_type)> menuitem, char key) {
shared_ptr<custom_parameter> u ( new custom_parameter ); shared_ptr<custom_parameter> u ( new custom_parameter );
u->setup(n); u->setup(n);
ld dft = val; ld dft = val;
@ -1245,8 +1247,8 @@ EX void initConfig() {
param_b(vid.relative_window_size, "window_relative", true) param_b(vid.relative_window_size, "window_relative", true)
->editable("specify relative window size", 'g'); ->editable("specify relative window size", 'g');
param_custom_int(vid.xres, "xres", [] (char ch) {}, 0)->restrict = return_false; param_custom_int(vid.xres, "xres", [] (key_type ch) {}, 0)->restrict = return_false;
param_custom_int(vid.yres, "yres", [] (char ch) {}, 0)->restrict = return_false; param_custom_int(vid.yres, "yres", [] (key_type ch) {}, 0)->restrict = return_false;
param_i(vid.fullscreen_x, "fullscreen_x", 1280) param_i(vid.fullscreen_x, "fullscreen_x", 1280)
-> editable(640, 3840, 640, "fullscreen resolution to use (X)", "", 'x') -> editable(640, 3840, 640, "fullscreen resolution to use (X)", "", 'x')
@ -1939,7 +1941,7 @@ string solhelp() {
#endif #endif
} }
EX void menuitem_sightrange_bonus(char c) { EX void menuitem_sightrange_bonus(key_type c) {
dialog::addSelItem(XLAT("sight range bonus"), its(sightrange_bonus), c); dialog::addSelItem(XLAT("sight range bonus"), its(sightrange_bonus), c);
dialog::add_action([]{ dialog::add_action([]{
dialog::editNumber(sightrange_bonus, -5, allowIncreasedSight() ? 3 : 0, 1, 0, XLAT("sight range"), dialog::editNumber(sightrange_bonus, -5, allowIncreasedSight() ? 3 : 0, 1, 0, XLAT("sight range"),
@ -2041,7 +2043,7 @@ EX void edit_sightrange() {
dialog::display(); dialog::display();
} }
EX void menuitem_sightrange_style(char c IS('c')) { EX void menuitem_sightrange_style(key_type c IS('c')) {
dialog::addSelItem(XLAT("draw range based on"), dialog::addSelItem(XLAT("draw range based on"),
vid.use_smart_range == 0 ? XLAT("distance") : vid.use_smart_range == 0 ? XLAT("distance") :
vid.use_smart_range == 1 ? XLAT("size (no gen)") : vid.use_smart_range == 1 ? XLAT("size (no gen)") :
@ -2068,7 +2070,7 @@ EX void menuitem_sightrange_style(char c IS('c')) {
}); });
} }
EX void menuitem_sightrange(char c IS('c')) { EX void menuitem_sightrange(key_type c IS('c')) {
#if CAP_SOLV #if CAP_SOLV
if(pmodel == mdGeodesic && sol) if(pmodel == mdGeodesic && sol)
dialog::addSelItem(XLAT("sight range settings"), fts(sn::solrange_xy) + "x" + fts(sn::solrange_z), c); dialog::addSelItem(XLAT("sight range settings"), fts(sn::solrange_xy) + "x" + fts(sn::solrange_z), c);
@ -2559,7 +2561,7 @@ EX void projectionDialog() {
}; };
} }
EX void menuitem_projection_distance(char key) { EX void menuitem_projection_distance(key_type key) {
dialog::addSelItem(XLAT("projection distance"), fts(vpconf.alpha) + " (" + current_proj_name() + ")", key); dialog::addSelItem(XLAT("projection distance"), fts(vpconf.alpha) + " (" + current_proj_name() + ")", key);
dialog::add_action(projectionDialog); dialog::add_action(projectionDialog);
} }
@ -3905,7 +3907,7 @@ EX void edit_all_parameters() {
dialog::display(); dialog::display();
} }
void list_parameter::show_edit_option(int key) { void list_parameter::show_edit_option(key_type key) {
string opt; string opt;
if(get_value() < 0 || get_value() >= isize(options)) opt = its(get_value()); if(get_value() < 0 || get_value() >= isize(options)) opt = its(get_value());
else opt = options[get_value()].first; else opt = options[get_value()].first;

View File

@ -23,7 +23,7 @@ EX namespace dialog {
tDialogItem type; tDialogItem type;
string body; string body;
string value; string value;
int key; key_type key;
color_t color, colorv, colork, colors, colorc; color_t color, colorv, colork, colors, colorc;
int scale; int scale;
double param; double param;
@ -180,13 +180,13 @@ EX namespace dialog {
EX item& titleItem() { return items[0]; } EX item& titleItem() { return items[0]; }
EX map<int, reaction_t> key_actions; EX map<key_type, reaction_t> key_actions;
EX void add_key_action(int key, const reaction_t& action) { EX void add_key_action(key_type key, const reaction_t& action) {
key_actions[key] = action; key_actions[key] = action;
} }
EX void add_key_action_adjust(int& key, const reaction_t& action) { EX void add_key_action_adjust(key_type& key, const reaction_t& action) {
while(key_actions.count(key)) key++; while(key_actions.count(key)) key++;
add_key_action(key, action); add_key_action(key, action);
} }
@ -220,7 +220,7 @@ EX namespace dialog {
keyhandler = dialog::handler; keyhandler = dialog::handler;
} }
EX string keyname(int k) { EX string keyname(key_type k) {
if(k == 0) return ""; if(k == 0) return "";
if(k == SDLK_ESCAPE) return "Esc"; if(k == SDLK_ESCAPE) return "Esc";
if(k == SDLK_F1) return "F1"; if(k == SDLK_F1) return "F1";
@ -254,14 +254,14 @@ EX namespace dialog {
scale = 100; scale = 100;
} }
EX void addSlider(double d1, double d2, double d3, int key) { EX void addSlider(double d1, double d2, double d3, key_type key) {
item it(diSlider); item it(diSlider);
it.key = key; it.key = key;
it.param = (d2-d1) / (d3-d1); it.param = (d2-d1) / (d3-d1);
items.push_back(it); items.push_back(it);
} }
EX void addIntSlider(int d1, int d2, int d3, int key) { EX void addIntSlider(int d1, int d2, int d3, key_type key) {
item it(diIntSlider); item it(diIntSlider);
it.key = key; it.key = key;
it.p1 = (d2-d1); it.p1 = (d2-d1);
@ -269,7 +269,7 @@ EX namespace dialog {
items.push_back(it); items.push_back(it);
} }
EX void addSelItem(string body, string value, int key) { EX void addSelItem(string body, string value, key_type key) {
item it(diItem); item it(diItem);
it.body = body; it.body = body;
it.value = value; it.value = value;
@ -279,7 +279,7 @@ EX namespace dialog {
items.push_back(it); items.push_back(it);
} }
EX void addBoolItem(string body, bool value, int key) { EX void addBoolItem(string body, bool value, key_type key) {
addSelItem(body, ONOFF(value), key); addSelItem(body, ONOFF(value), key);
} }
@ -303,7 +303,7 @@ EX namespace dialog {
items.push_back(it); items.push_back(it);
} }
EX void addColorItem(string body, int value, int key) { EX void addColorItem(string body, int value, key_type key) {
addSelItem(body, COLORBAR, key); addSelItem(body, COLORBAR, key);
auto& it = items.back(); auto& it = items.back();
it.type = diColorItem; it.type = diColorItem;
@ -318,7 +318,7 @@ EX namespace dialog {
return alpha / degree; return alpha / degree;
} }
EX void addMatrixItem(string body, transmatrix& value, int key, int dim IS(GDIM)) { EX void addMatrixItem(string body, transmatrix& value, key_type key, int dim IS(GDIM)) {
addSelItem(body, COLORBAR, key); addSelItem(body, COLORBAR, key);
auto& it = items.back(); auto& it = items.back();
it.type = diMatrixItem; it.type = diMatrixItem;
@ -360,14 +360,14 @@ EX namespace dialog {
items.push_back(it); items.push_back(it);
} }
EX void addItem(string body, int key) { EX void addItem(string body, key_type key) {
item it(diItem); item it(diItem);
it.body = body; it.body = body;
it.key = key; it.key = key;
items.push_back(it); items.push_back(it);
} }
EX void addBigItem(string body, int key) { EX void addBigItem(string body, key_type key) {
item it(diBigItem); item it(diBigItem);
it.body = body; it.body = body;
it.key = key; it.key = key;

View File

@ -680,22 +680,23 @@ void action_change_variation() {
#endif #endif
} }
EX void menuitem_change_variation(char key) {
EX void menuitem_change_variation(key_type key) {
dialog::addSelItem(XLAT("variations"), gp::operation_name(), key); dialog::addSelItem(XLAT("variations"), gp::operation_name(), key);
dialog::add_action(action_change_variation); dialog::add_action(action_change_variation);
} }
EX void menuitem_change_geometry(char key) { EX void menuitem_change_geometry(key_type key) {
dialog::addSelItem(XLAT("geometry/topology/tiling"), full_geometry_name(), key); dialog::addSelItem(XLAT("geometry/topology/tiling"), full_geometry_name(), key);
dialog::add_action_push(current_filter ? ge_select_tiling : ge_select_filter); dialog::add_action_push(current_filter ? ge_select_tiling : ge_select_filter);
} }
EX void menuitem_projection(char key) { EX void menuitem_projection(key_type key) {
dialog::addSelItem(XLAT("projection"), current_proj_name(), key); dialog::addSelItem(XLAT("projection"), current_proj_name(), key);
dialog::add_action_push(models::model_menu); dialog::add_action_push(models::model_menu);
} }
EX void menuitem_binary_width(char key) { EX void menuitem_binary_width(key_type key) {
dialog::addSelItem(XLAT("binary tiling width"), fts(vid.binary_width), key); dialog::addSelItem(XLAT("binary tiling width"), fts(vid.binary_width), key);
dialog::add_action([] { dialog::add_action([] {
dialog::editNumber(vid.binary_width, 0, 2, 0.1, 1, XLAT("binary tiling width"), ""); dialog::editNumber(vid.binary_width, 0, 2, 0.1, 1, XLAT("binary tiling width"), "");
@ -710,7 +711,7 @@ EX void menuitem_binary_width(char key) {
}); });
} }
EX void menuitem_nilwidth(char key) { EX void menuitem_nilwidth(key_type key) {
dialog::addSelItem(XLAT("Nil width"), fts(nilv::nilwidth), key); dialog::addSelItem(XLAT("Nil width"), fts(nilv::nilwidth), key);
dialog::add_action([] { dialog::add_action([] {
dialog::editNumber(nilv::nilwidth, 0.01, 2, 0.1, 1, XLAT("Nil width"), ""); dialog::editNumber(nilv::nilwidth, 0.01, 2, 0.1, 1, XLAT("Nil width"), "");

View File

@ -724,7 +724,7 @@ EX eLandStructure default_land_structure() {
return lsNoWalls; return lsNoWalls;
} }
EX void menuitem_land_structure(char key) { EX void menuitem_land_structure(key_type key) {
if(default_land_structure() == land_structure && !ineligible_starting_land) if(default_land_structure() == land_structure && !ineligible_starting_land)
dialog::addBoolItem(XLAT("land structure"), false, key); dialog::addBoolItem(XLAT("land structure"), false, key);