Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] Re: (PR#2923) New government choice submenus patch V2 (GTK
Home

[Freeciv-Dev] Re: (PR#2923) New government choice submenus patch V2 (GTK

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#2923) New government choice submenus patch V2 (GTK+ 2.0)
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Mon, 27 Jan 2003 18:37:02 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Jason Short via RT wrote:

> Is this ok now? :)

Here's a changed version of the patch.

Changes:

1. Don't try to revolt if !can_client_issue_orders.  This should be 
taken care of by the GUI, but it's not worth a segfault.

2. Don't revolt at all if you choose the current government type.

3. Reset the government selection when the client disconnects. 
Otherwise you could get odd behavior if you disconnected from a game 
where you were in anarchy, and connected to a different game where you 
were in anarchy.

4. Rename function to choose_government, and restructure it a little.

5. Some style fixes & added comments.

I really like the interface; this patch should go in ASAP.

jason

? client/mapview_common.c-clip_mapview_window
? client/gui-gtk/diff
Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.160
diff -u -r1.160 civclient.c
--- client/civclient.c  2003/01/05 20:51:36     1.160
+++ client/civclient.c  2003/01/28 02:32:59
@@ -601,6 +601,7 @@
   attribute_init();
   agents_init();
   cm_init();
+  target_government_init();
 }
 
 /**************************************************************************
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.277
diff -u -r1.277 packhand.c
--- client/packhand.c   2003/01/27 22:00:34     1.277
+++ client/packhand.c   2003/01/28 02:33:00
@@ -1182,6 +1182,62 @@
 }
 
 /**************************************************************************
+  government_selected will be set if the player has chosen a 'target'
+  government.  If so, then government_choice holds that government value.
+**************************************************************************/
+static bool government_selected = FALSE;
+static int government_choice;
+
+/**************************************************************************
+  Reset the target government (for instance when you disconnect from a
+  server).
+**************************************************************************/
+void target_government_init(void)
+{
+  /* We have to reset this, otherwise if we joined a new game where we
+   * were already in anarchy, odd behavior would result. */
+  government_selected = FALSE;
+}
+
+/**************************************************************************
+  Sets the target government.  This will automatically start a revolution
+  if the target government differs from the current one.
+**************************************************************************/
+void set_government_choice(int government)
+{
+  if (!government_selected
+      && government != game.player_ptr->government
+      && can_client_issue_orders()) {
+    struct packet_player_request packet;
+
+    send_packet_player_request(&aconnection, &packet,
+                              PACKET_PLAYER_REVOLUTION);
+    government_selected = TRUE;
+  }
+  government_choice = government;
+}
+
+/**************************************************************************
+  Choose the government after a revolution completes, either by taking the
+  government that the player has already specified or by popping up a
+  dialog to ask.
+**************************************************************************/
+static void choose_government(void)
+{
+  if (government_selected) {
+    struct packet_player_request packet;
+
+    packet.government = government_choice;
+    send_packet_player_request(&aconnection, &packet,
+                              PACKET_PLAYER_GOVERNMENT);
+
+    government_selected = FALSE;
+  } else {
+    popup_government_dialog();
+  }
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void handle_player_info(struct packet_player_info *pinfo)
@@ -1265,7 +1321,8 @@
       (!game.player_ptr->ai.control || ai_popup_windows) &&
       can_client_change_view()) {
     create_event(-1, -1, E_REVOLT_DONE, _("Game: Revolution finished"));
-    popup_government_dialog();
+
+    choose_government();
   }
   
   update_players_dialog();
Index: client/packhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.h,v
retrieving revision 1.30
diff -u -r1.30 packhand.h
--- client/packhand.h   2002/11/11 10:00:47     1.30
+++ client/packhand.h   2003/01/28 02:33:00
@@ -72,4 +72,8 @@
                                  int packet_type, int size,
                                  int request_id);
 void set_reports_thaw_request(int request_id);
+
+void target_government_init(void);
+void set_government_choice(int government);
+
 #endif /* FC__PACKHAND_H */
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.11
diff -u -r1.11 menu.c
--- client/gui-gtk-2.0/menu.c   2003/01/12 23:31:22     1.11
+++ client/gui-gtk-2.0/menu.c   2003/01/28 02:33:01
@@ -24,6 +24,7 @@
 #include "astring.h"
 #include "fcintl.h"
 #include "log.h"
+#include "government.h"
 #include "map.h"
 #include "mem.h"
 #include "support.h"
@@ -37,6 +38,7 @@
 #include "dialogs.h"
 #include "finddlg.h"
 #include "gotodlg.h"
+#include "graphics.h"
 #include "gui_stuff.h"
 #include "helpdlg.h"
 #include "mapctrl.h"   /* center_on_unit */
