Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2005:
[Freeciv-Dev] (PR#13661) caravan popups are inaccurate
Home

[Freeciv-Dev] (PR#13661) caravan popups are inaccurate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: chrisk@xxxxxxxxx, jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#13661) caravan popups are inaccurate
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Tue, 1 Nov 2005 01:14:28 -0800
Reply-to: bugs@xxxxxxxxxxx

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

> [jdorje - Tue Nov 01 08:58:09 2005]:
> 
> Mateusz Stefek wrote:
> > <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13661 >
> > 
> > Here's a patch.
> > - message_dialog is renamed choice_dialog. Because it was easily
> > confused with gtk_message_dialog and freeciv messages dialog.
> > 
> > - caravan_dialog and choice_dialog are moved to separate files.
> 
> Why?  Just so update_caravan_dialog can be called?

I forgot to say that I had also cleaned some things around.
I remember you once said that splitting dialogs.c is a good idea.

> > - new function update_caravan_dialog is added
> 
> Does this get called if there's an update from some other source (like 
> changing production to a less expensive wonder while the dialog is open)?

Good point. Updated patch attached.

--
mateusz
Index: client/control.c
===================================================================
--- client/control.c    (wersja 11206)
+++ client/control.c    (kopia robocza)
@@ -579,7 +579,7 @@
   }
 
   /* There can only be one dialog at a time: */
