Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] Re: (PR#14263) loading data about saved games
Home

[Freeciv-Dev] Re: (PR#14263) loading data about saved games

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#14263) loading data about saved games
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 11 Oct 2005 18:48:03 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14263 >

Mateusz Stefek wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=14263 >
> 
>>[jdorje - Mon Oct 10 22:50:39 2005]:
>>
>>Currently saved games just show the name of the file.  Not very helpful. 
>>  We can use a similar mechanism to what we use for scenarios to load 
>>descriptive data about the savegame.
>>
>>This patch does that.
> 
> Why don't you create new columns for that additional information?
> The way it is done now looks unesteathic.

Surely.  This patch improves that a bit.  But it'll take more work than 
this.  Someone who understands the GUI code (vasco...) should fix it.

> BTW, it would be nice if there was a file size column and a button which
> would allow to delete a savegame.

Yes.  And in the save-game dialog there is (a delete button anyway).

-jason

Index: utility/registry.c
===================================================================
--- utility/registry.c  (revision 11104)
+++ utility/registry.c  (working copy)
@@ -648,7 +648,7 @@
   inf = inf_from_file(real_filename, datafilename);
 
   return section_file_read_dup(my_section_file, real_filename,
-                              inf, TRUE, NULL);
+                              inf, TRUE, part);
 }
 
 /**************************************************************************
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 11104)
+++ server/savegame.c   (working copy)
@@ -3722,6 +3722,28 @@
   } players_iterate_end;
 }
 
+static void insert_save_description(struct section_file *file,
+                                   const char *save_reason)
+{
+  const char *player = "-", *nation = "-", *savetime = "-";
+
+  if (game.info.nplayers > 0) {
+    player = game.players[0].name;
+  }
+  if (game.info.nplayers > 0 && game.players[0].nation) {
+    nation = game.players[0].nation->name_orig;
+  }
+  if (1) {
+    /* ??? Set savetime.  It should be local time. */
+  }
+
+  secfile_insert_int(file, game.info.year, "savedesc.year");
+  secfile_insert_str(file, player, "savedesc.player");
+  secfile_insert_str(file, nation, "savedesc.nation");
+  secfile_insert_str(file, savetime, "savedesc.savetime");
+  secfile_insert_str(file, save_reason, "savedesc.reason");
+}
+
 /***************************************************************
 ...
 ***************************************************************/
@@ -3732,6 +3754,8 @@
   char options[512];
   char temp[B_LAST+1];
 
+  insert_save_description(file, save_reason);
+
   version = MAJOR_VERSION *10000 + MINOR_VERSION *100 + PATCH_VERSION; 
   secfile_insert_int(file, version, "game.version");
 
Index: client/gui-gtk-2.0/pages.c
===================================================================
--- client/gui-gtk-2.0/pages.c  (revision 11104)
+++ client/gui-gtk-2.0/pages.c  (working copy)
@@ -1359,22 +1359,60 @@
 }
 
 /**************************************************************************
-  update the saved games list store.
+  Append saves from the prefix directory to the store.
 **************************************************************************/
