shithub: puzzles

Download patch

ref: ff860360c3eb6b146674384a15d10fde788bd545
parent: 0dd01866627e82ea21ed0e85021abdb070e0159c
author: Ben Harris <bjh21@bjh21.me.uk>
date: Tue Aug 1 19:07:08 EDT 2023

Same Game: level-triggered keyboard cursor hiding

Same Game doesn't want to show the keyboard cursor when the game is in a
state where no move is possible.  Previously, it did this by having
game_changed_state() hide the cursor on entry to such a state.  That
meant that reaching a dead end and undoing out of it hid the cursor,
which was confusing.

Now the cursor is hidden in game_redraw() if the game is in a dead-end
state without changing the displaysel flag in the game_ui.  That way, if
you undo out of a dead end, the cursor becomes visible again if it was
visible before.

This does mean that you can move the cursor in a dead-end state without
being able to see where it's going.  I think that's tolerable, but maybe
the cursor keys should be disabled in that state as well.

--- a/samegame.c
+++ b/samegame.c
@@ -1093,14 +1093,6 @@
                                const game_state *newstate)
 {
     sel_clear(ui, newstate);
-
-    /*
-     * If the game state has just changed into an unplayable one
-     * (either completed or impossible), we vanish the keyboard-
-     * control cursor.
-     */
-    if (newstate->complete || newstate->impossible)
-	ui->displaysel = false;
 }
 
 static const char *current_key_label(const game_ui *ui,
@@ -1572,8 +1564,13 @@
 	    if ((tile & TILE_JOINRIGHT) && (tile & TILE_JOINDOWN) &&
 		COL(state,x+1,y+1) == col)
 		tile |= TILE_JOINDIAG;
-
-	    if (ui->displaysel && ui->xsel == x && ui->ysel == y)
+            /*
+             * If the game state is an unplayable one (either
+             * completed or impossible), we hide the keyboard-control
+             * cursor.
+             */
+	    if (ui->displaysel && ui->xsel == x && ui->ysel == y &&
+                !(state->complete || state->impossible))
 		tile |= TILE_HASSEL;
 
 	    /* For now we're never expecting oldstate at all (because we have