Author: cazfi
Date: Wed Oct 12 02:29:23 2016
New Revision: 34101

URL: http://svn.gna.org/viewcvs/freeciv?rev=34101&view=rev
Log:
Fill initial default for tileset option for all topologies.

See patch #6875

Modified:
    trunk/client/client_main.c
    trunk/client/options.c
    trunk/client/options.h
    trunk/client/tilespec.c
    trunk/client/tilespec.h

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=34101&r1=34100&r2=34101&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Wed Oct 12 02:29:23 2016
@@ -662,10 +662,12 @@
   helpdata_init();
   boot_help_texts();
 
+  fill_topo_ts_default();
+
   if (forced_tileset_name[0] != '\0') {
-    tilespec_try_read(forced_tileset_name, TRUE);
+    tilespec_try_read(forced_tileset_name, TRUE, -1, TRUE);
   } else {
-    tilespec_try_read(gui_options.default_tileset_name, FALSE);
+    tilespec_try_read(gui_options.default_tileset_name, FALSE, -1, TRUE);
   }
 
   audio_real_init(sound_set_name, music_set_name, sound_plugin_name);

Modified: trunk/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.c?rev=34101&r1=34100&r2=34101&view=diff
==============================================================================
--- trunk/client/options.c      (original)
+++ trunk/client/options.c      Wed Oct 12 02:29:23 2016
@@ -6296,3 +6296,49 @@
   opt->str_vtable->set(opt, tileset_basename(t));
   option_gui_update(opt);
 }
+
+/****************************************************************************
+  Does topology-specific tileset option lack value?
+****************************************************************************/
+static bool is_ts_option_unset(const char *optname)
+{
+  struct option *opt;
+  const char *val;
+
+  opt = optset_option_by_name(client_optset, optname);
+
+  if (opt == NULL) {
+    return TRUE;
+  }
+
+  val = opt->str_vtable->get(opt);
+
+  if (val == NULL || val[0] == '\0') {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/****************************************************************************
+  Fill default tilesets for topology-specific settings.
+****************************************************************************/
+void fill_topo_ts_default(void)
+{
+  if (is_ts_option_unset("default_tileset_overhead_name")) {
+    log_debug("Setting tileset for overhead topology.");
+    tilespec_try_read(NULL, FALSE, 0, FALSE);
+  }
+  if (is_ts_option_unset("default_tileset_iso_name")) {
+    log_debug("Setting tileset for iso topology.");
+    tilespec_try_read(NULL, FALSE, TF_ISO, FALSE);
+  }
+  if (is_ts_option_unset("default_tileset_hex_name")) {
+    log_debug("Setting tileset for hex topology.");
+    tilespec_try_read(NULL, FALSE, TF_HEX, FALSE);
+  }
+  if (is_ts_option_unset("default_tileset_isohex_name")) {
+    log_debug("Setting tileset for isohex topology.");
+    tilespec_try_read(NULL, FALSE, TF_ISO | TF_HEX, FALSE);
+  }
+}

Modified: trunk/client/options.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.h?rev=34101&r1=34100&r2=34101&view=diff
==============================================================================
--- trunk/client/options.h      (original)
+++ trunk/client/options.h      Wed Oct 12 02:29:23 2016
@@ -566,6 +566,7 @@
 
 const char *tileset_name_for_topology(int topology_id);
 void option_set_default_ts(struct tileset *t);
+void fill_topo_ts_default(void);
 
 #ifdef __cplusplus
 }

Modified: trunk/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/tilespec.c?rev=34101&r1=34100&r2=34101&view=diff
==============================================================================
--- trunk/client/tilespec.c     (original)
+++ trunk/client/tilespec.c     Wed Oct 12 02:29:23 2016
@@ -980,7 +980,7 @@
     return is_valid_tileset_dir(t, dir);
   } else {
     return (dir == DIR8_NORTH || dir == DIR8_EAST
-           || dir == DIR8_SOUTH || dir == DIR8_WEST);
+            || dir == DIR8_SOUTH || dir == DIR8_WEST);
   }
 }
 
@@ -992,14 +992,15 @@
 {
   int idx;
 
-  if (actual_topology & TF_ISO) {
+  if ((actual_topology & TF_HEX)
+      && (actual_topology & TF_ISO)) {
+    idx = TS_TOPO_ISOHEX;
+  } else if (actual_topology & TF_ISO) {
     idx = TS_TOPO_ISO;
+  } else if (actual_topology & TF_HEX) {
+    idx = TS_TOPO_HEX;
   } else {
-    idx = 0;
-  }
-
-  if (actual_topology & TF_HEX) {
-    idx |= TS_TOPO_HEX;
+    idx = TS_TOPO_OVERHEAD;
   }
 
   return idx;
@@ -1200,18 +1201,22 @@
   Call this function with the (guessed) name of the tileset, when
   starting the client.
 ***********************************************************************/
-void tilespec_try_read(const char *tileset_name, bool verbose)
-{
-  if (!(tileset = tileset_read_toplevel(tileset_name, verbose, -1))) {
+void tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
+                       bool global_default)
+{
+  if (tileset_name == NULL
+      || !(tileset = tileset_read_toplevel(tileset_name, verbose, topo_id))) {
     struct strvec *list = fileinfolist(get_data_dirs(), TILESPEC_SUFFIX);
 
     strvec_iterate(list, file) {
-      struct tileset *t = tileset_read_toplevel(file, FALSE, -1);
+      struct tileset *t = tileset_read_toplevel(file, FALSE, topo_id);
 
       if (t) {
         if (!tileset) {
           tileset = t;
-        } else if (t->priority > tileset->priority) {
+        } else if (t->priority > tileset->priority
+                   || (topo_id >= 0
+                       && tileset_topo_index(tileset) != 
tileset_topo_index(t))) {
           tileset_free(tileset);
           tileset = t;
         } else {
@@ -1228,7 +1233,10 @@
     log_verbose("Trying tileset \"%s\".", tileset->name);
   }
   option_set_default_ts(tileset);
-  sz_strlcpy(gui_options.default_tileset_name, tileset_basename(tileset));
+
+  if (global_default) {
+    sz_strlcpy(gui_options.default_tileset_name, tileset_basename(tileset));
+  }
 }
 
 /**********************************************************************

Modified: trunk/client/tilespec.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/tilespec.h?rev=34101&r1=34100&r2=34101&view=diff
==============================================================================
--- trunk/client/tilespec.h     (original)
+++ trunk/client/tilespec.h     Wed Oct 12 02:29:23 2016
@@ -220,7 +220,8 @@
 
 void finish_loading_sprites(struct tileset *t);
 
-void tilespec_try_read(const char *tileset_name, bool verbose);
+void tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
+                       bool global_default);
 void tilespec_reread(const char *tileset_name, bool game_fully_initialized);
 void tilespec_reread_callback(struct option *poption);
 void tilespec_reread_frozen_refresh(const char *tname);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to