From 4227ac1fd5dc25c247e7526526079b85e1890766 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 30 May 2023 19:57:15 +0200 Subject: [PATCH] Add preferences for existing UI style controls Some puzzles have keys that make changes to the display style in ways that would probably have been user preferences if they had existed. I've added a user preference for each of these. The keys still work, and unlike the preferences can be changed without saving any state. The affected settings are: * Labelling colours with numbers in Guess ("L" key) * Labelling regions with numbers in Map ("L" key) * Whether monsters are shown as letters or pictures in Undead ("A" key) --- guess.c | 37 +++++++++++++++++++++++++++++++------ map.c | 12 +++++++++--- puzzles.but | 16 +++++++++++++++- undead.c | 26 +++++++++++++++++++++++++- 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/guess.c b/guess.c index a59e54e..949641a 100644 --- a/guess.c +++ b/guess.c @@ -411,20 +411,45 @@ static game_ui *new_ui(const game_state *state) { game_ui *ui = snew(game_ui); memset(ui, 0, sizeof(game_ui)); - ui->params = state->params; /* structure copy */ - ui->curr_pegs = new_pegrow(state->params.npegs); - ui->holds = snewn(state->params.npegs, bool); + if (state != NULL) { + ui->params = state->params; /* structure copy */ + ui->curr_pegs = new_pegrow(state->params.npegs); + ui->holds = snewn(state->params.npegs, bool); + memset(ui->holds, 0, sizeof(bool)*state->params.npegs); + } ui->display_cur = getenv_bool("PUZZLES_SHOW_CURSOR", false); - memset(ui->holds, 0, sizeof(bool)*state->params.npegs); ui->drag_opeg = -1; return ui; } +static config_item *get_prefs(game_ui *ui) +{ + config_item *ret; + + ret = snewn(2, config_item); + + ret[0].name = "Label colours with numbers"; + ret[0].kw = "show-labels"; + ret[0].type = C_BOOLEAN; + ret[0].u.boolean.bval = ui->show_labels; + + ret[1].name = NULL; + ret[1].type = C_END; + + return ret; +} + +static void set_prefs(game_ui *ui, const config_item *cfg) +{ + ui->show_labels = cfg[0].u.boolean.bval; +} + static void free_ui(game_ui *ui) { if (ui->hint) free_pegrow(ui->hint); - free_pegrow(ui->curr_pegs); + if (ui->curr_pegs) + free_pegrow(ui->curr_pegs); sfree(ui->holds); sfree(ui); } @@ -1518,7 +1543,7 @@ const struct game thegame = { free_game, true, solve_game, false, NULL, NULL, /* can_format_as_text_now, text_format */ - NULL, NULL, /* get_prefs, set_prefs */ + get_prefs, set_prefs, new_ui, free_ui, encode_ui, diff --git a/map.c b/map.c index 966ab75..127db04 100644 --- a/map.c +++ b/map.c @@ -2337,7 +2337,7 @@ static config_item *get_prefs(game_ui *ui) { config_item *ret; - ret = snewn(2, config_item); + ret = snewn(3, config_item); ret[0].name = "Victory flash effect"; ret[0].kw = "flash-type"; @@ -2346,8 +2346,13 @@ static config_item *get_prefs(game_ui *ui) ret[0].u.choices.choicekws = ":cyclic:each-white:all-white"; ret[0].u.choices.selected = ui->flash_type; - ret[1].name = NULL; - ret[1].type = C_END; + ret[1].name = "Number regions"; + ret[1].kw = "show-numbers"; + ret[1].type = C_BOOLEAN; + ret[1].u.boolean.bval = ui->show_numbers; + + ret[2].name = NULL; + ret[2].type = C_END; return ret; } @@ -2355,6 +2360,7 @@ static config_item *get_prefs(game_ui *ui) static void set_prefs(game_ui *ui, const config_item *cfg) { ui->flash_type = cfg[0].u.choices.selected; + ui->show_numbers = cfg[1].u.boolean.bval; } static void free_ui(game_ui *ui) diff --git a/puzzles.but b/puzzles.but index 1e0ebb7..c427d7b 100644 --- a/puzzles.but +++ b/puzzles.but @@ -1443,6 +1443,13 @@ that, use one extra colour. this increases the search space (making things harder), and is turned on by default. +\H{guess-prefs} \I{preferences, for Guess}Guess user preferences + +On platforms that support user preferences, the \q{Preferences} option +on the \q{Game} menu will let you configure whether pegs are labelled +with their numbers. Unlike the \q{L} key, this will persist between +games. + \C{pegs} \i{Pegs} @@ -2004,7 +2011,7 @@ Unreasonable puzzles may require guessing and backtracking. On platforms that support user preferences, the \q{Preferences} option on the \q{Game} menu will let you configure the style of the victory -flash. +flash and also whether the regions start out labelled with numbers. \C{loopy} \i{Loopy} @@ -3288,6 +3295,13 @@ These parameters are available from the \q{Custom...} option on the \dd Controls the difficulty of the generated puzzle. +\H{undead-prefs} \I{preferences, for Undead}Undead user preferences + +On platforms that support user preferences, the \q{Preferences} option +on the \q{Game} menu will let you configure whether Undead uses letters +or pictures to represent monsters. + + \C{unruly} \i{Unruly} \cfg{winhelp-topic}{games.unruly} diff --git a/undead.c b/undead.c index 74dbefc..4784754 100644 --- a/undead.c +++ b/undead.c @@ -1656,6 +1656,30 @@ static game_ui *new_ui(const game_state *state) return ui; } +static config_item *get_prefs(game_ui *ui) +{ + config_item *ret; + + ret = snewn(2, config_item); + + ret[0].name = "Monster representation"; + ret[0].kw = "monsters"; + ret[0].type = C_CHOICES; + ret[0].u.choices.choicenames = ":Pictures:Letters"; + ret[0].u.choices.choicekws = ":pictures:letters"; + ret[0].u.choices.selected = ui->ascii; + + ret[1].name = NULL; + ret[1].type = C_END; + + return ret; +} + +static void set_prefs(game_ui *ui, const config_item *cfg) +{ + ui->ascii = cfg[0].u.choices.selected; +} + static void free_ui(game_ui *ui) { sfree(ui); return; @@ -2784,7 +2808,7 @@ const struct game thegame = { free_game, true, solve_game, true, game_can_format_as_text_now, game_text_format, - NULL, NULL, /* get_prefs, set_prefs */ + get_prefs, set_prefs, new_ui, free_ui, NULL, /* encode_ui */