Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#13865) Prefered theme for tileset
Home

[Freeciv-Dev] (PR#13865) Prefered theme for tileset

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13865) Prefered theme for tileset
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Tue, 11 Oct 2005 03:00:45 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [mstefek - Mon Sep 05 17:15:20 2005]:
> 
> The attached patch allows tileset to specify prefered themes in
> *.tilespec file. Like in this line:
> 
> prefered_themes = "Industrial", "EasyListening", "Redmond"
> 
> The first existing theme will be used.
> 
> Before commiting it I have to create option to disable theme changing
> for users who prefer system defaults. 
> How do you add an option which will be only used by the gtk2 client?
I was blind. This is very easy.
--
mateusz
Index: client/themes_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/themes_common.c,v
retrieving revision 1.1
diff -u -r1.1 themes_common.c
--- client/themes_common.c      3 Sep 2005 09:56:20 -0000       1.1
+++ client/themes_common.c      5 Sep 2005 12:35:38 -0000
@@ -175,16 +175,18 @@
 
 /****************************************************************************
   Loads a theme with the given name. First matching directory will be used.
+  If there's no such theme the function returns FALSE.
 ****************************************************************************/
-void load_theme(const char *theme_name)
+bool load_theme(const char *theme_name)
 {
   int i, j;
   for (i = 0; i < num_directories; i++) {
     for (j = 0; j < directories[i].num_themes; j++) {
       if (strcmp(theme_name, directories[i].themes[j]) == 0) {
        gui_load_theme(directories[i].path, directories[i].themes[j]);
-       return;
+       return TRUE;
       }
     }
   }
+  return FALSE;
 }
Index: client/themes_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/themes_common.h,v
retrieving revision 1.1
diff -u -r1.1 themes_common.h
--- client/themes_common.h      3 Sep 2005 09:56:20 -0000       1.1
+++ client/themes_common.h      5 Sep 2005 12:35:38 -0000
@@ -16,5 +16,5 @@
 
 void init_themes(void);
 const char** get_themes_list(void);
-void load_theme(const char* theme_name);
+bool load_theme(const char* theme_name);
 #endif
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.322
diff -u -r1.322 tilespec.c
--- client/tilespec.c   25 Aug 2005 18:57:22 -0000      1.322
+++ client/tilespec.c   5 Sep 2005 12:35:51 -0000
@@ -46,12 +46,14 @@
 #include "graphics_g.h"
 #include "gui_main_g.h"
 #include "mapview_g.h"         /* for update_map_canvas_visible */
+#include "themes_g.h"
 
 #include "civclient.h"         /* for get_client_state() */
 #include "climap.h"            /* for client_tile_get_known() */
 #include "control.h"           /* for fill_xxx */
 #include "goto.h"
 #include "options.h"           /* for fill_xxx */
+#include "themes_common.h"
 
 #include "tilespec.h"
 
@@ -383,6 +385,9 @@
   struct named_sprites sprites;
 
   struct color_system *color_system;
+  
+  int num_prefered_themes;
+  char** prefered_themes;
 };
 
 struct tileset *tileset;
@@ -756,6 +761,16 @@
     free(t->minimap_intro_filename);
     t->minimap_intro_filename = NULL;
   }
+  
+  if (t->prefered_themes) {
+    int i;
+    for (i = 0; i < t->num_prefered_themes; i++) {
+      free(t->prefered_themes[i]);
+    }
+    free(t->prefered_themes);
+    t->prefered_themes = NULL;
+  }
+  t->num_prefered_themes = 0;
 
   while (hash_num_entries(t->terrain_hash) > 0) {
     const struct terrain_drawing_data *draw;
@@ -858,6 +873,7 @@
   }
   sz_strlcpy(default_tileset_name, tileset->name);
   tileset_load_tiles(tileset);
+  tileset_use_prefered_theme(tileset);
 
   /* Step 3: Setup
    *
@@ -1530,6 +1546,12 @@
 
   section_file_check_unused(file, fname);
   
+  t->prefered_themes = secfile_lookup_str_vec(file, &(t->num_prefered_themes),
+                                              "tilespec.prefered_themes");
+  for (i = 0; i < t->num_prefered_themes; i++) {
+    t->prefered_themes[i] = mystrdup(t->prefered_themes[i]);
+  }
+  
   section_file_free(file);
   freelog(LOG_VERBOSE, "finished reading %s", fname);
   free(fname);
@@ -4577,3 +4599,21 @@
 {
   return t->color_system;
 }
+
+/****************************************************************************
+  Loads prefered theme if there's any.
+****************************************************************************/
+void tileset_use_prefered_theme(const struct tileset *t)
+{
+  int i;
+  for (i = 0; i < t->num_prefered_themes; i++) {
+    freelog(LOG_DEBUG, "trying theme %s", t->prefered_themes[i]);
+    if (load_theme(t->prefered_themes[i])) {
+      return;
+    }
+  }
+  freelog(LOG_VERBOSE, "The tileset doesn't specify prefered themes or "
+                       "none of prefered themes can be used. Using system "
+                      "default");
+  gui_clear_theme();
+}
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.159
diff -u -r1.159 tilespec.h
--- client/tilespec.h   25 Aug 2005 18:57:22 -0000      1.159
+++ client/tilespec.h   5 Sep 2005 12:35:51 -0000
@@ -240,5 +240,6 @@
 const char *tileset_main_intro_filename(const struct tileset *t);
 const char *tileset_mini_intro_filename(const struct tileset *t);
 int tileset_num_city_colors(const struct tileset *t);
+void tileset_use_prefered_theme(const struct tileset *t);
 
 #endif  /* FC__TILESPEC_H */
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.137
diff -u -r1.137 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       29 Aug 2005 13:56:49 -0000      1.137
+++ client/gui-gtk-2.0/gui_main.c       5 Sep 2005 12:35:53 -0000
@@ -1207,6 +1207,8 @@
   init_mapcanvas_and_overview();
 
   set_client_state(CLIENT_PRE_GAME_STATE);
+  
+  tileset_use_prefered_theme(tileset);
 
   gtk_main();
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13865) Prefered theme for tileset, Mateusz Stefek <=