Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] Re: (PR#8739) menu-based connect
Home

[Freeciv-Dev] Re: (PR#8739) menu-based connect

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8739) menu-based connect
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 15 May 2004 00:33:31 -0700
Reply-to: rt@xxxxxxxxxxx

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

Jason Short wrote:

> This patch (based on the PR#7282 patch) introduces a new system.  The 
> connect entry in the menu is a sub-menu containing the possible connect 
> activities.  When the user chooses an activity (possibly via keypress) 
> we go into the connect hover state, now knowing the activity.  So when 
> the user chooses a target location, we skip the popup dialog and send 
> the request straight to the server.

Here's a new patch.  All the old bits are the same but support is added 
to the stub, xaw, gtk, and win32 clients.

jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.134
diff -u -r1.134 control.c
--- client/control.c    16 Apr 2004 17:27:08 -0000      1.134
+++ client/control.c    15 May 2004 07:32:24 -0000
@@ -55,6 +55,7 @@
 /* These should be set via set_hover_state() */
 int hover_unit = 0; /* id of unit hover_state applies to */
 enum cursor_hover_state hover_state = HOVER_NONE;
+enum unit_activity connect_activity;
 /* This may only be here until client goto is fully implemented.
    It is reset each time the hower_state is reset. */
 bool draw_goto_line = TRUE;
@@ -79,15 +80,18 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void set_hover_state(struct unit *punit, enum cursor_hover_state state)
+void set_hover_state(struct unit *punit, enum cursor_hover_state state,
+                    enum unit_activity activity)
 {
   assert(punit != NULL || state == HOVER_NONE);
+  assert(state == HOVER_CONNECT || activity == ACTIVITY_LAST);
   draw_goto_line = TRUE;
   if (punit)
     hover_unit = punit->id;
   else
     hover_unit = 0;
   hover_state = state;
+  connect_activity = activity;
   exit_goto_state();
 }
 
@@ -220,7 +224,7 @@
   struct unit *punit_old_focus = punit_focus;
   struct unit *candidate = find_best_focus_candidate(FALSE);
 
-  set_hover_state(NULL, HOVER_NONE);
+  set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
   if (!can_client_change_view()) {
     return;
   }
@@ -601,7 +605,7 @@
     return;
 
   if (hover_state != HOVER_GOTO) {
-    set_hover_state(punit, HOVER_GOTO);
+    set_hover_state(punit, HOVER_GOTO, ACTIVITY_LAST);
     update_unit_info_label(punit);
     /* Not yet implemented for air units, including helicopters. */
     if (is_air_unit(punit) || is_heli_unit(punit)) {
@@ -620,10 +624,15 @@
 prompt player for entering destination point for unit connect
 (e.g. connecting with roads)
 **************************************************************************/
-void request_unit_connect(void)
+void request_unit_connect(enum unit_activity activity)
 {
-  if (punit_focus && can_unit_do_connect (punit_focus, ACTIVITY_IDLE)) {
-    set_hover_state(punit_focus, HOVER_CONNECT);
+  if (!punit_focus || !can_unit_do_connect(punit_focus, activity)) {
+    return;
+  }
+
+  if (hover_state != HOVER_CONNECT || connect_activity != activity) {
+    /* Enter or change the hover connect state. */
+    set_hover_state(punit_focus, HOVER_CONNECT, activity);
     update_unit_info_label(punit_focus);
   }
 }
@@ -926,7 +935,7 @@
   if(punit->moves_left == 0)
     do_unit_nuke(punit);
   else {
-    set_hover_state(punit, HOVER_NUKE);
+    set_hover_state(punit, HOVER_NUKE, ACTIVITY_LAST);
     update_unit_info_label(punit);
   }
 }
@@ -943,7 +952,7 @@
   if(!can_unit_paradrop(punit))
     return;
 
-  set_hover_state(punit, HOVER_PARADROP);
+  set_hover_state(punit, HOVER_PARADROP, ACTIVITY_LAST);
   update_unit_info_label(punit);
 }
 
@@ -958,7 +967,7 @@
     return;
 
   if (hover_state != HOVER_PATROL) {
-    set_hover_state(punit, HOVER_PATROL);
+    set_hover_state(punit, HOVER_PATROL, ACTIVITY_LAST);
     update_unit_info_label(punit);
     /* Not yet implemented for air units, including helicopters. */
     if (is_air_unit(punit) || is_heli_unit(punit)) {
@@ -1378,13 +1387,13 @@
       do_unit_paradrop_to(punit, xtile, ytile);
       break;
     case HOVER_CONNECT:
-      popup_unit_connect_dialog(punit, xtile, ytile);
+      do_unit_connect(punit, xtile, ytile, connect_activity);
       break;
     case HOVER_PATROL:
       do_unit_patrol_to(punit, xtile, ytile);
       break;   
     }
-    set_hover_state(NULL, HOVER_NONE);
+    set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
     update_unit_info_label(punit);
   }
 
@@ -1578,7 +1587,7 @@
     }
   }
 
-  set_hover_state(NULL, HOVER_NONE);
+  set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
 }
 
 /**************************************************************************
@@ -1616,7 +1625,22 @@
     }
   }
 
-  set_hover_state(NULL, HOVER_NONE);
+  set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
+}
+ 
+/**************************************************************************
+  "Connect" to the given location.
+**************************************************************************/
+void do_unit_connect(struct unit *punit, int x, int y,
+                    enum unit_activity activity)
+{
+  struct packet_unit_connect req;
+
+  req.activity_type = activity;
+  req.unit_id = punit->id;
+  req.dest_x = x;
+  req.dest_y = y;
+  send_packet_unit_connect(&aconnection, &req);
 }
  
 /**************************************************************************
@@ -1635,7 +1659,7 @@
   if (hover_state != HOVER_NONE && !popped) {
     struct unit *punit = player_find_unit_by_id(game.player_ptr, hover_unit);
 
-    set_hover_state(NULL, HOVER_NONE);
+    set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
     update_unit_info_label(punit);
 
     keyboardless_goto_button_down = FALSE;
@@ -1716,10 +1740,10 @@
 /**************************************************************************
 handle user pressing key for 'Connect' command
 **************************************************************************/
