Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7393) show orders in the client
Home

[Freeciv-Dev] (PR#7393) show orders in the client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7393) show orders in the client
From: "Jason Dorje Short" <jdorje@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 7 Feb 2004 12:21:16 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch actually draws the orders/goto route in the client when the 
user middle-clicks on a unit with orders.

Supported clients: GTK, GTK2, XAW.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.74
diff -u -r1.74 mapview_common.c
--- client/mapview_common.c     2004/02/03 20:16:07     1.74
+++ client/mapview_common.c     2004/02/07 20:20:17
@@ -1194,6 +1194,49 @@
   }
 }
 
+/****************************************************************************
+  Draw the goto route for the unit.  Return TRUE if anything is drawn.
+
+  This duplicates drawing code that is run during the hover state.
+****************************************************************************/
+bool show_unit_orders(struct unit *punit)
+{
+  if (punit && unit_has_orders(punit)) {
+    int unit_x = punit->x, unit_y = punit->y, i;
+
+    for (i = 0; i < punit->orders.length; i++) {
+      int index = (punit->orders.index + i) % punit->orders.length;
+      struct unit_order *order;
+
+      if (punit->orders.index + i >= punit->orders.length
+         && !punit->orders.repeat) {
+       break;
+      }
+
+      order = &punit->orders.list[index];
+
+      switch (order->order) {
+      case ORDER_MOVE:
+       draw_segment(unit_x, unit_y, order->dir);
+       if (!MAPSTEP(unit_x, unit_y, unit_x, unit_y, order->dir)) {
+         /* This shouldn't happen unless the server gives us invalid
+          * data.  To avoid disaster we need to break out of the
+          * switch and the enclosing for loop. */
+         assert(0);
+         i = punit->orders.length;
+       }
+       break;
+      default:
+       /* TODO: graphics for other orders. */
+       break;
+      }
+    }
+    return TRUE;
+  } else {
+    return FALSE;
+  }
+}
+
 /**************************************************************************
   Remove the line from src_x, src_y in the given direction, and redraw
   the change if necessary.
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.40
diff -u -r1.40 mapview_common.h
--- client/mapview_common.h     2004/02/03 20:16:07     1.40
+++ client/mapview_common.h     2004/02/07 20:20:17
@@ -177,6 +177,7 @@
 void update_map_canvas_visible(void);
 
 void show_city_descriptions(void);
+bool show_unit_orders(struct unit *punit);
 
 void undraw_segment(int src_x, int src_y, int dir);
 
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.95
diff -u -r1.95 mapctrl.c
--- client/gui-gtk/mapctrl.c    2004/01/23 21:19:23     1.95
+++ client/gui-gtk/mapctrl.c    2004/02/07 20:20:17
@@ -74,12 +74,16 @@
   int i;
   static struct t_popup_pos popup_pos;
   struct unit *punit;
+  bool is_orders;
 
   if(tile_get_known(xtile, ytile) >= TILE_KNOWN_FOGGED) {
     p=gtk_window_new(GTK_WINDOW_POPUP);
     gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(xtile, 
ytile)));
-    
+
     punit = find_visible_unit(map_get_tile(xtile, ytile));
+
+    is_orders = show_unit_orders(punit);
+
     if (punit && is_goto_dest_set(punit))  {
       cross_head->x = goto_dest_x(punit);
       cross_head->y = goto_dest_y(punit);
@@ -96,7 +100,7 @@
     }
     gtk_signal_connect(GTK_OBJECT(p),"destroy",
                       GTK_SIGNAL_FUNC(popupinfo_popdown_callback),
-                      cross_list);
+                      GINT_TO_POINTER(is_orders));
 
     popup_pos.xroot = event->x_root;
     popup_pos.yroot = event->y_root;
@@ -120,11 +124,12 @@
 **************************************************************************/
 void popupinfo_popdown_callback(GtkWidget *w, gpointer data)
 {
-  struct map_position *cross_list=(struct map_position *)data;
+  bool full = GPOINTER_TO_INT(data);
 
-  while (cross_list->x >= 0) {
-    refresh_tile_mapcanvas(cross_list->x, cross_list->y, TRUE);
-    cross_list++;
+  if (full) {
+    update_map_canvas_visible();
+  } else {
+    dirty_all();
   }
 }
 
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.191
diff -u -r1.191 mapview.c
--- client/gui-gtk/mapview.c    2004/02/05 20:20:27     1.191
+++ client/gui-gtk/mapview.c    2004/02/07 20:20:17
@@ -1229,8 +1229,6 @@
 **************************************************************************/
 void draw_segment(int src_x, int src_y, int dir)
 {
-  assert(get_drawn(src_x, src_y, dir) > 0);
-
   if (is_isometric) {
     really_draw_segment(src_x, src_y, dir, TRUE, FALSE);
   } else {
Index: client/gui-gtk-2.0/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.c,v
retrieving revision 1.37
diff -u -r1.37 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        2004/01/23 21:19:23     1.37
+++ client/gui-gtk-2.0/mapctrl.c        2004/02/07 20:20:17
@@ -71,6 +71,7 @@
   int i;
   int popx, popy;
   struct unit *punit;
+  bool is_orders;
 
   if(tile_get_known(xtile, ytile) >= TILE_KNOWN_FOGGED) {
     p=gtk_window_new(GTK_WINDOW_POPUP);
@@ -79,6 +80,9 @@
     gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(xtile, 
ytile)));
     
     punit = find_visible_unit(map_get_tile(xtile, ytile));
+
+    is_orders = show_unit_orders(punit);
+
     if (punit && is_goto_dest_set(punit)) {
       cross_head->x = goto_dest_x(punit);
       cross_head->y = goto_dest_y(punit);
@@ -94,7 +98,7 @@
     }
     g_signal_connect(p, "destroy",
                     G_CALLBACK(popupinfo_popdown_callback),
-                    cross_list);
+                    GINT_TO_POINTER(is_orders));
 
     /* displace popup so as not to obscure it by the mouse cursor */
     popx= event->x_root + 16;
@@ -117,11 +121,12 @@
 **************************************************************************/
 void popupinfo_popdown_callback(GtkWidget *w, gpointer data)
 {
-  struct map_position *cross_list=(struct map_position *)data;
+  bool full = GPOINTER_TO_INT(data);
 
-  while (cross_list->x >= 0) {
-    refresh_tile_mapcanvas(cross_list->x, cross_list->y, TRUE);
-    cross_list++;
+  if (full) {
+    update_map_canvas_visible();
+  } else {
+    dirty_all();
   }
 }
 
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.91
diff -u -r1.91 mapview.c
--- client/gui-gtk-2.0/mapview.c        2004/02/05 20:20:27     1.91
+++ client/gui-gtk-2.0/mapview.c        2004/02/07 20:20:17
@@ -1306,8 +1306,6 @@
 **************************************************************************/
 void draw_segment(int src_x, int src_y, int dir)
 {
-  assert(get_drawn(src_x, src_y, dir) > 0);
-
   if (is_isometric) {
     really_draw_segment(src_x, src_y, dir, TRUE, FALSE);
   } else {
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.82
diff -u -r1.82 mapctrl.c
--- client/gui-xaw/mapctrl.c    2004/01/23 21:19:23     1.82
+++ client/gui-xaw/mapctrl.c    2004/02/07 20:20:18
@@ -105,6 +105,7 @@
   int i;
   struct unit *punit;
   char *content;
+  static bool is_orders;
   
   if (tile_get_known(xtile, ytile)>=TILE_KNOWN_FOGGED) {
     Widget p=XtCreatePopupShell("popupinfo", simpleMenuWidgetClass,
@@ -128,6 +129,7 @@
     }
 
     punit = find_visible_unit(map_get_tile(xtile, ytile));
+    is_orders = show_unit_orders(punit);
     if (punit && is_goto_dest_set(punit)) {
       cross_head->x = goto_dest_x(punit);
       cross_head->y = goto_dest_y(punit);
@@ -162,7 +164,7 @@
       put_cross_overlay_tile(cross_list[i].x,cross_list[i].y);
     }
     XtAddCallback(p,XtNpopdownCallback,popupinfo_popdown_callback,
-                 (XtPointer)cross_list);
+                 (XtPointer)&is_orders);
 
     XtPopupSpringLoaded(p);
   }
@@ -175,11 +177,12 @@
 void popupinfo_popdown_callback(Widget w, XtPointer client_data,
         XtPointer call_data)
 {
-  struct map_position *cross_list=(struct map_position *)client_data;
+  bool *full = client_data;
 
-  while (cross_list->x >= 0) {
-    refresh_tile_mapcanvas(cross_list->x, cross_list->y, TRUE);
-    cross_list++;
+  if (*full) {
+    update_map_canvas_visible();
+  } else {
+    dirty_all();
   }
 
   XtDestroyWidget(w);
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.155
diff -u -r1.155 mapview.c
--- client/gui-xaw/mapview.c    2004/02/03 20:16:08     1.155
+++ client/gui-xaw/mapview.c    2004/02/07 20:20:19
@@ -1054,8 +1054,6 @@
 {
   int dest_x, dest_y, is_real;
 
-  assert(get_drawn(src_x, src_y, dir) > 0);
-
   is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
   assert(is_real);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7393) show orders in the client, Jason Dorje Short <=