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

This patch introduces two new simple feature for gtk2 client:

    * Select same type in tile: Select all units with same type as
      selected units that has the same tile too
    * Select all (in select unit dialog): Ability to select all units of
      a tile at once

Hope to be useful

Regards
____________________
Arman Ordookhani

Index: client/control.c
===================================================================
--- client/control.c	(revision 13404)
+++ client/control.c	(working copy)
@@ -1156,6 +1156,26 @@
   }
 }
 
+/****************************************************************************
+  Select all units of the same type as the given unit that have the same tile
+****************************************************************************/
+void request_unit_select_same_type_tile(struct unit_list *punits)
+{
+  if (can_client_change_view()) {
+    unit_list_iterate(punits, punit) {
+      unit_list_iterate(unit_owner(punit)->units, punit2) {
+	if (unit_type(punit2) == unit_type(punit)
+	    && !unit_list_search(punits, punit2)
+	    && punit2->activity == ACTIVITY_IDLE
+	    && !unit_has_orders(punit2)
+	    && punit->tile == punit2->tile) {
+	  add_unit_focus(punit2);
+	}
+      } unit_list_iterate_end;
+    } unit_list_iterate_end;
+  }
+}
+
 /**************************************************************************
   Request a diplomat to do a specific action.
   - action : The action to be requested.
Index: client/gui-gtk-2.0/menu.c
===================================================================
--- client/gui-gtk-2.0/menu.c	(revision 13404)
+++ client/gui-gtk-2.0/menu.c	(working copy)
@@ -147,6 +147,7 @@
   MENU_ORDER_DIPLOMAT_DLG,
   MENU_ORDER_NUKE,
   MENU_ORDER_SELECT_SAME_TYPE,
+  MENU_ORDER_SELECT_SAME_TYPE_TILE,
   MENU_ORDER_WAIT,
   MENU_ORDER_DONE,
 
@@ -407,6 +408,9 @@
   case MENU_ORDER_SELECT_SAME_TYPE:
     request_unit_select_same_type(get_units_in_focus());
     break;
+  case MENU_ORDER_SELECT_SAME_TYPE_TILE:
+    request_unit_select_same_type_tile(get_units_in_focus());
+    break;
   case MENU_ORDER_BUILD_CITY:
     unit_list_iterate(get_units_in_focus(), punit) {
       /* FIXME: this can provide different actions for different units...
@@ -917,6 +921,8 @@
 	NULL,			0,					"<Separator>"	},
   { "/" N_("Orders") "/" N_("Select same type"), "y",
     orders_menu_callback, MENU_ORDER_SELECT_SAME_TYPE },
+  { "/" N_("Orders") "/" N_("Select same type in tile"), "<shift>y",
+    orders_menu_callback, MENU_ORDER_SELECT_SAME_TYPE_TILE },
   { "/" N_("Orders") "/" N_("_Wait"),			"w",
 	orders_menu_callback,	MENU_ORDER_WAIT						},
   { "/" N_("Orders") "/" N_("Done"),			"space",
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c	(revision 13404)
+++ client/gui-gtk-2.0/dialogs.c	(working copy)
@@ -71,6 +71,7 @@
 /******************************************************************/
 #define SELECT_UNIT_READY  1
 #define SELECT_UNIT_SENTRY 2
+#define SELECT_UNIT_ALL    3
 
 static GtkWidget *unit_select_dialog_shell;
 static GtkTreeStore *unit_select_store;
@@ -491,6 +492,19 @@
     }
     break;
 
+  case SELECT_UNIT_ALL:
+    {
+      unit_list_iterate(ptile->units, punit) {
+        if (game.player_ptr == punit->owner) {
+          if (punit->activity == ACTIVITY_IDLE) {
+            /* Give focus to it */
+            add_unit_focus(punit);
+          }
+        }
+      } unit_list_iterate_end;
+    }
+    break;
+
   default:
     break;
   }
@@ -508,7 +522,7 @@
   if (!unit_select_dialog_shell) {
     GtkTreeStore *store;
     GtkWidget *shell, *view, *sw, *hbox;
-    GtkWidget *ready_cmd, *sentry_cmd, *close_cmd;
+    GtkWidget *ready_cmd, *sentry_cmd, *select_all_cmd, *close_cmd;
 
     static const char *titles[NUM_UNIT_SELECT_COLUMNS] = {
       N_("Unit"),
@@ -601,6 +615,14 @@
       GTK_BUTTON_BOX(GTK_DIALOG(shell)->action_area),
       sentry_cmd, TRUE);
 
+    select_all_cmd =
+    gtk_dialog_add_button(GTK_DIALOG(shell),
+      _("Select _all"), SELECT_UNIT_ALL);
+
+    gtk_button_box_set_child_secondary(
+      GTK_BUTTON_BOX(GTK_DIALOG(shell)->action_area),
+      select_all_cmd, TRUE);
+
     close_cmd =
     gtk_dialog_add_button(GTK_DIALOG(shell),
       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
Index: client/control.h
===================================================================
--- client/control.h	(revision 13404)
+++ client/control.h	(working copy)
@@ -91,6 +91,7 @@
 void request_units_wait(struct unit_list *punits);
 void request_unit_wakeup(struct unit *punit);
 void request_unit_select_same_type(struct unit_list *punits);
+void request_unit_select_same_type_tile(struct unit_list *punits);
 void request_diplomat_action(enum diplomat_actions action, int dipl_id,
 			     int target_id, int value);
 void request_toggle_city_outlines(void);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to