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)
This commit is contained in:
Ben Harris
2023-05-30 19:57:15 +02:00
parent 5acce15ed9
commit 4227ac1fd5
4 changed files with 80 additions and 11 deletions

37
guess.c
View File

@ -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,

12
map.c
View File

@ -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)

View File

@ -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}

View File

@ -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 */