chiark / gitweb /
Net: rework status line to cope with empty squares.
authorSimon Tatham <anakin@pobox.com>
Mon, 13 Mar 2017 19:58:22 +0000 (19:58 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 13 Mar 2017 19:58:22 +0000 (19:58 +0000)
Another oddity involving an empty square is that if it coincides with
the source square for highlights (either by original design of the
game id, or because the player Ctrl-moves the source square into an
empty grid cell during play), then everything stops being lit up as
active. That's fine - you can still play the game using other
indications of error, such as the loop detection highlight - but it
looks silly for the status line to say 'Active: 1/lots'. So in that
situation I suppress the 'active' counter completely; it comes back
when you move the source square to somewhere it's _possible_ to
highlight more than one square.

While I'm at it, I've also removed the active counter in the case
where the game is completely solved, because in that situation it's
more or less unnecessary anyway, and that way the normal course of
play on the default small grid size doesn't overflow the available
status line space.

net.c

diff --git a/net.c b/net.c
index d3952a864dfac3c4ad3c8592e14252aa69773e37..738ff53d83c92fb8a4850baaa16f15f36cc425cc 100644 (file)
--- a/net.c
+++ b/net.c
@@ -2971,20 +2971,43 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
      * Update the status bar.
      */
     {
-       char statusbuf[256];
+       char statusbuf[256], *p;
        int i, n, n2, a;
+        int complete = FALSE;
 
-       n = state->width * state->height;
-       for (i = a = n2 = 0; i < n; i++) {
-           if (active[i])
-               a++;
-            if (state->tiles[i] & 0xF)
-                n2++;
+        p = statusbuf;
+        *p = '\0';     /* ensure even an empty status string is terminated */
+
+        if (state->used_solve) {
+            p += sprintf(p, "Auto-solved. ");
+            complete = TRUE;
+        } else if (state->completed) {
+            p += sprintf(p, "COMPLETED! ");
+            complete = TRUE;
         }
 
-       sprintf(statusbuf, "%sActive: %d/%d",
-               (state->used_solve ? "Auto-solved. " :
-                state->completed ? "COMPLETED! " : ""), a, n2);
+        /*
+         * Omit the 'Active: n/N' counter completely if the source
+         * tile is a completely empty one, because then the active
+         * count can't help but read '1'.
+         */
+        if (tile(state, ui->cx, ui->cy) & 0xF) {
+            n = state->width * state->height;
+            for (i = a = n2 = 0; i < n; i++) {
+                if (active[i])
+                    a++;
+                if (state->tiles[i] & 0xF)
+                    n2++;
+            }
+
+            /*
+             * Also, if we're displaying a completion indicator and
+             * the game is still in its completed state (i.e. every
+             * tile is active), we might as well omit this too.
+             */
+            if (!complete || a < n2)
+                p += sprintf(p, "Active: %d/%d", a, n2);
+        }
 
        status_bar(dr, statusbuf);
     }