Freeciv-3.1
Loading...
Searching...
No Matches
editprop.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <limits.h> /* USHRT_MAX */
19
20#include <gtk/gtk.h>
21#include <gdk/gdkkeysyms.h>
22
23/* utility */
24#include "bitvector.h"
25#include "fc_cmdline.h"
26#include "fcintl.h"
27#include "log.h"
28#include "mem.h"
29
30/* common */
31#include "fc_interface.h"
32#include "game.h"
33#include "government.h"
34#include "map.h"
35#include "movement.h"
36#include "research.h"
37#include "tile.h"
38
39/* client */
40#include "client_main.h"
41#include "climisc.h"
42#include "editor.h"
43#include "mapview_common.h"
44#include "tilespec.h"
45
46/* client/gui-gtk-4.0 */
47#include "canvas.h"
48#include "gui_main.h"
49#include "gui_stuff.h"
50#include "plrdlg.h"
51#include "sprite.h"
52
53#include "editprop.h"
54
55
56/* Forward declarations. */
57struct objprop;
58struct objbind;
59struct property_page;
60struct property_editor;
61struct extviewer;
62
63/****************************************************************************
64 Miscellaneous helpers.
65****************************************************************************/
66static GdkPixbuf *create_pixbuf_from_layers(const struct tile *ptile,
67 const struct unit *punit,
68 const struct city *pcity,
69 enum layer_category category);
70static GdkPixbuf *create_tile_pixbuf(const struct tile *ptile);
71static GdkPixbuf *create_unit_pixbuf(const struct unit *punit);
72static GdkPixbuf *create_city_pixbuf(const struct city *pcity);
73
74static void add_column(GtkWidget *view,
75 int col_id,
76 const char *name,
77 GType gtype,
78 bool editable,
79 bool is_radio,
80 GCallback edit_callback,
81 gpointer callback_userdata);
82
83static bool can_create_unit_at_tile(struct tile *ptile);
84
85static int get_next_unique_tag(void);
86
87/* 'struct stored_tag_hash' and related functions. */
88#define SPECHASH_TAG stored_tag
89#define SPECHASH_INT_KEY_TYPE
90#define SPECHASH_INT_DATA_TYPE
91#include "spechash.h"
92
93/* NB: If packet definitions change, be sure to
94 * update objbind_pack_current_values()!!! */
95union packetdata {
96 struct {
97 gpointer v_pointer1;
98 gpointer v_pointer2;
100 struct packet_edit_tile *tile;
102 struct packet_edit_city *city;
103 struct packet_edit_unit *unit;
105 struct {
106 struct packet_edit_game *game;
107 struct packet_edit_scenario_desc *desc;
109};
110
111/* Helpers for the OPID_TILE_VISION property. */
112struct tile_vision_data {
113 bv_player tile_known, tile_seen[V_COUNT];
114};
115const char *vision_layer_get_name(enum vision_layer);
116
117#define PF_MAX_CLAUSES 16
118#define PF_DISJUNCTION_SEPARATOR "|"
119#define PF_CONJUNCTION_SEPARATOR "&"
120
121struct pf_pattern {
122 bool negate;
123 char *text;
124};
125
126struct pf_conjunction {
128 int count;
129};
130
131struct property_filter {
133 int count;
134};
135
136static struct property_filter *property_filter_new(const char *filter);
137static bool property_filter_match(struct property_filter *pf,
138 const struct objprop *op);
139static void property_filter_free(struct property_filter *pf);
140
141
142/****************************************************************************
143 Object type declarations.
144
145 To add a new object type:
146 1. Add a value in enum editor_object_type in client/editor.h.
147 2. Add a string name to objtype_get_name.
148 3. Add code in objtype_get_id_from_object.
149 4. Add code in objtype_get_object_from_id.
150 5. Add a case handler in objtype_is_conserved, and if
151 the object type is not conserved, then also in
152 objbind_request_destroy_object and property_page_create_objects.
153 6. Add an if-block in objbind_get_value_from_object.
154 7. Add an if-block in objbind_get_allowed_value_span.
155 9. Add a case handler in property_page_setup_objprops.
156 10. Add a case handler in property_page_add_objbinds_from_tile
157 if applicable.
158
159 Furthermore, if the object type is to be editable:
160 11. Define its edit packet in common/networking/packets.def.
161 12. Add the packet handler in server/edithand.c.
162 13. Add its edit packet type to union packetdata.
163 14. Add an if-block in objbind_pack_current_values.
164 15. Add an if-block in objbind_pack_modified_value.
165 16. Add code in property_page_new_packet.
166 17. Add code in property_page_send_packet.
167 18. Add calls to editgui_notify_object_changed in
168 client/packhand.c or where applicable.
169
170****************************************************************************/
171
172/* OBJTYPE_* enum values defined in client/editor.h */
173
174static const char *objtype_get_name(enum editor_object_type objtype);
176 gpointer object);
178 int id);
180
181
182/****************************************************************************
183 Value type declarations.
184
185 To add a new value type:
186 1. Add a value in enum value_types.
187 2. Add its field in union propval_data.
188 3. Add a case handler in valtype_get_name.
189 4. Add a case handler in propval_copy if needed.
190 5. Add a case handler in propval_free if needed.
191 6. Add a case handler in propval_equal if needed.
192 7. Add a case handler in objprop_get_gtype.
193 8. Add a case handler in property_page_set_store_value.
194 9. Add a case handler in propval_as_string if needed.
195****************************************************************************/
212
213static const char *valtype_get_name(enum value_types valtype);
214
215
216/****************************************************************************
217 Propstate and propval declarations.
218
219 To add a new member to union propval_data, see the steps for adding a
220 new value type above.
221
222 New property values are "constructed" by objbind_get_value_from_object().
223****************************************************************************/
224union propval_data {
225 gpointer v_pointer;
226 int v_int;
227 bool v_bool;
228 char *v_string;
229 const char *v_const_string;
230 GdkPixbuf *v_pixbuf;
231 struct built_status *v_built;
232 bv_max_extras v_bv_special;
233 bv_max_extras v_bv_roads;
234 bv_max_extras v_bv_bases;
235 struct nation_type *v_nation;
236 struct nation_hash *v_nation_hash;
237 struct government *v_gov;
238 bv_techs v_bv_inventions;
240};
241
242struct propval {
243 union propval_data data;
244 enum value_types valtype;
245 bool must_free;
246};
247
248static void propval_free(struct propval *pv);
249static void propval_free_data(struct propval *pv);
250static struct propval *propval_copy(struct propval *pv);
251static bool propval_equal(struct propval *pva, struct propval *pvb);
252
253struct propstate {
254 int property_id;
255 struct propval *property_value;
256};
257
258static struct propstate *propstate_new(struct objprop *op,
259 struct propval *pv);
260static void propstate_destroy(struct propstate *ps);
261static void propstate_clear_value(struct propstate *ps);
262static void propstate_set_value(struct propstate *ps,
263 struct propval *pv);
264static struct propval *propstate_get_value(struct propstate *ps);
265
266#define SPECHASH_TAG propstate
267#define SPECHASH_INT_KEY_TYPE
268#define SPECHASH_IDATA_TYPE struct propstate *
269#define SPECHASH_IDATA_FREE propstate_destroy
270#include "spechash.h"
271
272
273/****************************************************************************
274 Objprop declarations.
275
276 To add a new object property:
277 1. Add a value in enum object_property_ids (grouped by
278 object type).
279 2. Define the property in property_page_setup_objprops.
280 3. Add a case handler in objbind_get_value_from_object
281 in the appropriate object type block.
282 4. Add a case handler in objprop_setup_widget.
283 5. Add a case handler in objprop_refresh_widget.
284
285 Furthermore, if the property is editable:
286 5. Add a field for this property in the edit
287 packet for this object type in common/networking/packets.def.
288 6. Add a case handler in objbind_pack_modified_value.
289 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
290 !!! 7. Add code to set the packet field in !!!
291 !!! objbind_pack_current_values(). !!!
292 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
293 8. Add code to handle changes in the packet field in
294 server/edithand.c handle_edit_<objtype>.
295
296 If the property makes use of an extviewer:
297 9. Handle widget creation in extviewer_new.
298 10. Handle refresh in extviewer_refresh_widgets.
299 11. Handle clear in extviewer_clear_widgets.
300 12. Handle any signal callbacks (e.g. toggled) if needed.
301
302 TODO: Add more object properties.
303****************************************************************************/
311#ifdef FREECIV_DEBUG
312 OPID_TILE_ADDRESS,
313#endif /* FREECIV_DEBUG */
321 OPID_TILE_VISION, /* tile_known and tile_seen */
323
328
330#ifdef FREECIV_DEBUG
331 OPID_UNIT_ADDRESS,
332#endif /* FREECIV_DEBUG */
343
346#ifdef FREECIV_DEBUG
347 OPID_CITY_ADDRESS,
348#endif /* FREECIV_DEBUG */
356
361#ifdef FREECIV_DEBUG
362 OPID_PLAYER_ADDRESS,
363#endif /* FREECIV_DEBUG */
368
380
387
388struct objprop {
389 int id;
390 const char *name;
391 const char *tooltip;
393 enum value_types valtype;
394 int column_id;
395 GtkTreeViewColumn *view_column;
396 GtkWidget *widget;
397 struct extviewer *extviewer;
399};
400
401static struct objprop *objprop_new(int id,
402 const char *name,
403 const char *tooltip,
405 enum value_types valtype,
406 struct property_page *parent);
407static int objprop_get_id(const struct objprop *op);
408static const char *objprop_get_name(const struct objprop *op);
409static const char *objprop_get_tooltip(const struct objprop *op);
410static enum value_types objprop_get_valtype(const struct objprop *op);
411static struct property_page *
412objprop_get_property_page(const struct objprop *op);
413
414static bool objprop_show_in_listview(const struct objprop *op);
415static bool objprop_is_sortable(const struct objprop *op);
416static bool objprop_is_readonly(const struct objprop *op);
417static bool objprop_has_widget(const struct objprop *op);
418
419static GType objprop_get_gtype(const struct objprop *op);
420static const char *objprop_get_attribute_type_string(const struct objprop *op);
421static void objprop_set_column_id(struct objprop *op, int col_id);
422static int objprop_get_column_id(const struct objprop *op);
423static void objprop_set_treeview_column(struct objprop *op,
424 GtkTreeViewColumn *col);
425static GtkTreeViewColumn *objprop_get_treeview_column(const struct objprop *op);
426static GtkCellRenderer *objprop_create_cell_renderer(const struct objprop *op);
427
428static void objprop_setup_widget(struct objprop *op);
429static GtkWidget *objprop_get_widget(struct objprop *op);
430static void objprop_set_child_widget(struct objprop *op,
431 const char *widget_name,
432 GtkWidget *widget);
433static GtkWidget *objprop_get_child_widget(struct objprop *op,
434 const char *widget_name);
435static void objprop_set_extviewer(struct objprop *op,
436 struct extviewer *ev);
437static struct extviewer *objprop_get_extviewer(struct objprop *op);
438static void objprop_refresh_widget(struct objprop *op,
439 struct objbind *ob);
440static void objprop_widget_text_changed(GtkEditable *text, gpointer userdata);
441static void objprop_widget_spin_button_changed(GtkSpinButton *spin,
442 gpointer userdata);
443static void objprop_widget_toggle_button_changed(GtkToggleButton *button,
444 gpointer userdata);
445
446#define SPECHASH_TAG objprop
447#define SPECHASH_INT_KEY_TYPE
448#define SPECHASH_IDATA_TYPE struct objprop *
449#include "spechash.h"
450
451
452/****************************************************************************
453 Objbind declarations.
454****************************************************************************/
455struct objbind {
457 int object_id;
459 struct propstate_hash *propstate_table;
460 GtkTreeRowReference *rowref;
461};
462
464 gpointer object);
465static void objbind_destroy(struct objbind *ob);
466static enum editor_object_type objbind_get_objtype(const struct objbind *ob);
467static void objbind_bind_properties(struct objbind *ob,
468 struct property_page *pp);
469static gpointer objbind_get_object(struct objbind *ob);
470static int objbind_get_object_id(struct objbind *ob);
471static void objbind_request_destroy_object(struct objbind *ob);
472static struct propval *objbind_get_value_from_object(struct objbind *ob,
473 struct objprop *op);
474static bool objbind_get_allowed_value_span(struct objbind *ob,
475 struct objprop *op,
476 double *pmin,
477 double *pmax,
478 double *pstep,
479 double *pbig_step);
480static bool objbind_set_modified_value(struct objbind *ob,
481 struct objprop *op,
482 struct propval *pv);
483static struct propval *objbind_get_modified_value(struct objbind *ob,
484 struct objprop *op);
485static void objbind_clear_modified_value(struct objbind *ob,
486 struct objprop *op);
487static bool objbind_property_is_modified(struct objbind *ob,
488 struct objprop *op);
489static bool objbind_has_modified_properties(struct objbind *ob);
490static void objbind_clear_all_modified_values(struct objbind *ob);
491static void objbind_pack_current_values(struct objbind *ob,
492 union packetdata packet);
493static void objbind_pack_modified_value(struct objbind *ob,
494 struct objprop *op,
495 union packetdata packet);
496static void objbind_set_rowref(struct objbind *ob,
497 GtkTreeRowReference *rr);
498static GtkTreeRowReference *objbind_get_rowref(struct objbind *ob);
499
500#define SPECHASH_TAG objbind
501#define SPECHASH_INT_KEY_TYPE
502#define SPECHASH_IDATA_TYPE struct objbind *
503#define SPECHASH_IDATA_FREE objbind_destroy
504#include "spechash.h"
505
506
507/****************************************************************************
508 Extended property viewer declarations. This is a set of widgets used
509 for viewing and/or editing properties with complex values (e.g. arrays).
510****************************************************************************/
511struct extviewer {
512 struct objprop *objprop;
513 struct propval *pv_cached;
514
515 GtkWidget *panel_widget;
516 GtkWidget *panel_label;
517 GtkWidget *panel_button;
518 GtkWidget *panel_image;
519
520 GtkWidget *view_widget;
521 GtkWidget *view_label;
522
523 GtkListStore *store;
524 GtkTextBuffer *textbuf;
525};
526
527static struct extviewer *extviewer_new(struct objprop *op);
528static struct objprop *extviewer_get_objprop(struct extviewer *ev);
529static GtkWidget *extviewer_get_panel_widget(struct extviewer *ev);
530static GtkWidget *extviewer_get_view_widget(struct extviewer *ev);
531static void extviewer_refresh_widgets(struct extviewer *ev,
532 struct propval *pv);
533static void extviewer_clear_widgets(struct extviewer *ev);
534static void extviewer_panel_button_clicked(GtkButton *button,
535 gpointer userdata);
536static void extviewer_view_cell_toggled(GtkCellRendererToggle *cell,
537 gchar *path,
538 gpointer userdata);
539static void extviewer_textbuf_changed(GtkTextBuffer *textbuf,
540 gpointer userdata);
541
542
543/****************************************************************************
544 Property page declarations.
545****************************************************************************/
546struct property_page {
548
549 GtkWidget *widget;
550 GtkListStore *object_store;
551 GtkWidget *object_view;
552 GtkWidget *extviewer_notebook;
553
555
556 struct objprop_hash *objprop_table;
557 struct objbind_hash *objbind_table;
558 struct stored_tag_hash *tag_table;
559
560 struct objbind *focused_objbind;
561};
562
563static struct property_page *
565 struct property_editor *parent);
566static void property_page_setup_objprops(struct property_page *pp);
567static const char *property_page_get_name(const struct property_page *pp);
568static enum editor_object_type
570static void property_page_load_tiles(struct property_page *pp,
571 const struct tile_list *tiles);
573 const struct tile *ptile);
574static int property_page_get_num_objbinds(const struct property_page *pp);
575static void property_page_clear_objbinds(struct property_page *pp);
576static void property_page_add_objbind(struct property_page *pp,
577 gpointer object_data);
578static void property_page_fill_widgets(struct property_page *pp);
579static struct objbind *
582 struct objbind *ob);
583static struct objbind *property_page_get_objbind(struct property_page *pp,
584 int object_id);
585static void property_page_selection_changed(GtkTreeSelection *sel,
586 gpointer userdata);
587static gboolean property_page_selection_func(GtkTreeSelection *sel,
588 GtkTreeModel *model,
589 GtkTreePath *path,
590 gboolean currently_selected,
591 gpointer data);
592static void property_page_quick_find_entry_changed(GtkWidget *entry,
593 gpointer userdata);
594static void property_page_change_value(struct property_page *pp,
595 struct objprop *op,
596 struct propval *pv);
597static void property_page_send_values(struct property_page *pp);
598static void property_page_reset_objbinds(struct property_page *pp);
599static void property_page_destroy_objects(struct property_page *pp);
600static void property_page_create_objects(struct property_page *pp,
601 struct tile_list *hint_tiles);
602static union packetdata property_page_new_packet(struct property_page *pp);
603static void property_page_send_packet(struct property_page *pp,
604 union packetdata packet);
605static void property_page_free_packet(struct property_page *pp,
606 union packetdata packet);
607static void property_page_object_changed(struct property_page *pp,
608 int object_id,
609 bool remove);
610static void property_page_object_created(struct property_page *pp,
611 int tag, int object_id);
612static void property_page_add_extviewer(struct property_page *pp,
613 struct extviewer *ev);
614static void property_page_show_extviewer(struct property_page *pp,
615 struct extviewer *ev);
617 int tag, int count);
619 int tag);
620static bool property_page_tag_is_known(struct property_page *pp, int tag);
621static void property_page_clear_tags(struct property_page *pp);
622static void property_page_apply_button_clicked(GtkButton *button,
623 gpointer userdata);
624static void property_page_refresh_button_clicked(GtkButton *button,
625 gpointer userdata);
626static void property_page_create_button_clicked(GtkButton *button,
627 gpointer userdata);
628static void property_page_destroy_button_clicked(GtkButton *button,
629 gpointer userdata);
630
631
632#define property_page_objprop_iterate(ARG_pp, NAME_op) \
633 TYPED_HASH_DATA_ITERATE(struct objprop *, (ARG_pp)->objprop_table, NAME_op)
634#define property_page_objprop_iterate_end HASH_DATA_ITERATE_END
635
636#define property_page_objbind_iterate(ARG_pp, NAME_ob) \
637 TYPED_HASH_DATA_ITERATE(struct objbind *, (ARG_pp)->objbind_table, NAME_ob)
638#define property_page_objbind_iterate_end HASH_DATA_ITERATE_END
639
640
641/****************************************************************************
642 Property editor declarations.
643****************************************************************************/
644struct property_editor {
645 GtkWidget *widget;
646 GtkWidget *notebook;
647
649};
650
651static struct property_editor *property_editor_new(void);
652static bool property_editor_add_page(struct property_editor *pe,
654static struct property_page *
657
659
660
661/************************************************************************/
665{
666 switch (objtype) {
667 case OBJTYPE_TILE:
668 return _("Tile");
669 case OBJTYPE_STARTPOS:
670 return _("Start Position");
671 case OBJTYPE_UNIT:
672 return _("Unit");
673 case OBJTYPE_CITY:
674 return _("City");
675 case OBJTYPE_PLAYER:
676 return _("Player");
677 case OBJTYPE_GAME:
678 return Q_("?play:Game");
679 case NUM_OBJTYPES:
680 break;
681 }
682
683 log_error("%s() Unhandled request to get name of object type %d.",
684 __FUNCTION__, objtype);
685 return "Unknown";
686}
687
688/************************************************************************/
694 gpointer object)
695{
696 switch (objtype) {
697 case OBJTYPE_TILE:
698 return tile_index((struct tile *) object);
699 case OBJTYPE_STARTPOS:
700 return startpos_number((struct startpos *) object);
701 case OBJTYPE_UNIT:
702 return ((struct unit *) object)->id;
703 case OBJTYPE_CITY:
704 return ((struct city *) object)->id;
705 case OBJTYPE_PLAYER:
706 return player_number((struct player *) object);
707 case OBJTYPE_GAME:
708 return 1;
709 case NUM_OBJTYPES:
710 break;
711 }
712
713 log_error("%s(): Unhandled request to get object ID from object %p of "
714 "type %d (%s).", __FUNCTION__, object, objtype,
716 return -1;
717}
718
719/************************************************************************/
723 int id)
724{
725 switch (objtype) {
726 case OBJTYPE_TILE:
727 return index_to_tile(&(wld.map), id);
728 case OBJTYPE_STARTPOS:
729 return map_startpos_by_number(id);
730 case OBJTYPE_UNIT:
731 return game_unit_by_number(id);
732 case OBJTYPE_CITY:
733 return game_city_by_number(id);
734 case OBJTYPE_PLAYER:
735 return player_by_number(id);
736 case OBJTYPE_GAME:
737 return &game;
738 case NUM_OBJTYPES:
739 break;
740 }
741
742 log_error("%s(): Unhandled request to get object of type %d (%s) "
743 "with ID %d.", __FUNCTION__, objtype,
745 return NULL;
746}
747
748/************************************************************************/
754{
755 switch (objtype) {
756 case OBJTYPE_TILE:
757 case OBJTYPE_GAME:
758 return TRUE;
759 case OBJTYPE_STARTPOS:
760 case OBJTYPE_UNIT:
761 case OBJTYPE_CITY:
762 case OBJTYPE_PLAYER:
763 return FALSE;
764 case NUM_OBJTYPES:
765 break;
766 }
767
768 log_error("%s(): Unhandled request for object type %d (%s)).",
769 __FUNCTION__, objtype, objtype_get_name(objtype));
770 return TRUE;
771}
772
773/************************************************************************/
776static const char *valtype_get_name(enum value_types valtype)
777{
778 switch (valtype) {
779 case VALTYPE_NONE:
780 return "none";
781 case VALTYPE_STRING:
782 return "string";
783 case VALTYPE_INT:
784 return "int";
785 case VALTYPE_BOOL:
786 return "bool";
787 case VALTYPE_PIXBUF:
788 return "pixbuf";
790 return "struct built_status[B_LAST]";
792 return "bool[A_LAST]";
794 return "bv_special";
795 case VALTYPE_BV_ROADS:
796 return "bv_roads";
797 case VALTYPE_BV_BASES:
798 return "bv_bases";
799 case VALTYPE_NATION:
800 return "nation";
802 return "struct nation_hash";
803 case VALTYPE_GOV:
804 return "government";
806 return "struct tile_vision_data";
807 }
808
809 log_error("%s(): unhandled value type %d.", __FUNCTION__, valtype);
810 return "void";
811}
812
813/************************************************************************/
817static void add_column(GtkWidget *view,
818 int col_id,
819 const char *name,
820 GType gtype,
821 bool editable,
822 bool is_radio,
823 GCallback edit_callback,
824 gpointer userdata)
825{
826 GtkCellRenderer *cell;
827 GtkTreeViewColumn *col;
828 const char *attr = NULL;
829
830 if (gtype == G_TYPE_BOOLEAN) {
831 cell = gtk_cell_renderer_toggle_new();
832 gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(cell),
833 is_radio);
834 if (editable) {
835 g_signal_connect(cell, "toggled", edit_callback, userdata);
836 }
837 attr = "active";
838 } else if (gtype == GDK_TYPE_PIXBUF) {
839 cell = gtk_cell_renderer_pixbuf_new();
840 attr = "pixbuf";
841 } else {
842 cell = gtk_cell_renderer_text_new();
843 if (editable) {
844 g_object_set(cell, "editable", TRUE, NULL);
845 g_signal_connect(cell, "edited", edit_callback, userdata);
846 }
847 attr = "text";
848 }
849
850 col = gtk_tree_view_column_new_with_attributes(name, cell,
851 attr, col_id, NULL);
852 gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
853}
854
855/************************************************************************/
859static gchar *propval_as_string(struct propval *pv)
860{
861 int count = 0;
862
863 fc_assert_ret_val(NULL != pv, 0);
864
865 switch (pv->valtype) {
866 case VALTYPE_NONE:
867 return g_strdup("");
868
869 case VALTYPE_INT:
870 return g_strdup_printf("%d", pv->data.v_int);
871
872 case VALTYPE_BOOL:
873 return g_strdup_printf("%s", pv->data.v_bool ? _("TRUE") : _("FALSE"));
874
875 case VALTYPE_NATION:
876 return g_strdup_printf("%s", nation_adjective_translation(pv->data.v_nation));
877
878 case VALTYPE_GOV:
879 return g_strdup_printf("%s", government_name_translation(pv->data.v_gov));
880
882 {
883 int great_wonder_count = 0, small_wonder_count = 0, building_count = 0;
884 int id;
885
886 improvement_iterate(pimprove) {
887 id = improvement_index(pimprove);
888 if (pv->data.v_built[id].turn < 0) {
889 continue;
890 }
891 if (is_great_wonder(pimprove)) {
892 great_wonder_count++;
893 } else if (is_small_wonder(pimprove)) {
894 small_wonder_count++;
895 } else {
896 building_count++;
897 }
899 /* TRANS: "Number of buildings, number of small
900 * wonders (e.g. palace), number of great wonders." */
901 return g_strdup_printf(_("%db %ds %dW"),
902 building_count, small_wonder_count,
903 great_wonder_count);
904 }
905
908 if (BV_ISSET(pv->data.v_bv_inventions, tech)) {
909 count++;
910 }
912 /* TRANS: "Number of technologies known". */
913 return g_strdup_printf(_("%d known"), count);
914
917 if (BV_ISSET(pv->data.v_bv_special, spe->data.special_idx)) {
918 count++;
919 }
921 /* TRANS: "The number of terrain specials (e.g. hut,
922 * river, pollution, etc.) present on a tile." */
923 return g_strdup_printf(_("%d present"), count);
924
925 case VALTYPE_BV_ROADS:
926 extra_type_by_cause_iterate(EC_ROAD, pextra) {
927 struct road_type *proad = extra_road_get(pextra);
928
929 if (BV_ISSET(pv->data.v_bv_roads, road_number(proad))) {
930 count++;
931 }
933 return g_strdup_printf(_("%d present"), count);
934
935 case VALTYPE_BV_BASES:
936 extra_type_by_cause_iterate(EC_BASE, pextra) {
937 struct base_type *pbase = extra_base_get(pextra);
938
939 if (BV_ISSET(pv->data.v_bv_bases, base_number(pbase))) {
940 count++;
941 }
943 return g_strdup_printf(_("%d present"), count);
944
946 count = nation_hash_size(pv->data.v_nation_hash);
947 if (0 == count) {
948 return g_strdup(_("All nations"));
949 } else {
950 return g_strdup_printf(PL_("%d nation", "%d nations",
951 count), count);
952 }
953
954 case VALTYPE_STRING:
955 /* Assume it is a very long string. */
956 count = strlen(pv->data.v_const_string);
957 return g_strdup_printf(PL_("%d byte", "%d bytes", count),
958 count);
959
960 case VALTYPE_PIXBUF:
962 break;
963 }
964
965 log_error("%s(): Unhandled value type %d for property value %p.",
966 __FUNCTION__, pv->valtype, pv);
967 return g_strdup("");
968}
969
970/************************************************************************/
974static gchar *built_status_to_string(struct built_status *bs)
975{
976 int turn_built;
977
978 turn_built = bs->turn;
979
980 if (turn_built == I_NEVER) {
981 /* TRANS: Improvement never built. */
982 return g_strdup(_("(never)"));
983 } else if (turn_built == I_DESTROYED) {
984 /* TRANS: Improvement was destroyed. */
985 return g_strdup(_("(destroyed)"));
986 } else {
987 return g_strdup_printf("%d", turn_built);
988 }
989}
990
991/************************************************************************/
995static bool can_create_unit_at_tile(struct tile *ptile)
996{
997 struct unit *vunit;
998 struct city *pcity;
999 struct player *pplayer;
1000 bool ret;
1001
1002 if (!ptile) {
1003 return FALSE;
1004 }
1005
1007 if (!vunit) {
1008 return FALSE;
1009 }
1010
1011 pcity = tile_city(ptile);
1012 pplayer = unit_owner(vunit);
1013
1014 ret = (can_unit_exist_at_tile(&(wld.map), vunit, ptile)
1015 && !is_non_allied_unit_tile(ptile, pplayer)
1016 && (pcity == NULL
1017 || pplayers_allied(city_owner(pcity),
1018 unit_owner(vunit))));
1019 free(vunit);
1020
1021 return ret;
1022}
1023
1024/************************************************************************/
1027static int get_next_unique_tag(void)
1028{
1029 static int tag_series = 0;
1030
1031 tag_series++;
1032 return tag_series;
1033}
1034
1035/************************************************************************/
1038static struct propval *propval_copy(struct propval *pv)
1039{
1040 struct propval *pv_copy;
1041 size_t size;
1042
1043 if (!pv) {
1044 return NULL;
1045 }
1046
1047 pv_copy = fc_calloc(1, sizeof(*pv));
1048 pv_copy->valtype = pv->valtype;
1049
1050 switch (pv->valtype) {
1051 case VALTYPE_NONE:
1052 return pv_copy;
1053 case VALTYPE_INT:
1054 pv_copy->data.v_int = pv->data.v_int;
1055 return pv_copy;
1056 case VALTYPE_BOOL:
1057 pv_copy->data.v_bool = pv->data.v_bool;
1058 return pv_copy;
1059 case VALTYPE_STRING:
1060 pv_copy->data.v_string = fc_strdup(pv->data.v_string);
1061 pv_copy->must_free = TRUE;
1062 return pv_copy;
1063 case VALTYPE_PIXBUF:
1064 g_object_ref(pv->data.v_pixbuf);
1065 pv_copy->data.v_pixbuf = pv->data.v_pixbuf;
1066 pv_copy->must_free = TRUE;
1067 return pv_copy;
1069 size = B_LAST * sizeof(struct built_status);
1070 pv_copy->data.v_pointer = fc_malloc(size);
1071 memcpy(pv_copy->data.v_pointer, pv->data.v_pointer, size);
1072 pv_copy->must_free = TRUE;
1073 return pv_copy;
1074 case VALTYPE_BV_SPECIAL:
1075 pv_copy->data.v_bv_special = pv->data.v_bv_special;
1076 return pv_copy;
1077 case VALTYPE_BV_ROADS:
1078 pv_copy->data.v_bv_roads = pv->data.v_bv_roads;
1079 return pv_copy;
1080 case VALTYPE_BV_BASES:
1081 pv_copy->data.v_bv_bases = pv->data.v_bv_bases;
1082 return pv_copy;
1083 case VALTYPE_NATION:
1084 pv_copy->data.v_nation = pv->data.v_nation;
1085 return pv_copy;
1086 case VALTYPE_GOV:
1087 pv_copy->data.v_gov = pv->data.v_gov;
1088 return pv_copy;
1090 pv_copy->data.v_nation_hash
1091 = nation_hash_copy(pv->data.v_nation_hash);
1092 pv_copy->must_free = TRUE;
1093 return pv_copy;
1096 return pv_copy;
1098 size = sizeof(struct tile_vision_data);
1099 pv_copy->data.v_tile_vision = fc_malloc(size);
1100 pv_copy->data.v_tile_vision->tile_known
1103 pv_copy->data.v_tile_vision->tile_seen[v]
1104 = pv->data.v_tile_vision->tile_seen[v];
1106 pv_copy->must_free = TRUE;
1107 return pv_copy;
1108 }
1109
1110 log_error("%s(): Unhandled value type %d for property value %p.",
1111 __FUNCTION__, pv->valtype, pv);
1112 pv_copy->data = pv->data;
1113 return pv_copy;
1114}
1115
1116/************************************************************************/
1120static void propval_free(struct propval *pv)
1121{
1122 if (!pv) {
1123 return;
1124 }
1125
1127 free(pv);
1128}
1129
1130/************************************************************************/
1134static void propval_free_data(struct propval *pv)
1135{
1136 if (!pv || !pv->must_free) {
1137 return;
1138 }
1139
1140 switch (pv->valtype) {
1141 case VALTYPE_NONE:
1142 case VALTYPE_INT:
1143 case VALTYPE_BOOL:
1144 case VALTYPE_BV_SPECIAL:
1145 case VALTYPE_BV_ROADS:
1146 case VALTYPE_BV_BASES:
1147 case VALTYPE_NATION:
1148 case VALTYPE_GOV:
1149 return;
1150 case VALTYPE_PIXBUF:
1151 g_object_unref(pv->data.v_pixbuf);
1152 return;
1153 case VALTYPE_STRING:
1157 free(pv->data.v_pointer);
1158 return;
1160 nation_hash_destroy(pv->data.v_nation_hash);
1161 return;
1162 }
1163
1164 log_error("%s(): Unhandled request to free data %p (type %s).",
1165 __FUNCTION__, pv->data.v_pointer, valtype_get_name(pv->valtype));
1166}
1167
1168/************************************************************************/
1171static bool propval_equal(struct propval *pva,
1172 struct propval *pvb)
1173{
1174 if (!pva || !pvb) {
1175 return pva == pvb;
1176 }
1177
1178 if (pva->valtype != pvb->valtype) {
1179 return FALSE;
1180 }
1181
1182 switch (pva->valtype) {
1183 case VALTYPE_NONE:
1184 return TRUE;
1185 case VALTYPE_INT:
1186 return pva->data.v_int == pvb->data.v_int;
1187 case VALTYPE_BOOL:
1188 return pva->data.v_bool == pvb->data.v_bool;
1189 case VALTYPE_STRING:
1190 if (pva->data.v_const_string != NULL
1191 && pvb->data.v_const_string != NULL) {
1192 return !strcmp(pva->data.v_const_string,
1193 pvb->data.v_const_string);
1194 }
1195 return pva->data.v_const_string == pvb->data.v_const_string;
1196 case VALTYPE_PIXBUF:
1197 return pva->data.v_pixbuf == pvb->data.v_pixbuf;
1199 if (pva->data.v_pointer == pvb->data.v_pointer) {
1200 return TRUE;
1201 } else if (!pva->data.v_pointer || !pvb->data.v_pointer) {
1202 return FALSE;
1203 }
1204
1205 improvement_iterate(pimprove) {
1206 int id, vatb, vbtb;
1207 id = improvement_index(pimprove);
1208 vatb = pva->data.v_built[id].turn;
1209 vbtb = pvb->data.v_built[id].turn;
1210 if (vatb < 0 && vbtb < 0) {
1211 continue;
1212 }
1213 if (vatb != vbtb) {
1214 return FALSE;
1215 }
1217 return TRUE;
1220 case VALTYPE_BV_SPECIAL:
1221 return BV_ARE_EQUAL(pva->data.v_bv_special, pvb->data.v_bv_special);
1222 case VALTYPE_BV_ROADS:
1223 return BV_ARE_EQUAL(pva->data.v_bv_roads, pvb->data.v_bv_roads);
1224 case VALTYPE_BV_BASES:
1225 return BV_ARE_EQUAL(pva->data.v_bv_bases, pvb->data.v_bv_bases);
1226 case VALTYPE_NATION:
1227 return pva->data.v_nation == pvb->data.v_nation;
1229 return nation_hashes_are_equal(pva->data.v_nation_hash,
1230 pvb->data.v_nation_hash);
1231 case VALTYPE_GOV:
1232 return pva->data.v_gov == pvb->data.v_gov;
1235 pvb->data.v_tile_vision->tile_known)) {
1236 return FALSE;
1237 }
1240 pvb->data.v_tile_vision->tile_seen[v])) {
1241 return FALSE;
1242 }
1244 return TRUE;
1245 }
1246
1247 log_error("%s(): Unhandled value type %d for property values %p and %p.",
1248 __FUNCTION__, pva->valtype, pva, pvb);
1249 return pva->data.v_pointer == pvb->data.v_pointer;
1250}
1251
1252/************************************************************************/
1258static struct propstate *propstate_new(struct objprop *op,
1259 struct propval *pv)
1260{
1261 struct propstate *ps;
1262
1263 if (!op) {
1264 return NULL;
1265 }
1266
1267 ps = fc_calloc(1, sizeof(*ps));
1268 ps->property_id = objprop_get_id(op);
1269 ps->property_value = pv;
1270
1271 return ps;
1272}
1273
1274/************************************************************************/
1277static void propstate_clear_value(struct propstate *ps)
1278{
1279 if (!ps) {
1280 return;
1281 }
1282
1284 ps->property_value = NULL;
1285}
1286
1287/************************************************************************/
1290static void propstate_destroy(struct propstate *ps)
1291{
1292 if (!ps) {
1293 return;
1294 }
1296 free(ps);
1297}
1298
1299/************************************************************************/
1305static void propstate_set_value(struct propstate *ps,
1306 struct propval *pv)
1307{
1308 if (!ps) {
1309 return;
1310 }
1312 ps->property_value = pv;
1313}
1314
1315/************************************************************************/
1320static struct propval *propstate_get_value(struct propstate *ps)
1321{
1322 if (!ps) {
1323 return NULL;
1324 }
1325 return ps->property_value;
1326}
1327
1328/************************************************************************/
1333 gpointer object)
1334{
1335 struct objbind *ob;
1336 int id;
1337
1338 if (object == NULL) {
1339 return NULL;
1340 }
1341
1342 id = objtype_get_id_from_object(objtype, object);
1343 if (id < 0) {
1344 return NULL;
1345 }
1346
1347 ob = fc_calloc(1, sizeof(*ob));
1348 ob->object_id = id;
1349 ob->objtype = objtype;
1350 ob->propstate_table = propstate_hash_new();
1351
1352 return ob;
1353}
1354
1355/************************************************************************/
1358static gpointer objbind_get_object(struct objbind *ob)
1359{
1360 int id;
1361
1362 if (!ob) {
1363 return NULL;
1364 }
1365
1366 id = objbind_get_object_id(ob);
1367
1368 return objtype_get_object_from_id(ob->objtype, id);
1369}
1370
1371/************************************************************************/
1374static int objbind_get_object_id(struct objbind *ob)
1375{
1376 if (NULL == ob) {
1377 return -1;
1378 }
1379 return ob->object_id;
1380}
1381
1382/************************************************************************/
1388{
1389 struct connection *my_conn = &client.conn;
1391 int id;
1392
1393 if (!ob) {
1394 return;
1395 }
1396
1399 return;
1400 }
1401
1402 id = objbind_get_object_id(ob);
1403
1404 switch (objtype) {
1405 case OBJTYPE_STARTPOS:
1406 dsend_packet_edit_startpos(my_conn, id, TRUE, 0);
1407 return;
1408 case OBJTYPE_UNIT:
1409 dsend_packet_edit_unit_remove_by_id(my_conn, id, id);
1410 return;
1411 case OBJTYPE_CITY:
1412 dsend_packet_edit_city_remove(my_conn, id, id);
1413 return;
1414 case OBJTYPE_PLAYER:
1416 return;
1417 case OBJTYPE_TILE:
1418 case OBJTYPE_GAME:
1419 case NUM_OBJTYPES:
1420 break;
1421 }
1422
1423 log_error("%s(): Unhandled request to destroy object %p (ID %d) of type "
1424 "%d (%s).", __FUNCTION__, objbind_get_object(ob), id, objtype,
1426}
1427
1428/************************************************************************/
1436 struct objprop *op)
1437{
1439 enum object_property_ids propid;
1440 struct propval *pv;
1441
1442 if (!ob || !op) {
1443 return NULL;
1444 }
1445
1447 propid = objprop_get_id(op);
1448
1449 pv = fc_calloc(1, sizeof(*pv));
1450 pv->valtype = objprop_get_valtype(op);
1451
1452 switch (objtype) {
1453 case OBJTYPE_TILE:
1454 {
1455 const struct tile *ptile = objbind_get_object(ob);
1456 int tile_x, tile_y, nat_x, nat_y;
1457
1458 if (NULL == ptile) {
1459 goto FAILED;
1460 }
1461
1462 index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
1464
1465 switch (propid) {
1466 case OPID_TILE_IMAGE:
1467 pv->data.v_pixbuf = create_tile_pixbuf(ptile);
1468 pv->must_free = TRUE;
1469 break;
1470#ifdef FREECIV_DEBUG
1471 case OPID_TILE_ADDRESS:
1472 pv->data.v_string = g_strdup_printf("%p", ptile);
1473 pv->must_free = TRUE;
1474 break;
1475#endif /* FREECIV_DEBUG */
1476 case OPID_TILE_TERRAIN:
1477 {
1478 const struct terrain *pterrain = tile_terrain(ptile);
1479
1480 if (NULL != pterrain) {
1482 } else {
1483 pv->data.v_const_string = "";
1484 }
1485 }
1486 break;
1487 case OPID_TILE_RESOURCE:
1488 {
1489 const struct extra_type *presource = tile_resource(ptile);
1490
1491 if (NULL != presource) {
1493 } else {
1494 pv->data.v_const_string = "";
1495 }
1496 }
1497 break;
1498 case OPID_TILE_XY:
1499 pv->data.v_string = g_strdup_printf("(%d, %d)", tile_x, tile_y);
1500 pv->must_free = TRUE;
1501 break;
1502 case OPID_TILE_INDEX:
1503 pv->data.v_int = tile_index(ptile);
1504 break;
1505 case OPID_TILE_X:
1506 pv->data.v_int = tile_x;
1507 break;
1508 case OPID_TILE_Y:
1509 pv->data.v_int = tile_y;
1510 break;
1511 case OPID_TILE_NAT_X:
1512 pv->data.v_int = nat_x;
1513 break;
1514 case OPID_TILE_NAT_Y:
1515 pv->data.v_int = nat_y;
1516 break;
1518 pv->data.v_int = ptile->continent;
1519 break;
1520 case OPID_TILE_SPECIALS:
1523 if (tile_has_extra(ptile, pextra)) {
1524 BV_SET(pv->data.v_bv_special, pextra->data.special_idx);
1525 }
1527 break;
1528 case OPID_TILE_ROADS:
1530 extra_type_by_cause_iterate(EC_ROAD, pextra) {
1531 if (tile_has_extra(ptile, pextra)) {
1533 }
1535 break;
1536 case OPID_TILE_BASES:
1538 extra_type_by_cause_iterate(EC_BASE, pextra) {
1539 if (tile_has_extra(ptile, pextra)) {
1541 }
1543 break;
1544 case OPID_TILE_VISION:
1545 pv->data.v_tile_vision = fc_malloc(sizeof(struct tile_vision_data));
1546
1547 /* The server saves the known tiles and the player vision in special
1548 * bitvectors with the number of tiles as index. Here we want the
1549 * information for one tile. Thus, the data is transformed to
1550 * bitvectors with the number of player slots as index. */
1552 players_iterate(pplayer) {
1553 if (dbv_isset(&pplayer->tile_known, tile_index(ptile))) {
1555 player_index(pplayer));
1556 }
1558
1561 players_iterate(pplayer) {
1562 if (fc_funcs->player_tile_vision_get(ptile, pplayer, v)) {
1564 player_index(pplayer));
1565 }
1568 pv->must_free = TRUE;
1569 break;
1570 case OPID_TILE_LABEL:
1571 if (ptile->label != NULL) {
1572 pv->data.v_const_string = ptile->label;
1573 } else {
1574 pv->data.v_const_string = "";
1575 }
1576 break;
1577 default:
1578 log_error("%s(): Unhandled request for value of property %d "
1579 "(%s) from object of type \"%s\".", __FUNCTION__,
1581 goto FAILED;
1582 }
1583 }
1584 return pv;
1585
1586 case OBJTYPE_STARTPOS:
1587 {
1588 const struct startpos *psp = objbind_get_object(ob);
1589 const struct tile *ptile;
1590
1591 if (NULL == psp) {
1592 goto FAILED;
1593 }
1594
1595 switch (propid) {
1597 ptile = startpos_tile(psp);
1598 pv->data.v_pixbuf = create_tile_pixbuf(ptile);
1599 pv->must_free = TRUE;
1600 break;
1601 case OPID_STARTPOS_XY:
1602 ptile = startpos_tile(psp);
1603 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1604 pv->must_free = TRUE;
1605 break;
1608 break;
1610 pv->data.v_nation_hash = nation_hash_copy(startpos_raw_nations(psp));
1611 pv->must_free = TRUE;
1612 break;
1613 default:
1614 log_error("%s(): Unhandled request for value of property %d "
1615 "(%s) from object of type \"%s\".", __FUNCTION__,
1617 goto FAILED;
1618 }
1619 }
1620 return pv;
1621
1622 case OBJTYPE_UNIT:
1623 {
1624 struct unit *punit = objbind_get_object(ob);
1625
1626 if (NULL == punit) {
1627 goto FAILED;
1628 }
1629
1630 switch (propid) {
1631 case OPID_UNIT_IMAGE:
1633 pv->must_free = TRUE;
1634 break;
1635#ifdef FREECIV_DEBUG
1636 case OPID_UNIT_ADDRESS:
1637 pv->data.v_string = g_strdup_printf("%p", punit);
1638 pv->must_free = TRUE;
1639 break;
1640#endif /* FREECIV_DEBUG */
1641 case OPID_UNIT_XY:
1642 {
1643 const struct tile *ptile = unit_tile(punit);
1644
1645 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1646 pv->must_free = TRUE;
1647 }
1648 break;
1649 case OPID_UNIT_ID:
1650 pv->data.v_int = punit->id;
1651 break;
1652 case OPID_UNIT_TYPE:
1653 {
1654 const struct unit_type *putype = unit_type_get(punit);
1655
1657 }
1658 break;
1660 pv->data.v_int = punit->moves_left;
1661 break;
1662 case OPID_UNIT_FUEL:
1663 pv->data.v_int = punit->fuel;
1664 break;
1665 case OPID_UNIT_MOVED:
1666 pv->data.v_bool = punit->moved;
1667 break;
1670 break;
1671 case OPID_UNIT_HP:
1672 pv->data.v_int = punit->hp;
1673 break;
1674 case OPID_UNIT_VETERAN:
1675 pv->data.v_int = punit->veteran;
1676 break;
1677 case OPID_UNIT_STAY:
1678 pv->data.v_bool = punit->stay;
1679 break;
1680 default:
1681 log_error("%s(): Unhandled request for value of property %d "
1682 "(%s) from object of type \"%s\".", __FUNCTION__,
1684 goto FAILED;
1685 }
1686 }
1687 return pv;
1688
1689 case OBJTYPE_CITY:
1690 {
1691 const struct city *pcity = objbind_get_object(ob);
1692
1693 if (NULL == pcity) {
1694 goto FAILED;
1695 }
1696
1697 switch (propid) {
1698 case OPID_CITY_IMAGE:
1699 pv->data.v_pixbuf = create_city_pixbuf(pcity);
1700 pv->must_free = TRUE;
1701 break;
1702#ifdef FREECIV_DEBUG
1703 case OPID_CITY_ADDRESS:
1704 pv->data.v_string = g_strdup_printf("%p", pcity);
1705 pv->must_free = TRUE;
1706 break;
1707#endif /* FREECIV_DEBUG */
1708 case OPID_CITY_XY:
1709 {
1710 const struct tile *ptile = city_tile(pcity);
1711
1712 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1713 pv->must_free = TRUE;
1714 }
1715 break;
1716 case OPID_CITY_ID:
1717 pv->data.v_int = pcity->id;
1718 break;
1719 case OPID_CITY_NAME:
1720 pv->data.v_const_string = pcity->name;
1721 break;
1722 case OPID_CITY_SIZE:
1723 pv->data.v_int = city_size_get(pcity);
1724 break;
1725 case OPID_CITY_HISTORY:
1726 pv->data.v_int = pcity->history;
1727 break;
1729 pv->data.v_built = fc_malloc(sizeof(pcity->built));
1730 memcpy(pv->data.v_built, pcity->built, sizeof(pcity->built));
1731 pv->must_free = TRUE;
1732 break;
1734 pv->data.v_int = pcity->food_stock;
1735 break;
1737 pv->data.v_int = pcity->shield_stock;
1738 break;
1739 default:
1740 log_error("%s(): Unhandled request for value of property %d "
1741 "(%s) from object of type \"%s\".", __FUNCTION__,
1743 goto FAILED;
1744 }
1745 }
1746 return pv;
1747
1748 case OBJTYPE_PLAYER:
1749 {
1750 const struct player *pplayer = objbind_get_object(ob);
1751 const struct research *presearch;
1752
1753 if (NULL == pplayer) {
1754 goto FAILED;
1755 }
1756
1757 switch (propid) {
1758 case OPID_PLAYER_NAME:
1759 pv->data.v_const_string = pplayer->name;
1760 break;
1761 case OPID_PLAYER_NATION:
1762 pv->data.v_nation = nation_of_player(pplayer);
1763 break;
1764 case OPID_PLAYER_GOV:
1765 pv->data.v_gov = pplayer->government;
1766 break;
1767 case OPID_PLAYER_AGE:
1768 pv->data.v_int = pplayer->turns_alive;
1769 break;
1770#ifdef FREECIV_DEBUG
1771 case OPID_PLAYER_ADDRESS:
1772 pv->data.v_string = g_strdup_printf("%p", pplayer);
1773 pv->must_free = TRUE;
1774 break;
1775#endif /* FREECIV_DEBUG */
1777 presearch = research_get(pplayer);
1780 if (TECH_KNOWN == research_invention_state(presearch, tech)) {
1781 BV_SET(pv->data.v_bv_inventions, tech);
1782 }
1784 break;
1786 pv->data.v_bool = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED);
1787 break;
1789 presearch = research_get(pplayer);
1790 pv->data.v_int = presearch->bulbs_researched;
1791 break;
1792 case OPID_PLAYER_GOLD:
1793 pv->data.v_int = pplayer->economic.gold;
1794 break;
1795 default:
1796 log_error("%s(): Unhandled request for value of property %d "
1797 "(%s) from object of type \"%s\".", __FUNCTION__,
1799 goto FAILED;
1800 }
1801 }
1802 return pv;
1803
1804 case OBJTYPE_GAME:
1805 {
1806 const struct civ_game *pgame = objbind_get_object(ob);
1807
1808 if (NULL == pgame) {
1809 goto FAILED;
1810 }
1811
1812 switch (propid) {
1813 case OPID_GAME_SCENARIO:
1814 pv->data.v_bool = pgame->scenario.is_scenario;
1815 break;
1817 pv->data.v_const_string = pgame->scenario.name;
1818 break;
1820 pv->data.v_const_string = pgame->scenario.authors;
1821 break;
1824 break;
1826 pv->data.v_bool = pgame->scenario.save_random;
1827 break;
1829 pv->data.v_bool = pgame->scenario.players;
1830 break;
1832 pv->data.v_bool = pgame->scenario.startpos_nations;
1833 break;
1836 break;
1838 pv->data.v_bool = pgame->scenario.lake_flooding;
1839 break;
1841 pv->data.v_bool = pgame->scenario.ruleset_locked;
1842 break;
1843 default:
1844 log_error("%s(): Unhandled request for value of property %d "
1845 "(%s) from object of type \"%s\".", __FUNCTION__,
1847 goto FAILED;
1848 }
1849 }
1850 return pv;
1851
1852 case NUM_OBJTYPES:
1853 break;
1854 }
1855
1856 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
1857 __FUNCTION__, objtype_get_name(objtype), objtype);
1858
1859FAILED:
1860 if (NULL != pv) {
1861 free(pv);
1862 }
1863 return NULL;
1864}
1865
1866/************************************************************************/
1871 struct objprop *op,
1872 double *pmin,
1873 double *pmax,
1874 double *pstep,
1875 double *pbig_step)
1876{
1878 enum object_property_ids propid;
1879 double dummy;
1880
1881 /* Fill the values with something. */
1882 if (NULL != pmin) {
1883 *pmin = 0;
1884 } else {
1885 pmin = &dummy;
1886 }
1887 if (NULL != pmax) {
1888 *pmax = 1;
1889 } else {
1890 pmax = &dummy;
1891 }
1892 if (NULL != pstep) {
1893 *pstep = 1;
1894 } else {
1895 pstep = &dummy;
1896 }
1897 if (NULL != pbig_step) {
1898 *pbig_step = 1;
1899 } else {
1900 pbig_step = &dummy;
1901 }
1902
1903 if (!ob || !op) {
1904 return FALSE;
1905 }
1906
1907 propid = objprop_get_id(op);
1909
1910 switch (objtype) {
1911 case OBJTYPE_TILE:
1912 case OBJTYPE_STARTPOS:
1913 log_error("%s(): Unhandled request for value range of property %d (%s) "
1914 "from object of type \"%s\".", __FUNCTION__,
1916 return FALSE;
1917
1918 case OBJTYPE_UNIT:
1919 {
1920 const struct unit *punit = objbind_get_object(ob);
1921 const struct unit_type *putype;
1922
1923 if (NULL == punit) {
1924 return FALSE;
1925 }
1926
1927 putype = unit_type_get(punit);
1928
1929 switch (propid) {
1931 *pmin = 0;
1932 *pmax = MAX_MOVE_FRAGS;
1933 *pstep = 1;
1934 *pbig_step = 5;
1935 return TRUE;
1936 case OPID_UNIT_FUEL:
1937 *pmin = 0;
1938 *pmax = utype_fuel(putype);
1939 *pstep = 1;
1940 *pbig_step = 5;
1941 return TRUE;
1942 case OPID_UNIT_HP:
1943 *pmin = 1;
1944 *pmax = putype->hp;
1945 *pstep = 1;
1946 *pbig_step = 10;
1947 return TRUE;
1948 case OPID_UNIT_VETERAN:
1949 *pmin = 0;
1950 *pmax = utype_veteran_levels(putype) - 1;
1951 *pstep = 1;
1952 *pbig_step = 3;
1953 return TRUE;
1954 default:
1955 break;
1956 }
1957 }
1958 log_error("%s(): Unhandled request for value range of property %d (%s) "
1959 "from object of type \"%s\".", __FUNCTION__,
1961 return FALSE;
1962
1963 case OBJTYPE_CITY:
1964 {
1965 const struct city *pcity = objbind_get_object(ob);
1966
1967 if (NULL == pcity) {
1968 return FALSE;
1969 }
1970
1971 switch (propid) {
1972 case OPID_CITY_SIZE:
1973 *pmin = 1;
1974 *pmax = MAX_CITY_SIZE;
1975 *pstep = 1;
1976 *pbig_step = 5;
1977 return TRUE;
1978 case OPID_CITY_HISTORY:
1979 *pmin = 0;
1980 *pmax = USHRT_MAX;
1981 *pstep = 1;
1982 *pbig_step = 10;
1983 return TRUE;
1985 *pmin = 0;
1986 *pmax = city_granary_size(city_size_get(pcity));
1987 *pstep = 1;
1988 *pbig_step = 5;
1989 return TRUE;
1991 *pmin = 0;
1992 *pmax = USHRT_MAX; /* Limited to uint16 by city info packet. */
1993 *pstep = 1;
1994 *pbig_step = 10;
1995 return TRUE;
1996 default:
1997 break;
1998 }
1999 }
2000 log_error("%s(): Unhandled request for value range of property %d (%s) "
2001 "from object of type \"%s\".", __FUNCTION__,
2003 return FALSE;
2004
2005 case OBJTYPE_PLAYER:
2006 switch (propid) {
2008 *pmin = 0;
2009 *pmax = 1000000; /* Arbitrary. */
2010 *pstep = 1;
2011 *pbig_step = 100;
2012 return TRUE;
2013 case OPID_PLAYER_GOLD:
2014 *pmin = 0;
2015 *pmax = 1000000; /* Arbitrary. */
2016 *pstep = 1;
2017 *pbig_step = 100;
2018 return TRUE;
2019 default:
2020 break;
2021 }
2022 log_error("%s(): Unhandled request for value range of property %d (%s) "
2023 "from object of type \"%s\".", __FUNCTION__,
2025 return FALSE;
2026
2027 case OBJTYPE_GAME:
2028 log_error("%s(): Unhandled request for value range of property %d (%s) "
2029 "from object of type \"%s\".", __FUNCTION__,
2031 return FALSE;
2032
2033 case NUM_OBJTYPES:
2034 break;
2035 }
2036
2037 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
2038 __FUNCTION__, objtype_get_name(objtype), objtype);
2039 return FALSE;
2040}
2041
2042/************************************************************************/
2046 struct objprop *op)
2047{
2048 if (!ob || !op || !ob->propstate_table) {
2049 return;
2050 }
2051
2052 propstate_hash_remove(ob->propstate_table, objprop_get_id(op));
2053}
2054
2055/************************************************************************/
2060 struct objprop *op)
2061{
2062 if (!ob || !op) {
2063 return FALSE;
2064 }
2065
2066 if (objprop_is_readonly(op)) {
2067 return FALSE;
2068 }
2069
2070 return propstate_hash_lookup(ob->propstate_table,
2071 objprop_get_id(op), NULL);
2072}
2073
2074/************************************************************************/
2079{
2080 if (!ob) {
2081 return FALSE;
2082 }
2083
2084 return (0 < propstate_hash_size(ob->propstate_table));
2085}
2086
2087/************************************************************************/
2091{
2092 if (!ob) {
2093 return;
2094 }
2095 propstate_hash_clear(ob->propstate_table);
2096}
2097
2098/************************************************************************/
2105 struct objprop *op,
2106 struct propval *pv)
2107{
2108 struct propstate *ps;
2109 bool equal;
2110 struct propval *pv_old, *pv_copy;
2111 enum object_property_ids propid;
2112
2113 if (!ob || !op) {
2114 return FALSE;
2115 }
2116
2117 propid = objprop_get_id(op);
2118
2119 pv_old = objbind_get_value_from_object(ob, op);
2120 if (!pv_old) {
2121 return FALSE;
2122 }
2123
2124 equal = propval_equal(pv, pv_old);
2125 propval_free(pv_old);
2126
2127 if (equal) {
2129 return FALSE;
2130 }
2131
2132 pv_copy = propval_copy(pv);
2133
2134 if (propstate_hash_lookup(ob->propstate_table, propid, &ps)) {
2135 propstate_set_value(ps, pv_copy);
2136 } else {
2137 ps = propstate_new(op, pv_copy);
2138 propstate_hash_insert(ob->propstate_table, propid, ps);
2139 }
2140
2141 return TRUE;
2142}
2143
2144/************************************************************************/
2151 struct objprop *op)
2152{
2153 struct propstate *ps;
2154
2155 if (!ob || !op) {
2156 return NULL;
2157 }
2158
2159 if (propstate_hash_lookup(ob->propstate_table, objprop_get_id(op), &ps)) {
2160 return propstate_get_value(ps);
2161 } else {
2162 return NULL;
2163 }
2164}
2165
2166/************************************************************************/
2169static void objbind_destroy(struct objbind *ob)
2170{
2171 if (!ob) {
2172 return;
2173 }
2174 if (ob->propstate_table) {
2175 propstate_hash_destroy(ob->propstate_table);
2176 ob->propstate_table = NULL;
2177 }
2178 if (ob->rowref) {
2179 gtk_tree_row_reference_free(ob->rowref);
2180 ob->rowref = NULL;
2181 }
2182 free(ob);
2183}
2184
2185/************************************************************************/
2189{
2190 if (!ob) {
2191 return NUM_OBJTYPES;
2192 }
2193 return ob->objtype;
2194}
2195
2196/************************************************************************/
2199static void objbind_bind_properties(struct objbind *ob,
2200 struct property_page *pp)
2201{
2202 if (!ob) {
2203 return;
2204 }
2205 ob->parent_property_page = pp;
2206}
2207
2208/************************************************************************/
2214 union packetdata pd)
2215{
2217
2218 if (!ob || !pd.pointers.v_pointer1) {
2219 return;
2220 }
2221
2223
2224 switch (objtype) {
2225 case OBJTYPE_TILE:
2226 {
2227 struct packet_edit_tile *packet = pd.tile;
2228 const struct tile *ptile = objbind_get_object(ob);
2229
2230 if (NULL == ptile) {
2231 return;
2232 }
2233
2234 packet->tile = tile_index(ptile);
2235 packet->extras = *tile_extras(ptile);
2236 /* TODO: Set more packet fields. */
2237 }
2238 return;
2239
2240 case OBJTYPE_STARTPOS:
2241 {
2242 struct packet_edit_startpos_full *packet = pd.startpos;
2243 const struct startpos *psp = objbind_get_object(ob);
2244
2245 if (NULL != psp) {
2246 startpos_pack(psp, packet);
2247 }
2248 }
2249 return;
2250
2251 case OBJTYPE_UNIT:
2252 {
2253 struct packet_edit_unit *packet = pd.unit;
2254 const struct unit *punit = objbind_get_object(ob);
2255
2256 if (NULL == punit) {
2257 return;
2258 }
2259
2260 packet->id32 = punit->id;
2261 packet->id16 = packet->id32;
2262 packet->moves_left = punit->moves_left;
2263 packet->fuel = punit->fuel;
2264 packet->moved = punit->moved;
2265 packet->done_moving = punit->done_moving;
2266 packet->hp = punit->hp;
2267 packet->veteran = punit->veteran;
2268 packet->stay = punit->stay;
2269 /* TODO: Set more packet fields. */
2270 }
2271 return;
2272
2273 case OBJTYPE_CITY:
2274 {
2275 struct packet_edit_city *packet = pd.city;
2276 const struct city *pcity = objbind_get_object(ob);
2277 int i;
2278
2279 if (NULL == pcity) {
2280 return;
2281 }
2282
2283 packet->id32 = pcity->id;
2284 packet->id16 = packet->id32;
2285 sz_strlcpy(packet->name, pcity->name);
2286 packet->size = city_size_get(pcity);
2287 packet->history = pcity->history;
2288 for (i = 0; i < B_LAST; i++) {
2289 packet->built[i] = pcity->built[i].turn;
2290 }
2291 packet->food_stock = pcity->food_stock;
2292 packet->shield_stock = pcity->shield_stock;
2293 /* TODO: Set more packet fields. */
2294 }
2295 return;
2296
2297 case OBJTYPE_PLAYER:
2298 {
2299 struct packet_edit_player *packet = pd.player;
2300 const struct player *pplayer = objbind_get_object(ob);
2301 const struct nation_type *pnation;
2302 const struct research *presearch;
2303
2304 if (NULL == pplayer) {
2305 return;
2306 }
2307
2308 packet->id = player_number(pplayer);
2309 sz_strlcpy(packet->name, pplayer->name);
2310 pnation = nation_of_player(pplayer);
2311 packet->nation = nation_index(pnation);
2312 presearch = research_get(pplayer);
2314 packet->inventions[tech]
2315 = TECH_KNOWN == research_invention_state(presearch, tech);
2317 packet->gold = pplayer->economic.gold;
2318 packet->government = government_index(pplayer->government);
2319 packet->scenario_reserved = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED);
2320 /* TODO: Set more packet fields. */
2321 }
2322 return;
2323
2324 case OBJTYPE_GAME:
2325 {
2326 struct packet_edit_game *packet = pd.game.game;
2327 const struct civ_game *pgame = objbind_get_object(ob);
2328
2329 if (NULL == pgame) {
2330 return;
2331 }
2332
2333 packet->scenario = pgame->scenario.is_scenario;
2334 sz_strlcpy(packet->scenario_name, pgame->scenario.name);
2336 sz_strlcpy(pd.game.desc->scenario_desc, pgame->scenario_desc.description);
2337 packet->scenario_random = pgame->scenario.save_random;
2338 packet->scenario_players = pgame->scenario.players;
2341 packet->lake_flooding = pgame->scenario.lake_flooding;
2342 }
2343 return;
2344
2345 case NUM_OBJTYPES:
2346 break;
2347 }
2348
2349 log_error("%s(): Unhandled object type %s (nb %d).", __FUNCTION__,
2351}
2352
2353/************************************************************************/
2357 struct objprop *op,
2358 union packetdata pd)
2359{
2360 struct propval *pv;
2362 enum object_property_ids propid;
2363
2364 if (!op || !ob || !pd.pointers.v_pointer1) {
2365 return;
2366 }
2367
2368 if (NULL == objbind_get_object(ob)) {
2369 return;
2370 }
2371
2373 return;
2374 }
2375
2376 pv = objbind_get_modified_value(ob, op);
2377 if (!pv) {
2378 return;
2379 }
2380
2382 propid = objprop_get_id(op);
2383
2384 switch (objtype) {
2385 case OBJTYPE_TILE:
2386 {
2387 struct packet_edit_tile *packet = pd.tile;
2388
2389 switch (propid) {
2390 case OPID_TILE_SPECIALS:
2392 if (BV_ISSET(pv->data.v_bv_special, pextra->data.special_idx)) {
2393 BV_SET(packet->extras, pextra->data.special_idx);
2394 } else {
2395 BV_CLR(packet->extras, pextra->data.special_idx);
2396 }
2398 return;
2399 case OPID_TILE_ROADS:
2400 extra_type_by_cause_iterate(EC_ROAD, pextra) {
2401 int ridx = road_number(extra_road_get(pextra));
2402
2403 if (BV_ISSET(pv->data.v_bv_roads, ridx)) {
2404 BV_SET(packet->extras, extra_index(pextra));
2405 } else {
2406 BV_CLR(packet->extras, extra_index(pextra));
2407 }
2409 return;
2410 case OPID_TILE_BASES:
2411 extra_type_by_cause_iterate(EC_BASE, pextra) {
2412 int bidx = base_number(extra_base_get(pextra));
2413
2414 if (BV_ISSET(pv->data.v_bv_bases, bidx)) {
2415 BV_SET(packet->extras, extra_index(pextra));
2416 } else {
2417 BV_CLR(packet->extras, extra_index(pextra));
2418 }
2420 return;
2421 case OPID_TILE_LABEL:
2422 sz_strlcpy(packet->label, pv->data.v_string);
2423 return;
2424 default:
2425 break;
2426 }
2427 }
2428 log_error("%s(): Unhandled request to pack value of property "
2429 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2431 return;
2432
2433 case OBJTYPE_STARTPOS:
2434 {
2435 struct packet_edit_startpos_full *packet = pd.startpos;
2436
2437 switch (propid) {
2439 packet->exclude = pv->data.v_bool;
2440 return;
2442 BV_CLR_ALL(packet->nations);
2443 nation_hash_iterate(pv->data.v_nation_hash, pnation) {
2444 BV_SET(packet->nations, nation_number(pnation));
2446 return;
2447 default:
2448 break;
2449 }
2450 }
2451 log_error("%s(): Unhandled request to pack value of property "
2452 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2454 return;
2455
2456 case OBJTYPE_UNIT:
2457 {
2458 struct packet_edit_unit *packet = pd.unit;
2459
2460 switch (propid) {
2462 packet->moves_left = pv->data.v_int;
2463 return;
2464 case OPID_UNIT_FUEL:
2465 packet->fuel = pv->data.v_int;
2466 return;
2467 case OPID_UNIT_MOVED:
2468 packet->moved = pv->data.v_bool;
2469 return;
2471 packet->done_moving = pv->data.v_bool;
2472 return;
2473 case OPID_UNIT_HP:
2474 packet->hp = pv->data.v_int;
2475 return;
2476 case OPID_UNIT_VETERAN:
2477 packet->veteran = pv->data.v_int;
2478 return;
2479 case OPID_UNIT_STAY:
2480 packet->stay = pv->data.v_bool;
2481 return;
2482 default:
2483 break;
2484 }
2485 }
2486 log_error("%s(): Unhandled request to pack value of property "
2487 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2489 return;
2490
2491 case OBJTYPE_CITY:
2492 {
2493 struct packet_edit_city *packet = pd.city;
2494
2495 switch (propid) {
2496 case OPID_CITY_NAME:
2497 sz_strlcpy(packet->name, pv->data.v_string);
2498 return;
2499 case OPID_CITY_SIZE:
2500 packet->size = pv->data.v_int;
2501 return;
2502 case OPID_CITY_HISTORY:
2503 packet->history = pv->data.v_int;
2504 return;
2506 packet->food_stock = pv->data.v_int;
2507 return;
2509 packet->shield_stock = pv->data.v_int;
2510 return;
2512 {
2513 int i;
2514
2515 for (i = 0; i < B_LAST; i++) {
2516 packet->built[i] = pv->data.v_built[i].turn;
2517 }
2518 }
2519 return;
2520 default:
2521 break;
2522 }
2523 }
2524 log_error("%s(): Unhandled request to pack value of property "
2525 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2527 return;
2528
2529 case OBJTYPE_PLAYER:
2530 {
2531 struct packet_edit_player *packet = pd.player;
2532
2533 switch (propid) {
2534 case OPID_PLAYER_NAME:
2535 sz_strlcpy(packet->name, pv->data.v_string);
2536 return;
2537 case OPID_PLAYER_NATION:
2538 packet->nation = nation_index(pv->data.v_nation);
2539 return;
2540 case OPID_PLAYER_GOV:
2541 packet->government = government_index(pv->data.v_gov);
2542 return;
2545 packet->inventions[tech] = BV_ISSET(pv->data.v_bv_inventions, tech);
2547 return;
2549 packet->scenario_reserved = pv->data.v_bool;
2550 return;
2552 packet->bulbs_researched = pv->data.v_int;
2553 return;
2554 case OPID_PLAYER_GOLD:
2555 packet->gold = pv->data.v_int;
2556 return;
2557 default:
2558 break;
2559 }
2560 }
2561 log_error("%s(): Unhandled request to pack value of property "
2562 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2564 return;
2565
2566 case OBJTYPE_GAME:
2567 {
2568 struct packet_edit_game *packet = pd.game.game;
2569
2570 switch (propid) {
2571 case OPID_GAME_SCENARIO:
2572 packet->scenario = pv->data.v_bool;
2573 return;
2576 return;
2579 return;
2581 sz_strlcpy(pd.game.desc->scenario_desc, pv->data.v_const_string);
2582 return;
2584 packet->scenario_random = pv->data.v_bool;
2585 return;
2587 packet->scenario_players = pv->data.v_bool;
2588 return;
2590 packet->startpos_nations = pv->data.v_bool;
2591 return;
2593 packet->prevent_new_cities = pv->data.v_bool;
2594 return;
2596 packet->lake_flooding = pv->data.v_bool;
2597 return;
2599 packet->ruleset_locked = pv->data.v_bool;
2600 return;
2601 default:
2602 break;
2603 }
2604 }
2605 log_error("%s(): Unhandled request to pack value of property "
2606 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2608 return;
2609
2610 case NUM_OBJTYPES:
2611 break;
2612 }
2613
2614 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
2615 __FUNCTION__, objtype_get_name(objtype), objtype);
2616
2617}
2618
2619/************************************************************************/
2622static void objbind_set_rowref(struct objbind *ob,
2623 GtkTreeRowReference *rr)
2624{
2625 if (!ob) {
2626 return;
2627 }
2628 ob->rowref = rr;
2629}
2630
2631/************************************************************************/
2634static GtkTreeRowReference *objbind_get_rowref(struct objbind *ob)
2635{
2636 if (!ob) {
2637 return NULL;
2638 }
2639 return ob->rowref;
2640}
2641
2642/************************************************************************/
2645static int objprop_get_id(const struct objprop *op)
2646{
2647 if (!op) {
2648 return -1;
2649 }
2650 return op->id;
2651}
2652
2653/************************************************************************/
2660static GType objprop_get_gtype(const struct objprop *op)
2661{
2662 fc_assert_ret_val(NULL != op, G_TYPE_NONE);
2663
2664 switch (op->valtype) {
2665 case VALTYPE_NONE:
2667 return G_TYPE_NONE;
2668 case VALTYPE_INT:
2669 return G_TYPE_INT;
2670 case VALTYPE_BOOL:
2671 /* We want to show it as translated string, not as untranslated G_TYPE_BOOLEAN */
2672 return G_TYPE_STRING;
2673 case VALTYPE_STRING:
2676 case VALTYPE_BV_SPECIAL:
2677 case VALTYPE_BV_ROADS:
2678 case VALTYPE_BV_BASES:
2680 return G_TYPE_STRING;
2681 case VALTYPE_PIXBUF:
2682 case VALTYPE_NATION:
2683 case VALTYPE_GOV:
2684 return GDK_TYPE_PIXBUF;
2685 }
2686 log_error("%s(): Unhandled value type %d.", __FUNCTION__, op->valtype);
2687 return G_TYPE_NONE;
2688}
2689
2690/************************************************************************/
2693static enum value_types objprop_get_valtype(const struct objprop *op)
2694{
2695 if (!op) {
2696 return VALTYPE_NONE;
2697 }
2698 return op->valtype;
2699}
2700
2701/************************************************************************/
2704static bool objprop_show_in_listview(const struct objprop *op)
2705{
2706 if (!op) {
2707 return FALSE;
2708 }
2709 return op->flags & OPF_IN_LISTVIEW;
2710}
2711
2712/************************************************************************/
2715static bool objprop_has_widget(const struct objprop *op)
2716{
2717 if (!op) {
2718 return FALSE;
2719 }
2720 return op->flags & OPF_HAS_WIDGET;
2721}
2722
2723/************************************************************************/
2729static const char *objprop_get_attribute_type_string(const struct objprop *op)
2730{
2731 GType gtype;
2732
2733 if (!op) {
2734 return NULL;
2735 }
2736
2737 gtype = objprop_get_gtype(op);
2738 if (gtype == G_TYPE_INT || gtype == G_TYPE_STRING
2739 || gtype == G_TYPE_BOOLEAN) {
2740 return "text";
2741 } else if (gtype == GDK_TYPE_PIXBUF) {
2742 return "pixbuf";
2743 }
2744
2745 return NULL;
2746}
2747
2748/************************************************************************/
2754static void objprop_set_column_id(struct objprop *op, int col_id)
2755{
2756 if (!op) {
2757 return;
2758 }
2759 op->column_id = col_id;
2760}
2761
2762/************************************************************************/
2767static int objprop_get_column_id(const struct objprop *op)
2768{
2769 if (!op) {
2770 return -1;
2771 }
2772 return op->column_id;
2773}
2774
2775/************************************************************************/
2779 GtkTreeViewColumn *col)
2780{
2781 if (!op) {
2782 return;
2783 }
2784 op->view_column = col;
2785}
2786
2787/************************************************************************/
2791static GtkTreeViewColumn *objprop_get_treeview_column(const struct objprop *op)
2792{
2793 if (!op) {
2794 return NULL;
2795 }
2796 return op->view_column;
2797}
2798
2799/************************************************************************/
2802static const char *objprop_get_name(const struct objprop *op)
2803{
2804 if (!op) {
2805 return NULL;
2806 }
2807 return op->name;
2808}
2809
2810/************************************************************************/
2813static const char *objprop_get_tooltip(const struct objprop *op)
2814{
2815 if (!op) {
2816 return NULL;
2817 }
2818 return op->tooltip;
2819}
2820
2821/************************************************************************/
2826static GtkCellRenderer *objprop_create_cell_renderer(const struct objprop *op)
2827{
2828 GtkCellRenderer *cell = NULL;
2829 GType gtype;
2830
2831 gtype = objprop_get_gtype(op);
2832
2833 if (gtype == G_TYPE_INT || gtype == G_TYPE_STRING
2834 || gtype == G_TYPE_BOOLEAN) {
2835 cell = gtk_cell_renderer_text_new();
2836 } else if (gtype == GDK_TYPE_PIXBUF) {
2837 cell = gtk_cell_renderer_pixbuf_new();
2838 }
2839
2840 return cell;
2841}
2842
2843/************************************************************************/
2847static bool objprop_is_sortable(const struct objprop *op)
2848{
2849 GType gtype;
2850 if (!op) {
2851 return FALSE;
2852 }
2853 gtype = objprop_get_gtype(op);
2854 return gtype == G_TYPE_INT || gtype == G_TYPE_STRING;
2855}
2856
2857/************************************************************************/
2861static bool objprop_is_readonly(const struct objprop *op)
2862{
2863 if (!op) {
2864 return TRUE;
2865 }
2866 return !(op->flags & OPF_EDITABLE);
2867}
2868
2869/************************************************************************/
2872static void objprop_widget_text_changed(GtkEditable *text, gpointer userdata)
2873{
2874 struct objprop *op;
2875 struct property_page *pp;
2876 struct propval value = {{0,}, VALTYPE_STRING, FALSE};
2877
2878 op = userdata;
2880 value.data.v_const_string = gtk_entry_buffer_get_text(gtk_text_get_buffer(GTK_TEXT(text)));
2881
2882 property_page_change_value(pp, op, &value);
2883}
2884
2885/************************************************************************/
2888static void objprop_widget_spin_button_changed(GtkSpinButton *spin,
2889 gpointer userdata)
2890{
2891 struct objprop *op;
2892 struct property_page *pp;
2893 struct propval value = {{0,}, VALTYPE_INT, FALSE};
2894
2895 op = userdata;
2897 value.data.v_int = gtk_spin_button_get_value_as_int(spin);
2898
2899 property_page_change_value(pp, op, &value);
2900}
2901
2902/************************************************************************/
2905static void objprop_widget_toggle_button_changed(GtkToggleButton *button,
2906 gpointer userdata)
2907{
2908 struct objprop *op;
2909 struct property_page *pp;
2910 struct propval value = {{0,}, VALTYPE_BOOL, FALSE};
2911
2912 op = userdata;
2914 value.data.v_bool = gtk_toggle_button_get_active(button);
2915
2916 property_page_change_value(pp, op, &value);
2917}
2918
2919/************************************************************************/
2922static void objprop_setup_widget(struct objprop *op)
2923{
2924 GtkWidget *hbox, *hbox2, *label, *image, *text, *spin, *button;
2925 struct extviewer *ev = NULL;
2926 enum object_property_ids propid;
2927
2928 if (!op) {
2929 return;
2930 }
2931
2932 if (!objprop_has_widget(op)) {
2933 return;
2934 }
2935
2936 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
2937 op->widget = hbox;
2938
2939 label = gtk_label_new(objprop_get_name(op));
2940 gtk_widget_set_halign(label, GTK_ALIGN_START);
2941 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
2942 gtk_box_append(GTK_BOX(hbox), label);
2943 objprop_set_child_widget(op, "name-label", label);
2944
2945 propid = objprop_get_id(op);
2946
2947 switch (propid) {
2948 case OPID_TILE_INDEX:
2949 case OPID_TILE_X:
2950 case OPID_TILE_Y:
2951 case OPID_TILE_NAT_X:
2952 case OPID_TILE_NAT_Y:
2954 case OPID_TILE_TERRAIN:
2955 case OPID_TILE_RESOURCE:
2956 case OPID_TILE_XY:
2957 case OPID_STARTPOS_XY:
2958 case OPID_UNIT_ID:
2959 case OPID_UNIT_XY:
2960 case OPID_UNIT_TYPE:
2961 case OPID_CITY_ID:
2962 case OPID_CITY_XY:
2963 case OPID_PLAYER_AGE:
2964#ifdef FREECIV_DEBUG
2965 case OPID_TILE_ADDRESS:
2966 case OPID_UNIT_ADDRESS:
2967 case OPID_CITY_ADDRESS:
2968 case OPID_PLAYER_ADDRESS:
2969#endif /* FREECIV_DEBUG */
2970 label = gtk_label_new(NULL);
2971 gtk_widget_set_hexpand(label, TRUE);
2972 gtk_widget_set_halign(label, GTK_ALIGN_START);
2973 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
2974 gtk_box_append(GTK_BOX(hbox), label);
2975 objprop_set_child_widget(op, "value-label", label);
2976 return;
2977
2978 case OPID_TILE_IMAGE:
2980 case OPID_UNIT_IMAGE:
2981 case OPID_CITY_IMAGE:
2982 image = gtk_image_new();
2983 gtk_widget_set_size_request(image,
2986 gtk_widget_set_hexpand(image, TRUE);
2987 gtk_widget_set_halign(image, GTK_ALIGN_START);
2988 gtk_widget_set_valign(image, GTK_ALIGN_CENTER);
2989 gtk_box_append(GTK_BOX(hbox), image);
2990 objprop_set_child_widget(op, "image", image);
2991 return;
2992
2993 case OPID_CITY_NAME:
2994 case OPID_PLAYER_NAME:
2996 case OPID_TILE_LABEL:
2997 text = gtk_text_new();
2998 gtk_widget_set_hexpand(text, TRUE);
2999 gtk_widget_set_halign(text, GTK_ALIGN_END);
3000 gtk_editable_set_width_chars(GTK_EDITABLE(text), 8);
3001 g_signal_connect(text, "changed",
3002 G_CALLBACK(objprop_widget_text_changed), op);
3003 gtk_box_append(GTK_BOX(hbox), text);
3004 objprop_set_child_widget(op, "text", text);
3005 return;
3006
3008 case OPID_CITY_SIZE:
3009 case OPID_CITY_HISTORY:
3012 case OPID_PLAYER_GOLD:
3013 spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
3014 gtk_widget_set_hexpand(spin, TRUE);
3015 gtk_widget_set_halign(spin, GTK_ALIGN_END);
3016 g_signal_connect(spin, "value-changed",
3017 G_CALLBACK(objprop_widget_spin_button_changed), op);
3018 gtk_box_append(GTK_BOX(hbox), spin);
3019 objprop_set_child_widget(op, "spin", spin);
3020 return;
3021
3022 case OPID_UNIT_FUEL:
3023 case OPID_UNIT_HP:
3024 case OPID_UNIT_VETERAN:
3026 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
3027 gtk_widget_set_hexpand(hbox2, TRUE);
3028 gtk_widget_set_halign(hbox2, GTK_ALIGN_END);
3029 gtk_box_append(GTK_BOX(hbox), hbox2);
3030 spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
3031 g_signal_connect(spin, "value-changed",
3032 G_CALLBACK(objprop_widget_spin_button_changed), op);
3033 gtk_box_append(GTK_BOX(hbox2), spin);
3034 objprop_set_child_widget(op, "spin", spin);
3035 label = gtk_label_new(NULL);
3036 gtk_widget_set_halign(label, GTK_ALIGN_START);
3037 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
3038 gtk_box_append(GTK_BOX(hbox2), label);
3039 objprop_set_child_widget(op, "max-value-label", label);
3040 return;
3041
3042 case OPID_TILE_SPECIALS:
3043 case OPID_TILE_ROADS:
3044 case OPID_TILE_BASES:
3045 case OPID_TILE_VISION:
3048 case OPID_PLAYER_NATION:
3049 case OPID_PLAYER_GOV:
3053 ev = extviewer_new(op);
3054 objprop_set_extviewer(op, ev);
3055 gtk_widget_set_hexpand(extviewer_get_panel_widget(ev), TRUE);
3056 gtk_widget_set_halign(extviewer_get_panel_widget(ev), GTK_ALIGN_END);
3057 gtk_box_append(GTK_BOX(hbox), extviewer_get_panel_widget(ev));
3059 return;
3060
3062 case OPID_UNIT_MOVED:
3064 case OPID_UNIT_STAY:
3065 case OPID_GAME_SCENARIO:
3073 button = gtk_toggle_button_new();
3074 gtk_widget_set_hexpand(button, TRUE);
3075 gtk_widget_set_halign(button, GTK_ALIGN_END);
3076 g_signal_connect(button, "toggled",
3078 op);
3079 gtk_box_append(GTK_BOX(hbox), button);
3080 objprop_set_child_widget(op, "togglebutton", button);
3081 return;
3082 }
3083
3084 log_error("%s(): Unhandled request to create widget for property %d (%s).",
3085 __FUNCTION__, propid, objprop_get_name(op));
3086}
3087
3088/************************************************************************/
3096static void objprop_refresh_widget(struct objprop *op,
3097 struct objbind *ob)
3098{
3099 GtkWidget *w, *label, *image, *text, *spin, *button;
3100 struct extviewer *ev;
3101 struct propval *pv;
3102 bool modified;
3103 enum object_property_ids propid;
3104 double min, max, step, big_step;
3105 char buf[256];
3106 const char *newtext;
3107 GtkEntryBuffer *buffer;
3108
3109 if (!op || !objprop_has_widget(op)) {
3110 return;
3111 }
3112
3113 w = objprop_get_widget(op);
3114 if (!w) {
3115 return;
3116 }
3117
3118 propid = objprop_get_id(op);
3119
3120 /* NB: We must take care to propval_free() the return value of
3121 * objbind_get_value_from_object(), since it always makes a
3122 * copy, but to NOT free the result of objbind_get_modified_value()
3123 * since it returns its own stored value. */
3124 pv = objbind_get_value_from_object(ob, op);
3125 modified = objbind_property_is_modified(ob, op);
3126
3127 if (pv && modified) {
3128 struct propval *pv_mod;
3129
3130 pv_mod = objbind_get_modified_value(ob, op);
3131 if (pv_mod) {
3132 if (propval_equal(pv, pv_mod)) {
3134 modified = FALSE;
3135 } else {
3136 propval_free(pv);
3137 pv = pv_mod;
3138 modified = TRUE;
3139 }
3140 } else {
3141 modified = FALSE;
3142 }
3143 }
3144
3145 switch (propid) {
3146 case OPID_TILE_IMAGE:
3148 case OPID_UNIT_IMAGE:
3149 case OPID_CITY_IMAGE:
3150 image = objprop_get_child_widget(op, "image");
3151 if (pv) {
3152 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pv->data.v_pixbuf);
3153 } else {
3154 gtk_image_set_from_pixbuf(GTK_IMAGE(image), NULL);
3155 }
3156 break;
3157
3158 case OPID_TILE_XY:
3159 case OPID_TILE_TERRAIN:
3160 case OPID_TILE_RESOURCE:
3161 case OPID_STARTPOS_XY:
3162 case OPID_UNIT_XY:
3163 case OPID_UNIT_TYPE:
3164 case OPID_CITY_XY:
3165#ifdef FREECIV_DEBUG
3166 case OPID_TILE_ADDRESS:
3167 case OPID_UNIT_ADDRESS:
3168 case OPID_CITY_ADDRESS:
3169 case OPID_PLAYER_ADDRESS:
3170#endif /* FREECIV_DEBUG */
3171 label = objprop_get_child_widget(op, "value-label");
3172 if (pv) {
3173 gtk_label_set_text(GTK_LABEL(label), pv->data.v_string);
3174 } else {
3175 gtk_label_set_text(GTK_LABEL(label), NULL);
3176 }
3177 break;
3178
3179 case OPID_TILE_INDEX:
3180 case OPID_TILE_X:
3181 case OPID_TILE_Y:
3182 case OPID_TILE_NAT_X:
3183 case OPID_TILE_NAT_Y:
3185 case OPID_UNIT_ID:
3186 case OPID_CITY_ID:
3187 case OPID_PLAYER_AGE:
3188 label = objprop_get_child_widget(op, "value-label");
3189 if (pv) {
3190 char agebuf[16];
3191
3192 fc_snprintf(agebuf, sizeof(agebuf), "%d", pv->data.v_int);
3193 gtk_label_set_text(GTK_LABEL(label), agebuf);
3194 } else {
3195 gtk_label_set_text(GTK_LABEL(label), NULL);
3196 }
3197 break;
3198
3199 case OPID_CITY_NAME:
3200 case OPID_PLAYER_NAME:
3202 case OPID_TILE_LABEL:
3203 text = objprop_get_child_widget(op, "text");
3204 if (pv) {
3205 /* Most of these are semantically in "v_const_string",
3206 * but this works as the address is the same regardless. */
3207 newtext = pv->data.v_string;
3208 } else {
3209 newtext = "";
3210 }
3211 buffer = gtk_text_get_buffer(GTK_TEXT(text));
3212
3213 /* Only set the text if it has changed. This breaks
3214 * recursive loop. */
3215 if (strcmp(newtext, gtk_entry_buffer_get_text(buffer))) {
3216 gtk_entry_buffer_set_text(buffer, newtext, -1);
3217 }
3218 gtk_widget_set_sensitive(text, pv != NULL);
3219 break;
3220
3222 case OPID_CITY_SIZE:
3223 case OPID_CITY_HISTORY:
3226 case OPID_PLAYER_GOLD:
3227 spin = objprop_get_child_widget(op, "spin");
3228 if (pv) {
3229 disable_gobject_callback(G_OBJECT(spin),
3231 if (objbind_get_allowed_value_span(ob, op, &min, &max,
3232 &step, &big_step)) {
3233 gtk_spin_button_set_range(GTK_SPIN_BUTTON(spin), min, max);
3234 gtk_spin_button_set_increments(GTK_SPIN_BUTTON(spin),
3235 step, big_step);
3236 }
3237 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), pv->data.v_int);
3238 enable_gobject_callback(G_OBJECT(spin),
3240 }
3241 gtk_widget_set_sensitive(spin, pv != NULL);
3242 break;
3243
3244 case OPID_UNIT_FUEL:
3245 case OPID_UNIT_HP:
3246 case OPID_UNIT_VETERAN:
3248 spin = objprop_get_child_widget(op, "spin");
3249 label = objprop_get_child_widget(op, "max-value-label");
3250 if (pv) {
3251 disable_gobject_callback(G_OBJECT(spin),
3253 if (objbind_get_allowed_value_span(ob, op, &min, &max,
3254 &step, &big_step)) {
3255 gtk_spin_button_set_range(GTK_SPIN_BUTTON(spin), min, max);
3256 gtk_spin_button_set_increments(GTK_SPIN_BUTTON(spin),
3257 step, big_step);
3258 fc_snprintf(buf, sizeof(buf), "/%d", (int) max);
3259 gtk_label_set_text(GTK_LABEL(label), buf);
3260 } else {
3261 gtk_label_set_text(GTK_LABEL(label), NULL);
3262 }
3263 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), pv->data.v_int);
3264 enable_gobject_callback(G_OBJECT(spin),
3266 } else {
3267 gtk_label_set_text(GTK_LABEL(label), NULL);
3268 }
3269 gtk_widget_set_sensitive(spin, pv != NULL);
3270 break;
3271
3272 case OPID_TILE_SPECIALS:
3273 case OPID_TILE_ROADS:
3274 case OPID_TILE_BASES:
3275 case OPID_TILE_VISION:
3278 case OPID_PLAYER_NATION:
3279 case OPID_PLAYER_GOV:
3283 ev = objprop_get_extviewer(op);
3284 if (pv) {
3286 } else {
3288 }
3289 break;
3290
3292 case OPID_UNIT_MOVED:
3294 case OPID_UNIT_STAY:
3295 case OPID_GAME_SCENARIO:
3303 button = objprop_get_child_widget(op, "togglebutton");
3304 disable_gobject_callback(G_OBJECT(button),
3306 if (pv) {
3307 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
3308 pv->data.v_bool);
3309 } else {
3310 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
3311 }
3312 enable_gobject_callback(G_OBJECT(button),
3314 gtk_widget_set_sensitive(button, pv != NULL);
3315 break;
3316 }
3317
3318 if (!modified) {
3319 propval_free(pv);
3320 }
3321
3322 label = objprop_get_child_widget(op, "name-label");
3323 if (label) {
3324 const char *name = objprop_get_name(op);
3325 if (modified) {
3326 char namebuf[128];
3327
3328 fc_snprintf(namebuf, sizeof(namebuf),
3329 "<span foreground=\"red\">%s</span>", name);
3330 gtk_label_set_markup(GTK_LABEL(label), namebuf);
3331 } else {
3332 gtk_label_set_text(GTK_LABEL(label), name);
3333 }
3334 }
3335}
3336
3337/************************************************************************/
3341static GtkWidget *objprop_get_widget(struct objprop *op)
3342{
3343 if (!op) {
3344 return NULL;
3345 }
3346 if (!op->widget) {
3348 }
3349 return op->widget;
3350}
3351
3352/************************************************************************/
3356static void objprop_set_child_widget(struct objprop *op,
3357 const char *widget_name,
3358 GtkWidget *widget)
3359{
3360 GtkWidget *w;
3361
3362 if (!op || !widget_name || !widget) {
3363 return;
3364 }
3365
3366 w = objprop_get_widget(op);
3367 if (!w) {
3368 log_error("Cannot store child widget %p under name "
3369 "\"%s\" using objprop_set_child_widget for object "
3370 "property %d (%s) because objprop_get_widget does "
3371 "not return a valid widget.",
3372 widget, widget_name, objprop_get_id(op), objprop_get_name(op));
3373 return;
3374 }
3375
3376 g_object_set_data(G_OBJECT(w), widget_name, widget);
3377}
3378
3379/************************************************************************/
3383static GtkWidget *objprop_get_child_widget(struct objprop *op,
3384 const char *widget_name)
3385{
3386 GtkWidget *w, *child;
3387
3388 if (!op || !widget_name) {
3389 return NULL;
3390 }
3391
3392 w = objprop_get_widget(op);
3393 if (!w) {
3394 log_error("Cannot retrieve child widget under name "
3395 "\"%s\" using objprop_get_child_widget for object "
3396 "property %d (%s) because objprop_get_widget does "
3397 "not return a valid widget.",
3398 widget_name, objprop_get_id(op), objprop_get_name(op));
3399 return NULL;
3400 }
3401
3402 child = g_object_get_data(G_OBJECT(w), widget_name);
3403 if (!child) {
3404 log_error("Child widget \"%s\" not found for object "
3405 "property %d (%s) via objprop_get_child_widget.",
3406 widget_name, objprop_get_id(op), objprop_get_name(op));
3407 return NULL;
3408 }
3409
3410 return child;
3411}
3412
3413/************************************************************************/
3416static void objprop_set_extviewer(struct objprop *op,
3417 struct extviewer *ev)
3418{
3419 if (!op) {
3420 return;
3421 }
3422 op->extviewer = ev;
3423}
3424
3425/************************************************************************/
3428static struct extviewer *objprop_get_extviewer(struct objprop *op)
3429{
3430 if (!op) {
3431 return NULL;
3432 }
3433 return op->extviewer;
3434}
3435
3436/************************************************************************/
3439static struct property_page *objprop_get_property_page(const struct objprop *op)
3440{
3441 if (!op) {
3442 return NULL;
3443 }
3444 return op->parent_page;
3445}
3446
3447/************************************************************************/
3450static struct objprop *objprop_new(int id,
3451 const char *name,
3452 const char *tooltip,
3454 enum value_types valtype,
3455 struct property_page *parent)
3456{
3457 struct objprop *op;
3458
3459 op = fc_calloc(1, sizeof(*op));
3460 op->id = id;
3461 op->name = name;
3462 op->tooltip = tooltip;
3463 op->flags = flags;
3464 op->valtype = valtype;
3465 op->column_id = -1;
3466 op->parent_page = parent;
3467
3468 return op;
3469}
3470
3471/************************************************************************/
3475static struct extviewer *extviewer_new(struct objprop *op)
3476{
3477 struct extviewer *ev;
3478 GtkWidget *hbox, *vbox, *label, *button, *scrollwin, *image;
3479 GtkWidget *view = NULL;
3480 GtkTreeSelection *sel;
3481 GtkListStore *store = NULL;
3482 GtkTextBuffer *textbuf = NULL;
3483 GType *gtypes;
3484 enum object_property_ids propid;
3485 int num_cols;
3486
3487 if (!op) {
3488 return NULL;
3489 }
3490
3491 ev = fc_calloc(1, sizeof(*ev));
3492 ev->objprop = op;
3493
3494 propid = objprop_get_id(op);
3495
3496
3497 /* Create the panel widget. */
3498
3499 switch (propid) {
3500 case OPID_TILE_SPECIALS:
3501 case OPID_TILE_ROADS:
3502 case OPID_TILE_BASES:
3508 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
3509 ev->panel_widget = hbox;
3510
3511 label = gtk_label_new(NULL);
3512 gtk_widget_set_halign(label, GTK_ALIGN_START);
3513 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
3514 gtk_box_append(GTK_BOX(hbox), label);
3515 ev->panel_label = label;
3516 break;
3517
3518 case OPID_PLAYER_NATION:
3519 case OPID_PLAYER_GOV:
3520 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
3521 ev->panel_widget = vbox;
3522
3523 label = gtk_label_new(NULL);
3524 gtk_widget_set_halign(label, GTK_ALIGN_START);
3525 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
3526 gtk_box_append(GTK_BOX(vbox), label);
3527 ev->panel_label = label;
3528
3529 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
3530 gtk_box_append(GTK_BOX(vbox), hbox);
3531
3532 image = gtk_image_new();
3533 if (propid == OPID_PLAYER_GOV) {
3534 gtk_widget_set_size_request(image,
3537 } else {
3538 /* propid OPID_PLAYER_NATION */
3539 gtk_widget_set_size_request(image, 100, 40);
3540 }
3541 gtk_widget_set_halign(image, GTK_ALIGN_START);
3542 gtk_widget_set_valign(image, GTK_ALIGN_CENTER);
3543 gtk_box_append(GTK_BOX(hbox), image);
3544 ev->panel_image = image;
3545 break;
3546
3547 case OPID_TILE_VISION:
3548 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
3549 ev->panel_widget = hbox;
3550 break;
3551
3552 default:
3553 log_error("Unhandled request to create panel widget "
3554 "for property %d (%s) in extviewer_new().",
3555 propid, objprop_get_name(op));
3556 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
3557 ev->panel_widget = hbox;
3558 break;
3559 }
3560
3561 if (objprop_is_readonly(op)) {
3562 button = gtk_button_new_with_label(Q_("?verb:View"));
3563 } else {
3564 button = gtk_button_new_with_label(_("Edit"));
3565 }
3566 g_signal_connect(button, "clicked",
3567 G_CALLBACK(extviewer_panel_button_clicked), ev);
3568 gtk_box_append(GTK_BOX(hbox), button);
3569 ev->panel_button = button;
3570
3571
3572 /* Create the data store. */
3573
3574 switch (propid) {
3575 case OPID_TILE_SPECIALS:
3576 case OPID_TILE_ROADS:
3577 case OPID_TILE_BASES:
3579 store = gtk_list_store_new(3, G_TYPE_BOOLEAN, G_TYPE_INT,
3580 G_TYPE_STRING);
3581 break;
3582 case OPID_TILE_VISION:
3583 num_cols = 3 + 1 + V_COUNT;
3584 gtypes = fc_malloc(num_cols * sizeof(GType));
3585 gtypes[0] = G_TYPE_INT; /* player number */
3586 gtypes[1] = GDK_TYPE_PIXBUF; /* player flag */
3587 gtypes[2] = G_TYPE_STRING; /* player name */
3588 gtypes[3] = G_TYPE_BOOLEAN; /* tile_known */
3590 gtypes[4 + v] = G_TYPE_BOOLEAN; /* tile_seen[v] */
3592 store = gtk_list_store_newv(num_cols, gtypes);
3593 free(gtypes);
3594 break;
3596 store = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_INT,
3597 G_TYPE_STRING, G_TYPE_STRING);
3598 break;
3600 case OPID_PLAYER_NATION:
3601 case OPID_PLAYER_GOV:
3602 store = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_INT,
3603 GDK_TYPE_PIXBUF, G_TYPE_STRING);
3604 break;
3607 textbuf = gtk_text_buffer_new(NULL);
3608 break;
3609 default:
3610 log_error("Unhandled request to create data store "
3611 "for property %d (%s) in extviewer_new().",
3612 propid, objprop_get_name(op));
3613 break;
3614 }
3615
3616 ev->store = store;
3617 ev->textbuf = textbuf;
3618
3619 /* Create the view widget. */
3620
3621 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
3622 ev->view_widget = vbox;
3623
3624 label = gtk_label_new(objprop_get_name(op));
3625 gtk_widget_set_halign(label, GTK_ALIGN_START);
3626 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
3627 gtk_box_append(GTK_BOX(vbox), label);
3628 ev->view_label = label;
3629
3630 if (store || textbuf) {
3631 scrollwin = gtk_scrolled_window_new();
3632 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(scrollwin),
3633 TRUE);
3634 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
3635 GTK_POLICY_AUTOMATIC,
3636 GTK_POLICY_AUTOMATIC);
3637 gtk_box_append(GTK_BOX(vbox), scrollwin);
3638
3639 if (store) {
3640 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
3641 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
3642 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE);
3643 } else {
3644 const bool editable = !objprop_is_readonly(op);
3645
3646 view = gtk_text_view_new_with_buffer(textbuf);
3647 gtk_text_view_set_editable(GTK_TEXT_VIEW(view), editable);
3648 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), editable);
3649 }
3650 gtk_widget_set_hexpand(view, TRUE);
3651 gtk_widget_set_vexpand(view, TRUE);
3652
3653 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrollwin), view);
3654 }
3655
3656 switch (propid) {
3657
3658 case OPID_TILE_SPECIALS:
3659 case OPID_TILE_ROADS:
3660 case OPID_TILE_BASES:
3661 /* TRANS: As in "this tile special is present". */
3662 add_column(view, 0, _("Present"), G_TYPE_BOOLEAN, TRUE, FALSE,
3663 G_CALLBACK(extviewer_view_cell_toggled), ev);
3664 add_column(view, 1, _("ID"), G_TYPE_INT,
3665 FALSE, FALSE, NULL, NULL);
3666 add_column(view, 2, _("Name"), G_TYPE_STRING,
3667 FALSE, FALSE, NULL, NULL);
3668 break;
3669
3670 case OPID_TILE_VISION:
3671 add_column(view, 0, _("ID"), G_TYPE_INT,
3672 FALSE, FALSE, NULL, NULL);
3673 add_column(view, 1, _("Nation"), GDK_TYPE_PIXBUF,
3674 FALSE, FALSE, NULL, NULL);
3675 add_column(view, 2, _("Name"), G_TYPE_STRING,
3676 FALSE, FALSE, NULL, NULL);
3677 add_column(view, 3, _("Known"), G_TYPE_BOOLEAN,
3678 FALSE, FALSE, NULL, NULL);
3681 G_TYPE_BOOLEAN, FALSE, FALSE, NULL, NULL);
3683 break;
3684
3686 /* TRANS: As in "this building is present". */
3687 add_column(view, 0, _("Present"), G_TYPE_BOOLEAN, TRUE, FALSE,
3688 G_CALLBACK(extviewer_view_cell_toggled), ev);
3689 add_column(view, 1, _("ID"), G_TYPE_INT,
3690 FALSE, FALSE, NULL, NULL);
3691 add_column(view, 2, _("Name"), G_TYPE_STRING,
3692 FALSE, FALSE, NULL, NULL);
3693 /* TRANS: As in "the turn when this building was built". */
3694 add_column(view, 3, _("Turn Built"), G_TYPE_STRING,
3695 FALSE, FALSE, NULL, NULL);
3696 break;
3697
3699 /* TRANS: As in "the player has set this nation". */
3700 add_column(view, 0, _("Set"), G_TYPE_BOOLEAN, TRUE, FALSE,
3701 G_CALLBACK(extviewer_view_cell_toggled), ev);
3702 add_column(view, 1, _("ID"), G_TYPE_INT,
3703 FALSE, FALSE, NULL, NULL);
3704 add_column(view, 2, _("Flag"), GDK_TYPE_PIXBUF,
3705 FALSE, FALSE, NULL, NULL);
3706 add_column(view, 3, _("Name"), G_TYPE_STRING,
3707 FALSE, FALSE, NULL, NULL);
3708 break;
3709
3710 case OPID_PLAYER_NATION:
3711 case OPID_PLAYER_GOV:
3712 /* TRANS: As in "the player has set this nation". */
3713 add_column(view, 0, _("Set"), G_TYPE_BOOLEAN, TRUE, TRUE,
3714 G_CALLBACK(extviewer_view_cell_toggled), ev);
3715 add_column(view, 1, _("ID"), G_TYPE_INT,
3716 FALSE, FALSE, NULL, NULL);
3717 add_column(view, 2,
3718 propid == OPID_PLAYER_GOV ? _("Icon") : _("Flag"),
3719 GDK_TYPE_PIXBUF,
3720 FALSE, FALSE, NULL, NULL);
3721 add_column(view, 3, _("Name"), G_TYPE_STRING,
3722 FALSE, FALSE, NULL, NULL);
3723 break;
3724
3726 /* TRANS: As in "this invention is known". */
3727 add_column(view, 0, _("Known"), G_TYPE_BOOLEAN, TRUE, FALSE,
3728 G_CALLBACK(extviewer_view_cell_toggled), ev);
3729 add_column(view, 1, _("ID"), G_TYPE_INT,
3730 FALSE, FALSE, NULL, NULL);
3731 add_column(view, 2, _("Name"), G_TYPE_STRING,
3732 FALSE, FALSE, NULL, NULL);
3733 break;
3734
3737 g_signal_connect(textbuf, "changed",
3738 G_CALLBACK(extviewer_textbuf_changed), ev);
3739 break;
3740
3741 default:
3742 log_error("Unhandled request to configure view widget "
3743 "for property %d (%s) in extviewer_new().",
3744 propid, objprop_get_name(op));
3745 break;
3746 }
3747
3748 gtk_widget_show(ev->panel_widget);
3749 gtk_widget_show(ev->view_widget);
3750
3751 return ev;
3752}
3753
3754/************************************************************************/
3757static struct objprop *extviewer_get_objprop(struct extviewer *ev)
3758{
3759 if (!ev) {
3760 return NULL;
3761 }
3762 return ev->objprop;
3763}
3764
3765/************************************************************************/
3769static GtkWidget *extviewer_get_panel_widget(struct extviewer *ev)
3770{
3771 if (!ev) {
3772 return NULL;
3773 }
3774 return ev->panel_widget;
3775}
3776
3777/************************************************************************/
3781static GtkWidget *extviewer_get_view_widget(struct extviewer *ev)
3782{
3783 if (!ev) {
3784 return NULL;
3785 }
3786 return ev->view_widget;
3787}
3788
3789/************************************************************************/
3793 struct propval *pv)
3794{
3795 struct objprop *op;
3796 enum object_property_ids propid;
3797 int id, turn_built;
3798 bool present, all;
3799 const char *name;
3800 GdkPixbuf *pixbuf;
3801 GtkListStore *store;
3802 GtkTextBuffer *textbuf;
3803 GtkTreeIter iter;
3804 gchar *buf;
3805
3806 if (!ev) {
3807 return;
3808 }
3809
3810 op = extviewer_get_objprop(ev);
3811 propid = objprop_get_id(op);
3812
3813 if (propval_equal(pv, ev->pv_cached)) {
3814 return;
3815 }
3817 ev->pv_cached = propval_copy(pv);
3818 store = ev->store;
3819 textbuf = ev->textbuf;
3820
3821
3822 /* NB: Remember to have -1 as the last argument to
3823 * gtk_list_store_set() and to use the correct column
3824 * number when inserting data. :) */
3825 switch (propid) {
3826
3827 case OPID_TILE_SPECIALS:
3828 gtk_list_store_clear(store);
3830 id = spe->data.special_idx;
3832 present = BV_ISSET(pv->data.v_bv_special, id);
3833 gtk_list_store_append(store, &iter);
3834 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3836 buf = propval_as_string(pv);
3837 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3838 g_free(buf);
3839 break;
3840
3841 case OPID_TILE_ROADS:
3842 gtk_list_store_clear(store);
3843 extra_type_by_cause_iterate(EC_ROAD, pextra) {
3844 struct road_type *proad = extra_road_get(pextra);
3845
3846 id = road_number(proad);
3847 name = extra_name_translation(pextra);
3848 present = BV_ISSET(pv->data.v_bv_roads, id);
3849 gtk_list_store_append(store, &iter);
3850 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3852 buf = propval_as_string(pv);
3853 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3854 g_free(buf);
3855 break;
3856
3857 case OPID_TILE_BASES:
3858 gtk_list_store_clear(store);
3859 extra_type_by_cause_iterate(EC_BASE, pextra) {
3860 struct base_type *pbase = extra_base_get(pextra);
3861
3862 id = base_number(pbase);
3863 name = extra_name_translation(pextra);
3864 present = BV_ISSET(pv->data.v_bv_bases, id);
3865 gtk_list_store_append(store, &iter);
3866 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3868 buf = propval_as_string(pv);
3869 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3870 g_free(buf);
3871 break;
3872
3873 case OPID_TILE_VISION:
3874 gtk_list_store_clear(store);
3875 player_slots_iterate(pslot) {
3876 id = player_slot_index(pslot);
3877 if (player_slot_is_used(pslot)) {
3878 struct player *pplayer = player_slot_get_player(pslot);
3879
3880 name = player_name(pplayer);
3881 pixbuf = get_flag(pplayer->nation);
3882 } else {
3883 name = "";
3884 pixbuf = NULL;
3885 }
3886 gtk_list_store_append(store, &iter);
3887 gtk_list_store_set(store, &iter, 0, id, 2, name, -1);
3888 if (pixbuf) {
3889 gtk_list_store_set(store, &iter, 1, pixbuf, -1);
3890 g_object_unref(pixbuf);
3891 pixbuf = NULL;
3892 }
3893 present = BV_ISSET(pv->data.v_tile_vision->tile_known, id);
3894 gtk_list_store_set(store, &iter, 3, present, -1);
3896 present = BV_ISSET(pv->data.v_tile_vision->tile_seen[v], id);
3897 gtk_list_store_set(store, &iter, 4 + v, present, -1);
3900 break;
3901
3903 gtk_list_store_clear(store);
3904 gtk_list_store_append(store, &iter);
3905 all = (0 == nation_hash_size(pv->data.v_nation_hash));
3906 gtk_list_store_set(store, &iter, 0, all, 1, -1, 3,
3907 _("All nations"), -1);
3908 nations_iterate(pnation) {
3910 && is_nation_playable(pnation)) {
3911 present = (!all && nation_hash_lookup(pv->data.v_nation_hash,
3912 pnation, NULL));
3913 id = nation_number(pnation);
3914 pixbuf = get_flag(pnation);
3916 gtk_list_store_append(store, &iter);
3917 gtk_list_store_set(store, &iter, 0, present, 1, id,
3918 2, pixbuf, 3, name, -1);
3919 if (pixbuf) {
3920 g_object_unref(pixbuf);
3921 }
3922 }
3924 buf = propval_as_string(pv);
3925 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3926 g_free(buf);
3927 break;
3928
3930 gtk_list_store_clear(store);
3931 improvement_iterate(pimprove) {
3932 if (is_special_improvement(pimprove)) {
3933 continue;
3934 }
3935 id = improvement_index(pimprove);
3937 turn_built = pv->data.v_built[id].turn;
3938 present = turn_built >= 0;
3939 buf = built_status_to_string(&pv->data.v_built[id]);
3940 gtk_list_store_append(store, &iter);
3941 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name,
3942 3, buf, -1);
3943 g_free(buf);
3945 buf = propval_as_string(pv);
3946 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3947 g_free(buf);
3948 break;
3949
3950 case OPID_PLAYER_NATION:
3951 {
3952 enum barbarian_type barbarian_type =
3954
3955 gtk_list_store_clear(store);
3956 nations_iterate(pnation) {
3958 && nation_barbarian_type(pnation) == barbarian_type
3959 && (barbarian_type != NOT_A_BARBARIAN
3960 || is_nation_playable(pnation))) {
3961 present = (pnation == pv->data.v_nation);
3962 id = nation_index(pnation);
3963 pixbuf = get_flag(pnation);
3965 gtk_list_store_append(store, &iter);
3966 gtk_list_store_set(store, &iter, 0, present, 1, id,
3967 2, pixbuf, 3, name, -1);
3968 if (pixbuf) {
3969 g_object_unref(pixbuf);
3970 }
3971 }
3973 gtk_label_set_text(GTK_LABEL(ev->panel_label),
3975 pixbuf = get_flag(pv->data.v_nation);
3976 gtk_image_set_from_pixbuf(GTK_IMAGE(ev->panel_image), pixbuf);
3977 if (pixbuf) {
3978 g_object_unref(pixbuf);
3979 }
3980 }
3981 break;
3982
3983 case OPID_PLAYER_GOV:
3984 {
3985 gtk_list_store_clear(store);
3986 governments_iterate(pgov) {
3987 present = (pgov == pv->data.v_gov);
3988 id = government_index(pgov);
3991 gtk_list_store_append(store, &iter);
3992 gtk_list_store_set(store, &iter, 0, present, 1, id,
3993 2, pixbuf, 3, name, -1);
3994 if (pixbuf) {
3995 g_object_unref(pixbuf);
3996 }
3998 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4001 gtk_image_set_from_pixbuf(GTK_IMAGE(ev->panel_image), pixbuf);
4002 if (pixbuf) {
4003 g_object_unref(pixbuf);
4004 }
4005 }
4006 break;
4007
4009 gtk_list_store_clear(store);
4010 advance_iterate(A_FIRST, padvance) {
4011 id = advance_index(padvance);
4012 present = BV_ISSET(pv->data.v_bv_inventions, id);
4013 name = advance_name_translation(padvance);
4014 gtk_list_store_append(store, &iter);
4015 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
4017 buf = propval_as_string(pv);
4018 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4019 g_free(buf);
4020 break;
4021
4024 disable_gobject_callback(G_OBJECT(ev->textbuf),
4025 G_CALLBACK(extviewer_textbuf_changed));
4026 {
4027 GtkTextIter start, end;
4028 char *oldtext;
4029
4030 /* Don't re-set content if unchanged, to avoid moving cursor */
4031 gtk_text_buffer_get_bounds(textbuf, &start, &end);
4032 oldtext = gtk_text_buffer_get_text(textbuf, &start, &end, TRUE);
4033 if (strcmp(oldtext, pv->data.v_const_string) != 0) {
4034 gtk_text_buffer_set_text(textbuf, pv->data.v_const_string, -1);
4035 }
4036 }
4037 enable_gobject_callback(G_OBJECT(ev->textbuf),
4038 G_CALLBACK(extviewer_textbuf_changed));
4039 gtk_widget_set_sensitive(ev->view_widget, TRUE);
4040 buf = propval_as_string(pv);
4041 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4042 g_free(buf);
4043 break;
4044
4045 default:
4046 log_error("Unhandled request to refresh widgets "
4047 "extviewer_refresh_widgets() for objprop id=%d "
4048 "name \"%s\".", propid, objprop_get_name(op));
4049 break;
4050 }
4051}
4052
4053/************************************************************************/
4056static void extviewer_clear_widgets(struct extviewer *ev)
4057{
4058 struct objprop *op;
4059 enum object_property_ids propid;
4060
4061 if (!ev) {
4062 return;
4063 }
4064
4065 op = extviewer_get_objprop(ev);
4066 propid = objprop_get_id(op);
4067
4069 ev->pv_cached = NULL;
4070
4071 if (ev->panel_label != NULL) {
4072 gtk_label_set_text(GTK_LABEL(ev->panel_label), NULL);
4073 }
4074
4075 switch (propid) {
4076 case OPID_TILE_SPECIALS:
4077 case OPID_TILE_ROADS:
4078 case OPID_TILE_BASES:
4079 case OPID_TILE_VISION:
4083 gtk_list_store_clear(ev->store);
4084 break;
4085 case OPID_PLAYER_NATION:
4086 case OPID_PLAYER_GOV:
4087 gtk_list_store_clear(ev->store);
4088 gtk_image_set_from_pixbuf(GTK_IMAGE(ev->panel_image), NULL);
4089 break;
4092 disable_gobject_callback(G_OBJECT(ev->textbuf),
4093 G_CALLBACK(extviewer_textbuf_changed));
4094 gtk_text_buffer_set_text(ev->textbuf, "", -1);
4095 enable_gobject_callback(G_OBJECT(ev->textbuf),
4096 G_CALLBACK(extviewer_textbuf_changed));
4097 gtk_widget_set_sensitive(ev->view_widget, FALSE);
4098 break;
4099 default:
4100 log_error("Unhandled request to clear widgets "
4101 "in extviewer_clear_widgets() for objprop id=%d "
4102 "name \"%s\".", propid, objprop_get_name(op));
4103 break;
4104 }
4105}
4106
4107/************************************************************************/
4111static void extviewer_panel_button_clicked(GtkButton *button,
4112 gpointer userdata)
4113{
4114 struct extviewer *ev;
4115 struct property_page *pp;
4116 struct objprop *op;
4117
4118 ev = userdata;
4119 if (!ev) {
4120 return;
4121 }
4122
4123 op = extviewer_get_objprop(ev);
4126}
4127
4128/************************************************************************/
4131static void extviewer_view_cell_toggled(GtkCellRendererToggle *cell,
4132 gchar *path,
4133 gpointer userdata)
4134{
4135 struct extviewer *ev;
4136 struct objprop *op;
4137 struct property_page *pp;
4138 enum object_property_ids propid;
4139 GtkTreeModel *model;
4140 GtkTreeIter iter;
4141 int id, old_id, turn_built;
4142 struct propval *pv;
4143 bool active, present;
4144 gchar *buf;
4145 GdkPixbuf *pixbuf = NULL;
4146
4147 ev = userdata;
4148 if (!ev) {
4149 return;
4150 }
4151
4152 pv = ev->pv_cached;
4153 if (!pv) {
4154 return;
4155 }
4156
4157 op = extviewer_get_objprop(ev);
4158 propid = objprop_get_id(op);
4159 active = gtk_cell_renderer_toggle_get_active(cell);
4161
4162 model = GTK_TREE_MODEL(ev->store);
4163 if (!gtk_tree_model_get_iter_from_string(model, &iter, path)) {
4164 return;
4165 }
4166 present = !active;
4167
4168
4169 switch (propid) {
4170
4171 case OPID_TILE_SPECIALS:
4172 gtk_tree_model_get(model, &iter, 1, &id, -1);
4173 if (id < 0 || id >= extra_type_list_size(extra_type_list_by_cause(EC_SPECIAL))) {
4174 return;
4175 }
4176 if (present) {
4177 BV_SET(pv->data.v_bv_special, id);
4178 } else {
4179 BV_CLR(pv->data.v_bv_special, id);
4180 }
4181 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4182 buf = propval_as_string(pv);
4183 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4184 g_free(buf);
4185 break;
4186
4187 case OPID_TILE_ROADS:
4188 gtk_tree_model_get(model, &iter, 1, &id, -1);
4189 if (!(0 <= id && id < road_count())) {
4190 return;
4191 }
4192 if (present) {
4193 BV_SET(pv->data.v_bv_roads, id);
4194 } else {
4195 BV_CLR(pv->data.v_bv_roads, id);
4196 }
4197 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4198 buf = propval_as_string(pv);
4199 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4200 g_free(buf);
4201 break;
4202
4203 case OPID_TILE_BASES:
4204 gtk_tree_model_get(model, &iter, 1, &id, -1);
4205 if (!(0 <= id && id < base_count())) {
4206 return;
4207 }
4208 if (present) {
4209 BV_SET(pv->data.v_bv_bases, id);
4210 } else {
4211 BV_CLR(pv->data.v_bv_bases, id);
4212 }
4213 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4214 buf = propval_as_string(pv);
4215 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4216 g_free(buf);
4217 break;
4218
4220 gtk_tree_model_get(model, &iter, 1, &id, -1);
4221 if (-1 > id && id >= nation_count()) {
4222 return;
4223 }
4224
4225 if (-1 == id) {
4226 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4227 gtk_tree_model_get_iter_first(model, &iter);
4228 if (present) {
4229 while (gtk_tree_model_iter_next(model, &iter)) {
4230 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4231 }
4232 nation_hash_clear(pv->data.v_nation_hash);
4233 } else {
4234 const struct nation_type *pnation;
4235 int id2;
4236
4237 gtk_tree_model_iter_next(model, &iter);
4238 gtk_tree_model_get(model, &iter, 0, &id2, -1);
4239 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4240 pnation = nation_by_number(id2);
4241 nation_hash_insert(pv->data.v_nation_hash, pnation, NULL);
4242 }
4243 } else {
4244 const struct nation_type *pnation;
4245 bool all;
4246
4247 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4248 pnation = nation_by_number(id);
4249 if (present) {
4250 nation_hash_insert(pv->data.v_nation_hash, pnation, NULL);
4251 } else {
4252 nation_hash_remove(pv->data.v_nation_hash, pnation);
4253 }
4254 gtk_tree_model_get_iter_first(model, &iter);
4255 all = (0 == nation_hash_size(pv->data.v_nation_hash));
4256 gtk_list_store_set(ev->store, &iter, 0, all, -1);
4257 }
4258 buf = propval_as_string(pv);
4259 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4260 g_free(buf);
4261 break;
4262
4264 gtk_tree_model_get(model, &iter, 1, &id, -1);
4265 if (!(0 <= id && id < B_LAST)) {
4266 return;
4267 }
4268 turn_built = present ? game.info.turn : I_NEVER;
4269 pv->data.v_built[id].turn = turn_built;
4270 buf = built_status_to_string(&pv->data.v_built[id]);
4271 gtk_list_store_set(ev->store, &iter, 0, present, 3, buf, -1);
4272 g_free(buf);
4273 buf = propval_as_string(pv);
4274 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4275 g_free(buf);
4276 break;
4277
4278 case OPID_PLAYER_NATION:
4279 gtk_tree_model_get(model, &iter, 1, &id, -1);
4280 if (!(0 <= id && id < nation_count()) || !present) {
4281 return;
4282 }
4283 old_id = nation_index(pv->data.v_nation);
4284 pv->data.v_nation = nation_by_number(id);
4285 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4286 gtk_tree_model_iter_nth_child(model, &iter, NULL, old_id);
4287 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4288 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4290 pixbuf = get_flag(pv->data.v_nation);
4291 gtk_image_set_from_pixbuf(GTK_IMAGE(ev->panel_image), pixbuf);
4292 if (pixbuf) {
4293 g_object_unref(pixbuf);
4294 }
4295 break;
4296
4297 case OPID_PLAYER_GOV:
4298 gtk_tree_model_get(model, &iter, 1, &id, -1);
4299 if (!(0 <= id && id < government_count()) || !present) {
4300 return;
4301 }
4302 old_id = government_index(pv->data.v_gov);
4304 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4305 gtk_tree_model_iter_nth_child(model, &iter, NULL, old_id);
4306 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4307 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4310 gtk_image_set_from_pixbuf(GTK_IMAGE(ev->panel_image), pixbuf);
4311 if (pixbuf) {
4312 g_object_unref(pixbuf);
4313 }
4314 break;
4315
4317 gtk_tree_model_get(model, &iter, 1, &id, -1);
4318 if (!(A_FIRST <= id && id < advance_count())) {
4319 return;
4320 }
4321 if (present) {
4322 BV_SET(pv->data.v_bv_inventions, id);
4323 } else {
4324 BV_CLR(pv->data.v_bv_inventions, id);
4325 }
4326 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4327 buf = propval_as_string(pv);
4328 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4329 g_free(buf);
4330 break;
4331
4332 default:
4333 log_error("Unhandled widget toggled signal in "
4334 "extviewer_view_cell_toggled() for objprop id=%d "
4335 "name \"%s\".", propid, objprop_get_name(op));
4336 return;
4337 break;
4338 }
4339
4340 property_page_change_value(pp, op, pv);
4341}
4342
4343/************************************************************************/
4346static void extviewer_textbuf_changed(GtkTextBuffer *textbuf,
4347 gpointer userdata)
4348{
4349 struct extviewer *ev;
4350 struct objprop *op;
4351 struct property_page *pp;
4352 enum object_property_ids propid;
4353 struct propval value = {{0,}, VALTYPE_STRING, FALSE}, *pv;
4354 GtkTextIter start, end;
4355 char *text;
4356 gchar *buf;
4357
4358 ev = userdata;
4359 if (!ev) {
4360 return;
4361 }
4362
4363 op = extviewer_get_objprop(ev);
4364 propid = objprop_get_id(op);
4366
4367 gtk_text_buffer_get_start_iter(textbuf, &start);
4368 gtk_text_buffer_get_end_iter(textbuf, &end);
4369 text = gtk_text_buffer_get_text(textbuf, &start, &end, FALSE);
4370 value.data.v_const_string = text;
4371 pv = &value;
4372
4373 switch (propid) {
4376 buf = propval_as_string(pv);
4377 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4378 g_free(buf);
4379 break;
4380 default:
4381 log_error("Unhandled widget modified signal in "
4382 "extviewer_textbuf_changed() for objprop id=%d "
4383 "name \"%s\".", propid, objprop_get_name(op));
4384 return;
4385 break;
4386 }
4387
4388 property_page_change_value(pp, op, pv);
4389 g_free(text);
4390}
4391
4392/************************************************************************/
4396{
4397#define ADDPROP(ARG_id, ARG_name, ARG_tooltip, ARG_flags, ARG_valtype) do { \
4398 struct objprop *MY_op = objprop_new(ARG_id, ARG_name, ARG_tooltip, \
4399 ARG_flags, ARG_valtype, pp); \
4400 objprop_hash_insert(pp->objprop_table, MY_op->id, MY_op); \
4401} while (FALSE)
4402
4403 switch (property_page_get_objtype(pp)) {
4404 case OBJTYPE_TILE:
4405 ADDPROP(OPID_TILE_IMAGE, _("Image"), NULL,
4407 ADDPROP(OPID_TILE_TERRAIN, _("Terrain"), NULL,
4409 ADDPROP(OPID_TILE_RESOURCE, _("Resource"), NULL,
4411 ADDPROP(OPID_TILE_INDEX, _("Index"), NULL,
4413 ADDPROP(OPID_TILE_X, Q_("?coordinate:X"), NULL,
4415 ADDPROP(OPID_TILE_Y, Q_("?coordinate:Y"), NULL,
4417 /* TRANS: The coordinate X in native coordinates.
4418 * The freeciv coordinate system is described in doc/HACKING. */
4419 ADDPROP(OPID_TILE_NAT_X, _("NAT X"), NULL,
4421 /* TRANS: The coordinate Y in native coordinates.
4422 * The freeciv coordinate system is described in doc/HACKING. */
4423 ADDPROP(OPID_TILE_NAT_Y, _("NAT Y"), NULL,
4425 ADDPROP(OPID_TILE_CONTINENT, _("Continent"), NULL,
4427 ADDPROP(OPID_TILE_XY, Q_("?coordinates:X,Y"), NULL,
4429 ADDPROP(OPID_TILE_SPECIALS, _("Specials"), NULL,
4432 ADDPROP(OPID_TILE_ROADS, _("Roads"), NULL,
4435 ADDPROP(OPID_TILE_BASES, _("Bases"), NULL,
4438#ifdef FREECIV_DEBUG
4439 ADDPROP(OPID_TILE_ADDRESS, _("Address"), NULL,
4441#endif /* FREECIV_DEBUG */
4442#if 0
4443 /* Disabled entirely for now as server is not sending other
4444 * players' vision information anyway. */
4445 ADDPROP(OPID_TILE_VISION, _("Vision"), NULL,
4447#endif
4448 /* TRANS: Tile property "Label" label in editor */
4449 ADDPROP(OPID_TILE_LABEL, Q_("?property:Label"), NULL,
4451 return;
4452
4453 case OBJTYPE_STARTPOS:
4454 ADDPROP(OPID_STARTPOS_IMAGE, _("Image"), NULL,
4456 ADDPROP(OPID_STARTPOS_XY, Q_("?coordinates:X,Y"), NULL,
4458 ADDPROP(OPID_STARTPOS_EXCLUDE, _("Exclude Nations"), NULL,
4460 ADDPROP(OPID_STARTPOS_NATIONS, _("Nations"), NULL,
4463 return;
4464
4465 case OBJTYPE_UNIT:
4466 ADDPROP(OPID_UNIT_IMAGE, _("Image"), NULL,
4468#ifdef FREECIV_DEBUG
4469 ADDPROP(OPID_UNIT_ADDRESS, _("Address"), NULL,
4471#endif /* FREECIV_DEBUG */
4472 ADDPROP(OPID_UNIT_TYPE, _("Type"), NULL,
4474 ADDPROP(OPID_UNIT_ID, _("ID"), NULL,
4476 ADDPROP(OPID_UNIT_XY, Q_("?coordinates:X,Y"), NULL,
4478 ADDPROP(OPID_UNIT_MOVES_LEFT, _("Moves Left"), NULL,
4480 ADDPROP(OPID_UNIT_FUEL, _("Fuel"), NULL,
4482 ADDPROP(OPID_UNIT_MOVED, _("Moved"), NULL,
4484 ADDPROP(OPID_UNIT_DONE_MOVING, _("Done Moving"), NULL,
4486 /* TRANS: HP = Hit Points of a unit. */
4487 ADDPROP(OPID_UNIT_HP, _("HP"), NULL,
4489 ADDPROP(OPID_UNIT_VETERAN, _("Veteran"), NULL,
4491 ADDPROP(OPID_UNIT_STAY, _("Stay put"), NULL,
4493 return;
4494
4495 case OBJTYPE_CITY:
4496 ADDPROP(OPID_CITY_IMAGE, _("Image"), NULL,
4498 ADDPROP(OPID_CITY_NAME, _("Name"), NULL,
4500#ifdef FREECIV_DEBUG
4501 ADDPROP(OPID_CITY_ADDRESS, _("Address"), NULL,
4503#endif /* FREECIV_DEBUG */
4504 ADDPROP(OPID_CITY_ID, _("ID"), NULL,
4506 ADDPROP(OPID_CITY_XY, Q_("?coordinates:X,Y"), NULL,
4508 ADDPROP(OPID_CITY_SIZE, _("Size"), NULL,
4510 ADDPROP(OPID_CITY_HISTORY, _("History"), NULL,
4512 ADDPROP(OPID_CITY_BUILDINGS, _("Buildings"), NULL,
4515 ADDPROP(OPID_CITY_FOOD_STOCK, _("Food Stock"), NULL,
4517 ADDPROP(OPID_CITY_SHIELD_STOCK, _("Shield Stock"), NULL,
4519 return;
4520
4521 case OBJTYPE_PLAYER:
4522 ADDPROP(OPID_PLAYER_NAME, _("Name"), NULL,
4525#ifdef FREECIV_DEBUG
4526 ADDPROP(OPID_PLAYER_ADDRESS, _("Address"), NULL,
4528#endif /* FREECIV_DEBUG */
4529 ADDPROP(OPID_PLAYER_NATION, _("Nation"), NULL,
4532 ADDPROP(OPID_PLAYER_GOV, _("Government"), NULL,
4534 VALTYPE_GOV);
4535 ADDPROP(OPID_PLAYER_AGE, _("Age"), NULL,
4537 ADDPROP(OPID_PLAYER_INVENTIONS, _("Inventions"), NULL,
4540 ADDPROP(OPID_PLAYER_SCENARIO_RESERVED, _("Reserved"), NULL,
4542 ADDPROP(OPID_PLAYER_SCIENCE, _("Science"), NULL,
4544 ADDPROP(OPID_PLAYER_GOLD, _("Gold"), NULL,
4546 VALTYPE_INT);
4547 return;
4548
4549 case OBJTYPE_GAME:
4550 ADDPROP(OPID_GAME_SCENARIO, _("Scenario"), NULL,
4552 VALTYPE_BOOL);
4554 _("Scenario Name"), NULL,
4558 _("Scenario Authors"), NULL,
4562 _("Scenario Description"), NULL,
4566 _("Save Random Number State"), NULL,
4569 _("Save Players"), NULL,
4572 _("Nation Start Positions"), NULL,
4575 _("Prevent New Cities"), NULL,
4578 _("Saltwater Flooding Lakes"), NULL,
4581 _("Lock to current Ruleset"), NULL,
4583 return;
4584
4585 case NUM_OBJTYPES:
4586 break;
4587 }
4588
4589 log_error("%s(): Unhandled page object type %s (nb %d).", __FUNCTION__,
4592#undef ADDPROP
4593}
4594
4595/************************************************************************/
4598static void property_page_selection_changed(GtkTreeSelection *sel,
4599 gpointer userdata)
4600{
4601 struct property_page *pp;
4602 struct objbind *ob = NULL;
4603
4604 pp = userdata;
4605 if (!pp) {
4606 return;
4607 }
4608
4609 if (gtk_tree_selection_count_selected_rows(sel) < 1) {
4611 }
4612
4615 objprop_refresh_widget(op, ob);
4617}
4618
4619/************************************************************************/
4623static gboolean property_page_selection_func(GtkTreeSelection *sel,
4624 GtkTreeModel *model,
4625 GtkTreePath *sel_path,
4626 gboolean currently_selected,
4627 gpointer data)
4628{
4629 struct property_page *pp;
4630 struct objbind *ob = NULL, *old_ob;
4631 GtkTreeIter iter;
4632
4633 pp = data;
4634 if (!pp || !sel_path) {
4635 return TRUE;
4636 }
4637
4638 if (!gtk_tree_model_get_iter(model, &iter, sel_path)) {
4639 return TRUE;
4640 }
4641
4643 gtk_tree_model_get(model, &iter, 0, &ob, -1);
4644 if (currently_selected) {
4645 if (ob == old_ob) {
4646 GList *rows, *p;
4647 GtkTreePath *path;
4648 struct objbind *new_ob = NULL;
4649
4650 rows = gtk_tree_selection_get_selected_rows(sel, NULL);
4651 for (p = rows; p != NULL; p = p->next) {
4652 path = p->data;
4653 if (gtk_tree_model_get_iter(model, &iter, path)) {
4654 struct objbind *test_ob = NULL;
4655 gtk_tree_model_get(model, &iter, 0, &test_ob, -1);
4656 if (test_ob == ob) {
4657 continue;
4658 }
4659 new_ob = test_ob;
4660 break;
4661 }
4662 }
4663 g_list_foreach(rows, (GFunc) gtk_tree_path_free, NULL);
4664 g_list_free(rows);
4665
4667 }
4668 } else {
4670 }
4671
4672 return TRUE;
4673}
4674
4675/************************************************************************/
4679 gpointer userdata)
4680{
4681 struct property_page *pp;
4682 const gchar *text;
4683 GtkWidget *w;
4684 GtkTreeViewColumn *col;
4685 struct property_filter *pf;
4686 bool matched;
4687
4688 pp = userdata;
4689 text = gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(entry)));
4690 pf = property_filter_new(text);
4691
4693 if (!objprop_has_widget(op)
4694 && !objprop_show_in_listview(op)) {
4695 continue;
4696 }
4697 matched = property_filter_match(pf, op);
4698 w = objprop_get_widget(op);
4699 if (objprop_has_widget(op) && w != NULL) {
4700 if (matched) {
4701 gtk_widget_show(w);
4702 } else {
4703 gtk_widget_hide(w);
4704 }
4705 }
4707 if (objprop_show_in_listview(op) && col != NULL) {
4708 gtk_tree_view_column_set_visible(col, matched);
4709 }
4711
4713}
4714
4715/************************************************************************/
4719static struct property_page *
4721 struct property_editor *pe)
4722{
4723 struct property_page *pp;
4724 GtkWidget *vgrid, *vgrid2, *hgrid, *hgrid2, *paned, *frame, *w;
4725 GtkWidget *scrollwin, *view, *label, *entry, *notebook;
4726 GtkWidget *button, *hsep;
4727 GtkTreeSelection *sel;
4728 GtkCellRenderer *cell;
4729 GtkTreeViewColumn *col;
4730 GtkSizeGroup *sizegroup;
4731 int num_columns = 0;
4732 GType *gtype_array;
4733 int col_id = 1;
4734 const char *attr_type_str, *name, *tooltip;
4735 gchar *title;
4736 int grid_row = 0;
4737 int grid2_row = 0;
4738 int grid_col = 0;
4739 int grid2_col = 0;
4740
4741 if (!(objtype < NUM_OBJTYPES)) {
4742 return NULL;
4743 }
4744
4745 pp = fc_calloc(1, sizeof(struct property_page));
4746 pp->objtype = objtype;
4747 pp->pe_parent = pe;
4748
4749 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
4750
4751 pp->objprop_table = objprop_hash_new();
4753
4754 pp->objbind_table = objbind_hash_new();
4755
4756 pp->tag_table = stored_tag_hash_new();
4757
4759 if (objprop_show_in_listview(op)) {
4760 num_columns++;
4761 }
4763
4764 /* Column zero in the store holds an objbind
4765 * pointer and is never displayed. */
4766 num_columns++;
4767 gtype_array = fc_malloc(num_columns * sizeof(GType));
4768 gtype_array[0] = G_TYPE_POINTER;
4769
4771 if (objprop_show_in_listview(op)) {
4772 gtype_array[col_id] = objprop_get_gtype(op);
4773 objprop_set_column_id(op, col_id);
4774 col_id++;
4775 }
4777
4778 pp->object_store = gtk_list_store_newv(num_columns, gtype_array);
4779 free(gtype_array);
4780
4781 paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
4782 gtk_paned_set_position(GTK_PANED(paned), 256);
4783 pp->widget = paned;
4784
4785 /* Left side object list view. */
4786
4787 vgrid = gtk_grid_new();
4788 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
4789 GTK_ORIENTATION_VERTICAL);
4790 gtk_grid_set_row_spacing(GTK_GRID(vgrid), 4);
4791 gtk_widget_set_margin_start(vgrid, 4);
4792 gtk_widget_set_margin_end(vgrid, 4);
4793 gtk_widget_set_margin_top(vgrid, 4);
4794 gtk_widget_set_margin_bottom(vgrid, 4);
4795 gtk_paned_set_start_child(GTK_PANED(paned), vgrid);
4796
4797 scrollwin = gtk_scrolled_window_new();
4798 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(scrollwin),
4799 TRUE);
4800 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
4801 GTK_POLICY_AUTOMATIC,
4802 GTK_POLICY_AUTOMATIC);
4803 gtk_grid_attach(GTK_GRID(vgrid), scrollwin, 0, grid_row++, 1, 1);
4804
4805 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pp->object_store));
4806 gtk_widget_set_hexpand(view, TRUE);
4807 gtk_widget_set_vexpand(view, TRUE);
4808
4810 if (!objprop_show_in_listview(op)) {
4811 continue;
4812 }
4813
4814 attr_type_str = objprop_get_attribute_type_string(op);
4815 if (!attr_type_str) {
4816 continue;
4817 }
4818 col_id = objprop_get_column_id(op);
4819 if (col_id < 0) {
4820 continue;
4821 }
4822 name = objprop_get_name(op);
4823 if (!name) {
4824 continue;
4825 }
4827 if (!cell) {
4828 continue;
4829 }
4830
4831 col = gtk_tree_view_column_new_with_attributes(name, cell,
4832 attr_type_str, col_id,
4833 NULL);
4834
4835 gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
4836 gtk_tree_view_column_set_resizable(col, TRUE);
4837 gtk_tree_view_column_set_reorderable(col, TRUE);
4838 if (objprop_is_sortable(op)) {
4839 gtk_tree_view_column_set_clickable(col, TRUE);
4840 gtk_tree_view_column_set_sort_column_id(col, col_id);
4841 } else {
4842 gtk_tree_view_column_set_clickable(col, FALSE);
4843 }
4844 gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
4846
4848
4849 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
4850 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE);
4851 g_signal_connect(sel, "changed",
4852 G_CALLBACK(property_page_selection_changed), pp);
4853 gtk_tree_selection_set_select_function(sel,
4855
4856 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrollwin), view);
4857 pp->object_view = view;
4858
4860 hgrid = gtk_grid_new();
4861 gtk_grid_set_column_spacing(GTK_GRID(hgrid), 4);
4862 gtk_grid_attach(GTK_GRID(vgrid), hgrid, 0, grid_row++, 1, 1);
4863
4864 button = gtk_button_new();
4865 gtk_button_set_icon_name(GTK_BUTTON(button), "list-add");
4866 gtk_button_set_label(GTK_BUTTON(button), _("Create"));
4867 gtk_size_group_add_widget(sizegroup, button);
4868 gtk_widget_set_tooltip_text(button,
4869 _("Pressing this button will create a new object of the "
4870 "same type as the current property page and add it to "
4871 "the page. The specific type and count of the objects "
4872 "is taken from the editor tool state. So for example, "
4873 "the \"tool value\" of the unit tool and its \"count\" "
4874 "parameter affect unit creation."));
4875 g_signal_connect(button, "clicked",
4876 G_CALLBACK(property_page_create_button_clicked), pp);
4877 gtk_grid_attach(GTK_GRID(hgrid), button, grid_col++, 0, 1, 1);
4878
4879 button = gtk_button_new();
4880 gtk_button_set_icon_name(GTK_BUTTON(button), "list-remove");
4881 gtk_button_set_label(GTK_BUTTON(button), _("Destroy"));
4882 gtk_size_group_add_widget(sizegroup, button);
4883 gtk_widget_set_tooltip_text(button,
4884 _("Pressing this button will send a request to the server "
4885 "to destroy (i.e. erase) the objects selected in the object "
4886 "list."));
4887 g_signal_connect(button, "clicked",
4888 G_CALLBACK(property_page_destroy_button_clicked), pp);
4889 gtk_grid_attach(GTK_GRID(hgrid), button, grid_col++, 0, 1, 1);
4890 }
4891
4892 /* Right side properties panel. */
4893
4894 hgrid = gtk_grid_new();
4895 grid_col = 0;
4896 gtk_grid_set_column_spacing(GTK_GRID(hgrid), 4);
4897 gtk_paned_set_end_child(GTK_PANED(paned), hgrid);
4898
4899 vgrid = gtk_grid_new();
4900 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
4901 GTK_ORIENTATION_VERTICAL);
4902 gtk_grid_set_row_spacing(GTK_GRID(vgrid), 4);
4903 gtk_widget_set_margin_start(vgrid, 4);
4904 gtk_widget_set_margin_end(vgrid, 4);
4905 gtk_widget_set_margin_top(vgrid, 4);
4906 gtk_widget_set_margin_bottom(vgrid, 4);
4907 gtk_grid_attach(GTK_GRID(hgrid), vgrid, grid_col++, 0, 1, 1);
4908
4909 /* Extended property viewer to the right of the properties panel.
4910 * This needs to be created before property widgets, since some
4911 * might try to append themselves to this notebook. */
4912
4913 vgrid2 = gtk_grid_new();
4914 gtk_widget_set_hexpand(vgrid2, TRUE);
4915 gtk_widget_set_vexpand(vgrid, TRUE);
4916 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid2),
4917 GTK_ORIENTATION_VERTICAL);
4918 gtk_grid_set_row_spacing(GTK_GRID(vgrid2), 4);
4919 gtk_grid_attach(GTK_GRID(hgrid), vgrid2, grid_col++, 0, 1, 1);
4920
4921 notebook = gtk_notebook_new();
4922 gtk_widget_set_vexpand(notebook, TRUE);
4923 gtk_widget_set_size_request(notebook, 256, -1);
4924 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
4925 gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
4926 gtk_grid_attach(GTK_GRID(vgrid2), notebook, 0, grid2_row++, 1, 1);
4927 pp->extviewer_notebook = notebook;
4928
4929 hsep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
4930 gtk_grid_attach(GTK_GRID(vgrid2), hsep, 0, grid2_row++, 1, 1);
4931
4932 hgrid2 = gtk_grid_new();
4933 gtk_widget_set_margin_start(hgrid2, 4);
4934 gtk_widget_set_margin_end(hgrid2, 4);
4935 gtk_widget_set_margin_top(hgrid2, 4);
4936 gtk_widget_set_margin_bottom(hgrid2, 4);
4937 gtk_grid_attach(GTK_GRID(vgrid2), hgrid2, 0, grid2_row++, 1, 1);
4938
4939 button = gtk_button_new_with_mnemonic(_("_Close"));
4940 gtk_size_group_add_widget(sizegroup, button);
4941 g_signal_connect_swapped(button, "clicked",
4942 G_CALLBACK(gtk_widget_hide), pe->widget);
4943 gtk_grid_attach(GTK_GRID(hgrid2), button, grid2_col++, 0, 1, 1);
4944
4945 /* Now create the properties panel. */
4946
4947 /* TRANS: %s is a type of object that can be edited, such as "Tile",
4948 * "Unit", "Start Position", etc. */
4949 title = g_strdup_printf(_("%s Properties"),
4951 frame = gtk_frame_new(title);
4952 g_free(title);
4953 gtk_widget_set_size_request(frame, 256, -1);
4954 gtk_grid_attach(GTK_GRID(vgrid), frame, 0, grid_row++, 1, 1);
4955
4956 scrollwin = gtk_scrolled_window_new();
4957 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(scrollwin),
4958 FALSE);
4959 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
4960 GTK_POLICY_AUTOMATIC,
4961 GTK_POLICY_AUTOMATIC);
4962 gtk_frame_set_child(GTK_FRAME(frame), scrollwin);
4963
4964 vgrid2 = gtk_grid_new();
4965 grid2_row = 0;
4966 gtk_widget_set_vexpand(vgrid2, TRUE);
4967 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid2),
4968 GTK_ORIENTATION_VERTICAL);
4969 gtk_grid_set_row_spacing(GTK_GRID(vgrid2), 4);
4970 gtk_widget_set_margin_start(vgrid2, 4);
4971 gtk_widget_set_margin_end(vgrid2, 4);
4972 gtk_widget_set_margin_top(vgrid2, 4);
4973 gtk_widget_set_margin_bottom(vgrid2, 4);
4974 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrollwin), vgrid2);
4975
4977 if (!objprop_has_widget(op)) {
4978 continue;
4979 }
4980 w = objprop_get_widget(op);
4981 if (!w) {
4982 continue;
4983 }
4984 gtk_grid_attach(GTK_GRID(vgrid2), w, 0, grid2_row++, 1, 1);
4986 if (NULL != tooltip) {
4987 gtk_widget_set_tooltip_text(w, tooltip);
4988 }
4990
4991 hgrid2 = gtk_grid_new();
4992 grid2_col = 0;
4993 gtk_widget_set_margin_top(hgrid2, 4);
4994 gtk_widget_set_margin_bottom(hgrid2, 4);
4995 gtk_grid_set_column_spacing(GTK_GRID(hgrid2), 4);
4996 gtk_grid_attach(GTK_GRID(vgrid), hgrid2, 0, grid_row++, 1, 1);
4997
4998 label = gtk_label_new(_("Filter:"));
4999 gtk_grid_attach(GTK_GRID(hgrid2), label, grid2_col++, 0, 1, 1);
5000
5001 entry = gtk_entry_new();
5002 gtk_widget_set_tooltip_text(entry,
5003 _("Enter a filter string to limit which properties are shown. "
5004 "The filter is one or more text patterns separated by | "
5005 "(\"or\") or & (\"and\"). The symbol & has higher precedence "
5006 "than |. A pattern may also be negated by prefixing it with !."));
5007 g_signal_connect(entry, "changed",
5009 gtk_grid_attach(GTK_GRID(hgrid2), entry, grid2_col++, 0, 1, 1);
5010
5011 hgrid2 = gtk_grid_new();
5012 grid2_col = 0;
5013 gtk_grid_set_column_spacing(GTK_GRID(hgrid2), 4);
5014 gtk_grid_attach(GTK_GRID(vgrid), hgrid2, 0, grid_row++, 1, 1);
5015
5016 button = gtk_button_new_with_mnemonic(_("_Refresh"));
5017 gtk_size_group_add_widget(sizegroup, button);
5018 gtk_widget_set_tooltip_text(button,
5019 _("Pressing this button will reset all modified properties of "
5020 "the selected objects to their current values (the values "
5021 "they have on the server)."));
5022 g_signal_connect(button, "clicked",
5023 G_CALLBACK(property_page_refresh_button_clicked), pp);
5024 gtk_grid_attach(GTK_GRID(hgrid2), button, grid2_col++, 0, 1, 1);
5025
5026 button = gtk_button_new_with_mnemonic(_("_Apply"));
5027 gtk_size_group_add_widget(sizegroup, button);
5028 gtk_widget_set_tooltip_text(button,
5029 _("Pressing this button will send all modified properties of "
5030 "the objects selected in the object list to the server. "
5031 "Modified properties' names are shown in red in the properties "
5032 "panel."));
5033 g_signal_connect(button, "clicked",
5034 G_CALLBACK(property_page_apply_button_clicked), pp);
5035 gtk_grid_attach(GTK_GRID(hgrid2), button, grid2_col++, 0, 1, 1);
5036
5037 return pp;
5038}
5039
5040/************************************************************************/
5043static const char *property_page_get_name(const struct property_page *pp)
5044{
5045 if (!pp) {
5046 return "";
5047 }
5049}
5050
5051/************************************************************************/
5054static enum editor_object_type
5056{
5057 if (!pp) {
5058 return -1;
5059 }
5060 return pp->objtype;
5061}
5062
5063/************************************************************************/
5071static GdkPixbuf *create_tile_pixbuf(const struct tile *ptile)
5072{
5073 return create_pixbuf_from_layers(ptile, NULL, NULL, LAYER_CATEGORY_TILE);
5074}
5075
5076/************************************************************************/
5083static GdkPixbuf *create_unit_pixbuf(const struct unit *punit)
5084{
5086}
5087
5088/************************************************************************/
5095static GdkPixbuf *create_city_pixbuf(const struct city *pcity)
5096{
5097 return create_pixbuf_from_layers(city_tile(pcity), NULL, pcity,
5099}
5100
5101/************************************************************************/
5109static GdkPixbuf *create_pixbuf_from_layers(const struct tile *ptile,
5110 const struct unit *punit,
5111 const struct city *pcity,
5112 enum layer_category category)
5113{
5115 int h, fh, fw, canvas_x, canvas_y;
5116 GdkPixbuf *pixbuf;
5117 cairo_t *cr;
5118
5122
5123 canvas.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, fw, fh);
5124
5125 cr = cairo_create(canvas.surface);
5126 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
5127 cairo_paint(cr);
5128 cairo_destroy(cr);
5129
5130 canvas_x = 0;
5131 canvas_y = 0;
5132
5133 canvas_y += (fh - h);
5134
5135 mapview_layer_iterate(layer) {
5136 if (tileset_layer_in_category(layer, category)) {
5137 put_one_element(&canvas, 1.0, layer,
5138 ptile, NULL, NULL, punit, pcity,
5139 canvas_x, canvas_y, NULL, NULL);
5140 }
5142 pixbuf = surface_get_pixbuf(canvas.surface, fw, fh);
5143 cairo_surface_destroy(canvas.surface);
5144
5145 return pixbuf;
5146}
5147
5148/************************************************************************/
5152{
5153 if (!pp) {
5154 return;
5155 }
5156
5157 gtk_list_store_clear(pp->object_store);
5158 objbind_hash_clear(pp->objbind_table);
5160}
5161
5162/************************************************************************/
5167 gpointer object_data)
5168{
5169 struct objbind *ob;
5171 int id;
5172
5173 if (!pp) {
5174 return;
5175 }
5176
5178 id = objtype_get_id_from_object(objtype, object_data);
5179 if (id < 0) {
5180 return;
5181 }
5182
5183 if (objbind_hash_lookup(pp->objbind_table, id, NULL)) {
5184 /* Object already exists. */
5185 return;
5186 }
5187
5188 ob = objbind_new(objtype, object_data);
5189 if (!ob) {
5190 return;
5191 }
5192
5194
5195 objbind_hash_insert(pp->objbind_table, ob->object_id, ob);
5196}
5197
5198/************************************************************************/
5203 const struct tile *ptile)
5204{
5205
5206 if (!pp || !ptile) {
5207 return;
5208 }
5209
5210 switch (property_page_get_objtype(pp)) {
5211 case OBJTYPE_TILE:
5212 property_page_add_objbind(pp, (gpointer) ptile);
5213 return;
5214
5215 case OBJTYPE_STARTPOS:
5216 {
5217 struct startpos *psp = map_startpos_get(ptile);
5218
5219 if (NULL != psp) {
5221 }
5222 }
5223 return;
5224
5225 case OBJTYPE_UNIT:
5226 unit_list_iterate(ptile->units, punit) {
5229 return;
5230
5231 case OBJTYPE_CITY:
5232 if (tile_city(ptile)) {
5234 }
5235 return;
5236
5237 case OBJTYPE_PLAYER:
5238 case OBJTYPE_GAME:
5239 return;
5240
5241 case NUM_OBJTYPES:
5242 break;
5243 }
5244
5245 log_error("%s(): Unhandled page object type %s (nb %d).", __FUNCTION__,
5248}
5249
5250/************************************************************************/
5257 struct objprop *op,
5258 struct objbind *ob,
5259 GtkTreeIter *iter)
5260{
5261 int col_id;
5262 struct propval *pv;
5263 enum value_types valtype;
5264 char buf[128], *p;
5265 GdkPixbuf *pixbuf = NULL;
5266 GtkListStore *store;
5267 gchar *buf2;
5268
5269 if (!pp || !pp->object_store || !op || !ob) {
5270 return FALSE;
5271 }
5272
5273 if (!objprop_show_in_listview(op)) {
5274 return FALSE;
5275 }
5276
5277 col_id = objprop_get_column_id(op);
5278 if (col_id < 0) {
5279 return FALSE;
5280 }
5281
5282 pv = objbind_get_value_from_object(ob, op);
5283 if (!pv) {
5284 return FALSE;
5285 }
5286
5288 store = pp->object_store;
5289
5290 switch (valtype) {
5291 case VALTYPE_NONE:
5292 break;
5293 case VALTYPE_INT:
5294 gtk_list_store_set(store, iter, col_id, pv->data.v_int, -1);
5295 break;
5296 case VALTYPE_BOOL:
5297 /* Set as translated string, not as untranslated G_TYPE_BOOLEAN */
5298 gtk_list_store_set(store, iter, col_id, propval_as_string(pv), -1);
5299 break;
5300 case VALTYPE_STRING:
5301 if (fc_strlcpy(buf, pv->data.v_string, 28) >= 28) {
5302 sz_strlcat(buf, "...");
5303 }
5304 for (p = buf; *p; p++) {
5305 if (*p == '\n' || *p == '\t' || *p == '\r') {
5306 *p = ' ';
5307 }
5308 }
5309 gtk_list_store_set(store, iter, col_id, buf, -1);
5310 break;
5311 case VALTYPE_PIXBUF:
5312 gtk_list_store_set(store, iter, col_id, pv->data.v_pixbuf, -1);
5313 break;
5316 case VALTYPE_BV_SPECIAL:
5317 case VALTYPE_BV_ROADS:
5318 case VALTYPE_BV_BASES:
5320 buf2 = propval_as_string(pv);
5321 gtk_list_store_set(store, iter, col_id, buf2, -1);
5322 g_free(buf2);
5323 break;
5324 case VALTYPE_NATION:
5325 pixbuf = get_flag(pv->data.v_nation);
5326 gtk_list_store_set(store, iter, col_id, pixbuf, -1);
5327 if (pixbuf) {
5328 g_object_unref(pixbuf);
5329 }
5330 break;
5331 case VALTYPE_GOV:
5333 gtk_list_store_set(store, iter, col_id, pixbuf, -1);
5334 if (pixbuf) {
5335 g_object_unref(pixbuf);
5336 }
5337 break;
5339 break;
5340 }
5341
5342 propval_free(pv);
5343
5344 return TRUE;
5345}
5346
5347/************************************************************************/
5352{
5353 struct objbind *focused;
5354
5355 if (!pp || !pp->objbind_table) {
5356 return;
5357 }
5358
5359 if (pp->object_store) {
5360 GtkTreeIter iter;
5361 GtkTreeRowReference *rr;
5362 GtkTreeModel *model;
5363 GtkTreePath *path;
5364
5365 model = GTK_TREE_MODEL(pp->object_store);
5366
5368 if (objbind_get_rowref(ob)) {
5369 continue;
5370 }
5371 gtk_list_store_append(pp->object_store, &iter);
5372 gtk_list_store_set(pp->object_store, &iter, 0, ob, -1);
5373 path = gtk_tree_model_get_path(model, &iter);
5374 rr = gtk_tree_row_reference_new(model, path);
5375 gtk_tree_path_free(path);
5376 objbind_set_rowref(ob, rr);
5377
5379 property_page_set_store_value(pp, op, ob, &iter);
5382
5383 if (gtk_tree_model_get_iter_first(model, &iter)) {
5384 GtkTreeSelection *sel;
5385 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pp->object_view));
5386 gtk_tree_selection_select_iter(sel, &iter);
5387 }
5388 }
5389
5392 objprop_refresh_widget(op, focused);
5394}
5395
5396/************************************************************************/
5401{
5402 if (!pp) {
5403 return NULL;
5404 }
5405 return pp->focused_objbind;
5406}
5407
5408/************************************************************************/
5413 struct objbind *ob)
5414{
5415 if (!pp) {
5416 return;
5417 }
5418 pp->focused_objbind = ob;
5419}
5420
5421/************************************************************************/
5426 int object_id)
5427{
5428 struct objbind *ob;
5429
5430 if (!pp || !pp->objbind_table) {
5431 return NULL;
5432 }
5433
5434 objbind_hash_lookup(pp->objbind_table, object_id, &ob);
5435 return ob;
5436}
5437
5438/************************************************************************/
5443 const struct tile_list *tiles)
5444{
5445 if (!pp || !tiles) {
5446 return;
5447 }
5448
5449 tile_list_iterate(tiles, ptile) {
5452
5454}
5455
5456/************************************************************************/
5460{
5461 if (!pp || !pp->objbind_table) {
5462 return 0;
5463 }
5464 return objbind_hash_size(pp->objbind_table);
5465}
5466
5467/************************************************************************/
5472 struct objprop *op,
5473 struct propval *pv)
5474{
5475 GtkTreeSelection *sel;
5476 GtkTreeModel *model;
5477 GList *rows, *p;
5478 GtkTreePath *path;
5479 GtkTreeIter iter;
5480 struct objbind *ob;
5481 bool changed = FALSE;
5482
5483 if (!pp || !op || !pp->object_view) {
5484 return;
5485 }
5486
5487 if (objprop_is_readonly(op)) {
5488 return;
5489 }
5490
5491 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pp->object_view));
5492 rows = gtk_tree_selection_get_selected_rows(sel, &model);
5493
5494 for (p = rows; p != NULL; p = p->next) {
5495 path = p->data;
5496 if (gtk_tree_model_get_iter(model, &iter, path)) {
5497 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5498 changed |= objbind_set_modified_value(ob, op, pv);
5499 }
5500 gtk_tree_path_free(path);
5501 }
5502 g_list_free(rows);
5503
5504 if (changed) {
5506 objprop_refresh_widget(op, ob);
5507 }
5508}
5509
5510/************************************************************************/
5514{
5515 GtkTreeSelection *sel;
5516 GtkTreeModel *model;
5517 GList *rows, *p;
5518 GtkTreePath *path;
5519 GtkTreeIter iter;
5520 struct objbind *ob;
5521 union packetdata packet;
5522 struct connection *my_conn = &client.conn;
5523
5524 if (!pp || !pp->object_view) {
5525 return;
5526 }
5527
5528 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pp->object_view));
5529 if (gtk_tree_selection_count_selected_rows(sel) < 1) {
5530 return;
5531 }
5532
5533 packet = property_page_new_packet(pp);
5534 if (!packet.pointers.v_pointer1) {
5535 return;
5536 }
5537
5538 rows = gtk_tree_selection_get_selected_rows(sel, &model);
5539 connection_do_buffer(my_conn);
5540 for (p = rows; p != NULL; p = p->next) {
5541 path = p->data;
5542 if (gtk_tree_model_get_iter(model, &iter, path)) {
5543 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5545 objbind_pack_current_values(ob, packet);
5547 if (objprop_is_readonly(op)) {
5548 continue;
5549 }
5550 objbind_pack_modified_value(ob, op, packet);
5552 property_page_send_packet(pp, packet);
5553 }
5554 }
5555 gtk_tree_path_free(path);
5556 }
5557 connection_do_unbuffer(my_conn);
5558 g_list_free(rows);
5559
5560 property_page_free_packet(pp, packet);
5561}
5562
5563/************************************************************************/
5568{
5569 union packetdata packet;
5570
5571 packet.pointers.v_pointer2 = NULL;
5572
5573 if (!pp) {
5574 packet.pointers.v_pointer1 = NULL;
5575 return packet;
5576 }
5577
5578 switch (property_page_get_objtype(pp)) {
5579 case OBJTYPE_TILE:
5580 packet.tile = fc_calloc(1, sizeof(*packet.tile));
5581 break;
5582 case OBJTYPE_STARTPOS:
5583 packet.startpos = fc_calloc(1, sizeof(*packet.startpos));
5584 break;
5585 case OBJTYPE_UNIT:
5586 packet.unit = fc_calloc(1, sizeof(*packet.unit));
5587 break;
5588 case OBJTYPE_CITY:
5589 packet.city = fc_calloc(1, sizeof(*packet.city));
5590 break;
5591 case OBJTYPE_PLAYER:
5592 packet.player = fc_calloc(1, sizeof(*packet.player));
5593 break;
5594 case OBJTYPE_GAME:
5595 packet.game.game = fc_calloc(1, sizeof(*packet.game.game));
5596 packet.game.desc = fc_calloc(1, sizeof(*packet.game.desc));
5597 break;
5598 case NUM_OBJTYPES:
5599 break;
5600 }
5601
5602 return packet;
5603}
5604
5605/************************************************************************/
5609 union packetdata packet)
5610{
5611 struct connection *my_conn = &client.conn;
5612
5613 if (!pp || !packet.pointers.v_pointer1) {
5614 return;
5615 }
5616
5617 switch (property_page_get_objtype(pp)) {
5618 case OBJTYPE_TILE:
5619 send_packet_edit_tile(my_conn, packet.tile);
5620 return;
5621 case OBJTYPE_STARTPOS:
5623 return;
5624 case OBJTYPE_UNIT:
5625 send_packet_edit_unit(my_conn, packet.unit);
5626 return;
5627 case OBJTYPE_CITY:
5628 send_packet_edit_city(my_conn, packet.city);
5629 return;
5630 case OBJTYPE_PLAYER:
5631 send_packet_edit_player(my_conn, packet.player);
5632 return;
5633 case OBJTYPE_GAME:
5634 send_packet_edit_game(my_conn, packet.game.game);
5635 send_packet_edit_scenario_desc(my_conn, packet.game.desc);
5636 return;
5637 case NUM_OBJTYPES:
5638 break;
5639 }
5640
5641 log_error("%s(): Unhandled object type %s (nb %d).",
5644}
5645
5646/************************************************************************/
5650 union packetdata packet)
5651{
5652 if (!packet.pointers.v_pointer1) {
5653 return;
5654 }
5655
5656 free(packet.pointers.v_pointer1);
5657 packet.pointers.v_pointer1 = NULL;
5658
5659 if (packet.pointers.v_pointer2 != NULL) {
5660 free(packet.pointers.v_pointer2);
5661 packet.pointers.v_pointer2 = NULL;
5662 }
5663}
5664
5665/************************************************************************/
5670{
5671 GtkTreeSelection *sel;
5672 GtkTreeModel *model;
5673 GtkTreeIter iter;
5674 GtkTreePath *path;
5675 GList *rows, *p;
5676 struct objbind *ob;
5677
5678 if (!pp || !pp->object_view) {
5679 return;
5680 }
5681
5682 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pp->object_view));
5683 if (gtk_tree_selection_count_selected_rows(sel) < 1) {
5684 return;
5685 }
5686
5687 rows = gtk_tree_selection_get_selected_rows(sel, &model);
5688 for (p = rows; p != NULL; p = p->next) {
5689 path = p->data;
5690 if (gtk_tree_model_get_iter(model, &iter, path)) {
5691 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5694 property_page_set_store_value(pp, op, ob, &iter);
5696 }
5697 gtk_tree_path_free(path);
5698 }
5699 g_list_free(rows);
5700
5703 objprop_refresh_widget(op, ob);
5705}
5706
5707/************************************************************************/
5711{
5712 GtkTreeSelection *sel;
5713 GtkTreeModel *model;
5714 GtkTreeIter iter;
5715 GtkTreePath *path;
5716 GList *rows, *p;
5717 struct objbind *ob;
5718 struct connection *my_conn = &client.conn;
5719
5720 if (!pp || !pp->object_view) {
5721 return;
5722 }
5723
5724 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pp->object_view));
5725 if (gtk_tree_selection_count_selected_rows(sel) < 1) {
5726 return;
5727 }
5728
5729 rows = gtk_tree_selection_get_selected_rows(sel, &model);
5730 connection_do_buffer(my_conn);
5731 for (p = rows; p != NULL; p = p->next) {
5732 path = p->data;
5733 if (gtk_tree_model_get_iter(model, &iter, path)) {
5734 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5736 }
5737 gtk_tree_path_free(path);
5738 }
5739 connection_do_unbuffer(my_conn);
5740 g_list_free(rows);
5741}
5742
5743/************************************************************************/
5750 struct tile_list *hint_tiles)
5751{
5753 int apno, value, count, size;
5754 int tag;
5755 struct connection *my_conn = &client.conn;
5756 struct tile *ptile = NULL;
5757 struct player *pplayer;
5758
5759 if (!pp) {
5760 return;
5761 }
5762
5765 return;
5766 }
5767
5768 tag = get_next_unique_tag();
5769 count = 1;
5770
5771 switch (objtype) {
5772 case OBJTYPE_STARTPOS:
5773 if (hint_tiles) {
5774 tile_list_iterate(hint_tiles, atile) {
5775 if (NULL == map_startpos_get(atile)) {
5776 ptile = atile;
5777 break;
5778 }
5780 }
5781
5782 if (NULL == ptile) {
5783 ptile = get_center_tile_mapcanvas();
5784 }
5785
5786 if (NULL == ptile) {
5787 break;
5788 }
5789
5790 dsend_packet_edit_startpos(my_conn, tile_index(ptile), FALSE, tag);
5791 break;
5792
5793 case OBJTYPE_UNIT:
5794 if (hint_tiles) {
5795 tile_list_iterate(hint_tiles, atile) {
5796 if (can_create_unit_at_tile(atile)) {
5797 ptile = atile;
5798 break;
5799 }
5801 }
5802
5803 if (!ptile) {
5804 struct unit *punit;
5808 ptile = unit_tile(punit);
5809 break;
5810 }
5812 }
5813
5814 if (!ptile) {
5815 ptile = get_center_tile_mapcanvas();
5816 }
5817
5818 if (!ptile) {
5819 break;
5820 }
5821
5825 dsend_packet_edit_unit_create(my_conn, apno, tile_index(ptile),
5826 value, count, tag);
5827 break;
5828
5829 case OBJTYPE_CITY:
5831 pplayer = player_by_number(apno);
5832 if (pplayer && hint_tiles) {
5833 tile_list_iterate(hint_tiles, atile) {
5834 if (!is_enemy_unit_tile(atile, pplayer)
5835 && city_can_be_built_here(&(wld.map), atile,
5836 NULL, FALSE)) {
5837 ptile = atile;
5838 break;
5839 }
5841 }
5842
5843 if (!ptile) {
5844 ptile = get_center_tile_mapcanvas();
5845 }
5846
5847 if (!ptile) {
5848 break;
5849 }
5850
5852 dsend_packet_edit_city_create(my_conn, apno, tile_index(ptile),
5853 size, tag);
5854 break;
5855
5856 case OBJTYPE_PLAYER:
5857 dsend_packet_edit_player_create(my_conn, tag);
5858 break;
5859
5860 case OBJTYPE_TILE:
5861 case OBJTYPE_GAME:
5862 case NUM_OBJTYPES:
5863 break;
5864 }
5865
5866 property_page_store_creation_tag(pp, tag, count);
5867}
5868
5869/************************************************************************/
5875 int object_id,
5876 bool removed)
5877{
5878 struct objbind *ob;
5879 GtkTreeRowReference *rr;
5880
5882 if (!ob) {
5883 return;
5884 }
5885
5886 rr = objbind_get_rowref(ob);
5887 if (rr && gtk_tree_row_reference_valid(rr)) {
5888 GtkTreePath *path;
5889 GtkTreeIter iter;
5890 GtkTreeModel *model;
5891
5892 model = GTK_TREE_MODEL(pp->object_store);
5893 path = gtk_tree_row_reference_get_path(rr);
5894
5895 if (gtk_tree_model_get_iter(model, &iter, path)) {
5896 if (removed) {
5897 gtk_list_store_remove(pp->object_store, &iter);
5898 } else {
5900 property_page_set_store_value(pp, op, ob, &iter);
5902 }
5903 }
5904
5905 gtk_tree_path_free(path);
5906 }
5907
5908 if (removed) {
5909 objbind_hash_remove(pp->objbind_table, object_id);
5910 return;
5911 }
5912
5913 if (ob == property_page_get_focused_objbind(pp)) {
5915 objprop_refresh_widget(op, ob);
5917 }
5918}
5919
5920/************************************************************************/
5927 int tag, int object_id)
5928{
5929 gpointer object;
5931
5932 if (!property_page_tag_is_known(pp, tag)) {
5933 return;
5934 }
5936
5939
5940 if (!object) {
5941 return;
5942 }
5943
5944 property_page_add_objbind(pp, object);
5946}
5947
5948/************************************************************************/
5953 struct extviewer *ev)
5954{
5955 GtkWidget *w;
5956
5957 if (!pp || !ev) {
5958 return;
5959 }
5960
5962 if (!w) {
5963 return;
5964 }
5965 gtk_notebook_append_page(GTK_NOTEBOOK(pp->extviewer_notebook), w, NULL);
5966}
5967
5968/************************************************************************/
5973 struct extviewer *ev)
5974{
5975 GtkWidget *w;
5976 GtkNotebook *notebook;
5977 int page;
5978
5979 if (!pp || !ev) {
5980 return;
5981 }
5982
5984 if (!w) {
5985 return;
5986 }
5987
5988 notebook = GTK_NOTEBOOK(pp->extviewer_notebook);
5989 page = gtk_notebook_page_num(notebook, w);
5990 gtk_notebook_set_current_page(notebook, page);
5991}
5992
5993/************************************************************************/
5998 int tag, int count)
5999{
6000 if (!pp || !pp->tag_table) {
6001 return;
6002 }
6003
6004 if (stored_tag_hash_lookup(pp->tag_table, tag, NULL)) {
6005 log_error("Attempted to insert object creation tag %d "
6006 "twice into tag table for property page %p (%d %s).",
6007 tag, pp, property_page_get_objtype(pp),
6009 return;
6010 }
6011
6012 stored_tag_hash_insert(pp->tag_table, tag, count);
6013}
6014
6015/************************************************************************/
6020 int tag)
6021{
6022 int count;
6023
6024 if (!pp || !pp->tag_table) {
6025 return;
6026 }
6027
6028 if (stored_tag_hash_lookup(pp->tag_table, tag, &count)) {
6029 if (0 >= --count) {
6030 stored_tag_hash_remove(pp->tag_table, tag);
6031 }
6032 }
6033}
6034
6035/************************************************************************/
6038static bool property_page_tag_is_known(struct property_page *pp, int tag)
6039{
6040 if (!pp || !pp->tag_table) {
6041 return FALSE;
6042 }
6043 return stored_tag_hash_lookup(pp->tag_table, tag, NULL);
6044}
6045
6046/************************************************************************/
6050{
6051 if (!pp || !pp->tag_table) {
6052 return;
6053 }
6054 stored_tag_hash_clear(pp->tag_table);
6055}
6056
6057/************************************************************************/
6060static void property_page_apply_button_clicked(GtkButton *button,
6061 gpointer userdata)
6062{
6063 struct property_page *pp = userdata;
6065}
6066
6067/************************************************************************/
6071static void property_page_refresh_button_clicked(GtkButton *button,
6072 gpointer userdata)
6073{
6074 struct property_page *pp = userdata;
6076}
6077
6078/************************************************************************/
6081static void property_page_create_button_clicked(GtkButton *button,
6082 gpointer userdata)
6083{
6084 struct property_page *pp = userdata, *tile_pp;
6085 struct tile_list *tiles = NULL;
6086 struct tile *ptile;
6087
6088 if (!pp) {
6089 return;
6090 }
6091
6093 tiles = tile_list_new();
6094
6095 property_page_objbind_iterate(tile_pp, ob) {
6096 ptile = objbind_get_object(ob);
6097 if (ptile) {
6098 tile_list_append(tiles, ptile);
6099 }
6101
6103 tile_list_destroy(tiles);
6104}
6105
6106/************************************************************************/
6109static void property_page_destroy_button_clicked(GtkButton *button,
6110 gpointer userdata)
6111{
6112 struct property_page *pp = userdata;
6114}
6115
6116/************************************************************************/
6122{
6123 struct property_page *pp;
6124 GtkWidget *label;
6125 const char *name;
6126
6127 if (!pe || !pe->notebook) {
6128 return FALSE;
6129 }
6130
6131 if (!(objtype < NUM_OBJTYPES)) {
6132 return FALSE;
6133 }
6134
6135 pp = property_page_new(objtype, pe);
6136 if (!pp) {
6137 return FALSE;
6138 }
6139
6141 label = gtk_label_new(name);
6142 gtk_notebook_append_page(GTK_NOTEBOOK(pe->notebook),
6143 pp->widget, label);
6144
6145 pe->property_pages[objtype] = pp;
6146
6147 return TRUE;
6148}
6149
6150/************************************************************************/
6153static struct property_page *
6156{
6157 if (!pe || !(objtype < NUM_OBJTYPES)) {
6158 return NULL;
6159 }
6160
6161 return pe->property_pages[objtype];
6162}
6163
6164/************************************************************************/
6168{
6169 struct property_editor *pe;
6170 GtkWidget *win, *notebook, *vgrid;
6172 int grid_row = 0;
6173
6174 pe = fc_calloc(1, sizeof(*pe));
6175
6176 /* The property editor dialog window. */
6177
6178 win = gtk_window_new();
6179 gtk_window_set_title(GTK_WINDOW(win), _("Property Editor"));
6180 gtk_window_set_resizable(GTK_WINDOW(win), TRUE);
6181 gtk_window_set_default_size(GTK_WINDOW(win), 780, 560);
6182 gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(toplevel));
6183 gtk_window_set_destroy_with_parent(GTK_WINDOW(win), TRUE);
6184 gtk_widget_set_margin_start(win, 4);
6185 gtk_widget_set_margin_end(win, 4);
6186 gtk_widget_set_margin_top(win, 4);
6187 gtk_widget_set_margin_bottom(win, 4);
6188 gtk_window_set_hide_on_close(GTK_WINDOW(win), TRUE);
6189 pe->widget = win;
6190
6191 vgrid = gtk_grid_new();
6192 gtk_window_set_child(GTK_WINDOW(win), vgrid);
6193
6194 /* Property pages. */
6195
6196 notebook = gtk_notebook_new();
6197 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
6198 gtk_grid_attach(GTK_GRID(vgrid), notebook, 0, grid_row++, 1, 1);
6199 pe->notebook = notebook;
6200
6201 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6203 }
6204
6205 return pe;
6206}
6207
6208/************************************************************************/
6218
6219/************************************************************************/
6223 const struct tile_list *tiles)
6224{
6225 struct property_page *pp;
6227 int i;
6228 const enum editor_object_type preferred[] = {
6233 };
6234
6235 if (!pe || !tiles) {
6236 return;
6237 }
6238
6239 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6241 property_page_load_tiles(pp, tiles);
6242 }
6243
6244 for (i = 0; i < ARRAY_SIZE(preferred) - 1; i++) {
6245 pp = property_editor_get_page(pe, preferred[i]);
6246 if (property_page_get_num_objbinds(pp) > 0) {
6247 break;
6248 }
6249 }
6250 objtype = preferred[i];
6251 gtk_notebook_set_current_page(GTK_NOTEBOOK(pe->notebook), objtype);
6252}
6253
6254/************************************************************************/
6260{
6261 if (!pe || !pe->widget) {
6262 return;
6263 }
6264
6265 gtk_widget_show(pe->widget);
6266
6267 gtk_window_present(GTK_WINDOW(pe->widget));
6268 if (objtype < NUM_OBJTYPES) {
6269 gtk_notebook_set_current_page(GTK_NOTEBOOK(pe->notebook), objtype);
6270 }
6271}
6272
6273/************************************************************************/
6277{
6278 if (!pe || !pe->widget) {
6279 return;
6280 }
6281 gtk_widget_hide(pe->widget);
6282}
6283
6284/************************************************************************/
6290 int object_id,
6291 bool remove)
6292{
6293 struct property_page *pp;
6294
6295 if (!pe) {
6296 return;
6297 }
6298
6299 if (!(objtype < NUM_OBJTYPES)) {
6300 return;
6301 }
6302
6304 property_page_object_changed(pp, object_id, remove);
6305}
6306
6307/************************************************************************/
6311 int tag, int object_id)
6312{
6314 struct property_page *pp;
6315
6316 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6318 continue;
6319 }
6321 property_page_object_created(pp, tag, object_id);
6322 }
6323}
6324
6325/************************************************************************/
6329{
6331 struct property_page *pp;
6332
6333 if (!pe) {
6334 return;
6335 }
6336
6337 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6341 }
6342}
6343
6344/************************************************************************/
6350{
6351 struct property_page *pp;
6352
6353 if (!pe) {
6354 return;
6355 }
6356
6358 if (!pp) {
6359 return;
6360 }
6361
6363
6364 switch (objtype) {
6365 case OBJTYPE_PLAYER:
6366 players_iterate(pplayer) {
6367 property_page_add_objbind(pp, pplayer);
6369 break;
6370 case OBJTYPE_GAME:
6372 break;
6373 case OBJTYPE_TILE:
6374 case OBJTYPE_STARTPOS:
6375 case OBJTYPE_UNIT:
6376 case OBJTYPE_CITY:
6377 case NUM_OBJTYPES:
6378 break;
6379 }
6380
6382 gtk_notebook_set_current_page(GTK_NOTEBOOK(pe->notebook), objtype);
6383}
6384
6385/************************************************************************/
6396static struct property_filter *property_filter_new(const char *filter)
6397{
6398 struct property_filter *pf;
6399 struct pf_conjunction *pfc;
6400 struct pf_pattern *pfp;
6401 int or_clause_count, and_clause_count;
6402 char *or_clauses[PF_MAX_CLAUSES], *and_clauses[PF_MAX_CLAUSES];
6403 const char *pattern;
6404 int i, j;
6405
6406 pf = fc_calloc(1, sizeof(*pf));
6407
6408 if (!filter || filter[0] == '\0') {
6409 return pf;
6410 }
6411
6412 or_clause_count = get_tokens(filter, or_clauses,
6415
6416 for (i = 0; i < or_clause_count; i++) {
6417 if (or_clauses[i][0] == '\0') {
6418 continue;
6419 }
6420 pfc = &pf->disjunction[pf->count];
6421
6422 and_clause_count = get_tokens(or_clauses[i], and_clauses,
6425
6426 for (j = 0; j < and_clause_count; j++) {
6427 if (and_clauses[j][0] == '\0') {
6428 continue;
6429 }
6430 pfp = &pfc->conjunction[pfc->count];
6431 pattern = and_clauses[j];
6432
6433 switch (pattern[0]) {
6434 case '!':
6435 pfp->negate = TRUE;
6436 pfp->text = fc_strdup(pattern + 1);
6437 break;
6438 default:
6439 pfp->text = fc_strdup(pattern);
6440 break;
6441 }
6442 pfc->count++;
6443 }
6444 free_tokens(and_clauses, and_clause_count);
6445 pf->count++;
6446 }
6447
6448 free_tokens(or_clauses, or_clause_count);
6449
6450 return pf;
6451}
6452
6453/************************************************************************/
6471 const struct objprop *op)
6472{
6473 struct pf_pattern *pfp;
6474 struct pf_conjunction *pfc;
6475 const char *name;
6476 bool match, or_result, and_result;
6477 int i, j;
6478
6479 if (!pf) {
6480 return TRUE;
6481 }
6482 if (!op) {
6483 return FALSE;
6484 }
6485
6486 name = objprop_get_name(op);
6487 if (!name) {
6488 return FALSE;
6489 }
6490
6491 if (pf->count < 1) {
6492 return TRUE;
6493 }
6494
6495 or_result = FALSE;
6496
6497 for (i = 0; i < pf->count; i++) {
6498 pfc = &pf->disjunction[i];
6499 and_result = TRUE;
6500 for (j = 0; j < pfc->count; j++) {
6501 pfp = &pfc->conjunction[j];
6502 match = (pfp->text[0] == '\0'
6503 || fc_strcasestr(name, pfp->text));
6504 if (pfp->negate) {
6505 match = !match;
6506 }
6507 and_result = and_result && match;
6508 if (!and_result) {
6509 break;
6510 }
6511 }
6512 or_result = or_result || and_result;
6513 if (or_result) {
6514 break;
6515 }
6516 }
6517
6518 return or_result;
6519}
6520
6521/************************************************************************/
6525{
6526 struct pf_pattern *pfp;
6527 struct pf_conjunction *pfc;
6528 int i, j;
6529
6530 if (!pf) {
6531 return;
6532 }
6533
6534 for (i = 0; i < pf->count; i++) {
6535 pfc = &pf->disjunction[i];
6536 for (j = 0; j < pfc->count; j++) {
6537 pfp = &pfc->conjunction[j];
6538 if (pfp->text != NULL) {
6539 free(pfp->text);
6540 pfp->text = NULL;
6541 }
6542 }
6543 pfc->count = 0;
6544 }
6545 pf->count = 0;
6546 free(pf);
6547}
6548
6549/************************************************************************/
6552const char *vision_layer_get_name(enum vision_layer vl)
6553{
6554 switch (vl) {
6555 case V_MAIN:
6556 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6557 return _("Seen (Main)");
6558 case V_INVIS:
6559 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6560 return _("Seen (Invis)");
6561 case V_SUBSURFACE:
6562 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6563 return _("Seen (Subsurface)");
6564 case V_COUNT:
6565 break;
6566 }
6567
6568 log_error("%s(): Unrecognized vision layer %d.", __FUNCTION__, vl);
6569 return _("Unknown");
6570}
Base_type_id base_number(const struct base_type *pbase)
Definition base.c:92
Base_type_id base_count(void)
Definition base.c:109
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
int city_granary_size(int city_size)
Definition city.c:2101
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1456
#define city_tile(_pcity_)
Definition city.h:544
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
#define city_owner(_pcity_)
Definition city.h:543
#define MAX_CITY_SIZE
Definition city.h:98
#define I_DESTROYED
Definition city.h:240
#define I_NEVER
Definition city.h:239
struct civclient client
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition climisc.c:1491
void connection_do_buffer(struct connection *pc)
Definition connection.c:323
void connection_do_unbuffer(struct connection *pc)
Definition connection.c:335
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
int objtype
Definition editgui_g.h:28
int int id
Definition editgui_g.h:28
int editor_tool_get_size(enum editor_tool_type ett)
Definition editor.c:1218
int editor_tool_get_value(enum editor_tool_type ett)
Definition editor.c:409
int editor_tool_get_count(enum editor_tool_type ett)
Definition editor.c:1252
struct unit * editor_unit_virtual_create(void)
Definition editor.c:1405
int editor_tool_get_applied_player(enum editor_tool_type ett)
Definition editor.c:1341
editor_object_type
Definition editor.h:25
@ OBJTYPE_PLAYER
Definition editor.h:30
@ OBJTYPE_UNIT
Definition editor.h:28
@ OBJTYPE_STARTPOS
Definition editor.h:27
@ OBJTYPE_GAME
Definition editor.h:31
@ NUM_OBJTYPES
Definition editor.h:33
@ OBJTYPE_CITY
Definition editor.h:29
@ OBJTYPE_TILE
Definition editor.h:26
@ ETT_UNIT
Definition editor.h:42
@ ETT_CITY
Definition editor.h:43
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:241
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
#define extra_index(_e_)
Definition extras.h:177
#define extra_base_get(_e_)
Definition extras.h:184
#define extra_road_get(_e_)
Definition extras.h:185
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
void free_tokens(char **tokens, size_t ntokens)
Definition fc_cmdline.c:203
int get_tokens(const char *str, char **tokens, size_t num_tokens, const char *delimiterset)
Definition fc_cmdline.c:166
const struct functions * fc_funcs
#define EC_SPECIAL
Definition fc_types.h:968
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
struct unit * game_unit_by_number(int id)
Definition game.c:111
struct city * game_city_by_number(int id)
Definition game.c:102
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
Government_type_id government_count(void)
Definition government.c:70
struct government * government_by_number(const Government_type_id gov)
Definition government.c:102
Government_type_id government_index(const struct government *pgovern)
Definition government.c:81
#define governments_iterate(NAME_pgov)
Definition government.h:120
#define governments_iterate_end
Definition government.h:123
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:27
static void add_column(GtkWidget *view, int col_id, const char *name, GType gtype, bool editable, bool is_radio, GCallback edit_callback, gpointer callback_userdata)
Definition editprop.c:817
static void property_page_reset_objbinds(struct property_page *pp)
Definition editprop.c:5644
static void property_page_send_values(struct property_page *pp)
Definition editprop.c:5488
static void objprop_setup_widget(struct objprop *op)
Definition editprop.c:2922
static void property_page_store_creation_tag(struct property_page *pp, int tag, int count)
Definition editprop.c:5972
static gchar * propval_as_string(struct propval *pv)
Definition editprop.c:859
static struct property_page * objprop_get_property_page(const struct objprop *op)
Definition editprop.c:3430
static const char * objprop_get_name(const struct objprop *op)
Definition editprop.c:2802
const char * vision_layer_get_name(enum vision_layer)
Definition editprop.c:6526
static int objbind_get_object_id(struct objbind *ob)
Definition editprop.c:1374
static void objprop_set_extviewer(struct objprop *op, struct extviewer *ev)
Definition editprop.c:3407
static GtkWidget * extviewer_get_panel_widget(struct extviewer *ev)
Definition editprop.c:3763
static gpointer objtype_get_object_from_id(enum editor_object_type objtype, int id)
Definition editprop.c:722
void property_editor_handle_object_changed(struct property_editor *pe, enum editor_object_type objtype, int object_id, bool remove)
Definition editprop.c:6262
static struct propstate * propstate_new(struct objprop *op, struct propval *pv)
Definition editprop.c:1258
static const char * valtype_get_name(enum value_types valtype)
Definition editprop.c:776
static void propstate_destroy(struct propstate *ps)
Definition editprop.c:1290
static bool objbind_set_modified_value(struct objbind *ob, struct objprop *op, struct propval *pv)
Definition editprop.c:2104
static GtkCellRenderer * objprop_create_cell_renderer(const struct objprop *op)
Definition editprop.c:2826
static void extviewer_clear_widgets(struct extviewer *ev)
Definition editprop.c:4049
value_types
Definition editprop.c:196
@ VALTYPE_STRING
Definition editprop.c:200
@ VALTYPE_BV_SPECIAL
Definition editprop.c:204
@ VALTYPE_BV_BASES
Definition editprop.c:206
@ VALTYPE_INT
Definition editprop.c:198
@ VALTYPE_INVENTIONS_ARRAY
Definition editprop.c:203
@ VALTYPE_BV_ROADS
Definition editprop.c:205
@ VALTYPE_PIXBUF
Definition editprop.c:201
@ VALTYPE_TILE_VISION_DATA
Definition editprop.c:210
@ VALTYPE_NONE
Definition editprop.c:197
@ VALTYPE_NATION_HASH
Definition editprop.c:208
@ VALTYPE_BOOL
Definition editprop.c:199
@ VALTYPE_NATION
Definition editprop.c:207
@ VALTYPE_GOV
Definition editprop.c:209
@ VALTYPE_BUILT_ARRAY
Definition editprop.c:202
static void objprop_set_child_widget(struct objprop *op, const char *widget_name, GtkWidget *widget)
Definition editprop.c:3347
static bool property_editor_add_page(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6095
static void propstate_clear_value(struct propstate *ps)
Definition editprop.c:1277
static void objbind_pack_modified_value(struct objbind *ob, struct objprop *op, union packetdata packet)
Definition editprop.c:2356
static struct objbind * property_page_get_focused_objbind(struct property_page *pp)
Definition editprop.c:5375
static bool objprop_has_widget(const struct objprop *op)
Definition editprop.c:2715
static int objtype_get_id_from_object(enum editor_object_type objtype, gpointer object)
Definition editprop.c:693
static enum editor_object_type objbind_get_objtype(const struct objbind *ob)
Definition editprop.c:2188
static struct extviewer * objprop_get_extviewer(struct objprop *op)
Definition editprop.c:3419
static void extviewer_refresh_widgets(struct extviewer *ev, struct propval *pv)
Definition editprop.c:3786
static enum editor_object_type property_page_get_objtype(const struct property_page *pp)
Definition editprop.c:5030
#define property_page_objbind_iterate_end
Definition editprop.c:638
static void property_page_show_extviewer(struct property_page *pp, struct extviewer *ev)
Definition editprop.c:5947
static gpointer objbind_get_object(struct objbind *ob)
Definition editprop.c:1358
static const char * property_page_get_name(const struct property_page *pp)
Definition editprop.c:5018
void property_editor_handle_object_created(struct property_editor *pe, int tag, int object_id)
Definition editprop.c:6284
static bool objbind_property_is_modified(struct objbind *ob, struct objprop *op)
Definition editprop.c:2059
static struct propval * propstate_get_value(struct propstate *ps)
Definition editprop.c:1320
static void property_page_clear_tags(struct property_page *pp)
Definition editprop.c:6024
static void property_page_object_created(struct property_page *pp, int tag, int object_id)
Definition editprop.c:5901
static bool property_page_tag_is_known(struct property_page *pp, int tag)
Definition editprop.c:6013
static void property_page_remove_creation_tag(struct property_page *pp, int tag)
Definition editprop.c:5994
static void property_page_load_tiles(struct property_page *pp, const struct tile_list *tiles)
Definition editprop.c:5417
static void property_page_create_objects(struct property_page *pp, struct tile_list *hint_tiles)
Definition editprop.c:5724
static void property_page_add_extviewer(struct property_page *pp, struct extviewer *ev)
Definition editprop.c:5927
static void property_page_refresh_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6046
static void property_page_set_focused_objbind(struct property_page *pp, struct objbind *ob)
Definition editprop.c:5387
static void property_page_setup_objprops(struct property_page *pp)
Definition editprop.c:4388
static void objbind_set_rowref(struct objbind *ob, GtkTreeRowReference *rr)
Definition editprop.c:2622
object_property_flags
Definition editprop.c:381
@ OPF_IN_LISTVIEW
Definition editprop.c:384
@ OPF_EDITABLE
Definition editprop.c:383
@ OPF_HAS_WIDGET
Definition editprop.c:385
@ OPF_NO_FLAGS
Definition editprop.c:382
static void objbind_clear_modified_value(struct objbind *ob, struct objprop *op)
Definition editprop.c:2045
static struct propval * objbind_get_value_from_object(struct objbind *ob, struct objprop *op)
Definition editprop.c:1435
static void propval_free(struct propval *pv)
Definition editprop.c:1120
static struct property_filter * property_filter_new(const char *filter)
Definition editprop.c:6370
static bool property_page_set_store_value(struct property_page *pp, struct objprop *op, struct objbind *ob, GtkTreeIter *iter)
Definition editprop.c:5231
static const char * objtype_get_name(enum editor_object_type objtype)
Definition editprop.c:664
static void objbind_clear_all_modified_values(struct objbind *ob)
Definition editprop.c:2090
static bool property_filter_match(struct property_filter *pf, const struct objprop *op)
Definition editprop.c:6444
void property_editor_popup(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6232
static void property_page_destroy_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6084
static struct objbind * objbind_new(enum editor_object_type objtype, gpointer object)
Definition editprop.c:1332
static gboolean property_page_selection_func(GtkTreeSelection *sel, GtkTreeModel *model, GtkTreePath *path, gboolean currently_selected, gpointer data)
Definition editprop.c:4614
static int property_page_get_num_objbinds(const struct property_page *pp)
Definition editprop.c:5434
static bool objprop_show_in_listview(const struct objprop *op)
Definition editprop.c:2704
static GType objprop_get_gtype(const struct objprop *op)
Definition editprop.c:2660
static void objprop_set_treeview_column(struct objprop *op, GtkTreeViewColumn *col)
Definition editprop.c:2778
static void objbind_pack_current_values(struct objbind *ob, union packetdata packet)
Definition editprop.c:2213
static const char * objprop_get_attribute_type_string(const struct objprop *op)
Definition editprop.c:2729
static struct propval * propval_copy(struct propval *pv)
Definition editprop.c:1038
struct property_editor * editprop_get_property_editor(void)
Definition editprop.c:6185
void property_editor_reload(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6322
static GdkPixbuf * create_unit_pixbuf(const struct unit *punit)
Definition editprop.c:5058
static void extviewer_view_cell_toggled(GtkCellRendererToggle *cell, gchar *path, gpointer userdata)
Definition editprop.c:4124
static struct property_editor * property_editor_new(void)
Definition editprop.c:6142
static void property_page_send_packet(struct property_page *pp, union packetdata packet)
Definition editprop.c:5583
static gchar * built_status_to_string(struct built_status *bs)
Definition editprop.c:974
static int objprop_get_id(const struct objprop *op)
Definition editprop.c:2645
object_property_ids
Definition editprop.c:304
@ OPID_STARTPOS_IMAGE
Definition editprop.c:324
@ OPID_TILE_Y
Definition editprop.c:307
@ OPID_TILE_BASES
Definition editprop.c:320
@ OPID_CITY_XY
Definition editprop.c:350
@ OPID_UNIT_ID
Definition editprop.c:334
@ OPID_CITY_BUILDINGS
Definition editprop.c:353
@ OPID_CITY_NAME
Definition editprop.c:345
@ OPID_TILE_NAT_Y
Definition editprop.c:309
@ OPID_CITY_SIZE
Definition editprop.c:351
@ OPID_UNIT_VETERAN
Definition editprop.c:341
@ OPID_CITY_IMAGE
Definition editprop.c:344
@ OPID_CITY_SHIELD_STOCK
Definition editprop.c:355
@ OPID_PLAYER_NAME
Definition editprop.c:357
@ OPID_PLAYER_AGE
Definition editprop.c:360
@ OPID_STARTPOS_NATIONS
Definition editprop.c:327
@ OPID_GAME_LAKE_FLOODING
Definition editprop.c:377
@ OPID_UNIT_IMAGE
Definition editprop.c:329
@ OPID_TILE_TERRAIN
Definition editprop.c:314
@ OPID_TILE_SPECIALS
Definition editprop.c:318
@ OPID_TILE_RESOURCE
Definition editprop.c:317
@ OPID_TILE_IMAGE
Definition editprop.c:305
@ OPID_TILE_VISION
Definition editprop.c:321
@ OPID_PLAYER_INVENTIONS
Definition editprop.c:364
@ OPID_GAME_SCENARIO_NAME
Definition editprop.c:370
@ OPID_PLAYER_SCIENCE
Definition editprop.c:366
@ OPID_TILE_CONTINENT
Definition editprop.c:310
@ OPID_CITY_HISTORY
Definition editprop.c:352
@ OPID_TILE_XY
Definition editprop.c:316
@ OPID_GAME_SCENARIO_AUTHORS
Definition editprop.c:371
@ OPID_TILE_X
Definition editprop.c:306
@ OPID_TILE_NAT_X
Definition editprop.c:308
@ OPID_PLAYER_NATION
Definition editprop.c:358
@ OPID_GAME_PREVENT_CITIES
Definition editprop.c:376
@ OPID_STARTPOS_XY
Definition editprop.c:325
@ OPID_UNIT_MOVED
Definition editprop.c:338
@ OPID_TILE_LABEL
Definition editprop.c:322
@ OPID_CITY_FOOD_STOCK
Definition editprop.c:354
@ OPID_UNIT_DONE_MOVING
Definition editprop.c:339
@ OPID_UNIT_MOVES_LEFT
Definition editprop.c:336
@ OPID_GAME_SCENARIO_DESC
Definition editprop.c:372
@ OPID_GAME_STARTPOS_NATIONS
Definition editprop.c:375
@ OPID_UNIT_HP
Definition editprop.c:340
@ OPID_UNIT_FUEL
Definition editprop.c:337
@ OPID_PLAYER_SCENARIO_RESERVED
Definition editprop.c:365
@ OPID_TILE_ROADS
Definition editprop.c:319
@ OPID_PLAYER_GOLD
Definition editprop.c:367
@ OPID_CITY_ID
Definition editprop.c:349
@ OPID_GAME_SCENARIO_RANDSTATE
Definition editprop.c:373
@ OPID_GAME_SCENARIO_PLAYERS
Definition editprop.c:374
@ OPID_UNIT_STAY
Definition editprop.c:342
@ OPID_PLAYER_GOV
Definition editprop.c:359
@ OPID_STARTPOS_EXCLUDE
Definition editprop.c:326
@ OPID_UNIT_TYPE
Definition editprop.c:333
@ OPID_GAME_SCENARIO
Definition editprop.c:369
@ OPID_GAME_RULESET_LOCKED
Definition editprop.c:378
@ OPID_UNIT_XY
Definition editprop.c:335
@ OPID_TILE_INDEX
Definition editprop.c:315
static enum value_types objprop_get_valtype(const struct objprop *op)
Definition editprop.c:2693
static int get_next_unique_tag(void)
Definition editprop.c:1027
static bool objprop_is_sortable(const struct objprop *op)
Definition editprop.c:2847
static void property_page_add_objbinds_from_tile(struct property_page *pp, const struct tile *ptile)
Definition editprop.c:5177
static const char * objprop_get_tooltip(const struct objprop *op)
Definition editprop.c:2813
static GtkTreeRowReference * objbind_get_rowref(struct objbind *ob)
Definition editprop.c:2634
static void property_filter_free(struct property_filter *pf)
Definition editprop.c:6498
static void objprop_widget_spin_button_changed(GtkSpinButton *spin, gpointer userdata)
Definition editprop.c:2888
#define PF_DISJUNCTION_SEPARATOR
Definition editprop.c:118
static GtkWidget * objprop_get_child_widget(struct objprop *op, const char *widget_name)
Definition editprop.c:3374
static void property_page_selection_changed(GtkTreeSelection *sel, gpointer userdata)
Definition editprop.c:4589
static bool objtype_is_conserved(enum editor_object_type objtype)
Definition editprop.c:753
static struct extviewer * extviewer_new(struct objprop *op)
Definition editprop.c:3466
static bool propval_equal(struct propval *pva, struct propval *pvb)
Definition editprop.c:1171
static void property_page_quick_find_entry_changed(GtkWidget *entry, gpointer userdata)
Definition editprop.c:4669
static void objprop_refresh_widget(struct objprop *op, struct objbind *ob)
Definition editprop.c:3098
#define PF_MAX_CLAUSES
Definition editprop.c:117
void property_editor_popdown(struct property_editor *pe)
Definition editprop.c:6250
static void objbind_destroy(struct objbind *ob)
Definition editprop.c:2169
static void property_page_add_objbind(struct property_page *pp, gpointer object_data)
Definition editprop.c:5141
static void objbind_request_destroy_object(struct objbind *ob)
Definition editprop.c:1387
static void property_page_create_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6056
static GdkPixbuf * create_pixbuf_from_layers(const struct tile *ptile, const struct unit *punit, const struct city *pcity, enum layer_category category)
Definition editprop.c:5084
static union packetdata property_page_new_packet(struct property_page *pp)
Definition editprop.c:5542
static void propstate_set_value(struct propstate *ps, struct propval *pv)
Definition editprop.c:1305
static int objprop_get_column_id(const struct objprop *op)
Definition editprop.c:2767
static GdkPixbuf * create_tile_pixbuf(const struct tile *ptile)
Definition editprop.c:5046
static struct objprop * extviewer_get_objprop(struct extviewer *ev)
Definition editprop.c:3751
static bool can_create_unit_at_tile(struct tile *ptile)
Definition editprop.c:995
static struct objbind * property_page_get_objbind(struct property_page *pp, int object_id)
Definition editprop.c:5400
static bool objbind_get_allowed_value_span(struct objbind *ob, struct objprop *op, double *pmin, double *pmax, double *pstep, double *pbig_step)
Definition editprop.c:1870
static void property_page_free_packet(struct property_page *pp, union packetdata packet)
Definition editprop.c:5624
static GdkPixbuf * create_city_pixbuf(const struct city *pcity)
Definition editprop.c:5070
#define ADDPROP(ARG_id, ARG_name, ARG_tooltip, ARG_flags, ARG_valtype)
static void extviewer_panel_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:4104
static void property_page_destroy_objects(struct property_page *pp)
Definition editprop.c:5685
void property_editor_load_tiles(struct property_editor *pe, const struct tile_list *tiles)
Definition editprop.c:6196
static struct property_page * property_page_new(enum editor_object_type objtype, struct property_editor *parent)
Definition editprop.c:4711
#define property_page_objprop_iterate_end
Definition editprop.c:634
static void property_page_clear_objbinds(struct property_page *pp)
Definition editprop.c:5126
void property_editor_clear(struct property_editor *pe)
Definition editprop.c:6302
#define property_page_objprop_iterate(ARG_pp, NAME_op)
Definition editprop.c:632
static void objprop_set_column_id(struct objprop *op, int col_id)
Definition editprop.c:2754
static void objbind_bind_properties(struct objbind *ob, struct property_page *pp)
Definition editprop.c:2199
static void property_page_fill_widgets(struct property_page *pp)
Definition editprop.c:5326
static bool objbind_has_modified_properties(struct objbind *ob)
Definition editprop.c:2078
static void property_page_change_value(struct property_page *pp, struct objprop *op, struct propval *pv)
Definition editprop.c:5446
static void objprop_widget_toggle_button_changed(GtkToggleButton *button, gpointer userdata)
Definition editprop.c:2905
#define PF_CONJUNCTION_SEPARATOR
Definition editprop.c:119
static void property_page_apply_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6035
static struct objprop * objprop_new(int id, const char *name, const char *tooltip, enum object_property_flags flags, enum value_types valtype, struct property_page *parent)
Definition editprop.c:3441
static GtkWidget * extviewer_get_view_widget(struct extviewer *ev)
Definition editprop.c:3775
static GtkWidget * objprop_get_widget(struct objprop *op)
Definition editprop.c:3332
static void propval_free_data(struct propval *pv)
Definition editprop.c:1134
static void extviewer_textbuf_changed(GtkTextBuffer *textbuf, gpointer userdata)
Definition editprop.c:4339
static struct property_editor * the_property_editor
Definition editprop.c:658
static void property_page_object_changed(struct property_page *pp, int object_id, bool remove)
Definition editprop.c:5849
static bool objprop_is_readonly(const struct objprop *op)
Definition editprop.c:2861
#define property_page_objbind_iterate(ARG_pp, NAME_ob)
Definition editprop.c:636
static GtkTreeViewColumn * objprop_get_treeview_column(const struct objprop *op)
Definition editprop.c:2791
static struct property_page * property_editor_get_page(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6129
static struct propval * objbind_get_modified_value(struct objbind *ob, struct objprop *op)
Definition editprop.c:2150
GtkWidget * toplevel
Definition gui_main.c:124
void disable_gobject_callback(GObject *obj, GCallback cb)
Definition gui_stuff.c:1087
void enable_gobject_callback(GObject *obj, GCallback cb)
Definition gui_stuff.c:1103
GdkPixbuf * get_flag(const struct nation_type *nation)
Definition plrdlg.c:609
const char * tooltip
Definition repodlgs.c:1314
const char * title
Definition repodlgs.c:1313
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
Definition sprite.c:418
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
static void objprop_widget_text_changed(GtkEditable *text, gpointer userdata)
Definition editprop.c:2872
#define PF_MAX_CLAUSES
Definition editprop.c:117
bool is_special_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
struct startpos * map_startpos_get(const struct tile *ptile)
Definition map.c:1686
int startpos_number(const struct startpos *psp)
Definition map.c:1436
#define nat_x
#define nat_y
struct tile * startpos_tile(const struct startpos *psp)
Definition map.c:1479
const struct nation_hash * startpos_raw_nations(const struct startpos *psp)
Definition map.c:1568
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
Definition map.c:1509
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:454
bool startpos_is_excluding(const struct startpos *psp)
Definition map.c:1556
struct startpos * map_startpos_by_number(int id)
Definition map.c:1427
#define index_to_native_pos(pnat_x, pnat_y, mindex)
Definition map.h:151
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:227
struct tile * get_center_tile_mapcanvas(void)
void put_one_element(struct canvas *pcanvas, float zoom, enum mapview_layer layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, int canvas_x, int canvas_y, const struct city *citymode, const struct unit_type *putype)
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
#define MAX_MOVE_FRAGS
Definition movement.h:27
Nation_type_id nation_count(void)
Definition nation.c:506
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:485
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:148
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:474
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
#define nation_hash_iterate(nationhash, pnation)
Definition nation.h:92
#define nations_iterate_end
Definition nation.h:335
#define nations_iterate(NAME_pnation)
Definition nation.h:332
#define nation_hash_iterate_end
Definition nation.h:94
int dsend_packet_edit_city_create(struct connection *pc, int owner, int tile, int size, int tag)
int send_packet_edit_city(struct connection *pc, const struct packet_edit_city *packet)
int send_packet_edit_game(struct connection *pc, const struct packet_edit_game *packet)
int dsend_packet_edit_city_remove(struct connection *pc, int id16, int id32)
int dsend_packet_edit_unit_remove_by_id(struct connection *pc, int id16, int id32)
int send_packet_edit_startpos_full(struct connection *pc, const struct packet_edit_startpos_full *packet)
int dsend_packet_edit_startpos(struct connection *pc, int id, bool removal, int tag)
int send_packet_edit_player(struct connection *pc, const struct packet_edit_player *packet)
int dsend_packet_edit_player_create(struct connection *pc, int tag)
int send_packet_edit_unit(struct connection *pc, const struct packet_edit_unit *packet)
int send_packet_edit_scenario_desc(struct connection *pc, const struct packet_edit_scenario_desc *packet)
int dsend_packet_edit_unit_create(struct connection *pc, int owner, int tile, Unit_type_id type, int count, int tag)
int dsend_packet_edit_player_remove(struct connection *pc, int id)
int send_packet_edit_tile(struct connection *pc, const struct packet_edit_tile *packet)
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:441
struct player * player_by_number(const int player_id)
Definition player.c:840
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
int player_slot_index(const struct player_slot *pslot)
Definition player.c:419
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1954
int player_index(const struct player *pplayer)
Definition player.c:820
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:430
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
#define player_slots_iterate(_pslot)
Definition player.h:521
#define player_slots_iterate_end
Definition player.h:525
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
Road_type_id road_count(void)
Definition road.c:50
Road_type_id road_number(const struct road_type *proad)
Definition road.c:32
#define ARRAY_SIZE(x)
Definition shared.h:85
int step
Definition specpq.h:92
size_t size
Definition specvec.h:72
int turn
Definition city.h:238
cairo_surface_t * surface
Definition canvas.h:22
Definition city.h:309
int food_stock
Definition city.h:354
struct built_status built[B_LAST]
Definition city.h:380
int history
Definition city.h:393
int id
Definition city.h:315
char * name
Definition city.h:310
int shield_stock
Definition city.h:355
struct packet_scenario_description scenario_desc
Definition game.h:88
struct packet_game_info info
Definition game.h:89
struct packet_scenario_info scenario
Definition game.h:87
struct connection conn
Definition client_main.h:96
GtkWidget * view_widget
Definition editprop.c:520
GtkWidget * panel_button
Definition editprop.c:517
GtkWidget * view_label
Definition editprop.c:521
GtkWidget * panel_image
Definition editprop.c:518
GtkTextBuffer * textbuf
Definition editprop.c:524
struct objprop * objprop
Definition editprop.c:512
GtkWidget * panel_label
Definition editprop.c:516
struct propval * pv_cached
Definition editprop.c:513
GtkListStore * store
Definition editprop.c:523
GtkWidget * panel_widget
Definition editprop.c:515
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
int object_id
Definition editprop.c:457
struct propstate_hash * propstate_table
Definition editprop.c:459
struct property_page * parent_property_page
Definition editprop.c:458
GtkTreeRowReference * rowref
Definition editprop.c:460
enum editor_object_type objtype
Definition editprop.c:456
const char * name
Definition editprop.c:390
const char * tooltip
Definition editprop.c:391
GtkWidget * widget
Definition editprop.c:396
struct property_page * parent_page
Definition editprop.c:398
enum object_property_flags flags
Definition editprop.c:392
struct extviewer * extviewer
Definition editprop.c:397
int id
Definition editprop.c:389
enum value_types valtype
Definition editprop.c:393
int column_id
Definition editprop.c:394
GtkTreeViewColumn * view_column
Definition editprop.c:395
int built[B_LAST]
char name[MAX_LEN_CITYNAME]
char scenario_name[256]
char scenario_authors[MAX_LEN_PACKET/3]
Nation_type_id nation
char name[MAX_LEN_NAME]
Government_type_id government
bool inventions[A_LAST+1]
bv_startpos_nations nations
char label[MAX_LEN_NAME]
char description[MAX_LEN_CONTENT]
char authors[MAX_LEN_PACKET/3]
struct pf_pattern conjunction[PF_MAX_CLAUSES]
Definition editprop.c:127
char * text
Definition editprop.c:123
bool negate
Definition editprop.c:122
struct government * government
Definition player.h:258
int turns_alive
Definition player.h:266
struct player_economic economic
Definition player.h:284
char name[MAX_LEN_NAME]
Definition player.h:251
struct nation_type * nation
Definition player.h:260
GtkWidget * notebook
Definition editprop.c:646
struct property_page * property_pages[NUM_OBJTYPES]
Definition editprop.c:648
GtkWidget * widget
Definition editprop.c:645
struct pf_conjunction disjunction[PF_MAX_CLAUSES]
Definition editprop.c:132
GtkListStore * object_store
Definition editprop.c:550
struct property_editor * pe_parent
Definition editprop.c:554
GtkWidget * extviewer_notebook
Definition editprop.c:552
GtkWidget * widget
Definition editprop.c:549
struct objbind_hash * objbind_table
Definition editprop.c:557
GtkWidget * object_view
Definition editprop.c:551
struct objbind * focused_objbind
Definition editprop.c:560
struct stored_tag_hash * tag_table
Definition editprop.c:558
enum editor_object_type objtype
Definition editprop.c:547
struct objprop_hash * objprop_table
Definition editprop.c:556
struct propval * property_value
Definition editprop.c:255
int property_id
Definition editprop.c:254
union propval_data data
Definition editprop.c:243
enum value_types valtype
Definition editprop.c:244
bool must_free
Definition editprop.c:245
int bulbs_researched
Definition research.h:53
Definition map.c:41
bv_player tile_known
Definition editprop.c:113
bv_player tile_seen[V_COUNT]
Definition editprop.c:113
Definition tile.h:49
char * label
Definition tile.h:64
Continent_id continent
Definition tile.h:53
Definition unit.h:138
int moves_left
Definition unit.h:150
int id
Definition unit.h:145
bool moved
Definition unit.h:173
int hp
Definition unit.h:151
int fuel
Definition unit.h:153
bool stay
Definition unit.h:205
bool done_moving
Definition unit.h:181
int veteran
Definition unit.h:152
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
char * fc_strcasestr(const char *haystack, const char *needle)
Definition support.c:439
#define sz_strlcpy(dest, src)
Definition support.h:161
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:162
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
#define advance_index_iterate_end
Definition tech.h:248
#define advance_iterate(_start, _p)
Definition tech.h:264
static Tech_type_id advance_count(void)
Definition tech.h:170
#define A_FIRST
Definition tech.h:44
#define advance_iterate_end
Definition tech.h:270
#define advance_index_iterate(_start, _index)
Definition tech.h:244
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:87
#define tile_resource(_tile)
Definition tile.h:101
#define tile_list_iterate(tile_list, ptile)
Definition tile.h:72
#define tile_terrain(_tile)
Definition tile.h:109
#define TILE_XY(ptile)
Definition tile.h:42
#define tile_list_iterate_end
Definition tile.h:74
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:119
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:6508
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:864
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:752
bool tileset_layer_in_category(enum mapview_layer layer, enum layer_category cat)
Definition tilespec.c:7029
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:900
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:728
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:739
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:716
#define mapview_layer_iterate(layer)
Definition tilespec.h:174
#define mapview_layer_iterate_end
Definition tilespec.h:182
layer_category
Definition tilespec.h:188
@ LAYER_CATEGORY_TILE
Definition tilespec.h:190
@ LAYER_CATEGORY_CITY
Definition tilespec.h:189
@ LAYER_CATEGORY_UNIT
Definition tilespec.h:191
gpointer v_pointer2
Definition editprop.c:98
struct packet_edit_tile * tile
Definition editprop.c:100
gpointer v_pointer1
Definition editprop.c:97
struct packet_edit_unit * unit
Definition editprop.c:103
struct packetdata::@145 pointers
struct packet_edit_player * player
Definition editprop.c:104
struct packet_edit_city * city
Definition editprop.c:102
struct packet_edit_game * game
Definition editprop.c:106
struct packet_edit_startpos_full * startpos
Definition editprop.c:101
struct government * v_gov
Definition editprop.c:237
bv_techs v_bv_inventions
Definition editprop.c:238
bv_max_extras v_bv_special
Definition editprop.c:232
struct tile_vision_data * v_tile_vision
Definition editprop.c:239
char * v_string
Definition editprop.c:228
struct built_status * v_built
Definition editprop.c:231
bv_max_extras v_bv_roads
Definition editprop.c:233
gpointer v_pointer
Definition editprop.c:225
struct nation_type * v_nation
Definition editprop.c:235
struct nation_hash * v_nation_hash
Definition editprop.c:236
bv_max_extras v_bv_bases
Definition editprop.c:234
GdkPixbuf * v_pixbuf
Definition editprop.c:230
const char * v_const_string
Definition editprop.c:229
#define unit_tile(_pu)
Definition unit.h:388
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:411
#define unit_owner(_pu)
Definition unit.h:387
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:423
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2661
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
#define utype_fuel(ptype)
Definition unittype.h:822
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80