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

 Default tilesets simply don't work with custom rulesets. It's quite
demanding for new users to load correct tileset by giving commandline
parameters to client before custom rulesets can be used.
 This patch implements tileset suggestions to game.ruleset. If
game.ruleset contains tileset.suggest -entry, it is sent to client in
packet_ruleset_control. Client then asks from user if tileset should
be changed. Gtk client supports this. Other clients will not even
compile with this patch version.

 Rulesets compatible with typical tilesets (Amplio/Trident/Freeland)
should *not* include tileset suggestion. User has chosen his/her
tileset and that's it. Still, I find confirmation dialog in the client
end necessary. It could be made optional (always accept
suggestion/ask/never accept suggestion), but that's out of this scope
of this patch.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/Makefile.am freeciv/client/gui-gtk-2.0/Makefile.am
--- freeciv/client/gui-gtk-2.0/Makefile.am	2007-03-05 21:11:59.000000000 +0200
+++ freeciv/client/gui-gtk-2.0/Makefile.am	2007-03-12 04:06:48.000000000 +0200
@@ -92,6 +92,6 @@
 	sprite.c	\
 	sprite.h	\
 	themes.c	\
+	tileset_dlg.c	\
 	wldlg.c		\
 	wldlg.h	
-
diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/tileset_dlg.c freeciv/client/gui-gtk-2.0/tileset_dlg.c
--- freeciv/client/gui-gtk-2.0/tileset_dlg.c	1970-01-01 02:00:00.000000000 +0200
+++ freeciv/client/gui-gtk-2.0/tileset_dlg.c	2007-03-12 05:19:36.000000000 +0200
@@ -0,0 +1,78 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+#include "fcintl.h"
+
+#include "game.h"
+#include "unitlist.h"
+
+#include "tilespec.h"
+
+#include "dialogs_g.h"
+
+static void tileset_suggestion_callback(GtkWidget *dlg, gint arg);
+
+/****************************************************************
+  Callback either loading suggested tileset or doing nothing
+*****************************************************************/
+static void tileset_suggestion_callback(GtkWidget *dlg, gint arg)
+{
+  if (arg == GTK_RESPONSE_YES) {
+    /* User accepted tileset loading */
+    tilespec_reread(game.control.suggested_tileset);
+  }
+}
+
+/****************************************************************
+  Popup dialog asking if ruleset suggested tileset should be
+  used.
+*****************************************************************/
+void popup_tileset_suggestion_dialog(void)
+{
+  GtkWidget *dialog, *label;
+  char buf[1024];
+
+  dialog = gtk_dialog_new_with_buttons(_("Tileset suggested"),
+                                       NULL,
+                                       0,
+                                       _("Load tileset"),
+                                       GTK_RESPONSE_YES,
+                                       _("Keep current tileset"),
+                                       GTK_RESPONSE_NO,
+                                       NULL);
+  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
+  gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
+
+  sprintf(buf,
+          _("Rulesets suggest using %s tileset.\n"
+            "You are currently using %s."),
+          game.control.suggested_tileset, tileset_get_name(tileset));
+
+  label = gtk_label_new(buf);
+  gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
+  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
+  gtk_widget_show(label);
+
+  g_signal_connect(dialog, "response",
+                   G_CALLBACK(tileset_suggestion_callback), NULL);
+
+  gtk_dialog_run(GTK_DIALOG(dialog));
+
+  gtk_widget_destroy(dialog);
+}
diff -Nurd -X.diff_ignore freeciv/client/include/dialogs_g.h freeciv/client/include/dialogs_g.h
--- freeciv/client/include/dialogs_g.h	2007-03-05 21:12:04.000000000 +0200
+++ freeciv/client/include/dialogs_g.h	2007-03-12 04:28:22.000000000 +0200
@@ -46,6 +46,7 @@
 void popup_sabotage_dialog(struct city *pcity);
 void popup_pillage_dialog(struct unit *punit, bv_special may_pillage);
 void popup_upgrade_dialog(struct unit_list *punits);
+void popup_tileset_suggestion_dialog(void);
 
 void popdown_all_game_dialogs(void);
 
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-03-12 02:47:07.000000000 +0200
+++ freeciv/client/packhand.c	2007-03-12 05:18:33.000000000 +0200
@@ -2126,6 +2126,14 @@
   governments_alloc(packet->government_count);
   nations_alloc(packet->nation_count);
   city_styles_alloc(packet->styles_count);
+
+  if (packet->suggested_tileset[0] != '\0') {
+    /* There is tileset suggestion */
+    if (strcmp(packet->suggested_tileset, tileset_get_name(tileset))) {
+      /* It's not currently in use */
+      popup_tileset_suggestion_dialog();
+    }
+  }
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/game.c freeciv/common/game.c
--- freeciv/common/game.c	2007-03-08 17:18:27.000000000 +0200
+++ freeciv/common/game.c	2007-03-12 03:27:52.000000000 +0200
@@ -305,6 +305,8 @@
   game.control.nation_count = 0;
   game.control.government_count = 0;
 
+  game.control.suggested_tileset[0] = '\0';
+
   sz_strlcpy(game.demography, GAME_DEFAULT_DEMOGRAPHY);
   sz_strlcpy(game.allow_take, GAME_DEFAULT_ALLOW_TAKE);
 
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-03-12 02:47:07.000000000 +0200
+++ freeciv/common/packets.def	2007-03-12 03:24:20.000000000 +0200
@@ -1303,6 +1303,8 @@
   UINT8 terrain_count;
   UINT8 resource_count;
   UINT8 num_specialist_types;
+
+  STRING suggested_tileset[MAX_LEN_NAME];
 end
 
 /*********************************************************
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-09 16:12:48.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-12 03:40:58.000000000 +0200
@@ -2661,12 +2661,22 @@
   const char *filename;
   int *food_ini;
   int i;
+  char *tileset;
 
   openload_ruleset_file(&file, "game");
   filename = secfile_filename(&file);
   (void) check_ruleset_capabilities(&file, "+1.11.1", filename);
   (void) section_file_lookup(&file, "datafile.description");	/* unused */
 
+  tileset = secfile_lookup_str_default(&file, "", "tileset.suggest");
+  if (tileset[0] != '\0') {
+    /* There was tileset suggestion */
+    sz_strlcpy(game.control.suggested_tileset, tileset);
+  } else {
+    /* No tileset suggestions */
+    game.control.suggested_tileset[0] = '\0';
+  }
+
   game.info.base_pollution = 
         secfile_lookup_int_default(&file, -20, "civstyle.base_pollution");
   game.info.happy_cost =
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to