-void key_unit_connect(void)
+void key_unit_connect(enum unit_activity activity)
 {
   if (punit_focus) {
-    request_unit_connect();
+    request_unit_connect(activity);
   }
 }
 
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.42
diff -u -r1.42 control.h
--- client/control.h    1 Apr 2004 23:46:25 -0000       1.42
+++ client/control.h    15 May 2004 07:32:24 -0000
@@ -31,6 +31,7 @@
 
 extern int hover_unit; /* unit hover_state applies to */
 extern enum cursor_hover_state hover_state;
+extern enum unit_activity connect_activity;
 extern bool draw_goto_line;
 extern bool non_ai_unit_focus;
 
@@ -39,9 +40,12 @@
 void do_unit_nuke(struct unit *punit);
 void do_unit_paradrop_to(struct unit *punit, int x, int y);
 void do_unit_patrol_to(struct unit *punit, int x, int y);
+void do_unit_connect(struct unit *punit, int x, int y,
+                    enum unit_activity activity);
 void do_map_click(int xtile, int ytile, enum quickselect_type qtype);
 
-void set_hover_state(struct unit *punit, enum cursor_hover_state state);
+void set_hover_state(struct unit *punit, enum cursor_hover_state state,
+                    enum unit_activity activity);
 void request_center_focus_unit(void);
 void request_move_unit_direction(struct unit *punit, int dir);
 void request_new_unit_activity(struct unit *punit, enum unit_activity act);
@@ -54,7 +58,7 @@
 void request_unit_build_city(struct unit *punit);
 void request_unit_caravan_action(struct unit *punit, enum packet_type action);
 void request_unit_change_homecity(struct unit *punit);
-void request_unit_connect(void);
+void request_unit_connect(enum unit_activity activity);
 void request_unit_disband(struct unit *punit);
 void request_unit_fortify(struct unit *punit);
 void request_unit_goto(void);
@@ -135,7 +139,7 @@
 void key_unit_auto_settle(void);
 void key_unit_build_city(void);
 void key_unit_build_wonder(void);
-void key_unit_connect(void);
+void key_unit_connect(enum unit_activity activity);
 void key_unit_diplomat_actions(void);
 void key_unit_disband(void);
 void key_unit_done(void);
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.35
diff -u -r1.35 mapctrl_common.c
--- client/mapctrl_common.c     4 May 2004 17:40:26 -0000       1.35
+++ client/mapctrl_common.c     15 May 2004 07:32:24 -0000
@@ -415,7 +415,7 @@
     struct unit *punit =
         player_find_unit_by_id(game.player_ptr, hover_unit);
     do_unit_goto(tile_x, tile_y);
-    set_hover_state(NULL, HOVER_NONE);
+    set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
     update_unit_info_label(punit);
   }
   keyboardless_goto_active = FALSE;
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.114
diff -u -r1.114 mapview_common.c
--- client/mapview_common.c     14 May 2004 02:23:42 -0000      1.114
+++ client/mapview_common.c     15 May 2004 07:32:24 -0000
@@ -1692,7 +1692,7 @@
   anim_timer = renew_timer_start(anim_timer, TIMER_USER, TIMER_ACTIVE);
 
   if (punit == get_unit_in_focus() && hover_state != HOVER_NONE) {
-    set_hover_state(NULL, HOVER_NONE);
+    set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
     update_unit_info_label(punit);
   }
 
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.140
diff -u -r1.140 dialogs.c
--- client/gui-gtk/dialogs.c    8 May 2004 00:00:22 -0000       1.140
+++ client/gui-gtk/dialogs.c    15 May 2004 07:32:25 -0000
@@ -164,12 +164,6 @@
   enum tile_special_type what;
 };
 
-struct connect_data {
-  int unit_id;
-  int dest_x, dest_y;
-  enum unit_activity what;
-};
-                    
 /****************************************************************
 ...
 *****************************************************************/
