gnome-games r8367 - in trunk: gtali libgames-support



Author: jclinton
Date: Mon Dec 15 04:03:30 2008
New Revision: 8367
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8367&view=rev

Log:
Make the High score table allow the user to change name to someone other
than their username. (Bug #552963, Geoff Buchan)

Modified:
   trunk/gtali/gyahtzee.c
   trunk/libgames-support/games-scores-dialog.c
   trunk/libgames-support/games-scores.c
   trunk/libgames-support/games-scores.h

Modified: trunk/gtali/gyahtzee.c
==============================================================================
--- trunk/gtali/gyahtzee.c	(original)
+++ trunk/gtali/gyahtzee.c	Mon Dec 15 04:03:30 2008
@@ -199,6 +199,7 @@
     pos = games_scores_add_score (highscores, score);
 
     if (pos > 0) {
+      games_scores_update_score (highscores, players[winner].name);
       if (dialog) {
         gtk_window_present (GTK_WINDOW (dialog));
       } else {
@@ -600,6 +601,9 @@
     "",
     N_("Console version (1992):"),
     "Orest Zborowski",
+    "",
+    N_("Colors game and multi-level AI (2006):"),
+    "Geoff Buchan",
     NULL
   };
 

Modified: trunk/libgames-support/games-scores-dialog.c
==============================================================================
--- trunk/libgames-support/games-scores-dialog.c	(original)
+++ trunk/libgames-support/games-scores-dialog.c	Mon Dec 15 04:03:30 2008
@@ -182,12 +182,18 @@
 					     GamesScoresDialog *self)
 {
   GtkTreeIter iter;
+  gchar *old_name = NULL;
 
   gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (self->_priv->list), 
 				       &iter, path);
+
+  /* Get old name for comparison */
+  gtk_tree_model_get (GTK_TREE_MODEL (self->_priv->list),
+                      &iter, 0, &old_name, -1);
+                           
   gtk_list_store_set (self->_priv->list, &iter, 0, new_text, -1);
 
-  games_scores_update_score (self->_priv->scores, new_text);
+  games_scores_update_score_name (self->_priv->scores, new_text, old_name);
 }
 
 /* Prevent editing of any cell in the high score list but the one we set. */

Modified: trunk/libgames-support/games-scores.c
==============================================================================
--- trunk/libgames-support/games-scores.c	(original)
+++ trunk/libgames-support/games-scores.c	Mon Dec 15 04:03:30 2008
@@ -289,7 +289,7 @@
 }
 
 /**
- * games_scores_update_score:
+ * games_scores_update_score_name:
  * @self: A scores object.
  * @new_name: The new name to use.
  *
@@ -300,12 +300,11 @@
  *
  **/
 void
-games_scores_update_score (GamesScores * self, gchar * new_name)
+games_scores_update_score_name (GamesScores * self, gchar * new_name, gchar * old_name)
 {
   GamesScoresCategoryPrivate *cat;
   GList *s, *scores_list;
   gint n, place;
-  gchar *old_name;
   GamesScore *sc;
   GamesScoreValue score;
 
@@ -318,7 +317,10 @@
   if (place == 0)
     return;
 
-  old_name = g_strdup (g_get_real_name ());
+  if (old_name)
+      old_name = g_strdup (old_name); /* Make copy so we can free it later */
+  else
+      old_name = g_strdup (g_get_real_name ());
 
   cat = games_scores_get_current (self);
 
@@ -351,6 +353,23 @@
 }
 
 /**
+ * games_scores_update_score:
+ * @self: A scores object.
+ * @new_name: The new name to use.
+ *
+ * By default add_score uses the current user name. This routine updates
+ * that name. There are a few wrinkles: the score may have moved since we
+ * got the original score. Use in normal code is discouraged, it is here 
+ * to be used by GamesScoresDialog.
+ *
+ **/
+void
+games_scores_update_score (GamesScores * self, gchar * new_name)
+{
+    games_scores_update_score_name (self, new_name, NULL);
+}
+
+/**
  * get:
  * @self: A scores object.
  *

Modified: trunk/libgames-support/games-scores.h
==============================================================================
--- trunk/libgames-support/games-scores.h	(original)
+++ trunk/libgames-support/games-scores.h	Mon Dec 15 04:03:30 2008
@@ -72,6 +72,7 @@
 void games_scores_set_category (GamesScores * self, gchar * category);
 gint games_scores_add_score (GamesScores * self, GamesScoreValue score);
 void games_scores_update_score (GamesScores * self, gchar * new_name);
+void games_scores_update_score_name (GamesScores * self, gchar * new_name, gchar * old_name);
 GList *games_scores_get (GamesScores * self);
 void games_scores_category_foreach (GamesScores * self,
 				    GamesScoresCategoryForeachFunc func,



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