[gnome-robots/wip/libgames-support: 27/41] Successfully send category names from keys to libgames-scores.



commit 788e4123c1bd59cce303eda346d5f09539e55e14
Author: Nikhar Agrawal <nikharagrawal2006 gmail com>
Date:   Mon Aug 18 01:20:34 2014 +0530

    Successfully send category names from keys to libgames-scores.

 src/game.c         |    2 +-
 src/gnome-robots.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/src/game.c b/src/game.c
index 6aef7d6..75f046a 100644
--- a/src/game.c
+++ b/src/game.c
@@ -232,7 +232,7 @@ log_score (gint sc)
 
   if (sc != 0) {
   //  games_scores_set_category (highscores, sbuf);
-    current_cat = games_scores_category_new (sbuf, sbuf);
+    current_cat = games_scores_category_new (sbuf, name_from_key (sbuf));
     pos = games_scores_context_add_score (highscores, (guint32) sc, current_cat);
   }
   g_free (sbuf);
diff --git a/src/gnome-robots.c b/src/gnome-robots.c
index 286488b..b2328b3 100644
--- a/src/gnome-robots.c
+++ b/src/gnome-robots.c
@@ -47,6 +47,16 @@
 #define KEY_GEOMETRY_GROUP "geometry"
 
 /**********************************************************************/
+/* Utility structs                                                    */
+/**********************************************************************/
+typedef struct
+{
+    gchar* key;
+    gchar* name;
+} key_value;
+/**********************************************************************/
+
+/**********************************************************************/
 /* Exported Variables                                                 */
 /**********************************************************************/
 GtkWidget *window = NULL;
@@ -91,6 +101,25 @@ static const GActionEntry win_entries[] = {
   { "wait", wait_cb, NULL, NULL, NULL },
 };
 
+static const key_value scorecats[] = {
+       {"classic_robots", N_("Classic robots")},
+       {"classic_robots-safe", N_("Classic robots with safe moves")},
+       {"classic_robots-super-safe", N_("Classic robots with super-safe moves")},
+       {"nightmare", N_("Nightmare")},
+       {"nightmare-safe", N_("Nightmare with safe moves")},
+       {"nightmare-super-safe", N_("Nightmare with super-safe moves")},
+       {"robots2", N_("Robots2")},
+       {"robots2-safe", N_("Robots2 with safe moves")},
+       {"robots2-super-safe", N_("Robots2 with super-safe moves")},
+       {"robots2_easy", N_("Robots2 easy")},
+       {"robots2_easy-safe", N_("Robots2 easy with safe moves")},
+       {"robots2_easy-super-safe", N_("Robots2 easy with super-safe moves")},
+       {"robots_with_safe_teleport", N_("Robots with safe teleport")},
+       {"robots_with_safe_teleport-safe", N_("Robots with safe teleport with safe moves")},
+       {"robots_with_safe_teleport-super-safe", N_("Robots with safe teleport with super-safe moves")}
+};
+static gint no_categories = 15;
+
 static gint safe_teleports = 0;
 static GtkWidget *safe_teleports_label;
 static GtkWidget *headerbar;
@@ -287,9 +316,22 @@ shutdown (GtkApplication *app, gpointer user_data)
   g_settings_set_boolean (settings, "window-is-maximized", window_is_maximized);
 }
 
+gchar* name_from_key (gchar* key)
+{
+  int i;
+  for (i = 0; i < no_categories; i++)
+  {
+    if (g_strcmp0 (scorecats[i].key, key) == 0)
+      return scorecats[i].name;
+  }
+  /*Return key as is if match not found*/
+  return key;
+}
+
 GamesScoresCategory *create_category_from_key (GamesScoresContext *context, const char *key, gpointer 
user_data)
 {
-       return games_scores_category_new (key, key);
+  gchar *name = name_from_key (key);
+  return games_scores_category_new (key, name);
 }
 
 static void


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