shithub: puzzles

Download patch

ref: 92ac45fe240b2063455b0b01dedc6ef6996f18af
parent: 3a841891bac72ce959fdc07e8a136dcf527b4f24
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sat Aug 12 10:15:45 EDT 2023

Add user preference for Singles' show_black_nums

I missed this in my main commit for UI preferences
(4227ac1fd5dc25c247e7526526079b85e1890766) because it wasn't documented.
Now it is documented and it has a preference.

--- a/puzzles.but
+++ b/puzzles.but
@@ -2866,7 +2866,9 @@
 
 Left-clicking on an empty square will colour it black; left-clicking again 
 will restore the number. Right-clicking will add a circle (useful for 
-indicating that a cell is definitely not black). 
+indicating that a cell is definitely not black). Clicking outside the
+grid will toggle whether black squares completely hide the numbers on
+them, or display them in dark grey.
 
 You can also use the cursor keys to move around the grid. Pressing the
 return or space keys will turn a square black or add a circle respectively,
@@ -2887,6 +2889,12 @@
 
 \dd Controls the difficulty of the generated puzzle.
 
+\H{Singles-prefs} \I{preferences, for Singles}Singles user preferences
+
+On platforms that support user preferences, the \q{Preferences} option
+on the \q{Game} menu will let you configure whether numbers on black
+squares are visible.  Unlike clicking outside the grid, this will
+persist between games.
 
 \C{magnets} \i{Magnets}
 
--- a/singles.c
+++ b/singles.c
@@ -1456,6 +1456,28 @@
     return ui;
 }
 
+static config_item *get_prefs(game_ui *ui)
+{
+    config_item *ret;
+
+    ret = snewn(2, config_item);
+
+    ret[0].name = "Show numbers on black squares";
+    ret[0].kw = "show-black-nums";
+    ret[0].type = C_BOOLEAN;
+    ret[0].u.boolean.bval = ui->show_black_nums;
+
+    ret[1].name = NULL;
+    ret[1].type = C_END;
+
+    return ret;
+}
+
+static void set_prefs(game_ui *ui, const config_item *cfg)
+{
+    ui->show_black_nums = cfg[0].u.boolean.bval;
+}
+
 static void free_ui(game_ui *ui)
 {
     sfree(ui);
@@ -1525,7 +1547,7 @@
         }
         if (!INGRID(state, x, y)) {
             ui->show_black_nums = !ui->show_black_nums;
-            action = UI; /* this wants to be a per-game option. */
+            action = UI;
         } else if (button == LEFT_BUTTON) {
             action = TOGGLE_BLACK;
         } else if (button == RIGHT_BUTTON) {
@@ -1851,7 +1873,7 @@
     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 */