@@ -1308,87 +1302,6 @@
 }
 
 /****************************************************************
-handle buttons in unit connect dialog
-*****************************************************************/
-static void unit_connect_callback(gpointer data)
-{
-  struct connect_data *pdata = data;
-
-  if (find_unit_by_id(pdata->unit_id)) {
-    struct packet_unit_connect req;
-
-    req.activity_type = pdata->what;
-    req.unit_id = pdata->unit_id;
-    req.dest_x = pdata->dest_x;
-    req.dest_y = pdata->dest_y;
-    send_packet_unit_connect(&aconnection, &req);
-  }
-}
-
-/****************************************************************
-...
-*****************************************************************/
-static void unit_connect_close_callback(gpointer data)
-{
-  struct connect_data *connect_datas = data;
-  struct unit *punit = find_unit_by_id(connect_datas[0].unit_id);
-
-  if (punit) {
-    update_unit_info_label(punit);
-  }
-
-  free(connect_datas);
-}
-
-/****************************************************************
-popup dialog which prompts for activity type (unit connect)
-*****************************************************************/
-void popup_unit_connect_dialog(struct unit *punit, int dest_x, int dest_y)
-{
-  /* +1 for cancel button */
-  int j, num = 1;
-  struct button_descr *buttons;
-  enum unit_activity activity;
-  struct connect_data *datas;
-
-  for (activity = ACTIVITY_IDLE + 1; activity < ACTIVITY_LAST; activity++) {
-    if (!can_unit_do_connect(punit, activity)) {
-      continue;
-    }
-    num++;
-  }
-
-  buttons = fc_malloc(sizeof(struct button_descr) * num);
-  datas = fc_malloc(sizeof(struct connect_data) * num);
-
-  j = 0;
-  for (activity = ACTIVITY_IDLE + 1; activity < ACTIVITY_LAST; activity++) {
-    if (!can_unit_do_connect(punit, activity)) {
-      continue;
-    }
-
-    datas[j].unit_id = punit->id;
-    datas[j].dest_x = dest_x;
-    datas[j].dest_y = dest_y;
-    datas[j].what = activity;
-
-    buttons[j].text = get_activity_text(activity);
-    buttons[j].callback = unit_connect_callback;
-    buttons[j].data = &datas[j];
-    buttons[j].sensitive = TRUE;
-    j++;
-  }
-
-  buttons[num - 1].text = _("Cancel");
-  buttons[num - 1].callback = NULL;
-
-  base_popup_message_dialog(top_vbox, _("Connect"),
-                           _("Choose unit activity:"),
-                           unit_connect_close_callback, datas, num,
-                           buttons);
-}
-
-/****************************************************************
 ...
 *****************************************************************/
 static void popup_mes_close(GtkWidget *dialog_shell)
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.218
diff -u -r1.218 mapview.c
--- client/gui-gtk/mapview.c    26 Apr 2004 21:11:19 -0000      1.218
+++ client/gui-gtk/mapview.c    15 May 2004 07:32:25 -0000
@@ -203,7 +203,7 @@
     gtk_set_label(unit_info_label, buffer);
 
     if (hover_unit != punit->id)
-      set_hover_state(NULL, HOVER_NONE);
+      set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
 
     switch (hover_state) {
     case HOVER_NONE:
Index: client/gui-gtk/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/menu.c,v
retrieving revision 1.83
diff -u -r1.83 menu.c
--- client/gui-gtk/menu.c       16 Apr 2004 17:24:54 -0000      1.83
+++ client/gui-gtk/menu.c       15 May 2004 07:32:25 -0000
@@ -118,7 +118,9 @@
   MENU_ORDER_WAKEUP_OTHERS,
   MENU_ORDER_AUTO_SETTLER,   /* shared with AUTO_ATTACK */
   MENU_ORDER_AUTO_EXPLORE,
-  MENU_ORDER_CONNECT,
+  MENU_ORDER_CONNECT_ROAD,
+  MENU_ORDER_CONNECT_RAIL,
+  MENU_ORDER_CONNECT_IRRIGATE,
   MENU_ORDER_PATROL,
   MENU_ORDER_GOTO,
   MENU_ORDER_GOTO_CITY,
@@ -398,8 +400,14 @@
    case MENU_ORDER_AUTO_EXPLORE:
     key_unit_auto_explore();
     break;
-   case MENU_ORDER_CONNECT:
-    key_unit_connect();
+   case MENU_ORDER_CONNECT_ROAD:
+    key_unit_connect(ACTIVITY_ROAD);
+    break;
+   case MENU_ORDER_CONNECT_RAIL:
+    key_unit_connect(ACTIVITY_RAILROAD);
+    break;
+   case MENU_ORDER_CONNECT_IRRIGATE:
+    key_unit_connect(ACTIVITY_IRRIGATE);
     break;
    case MENU_ORDER_PATROL:
     key_unit_patrol();
@@ -722,8 +730,12 @@
        orders_menu_callback,   MENU_ORDER_AUTO_SETTLER                         
        },
   { "/" N_("Orders") "/" N_("Auto E_xplore"),          "x",
        orders_menu_callback,   MENU_ORDER_AUTO_EXPLORE                         
        },
-  { "/" N_("Orders") "/" N_("_Connect"),               "<shift>c",
-       orders_menu_callback,   MENU_ORDER_CONNECT                              
        },