@@ -44,6 +46,7 @@
 #include "messagewin.h"
 #include "optiondlg.h"
 #include "options.h"
+#include "packhand.h"
 #include "plrdlg.h"
 #include "ratesdlg.h"
 #include "repodlgs.h"
@@ -555,8 +558,6 @@
        NULL,                   0,                                      
"<Branch>"      },
   { "/" N_("Game") "/tearoff1",                                NULL,
        NULL,                   0,                                      
"<Tearoff>"     },
-  { "/" N_("Game") "/sep1",                            NULL,
-       NULL,                   0,                                      
"<Separator>"   },
   { "/" N_("Game") "/" N_("_Local Options"),           NULL,
        game_menu_callback,     MENU_GAME_OPTIONS                               
        },
   { "/" N_("Game") "/" N_("Messa_ge Options"),         NULL,
@@ -596,8 +597,13 @@
        kingdom_menu_callback,  MENU_KINGDOM_WORKLISTS                          
        },
   { "/" N_("Kingdom") "/sep2",                         NULL,
        NULL,                   0,                                      
"<Separator>"   },
-  { "/" N_("Kingdom") "/" N_("_Revolution"),           "<shift>r",
+  { "/" N_("_Kingdom") "/" N_("_Government"),           NULL,
+       NULL,                   0,                                      
"<Branch>"      },
+  { "/" N_("Kingdom") "/" N_("_Government") "/" N_("_Revolution"),
+                                                        "<shift>r",
        kingdom_menu_callback,  MENU_KINGDOM_REVOLUTION                         
        },
+  { "/" N_("_Kingdom") "/" N_("_Government") "/sep1", NULL,
+       NULL,                   0,                                      
"<Separator>"   },
   /* View menu ... */
   { "/" N_("_View"),                                   NULL,
        NULL,                   0,                                      
"<Branch>"      },
@@ -984,6 +990,13 @@
   gtk_label_set_text_with_mnemonic(GTK_LABEL(GTK_BIN(item)->child), s);
 }
 
+/****************************************************************
+  The player has chosen a government from the menu.
+*****************************************************************/
+static void government_callback(GtkMenuItem *item, gpointer data)
+{
+  set_government_choice(GPOINTER_TO_INT(data));
+}
 
 /****************************************************************
 Note: the menu strings should contain underscores as in the
@@ -999,6 +1012,53 @@
     menus_set_sensitive("<main>/_Orders", FALSE);
   } else {
     struct unit *punit;
+    GtkWidget *parent, *item;
+    const char *path;
+
+    path = translate_menu_path("<main>/_Kingdom/_Government", 1);
+
+    if ((parent = gtk_item_factory_get_widget(item_factory, path))) {
+      int i;
+      GList *iter, *iter_next;
+
+      /* remove previous government entries. */
+      iter = gtk_container_get_children(GTK_CONTAINER(parent));
+      for (iter = g_list_nth(iter, 3); iter; iter = iter_next) {
+        iter_next = iter->next;
+
+        gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET(iter->data));
+      }
+
+      /* add new government entries. */
+      for (i = 0; i < game.government_count; ++i) {
+        struct government *g = &governments[i];
+
+        if (i != game.government_when_anarchy) {
+          GtkWidget *image;
+          struct Sprite *gsprite;
+
+          item = gtk_image_menu_item_new_with_label(g->name);
+
+          gsprite = get_government(g->index)->sprite;
+          image = gtk_image_new_from_pixmap(gsprite->pixmap, gsprite->mask);
+          gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
+
+          gtk_widget_show(image);
+          gtk_widget_show(item);
+
+          g_signal_connect(item, "activate",
+            G_CALLBACK(government_callback), GINT_TO_POINTER(g->index));
+
+          if (!can_change_to_government(game.player_ptr, i)) {
+            gtk_widget_set_sensitive(item, FALSE);
+         }
+
+          gtk_menu_shell_append(GTK_MENU_SHELL(parent), item);
+          gtk_widget_show(item);
+        }
+      }
+    }
+
     menus_set_sensitive("<main>/_Reports", TRUE);
     menus_set_sensitive("<main>/_Kingdom", TRUE);
     menus_set_sensitive("<main>/_View", TRUE);
@@ -1008,7 +1068,7 @@
                        can_client_issue_orders());
     menus_set_sensitive("<main>/_Kingdom/Work_lists",
                        can_client_issue_orders());
-    menus_set_sensitive("<main>/_Kingdom/_Revolution",
+    menus_set_sensitive("<main>/_Kingdom/_Government",
                        can_client_issue_orders());
 
     menus_set_sensitive("<main>/_Reports/S_paceship",

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