[Freeciv-Dev] (PR#13605) editing the terrain
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13605 >
The attached patch allows changing of terrains through the client in
editor mode.
This is just a proof-of-concept at this point. This follows the new civ
editor design.
1. You can enter editor mode (see the options dialog).
2. Once in editor mode right-clicking on the center tile will bring up
a menu that lets you change the terrain.
3. Tile-edit packets are sent to the server (currently only changing
terrains is supported). Only HACK connections can edit.
In making this I quickly realized there are some problems with the
interface. The biggest one is that tiles near the border _can't_ be
turned into the center tile. Unfortunately there are no more mouse
buttons available that I can see so someone will have to work on this.
Also changing terrain that adds/removes continents is likely to break.
I just looked at the global-warming code (which uses
tile_change_terrain) to write this code and I guess that code has the
same problem.
-jason
? server/stvWuFad
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.138
diff -p -u -r1.138 options.c
--- client/options.c 2 Aug 2005 02:40:58 -0000 1.138
+++ client/options.c 4 Aug 2005 05:29:21 -0000
@@ -76,6 +76,7 @@ bool ask_city_name = TRUE;
bool popup_new_cities = TRUE;
bool keyboardless_goto = TRUE;
bool show_task_icons = TRUE;
+bool editor_mode = FALSE;
/* This option is currently set by the client - not by the user. */
bool update_city_text_in_refresh_tile = TRUE;
@@ -85,7 +86,8 @@ const char *client_option_class_names[CO
N_("Overview"),
N_("Sound"),
N_("Interface"),
- N_("Network")
+ N_("Network"),
+ N_("Civ Editor")
};
static client_option common_options[] = {
@@ -242,7 +244,11 @@ static client_option common_options[] =
GEN_BOOL_OPTION(overview.fog,
N_("Overview fog of war"),
N_("If enabled, fog of war is shown on the overview."),
- COC_OVERVIEW)
+ COC_OVERVIEW),
+ GEN_BOOL_OPTION(editor_mode,
+ N_("Editor mode enabled"),
+ N_("Select this option to enable editor mode."),
+ COC_EDITOR)
};
#undef GEN_INT_OPTION
#undef GEN_BOOL_OPTION
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.55
diff -p -u -r1.55 options.h
--- client/options.h 30 Jul 2005 06:39:37 -0000 1.55
+++ client/options.h 4 Aug 2005 05:29:21 -0000
@@ -50,6 +50,7 @@ extern bool popup_new_cities;
extern bool update_city_text_in_refresh_tile;
extern bool keyboardless_goto;
extern bool show_task_icons;
+extern bool editor_mode;
enum client_option_type {
COT_BOOL,
@@ -63,6 +64,7 @@ enum client_option_class {
COC_SOUND,
COC_INTERFACE,
COC_NETWORK,
+ COC_EDITOR,
COC_MAX
};
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.53
diff -p -u -r1.53 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c 27 Jul 2005 20:22:13 -0000 1.53
+++ client/gui-gtk-2.0/mapctrl.c 4 Aug 2005 05:29:21 -0000
@@ -217,13 +217,54 @@ gboolean butt_release_mapcanvas(GtkWidge
if (ev->button == 1 || ev->button == 3) {
release_goto_button(ev->x, ev->y);
}
- if(ev->button == 3 && (rbutton_down || hover_state != HOVER_NONE)) {
+ if (ev->button == 3
+ && (rbutton_down || hover_state != HOVER_NONE)
+ && !editor_mode) {
release_right_button(ev->x, ev->y);
}
return TRUE;
}
+static struct tile *edit_tile;
+
+static void edit_terrain_activate(GtkMenuItem* menuitem, gpointer data)
+{
+ struct terrain *pterrain = data;
+ struct tile *ptile = edit_tile;
+
+ if (!pterrain || !ptile) {
+ return;
+ }
+ dsend_packet_edit_tile(&aconnection, ptile->x, ptile->y, pterrain->index);
+}
+
+static void popup_tile_edit_menu(struct tile *ptile, guint button)
+{
+ GtkWidget *menu;
+
+ menu = gtk_menu_new();
+
+ terrain_type_iterate(pterrain) {
+ GtkWidget *item;
+
+ item = gtk_menu_item_new_with_label(pterrain->name);
+ gtk_widget_ref(item);
+ g_object_set_data_full(G_OBJECT(menu), pterrain->name_orig, item,
+ (GtkDestroyNotify)gtk_widget_unref);
+ gtk_container_add(GTK_CONTAINER(menu), item);
+ gtk_widget_set_sensitive(item, TRUE);
+ g_signal_connect(item, "activate",
+ GTK_SIGNAL_FUNC(edit_terrain_activate),
+ pterrain);
+ } terrain_type_iterate_end;
+
+ gtk_widget_show_all(menu);
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, 0);
+
+ edit_tile = ptile;
+}
+
/**************************************************************************
Handle all mouse button press on canvas.
Future feature: User-configurable mouse clicks.
@@ -297,9 +338,8 @@ gboolean butt_down_mapcanvas(GtkWidget *
else if ((ev->state & GDK_SHIFT_MASK) && pcity) {
clipboard_paste_production(pcity);
cancel_tile_hiliting();
- }
- /* Plain RMB click. */
- else {
+ } else if (!editor_mode) {
+ /* Plain RMB click. */
/* A foolproof user will depress button on canvas,
* release it on another widget, and return to canvas
* to find rectangle still active.
@@ -313,6 +353,16 @@ gboolean butt_down_mapcanvas(GtkWidget *
anchor_selection_rectangle(ev->x, ev->y);
rbutton_down = TRUE; /* causes rectangle updates */
}
+ } else {
+ /* Editor mode is special. */
+ struct tile *ptile = canvas_pos_to_tile(ev->x, ev->y);
+ struct tile *pcenter = get_center_tile_mapcanvas();
+
+ if (ptile && ptile == pcenter) {
+ popup_tile_edit_menu(ptile, ev->button);
+ } else {
+ center_tile_mapcanvas(ptile);
+ }
}
break;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.147
diff -p -u -r1.147 packets.def
--- common/packets.def 1 Aug 2005 22:38:25 -0000 1.147
+++ common/packets.def 4 Aug 2005 05:29:21 -0000
@@ -1349,3 +1349,10 @@ PACKET_RULESET_EFFECT_REQ=123;sc,lsend
BOOL negated;
end
+/************** Editor packets **********************/
+
+PACKET_EDIT_TILE=117;cs,dsend,handle-per-conn
+ COORD x, y;
+
+ TERRAIN terrain;
+end
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.170
diff -p -u -r1.170 maphand.c
--- server/maphand.c 14 Jul 2005 19:25:46 -0000 1.170
+++ server/maphand.c 4 Aug 2005 05:29:22 -0000
@@ -1834,3 +1834,26 @@ int get_ocean_size(Continent_id id)
assert(id > 0);
return ocean_sizes[id];
}
+
+/***************************************************************************
+ Handles an edit-tile request from the client.
+***************************************************************************/
+void handle_edit_tile(struct connection *pconn, int x, int y,
+ Terrain_type_id terrain)
+{
+ struct tile *ptile = map_pos_to_tile(x, y);
+ struct terrain *pterrain = get_terrain(terrain);
+
+ if (pconn->access_level < ALLOW_HACK
+ || !ptile
+ || !pterrain) {
+ return;
+ }
+
+ if (ptile->terrain != pterrain) {
+ /* FIXME: must recalculate ocean numbers, etc. */
+ tile_change_terrain(ptile, pterrain);
+ }
+
+ send_tile_info(NULL, ptile);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13605) editing the terrain,
Jason Short <=
|
|