Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] PATCH: Tile markers v2
Home

[Freeciv-Dev] PATCH: Tile markers v2

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: Tile markers v2
From: Teemu Kurppa <tkurppa@xxxxxxxxxx>
Date: Sat, 15 Dec 2001 12:23:03 +0200

This is tile markers patch v2, it adds view toggle for tile markers to
menu. 

Teemu Kurppa
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/README freeciv/README
--- freeciv-cvs/README  Sat May 19 17:59:02 2001
+++ freeciv/README      Sat Dec 15 11:25:13 2001
@@ -1,4 +1,4 @@
-====================
+===================
 Freeciv Version 1.12
 ====================
 
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/civclient.c 
freeciv/client/civclient.c
--- freeciv-cvs/client/civclient.c      Fri Oct 26 10:13:55 2001
+++ freeciv/client/civclient.c  Sat Dec 15 12:15:26 2001
@@ -50,6 +50,7 @@
 #include "gui_main_g.h"
 #include "helpdata.h"          /* boot_help_texts() */
 #include "mapctrl_g.h"
+#include "mapview_common.h"
 #include "mapview_g.h"
 #include "menu_g.h"
 #include "messagewin_g.h"
@@ -176,6 +177,7 @@
   init_our_capability();
   game_init();
   attribute_init();
+  coords_list_init(&marked_tiles);
 
   /* This seed is not saved anywhere; randoms in the client should
      have cosmetic effects only (eg city name suggestions).  --dwp */
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/control.c 
freeciv/client/control.c
--- freeciv-cvs/client/control.c        Thu Dec 13 22:05:32 2001
+++ freeciv/client/control.c    Sat Dec 15 12:04:41 2001
@@ -878,6 +878,18 @@
 }
 
 /**************************************************************************
+ Toggle display of city names
+**************************************************************************/
+void request_toggle_tile_markers(void)
+{
+  if (get_client_state() != CLIENT_GAME_RUNNING_STATE)
+    return;
+
+  draw_tile_markers ^= 1;
+  update_map_canvas_visible();
+}
+
+/**************************************************************************
  Toggle display of terrain
 **************************************************************************/
 void request_toggle_terrain(void)