-  if (caravan_dialog_is_open()) {
+  if (caravan_dialog_is_open(NULL, NULL)) {
     return;
   }
   
Index: client/gui-gtk-2.0/caravan_dialog.c
===================================================================
--- client/gui-gtk-2.0/caravan_dialog.c (wersja 0)
+++ client/gui-gtk-2.0/caravan_dialog.c (wersja 0)
@@ -0,0 +1,159 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
+   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 "support.h"
+
+#include "game.h"
+#include "unit.h"
+
+#include "dialogs_g.h"
+#include "chatline.h"
+#include "choice_dialog.h"
+#include "civclient.h"
+#include "climisc.h"
+#include "clinet.h"
+#include "control.h"
+#include "gui_main.h"
+#include "gui_stuff.h"
+
+#include "dialogs.h"
+#include "wldlg.h"
+
+static int caravan_city_id;
+static int caravan_unit_id;
+
+static GtkWidget *caravan_dialog;
+
+/****************************************************************
+...
+*****************************************************************/
+static void caravan_establish_trade_callback(GtkWidget *w, gpointer data)
+{
+  dsend_packet_unit_establish_trade(&aconnection, caravan_unit_id);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void caravan_help_build_wonder_callback(GtkWidget *w, gpointer data)
+{
+  dsend_packet_unit_help_build_wonder(&aconnection, caravan_unit_id);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void caravan_destroy_callback(GtkWidget *w, gpointer data)
+{
+  caravan_dialog = NULL;
+  process_caravan_arrival(NULL);
+}
+
+/****************************************************************
+  Fills the buf with proper text which should be displayed on 
+  the helpbuild wonder button.
+*****************************************************************/
+static void get_help_build_wonder_button_label(char* buf, int bufsize,
+                                               bool* help_build_possible)
+{
+  struct city* destcity = find_city_by_id(caravan_city_id);
+  struct unit* caravan = find_unit_by_id(caravan_unit_id);
+  
+  if (destcity && caravan
+      && unit_can_help_build_wonder(caravan, destcity)) {
+    my_snprintf(buf, bufsize, _("Help build _Wonder (%d remaining)"),
+       impr_build_shield_cost(destcity->production.value)
+       - destcity->shield_stock);
+    *help_build_possible = TRUE;
+  } else {
+    my_snprintf(buf, bufsize, _("Help build _Wonder"));
+    *help_build_possible = FALSE;
+  }
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void popup_caravan_dialog(struct unit *punit,
+                         struct city *phomecity, struct city *pdestcity)
+{
+  char buf[128], wonder[128];
+  bool can_establish, can_trade, can_wonder;
+  
+  my_snprintf(buf, sizeof(buf),
+             _("Your caravan from %s reaches the city of %s.\nWhat now?"),
+             phomecity->name, pdestcity->name);
+  
+  caravan_city_id=pdestcity->id; /* callbacks need these */
+  caravan_unit_id=punit->id;
+  
+  get_help_build_wonder_button_label(wonder, sizeof(wonder), &can_wonder);
+  
+  can_trade = can_cities_trade(phomecity, pdestcity);
+  can_establish = can_trade
+                 && can_establish_trade_route(phomecity, pdestcity);
+
+
+  caravan_dialog = popup_choice_dialog(GTK_WINDOW(toplevel),
+    _("Your Caravan Has Arrived"), 
+    buf,
+    (can_establish ? _("Establish _Traderoute") :
+    _("Enter Marketplace")),caravan_establish_trade_callback, NULL,
+    wonder,caravan_help_build_wonder_callback, NULL,
+    _("_Keep moving"), NULL, NULL,
+    NULL);
+
+  g_signal_connect(caravan_dialog, "destroy",
+                  G_CALLBACK(caravan_destroy_callback), NULL);
+  
+  if (!can_trade) {
+    choice_dialog_button_set_sensitive(caravan_dialog, 0, FALSE);
+  }
+  
+  if (!can_wonder) {
+    choice_dialog_button_set_sensitive(caravan_dialog, 1, FALSE);
+  }
+}
+
+/****************************************************************
+  Returns whether the caravan dialog is open, and sets 
+  caravan id and destination city id, if they are not NULL.
+*****************************************************************/
+bool caravan_dialog_is_open(int* unit_id, int* city_id)
+{
+  if (unit_id) {
+    *unit_id = caravan_unit_id;
+  }
+  if (city_id) {
+    *city_id = caravan_city_id;
+  }
+  return caravan_dialog != NULL;
+}
+
+/****************************************************************
+  Updates caravan dialog
+****************************************************************/
+void caravan_dialog_update(void)
+{
+  char buf[128];
+  bool can_help;
+  get_help_build_wonder_button_label(buf, sizeof(buf), &can_help);
+  choice_dialog_button_set_label(caravan_dialog, 1, buf);
+  choice_dialog_button_set_sensitive(caravan_dialog, 1, can_help);
+}
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c        (wersja 11206)
+++ client/gui-gtk-2.0/dialogs.c        (kopia robocza)
@@ -36,6 +36,7 @@
 #include "support.h"
 
 #include "chatline.h"
+#include "choice_dialog.h"
 #include "citydlg.h"
 #include "civclient.h"
 #include "climisc.h"
@@ -55,13 +56,6 @@
 #include "wldlg.h"
 
 /******************************************************************/
-GtkWidget *message_dialog_start(GtkWindow *parent, const gchar *name,
-                               const gchar *text);
-void message_dialog_add(GtkWidget *dshell, const gchar *label,
-                       GCallback handler, gpointer data);
-void message_dialog_end(GtkWidget *dshell);
-
-/******************************************************************/
 static GtkWidget  *races_shell;
 struct player *races_player;
 static GtkWidget  *races_nation_list[MAX_NUM_NATION_GROUPS + 1];
@@ -99,11 +93,6 @@
 static int is_showing_pillage_dialog = FALSE;
 static int unit_to_use_to_pillage;
 
-static int caravan_city_id;
-static int caravan_unit_id;
-
-static GtkWidget *caravan_dialog;
-
 /**************************************************************************
   Popup a generic dialog to display some generic information.
 **************************************************************************/
@@ -233,94 +222,6 @@
 /****************************************************************
 ...
 *****************************************************************/
-static void caravan_establish_trade_callback(GtkWidget *w, gpointer data)
-{
-  dsend_packet_unit_establish_trade(&aconnection, caravan_unit_id);
-}
-
-
-/****************************************************************
-...
-*****************************************************************/
-static void caravan_help_build_wonder_callback(GtkWidget *w, gpointer data)
-{
-  dsend_packet_unit_help_build_wonder(&aconnection, caravan_unit_id);
-}
-
-
-/****************************************************************
-...
-*****************************************************************/
-static void caravan_destroy_callback(GtkWidget *w, gpointer data)
-{
-  caravan_dialog = NULL;
-  process_caravan_arrival(NULL);
-}
-
-
-
-/****************************************************************
-...
-*****************************************************************/
-void popup_caravan_dialog(struct unit *punit,
-                         struct city *phomecity, struct city *pdestcity)
-{
-  char buf[128], wonder[128];
-  bool can_establish, can_trade, can_wonder;
-  
-  my_snprintf(buf, sizeof(buf),
-             _("Your caravan from %s reaches the city of %s.\nWhat now?"),
-             phomecity->name, pdestcity->name);
-  
-  caravan_city_id=pdestcity->id; /* callbacks need these */
-  caravan_unit_id=punit->id;
-  
-  can_trade = can_cities_trade(phomecity, pdestcity);
-  can_establish = can_trade
-                 && can_establish_trade_route(phomecity, pdestcity);
-
-  if (unit_can_help_build_wonder(punit, pdestcity)) {
-    my_snprintf(wonder, sizeof(wonder), _("Help build _Wonder (%d remaining)"),
-       impr_build_shield_cost(pdestcity->production.value)
-       - pdestcity->shield_stock);
-    can_wonder = TRUE;
-  } else {
-    my_snprintf(wonder, sizeof(wonder), _("Help build _Wonder"));
-    can_wonder = FALSE;
-  }
-
-  caravan_dialog = popup_message_dialog(GTK_WINDOW(toplevel),
-    _("Your Caravan Has Arrived"), 
-    buf,
-    (can_establish ? _("Establish _Traderoute") :
-    _("Enter Marketplace")),caravan_establish_trade_callback, NULL,
-    wonder,caravan_help_build_wonder_callback, NULL,
-    _("_Keep moving"), NULL, NULL,
-    NULL);
-
-  g_signal_connect(caravan_dialog, "destroy",
-                  G_CALLBACK(caravan_destroy_callback), NULL);
-  
-  if (!can_trade) {
-    message_dialog_button_set_sensitive(caravan_dialog, 0, FALSE);
-  }
-  
-  if (!can_wonder) {
-    message_dialog_button_set_sensitive(caravan_dialog, 1, FALSE);
-  }
-}
-
-/****************************************************************
-...
-*****************************************************************/
-bool caravan_dialog_is_open(void)
-{
-  return caravan_dialog != NULL;
-}
-
-/****************************************************************
-...
-*****************************************************************/
 static void revolution_response(GtkWidget *w, gint response, gpointer data)
 {
   struct government *government = data;
@@ -403,7 +304,7 @@
     is_showing_pillage_dialog = TRUE;
     unit_to_use_to_pillage = punit->id;
 
-    shl = message_dialog_start(GTK_WINDOW(toplevel),
+    shl = choice_dialog_start(GTK_WINDOW(toplevel),
                               _("What To Pillage"),
                               _("Select what to pillage:"));
 
@@ -412,8 +313,8 @@
 
       BV_CLR_ALL(what_bv);
       BV_SET(what_bv, what);
-      message_dialog_add(shl, get_infrastructure_text(what_bv),
-                        G_CALLBACK(pillage_callback), GINT_TO_POINTER(what));
+      choice_dialog_add(shl, get_infrastructure_text(what_bv),
+                       G_CALLBACK(pillage_callback), GINT_TO_POINTER(what));
 
       clear_special(&may_pillage, what);
       prereq = get_infrastructure_prereq(what);
@@ -422,163 +323,15 @@
       }
     }
 
-    message_dialog_add(shl, GTK_STOCK_CANCEL, 0, 0);
+    choice_dialog_add(shl, GTK_STOCK_CANCEL, 0, 0);
 
-    message_dialog_end(shl);
+    choice_dialog_end(shl);
 
     g_signal_connect(shl, "destroy", G_CALLBACK(pillage_destroy_callback),
                     NULL);   
   }
 }
 
-/****************************************************************
-...
-*****************************************************************/
-void message_dialog_button_set_sensitive(GtkWidget *shl, int button,
-                                        gboolean state)
-{
-  char button_name[512];
-  GtkWidget *b;
-
-  my_snprintf(button_name, sizeof(button_name), "button%d", button);
-
-  b = g_object_get_data(G_OBJECT(shl), button_name);
-  gtk_widget_set_sensitive(b, state);
-}
-
-/****************************************************************
-...
-*****************************************************************/
-GtkWidget *message_dialog_start(GtkWindow *parent, const gchar *name,
-                               const gchar *text)
-{
-  GtkWidget *dshell, *dlabel, *vbox, *bbox;
-
-  dshell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  setup_dialog(dshell, toplevel);
-  gtk_window_set_position (GTK_WINDOW(dshell), GTK_WIN_POS_MOUSE);
-
-  gtk_window_set_title(GTK_WINDOW(dshell), name);
-
-  gtk_window_set_transient_for(GTK_WINDOW(dshell), parent);
-  gtk_window_set_destroy_with_parent(GTK_WINDOW(dshell), TRUE);
-
-  vbox = gtk_vbox_new(FALSE, 5);
-  gtk_container_add(GTK_CONTAINER(dshell),vbox);
-
-  gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
-
-  dlabel = gtk_label_new(text);
-  gtk_container_add(GTK_CONTAINER(vbox), dlabel);
-
-  bbox = gtk_vbutton_box_new();
-  gtk_box_set_spacing(GTK_BOX(bbox), 2);
-  gtk_container_add(GTK_CONTAINER(vbox), bbox);
-  
-  g_object_set_data(G_OBJECT(dshell), "bbox", bbox);
-  g_object_set_data(G_OBJECT(dshell), "nbuttons", GINT_TO_POINTER(0));
-  g_object_set_data(G_OBJECT(dshell), "hide", GINT_TO_POINTER(FALSE));
-  
-  gtk_widget_show(vbox);
-  gtk_widget_show(dlabel);
-  
-  return dshell;
-}
-
-/****************************************************************
-...
-*****************************************************************/
-static void message_dialog_clicked(GtkWidget *w, gpointer data)
-{
-  if (g_object_get_data(G_OBJECT(data), "hide")) {
-    gtk_widget_hide(GTK_WIDGET(data));
-  } else {
-    gtk_widget_destroy(GTK_WIDGET(data));
-  }
-}
-
-/****************************************************************
-...
-*****************************************************************/
-void message_dialog_add(GtkWidget *dshell, const gchar *label,
-                       GCallback handler, gpointer data)
-{
-  GtkWidget *button, *bbox;
-  char name[512];
-  int nbuttons;
-
-  bbox = g_object_get_data(G_OBJECT(dshell), "bbox");
-  nbuttons = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dshell), "nbuttons"));
-  g_object_set_data(G_OBJECT(dshell), "nbuttons", GINT_TO_POINTER(nbuttons+1));
-
-  my_snprintf(name, sizeof(name), "button%d", nbuttons);
-
-  button = gtk_button_new_from_stock(label);
-  gtk_container_add(GTK_CONTAINER(bbox), button);
-  g_object_set_data(G_OBJECT(dshell), name, button);
-
-  if (handler) {
-    g_signal_connect(button, "clicked", handler, data);
-  }
-
-  g_signal_connect_after(button, "clicked",
-                        G_CALLBACK(message_dialog_clicked), dshell);
-}
-
-/****************************************************************
-...
-*****************************************************************/
-void message_dialog_end(GtkWidget *dshell)
-{
-  GtkWidget *bbox;
-  
-  bbox = g_object_get_data(G_OBJECT(dshell), "bbox");
-  
-  gtk_widget_show_all(bbox);
-  gtk_widget_show(dshell);  
-}
-
-/****************************************************************
-...
-*****************************************************************/
-void message_dialog_set_hide(GtkWidget *dshell, gboolean setting)
-{
-  g_object_set_data(G_OBJECT(dshell), "hide", GINT_TO_POINTER(setting));
-}
-
-/****************************************************************
-...
-*****************************************************************/
-GtkWidget *popup_message_dialog(GtkWindow *parent, const gchar *dialogname,
-                               const gchar *text, ...)
-{
-  GtkWidget *dshell;
-  va_list args;
-  gchar *name;
-  int i;
-
-  dshell = message_dialog_start(parent, dialogname, text);
-  
-  i = 0;
-  va_start(args, text);
-
-  while ((name = va_arg(args, gchar *))) {
-    GCallback handler;
-    gpointer data;
-
-    handler = va_arg(args, GCallback);
-    data = va_arg(args, gpointer);
-
-    message_dialog_add(dshell, name, handler, data);
-  }
-
-  va_end(args);
-
-  message_dialog_end(dshell);
-
-  return dshell;
-}
-
 /**************************************************************************
 ...
 **************************************************************************/