+  {"/" N_("Orders") "/" N_("_Connect") "/" N_("_Road"), "<ctrl>r",
+   orders_menu_callback, MENU_ORDER_CONNECT_ROAD},
+  {"/" N_("Orders") "/" N_("_Connect") "/" N_("Rai_l"), "<ctrl>l",
+   orders_menu_callback, MENU_ORDER_CONNECT_RAIL},
+  {"/" N_("Orders") "/" N_("_Connect") "/" N_("_Irrigate"), "<ctrl>i",
+   orders_menu_callback, MENU_ORDER_CONNECT_IRRIGATE},
   { "/" N_("Orders") "/" N_("Patrol (_Q)"),            "q",
        orders_menu_callback,   MENU_ORDER_PATROL                               
        },
   { "/" N_("Orders") "/" N_("_Go to"),                 "g",
@@ -1162,8 +1174,12 @@
                           can_unit_do_auto(punit));
       menus_set_sensitive("<main>/_Orders/Auto E_xplore",
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
-      menus_set_sensitive("<main>/_Orders/_Connect",
-                          can_unit_do_connect(punit, ACTIVITY_IDLE));
+      menus_set_sensitive("<main>/_Orders/_Connect/_Road",
+                          can_unit_do_connect(punit, ACTIVITY_ROAD));
+      menus_set_sensitive("<main>/_Orders/_Connect/_Rail",
+                          can_unit_do_connect(punit, ACTIVITY_RAILROAD));
+      menus_set_sensitive("<main>/_Orders/_Connect/_Irrigate",
+                          can_unit_do_connect(punit, ACTIVITY_IRRIGATE));
       menus_set_sensitive("<main>/_Orders/Return to nearest city",
                          !(is_air_unit(punit) || is_heli_unit(punit)));
       menus_set_sensitive("<main>/_Orders/_Disband Unit",
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.66
diff -u -r1.66 dialogs.c
--- client/gui-gtk-2.0/dialogs.c        11 May 2004 17:52:25 -0000      1.66
+++ client/gui-gtk-2.0/dialogs.c        15 May 2004 07:32:26 -0000
@@ -119,11 +119,6 @@
 
 static GtkWidget *caravan_dialog;
 
-static int is_showing_unit_connect_dialog = FALSE;
-static int unit_to_use_to_connect;
-static int connect_unit_x;
-static int connect_unit_y;
-
 /**************************************************************************
   Popup a generic dialog to display some generic information.
 **************************************************************************/
@@ -1180,77 +1175,6 @@
 }
 
 /****************************************************************
-handle buttons in unit connect dialog
-*****************************************************************/
-static void unit_connect_callback(GtkWidget *w, gpointer data)
-{
-  struct unit *punit;
-  int activity = GPOINTER_TO_INT(data);
-
-  punit = find_unit_by_id(unit_to_use_to_connect);
-
-  if (punit) {
-    if (activity != ACTIVITY_IDLE) {
-      struct packet_unit_connect req;
-      req.activity_type = activity;
-      req.unit_id = punit->id;
-      req.dest_x = connect_unit_x;
-      req.dest_y = connect_unit_y;
-      send_packet_unit_connect(&aconnection, &req);
-    }
-    else {
-      update_unit_info_label(punit);
-    }
-  }
-}
-
-/****************************************************************
-...
-*****************************************************************/
-static void unit_connect_destroy_callback(GtkWidget *w, gpointer data)
-{
-  is_showing_unit_connect_dialog = FALSE;
-}
-
-/****************************************************************
-popup dialog which prompts for activity type (unit connect)
-*****************************************************************/
-void popup_unit_connect_dialog(struct unit *punit, int dest_x, int dest_y)
-{
-  GtkWidget *shl;
-  int activity;
-
-  if (is_showing_unit_connect_dialog) 
-    return;
-
-  is_showing_unit_connect_dialog = TRUE;
-  unit_to_use_to_connect = punit->id;
-  connect_unit_x = dest_x;
-  connect_unit_y = dest_y;
-
-  shl = message_dialog_start(GTK_WINDOW(toplevel),
-                            _("Connect"),
-                            _("Choose unit activity:"));
-
-  for (activity = ACTIVITY_IDLE + 1; activity < ACTIVITY_LAST; activity++) {
-    if (! can_unit_do_connect (punit, activity)) continue;
-
-    message_dialog_add(shl, get_activity_text(activity),
-                      G_CALLBACK(unit_connect_callback),
-                      GINT_TO_POINTER(activity));
-  }
-
-  message_dialog_add(shl, GTK_STOCK_CANCEL, 
-                    G_CALLBACK(unit_connect_callback),
-                    GINT_TO_POINTER(ACTIVITY_IDLE));
-
-  message_dialog_end(shl);
-
-  g_signal_connect(shl, "destroy",
-                  G_CALLBACK(unit_connect_destroy_callback), NULL);
-}
-
-/****************************************************************
 ...
 *****************************************************************/
 void message_dialog_button_set_sensitive(GtkWidget *shl, int button,
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.123
diff -u -r1.123 mapview.c
--- client/gui-gtk-2.0/mapview.c        26 Apr 2004 21:11:19 -0000      1.123
+++ client/gui-gtk-2.0/mapview.c        15 May 2004 07:32:26 -0000
@@ -191,7 +191,7 @@
 
   if(punit) {
     if (hover_unit != punit->id)
-      set_hover_state(NULL, HOVER_NONE);
+      set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
 
     switch (hover_state) {
     case HOVER_NONE:
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.30
diff -u -r1.30 menu.c
--- client/gui-gtk-2.0/menu.c   11 May 2004 17:52:25 -0000      1.30
+++ client/gui-gtk-2.0/menu.c   15 May 2004 07:32:26 -0000
@@ -124,7 +124,9 @@
   MENU_ORDER_WAKEUP_OTHERS,
   MENU_ORDER_AUTO_SETTLER,   /* shared with AUTO_ATTACK */
   MENU_ORDER_AUTO_EXPLORE,
-  MENU_ORDER_CONNECT,
+  MENU_ORDER_CONNECT_ROAD,
+  MENU_ORDER_CONNECT_RAIL,
+  MENU_ORDER_CONNECT_IRRIGATE,
   MENU_ORDER_PATROL,
   MENU_ORDER_GOTO,
   MENU_ORDER_GOTO_CITY,
@@ -420,8 +422,14 @@
    case MENU_ORDER_AUTO_EXPLORE:
     key_unit_auto_explore();
     break;
-   case MENU_ORDER_CONNECT:
-    key_unit_connect();
+   case MENU_ORDER_CONNECT_ROAD:
+    key_unit_connect(ACTIVITY_ROAD);
+    break;
+   case MENU_ORDER_CONNECT_RAIL:
+    key_unit_connect(ACTIVITY_RAILROAD);
+    break;
+   case MENU_ORDER_CONNECT_IRRIGATE:
+    key_unit_connect(ACTIVITY_IRRIGATE);
     break;
    case MENU_ORDER_PATROL:
     key_unit_patrol();
@@ -755,8 +763,12 @@
        orders_menu_callback,   MENU_ORDER_AUTO_SETTLER                         
        },
   { "/" N_("Orders") "/" N_("Auto E_xplore"),          "x",
        orders_menu_callback,   MENU_ORDER_AUTO_EXPLORE                         
        },
-  { "/" N_("Orders") "/" N_("_Connect"),               "<shift>c",
-       orders_menu_callback,   MENU_ORDER_CONNECT                              
        },
+  {"/" N_("Orders") "/" N_("_Connect") "/" N_("_Road"), "<ctrl>r",
+   orders_menu_callback, MENU_ORDER_CONNECT_ROAD},
+  {"/" N_("Orders") "/" N_("_Connect") "/" N_("Rai_l"), "<ctrl>l",
+   orders_menu_callback, MENU_ORDER_CONNECT_RAIL},
+  {"/" N_("Orders") "/" N_("_Connect") "/" N_("_Irrigate"), "<ctrl>i",
+   orders_menu_callback, MENU_ORDER_CONNECT_IRRIGATE},
   { "/" N_("Orders") "/" N_("Patrol (_Q)"),            "q",
        orders_menu_callback,   MENU_ORDER_PATROL                               
        },
   { "/" N_("Orders") "/" N_("_Go to"),                 "g",
@@ -1239,8 +1251,12 @@
                           can_unit_do_auto(punit));
       menus_set_sensitive("<main>/_Orders/Auto E_xplore",
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
-      menus_set_sensitive("<main>/_Orders/_Connect",
-                          can_unit_do_connect(punit, ACTIVITY_IDLE));
+      menus_set_sensitive("<main>/_Orders/_Connect/_Road",
+                          can_unit_do_connect(punit, ACTIVITY_ROAD));
+      menus_set_sensitive("<main>/_Orders/_Connect/_Rail",
+                          can_unit_do_connect(punit, ACTIVITY_RAILROAD));
+      menus_set_sensitive("<main>/_Orders/_Connect/_Irrigate",
+                          can_unit_do_connect(punit, ACTIVITY_IRRIGATE));
       menus_set_sensitive("<main>/_Orders/Return to nearest city",
                          !(is_air_unit(punit) || is_heli_unit(punit)));
       menus_set_sensitive("<main>/_Orders/Diplomat\\/Spy Actions",
Index: client/gui-stub/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/dialogs.c,v
retrieving revision 1.12
diff -u -r1.12 dialogs.c
--- client/gui-stub/dialogs.c   8 May 2004 00:00:22 -0000       1.12
+++ client/gui-stub/dialogs.c   15 May 2004 07:32:26 -0000
@@ -183,15 +183,6 @@
 }
 
 /**************************************************************************
-  Popup a dialog asking the unit how they want to "connect" their
-  location to the destination.
-**************************************************************************/
-void popup_unit_connect_dialog(struct unit *punit, int dest_x, int dest_y)
-{
-  /* PORTME */
-}
-
-/**************************************************************************
   This function is called when the client disconnects or the game is
   over.  It should close all dialog windows for that game.
 **************************************************************************/
Index: client/gui-win32/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/menu.c,v
retrieving revision 1.19
diff -u -r1.19 menu.c
--- client/gui-win32/menu.c     2 May 2004 08:00:50 -0000       1.19
+++ client/gui-win32/menu.c     15 May 2004 07:32:26 -0000
@@ -118,7 +118,9 @@
   IDM_ORDERS_AUTOSETTLER,
   IDM_ORDERS_AUTOATTACK,
   IDM_ORDERS_AUTOEXPLORE,
-  IDM_ORDERS_CONNECT,
+  IDM_ORDERS_CONNECT_ROAD,
+  IDM_ORDERS_CONNECT_RAIL,
+  IDM_ORDERS_CONNECT_IRRIGATE,
   IDM_ORDERS_GOTO,
   IDM_ORDERS_AIRLIFT,
   IDM_ORDERS_RETURN,
@@ -340,7 +342,9 @@
   {N_("Auto Settler") "\tA",IDM_ORDERS_AUTOSETTLER},
   {N_("Auto Attack") "\tShift+A",IDM_ORDERS_AUTOATTACK},
   {N_("Auto E_xplore") "\tX",IDM_ORDERS_AUTOEXPLORE},
-  {N_("_Connect") "\tShift+C",IDM_ORDERS_CONNECT},
+  {N_("Connect/_road") "\tCtl+R", IDM_ORDERS_CONNECT_ROAD},
+  {N_("Connect/rai_l") "\tCtl+L", IDM_ORDERS_CONNECT_RAIL},
+  {N_("Connect/_irrigate") "\tCtl+I", IDM_ORDERS_CONNECT_IRRIGATE},
   {N_("_Go to") "\tG",IDM_ORDERS_GOTO},
   {N_("Go/Airlift to City") "\tL",IDM_ORDERS_AIRLIFT},
   {N_("Return to nearest city") "\tShift+G", IDM_ORDERS_RETURN},
@@ -673,9 +677,14 @@
       if(get_unit_in_focus())
        request_new_unit_activity(get_unit_in_focus(), road_activity);
       break;
-    case IDM_ORDERS_CONNECT:
-      if(get_unit_in_focus())
-       request_unit_connect();
+    case IDM_ORDERS_CONNECT_ROAD:
+      request_unit_connect(ACTIVITY_ROAD);
+      break;
+    case IDM_ORDERS_CONNECT_RAIL:
+      request_unit_connect(ACTIVITY_RAILROAD);
+      break;
+    case IDM_ORDERS_CONNECT_IRRIGATE:
+      request_unit_connect(ACTIVITY_IRRIGATE);
       break;
     case IDM_ORDERS_POLLUTION:
       if(can_unit_paradrop(get_unit_in_focus()))
@@ -936,8 +945,12 @@
        my_enable_menu(menu,IDM_ORDERS_ROAD,
                       can_unit_do_activity(punit, ACTIVITY_ROAD) ||
                       can_unit_do_activity(punit, ACTIVITY_RAILROAD));
-       my_enable_menu(menu,IDM_ORDERS_CONNECT,
-                      can_unit_do_connect(punit, ACTIVITY_IDLE));
+       my_enable_menu(menu,IDM_ORDERS_CONNECT_ROAD,
+                      can_unit_do_connect(punit, ACTIVITY_ROAD));
+       my_enable_menu(menu,IDM_ORDERS_CONNECT_RAIL,
+                      can_unit_do_connect(punit, ACTIVITY_RAILROAD));
+       my_enable_menu(menu,IDM_ORDERS_CONNECT_IRRIGATE,
+                      can_unit_do_connect(punit, ACTIVITY_IRRIGATE));
        my_enable_menu(menu,IDM_ORDERS_POLLUTION,
                       can_unit_do_activity(punit, ACTIVITY_POLLUTION) ||
                       can_unit_paradrop(punit));
Index: client/gui-xaw/actions.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/actions.c,v
retrieving revision 1.19
diff -u -r1.19 actions.c
--- client/gui-xaw/actions.c    1 Apr 2004 23:46:25 -0000       1.19
+++ client/gui-xaw/actions.c    15 May 2004 07:32:26 -0000
@@ -369,10 +369,22 @@
     key_unit_build_wonder();
 }
 
-static void xaw_key_unit_connect(Widget w, XEvent *event, String *argv, 
Cardinal *argc)
+static void xaw_key_unit_connect_road(Widget w, XEvent *event, String *argv, 
Cardinal *argc)
 {
-  if(is_menu_item_active(MENU_ORDER, MENU_ORDER_CONNECT))
-    key_unit_connect();
+  if(is_menu_item_active(MENU_ORDER, MENU_ORDER_CONNECT_ROAD))
+    key_unit_connect(ACTIVITY_ROAD);
+}
+
+static void xaw_key_unit_connect_rail(Widget w, XEvent *event, String *argv, 
Cardinal *argc)
+{
+  if(is_menu_item_active(MENU_ORDER, MENU_ORDER_CONNECT_RAIL))
+    key_unit_connect(ACTIVITY_RAILROAD);
+}
+
+static void xaw_key_unit_connect_irrigate(Widget w, XEvent *event, String 
*argv, Cardinal *argc)
+{
+  if(is_menu_item_active(MENU_ORDER, MENU_ORDER_CONNECT_IRRIGATE))
+    key_unit_connect(ACTIVITY_IRRIGATE);
 }
 
 static void xaw_key_unit_diplomat_spy_action(Widget w, XEvent *event, String 
*argv, Cardinal *argc)
@@ -656,7 +668,9 @@
   { "key-unit-build-city", xaw_key_unit_build_city },
   { "key-unit-build-city-or-wonder", xaw_key_unit_build_city_or_wonder },
   { "key-unit-build-wonder", xaw_key_unit_build_wonder },
-  { "key-unit-connect", xaw_key_unit_connect },
+  { "key-unit-connect-road", xaw_key_unit_connect_road },
+  { "key-unit-connect-rail", xaw_key_unit_connect_rail },
+  { "key-unit-connect-irrigate", xaw_key_unit_connect_irrigate },
   { "key-unit-diplomat-spy-action", xaw_key_unit_diplomat_spy_action },
   { "key-unit-disband", xaw_key_unit_disband },
   { "key-unit-done", xaw_key_unit_done },
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.96
diff -u -r1.96 dialogs.c
--- client/gui-xaw/dialogs.c    13 May 2004 18:14:22 -0000      1.96
+++ client/gui-xaw/dialogs.c    15 May 2004 07:32:27 -0000
@@ -175,11 +175,6 @@
 
 static Widget caravan_dialog;
 
-static int is_showing_unit_connect_dialog = FALSE;
-static int unit_to_use_to_connect;
-static int connect_unit_x;
-static int connect_unit_y;
-
 /****************************************************************
 ...
 *****************************************************************/
@@ -1377,87 +1372,6 @@
 }
 
 /****************************************************************
-common code for all buttons in unit connect dialog
-*****************************************************************/
-static void unit_connect_callback (Widget w, XtPointer client_data, 
-                                  XtPointer call_data)
-{
-  struct unit *punit;
-  int activity = XTPOINTER_TO_INT(client_data);
-
-  if (!is_showing_unit_connect_dialog) {
-    destroy_message_dialog(w);
-    return;
-  }
-
-  punit = find_unit_by_id(unit_to_use_to_connect);
-
-  if (punit) {
-    if (activity != ACTIVITY_IDLE) {
-      struct packet_unit_connect req;
-      req.activity_type = activity;
-      req.unit_id = punit->id;
-      req.dest_x = connect_unit_x;
-      req.dest_y = connect_unit_y;
-      send_packet_unit_connect(&aconnection, &req);
-    }
-    else {
-      update_unit_info_label(punit);
-    }
-  }
-
-  destroy_message_dialog(w);
-  is_showing_unit_connect_dialog = FALSE;
-}
-
-/****************************************************************
-popup dialog which prompts for activity type (unit connect)
-*****************************************************************/
-void popup_unit_connect_dialog(struct unit *punit, int dest_x, int dest_y)
-{
-  Widget shell, form, dlabel, button, prev;
-  int activity;
-
-  if (is_showing_unit_connect_dialog)
-    return;
-
-  is_showing_unit_connect_dialog = TRUE;
-  unit_to_use_to_connect = punit->id;
-  connect_unit_x = dest_x;
-  connect_unit_y = dest_y;
-
-  XtSetSensitive (toplevel, FALSE);
-
-  shell = I_T(XtCreatePopupShell("unitconnectdialog", 
transientShellWidgetClass,
-                                toplevel, NULL, 0));
-  form = XtVaCreateManagedWidget ("form", formWidgetClass, shell, NULL);
-  dlabel = I_L(XtVaCreateManagedWidget("dlabel", labelWidgetClass, form, 
NULL));
-
-  prev = dlabel;
-  for (activity = ACTIVITY_IDLE + 1; activity < ACTIVITY_LAST; activity++) {
-    if (! can_unit_do_connect (punit, activity)) continue;
-
-    button =
-      XtVaCreateManagedWidget ("button", commandWidgetClass, form,
-                              XtNfromVert, prev,
-                              XtNlabel,
-                                (XtArgVal)(get_activity_text (activity)),
-                              NULL);
-    XtAddCallback(button, XtNcallback, unit_connect_callback,
-                 INT_TO_XTPOINTER(activity));
-    prev = button;
-  }
-  button =
-    I_L(XtVaCreateManagedWidget("closebutton", commandWidgetClass, form,
-                               XtNfromVert, prev,
-                               NULL));
-  XtAddCallback (button, XtNcallback, unit_connect_callback, ACTIVITY_IDLE);
-
-  xaw_set_relative_position (toplevel, shell, 10, 0);
-  XtPopup (shell, XtGrabNone);
-}
-
-/****************************************************************
   Parameters after named parameters should be in triplets:
   - callback, callback_data, fixed_width 
 *****************************************************************/
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.171
diff -u -r1.171 mapview.c
--- client/gui-xaw/mapview.c    23 Apr 2004 22:58:06 -0000      1.171
+++ client/gui-xaw/mapview.c    15 May 2004 07:32:28 -0000
@@ -217,7 +217,7 @@
     xaw_set_label(unit_info_label, buffer);
 
     if (hover_unit != punit->id)
-      set_hover_state(NULL, HOVER_NONE);
+      set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
 
     switch (hover_state) {
     case HOVER_NONE:
Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.62
diff -u -r1.62 menu.c
--- client/gui-xaw/menu.c       13 May 2004 18:14:22 -0000      1.62
+++ client/gui-xaw/menu.c       15 May 2004 07:32:28 -0000
@@ -185,7 +185,9 @@
     { { N_("Auto Settler"), 0         },     "a", MENU_ORDER_AUTO_SETTLER, 0 },
     { { N_("Auto Attack"), 0          },     "a", MENU_ORDER_AUTO_ATTACK, 0 },
     { { N_("Auto Explore"), 0         },     "x", MENU_ORDER_AUTO_EXPLORE, 0 },
-    { { N_("Connect"), 0              },     "C", MENU_ORDER_CONNECT, 0 },
+    { { N_("Connect/Road"), 0         }, "<ctl>r", MENU_ORDER_CONNECT_ROAD, 0 
},
+    { { N_("Connect/Rail"), 0         }, "<ctl>l", MENU_ORDER_CONNECT_RAIL, 0 
},
+    { { N_("Connect/Irrigation"), 0   }, "<ctl>i", 
MENU_ORDER_CONNECT_IRRIGATE, 0 },
     { { N_("Patrol"), 0               },     "q", MENU_ORDER_PATROL, 0 },
     { { N_("Go to"), 0                },     "g", MENU_ORDER_GOTO, 0 },
     { { N_("Go/Airlift to City"), 0   },     "l", MENU_ORDER_GOTO_CITY, 0 },
@@ -376,8 +378,12 @@
                           !unit_flag(punit, F_UNDISBANDABLE));
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_AUTO_EXPLORE, 
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
-      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_CONNECT, 
-                          can_unit_do_connect(punit, ACTIVITY_IDLE));
+      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_CONNECT_ROAD,
+                          can_unit_do_connect(punit, ACTIVITY_ROAD));
+      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_CONNECT_RAIL,
+                          can_unit_do_connect(punit, ACTIVITY_RAILROAD));
+      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_CONNECT_IRRIGATE,
+                          can_unit_do_connect(punit, ACTIVITY_IRRIGATE));
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_GOTO_CITY,
                           any_cities);
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_BUILD_WONDER,
@@ -660,8 +666,14 @@
   case MENU_ORDER_AUTO_EXPLORE:
     key_unit_auto_explore();
     break;
