From ff860360c3eb6b146674384a15d10fde788bd545 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 1 Aug 2023 23:07:08 +0100 Subject: [PATCH] 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. --- samegame.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/samegame.c b/samegame.c index c55dafc..481154e 100644 --- a/samegame.c +++ b/samegame.c @@ -1093,14 +1093,6 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, 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 @@ static void game_redraw(drawing *dr, game_drawstate *ds, 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