@@ -1354,6 +1366,14 @@
 void key_city_productions_toggle(void)
 {
   request_toggle_city_productions();
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void key_tile_markers_toggle(void)
+{
+  request_toggle_tile_markers();
 }
 
 /**************************************************************************
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/control.h 
freeciv/client/control.h
--- freeciv-cvs/client/control.h        Thu Oct 18 18:12:47 2001
+++ freeciv/client/control.h    Sat Dec 15 12:02:10 2001
@@ -99,6 +99,7 @@
 void key_cancel_action(void);
 void key_city_names_toggle(void);
 void key_city_productions_toggle(void);
+void key_tile_markers_toggle(void);
 void key_terrain_toggle(void);
 void key_coastline_toggle(void);
 void key_roads_rails_toggle(void);
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/gui-gtk/gui_main.c 
freeciv/client/gui-gtk/gui_main.c
--- freeciv-cvs/client/gui-gtk/gui_main.c       Tue Oct  9 21:56:59 2001
+++ freeciv/client/gui-gtk/gui_main.c   Sat Dec 15 12:15:26 2001
@@ -253,7 +253,7 @@
     case GDK_KP_Enter:         key_end_turn();                 break;
 
     case GDK_Escape:           key_cancel_action();            break;
-
+      
     case GDK_t:                        key_city_workers(widget,event); break;
     default:                                                   return FALSE;
     }
@@ -301,6 +301,8 @@
     case GDK_Escape:           key_cancel_action();            break;
 
     case GDK_t:                        key_city_workers(widget,event); break;
+      
+    case GDK_asterisk:          key_mark_tile();                break;
     default:                                                   return FALSE;
     }
   }
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/gui-gtk/mapctrl.c 
freeciv/client/gui-gtk/mapctrl.c
--- freeciv-cvs/client/gui-gtk/mapctrl.c        Thu Dec 13 22:05:35 2001
+++ freeciv/client/gui-gtk/mapctrl.c    Sat Dec 15 12:15:26 2001
@@ -23,7 +23,9 @@
 
 #include "fcintl.h"
 #include "game.h"
+#include "log.h"
 #include "map.h"
+#include "mem.h" 
 #include "player.h"
 #include "support.h"
 #include "unit.h"
@@ -467,6 +469,36 @@
   return TRUE;
 }
 
+/**************************************************************************
+  Puts marker on tile.
+**************************************************************************/
+gint key_mark_tile() {
+  int x,y;
+  struct coords *pcoords;
+  
+  if(get_client_state()!=CLIENT_GAME_RUNNING_STATE)
+    return TRUE;
+  
+  /* Only these two lines are gui-specific.
+     Other code can be moved to common client code. TeeK */
+  gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
+  get_map_xy(x, y, &x, &y);
+  
+  if( (pcoords = coords_list_find(&marked_tiles, x, y)) ) {
+    coords_list_unlink(&marked_tiles, pcoords);
+    free(pcoords);
+    freelog(LOG_DEBUG, "Removed marker from tile (%d, %d)", x, y);
+  } else {
+    pcoords = fc_malloc(sizeof(struct coords));
+    pcoords->x = x;
+    pcoords->y = y;    
+    coords_list_insert(&marked_tiles, pcoords);
+    freelog(LOG_DEBUG, "Put marker on tile (%d, %d)", x, y);
+  }
+
+  update_map_canvas(x,y,1,1,1);
+  return TRUE;
+}
 
 /**************************************************************************
 ...
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/gui-gtk/mapctrl.h 
freeciv/client/gui-gtk/mapctrl.h
--- freeciv-cvs/client/gui-gtk/mapctrl.h        Mon Jan 29 20:55:28 2001
+++ freeciv/client/gui-gtk/mapctrl.h    Sat Dec 15 12:15:26 2001
@@ -20,6 +20,7 @@
 struct unit;
 
 gint key_city_workers(GtkWidget *w, GdkEventKey *ev);
+gint key_mark_tile();
 gint adjust_workers(GtkWidget *widget, GdkEventButton *ev);
 
 gint butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev);
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/gui-gtk/mapview.c 
freeciv/client/gui-gtk/mapview.c
--- freeciv-cvs/client/gui-gtk/mapview.c        Thu Dec 13 22:05:35 2001
+++ freeciv/client/gui-gtk/mapview.c    Sat Dec 15 12:16:18 2001
@@ -1138,6 +1138,27 @@
   }
 }
 
+void draw_mark_on_tile(GdkDrawable *pm, int x, int y, 
+                      int canvas_x, int canvas_y) {  
+  int dx = NORMAL_TILE_WIDTH / 4;
+  int dy = NORMAL_TILE_HEIGHT / 4;
+  dx = dx > 1 ? dx : 1;
+  dy = dy > 1 ? dy : 1;
+  
+  gdk_gc_set_foreground(civ_gc, colors_standard[3]);
+  gdk_draw_line(pm, civ_gc, 
+               canvas_x + dx, 
+               canvas_y + dy, 
+               canvas_x + NORMAL_TILE_WIDTH - dx, 
+               canvas_y + NORMAL_TILE_HEIGHT - dy);
+  gdk_draw_line(pm, civ_gc, 
+               canvas_x + dx, 
+               canvas_y + NORMAL_TILE_HEIGHT - dy, 
+               canvas_x + NORMAL_TILE_WIDTH - dx,
+               canvas_y + dy);
+}
+
+
 /**************************************************************************
 Refresh and draw to sceen all the tiles in a rectangde width,height (as
 seen in overhead ciew) with the top corner at x,y.
@@ -1267,6 +1288,17 @@
                          canvas_x, canvas_y, 0);
        }
       }
+    }
+    
+    if( draw_tile_markers ) {
+      coords_list_iterate(marked_tiles, pcoords) {
+       if( tile_visible_mapcanvas(pcoords->x, pcoords->y) ) {
+         get_canvas_xy(pcoords->x, pcoords->y, &canvas_x, &canvas_y);
+         draw_mark_on_tile(map_canvas_store, pcoords->x, pcoords->y, 
+                           canvas_x, canvas_y);
+       }
+      }
+      coords_list_iterate_end;
     }
 
     if (write_to_screen) {
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/gui-gtk/menu.c 
freeciv/client/gui-gtk/menu.c
--- freeciv-cvs/client/gui-gtk/menu.c   Fri Oct 26 11:07:13 2001
+++ freeciv/client/gui-gtk/menu.c       Sat Dec 15 12:12:43 2001
@@ -81,6 +81,7 @@
   MENU_VIEW_SHOW_MAP_GRID,
   MENU_VIEW_SHOW_CITY_NAMES,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
+  MENU_VIEW_SHOW_TILE_MARKERS,
   MENU_VIEW_SHOW_TERRAIN,
   MENU_VIEW_SHOW_COASTLINE,
   MENU_VIEW_SHOW_ROADS_RAILS,
@@ -234,6 +235,10 @@
     if (draw_city_productions ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_city_productions_toggle();
     break;
+  case MENU_VIEW_SHOW_TILE_MARKERS:
+    if (draw_tile_markers ^ GTK_CHECK_MENU_ITEM(widget)->active)
+      key_tile_markers_toggle();
+    break;
   case MENU_VIEW_SHOW_TERRAIN:
     if (draw_terrain ^ GTK_CHECK_MENU_ITEM(widget)->active) {
       key_terrain_toggle();
@@ -598,6 +603,8 @@
        view_menu_callback,     MENU_VIEW_SHOW_CITY_NAMES,              
"<CheckItem>"   },
   { "/" N_("View") "/" N_("City _Productions"),                "<control>p",
        view_menu_callback,     MENU_VIEW_SHOW_CITY_PRODUCTIONS,        
"<CheckItem>"   },
+  { "/" N_("View") "/" N_("Tile _Markers"),            NULL,
+       view_menu_callback,     MENU_VIEW_SHOW_TILE_MARKERS,            
"<CheckItem>"   },
   { "/" N_("View") "/sep1",                            NULL,
        NULL,                   0,                                      
"<Separator>"   },
   { "/" N_("View") "/" N_("Terrain"),                   NULL,
@@ -973,6 +980,7 @@
     menus_set_active("<main>/_View/Map _Grid", draw_map_grid);
     menus_set_active("<main>/_View/City _Names", draw_city_names);
     menus_set_active("<main>/_View/City _Productions", draw_city_productions);
+    menus_set_active("<main>/_View/Tile _Markers", draw_tile_markers);
     menus_set_active("<main>/_View/Terrain", draw_terrain);
     menus_set_active("<main>/_View/Coastline", draw_coastline);
     menus_set_sensitive("<main>/_View/Coastline", !draw_terrain);
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/mapview_common.c 
freeciv/client/mapview_common.c
--- freeciv-cvs/client/mapview_common.c Thu Dec 13 22:05:32 2001
+++ freeciv/client/mapview_common.c     Sat Dec 15 12:15:26 2001
@@ -23,6 +23,28 @@
 #include "mapview_common.h"
 #include "tilespec.h"
 
+/* List for coordinate pairs (x,y). */ 
+#define SPECLIST_TAG coords
+#define SPECLIST_TYPE struct coords
+#include "speclist_c.h"
+
+struct coords *coords_list_find(struct coords_list *This, int x, int y) {
+  struct genlist_iterator myiter;
+  struct coords *pcoords;
+  
+  genlist_iterator_init(&myiter, &This->list, 0);
+  for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
+    pcoords = (struct coords*)ITERATOR_PTR(myiter);
+    if( pcoords->x == x && pcoords->y == y) 
+      return ITERATOR_PTR(myiter);
+  }
+  return 0;
+}
+
+/* List to store marked tiles. */
+struct coords_list marked_tiles;
+
+
 /**************************************************************************
  Refreshes a single tile on the map canvas.
 **************************************************************************/