-  case MENU_ORDER_CONNECT:
-    key_unit_connect();
+  case MENU_ORDER_CONNECT_ROAD:
+    key_unit_connect(ACTIVITY_ROAD);
+    break;
+  case MENU_ORDER_CONNECT_RAIL:
+    key_unit_connect(ACTIVITY_RAILROAD);
+    break;
+  case MENU_ORDER_CONNECT_IRRIGATE:
+    key_unit_connect(ACTIVITY_IRRIGATE);
     break;
   case MENU_ORDER_PATROL:
     key_unit_patrol();
Index: client/gui-xaw/menu.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.h,v
retrieving revision 1.17
diff -u -r1.17 menu.h
--- client/gui-xaw/menu.h       16 Apr 2004 17:24:54 -0000      1.17
+++ client/gui-xaw/menu.h       15 May 2004 07:32:28 -0000
@@ -87,7 +87,9 @@
   MENU_ORDER_AUTO_SETTLER,
   MENU_ORDER_AUTO_ATTACK,
   MENU_ORDER_AUTO_EXPLORE,
-  MENU_ORDER_CONNECT,
+  MENU_ORDER_CONNECT_ROAD,
+  MENU_ORDER_CONNECT_RAIL,
+  MENU_ORDER_CONNECT_IRRIGATE,
   MENU_ORDER_PATROL,
   MENU_ORDER_GOTO,
   MENU_ORDER_GOTO_CITY,
