From 9e4ecd7a90a16550e276cbbf86ff0c7f1842666c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 28 Sep 2023 05:57:10 +0300 Subject: [PATCH 53/53] Save default tileset topo instead of full tileset name to options See osdn #47699 Signed-off-by: Marko Lindqvist --- client/client_main.c | 8 +++++++- client/options.c | 16 ++++++++++++---- client/options.h | 1 + client/tilespec.c | 31 +++++++++++++++++++++++++------ client/tilespec.h | 2 ++ 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 6c5425e82e..1c2a1f8443 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -331,7 +331,13 @@ int default_tileset_select(void) return EXIT_FAILURE; } } else { - tilespec_try_read(gui_options.default_tileset_name, FALSE, -1, TRUE); + if (gui_options.default_tileset_name[0] == '\0') { + /* Use topology by default */ + tilespec_try_read(tileset_name_for_topology(index_ts_topology(gui_options.default_topology)), + FALSE, -1, TRUE); + } else { + tilespec_try_read(gui_options.default_tileset_name, FALSE, -1, TRUE); + } } editor_init(); diff --git a/client/options.c b/client/options.c index d1c0d90fc7..24bff92029 100644 --- a/client/options.c +++ b/client/options.c @@ -82,6 +82,7 @@ struct client_options gui_options = { .default_music_set_name = "stdmusic", .default_sound_plugin_name = "\0", .default_chat_logfile = GUI_DEFAULT_CHAT_LOGFILE, + .default_topology = TS_TOPO_ISOHEX, .followtag_override = DEFAULT_FOLLOWTAG_OPTION, @@ -6197,8 +6198,12 @@ void options_load(void) = secfile_lookup_bool_default(sf, TRUE, "%s.gui_qt_show_wonders_panel", prefix); + /* default_tileset_name present until freeciv-3.2 */ str = secfile_lookup_str_default(sf, NULL, "client.default_tileset_name"); - if (str != NULL) { + if (str == NULL) { + gui_options.default_topology = secfile_lookup_int_default(sf, TS_TOPO_ISOHEX, + "client.default_topology"); + } else { sz_strlcpy(gui_options.default_tileset_name, str); } str = secfile_lookup_str_default(sf, NULL, "client.default_tileset_overhead_name"); @@ -6338,9 +6343,12 @@ void options_save(option_save_log_callback log_cb) secfile_insert_bool(sf, gui_options.gui_qt_show_wonders_panel, "client.gui_qt_show_wonders_panel"); - if (gui_options.default_tileset_name[0] != '\0') { - secfile_insert_str(sf, gui_options.default_tileset_name, - "client.default_tileset_name"); + if (tileset != NULL) { + secfile_insert_int(sf, tileset_topo_index(tileset), + "client.default_topology"); + } else { + secfile_insert_int(sf, gui_options.default_topology, + "client.default_topology"); } message_options_save(sf, "client"); diff --git a/client/options.h b/client/options.h index b06ea59ba5..6f42b2273b 100644 --- a/client/options.h +++ b/client/options.h @@ -120,6 +120,7 @@ struct client_options char default_music_set_name[512]; char default_sound_plugin_name[512]; char default_chat_logfile[512]; + int default_topology; bool save_options_on_exit; diff --git a/client/tilespec.c b/client/tilespec.c index 415ec00f71..12be30baa5 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -1078,6 +1078,24 @@ static int ts_topology_index(int actual_topology) return idx; } +/************************************************************************//** + Convert properties of an index of tileset topology type to one + (but not necessarily the only one) topology. +****************************************************************************/ +int index_ts_topology(int idx) +{ + switch (idx) { + case TS_TOPO_SQUARE: + return TF_ISO; + case TS_TOPO_HEX: + return TF_HEX; + case TS_TOPO_ISOHEX: + return TF_HEX | TF_ISO; + } + + return 0; +} + /************************************************************************//** Returns a static list of tilesets available on the system by searching all data directories for files matching TILESPEC_SUFFIX. @@ -1315,7 +1333,7 @@ bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id, option_set_default_ts(tileset); if (global_default) { - sz_strlcpy(gui_options.default_tileset_name, tileset_basename(tileset)); + gui_options.default_topology = tileset_topo_index(tileset); } return original; @@ -1485,7 +1503,7 @@ bool tilespec_reread(const char *new_tileset_name, } /************************************************************************//** - This is merely a wrapper for tilespec_reread (above) for use in + This is merely a wrapper for tilespec_reread() (above) for use in options.c and the client local options dialog. ****************************************************************************/ void tilespec_reread_callback(struct option *poption) @@ -1506,13 +1524,14 @@ void tilespec_reread_callback(struct option *poption) tileset_name = option_str_get(poption); - /* As it's going to be 'current' tileset, make it global default if - * options saved. */ - sz_strlcpy(gui_options.default_tileset_name, tileset_name); - fc_assert_ret(NULL != tileset_name && tileset_name[0] != '\0'); tileset_update = TRUE; tilespec_reread(tileset_name, client.conn.established, 1.0f); + + /* As it's going to be 'current' tileset, make it global default if + * options saved. */ + gui_options.default_topology = tileset_topo_index(tileset); + tileset_update = FALSE; menus_init(); } diff --git a/client/tilespec.h b/client/tilespec.h index cd15335339..8eae712fe2 100644 --- a/client/tilespec.h +++ b/client/tilespec.h @@ -464,6 +464,8 @@ char *tileset_what_ruleset(struct tileset *t); int tileset_topo_index(struct tileset *t); int tileset_svg_flag_height(struct tileset *t); +int index_ts_topology(int idx); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.40.1