Index: client/gui-gtk-2.0/dialogs.h
===================================================================
--- client/gui-gtk-2.0/dialogs.h        (wersja 11206)
+++ client/gui-gtk-2.0/dialogs.h        (kopia robocza)
@@ -22,11 +22,6 @@
 void popup_revolution_dialog(struct government *government);
 void message_dialog_button_set_sensitive(GtkWidget *shl, int button,
                                         gboolean state);
-GtkWidget *popup_message_dialog(GtkWindow *parent, const gchar *dialogname,
-                               const gchar *text, ...);
-
-void message_dialog_set_hide(GtkWidget *dshell, gboolean setting);
-
 gboolean taxrates_callback(GtkWidget *w, GdkEventButton *ev, gpointer data);
 
 #endif  /* FC__DIALOGS_H */
Index: client/gui-gtk-2.0/diplomat_dialog.c
===================================================================
--- client/gui-gtk-2.0/diplomat_dialog.c        (wersja 11206)
+++ client/gui-gtk-2.0/diplomat_dialog.c        (kopia robocza)
@@ -24,6 +24,7 @@
 
 #include "dialogs_g.h"
 #include "chatline.h"
+#include "choice_dialog.h"
 #include "civclient.h"
 #include "climisc.h"
 #include "clinet.h"
