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

On 3/14/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
> On 3/12/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> >
> >  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.
>
>  - Ruleset entry is now tileset.prefered. I didn't want to repeat word
> 'tileset' as in tileset.prefered_tileset.
>  - Internal namespace changes 'suggested' -> 'prefered'
>  - Word 'Ruleset' -> 'Modpack' in popup message. It may be less
> accurate, but I believe end user is more likely to understand latter.
>  - Added warning that it might be impossible to use modpack without
> suggested tileset
>  - Added stub functions for other clients, so they at least compile

 - Updated against svn


 - 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-18 18:36:20.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-18 18:36:20.000000000 +0200
@@ -0,0 +1,82 @@
+/********************************************************************** 
+ 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.prefered_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(_("Prefered tileset"),
+                                       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,
+          _("Modpack suggest using %s tileset.\n"
+            "It might not work with other tilesets.\n"
+            "You are currently using tileset %s."),
+          game.control.prefered_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);
+
+  /* In case incoming rulesets are incompatible with current tileset
+   * we need to block their receive before user has accepted loading
+   * of the correct tileset. */
+  gtk_dialog_run(GTK_DIALOG(dialog));
+
+  gtk_widget_destroy(dialog);
+}
diff -Nurd -X.diff_ignore freeciv/client/gui-sdl/dialogs.c freeciv/client/gui-sdl/dialogs.c
--- freeciv/client/gui-sdl/dialogs.c	2007-03-08 18:42:40.000000000 +0200
+++ freeciv/client/gui-sdl/dialogs.c	2007-03-18 18:36:20.000000000 +0200
@@ -3074,3 +3074,11 @@
   redraw_group(pNationDlg->pBeginWidgetList, pNationDlg->pEndWidgetList, 0);
   widget_flush(pNationDlg->pEndWidgetList);
 }
+
+/**************************************************************************
+  Ruleset (modpack) has suggested loading certain tileset. Confirm from
+  user and load.
+**************************************************************************/
+void popup_tileset_suggestion_dialog(void)
+{
+}
diff -Nurd -X.diff_ignore freeciv/client/gui-stub/dialogs.c freeciv/client/gui-stub/dialogs.c
--- freeciv/client/gui-stub/dialogs.c	2007-03-05 21:12:21.000000000 +0200
+++ freeciv/client/gui-stub/dialogs.c	2007-03-18 18:36:20.000000000 +0200
@@ -151,6 +151,15 @@
 }
 
 /**************************************************************************
+  Ruleset (modpack) has suggested loading certain tileset. Confirm from
+  user and load.
+**************************************************************************/
+void popup_tileset_suggestion_dialog(void)
+{
+  /* PORTME */
+}
+
+/**************************************************************************
   This function is called when the client disconnects or the game is
   over.  It should close all dialog windows for that game.
 **************************************************************************/
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/dialogs.c freeciv/client/gui-win32/dialogs.c
--- freeciv/client/gui-win32/dialogs.c	2007-03-05 21:12:09.000000000 +0200
+++ freeciv/client/gui-win32/dialogs.c	2007-03-18 18:36:20.000000000 +0200
@@ -1905,3 +1905,11 @@
   return (0);  
   
 }
+
+/**************************************************************************
+  Ruleset (modpack) has suggested loading certain tileset. Confirm from
+  user and load.
+**************************************************************************/
+void popup_tileset_suggestion_dialog(void)
+{
+}
diff -Nurd -X.diff_ignore freeciv/client/gui-xaw/dialogs.c freeciv/client/gui-xaw/dialogs.c
--- freeciv/client/gui-xaw/dialogs.c	2007-03-05 21:12:03.000000000 +0200
+++ freeciv/client/gui-xaw/dialogs.c	2007-03-18 18:36:20.000000000 +0200
@@ -1547,6 +1547,14 @@
   common_taxrates_callback((size_t) client_data);
 }
 
+/**************************************************************************
+  Ruleset (modpack) has suggested loading certain tileset. Confirm from
+  user and load.
+**************************************************************************/
+void popup_tileset_suggestion_dialog(void)
+{
+}
+
 /********************************************************************** 
   This function is called when the client disconnects or the game is
   over.  It should close all dialog windows for that game.
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-18 18:36:20.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-18 16:59:16.000000000 +0200
+++ freeciv/client/packhand.c	2007-03-18 18:37:06.000000000 +0200
@@ -2143,6 +2143,14 @@
   for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
     game.players[i].nation = NULL;
   }
+
+  if (packet->prefered_tileset[0] != '\0') {
+    /* There is tileset suggestion */
+    if (strcmp(packet->prefered_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-18 18:36:20.000000000 +0200
@@ -305,6 +305,8 @@
   game.control.nation_count = 0;
   game.control.government_count = 0;
 
+  game.control.prefered_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-18 16:59:16.000000000 +0200
+++ freeciv/common/packets.def	2007-03-18 18:36:20.000000000 +0200
@@ -1314,6 +1314,8 @@
   UINT8 terrain_count;
   UINT8 resource_count;
   UINT8 num_specialist_types;
+
+  STRING prefered_tileset[MAX_LEN_NAME];
 end
 
 /*********************************************************
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-18 16:59:16.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-18 18:36:20.000000000 +0200
@@ -2692,12 +2692,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.prefered");
+  if (tileset[0] != '\0') {
+    /* There was tileset suggestion */
+    sz_strlcpy(game.control.prefered_tileset, tileset);
+  } else {
+    /* No tileset suggestions */
+    game.control.prefered_tileset[0] = '\0';
+  }
+
   game.info.base_pollution = 
         secfile_lookup_int_default(&file, -20, "civstyle.base_pollution");
   game.info.happy_cost =
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2007-03-18 16:59:16.000000000 +0200
+++ freeciv/version.in	2007-03-18 18:37:16.000000000 +0200
@@ -24,4 +24,4 @@
 #   - Avoid adding a new manditory capbility to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-FREECIV_NETWORK_CAPSTRING(["+Freeciv.Devel.2007.Mar.18"])
+FREECIV_NETWORK_CAPSTRING(["+Freeciv.Devel.2007.Mar.18-2"])
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to