Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2006:
[Freeciv-Dev] (PR#17599) Implement unit menu in editor dialog
Home

[Freeciv-Dev] (PR#17599) Implement unit menu in editor dialog

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#17599) Implement unit menu in editor dialog
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sat, 3 Jun 2006 10:12:15 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch implements a unit dropdown menu in the editor dialog for 
placing units (instead of having to remember a unit type's index number).

My GTK skills are horrible, so please someone who knows GTK a little bit 
better than me, look over this code.

   - Per
Index: client/gui-gtk-2.0/editdlg.c
===================================================================
--- client/gui-gtk-2.0/editdlg.c        (revision 12005)
+++ client/gui-gtk-2.0/editdlg.c        (working copy)
@@ -199,9 +199,6 @@
   case UPARAM_OWNER:
     punit->owner = get_player(gtk_spin_button_get_value_as_int(spinbutton));
     return;
-  case UPARAM_TYPE:
-    punit->type = get_unit_type(gtk_spin_button_get_value_as_int(spinbutton));
-    return;
   case UPARAM_MOVES:
     punit->moves_left = gtk_spin_button_get_value_as_int(spinbutton);
     return;
@@ -214,6 +211,9 @@
   case UPARAM_ACTIVITY_COUNT:
     punit->activity_count = gtk_spin_button_get_value_as_int(spinbutton);
     return;
+  case UPARAM_TYPE:
+    assert(FALSE);
+    break;
   case UPARAM_LAST:
     break;
   }
@@ -222,6 +222,17 @@
 }
 
 /****************************************************************************
+  Set unit type.
+****************************************************************************/
+static void unit_type_callback(GtkWidget *button, gpointer data)
+{
+  size_t to = (size_t) data;
+  struct unit *punit = editor_get_selected_unit();
+
+  punit->type = get_unit_type(to);
+}
+
+/****************************************************************************
  FIXME: this is for demonstration purposes only (and not demonstration of
           coding goodness to be sure!)
 ****************************************************************************/
@@ -341,13 +352,39 @@
     {punit->activity_target, 0, S_LAST},
     {punit->activity_count, 0, 200}
   };
+  GtkWidget *unitmenu;
+  GtkWidget *popupmenu;
 
   vbox = gtk_vbox_new(FALSE, 5);
 
   label_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
   sb_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
 
+  unitmenu = gtk_option_menu_new();
+  hbox = gtk_hbox_new(FALSE, 5);
+  label = gtk_label_new(names[1]);
+  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+  gtk_size_group_add_widget(label_group, label);
+  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), unitmenu, TRUE, TRUE, 0);
+  popupmenu = gtk_menu_new();
+  gtk_option_menu_set_menu(GTK_OPTION_MENU(unitmenu), popupmenu);
+  unit_type_iterate(ptype) {
+    const gchar *data = get_unit_name(ptype);
+    GtkWidget *item = gtk_menu_item_new_with_label(data);
+
+    g_signal_connect(item, "activate",
+                     G_CALLBACK(unit_type_callback),
+                     GINT_TO_POINTER(ptype->index));
+    gtk_menu_shell_append(GTK_MENU_SHELL(popupmenu), item);
+  } unit_type_iterate_end;
+  gtk_widget_show_all(popupmenu);
+
   for (i = 0; i < UPARAM_LAST; i++) {
+    if (i == 1) {
+      continue; // handled above
+    }
     adj = GTK_ADJUSTMENT(gtk_adjustment_new(inits[i][0], inits[i][1], 
                                            inits[i][2], 1.0, 5.0, 5.0));
     hbox = gtk_hbox_new(FALSE, 5);

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