@@ -260,3 +282,5 @@
     *map_view_topleft_map_y = new_map_view_y0;
   }
 }
+
+
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/mapview_common.h 
freeciv/client/mapview_common.h
--- freeciv-cvs/client/mapview_common.h Wed Nov 28 22:31:09 2001
+++ freeciv/client/mapview_common.h     Sat Dec 15 12:15:26 2001
@@ -60,4 +60,22 @@
                                int map_view_map_width,
                                int map_view_map_height);
 
+/* Coordinate pairs (x,y) and typed list for them. */
+
+struct coords {
+  int x,y;
+};
+
+#define SPECLIST_TAG coords
+#define SPECLIST_TYPE struct coords
+#include "speclist.h"
+
+#define coords_list_iterate(coordslist, pcoords) \
+    TYPED_LIST_ITERATE(struct coords, coordslist, pcoords)
+#define coords_list_iterate_end  LIST_ITERATE_END
+
+struct coords *coords_list_find(struct coords_list *This, int x, int y);
+
+extern struct coords_list marked_tiles;
+
 #endif /* FC__MAPVIEW_COMMON_H */
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/options.c 
freeciv/client/options.c
--- freeciv-cvs/client/options.c        Tue Oct 30 13:12:04 2001
+++ freeciv/client/options.c    Sat Dec 15 12:08:16 2001
@@ -77,6 +77,7 @@
 int draw_map_grid=0;
 int draw_city_names=1;
 int draw_city_productions=0;
+int draw_tile_markers=1;
 int draw_terrain=1;
 int draw_coastline=0;
 int draw_roads_rails=1;
@@ -97,6 +98,7 @@
   VIEW_OPTION(draw_map_grid),
   VIEW_OPTION(draw_city_names),
   VIEW_OPTION(draw_city_productions),
+  VIEW_OPTION(draw_tile_markers),
   VIEW_OPTION(draw_terrain),
   VIEW_OPTION(draw_coastline),
   VIEW_OPTION(draw_roads_rails),
diff -Nur -X freeciv-cvs/diff_ignore freeciv-cvs/client/options.h 
freeciv/client/options.h
--- freeciv-cvs/client/options.h        Tue Oct 30 13:12:04 2001
+++ freeciv/client/options.h    Sat Dec 15 12:05:22 2001
@@ -51,6 +51,7 @@
 extern int draw_map_grid;
 extern int draw_city_names;
 extern int draw_city_productions;
+extern int draw_tile_markers;
 extern int draw_terrain;
 extern int draw_coastline;
 extern int draw_roads_rails;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] PATCH: Tile markers v2, Teemu Kurppa <=