Index: client/include/dialogs_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/dialogs_g.h,v
retrieving revision 1.16
diff -u -r1.16 dialogs_g.h
--- client/include/dialogs_g.h  8 May 2004 00:00:23 -0000       1.16
+++ client/include/dialogs_g.h  15 May 2004 07:32:28 -0000
@@ -49,7 +49,6 @@
 void popup_sabotage_dialog(struct city *pcity);
 void popup_pillage_dialog(struct unit *punit,
                          enum tile_special_type may_pillage);
-void popup_unit_connect_dialog (struct unit *punit, int dest_x, int dest_y);
 
 void popdown_all_game_dialogs(void);
 
Index: data/Freeciv
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/Freeciv,v
retrieving revision 1.212
diff -u -r1.212 Freeciv
--- data/Freeciv        22 Nov 2003 23:34:55 -0000      1.212
+++ data/Freeciv        15 May 2004 07:32:28 -0000
@@ -2833,7 +2833,9 @@
    Ctrl<Key>b:        key-map-borders-toggle()         \n\
    Ctrl<Key>n:        key-city-names-toggle()          \n\
    Ctrl<Key>p:        key-city-productions-toggle()    \n\
-   Shift<Key>c:       key-unit-connect()               \n\
+   Ctrl<Key>r:        key-unit-connect-road()          \n\
+   Ctrl<Key>l:        key-unit-connect-rail()          \n\
+   Ctrl<Key>i:        key-unit-connect-irrigate()      \n\
    Shift<Key>d:       key-unit-disband()               \n\
    Shift<Key>f:       key-open-find-city()             \n\
    Shift<Key>l:       key-open-worklists()             \n\
@@ -2910,7 +2912,9 @@
    Ctrl<Key>g:        key-map-grid-toggle()            \n\
    Ctrl<Key>n:        key-city-names-toggle()          \n\
    Ctrl<Key>p:        key-city-productions-toggle()    \n\
-   Shift<Key>c:       key-unit-connect()               \n\
+   Ctrl<Key>r:        key-unit-connect-road()          \n\
+   Ctrl<Key>l:        key-unit-connect-rail()          \n\
+   Ctrl<Key>i:        key-unit-connect-irrigate()      \n\
    Shift<Key>d:       key-unit-disband()               \n\
    Shift<Key>f:       key-open-find-city()             \n\
    Shift<Key>l:       key-open-worklists()             \n\

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#8739) menu-based connect, Jason Short <=