Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] (PR#15636) Editor: Change city from within city dialog
Home

[Freeciv-Dev] (PR#15636) Editor: Change city from within city dialog

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#15636) Editor: Change city from within city dialog
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Feb 2006 23:49:57 -0800
Reply-to: bugs@xxxxxxxxxxx

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

> [jdorje - Tue Feb 21 07:49:32 2006]:
> 
> Here is a simpler patch.


Index: server/edithand.c
===================================================================
--- server/edithand.c   (revision 11627)
+++ server/edithand.c   (working copy)
@@ -261,6 +261,22 @@
   send_city_info(NULL, pcity);  
 }
 
+/****************************************************************************
+  Allows the editor to change city size directly.
+****************************************************************************/
+void handle_edit_city_size(struct connection *pc,
+                          int id, int size)
+{
+  struct city *pcity = find_city_by_id(id);
+
+  if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
+      || !pcity) {
+    return;
+  }
+
+  city_change_size(pcity, CLIP(1, size, MAX_CITY_SIZE));
+}
+
 /**************************************************************************
  right now there are no checks whatsoever in the server. beware.
 ***************************************************************************/
Index: data/misc/small.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: data/misc/small.spec
===================================================================
--- data/misc/small.spec        (revision 11627)
+++ data/misc/small.spec        (working copy)
@@ -118,4 +118,6 @@
   1, 8,  "ev.wonderobsolete"
   1, 9,  "ev.wonderwillbebuilt"
   1, 10, "ev.wonderbuilt"
+  1, 11, "s.plus"
+  1, 12, "s.minus"
 }
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 11627)
+++ common/packets.def  (working copy)
@@ -1405,6 +1405,11 @@
   # cannot be controlled even by a privilidged client.
 end
 
+PACKET_EDIT_CITY_SIZE=130;cs,handle-per-conn,dsend
+  CITY id;
+  UINT8 size;
+end
+
 PACKET_EDIT_PLAYER=128;cs,handle-per-conn,lsend
   PLAYER playerno; key 
   STRING name[MAX_LEN_NAME];
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
--- client/gui-gtk-2.0/citydlg.c        (revision 11627)
+++ client/gui-gtk-2.0/citydlg.c        (working copy)
@@ -95,7 +95,7 @@
 
 enum info_style { NORMAL, ORANGE, RED, NUM_INFO_STYLES };
 
-#define NUM_CITIZENS_SHOWN 25
+#define NUM_CITIZENS_SHOWN 23
 #define NUM_INFO_FIELDS 11      /* number of fields in city_info */
 #define NUM_PAGES 6             /* the number of pages in city dialog notebook 
                                  * (+1) if you change this, you must add an
@@ -656,7 +656,8 @@
   gtk_widget_add_events(ebox, GDK_BUTTON_PRESS_MASK);
   gtk_box_pack_start(GTK_BOX(hbox), ebox, FALSE, FALSE, 0);
   pdialog->citizen_pixmap =
-      gtk_pixcomm_new(tileset_small_sprite_width(tileset) * NUM_CITIZENS_SHOWN,
+      gtk_pixcomm_new(tileset_small_sprite_width(tileset)
+                     * (NUM_CITIZENS_SHOWN + 2),
                      tileset_small_sprite_height(tileset));
   gtk_misc_set_padding(GTK_MISC(pdialog->citizen_pixmap), 2, 2);
   gtk_container_add(GTK_CONTAINER(ebox), pdialog->citizen_pixmap);
@@ -1337,7 +1338,7 @@
 *****************************************************************/
 static void city_dialog_update_citizens(struct city_dialog *pdialog)
 {
-  int i, width;
+  int i, j, width;
   struct city *pcity = pdialog->pcity;
   struct citizen_type citizens[MAX_CITY_SIZE];
 
@@ -1360,9 +1361,18 @@
 
   get_city_citizen_types(pcity, 4, citizens);
 
-  for (i = 0; i < pcity->size; i++) {
+  i = 0;
+  if (game.info.is_edit_mode) {
     gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
-                      get_citizen_sprite(tileset, citizens[i], i, pcity),
+                       get_arrow_sprite(tileset, ARROW_PLUS),
+                      i++ * width, 0);
+    gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
+                       get_arrow_sprite(tileset, ARROW_MINUS),
+                      i++ * width, 0);
+  }
+  for (j = 0; j < pcity->size; i++, j++) {
+    gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
+                      get_citizen_sprite(tileset, citizens[j], j, pcity),
                       i * width, 0);
   }
 
