gnome-games r7177 - trunk/aisleriot



Author: chpe
Date: Sun Jan 13 22:07:46 2008
New Revision: 7177
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7177&view=rev

Log:
Make aisleriot_board_move_cursor_start_end_in_slot work correctly in the presence
of face-up cards between face-down cards (e.g. Athena).
When extending the selection, don't jump over face-down cards (so the focus comes
to the start of the selection.)


Modified:
   trunk/aisleriot/board.c

Modified: trunk/aisleriot/board.c
==============================================================================
--- trunk/aisleriot/board.c	(original)
+++ trunk/aisleriot/board.c	Sun Jan 13 22:07:46 2008
@@ -1585,32 +1585,62 @@
 
 static gboolean
 aisleriot_board_move_cursor_start_end_in_slot (AisleriotBoard *board,
-                                               int count)
+                                               int count,
+                                               gboolean step_over_face_down_cards)
 {
   AisleriotBoardPrivate *priv = board->priv;
-  Slot *focus_slot;
-  int new_focus_card_id;
+  Slot *focus_slot = priv->focus_slot;
+  int first_card_id, top_card_id, new_focus_card_id;
+  guint8 *cards;
 
-  g_print ("start-end-in-slot %d\n", count);
+  if (focus_slot->cards->len == 0)
+    return FALSE;
 
-  focus_slot = priv->focus_slot;
-  if (count > 0) {
-    new_focus_card_id = ((int) focus_slot->cards->len) - 1;
-  } else {
-    if (focus_slot->cards->len > 0) {
-      new_focus_card_id = ((int) focus_slot->cards->len) - ((int) focus_slot->exposed);
-    } else {
-      new_focus_card_id = -1;
-    }
-  }
+  g_assert (priv->focus_card_id >= 0);
 
-  g_assert (new_focus_card_id >= -1);
+  /* Moves the cursor to the first/last card above/below a face-down
+   * card, or the start/end of the slot if there are no face-down cards
+   * between the currently focused card and the slot start/end.
+   * (Jumping over face-down cards and landing on a non-face-down card
+   * happens e.g. in Athena.)
+   */
+  cards = focus_slot->cards->data;
+  top_card_id = ((int) focus_slot->cards->len) - 1;
+  first_card_id = ((int) focus_slot->cards->len) - ((int) focus_slot->exposed);
+  new_focus_card_id = priv->focus_card_id;
 
-  /* FIXMEchpe: maybe just eat it up silently? */
-  if (new_focus_card_id == priv->focus_card_id)
-    return FALSE;
+  if (step_over_face_down_cards ||
+      CARD_GET_FACE_DOWN(((Card) cards[new_focus_card_id]))) {
+    /* Set new_focus_card_id to the index of the last face-down card
+     * in the run of face-down cards.
+     */
+    do {
+      new_focus_card_id += count;
+    } while (new_focus_card_id >= first_card_id &&
+            new_focus_card_id <= top_card_id &&
+            CARD_GET_FACE_DOWN (((Card) cards[new_focus_card_id])));
+
+    /* We went one too far */
+    new_focus_card_id -= count;
+  }
+
+  /* Now get to the start/end of the run of face-up cards */
+  do {
+    new_focus_card_id += count;
+  } while (new_focus_card_id >= first_card_id &&
+           new_focus_card_id <= top_card_id &&
+           !CARD_GET_FACE_DOWN (((Card) cards[new_focus_card_id])));
+
+  if (new_focus_card_id < first_card_id ||
+      new_focus_card_id > top_card_id ||
+      CARD_GET_FACE_DOWN (((Card) cards[new_focus_card_id]))) {
+    /* We went one too far */
+    new_focus_card_id -= count;
+  }
 
+  new_focus_card_id = CLAMP (new_focus_card_id, first_card_id, top_card_id);
   set_focus (board, focus_slot, new_focus_card_id, TRUE);
+
   return TRUE;
 }
 
@@ -1916,7 +1946,7 @@
     }
   }
 
-  aisleriot_board_move_cursor_start_end_in_slot (board, count);
+  aisleriot_board_move_cursor_start_end_in_slot (board, count, FALSE);
   return TRUE;
 }
 
@@ -2173,7 +2203,7 @@
       } else if (is_control) {
         rv = aisleriot_board_move_cursor_start_end_by_slot (board, count);
       } else {
-        rv = aisleriot_board_move_cursor_start_end_in_slot (board, count);
+        rv = aisleriot_board_move_cursor_start_end_in_slot (board, count, TRUE);
       }
       break;
     default:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]