@@ -78,7 +79,7 @@
   GtkWidget *shell;
 
   if (unit_flag(punit, F_UNBRIBABLE)) {
-    shell = popup_message_dialog(GTK_WINDOW(toplevel), _("Ooops..."),
+    shell = popup_choice_dialog(GTK_WINDOW(toplevel), _("Ooops..."),
                                  _("This unit cannot be bribed!"),
                                  GTK_STOCK_OK, NULL, NULL, NULL);
     gtk_window_present(GTK_WINDOW(shell));
@@ -616,7 +617,7 @@
                unit_name(punit->type), pcity->name);
 
     if (!unit_flag(punit, F_SPY)){
-      shl = popup_message_dialog(GTK_WINDOW(toplevel),
+      shl = popup_choice_dialog(GTK_WINDOW(toplevel),
        _(" Choose Your Diplomat's Strategy"), buf,
        _("Establish _Embassy"), diplomat_embassy_callback, NULL,
        _("_Investigate City"), diplomat_investigate_callback, NULL,
@@ -628,19 +629,19 @@
        NULL);
 
       if (!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile))
-       message_dialog_button_set_sensitive(shl, 0, FALSE);
+       choice_dialog_button_set_sensitive(shl, 0, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 1, FALSE);
+       choice_dialog_button_set_sensitive(shl, 1, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 2, FALSE);
+       choice_dialog_button_set_sensitive(shl, 2, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile))
-       message_dialog_button_set_sensitive(shl, 3, FALSE);
+       choice_dialog_button_set_sensitive(shl, 3, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 4, FALSE);
+       choice_dialog_button_set_sensitive(shl, 4, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 5, FALSE);
+       choice_dialog_button_set_sensitive(shl, 5, FALSE);
     } else {
-       shl = popup_message_dialog(GTK_WINDOW(toplevel),
+       shl = popup_choice_dialog(GTK_WINDOW(toplevel),
        _("Choose Your Spy's Strategy"), buf,
        _("Establish _Embassy"), diplomat_embassy_callback, NULL,
        _("_Investigate City"), diplomat_investigate_callback, NULL,
@@ -653,24 +654,24 @@
        NULL);
 
       if (!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile))
-       message_dialog_button_set_sensitive(shl, 0, FALSE);
+       choice_dialog_button_set_sensitive(shl, 0, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 1, FALSE);
+       choice_dialog_button_set_sensitive(shl, 1, FALSE);
       if (!diplomat_can_do_action(punit, SPY_POISON, dest_tile))
-       message_dialog_button_set_sensitive(shl, 2, FALSE);
+       choice_dialog_button_set_sensitive(shl, 2, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 3, FALSE);
+       choice_dialog_button_set_sensitive(shl, 3, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile))
-       message_dialog_button_set_sensitive(shl, 4, FALSE);
+       choice_dialog_button_set_sensitive(shl, 4, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 5, FALSE);
+       choice_dialog_button_set_sensitive(shl, 5, FALSE);
       if (!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile))