@@ -2347,17 +2357,32 @@
 {
   struct city_dialog *pdialog = data;
   struct city *pcity = pdialog->pcity;
-  int citnum;
+  int citnum, tlen, len;
 
   if (!can_client_issue_orders()) {
     return FALSE;
   }
 
-  if (ev->x > (pcity->size - 1) * pdialog->cwidth + 
tileset_small_sprite_width(tileset))
-    return FALSE;              /* no citizen that far to the right */
+  tlen = tileset_small_sprite_width(tileset);
+  len = (pcity->size - 1) * pdialog->cwidth + tlen;
+  if (game.info.is_edit_mode) {
+    if (ev->x > 0 && ev->x <= tlen) {
+      dsend_packet_edit_city_size(&aconnection, pcity->id, pcity->size + 1);
+      return TRUE;
+    } else if (ev->x > tlen && ev->x <= tlen * 2) {
+      dsend_packet_edit_city_size(&aconnection, pcity->id, pcity->size - 1);
+      return TRUE;
+    } else if (ev->x > len + tlen * 2) {
+      return FALSE;
+    }
+    citnum = MIN(pcity->size - 1, (ev->x - tlen * 2) / pdialog->cwidth);
+  } else {
+    if (ev->x > len) {
+      return FALSE;            /* no citizen that far to the right */
+    }
+    citnum = MIN(pcity->size - 1, ev->x / pdialog->cwidth);
+  }
 
-  citnum = MIN(pcity->size - 1, ev->x / pdialog->cwidth);
-
   city_rotate_specialist(pcity, citnum);
 
   return TRUE;
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
--- client/gui-gtk-2.0/gui_main.c       (revision 11627)
+++ client/gui-gtk-2.0/gui_main.c       (working copy)
@@ -702,7 +702,8 @@
   }
 
   more_arrow_pixmap
-    = gtk_image_new_from_pixbuf(sprite_get_pixbuf(get_arrow_sprite(tileset)));
+    = gtk_image_new_from_pixbuf(sprite_get_pixbuf(get_arrow_sprite(tileset,
+                                                  ARROW_RIGHT)));
   gtk_widget_ref(more_arrow_pixmap);
   gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap, 4, 5, 1, 2);
 
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 11627)
+++ client/packhand.c   (working copy)
@@ -1380,6 +1380,10 @@
     update_aifill_button = TRUE;
   }
   
+  if (game.info.is_edit_mode != pinfo->is_edit_mode) {
+    popdown_all_city_dialogs();
+  }
+
   game.info = *pinfo;
 
   game.government_when_anarchy
Index: client/tilespec.c
===================================================================
--- client/tilespec.c   (revision 11627)
+++ client/tilespec.c   (working copy)
@@ -125,7 +125,7 @@
   struct sprite
     *indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS],
     *treaty_thumb[2],     /* 0=disagree, 1=agree */
-    *right_arrow,
+    *arrow[ARROW_LAST], /* 0=right arrow, 1=plus, 2=minus */
 
     *icon[ICON_COUNT],
 
@@ -1989,7 +1989,9 @@
     }
   }
 
-  SET_SPRITE(right_arrow, "s.right_arrow");
+  SET_SPRITE(arrow[ARROW_RIGHT], "s.right_arrow");
+  SET_SPRITE(arrow[ARROW_PLUS], "s.plus");
+  SET_SPRITE(arrow[ARROW_MINUS], "s.minus");
   if (t->is_isometric) {
     SET_SPRITE(dither_tile, "t.dither_tile");
   }
@@ -4485,11 +4487,14 @@
 }
 
 /**************************************************************************
-  Return a sprite with the "right-arrow" theme graphic.
+  Return a sprite with an "arrow" theme graphic.
 **************************************************************************/
-struct sprite *get_arrow_sprite(const struct tileset *t)
+struct sprite *get_arrow_sprite(const struct tileset *t,
+                               enum arrow_type arrow)
 {
-  return t->sprites.right_arrow;
+  assert(arrow >= 0 && arrow < ARROW_LAST);
+
+  return t->sprites.arrow[arrow];
 }
 
 /**************************************************************************
Index: client/mapctrl_common.c
===================================================================
--- client/mapctrl_common.c     (revision 11627)
+++ client/mapctrl_common.c     (working copy)
@@ -531,7 +531,7 @@
 {
   struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
 
-  if (game.info.is_edit_mode) {
+  if (!ptile->city && game.info.is_edit_mode) {
     editor_do_click(ptile);
   } else if (can_client_change_view() && ptile) {
     /* FIXME: Some actions here will need to check can_client_issue_orders.
Index: client/tilespec.h
===================================================================
--- client/tilespec.h   (revision 11627)
+++ client/tilespec.h   (working copy)
@@ -99,6 +99,13 @@
 
 #define NUM_TILES_PROGRESS 8
 
+enum arrow_type {
+  ARROW_RIGHT,
+  ARROW_PLUS,
+  ARROW_MINUS,
+  ARROW_LAST
+};
+
 struct tileset;
 
 extern struct tileset *tileset;
@@ -209,7 +216,8 @@
                                   const struct unit_type *punittype);
 struct sprite *get_sample_city_sprite(const struct tileset *t,
                                      int city_style);
-struct sprite *get_arrow_sprite(const struct tileset *t);
+struct sprite *get_arrow_sprite(const struct tileset *t,
+                               enum arrow_type arrow);
 struct sprite *get_tax_sprite(const struct tileset *t, Output_type_id otype);
 struct sprite *get_treaty_thumb_sprite(const struct tileset *t, bool on_off);
 const struct sprite_vector *get_unit_explode_animation(const struct

[Prev in Thread] Current Thread [Next in Thread]