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

[Freeciv-Dev] (PR#2923) New government choice submenus patch V2 (GTK+ 2.

[Top] [All Lists]

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

---------- Forwarded message ----------
Date: Sat, 4 Jan 2003 00:13:28 +0000 (WET)
From: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] New government choice submenus patch V2 (GTK+ 2.0)


Moved some code to client/, and added TECHNICOLOR(TM) PANAVISION(TM)
PANAFLEX(TM)(C) government icons to the menu.

Is this ok now? :)

---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa


--- client/packhand.c   3 Jan 2003 08:58:47 -0000       1.268
+++ client/packhand.c   4 Jan 2003 00:09:30 -0000
@@ -1181,6 +1181,43 @@
 /**************************************************************************
 ...
 **************************************************************************/
+static bool government_selected = FALSE;
+static int government_choice;
+
+/**************************************************************************
+...
+**************************************************************************/
+void set_government_choice(int government)
+{
+  struct packet_player_request packet;
+
+  if (!government_selected) {
+    send_packet_player_request(&aconnection, &packet, 
PACKET_PLAYER_REVOLUTION);
+    government_selected = TRUE;
+  }
+  government_choice = government;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static bool government_chosen(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;
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
 void handle_player_info(struct packet_player_info *pinfo)
 {
   int i;
@@ -1266,7 +1303,10 @@
       (!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();
+
+    if (!government_chosen()) {
+      popup_government_dialog();
+    }
   }
   
   update_players_dialog();
--- client/packhand.h   11 Nov 2002 10:00:47 -0000      1.30
+++ client/packhand.h   4 Jan 2003 00:09:30 -0000
@@ -72,4 +72,6 @@
                                  int packet_type, int size,
                                  int request_id);
 void set_reports_thaw_request(int request_id);
+
+void set_government_choice(int government);
 #endif /* FC__PACKHAND_H */
--- client/gui-gtk-2.0/menu.c   1 Jan 2003 11:51:33 -0000       1.10
+++ client/gui-gtk-2.0/menu.c   4 Jan 2003 00:09:37 -0000
@@ -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>"      },
@@ -957,6 +963,13 @@
   gtk_label_set_text_with_mnemonic(GTK_LABEL(GTK_BIN(item)->child), s);
 }
 
+/****************************************************************
+...
+*****************************************************************/
+void government_callback(GtkMenuItem *item, gpointer data)
+{
+  set_government_choice(GPOINTER_TO_INT(data));
+}
 
 /****************************************************************
 Note: the menu strings should contain underscores as in the
@@ -972,6 +985,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);
@@ -981,7 +1041,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]