-       message_dialog_button_set_sensitive(shl, 6, FALSE);
+       choice_dialog_button_set_sensitive(shl, 6, FALSE);
      }
 
     diplomat_dialog = shl;
 
-    message_dialog_set_hide(shl, TRUE);
+    choice_dialog_set_hide(shl, TRUE);
     g_signal_connect(shl, "destroy",
                     G_CALLBACK(diplomat_destroy_callback), NULL);
     g_signal_connect(shl, "delete_event",
@@ -681,7 +682,7 @@
        
       diplomat_target_id = ptunit->id;
  
-      shl = popup_message_dialog(GTK_WINDOW(toplevel),
+      shl = popup_choice_dialog(GTK_WINDOW(toplevel),
        _("Subvert Enemy Unit"),
        (!unit_flag(punit, F_SPY))?
        _("Sir, the diplomat is waiting for your command"):
@@ -692,15 +693,15 @@
        NULL);
 
       if (!diplomat_can_do_action(punit, DIPLOMAT_BRIBE, dest_tile)) {
-       message_dialog_button_set_sensitive(shl, 0, FALSE);
+       choice_dialog_button_set_sensitive(shl, 0, FALSE);
       }
       if (!diplomat_can_do_action(punit, SPY_SABOTAGE_UNIT, dest_tile)) {
-       message_dialog_button_set_sensitive(shl, 1, FALSE);
+       choice_dialog_button_set_sensitive(shl, 1, FALSE);
       }
 
       diplomat_dialog = shl;
 
-      message_dialog_set_hide(shl, TRUE);
+      choice_dialog_set_hide(shl, TRUE);
       g_signal_connect(shl, "destroy",
                       G_CALLBACK(diplomat_destroy_callback), NULL);
       g_signal_connect(shl, "delete_event",
Index: client/gui-gtk-2.0/choice_dialog.c
===================================================================
--- client/gui-gtk-2.0/choice_dialog.c  (wersja 0)
+++ client/gui-gtk-2.0/choice_dialog.c  (wersja 0)
@@ -0,0 +1,197 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
+   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 "support.h"
+
+#include "gui_main.h"
+#include "gui_stuff.h"
+
+#include "choice_dialog.h"
+
+/****************************************************************
+  Choice dialog: A dialog with a label and a list of buttons
+  placed vertically
+****************************************************************/
+
+/****************************************************************
+...
+*****************************************************************/
+static GtkWidget* choice_dialog_get_nth_button(GtkWidget *cd,
+                                               int button)
+{
+  char button_name[512];
+  GtkWidget *b;
+
+  my_snprintf(button_name, sizeof(button_name), "button%d", button);
+
+  b = g_object_get_data(G_OBJECT(cd), button_name);
+
+  return b;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void choice_dialog_button_set_sensitive(GtkWidget *cd, int button,
+                                        gboolean state)
+{
+  gtk_widget_set_sensitive(choice_dialog_get_nth_button(cd, button), state);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void choice_dialog_button_set_label(GtkWidget *cd, int number,
+                                    const char* label)
+{
+  GtkWidget* button = choice_dialog_get_nth_button(cd, number);
+  gtk_button_set_label(GTK_BUTTON(button), label);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+GtkWidget *choice_dialog_start(GtkWindow *parent, const gchar *name,
+                               const gchar *text)
+{
+  GtkWidget *dshell, *dlabel, *vbox, *bbox;
+
+  dshell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  setup_dialog(dshell, toplevel);
+  gtk_window_set_position (GTK_WINDOW(dshell), GTK_WIN_POS_MOUSE);
+
+  gtk_window_set_title(GTK_WINDOW(dshell), name);
+
+  gtk_window_set_transient_for(GTK_WINDOW(dshell), parent);
+  gtk_window_set_destroy_with_parent(GTK_WINDOW(dshell), TRUE);
+
+  vbox = gtk_vbox_new(FALSE, 5);
+  gtk_container_add(GTK_CONTAINER(dshell),vbox);
+
+  gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
+
+  dlabel = gtk_label_new(text);
+  gtk_container_add(GTK_CONTAINER(vbox), dlabel);
+
+  bbox = gtk_vbutton_box_new();
+  gtk_box_set_spacing(GTK_BOX(bbox), 2);
+  gtk_container_add(GTK_CONTAINER(vbox), bbox);
+  
+  g_object_set_data(G_OBJECT(dshell), "bbox", bbox);
+  g_object_set_data(G_OBJECT(dshell), "nbuttons", GINT_TO_POINTER(0));
+  g_object_set_data(G_OBJECT(dshell), "hide", GINT_TO_POINTER(FALSE));
+  
+  gtk_widget_show(vbox);
+  gtk_widget_show(dlabel);
+  
+  return dshell;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void choice_dialog_clicked(GtkWidget *w, gpointer data)
+{
+  if (g_object_get_data(G_OBJECT(data), "hide")) {
+    gtk_widget_hide(GTK_WIDGET(data));
+  } else {
+    gtk_widget_destroy(GTK_WIDGET(data));
+  }
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void choice_dialog_add(GtkWidget *dshell, const gchar *label,
+                       GCallback handler, gpointer data)
+{
+  GtkWidget *button, *bbox;
+  char name[512];
+  int nbuttons;
+
+  bbox = g_object_get_data(G_OBJECT(dshell), "bbox");
+  nbuttons = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dshell), "nbuttons"));
+  g_object_set_data(G_OBJECT(dshell), "nbuttons", GINT_TO_POINTER(nbuttons+1));
+
+  my_snprintf(name, sizeof(name), "button%d", nbuttons);
+
+  button = gtk_button_new_from_stock(label);
+  gtk_container_add(GTK_CONTAINER(bbox), button);
+  g_object_set_data(G_OBJECT(dshell), name, button);
+
+  if (handler) {
+    g_signal_connect(button, "clicked", handler, data);
+  }
+
+  g_signal_connect_after(button, "clicked",
+                        G_CALLBACK(choice_dialog_clicked), dshell);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void choice_dialog_end(GtkWidget *dshell)
+{
+  GtkWidget *bbox;
+  
+  bbox = g_object_get_data(G_OBJECT(dshell), "bbox");
+  
+  gtk_widget_show_all(bbox);
+  gtk_widget_show(dshell);  
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void choice_dialog_set_hide(GtkWidget *dshell, gboolean setting)
+{
+  g_object_set_data(G_OBJECT(dshell), "hide", GINT_TO_POINTER(setting));
+}
+
+/****************************************************************
+...
+*****************************************************************/
+GtkWidget *popup_choice_dialog(GtkWindow *parent, const gchar *dialogname,
+                               const gchar *text, ...)
+{
+  GtkWidget *dshell;
+  va_list args;
+  gchar *name;
+  int i;
+
+  dshell = choice_dialog_start(parent, dialogname, text);
+  
+  i = 0;
+  va_start(args, text);
+
+  while ((name = va_arg(args, gchar *))) {
+    GCallback handler;
+    gpointer data;
+
+    handler = va_arg(args, GCallback);
+    data = va_arg(args, gpointer);
+
+    choice_dialog_add(dshell, name, handler, data);
+  }
+
+  va_end(args);
+
+  choice_dialog_end(dshell);
+
+  return dshell;
+}
Index: client/gui-gtk-2.0/choice_dialog.h
===================================================================
--- client/gui-gtk-2.0/choice_dialog.h  (wersja 0)
+++ client/gui-gtk-2.0/choice_dialog.h  (wersja 0)
@@ -0,0 +1,32 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
+   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.
+***********************************************************************/
+#ifndef FC__CHOICE_DIALOG_H
+#define FC__CHOICE_DIALOG_H
+
+#include <gtk/gtk.h>
+
+GtkWidget *popup_choice_dialog(GtkWindow *parent, const gchar *dialogname,
+                              const gchar *text, ...);
+
+void choice_dialog_set_hide(GtkWidget *dshell, gboolean setting);
+
+GtkWidget *choice_dialog_start(GtkWindow *parent, const gchar *name,
+                                      const gchar *text);
+void choice_dialog_add(GtkWidget *dshell, const gchar *label,
+                             GCallback handler, gpointer data);
+void choice_dialog_end(GtkWidget *dshell);
+void choice_dialog_button_set_sensitive(GtkWidget *shl, int button,
+                                        gboolean state);
+void choice_dialog_button_set_label(GtkWidget *cd, int button,
+                                    const char* label);
+#endif
Index: client/gui-gtk-2.0/Makefile.am
===================================================================
--- client/gui-gtk-2.0/Makefile.am      (wersja 11206)
+++ client/gui-gtk-2.0/Makefile.am      (kopia robocza)
@@ -24,8 +24,11 @@
        Freeciv.h       \
        canvas.c        \
        canvas.h        \
+       caravan_dialog.c \
        chatline.h      \
        chatline.c      \
+       choice_dialog.c \
+       choice_dialog.h \
        citydlg.c       \
        citydlg.h       \
        cityrep.c       \
Index: client/include/dialogs_g.h
===================================================================
--- client/include/dialogs_g.h  (wersja 11206)
+++ client/include/dialogs_g.h  (kopia robocza)
@@ -35,7 +35,9 @@
 
 void popup_caravan_dialog(struct unit *punit,
                          struct city *phomecity, struct city *pdestcity);
-bool caravan_dialog_is_open(void);
+bool caravan_dialog_is_open(int* unit_id, int* city_id);
+void caravan_dialog_update(void);
+
 void popup_diplomat_dialog(struct unit *punit, struct tile *ptile);
 int diplomat_handled_in_diplomat_dialog(void);
 void close_diplomat_dialog(void);
Index: client/packhand.c
===================================================================
--- client/packhand.c   (wersja 11206)
+++ client/packhand.c   (kopia robocza)
@@ -390,7 +390,10 @@
   bool need_units_dialog_update = FALSE;
   struct city *pcity;
   bool popup, update_descriptions = FALSE, name_changed = FALSE;
+  bool shield_stock_changed = FALSE;
+  bool production_changed = FALSE;
   struct unit *pfocus_unit = get_unit_in_focus();
+  int caravan_city_id;
 
   pcity=find_city_by_id(packet->id);
 
@@ -465,7 +468,10 @@
   } output_type_iterate_end;
 
   pcity->food_stock=packet->food_stock;
-  pcity->shield_stock=packet->shield_stock;
+  if (pcity->shield_stock != packet->shield_stock) {
+    shield_stock_changed = TRUE;
+    pcity->shield_stock = packet->shield_stock;
+  }
   pcity->pollution=packet->pollution;
 
   if (city_is_new
@@ -473,6 +479,10 @@
       || pcity->production.value != packet->production_value) {
     need_units_dialog_update = TRUE;
   }
+  if (pcity->production.is_unit != packet->production_is_unit
+      || pcity->production.value != packet->production_value) {
+    production_changed = TRUE;
+  }
   pcity->production.is_unit = packet->production_is_unit;
   pcity->production.value = packet->production_value;
   if (city_is_new) {
@@ -563,6 +573,13 @@
 
   /* Update the panel text (including civ population). */
   update_info_label();
+  
+  /* update caravan dialog */
+  if ((production_changed || shield_stock_changed)
+      && caravan_dialog_is_open(NULL, &caravan_city_id)
+      && caravan_city_id == pcity->id) {
+    caravan_dialog_update();
+  }
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]