-static void update_saves_store(GtkListStore *store)
+static void append_saves_store(const char *prefix, GtkListStore *store)
 {
   struct datafile_list *files;
+  bool failed = FALSE;
 
-  gtk_list_store_clear(store);
-
-  /* search for user saved games. */
-  files = datafilelist_infix("saves", ".sav", FALSE);
+  files = datafilelist_infix(prefix, ".sav", FALSE);
   datafile_list_iterate(files, pfile) {
     GtkTreeIter it;
+    struct section_file sf;
+    char desc_full[4096], *desc = _("unknown");
+    char *name = pfile->name, *reason = "?";
 
+    if (!failed
+       && section_file_load_section(&sf, pfile->fullname, "savedesc")) {
+      if (section_file_lookup(&sf, "savedesc.year")) {
+       int year = secfile_lookup_int_default(&sf, 0, "savedesc.year");
+       char *player
+         = secfile_lookup_str_default(&sf, "unknown", "savedesc.player");
+       char *nation
+         = secfile_lookup_str_default(&sf, "unknown", "savedesc.nation");
+#if 0
+       char *savetime
+         = secfile_lookup_str_default(&sf, "unknown", "savedesc.savetime");
+#endif
+       char *myreason
+         = secfile_lookup_str_default(&sf, "unknown", "savedesc.reason");
+
+       if (mystrcasecmp(myreason, "Autosave") == 0) {
+         reason = _(" autosave");
+       } else if (mystrcasecmp(myreason, "Game over") == 0) {
+         reason = _(" end of game");
+       } else if (mystrcasecmp(myreason, "User request") == 0) {
+         reason = _(" manual");
+       } else {
+         reason = _(" unknown");
+       }
+
+       my_snprintf(desc_full, sizeof(desc_full), _("Year %d - %s of the %s"),
+                   year, player, nation);
+       desc = desc_full;
+      } else {
+       failed = TRUE;
+      }
+      section_file_free(&sf);
+    }
+
     gtk_list_store_append(store, &it);
     gtk_list_store_set(store, &it,
-       0, pfile->name, 1, pfile->fullname, -1);
+                      0, name,
+                      1, pfile->fullname,
+                      2, desc,
+                      3, reason, -1);
 
     free(pfile->name);
     free(pfile->fullname);
@@ -1383,22 +1421,22 @@
 
   datafile_list_unlink_all(files);
   datafile_list_free(files);
+}
 
-  files = datafilelist_infix(NULL, ".sav", FALSE);
-  datafile_list_iterate(files, pfile) {
-    GtkTreeIter it;
+/**************************************************************************
+  update the saved games list store.
+**************************************************************************/
+static void update_saves_store(GtkListStore *store)
+{
+  struct timer *t = new_timer_start(TIMER_USER, TIMER_ACTIVE);
 
-    gtk_list_store_append(store, &it);
-    gtk_list_store_set(store, &it,
-       0, pfile->name, 1, pfile->fullname, -1);
+  gtk_list_store_clear(store);
 
-    free(pfile->name);
-    free(pfile->fullname);
-    free(pfile);
-  } datafile_list_iterate_end;
+  /* search for user saved games. */
+  append_saves_store("saves", store);
+  append_saves_store(NULL, store);
 
-  datafile_list_unlink_all(files);
-  datafile_list_free(files);
+  freelog(LOG_NORMAL, "Time taken: %f", read_timer_seconds_free(t));
 }
 
 /**************************************************************************
@@ -1425,7 +1463,8 @@
   align = gtk_alignment_new(0.5, 0.5, 0.0, 1.0);
   gtk_box_pack_start(GTK_BOX(box), align, TRUE, TRUE, 0);
 
-  load_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+  load_store = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING,
+                                 G_TYPE_STRING, G_TYPE_STRING);
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(load_store));
   g_object_unref(load_store);
 
@@ -1433,6 +1472,14 @@
   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
       -1, NULL, rend, "text", 0, NULL);
 
+  rend = gtk_cell_renderer_text_new();
+  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+      -1, NULL, rend, "text", 2, NULL);
+
+  rend = gtk_cell_renderer_text_new();
+  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+      -1, NULL, rend, "text", 3, NULL);
+
   load_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
   gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
 
@@ -2083,7 +2130,8 @@
   save_dialog_shell = shell;
   setup_dialog(shell, toplevel);
 
-  save_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+  save_store = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING,
+                                 G_TYPE_STRING, G_TYPE_STRING);
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(save_store));
   g_object_unref(save_store);
 
@@ -2091,6 +2139,14 @@
   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
       -1, NULL, rend, "text", 0, NULL);
 
+  rend = gtk_cell_renderer_text_new();
+  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+      -1, NULL, rend, "text", 2, NULL);
+
+  rend = gtk_cell_renderer_text_new();
+  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+      -1, NULL, rend, "text", 3, NULL);
+
   selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
   save_selection = selection;
   gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#14263) loading data about saved games, Jason Short <=