Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9783) gui-xaw: government menu choices
Home

[Freeciv-Dev] (PR#9783) gui-xaw: government menu choices

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9783) gui-xaw: government menu choices
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Aug 2004 17:51:10 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9783 >

This patch implements the government-change menu items for the XAW client.

See also PR#2327.

jason

Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.65
diff -u -r1.65 menu.c
--- client/gui-xaw/menu.c       23 Aug 2004 23:24:45 -0000      1.65
+++ client/gui-xaw/menu.c       24 Aug 2004 00:46:46 -0000
@@ -26,9 +26,11 @@
 #include <X11/Xaw/SmeLine.h>
 
 #include "fcintl.h"
-#include "map.h"
 #include "mem.h"
 #include "support.h"
+
+#include "government.h"
+#include "map.h"
 #include "unit.h"
 
 #include "chatline.h"
@@ -47,6 +49,7 @@
 #include "messagewin.h"
 #include "optiondlg.h"
 #include "options.h"
+#include "packhand.h"
 #include "plrdlg.h"
 #include "ratesdlg.h"
 #include "repodlgs.h"
@@ -127,6 +130,10 @@
     { { 0,                            },       0, MENU_END_OF_LIST, 0 }
 };
 
+/* One entry for every government, appended to the government menu. */
+static int num_government_entries = 0;
+static Widget government_widgets[G_MAGIC];
+
 static struct MenuEntry view_menu_entries[]={
     { { N_("Map Grid"), 0             }, "ctl-g", MENU_VIEW_SHOW_MAP_GRID, 0 },
     { { N_("National Borders"), 0     }, "ctl-b",
@@ -250,6 +257,9 @@
 static void menu_entry_rename(enum MenuIndex menu, enum MenuID id, int var, 
char *terr);
 static char *menu_entry_text(enum MenuIndex menu, int ent, int var, char 
*terr);
 
+static void revolution_menu_callback(Widget w, XtPointer client_data,
+                                    XtPointer garbage);
+
 /****************************************************************
 ...
 *****************************************************************/
@@ -295,6 +305,33 @@
                          can_client_issue_orders());
     menu_entry_sensitive(MENU_GOVERNMENT, MENU_GOVERNMENT_REVOLUTION,
                          can_client_issue_orders());
+
+    /* Destroy all government-change entries and build them from scratch.
+     * This could probably be done more efficiently if it were only done
+     * when the client receives the rulesets or disconnects. */
+    for (i = 0; i < num_government_entries; i++) {
+      XtDestroyWidget(government_widgets[i]);
+    }
+    i = 0;
+    government_iterate(gov) {
+      Widget w;
+
+      if (gov->index == game.government_when_anarchy) {
+       continue;
+      }
+
+      w = XtCreateManagedWidget(gov->name, smeBSBObjectClass,
+                               menus[MENU_GOVERNMENT]->shell, NULL, 0);
+      XtAddCallback(w, XtNcallback, revolution_menu_callback,
+                   (XtPointer)gov->index);
+      XtSetSensitive(w, can_change_to_government(game.player_ptr,
+                                                gov->index));
+
+      government_widgets[i] = w;
+      i++;
+    } government_iterate_end;
+    num_government_entries = i;
+
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_CITY_GROWTH,
                         draw_city_names);
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_TERRAIN, 1);
@@ -521,6 +558,15 @@
   }
 }
 
+/****************************************************************************
+  Callback for the government change entries in the government menu.
+****************************************************************************/
+static void revolution_menu_callback(Widget w, XtPointer client_data,
+                                    XtPointer garbage)
+{
+  set_government_choice((int)client_data);
+}
+
 /****************************************************************
 ...
 *****************************************************************/
Index: client/gui-xaw/menu.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.h,v
retrieving revision 1.19
diff -u -r1.19 menu.h
--- client/gui-xaw/menu.h       23 Aug 2004 20:59:57 -0000      1.19
+++ client/gui-xaw/menu.h       24 Aug 2004 00:46:46 -0000
@@ -47,6 +47,7 @@
   MENU_GOVERNMENT_FIND_CITY,
   MENU_GOVERNMENT_WORKLISTS,
   MENU_GOVERNMENT_REVOLUTION,
+  /* MENU_GOVERNMENT_CHANGE is handled separately. */
 
   MENU_VIEW_SHOW_MAP_GRID,
   MENU_VIEW_SHOW_NATIONAL_BORDERS,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9783) gui-xaw: government menu choices, Jason Short <=