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

[Freeciv-Dev] (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] (PR#8739) menu-based connect
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 May 2004 11:18:46 -0700
Reply-to: rt@xxxxxxxxxxx

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

Currently the user chooses connect from the menu.  This enters the 
connect hover state.  When the user chooses a location the connect 
dialog pops up.  Then the user selects the type of connect and the 
request is sent to the server.

This is bad for several reasons:

- Popups are bad, and this one is entirely unnecessary.  We can decrease 
the amount of user work needed with little added cost.

- To have connect show the path (e.g., connect as orders PR#7282) we 
have to know the activity before entering the hover state.

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.

For now only the gtk2 client is supported.  Obviously this will have to 
change.

However there is one issue: how does the GUI know which activities to 
support?  Currently I just hard-code the three possible activities 
(fortress is ignored).  But it would also be possible to have this list 
be in control.h:

   possible_activities = {ACTIVITY_ROAD, ACTIVITY_RAIL,
                          ACTIVITY_IRRIGATE, ACTIVITY_LAST};

and generate the menu at runtime like Vasco does with the revolution 
submenu.

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    14 May 2004 18:02:35 -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    14 May 2004 18:02:35 -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     14 May 2004 18:02:35 -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     14 May 2004 18:02:35 -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-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        14 May 2004 18:02:36 -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        14 May 2004 18:02:36 -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   14 May 2004 18:02:36 -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/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  14 May 2004 18:02:36 -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);
 

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