Freeciv-3.3
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 "nation.h"
37#include "research.h"
38#include "tile.h"
39
40/* client */
41#include "client_main.h"
42#include "climisc.h"
43#include "editor.h"
44#include "mapview_common.h"
45#include "tilespec.h"
46
47/* client/gui-gtk-5.0 */
48#include "canvas.h"
49#include "gui_main.h"
50#include "gui_stuff.h"
51#include "plrdlg.h"
52#include "sprite.h"
53
54#include "editprop.h"
55
56
57/* Forward declarations. */
58struct objprop;
59struct objbind;
60struct property_page;
61struct property_editor;
62struct extviewer;
63
64/****************************************************************************
65 Miscellaneous helpers.
66****************************************************************************/
67static GdkPixbuf *create_pixbuf_from_layers(const struct tile *ptile,
68 const struct unit *punit,
69 const struct city *pcity,
70 enum layer_category category);
71static GdkPixbuf *create_tile_pixbuf(const struct tile *ptile);
72static GdkPixbuf *create_unit_pixbuf(const struct unit *punit);
73static GdkPixbuf *create_city_pixbuf(const struct city *pcity);
74
75static void add_column(GtkWidget *view,
76 int col_id,
77 const char *name,
79 bool editable,
80 bool is_radio,
83
84static bool can_create_unit_at_tile(struct tile *ptile);
85
86static int get_next_unique_tag(void);
87
88/* 'struct stored_tag_hash' and related functions. */
89#define SPECHASH_TAG stored_tag
90#define SPECHASH_INT_KEY_TYPE
91#define SPECHASH_INT_DATA_TYPE
92#include "spechash.h"
93
94/* NB: If packet definitions change, be sure to
95 * update objbind_pack_current_values()!!! */
96union packetdata {
97 struct {
101 struct packet_edit_tile *tile;
103 struct packet_edit_city *city;
104 struct packet_edit_unit *unit;
106 struct {
107 struct packet_edit_game *game;
108 struct packet_edit_scenario_desc *desc;
110};
111
112/* Helpers for the OPID_TILE_VISION property. */
113struct tile_vision_data {
115};
116const char *vision_layer_get_name(enum vision_layer);
117
118#define PF_MAX_CLAUSES 16
119#define PF_DISJUNCTION_SEPARATOR "|"
120#define PF_CONJUNCTION_SEPARATOR "&"
121
122struct pf_pattern {
123 bool negate;
124 char *text;
125};
126
127struct pf_conjunction {
129 int count;
130};
131
132struct property_filter {
134 int count;
135};
136
137static struct property_filter *property_filter_new(const char *filter);
138static bool property_filter_match(struct property_filter *pf,
139 const struct objprop *op);
140static void property_filter_free(struct property_filter *pf);
141
142
143/****************************************************************************
144 Object type declarations.
145
146 To add a new object type:
147 1. Add a value in enum editor_object_type in client/editor.h.
148 2. Add a string name to objtype_get_name.
149 3. Add code in objtype_get_id_from_object.
150 4. Add code in objtype_get_object_from_id.
151 5. Add a case handler in objtype_is_conserved, and if
152 the object type is not conserved, then also in
153 objbind_request_destroy_object and property_page_create_objects.
154 6. Add an if-block in objbind_get_value_from_object.
155 7. Add an if-block in objbind_get_allowed_value_span.
156 9. Add a case handler in property_page_setup_objprops.
157 10. Add a case handler in property_page_add_objbinds_from_tile
158 if applicable.
159
160 Furthermore, if the object type is to be editable:
161 11. Define its edit packet in common/networking/packets.def.
162 12. Add the packet handler in server/edithand.c.
163 13. Add its edit packet type to union packetdata.
164 14. Add an if-block in objbind_pack_current_values.
165 15. Add an if-block in objbind_pack_modified_value.
166 16. Add code in property_page_new_packet.
167 17. Add code in property_page_send_packet.
168 18. Add calls to editgui_notify_object_changed in
169 client/packhand.c or where applicable.
170
171****************************************************************************/
172
173/* OBJTYPE_* enum values defined in client/editor.h */
174
175static const char *objtype_get_name(enum editor_object_type objtype);
177 gpointer object);
179 int id);
181
182
183/****************************************************************************
184 Value type declarations.
185
186 To add a new value type:
187 1. Add a value in enum value_types.
188 2. Add its field in union propval_data.
189 3. Add a case handler in valtype_get_name.
190 4. Add a case handler in propval_copy if needed.
191 5. Add a case handler in propval_free if needed.
192 6. Add a case handler in propval_equal if needed.
193 7. Add a case handler in objprop_get_gtype.
194 8. Add a case handler in property_page_set_store_value.
195 9. Add a case handler in propval_as_string if needed.
196****************************************************************************/
213
214static const char *valtype_get_name(enum value_types valtype);
215
216
217/****************************************************************************
218 Propstate and propval declarations.
219
220 To add a new member to union propval_data, see the steps for adding a
221 new value type above.
222
223 New property values are "constructed" by objbind_get_value_from_object().
224****************************************************************************/
225union propval_data {
227 int v_int;
228 bool v_bool;
229 char *v_string;
230 const char *v_const_string;
232 struct built_status *v_built;
236 struct nation_type *v_nation;
238 struct government *v_gov;
241};
242
243struct propval {
244 union propval_data data;
245 enum value_types valtype;
246 bool must_free;
247};
248
249static void propval_free(struct propval *pv);
250static void propval_free_data(struct propval *pv);
251static struct propval *propval_copy(struct propval *pv);
252static bool propval_equal(struct propval *pva, struct propval *pvb);
253
254struct propstate {
255 int property_id;
256 struct propval *property_value;
257};
258
259static struct propstate *propstate_new(struct objprop *op,
260 struct propval *pv);
261static void propstate_destroy(struct propstate *ps);
262static void propstate_clear_value(struct propstate *ps);
263static void propstate_set_value(struct propstate *ps,
264 struct propval *pv);
265static struct propval *propstate_get_value(struct propstate *ps);
266
267#define SPECHASH_TAG propstate
268#define SPECHASH_INT_KEY_TYPE
269#define SPECHASH_IDATA_TYPE struct propstate *
270#define SPECHASH_IDATA_FREE propstate_destroy
271#include "spechash.h"
272
273
274/****************************************************************************
275 Objprop declarations.
276
277 To add a new object property:
278 1. Add a value in enum object_property_ids (grouped by
279 object type).
280 2. Define the property in property_page_setup_objprops.
281 3. Add a case handler in objbind_get_value_from_object
282 in the appropriate object type block.
283 4. Add a case handler in objprop_setup_widget.
284 5. Add a case handler in objprop_refresh_widget.
285
286 Furthermore, if the property is editable:
287 5. Add a field for this property in the edit
288 packet for this object type in common/networking/packets.def.
289 6. Add a case handler in objbind_pack_modified_value.
290 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
291 !!! 7. Add code to set the packet field in !!!
292 !!! objbind_pack_current_values(). !!!
293 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
294 8. Add code to handle changes in the packet field in
295 server/edithand.c handle_edit_<objtype>.
296
297 If the property makes use of an extviewer:
298 9. Handle widget creation in extviewer_new.
299 10. Handle refresh in extviewer_refresh_widgets.
300 11. Handle clear in extviewer_clear_widgets.
301 12. Handle any signal callbacks (e.g. toggled) if needed.
302
303 TODO: Add more object properties.
304****************************************************************************/
312#ifdef FREECIV_DEBUG
314#endif /* FREECIV_DEBUG */
322 OPID_TILE_VISION, /* tile_known and tile_seen */
324
329
331#ifdef FREECIV_DEBUG
333#endif /* FREECIV_DEBUG */
344
347#ifdef FREECIV_DEBUG
349#endif /* FREECIV_DEBUG */
357
362#ifdef FREECIV_DEBUG
364#endif /* FREECIV_DEBUG */
371
383
390
391struct objprop {
392 int id;
393 const char *name;
394 const char *tooltip;
396 enum value_types valtype;
397 int column_id;
400 struct extviewer *extviewer;
402};
403
404static struct objprop *objprop_new(int id,
405 const char *name,
406 const char *tooltip,
408 enum value_types valtype,
409 struct property_page *parent);
410static int objprop_get_id(const struct objprop *op);
411static const char *objprop_get_name(const struct objprop *op);
412static const char *objprop_get_tooltip(const struct objprop *op);
413static enum value_types objprop_get_valtype(const struct objprop *op);
414static struct property_page *
416
417static bool objprop_show_in_listview(const struct objprop *op);
418static bool objprop_is_sortable(const struct objprop *op);
419static bool objprop_is_readonly(const struct objprop *op);
420static bool objprop_has_widget(const struct objprop *op);
421
422static GType objprop_get_gtype(const struct objprop *op);
423static const char *objprop_get_attribute_type_string(const struct objprop *op);
424static void objprop_set_column_id(struct objprop *op, int col_id);
425static int objprop_get_column_id(const struct objprop *op);
426static void objprop_set_treeview_column(struct objprop *op,
430
431static void objprop_setup_widget(struct objprop *op);
432static GtkWidget *objprop_get_widget(struct objprop *op);
433static void objprop_set_child_widget(struct objprop *op,
434 const char *widget_name,
437 const char *widget_name);
438static void objprop_set_extviewer(struct objprop *op,
439 struct extviewer *ev);
440static struct extviewer *objprop_get_extviewer(struct objprop *op);
441static void objprop_refresh_widget(struct objprop *op,
442 struct objbind *ob);
448
449#define SPECHASH_TAG objprop
450#define SPECHASH_INT_KEY_TYPE
451#define SPECHASH_IDATA_TYPE struct objprop *
452#include "spechash.h"
453
454
455/****************************************************************************
456 Objbind declarations.
457****************************************************************************/
458struct objbind {
460 int object_id;
464};
465
467 gpointer object);
468static void objbind_destroy(struct objbind *ob);
469static enum editor_object_type objbind_get_objtype(const struct objbind *ob);
470static void objbind_bind_properties(struct objbind *ob,
471 struct property_page *pp);
472static gpointer objbind_get_object(struct objbind *ob);
473static int objbind_get_object_id(struct objbind *ob);
474static void objbind_request_destroy_object(struct objbind *ob);
475static struct propval *objbind_get_value_from_object(struct objbind *ob,
476 struct objprop *op);
477static bool objbind_get_allowed_value_span(struct objbind *ob,
478 struct objprop *op,
479 double *pmin,
480 double *pmax,
481 double *pstep,
482 double *pbig_step);
483static bool objbind_set_modified_value(struct objbind *ob,
484 struct objprop *op,
485 struct propval *pv);
486static struct propval *objbind_get_modified_value(struct objbind *ob,
487 struct objprop *op);
488static void objbind_clear_modified_value(struct objbind *ob,
489 struct objprop *op);
490static bool objbind_property_is_modified(struct objbind *ob,
491 struct objprop *op);
492static bool objbind_has_modified_properties(struct objbind *ob);
493static void objbind_clear_all_modified_values(struct objbind *ob);
494static void objbind_pack_current_values(struct objbind *ob,
495 union packetdata packet);
496static void objbind_pack_modified_value(struct objbind *ob,
497 struct objprop *op,
498 union packetdata packet);
499static void objbind_set_rowref(struct objbind *ob,
502
503#define SPECHASH_TAG objbind
504#define SPECHASH_INT_KEY_TYPE
505#define SPECHASH_IDATA_TYPE struct objbind *
506#define SPECHASH_IDATA_FREE objbind_destroy
507#include "spechash.h"
508
509
510/****************************************************************************
511 Extended property viewer declarations. This is a set of widgets used
512 for viewing and/or editing properties with complex values (e.g. arrays).
513****************************************************************************/
514struct extviewer {
515 struct objprop *objprop;
516 struct propval *pv_cached;
517
522
525
528};
529
530static struct extviewer *extviewer_new(struct objprop *op);
531static struct objprop *extviewer_get_objprop(struct extviewer *ev);
534static void extviewer_refresh_widgets(struct extviewer *ev,
535 struct propval *pv);
536static void extviewer_clear_widgets(struct extviewer *ev);
537static void extviewer_panel_button_clicked(GtkButton *button,
540 gchar *path,
542static void extviewer_textbuf_changed(GtkTextBuffer *textbuf,
544
545
546/****************************************************************************
547 Property page declarations.
548****************************************************************************/
549struct property_page {
551
556
558
562
563 struct objbind *focused_objbind;
564};
565
566static struct property_page *
568 struct property_editor *parent);
570static const char *property_page_get_name(const struct property_page *pp);
571static enum editor_object_type
573static void property_page_load_tiles(struct property_page *pp,
574 const struct tile_list *tiles);
576 const struct tile *ptile);
577static int property_page_get_num_objbinds(const struct property_page *pp);
579static void property_page_add_objbind(struct property_page *pp,
581static void property_page_fill_widgets(struct property_page *pp);
582static struct objbind *
585 struct objbind *ob);
587 int object_id);
591 GtkTreeModel *model,
592 GtkTreePath *path,
594 gpointer data);
598 struct objprop *op,
599 struct propval *pv);
600static void property_page_send_values(struct property_page *pp);
604 struct tile_list *hint_tiles);
606static void property_page_send_packet(struct property_page *pp,
607 union packetdata packet);
608static void property_page_free_packet(struct property_page *pp,
609 union packetdata packet);
611 int object_id,
612 bool remove);
614 int tag, int object_id);
616 struct extviewer *ev);
618 struct extviewer *ev);
620 int tag, int count);
622 int tag);
623static bool property_page_tag_is_known(struct property_page *pp, int tag);
624static void property_page_clear_tags(struct property_page *pp);
633
634
635#define property_page_objprop_iterate(ARG_pp, NAME_op) \
636 TYPED_HASH_DATA_ITERATE(struct objprop *, (ARG_pp)->objprop_table, NAME_op)
637#define property_page_objprop_iterate_end HASH_DATA_ITERATE_END
638
639#define property_page_objbind_iterate(ARG_pp, NAME_ob) \
640 TYPED_HASH_DATA_ITERATE(struct objbind *, (ARG_pp)->objbind_table, NAME_ob)
641#define property_page_objbind_iterate_end HASH_DATA_ITERATE_END
642
643
644/****************************************************************************
645 Property editor declarations.
646****************************************************************************/
647struct property_editor {
650
652};
653
654static struct property_editor *property_editor_new(void);
657static struct property_page *
660
662
663
664/************************************************************************/
668{
669 switch (objtype) {
670 case OBJTYPE_TILE:
671 return _("Tile");
672 case OBJTYPE_STARTPOS:
673 return _("Start Position");
674 case OBJTYPE_UNIT:
675 return _("Unit");
676 case OBJTYPE_CITY:
677 return _("City");
678 case OBJTYPE_PLAYER:
679 return _("Player");
680 case OBJTYPE_GAME:
681 return Q_("?play:Game");
682 case NUM_OBJTYPES:
683 break;
684 }
685
686 log_error("%s() Unhandled request to get name of object type %d.",
688 return "Unknown";
689}
690
691/************************************************************************/
697 gpointer object)
698{
699 switch (objtype) {
700 case OBJTYPE_TILE:
701 return tile_index((struct tile *) object);
702 case OBJTYPE_STARTPOS:
703 return startpos_number((struct startpos *) object);
704 case OBJTYPE_UNIT:
705 return ((struct unit *) object)->id;
706 case OBJTYPE_CITY:
707 return ((struct city *) object)->id;
708 case OBJTYPE_PLAYER:
709 return player_number((struct player *) object);
710 case OBJTYPE_GAME:
711 return 1;
712 case NUM_OBJTYPES:
713 break;
714 }
715
716 log_error("%s(): Unhandled request to get object ID from object %p of "
717 "type %d (%s).", __FUNCTION__, object, objtype,
719 return -1;
720}
721
722/************************************************************************/
726 int id)
727{
728 switch (objtype) {
729 case OBJTYPE_TILE:
730 return index_to_tile(&(wld.map), id);
731 case OBJTYPE_STARTPOS:
732 return map_startpos_by_number(id);
733 case OBJTYPE_UNIT:
734 return game_unit_by_number(id);
735 case OBJTYPE_CITY:
736 return game_city_by_number(id);
737 case OBJTYPE_PLAYER:
738 return player_by_number(id);
739 case OBJTYPE_GAME:
740 return &game;
741 case NUM_OBJTYPES:
742 break;
743 }
744
745 log_error("%s(): Unhandled request to get object of type %d (%s) "
746 "with ID %d.", __FUNCTION__, objtype,
748 return NULL;
749}
750
751/************************************************************************/
757{
758 switch (objtype) {
759 case OBJTYPE_TILE:
760 case OBJTYPE_GAME:
761 return TRUE;
762 case OBJTYPE_STARTPOS:
763 case OBJTYPE_UNIT:
764 case OBJTYPE_CITY:
765 case OBJTYPE_PLAYER:
766 return FALSE;
767 case NUM_OBJTYPES:
768 break;
769 }
770
771 log_error("%s(): Unhandled request for object type %d (%s)).",
773 return TRUE;
774}
775
776/************************************************************************/
779static const char *valtype_get_name(enum value_types valtype)
780{
781 switch (valtype) {
782 case VALTYPE_NONE:
783 return "none";
784 case VALTYPE_STRING:
785 return "string";
786 case VALTYPE_INT:
787 return "int";
788 case VALTYPE_BOOL:
789 return "bool";
790 case VALTYPE_PIXBUF:
791 return "pixbuf";
793 return "struct built_status[B_LAST]";
795 return "bool[A_LAST]";
797 return "bv_special";
798 case VALTYPE_BV_ROADS:
799 return "bv_roads";
800 case VALTYPE_BV_BASES:
801 return "bv_bases";
802 case VALTYPE_NATION:
803 return "nation";
805 return "struct nation_hash";
806 case VALTYPE_GOV:
807 return "government";
809 return "struct tile_vision_data";
810 }
811
812 log_error("%s(): unhandled value type %d.", __FUNCTION__, valtype);
813 return "void";
814}
815
816/************************************************************************/
821 int col_id,
822 const char *name,
823 GType gtype,
824 bool editable,
825 bool is_radio,
828{
831 const char *attr = NULL;
832
833 if (gtype == G_TYPE_BOOLEAN) {
836 is_radio);
837 if (editable) {
839 }
840 attr = "active";
841 } else if (gtype == GDK_TYPE_PIXBUF) {
843 attr = "pixbuf";
844 } else {
846 if (editable) {
847 g_object_set(cell, "editable", TRUE, NULL);
849 }
850 attr = "text";
851 }
852
854 attr, col_id, NULL);
856}
857
858/************************************************************************/
863{
864 int count = 0;
865
867
868 switch (pv->valtype) {
869 case VALTYPE_NONE:
870 return g_strdup("");
871
872 case VALTYPE_INT:
873 return g_strdup_printf("%d", pv->data.v_int);
874
875 case VALTYPE_BOOL:
876 return g_strdup_printf("%s", pv->data.v_bool ? _("TRUE") : _("FALSE"));
877
878 case VALTYPE_NATION:
879 return g_strdup_printf("%s", nation_adjective_translation(pv->data.v_nation));
880
881 case VALTYPE_GOV:
882 if (pv->data.v_gov != NULL) {
883 return g_strdup_printf("%s", government_name_translation(pv->data.v_gov));
884 } else {
886 }
887
889 {
890 int great_wonder_count = 0, small_wonder_count = 0, building_count = 0;
891 int id;
892
893 improvement_iterate(pimprove) {
894 id = improvement_index(pimprove);
895 if (pv->data.v_built[id].turn < 0) {
896 continue;
897 }
898 if (is_great_wonder(pimprove)) {
900 } else if (is_small_wonder(pimprove)) {
902 } else {
903 building_count++;
904 }
906 /* TRANS: "Number of buildings, number of small
907 * wonders (e.g. palace), number of great wonders." */
908 return g_strdup_printf(_("%db %ds %dW"),
909 building_count, small_wonder_count,
911 }
912
915 if (BV_ISSET(pv->data.v_bv_inventions, tech)) {
916 count++;
917 }
919 /* TRANS: "Number of technologies known". */
920 return g_strdup_printf(_("%d known"), count);
921
924 if (BV_ISSET(pv->data.v_bv_special, spe->data.special_idx)) {
925 count++;
926 }
928 /* TRANS: "The number of terrain specials (e.g. hut,
929 * river, pollution, etc.) present on a tile." */
930 return g_strdup_printf(_("%d present"), count);
931
932 case VALTYPE_BV_ROADS:
934 struct road_type *proad = extra_road_get(pextra);
935
936 if (BV_ISSET(pv->data.v_bv_roads, road_number(proad))) {
937 count++;
938 }
940 return g_strdup_printf(_("%d present"), count);
941
942 case VALTYPE_BV_BASES:
944 struct base_type *pbase = extra_base_get(pextra);
945
946 if (BV_ISSET(pv->data.v_bv_bases, base_number(pbase))) {
947 count++;
948 }
950 return g_strdup_printf(_("%d present"), count);
951
953 count = nation_hash_size(pv->data.v_nation_hash);
954 if (0 == count) {
955 return g_strdup(_("All nations"));
956 } else {
957 return g_strdup_printf(PL_("%d nation", "%d nations",
958 count), count);
959 }
960
961 case VALTYPE_STRING:
962 /* Assume it is a very long string. */
963 count = strlen(pv->data.v_const_string);
964 return g_strdup_printf(PL_("%d byte", "%d bytes", count),
965 count);
966
967 case VALTYPE_PIXBUF:
969 break;
970 }
971
972 log_error("%s(): Unhandled value type %d for property value %p.",
973 __FUNCTION__, pv->valtype, pv);
974 return g_strdup("");
975}
976
977/************************************************************************/
982{
983 int turn_built;
984
985 turn_built = bs->turn;
986
987 if (turn_built == I_NEVER) {
988 /* TRANS: Improvement never built. */
989 return g_strdup(_("(never)"));
990 } else if (turn_built == I_DESTROYED) {
991 /* TRANS: Improvement was destroyed. */
992 return g_strdup(_("(destroyed)"));
993 } else {
994 return g_strdup_printf("%d", turn_built);
995 }
996}
997
998/************************************************************************/
1002static bool can_create_unit_at_tile(struct tile *ptile)
1003{
1004 struct unit *vunit;
1005 struct city *pcity;
1006 struct player *pplayer;
1007 bool ret;
1008
1009 if (!ptile) {
1010 return FALSE;
1011 }
1012
1014 if (!vunit) {
1015 return FALSE;
1016 }
1017
1018 pcity = tile_city(ptile);
1019 pplayer = unit_owner(vunit);
1020
1021 ret = (can_unit_exist_at_tile(&(wld.map), vunit, ptile)
1022 && !is_non_allied_unit_tile(ptile, pplayer,
1024 && (pcity == NULL
1026 unit_owner(vunit))));
1027 free(vunit);
1028
1029 return ret;
1030}
1031
1032/************************************************************************/
1035static int get_next_unique_tag(void)
1036{
1037 static int tag_series = 0;
1038
1039 tag_series++;
1040 return tag_series;
1041}
1042
1043/************************************************************************/
1046static struct propval *propval_copy(struct propval *pv)
1047{
1048 struct propval *pv_copy;
1049 size_t size;
1050
1051 if (!pv) {
1052 return NULL;
1053 }
1054
1055 pv_copy = fc_calloc(1, sizeof(*pv));
1056 pv_copy->valtype = pv->valtype;
1057
1058 switch (pv->valtype) {
1059 case VALTYPE_NONE:
1060 return pv_copy;
1061 case VALTYPE_INT:
1062 pv_copy->data.v_int = pv->data.v_int;
1063 return pv_copy;
1064 case VALTYPE_BOOL:
1065 pv_copy->data.v_bool = pv->data.v_bool;
1066 return pv_copy;
1067 case VALTYPE_STRING:
1068 pv_copy->data.v_string = fc_strdup(pv->data.v_string);
1069 pv_copy->must_free = TRUE;
1070 return pv_copy;
1071 case VALTYPE_PIXBUF:
1072 g_object_ref(pv->data.v_pixbuf);
1073 pv_copy->data.v_pixbuf = pv->data.v_pixbuf;
1074 pv_copy->must_free = TRUE;
1075 return pv_copy;
1077 size = B_LAST * sizeof(struct built_status);
1078 pv_copy->data.v_pointer = fc_malloc(size);
1079 memcpy(pv_copy->data.v_pointer, pv->data.v_pointer, size);
1080 pv_copy->must_free = TRUE;
1081 return pv_copy;
1082 case VALTYPE_BV_SPECIAL:
1083 pv_copy->data.v_bv_special = pv->data.v_bv_special;
1084 return pv_copy;
1085 case VALTYPE_BV_ROADS:
1086 pv_copy->data.v_bv_roads = pv->data.v_bv_roads;
1087 return pv_copy;
1088 case VALTYPE_BV_BASES:
1089 pv_copy->data.v_bv_bases = pv->data.v_bv_bases;
1090 return pv_copy;
1091 case VALTYPE_NATION:
1092 pv_copy->data.v_nation = pv->data.v_nation;
1093 return pv_copy;
1094 case VALTYPE_GOV:
1095 pv_copy->data.v_gov = pv->data.v_gov;
1096 return pv_copy;
1098 pv_copy->data.v_nation_hash
1099 = nation_hash_copy(pv->data.v_nation_hash);
1100 pv_copy->must_free = TRUE;
1101 return pv_copy;
1103 pv_copy->data.v_bv_inventions = pv->data.v_bv_inventions;
1104 return pv_copy;
1106 size = sizeof(struct tile_vision_data);
1107 pv_copy->data.v_tile_vision = fc_malloc(size);
1108 pv_copy->data.v_tile_vision->tile_known
1109 = pv->data.v_tile_vision->tile_known;
1111 pv_copy->data.v_tile_vision->tile_seen[v]
1112 = pv->data.v_tile_vision->tile_seen[v];
1114 pv_copy->must_free = TRUE;
1115 return pv_copy;
1116 }
1117
1118 log_error("%s(): Unhandled value type %d for property value %p.",
1119 __FUNCTION__, pv->valtype, pv);
1120 pv_copy->data = pv->data;
1121 return pv_copy;
1122}
1123
1124/************************************************************************/
1128static void propval_free(struct propval *pv)
1129{
1130 if (!pv) {
1131 return;
1132 }
1133
1135 free(pv);
1136}
1137
1138/************************************************************************/
1142static void propval_free_data(struct propval *pv)
1143{
1144 if (!pv || !pv->must_free) {
1145 return;
1146 }
1147
1148 switch (pv->valtype) {
1149 case VALTYPE_NONE:
1150 case VALTYPE_INT:
1151 case VALTYPE_BOOL:
1152 case VALTYPE_BV_SPECIAL:
1153 case VALTYPE_BV_ROADS:
1154 case VALTYPE_BV_BASES:
1155 case VALTYPE_NATION:
1156 case VALTYPE_GOV:
1157 return;
1158 case VALTYPE_PIXBUF:
1159 g_object_unref(pv->data.v_pixbuf);
1160 return;
1161 case VALTYPE_STRING:
1165 free(pv->data.v_pointer);
1166 return;
1168 nation_hash_destroy(pv->data.v_nation_hash);
1169 return;
1170 }
1171
1172 log_error("%s(): Unhandled request to free data %p (type %s).",
1173 __FUNCTION__, pv->data.v_pointer, valtype_get_name(pv->valtype));
1174}
1175
1176/************************************************************************/
1179static bool propval_equal(struct propval *pva,
1180 struct propval *pvb)
1181{
1182 if (!pva || !pvb) {
1183 return pva == pvb;
1184 }
1185
1186 if (pva->valtype != pvb->valtype) {
1187 return FALSE;
1188 }
1189
1190 switch (pva->valtype) {
1191 case VALTYPE_NONE:
1192 return TRUE;
1193 case VALTYPE_INT:
1194 return pva->data.v_int == pvb->data.v_int;
1195 case VALTYPE_BOOL:
1196 return pva->data.v_bool == pvb->data.v_bool;
1197 case VALTYPE_STRING:
1198 if (pva->data.v_const_string != NULL
1199 && pvb->data.v_const_string != NULL) {
1200 return !strcmp(pva->data.v_const_string,
1201 pvb->data.v_const_string);
1202 }
1203 return pva->data.v_const_string == pvb->data.v_const_string;
1204 case VALTYPE_PIXBUF:
1205 return pva->data.v_pixbuf == pvb->data.v_pixbuf;
1207 if (pva->data.v_pointer == pvb->data.v_pointer) {
1208 return TRUE;
1209 } else if (!pva->data.v_pointer || !pvb->data.v_pointer) {
1210 return FALSE;
1211 }
1212
1213 improvement_iterate(pimprove) {
1214 int id, vatb, vbtb;
1215
1216 id = improvement_index(pimprove);
1217 vatb = pva->data.v_built[id].turn;
1218 vbtb = pvb->data.v_built[id].turn;
1219 if (vatb < 0 && vbtb < 0) {
1220 continue;
1221 }
1222 if (vatb != vbtb) {
1223 return FALSE;
1224 }
1226 return TRUE;
1228 return BV_ARE_EQUAL(pva->data.v_bv_inventions, pvb->data.v_bv_inventions);
1229 case VALTYPE_BV_SPECIAL:
1230 return BV_ARE_EQUAL(pva->data.v_bv_special, pvb->data.v_bv_special);
1231 case VALTYPE_BV_ROADS:
1232 return BV_ARE_EQUAL(pva->data.v_bv_roads, pvb->data.v_bv_roads);
1233 case VALTYPE_BV_BASES:
1234 return BV_ARE_EQUAL(pva->data.v_bv_bases, pvb->data.v_bv_bases);
1235 case VALTYPE_NATION:
1236 return pva->data.v_nation == pvb->data.v_nation;
1238 return nation_hashes_are_equal(pva->data.v_nation_hash,
1239 pvb->data.v_nation_hash);
1240 case VALTYPE_GOV:
1241 return pva->data.v_gov == pvb->data.v_gov;
1243 if (!BV_ARE_EQUAL(pva->data.v_tile_vision->tile_known,
1244 pvb->data.v_tile_vision->tile_known)) {
1245 return FALSE;
1246 }
1248 if (!BV_ARE_EQUAL(pva->data.v_tile_vision->tile_seen[v],
1249 pvb->data.v_tile_vision->tile_seen[v])) {
1250 return FALSE;
1251 }
1253 return TRUE;
1254 }
1255
1256 log_error("%s(): Unhandled value type %d for property values %p and %p.",
1257 __FUNCTION__, pva->valtype, pva, pvb);
1258 return pva->data.v_pointer == pvb->data.v_pointer;
1259}
1260
1261/************************************************************************/
1267static struct propstate *propstate_new(struct objprop *op,
1268 struct propval *pv)
1269{
1270 struct propstate *ps;
1271
1272 if (!op) {
1273 return NULL;
1274 }
1275
1276 ps = fc_calloc(1, sizeof(*ps));
1277 ps->property_id = objprop_get_id(op);
1278 ps->property_value = pv;
1279
1280 return ps;
1281}
1282
1283/************************************************************************/
1287{
1288 if (!ps) {
1289 return;
1290 }
1291
1292 propval_free(ps->property_value);
1293 ps->property_value = NULL;
1294}
1295
1296/************************************************************************/
1299static void propstate_destroy(struct propstate *ps)
1300{
1301 if (!ps) {
1302 return;
1303 }
1305 free(ps);
1306}
1307
1308/************************************************************************/
1315 struct propval *pv)
1316{
1317 if (!ps) {
1318 return;
1319 }
1321 ps->property_value = pv;
1322}
1323
1324/************************************************************************/
1330{
1331 if (!ps) {
1332 return NULL;
1333 }
1334 return ps->property_value;
1335}
1336
1337/************************************************************************/
1342 gpointer object)
1343{
1344 struct objbind *ob;
1345 int id;
1346
1347 if (object == NULL) {
1348 return NULL;
1349 }
1350
1351 id = objtype_get_id_from_object(objtype, object);
1352 if (id < 0) {
1353 return NULL;
1354 }
1355
1356 ob = fc_calloc(1, sizeof(*ob));
1357 ob->object_id = id;
1358 ob->objtype = objtype;
1359 ob->propstate_table = propstate_hash_new();
1360
1361 return ob;
1362}
1363
1364/************************************************************************/
1368{
1369 int id;
1370
1371 if (!ob) {
1372 return NULL;
1373 }
1374
1376
1377 return objtype_get_object_from_id(ob->objtype, id);
1378}
1379
1380/************************************************************************/
1384{
1385 if (NULL == ob) {
1386 return -1;
1387 }
1388 return ob->object_id;
1389}
1390
1391/************************************************************************/
1397{
1398 struct connection *my_conn = &client.conn;
1400 int id;
1401
1402 if (!ob) {
1403 return;
1404 }
1405
1408 return;
1409 }
1410
1412
1413 switch (objtype) {
1414 case OBJTYPE_STARTPOS:
1416 return;
1417 case OBJTYPE_UNIT:
1419 return;
1420 case OBJTYPE_CITY:
1422 return;
1423 case OBJTYPE_PLAYER:
1425 return;
1426 case OBJTYPE_TILE:
1427 case OBJTYPE_GAME:
1428 case NUM_OBJTYPES:
1429 break;
1430 }
1431
1432 log_error("%s(): Unhandled request to destroy object %p (ID %d) of type "
1433 "%d (%s).", __FUNCTION__, objbind_get_object(ob), id, objtype,
1435}
1436
1437/************************************************************************/
1445 struct objprop *op)
1446{
1449 struct propval *pv;
1450
1451 if (!ob || !op) {
1452 return NULL;
1453 }
1454
1457
1458 pv = fc_calloc(1, sizeof(*pv));
1459 pv->valtype = objprop_get_valtype(op);
1460
1461 switch (objtype) {
1462 case OBJTYPE_TILE:
1463 {
1464 const struct tile *ptile = objbind_get_object(ob);
1465 int tile_x, tile_y, nat_x, nat_y;
1466
1467 if (NULL == ptile) {
1468 goto FAILED;
1469 }
1470
1473
1474 switch (propid) {
1475 case OPID_TILE_IMAGE:
1476 pv->data.v_pixbuf = create_tile_pixbuf(ptile);
1477 pv->must_free = TRUE;
1478 break;
1479#ifdef FREECIV_DEBUG
1480 case OPID_TILE_ADDRESS:
1481 pv->data.v_string = g_strdup_printf("%p", ptile);
1482 pv->must_free = TRUE;
1483 break;
1484#endif /* FREECIV_DEBUG */
1485 case OPID_TILE_TERRAIN:
1486 {
1487 const struct terrain *pterrain = tile_terrain(ptile);
1488
1489 if (NULL != pterrain) {
1490 pv->data.v_const_string = terrain_name_translation(pterrain);
1491 } else {
1492 pv->data.v_const_string = "";
1493 }
1494 }
1495 break;
1496 case OPID_TILE_RESOURCE:
1497 {
1498 const struct extra_type *presource = tile_resource(ptile);
1499
1500 if (NULL != presource) {
1501 pv->data.v_const_string = extra_name_translation(presource);
1502 } else {
1503 pv->data.v_const_string = "";
1504 }
1505 }
1506 break;
1507 case OPID_TILE_XY:
1508 pv->data.v_string = g_strdup_printf("(%d, %d)", tile_x, tile_y);
1509 pv->must_free = TRUE;
1510 break;
1511 case OPID_TILE_INDEX:
1512 pv->data.v_int = tile_index(ptile);
1513 break;
1514 case OPID_TILE_X:
1515 pv->data.v_int = tile_x;
1516 break;
1517 case OPID_TILE_Y:
1518 pv->data.v_int = tile_y;
1519 break;
1520 case OPID_TILE_NAT_X:
1521 pv->data.v_int = nat_x;
1522 break;
1523 case OPID_TILE_NAT_Y:
1524 pv->data.v_int = nat_y;
1525 break;
1527 pv->data.v_int = ptile->continent;
1528 break;
1529 case OPID_TILE_SPECIALS:
1530 BV_CLR_ALL(pv->data.v_bv_special);
1532 if (tile_has_extra(ptile, pextra)) {
1533 BV_SET(pv->data.v_bv_special, pextra->data.special_idx);
1534 }
1536 break;
1537 case OPID_TILE_ROADS:
1538 BV_CLR_ALL(pv->data.v_bv_roads);
1540 if (tile_has_extra(ptile, pextra)) {
1541 BV_SET(pv->data.v_bv_roads, road_number(extra_road_get(pextra)));
1542 }
1544 break;
1545 case OPID_TILE_BASES:
1546 BV_CLR_ALL(pv->data.v_bv_bases);
1548 if (tile_has_extra(ptile, pextra)) {
1549 BV_SET(pv->data.v_bv_bases, base_number(extra_base_get(pextra)));
1550 }
1552 break;
1553 case OPID_TILE_VISION:
1554 pv->data.v_tile_vision = fc_malloc(sizeof(struct tile_vision_data));
1555
1556 /* The server saves the known tiles and the player vision in special
1557 * bitvectors with the number of tiles as index. Here we want the
1558 * information for one tile. Thus, the data is transformed to
1559 * bitvectors with the number of player slots as index. */
1560 BV_CLR_ALL(pv->data.v_tile_vision->tile_known);
1561 players_iterate(pplayer) {
1562 if (dbv_isset(&pplayer->tile_known, tile_index(ptile))) {
1563 BV_SET(pv->data.v_tile_vision->tile_known,
1564 player_index(pplayer));
1565 }
1567
1569 BV_CLR_ALL(pv->data.v_tile_vision->tile_seen[v]);
1570 players_iterate(pplayer) {
1571 if (fc_funcs->player_tile_vision_get(ptile, pplayer, v)) {
1572 BV_SET(pv->data.v_tile_vision->tile_seen[v],
1573 player_index(pplayer));
1574 }
1577 pv->must_free = TRUE;
1578 break;
1579 case OPID_TILE_LABEL:
1580 if (ptile->label != NULL) {
1581 pv->data.v_const_string = ptile->label;
1582 } else {
1583 pv->data.v_const_string = "";
1584 }
1585 break;
1586 default:
1587 log_error("%s(): Unhandled request for value of property %d "
1588 "(%s) from object of type \"%s\".", __FUNCTION__,
1590 goto FAILED;
1591 }
1592 }
1593 return pv;
1594
1595 case OBJTYPE_STARTPOS:
1596 {
1597 const struct startpos *psp = objbind_get_object(ob);
1598 const struct tile *ptile;
1599
1600 if (NULL == psp) {
1601 goto FAILED;
1602 }
1603
1604 switch (propid) {
1606 ptile = startpos_tile(psp);
1607 pv->data.v_pixbuf = create_tile_pixbuf(ptile);
1608 pv->must_free = TRUE;
1609 break;
1610 case OPID_STARTPOS_XY:
1611 ptile = startpos_tile(psp);
1612 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1613 pv->must_free = TRUE;
1614 break;
1616 pv->data.v_bool = startpos_is_excluding(psp);
1617 break;
1619 pv->data.v_nation_hash = nation_hash_copy(startpos_raw_nations(psp));
1620 pv->must_free = TRUE;
1621 break;
1622 default:
1623 log_error("%s(): Unhandled request for value of property %d "
1624 "(%s) from object of type \"%s\".", __FUNCTION__,
1626 goto FAILED;
1627 }
1628 }
1629 return pv;
1630
1631 case OBJTYPE_UNIT:
1632 {
1633 struct unit *punit = objbind_get_object(ob);
1634
1635 if (NULL == punit) {
1636 goto FAILED;
1637 }
1638
1639 switch (propid) {
1640 case OPID_UNIT_IMAGE:
1641 pv->data.v_pixbuf = create_unit_pixbuf(punit);
1642 pv->must_free = TRUE;
1643 break;
1644#ifdef FREECIV_DEBUG
1645 case OPID_UNIT_ADDRESS:
1646 pv->data.v_string = g_strdup_printf("%p", punit);
1647 pv->must_free = TRUE;
1648 break;
1649#endif /* FREECIV_DEBUG */
1650 case OPID_UNIT_XY:
1651 {
1652 const struct tile *ptile = unit_tile(punit);
1653
1654 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1655 pv->must_free = TRUE;
1656 }
1657 break;
1658 case OPID_UNIT_ID:
1659 pv->data.v_int = punit->id;
1660 break;
1661 case OPID_UNIT_TYPE:
1662 {
1663 const struct unit_type *putype = unit_type_get(punit);
1664
1665 pv->data.v_const_string = utype_name_translation(putype);
1666 }
1667 break;
1669 pv->data.v_int = punit->moves_left;
1670 break;
1671 case OPID_UNIT_FUEL:
1672 pv->data.v_int = punit->fuel;
1673 break;
1674 case OPID_UNIT_MOVED:
1675 pv->data.v_bool = punit->moved;
1676 break;
1678 pv->data.v_bool = punit->done_moving;
1679 break;
1680 case OPID_UNIT_HP:
1681 pv->data.v_int = punit->hp;
1682 break;
1683 case OPID_UNIT_VETERAN:
1684 pv->data.v_int = punit->veteran;
1685 break;
1686 case OPID_UNIT_STAY:
1687 pv->data.v_bool = punit->stay;
1688 break;
1689 default:
1690 log_error("%s(): Unhandled request for value of property %d "
1691 "(%s) from object of type \"%s\".", __FUNCTION__,
1693 goto FAILED;
1694 }
1695 }
1696 return pv;
1697
1698 case OBJTYPE_CITY:
1699 {
1700 const struct city *pcity = objbind_get_object(ob);
1701
1702 if (NULL == pcity) {
1703 goto FAILED;
1704 }
1705
1706 switch (propid) {
1707 case OPID_CITY_IMAGE:
1708 pv->data.v_pixbuf = create_city_pixbuf(pcity);
1709 pv->must_free = TRUE;
1710 break;
1711#ifdef FREECIV_DEBUG
1712 case OPID_CITY_ADDRESS:
1713 pv->data.v_string = g_strdup_printf("%p", pcity);
1714 pv->must_free = TRUE;
1715 break;
1716#endif /* FREECIV_DEBUG */
1717 case OPID_CITY_XY:
1718 {
1719 const struct tile *ptile = city_tile(pcity);
1720
1721 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1722 pv->must_free = TRUE;
1723 }
1724 break;
1725 case OPID_CITY_ID:
1726 pv->data.v_int = pcity->id;
1727 break;
1728 case OPID_CITY_NAME:
1729 pv->data.v_const_string = pcity->name;
1730 break;
1731 case OPID_CITY_SIZE:
1732 pv->data.v_int = city_size_get(pcity);
1733 break;
1734 case OPID_CITY_HISTORY:
1735 pv->data.v_int = pcity->history;
1736 break;
1738 pv->data.v_built = fc_malloc(sizeof(pcity->built));
1739 memcpy(pv->data.v_built, pcity->built, sizeof(pcity->built));
1740 pv->must_free = TRUE;
1741 break;
1743 pv->data.v_int = pcity->food_stock;
1744 break;
1746 pv->data.v_int = pcity->shield_stock;
1747 break;
1748 default:
1749 log_error("%s(): Unhandled request for value of property %d "
1750 "(%s) from object of type \"%s\".", __FUNCTION__,
1752 goto FAILED;
1753 }
1754 }
1755 return pv;
1756
1757 case OBJTYPE_PLAYER:
1758 {
1759 const struct player *pplayer = objbind_get_object(ob);
1760 const struct research *presearch;
1761
1762 if (NULL == pplayer) {
1763 goto FAILED;
1764 }
1765
1766 switch (propid) {
1767 case OPID_PLAYER_NAME:
1768 pv->data.v_const_string = pplayer->name;
1769 break;
1770 case OPID_PLAYER_NATION:
1771 pv->data.v_nation = nation_of_player(pplayer);
1772 break;
1773 case OPID_PLAYER_GOV:
1774 pv->data.v_gov = pplayer->government;
1775 break;
1776 case OPID_PLAYER_AGE:
1777 pv->data.v_int = pplayer->turns_alive;
1778 break;
1779#ifdef FREECIV_DEBUG
1781 pv->data.v_string = g_strdup_printf("%p", pplayer);
1782 pv->must_free = TRUE;
1783 break;
1784#endif /* FREECIV_DEBUG */
1786 presearch = research_get(pplayer);
1787 BV_CLR_ALL(pv->data.v_bv_inventions);
1790 BV_SET(pv->data.v_bv_inventions, tech);
1791 }
1793 break;
1795 pv->data.v_bool = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED);
1796 break;
1798 pv->data.v_int = pplayer->autoselect_weight;
1799 break;
1801 presearch = research_get(pplayer);
1802 pv->data.v_int = presearch->bulbs_researched;
1803 break;
1804 case OPID_PLAYER_GOLD:
1805 pv->data.v_int = pplayer->economic.gold;
1806 break;
1808 pv->data.v_int = pplayer->economic.infra_points;
1809 break;
1810 default:
1811 log_error("%s(): Unhandled request for value of property %d "
1812 "(%s) from object of type \"%s\".", __FUNCTION__,
1814 goto FAILED;
1815 }
1816 }
1817 return pv;
1818
1819 case OBJTYPE_GAME:
1820 {
1821 const struct civ_game *pgame = objbind_get_object(ob);
1822
1823 if (NULL == pgame) {
1824 goto FAILED;
1825 }
1826
1827 switch (propid) {
1828 case OPID_GAME_SCENARIO:
1829 pv->data.v_bool = pgame->scenario.is_scenario;
1830 break;
1832 pv->data.v_const_string = pgame->scenario.name;
1833 break;
1835 pv->data.v_const_string = pgame->scenario.authors;
1836 break;
1838 pv->data.v_const_string = pgame->scenario_desc.description;
1839 break;
1841 pv->data.v_bool = pgame->scenario.save_random;
1842 break;
1844 pv->data.v_bool = pgame->scenario.players;
1845 break;
1847 pv->data.v_bool = pgame->scenario.startpos_nations;
1848 break;
1850 pv->data.v_bool = pgame->scenario.prevent_new_cities;
1851 break;
1853 pv->data.v_bool = pgame->scenario.lake_flooding;
1854 break;
1856 pv->data.v_bool = pgame->scenario.ruleset_locked;
1857 break;
1858 default:
1859 log_error("%s(): Unhandled request for value of property %d "
1860 "(%s) from object of type \"%s\".", __FUNCTION__,
1862 goto FAILED;
1863 }
1864 }
1865 return pv;
1866
1867 case NUM_OBJTYPES:
1868 break;
1869 }
1870
1871 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
1873
1874FAILED:
1875 if (NULL != pv) {
1876 free(pv);
1877 }
1878 return NULL;
1879}
1880
1881/************************************************************************/
1886 struct objprop *op,
1887 double *pmin,
1888 double *pmax,
1889 double *pstep,
1890 double *pbig_step)
1891{
1894 double dummy;
1895
1896 /* Fill the values with something. */
1897 if (NULL != pmin) {
1898 *pmin = 0;
1899 } else {
1900 pmin = &dummy;
1901 }
1902 if (NULL != pmax) {
1903 *pmax = 1;
1904 } else {
1905 pmax = &dummy;
1906 }
1907 if (NULL != pstep) {
1908 *pstep = 1;
1909 } else {
1910 pstep = &dummy;
1911 }
1912 if (NULL != pbig_step) {
1913 *pbig_step = 1;
1914 } else {
1915 pbig_step = &dummy;
1916 }
1917
1918 if (!ob || !op) {
1919 return FALSE;
1920 }
1921
1924
1925 switch (objtype) {
1926 case OBJTYPE_TILE:
1927 case OBJTYPE_STARTPOS:
1928 log_error("%s(): Unhandled request for value range of property %d (%s) "
1929 "from object of type \"%s\".", __FUNCTION__,
1931 return FALSE;
1932
1933 case OBJTYPE_UNIT:
1934 {
1935 const struct unit *punit = objbind_get_object(ob);
1936 const struct unit_type *putype;
1937
1938 if (NULL == punit) {
1939 return FALSE;
1940 }
1941
1943
1944 switch (propid) {
1946 *pmin = 0;
1948 *pstep = 1;
1949 *pbig_step = 5;
1950 return TRUE;
1951 case OPID_UNIT_FUEL:
1952 *pmin = 0;
1954 *pstep = 1;
1955 *pbig_step = 5;
1956 return TRUE;
1957 case OPID_UNIT_HP:
1958 *pmin = 1;
1959 *pmax = putype->hp;
1960 *pstep = 1;
1961 *pbig_step = 10;
1962 return TRUE;
1963 case OPID_UNIT_VETERAN:
1964 *pmin = 0;
1966 *pstep = 1;
1967 *pbig_step = 3;
1968 return TRUE;
1969 default:
1970 break;
1971 }
1972 }
1973 log_error("%s(): Unhandled request for value range of property %d (%s) "
1974 "from object of type \"%s\".", __FUNCTION__,
1976 return FALSE;
1977
1978 case OBJTYPE_CITY:
1979 {
1980 const struct city *pcity = objbind_get_object(ob);
1981
1982 if (NULL == pcity) {
1983 return FALSE;
1984 }
1985
1986 switch (propid) {
1987 case OPID_CITY_SIZE:
1988 *pmin = 1;
1990 *pstep = 1;
1991 *pbig_step = 5;
1992 return TRUE;
1993 case OPID_CITY_HISTORY:
1994 *pmin = 0;
1995 *pmax = USHRT_MAX;
1996 *pstep = 1;
1997 *pbig_step = 10;
1998 return TRUE;
2000 *pmin = 0;
2002 *pstep = 1;
2003 *pbig_step = 5;
2004 return TRUE;
2006 *pmin = 0;
2007 *pmax = USHRT_MAX; /* Limited to uint16 by city info packet. */
2008 *pstep = 1;
2009 *pbig_step = 10;
2010 return TRUE;
2011 default:
2012 break;
2013 }
2014 }
2015 log_error("%s(): Unhandled request for value range of property %d (%s) "
2016 "from object of type \"%s\".", __FUNCTION__,
2018 return FALSE;
2019
2020 case OBJTYPE_PLAYER:
2021 switch (propid) {
2023 *pmin = 0;
2024 *pmax = 1000000; /* Arbitrary. */
2025 *pstep = 1;
2026 *pbig_step = 100;
2027 return TRUE;
2028 case OPID_PLAYER_GOLD:
2029 *pmin = 0;
2030 *pmax = 1000000; /* Arbitrary. */
2031 *pstep = 1;
2032 *pbig_step = 100;
2033 return TRUE;
2035 *pmin = 0;
2036 *pmax = 1000000; /* Arbitrary. */
2037 *pstep = 1;
2038 *pbig_step = 100;
2039 return TRUE;
2041 *pmin = -1;
2042 *pmax = 10000; /* Keep it under SINT16 */
2043 *pstep = 1;
2044 *pbig_step = 10;
2045 return TRUE;
2046 default:
2047 break;
2048 }
2049 log_error("%s(): Unhandled request for value range of property %d (%s) "
2050 "from object of type \"%s\".", __FUNCTION__,
2052 return FALSE;
2053
2054 case OBJTYPE_GAME:
2055 log_error("%s(): Unhandled request for value range of property %d (%s) "
2056 "from object of type \"%s\".", __FUNCTION__,
2058 return FALSE;
2059
2060 case NUM_OBJTYPES:
2061 break;
2062 }
2063
2064 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
2066 return FALSE;
2067}
2068
2069/************************************************************************/
2073 struct objprop *op)
2074{
2075 if (!ob || !op || !ob->propstate_table) {
2076 return;
2077 }
2078
2079 propstate_hash_remove(ob->propstate_table, objprop_get_id(op));
2080}
2081
2082/************************************************************************/
2087 struct objprop *op)
2088{
2089 if (!ob || !op) {
2090 return FALSE;
2091 }
2092
2093 if (objprop_is_readonly(op)) {
2094 return FALSE;
2095 }
2096
2097 return propstate_hash_lookup(ob->propstate_table,
2099}
2100
2101/************************************************************************/
2106{
2107 if (!ob) {
2108 return FALSE;
2109 }
2110
2111 return (0 < propstate_hash_size(ob->propstate_table));
2112}
2113
2114/************************************************************************/
2118{
2119 if (!ob) {
2120 return;
2121 }
2122 propstate_hash_clear(ob->propstate_table);
2123}
2124
2125/************************************************************************/
2132 struct objprop *op,
2133 struct propval *pv)
2134{
2135 struct propstate *ps;
2136 bool equal;
2137 struct propval *pv_old, *pv_copy;
2139
2140 if (!ob || !op) {
2141 return FALSE;
2142 }
2143
2145
2147 if (!pv_old) {
2148 return FALSE;
2149 }
2150
2153
2154 if (equal) {
2156 return FALSE;
2157 }
2158
2160
2161 if (propstate_hash_lookup(ob->propstate_table, propid, &ps)) {
2163 } else {
2165 propstate_hash_insert(ob->propstate_table, propid, ps);
2166 }
2167
2168 return TRUE;
2169}
2170
2171/************************************************************************/
2178 struct objprop *op)
2179{
2180 struct propstate *ps;
2181
2182 if (!ob || !op) {
2183 return NULL;
2184 }
2185
2186 if (propstate_hash_lookup(ob->propstate_table, objprop_get_id(op), &ps)) {
2187 return propstate_get_value(ps);
2188 } else {
2189 return NULL;
2190 }
2191}
2192
2193/************************************************************************/
2196static void objbind_destroy(struct objbind *ob)
2197{
2198 if (!ob) {
2199 return;
2200 }
2201 if (ob->propstate_table) {
2202 propstate_hash_destroy(ob->propstate_table);
2203 ob->propstate_table = NULL;
2204 }
2205 if (ob->rowref) {
2207 ob->rowref = NULL;
2208 }
2209 free(ob);
2210}
2211
2212/************************************************************************/
2216{
2217 if (!ob) {
2218 return NUM_OBJTYPES;
2219 }
2220 return ob->objtype;
2221}
2222
2223/************************************************************************/
2227 struct property_page *pp)
2228{
2229 if (!ob) {
2230 return;
2231 }
2232 ob->parent_property_page = pp;
2233}
2234
2235/************************************************************************/
2241 union packetdata pd)
2242{
2244
2245 if (!ob || !pd.pointers.v_pointer1) {
2246 return;
2247 }
2248
2250
2251 switch (objtype) {
2252 case OBJTYPE_TILE:
2253 {
2254 struct packet_edit_tile *packet = pd.tile;
2255 const struct tile *ptile = objbind_get_object(ob);
2256
2257 if (NULL == ptile) {
2258 return;
2259 }
2260
2261 packet->tile = tile_index(ptile);
2262 packet->extras = *tile_extras(ptile);
2263 /* TODO: Set more packet fields. */
2264 }
2265 return;
2266
2267 case OBJTYPE_STARTPOS:
2268 {
2269 struct packet_edit_startpos_full *packet = pd.startpos;
2270 const struct startpos *psp = objbind_get_object(ob);
2271
2272 if (NULL != psp) {
2273 startpos_pack(psp, packet);
2274 }
2275 }
2276 return;
2277
2278 case OBJTYPE_UNIT:
2279 {
2280 struct packet_edit_unit *packet = pd.unit;
2281 const struct unit *punit = objbind_get_object(ob);
2282
2283 if (NULL == punit) {
2284 return;
2285 }
2286
2287 packet->id = punit->id;
2288 packet->moves_left = punit->moves_left;
2289 packet->fuel = punit->fuel;
2290 packet->moved = punit->moved;
2291 packet->done_moving = punit->done_moving;
2292 packet->hp = punit->hp;
2293 packet->veteran = punit->veteran;
2294 packet->stay = punit->stay;
2295 /* TODO: Set more packet fields. */
2296 }
2297 return;
2298
2299 case OBJTYPE_CITY:
2300 {
2301 struct packet_edit_city *packet = pd.city;
2302 const struct city *pcity = objbind_get_object(ob);
2303 int i;
2304
2305 if (NULL == pcity) {
2306 return;
2307 }
2308
2309 packet->id = pcity->id;
2310 sz_strlcpy(packet->name, pcity->name);
2311 packet->size = city_size_get(pcity);
2312 packet->history = pcity->history;
2313 for (i = 0; i < B_LAST; i++) {
2314 packet->built[i] = pcity->built[i].turn;
2315 }
2316 packet->food_stock = pcity->food_stock;
2317 packet->shield_stock = pcity->shield_stock;
2318 /* TODO: Set more packet fields. */
2319 }
2320 return;
2321
2322 case OBJTYPE_PLAYER:
2323 {
2324 struct packet_edit_player *packet = pd.player;
2325 const struct player *pplayer = objbind_get_object(ob);
2326 const struct nation_type *pnation;
2327 const struct research *presearch;
2328
2329 if (NULL == pplayer) {
2330 return;
2331 }
2332
2333 packet->id = player_number(pplayer);
2334 sz_strlcpy(packet->name, pplayer->name);
2335 pnation = nation_of_player(pplayer);
2336 packet->nation = nation_index(pnation);
2337 presearch = research_get(pplayer);
2339 packet->inventions[tech]
2342 packet->autoselect_weight = pplayer->autoselect_weight;
2343 packet->gold = pplayer->economic.gold;
2344 packet->infrapoints = pplayer->economic.infra_points;
2345 packet->government = government_index(pplayer->government);
2347 /* TODO: Set more packet fields. */
2348 }
2349 return;
2350
2351 case OBJTYPE_GAME:
2352 {
2353 struct packet_edit_game *packet = pd.game.game;
2354 const struct civ_game *pgame = objbind_get_object(ob);
2355
2356 if (NULL == pgame) {
2357 return;
2358 }
2359
2360 packet->scenario = pgame->scenario.is_scenario;
2361 sz_strlcpy(packet->scenario_name, pgame->scenario.name);
2362 sz_strlcpy(packet->scenario_authors, pgame->scenario.authors);
2363 sz_strlcpy(pd.game.desc->scenario_desc, pgame->scenario_desc.description);
2364 packet->scenario_random = pgame->scenario.save_random;
2365 packet->scenario_players = pgame->scenario.players;
2366 packet->startpos_nations = pgame->scenario.startpos_nations;
2367 packet->prevent_new_cities = pgame->scenario.prevent_new_cities;
2368 packet->lake_flooding = pgame->scenario.lake_flooding;
2369 }
2370 return;
2371
2372 case NUM_OBJTYPES:
2373 break;
2374 }
2375
2376 log_error("%s(): Unhandled object type %s (nb %d).", __FUNCTION__,
2378}
2379
2380/************************************************************************/
2384 struct objprop *op,
2385 union packetdata pd)
2386{
2387 struct propval *pv;
2390
2391 if (!op || !ob || !pd.pointers.v_pointer1) {
2392 return;
2393 }
2394
2395 if (NULL == objbind_get_object(ob)) {
2396 return;
2397 }
2398
2400 return;
2401 }
2402
2404 if (!pv) {
2405 return;
2406 }
2407
2410
2411 switch (objtype) {
2412 case OBJTYPE_TILE:
2413 {
2414 struct packet_edit_tile *packet = pd.tile;
2415
2416 switch (propid) {
2417 case OPID_TILE_SPECIALS:
2419 if (BV_ISSET(pv->data.v_bv_special, pextra->data.special_idx)) {
2420 BV_SET(packet->extras, pextra->data.special_idx);
2421 } else {
2422 BV_CLR(packet->extras, pextra->data.special_idx);
2423 }
2425 return;
2426 case OPID_TILE_ROADS:
2428 int ridx = road_number(extra_road_get(pextra));
2429
2430 if (BV_ISSET(pv->data.v_bv_roads, ridx)) {
2431 BV_SET(packet->extras, extra_index(pextra));
2432 } else {
2433 BV_CLR(packet->extras, extra_index(pextra));
2434 }
2436 return;
2437 case OPID_TILE_BASES:
2439 int bidx = base_number(extra_base_get(pextra));
2440
2441 if (BV_ISSET(pv->data.v_bv_bases, bidx)) {
2442 BV_SET(packet->extras, extra_index(pextra));
2443 } else {
2444 BV_CLR(packet->extras, extra_index(pextra));
2445 }
2447 return;
2448 case OPID_TILE_LABEL:
2449 sz_strlcpy(packet->label, pv->data.v_string);
2450 return;
2451 default:
2452 break;
2453 }
2454 }
2455 log_error("%s(): Unhandled request to pack value of property "
2456 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2458 return;
2459
2460 case OBJTYPE_STARTPOS:
2461 {
2462 struct packet_edit_startpos_full *packet = pd.startpos;
2463
2464 switch (propid) {
2466 packet->exclude = pv->data.v_bool;
2467 return;
2469 BV_CLR_ALL(packet->nations);
2470 nation_hash_iterate(pv->data.v_nation_hash, pnation) {
2471 BV_SET(packet->nations, nation_number(pnation));
2473 return;
2474 default:
2475 break;
2476 }
2477 }
2478 log_error("%s(): Unhandled request to pack value of property "
2479 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2481 return;
2482
2483 case OBJTYPE_UNIT:
2484 {
2485 struct packet_edit_unit *packet = pd.unit;
2486
2487 switch (propid) {
2489 packet->moves_left = pv->data.v_int;
2490 return;
2491 case OPID_UNIT_FUEL:
2492 packet->fuel = pv->data.v_int;
2493 return;
2494 case OPID_UNIT_MOVED:
2495 packet->moved = pv->data.v_bool;
2496 return;
2498 packet->done_moving = pv->data.v_bool;
2499 return;
2500 case OPID_UNIT_HP:
2501 packet->hp = pv->data.v_int;
2502 return;
2503 case OPID_UNIT_VETERAN:
2504 packet->veteran = pv->data.v_int;
2505 return;
2506 case OPID_UNIT_STAY:
2507 packet->stay = pv->data.v_bool;
2508 return;
2509 default:
2510 break;
2511 }
2512 }
2513 log_error("%s(): Unhandled request to pack value of property "
2514 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2516 return;
2517
2518 case OBJTYPE_CITY:
2519 {
2520 struct packet_edit_city *packet = pd.city;
2521
2522 switch (propid) {
2523 case OPID_CITY_NAME:
2524 sz_strlcpy(packet->name, pv->data.v_string);
2525 return;
2526 case OPID_CITY_SIZE:
2527 packet->size = pv->data.v_int;
2528 return;
2529 case OPID_CITY_HISTORY:
2530 packet->history = pv->data.v_int;
2531 return;
2533 packet->food_stock = pv->data.v_int;
2534 return;
2536 packet->shield_stock = pv->data.v_int;
2537 return;
2539 {
2540 int i;
2541
2542 for (i = 0; i < B_LAST; i++) {
2543 packet->built[i] = pv->data.v_built[i].turn;
2544 }
2545 }
2546 return;
2547 default:
2548 break;
2549 }
2550 }
2551 log_error("%s(): Unhandled request to pack value of property "
2552 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2554 return;
2555
2556 case OBJTYPE_PLAYER:
2557 {
2558 struct packet_edit_player *packet = pd.player;
2559
2560 switch (propid) {
2561 case OPID_PLAYER_NAME:
2562 sz_strlcpy(packet->name, pv->data.v_string);
2563 return;
2564 case OPID_PLAYER_NATION:
2565 packet->nation = nation_index(pv->data.v_nation);
2566 return;
2567 case OPID_PLAYER_GOV:
2568 packet->government = government_index(pv->data.v_gov);
2569 return;
2572 packet->inventions[tech] = BV_ISSET(pv->data.v_bv_inventions, tech);
2574 return;
2576 packet->scenario_reserved = pv->data.v_bool;
2577 return;
2579 packet->autoselect_weight = pv->data.v_int;
2580 return;
2582 packet->bulbs_researched = pv->data.v_int;
2583 return;
2584 case OPID_PLAYER_GOLD:
2585 packet->gold = pv->data.v_int;
2586 return;
2588 packet->infrapoints = pv->data.v_int;
2589 return;
2590 default:
2591 break;
2592 }
2593 }
2594 log_error("%s(): Unhandled request to pack value of property "
2595 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2597 return;
2598
2599 case OBJTYPE_GAME:
2600 {
2601 struct packet_edit_game *packet = pd.game.game;
2602
2603 switch (propid) {
2604 case OPID_GAME_SCENARIO:
2605 packet->scenario = pv->data.v_bool;
2606 return;
2608 sz_strlcpy(packet->scenario_name, pv->data.v_const_string);
2609 return;
2611 sz_strlcpy(packet->scenario_authors, pv->data.v_const_string);
2612 return;
2614 sz_strlcpy(pd.game.desc->scenario_desc, pv->data.v_const_string);
2615 return;
2617 packet->scenario_random = pv->data.v_bool;
2618 return;
2620 packet->scenario_players = pv->data.v_bool;
2621 return;
2623 packet->startpos_nations = pv->data.v_bool;
2624 return;
2626 packet->prevent_new_cities = pv->data.v_bool;
2627 return;
2629 packet->lake_flooding = pv->data.v_bool;
2630 return;
2632 packet->ruleset_locked = pv->data.v_bool;
2633 return;
2634 default:
2635 break;
2636 }
2637 }
2638 log_error("%s(): Unhandled request to pack value of property "
2639 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2641 return;
2642
2643 case NUM_OBJTYPES:
2644 break;
2645 }
2646
2647 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
2649
2650}
2651
2652/************************************************************************/
2655static void objbind_set_rowref(struct objbind *ob,
2657{
2658 if (!ob) {
2659 return;
2660 }
2661 ob->rowref = rr;
2662}
2663
2664/************************************************************************/
2668{
2669 if (!ob) {
2670 return NULL;
2671 }
2672 return ob->rowref;
2673}
2674
2675/************************************************************************/
2678static int objprop_get_id(const struct objprop *op)
2679{
2680 if (!op) {
2681 return -1;
2682 }
2683 return op->id;
2684}
2685
2686/************************************************************************/
2693static GType objprop_get_gtype(const struct objprop *op)
2694{
2696
2697 switch (op->valtype) {
2698 case VALTYPE_NONE:
2700 return G_TYPE_NONE;
2701 case VALTYPE_INT:
2702 return G_TYPE_INT;
2703 case VALTYPE_BOOL:
2704 /* We want to show it as translated string, not as untranslated G_TYPE_BOOLEAN */
2705 return G_TYPE_STRING;
2706 case VALTYPE_STRING:
2709 case VALTYPE_BV_SPECIAL:
2710 case VALTYPE_BV_ROADS:
2711 case VALTYPE_BV_BASES:
2713 return G_TYPE_STRING;
2714 case VALTYPE_PIXBUF:
2715 case VALTYPE_NATION:
2716 case VALTYPE_GOV:
2717 return GDK_TYPE_PIXBUF;
2718 }
2719 log_error("%s(): Unhandled value type %d.", __FUNCTION__, op->valtype);
2720 return G_TYPE_NONE;
2721}
2722
2723/************************************************************************/
2726static enum value_types objprop_get_valtype(const struct objprop *op)
2727{
2728 if (!op) {
2729 return VALTYPE_NONE;
2730 }
2731 return op->valtype;
2732}
2733
2734/************************************************************************/
2737static bool objprop_show_in_listview(const struct objprop *op)
2738{
2739 if (!op) {
2740 return FALSE;
2741 }
2742 return op->flags & OPF_IN_LISTVIEW;
2743}
2744
2745/************************************************************************/
2748static bool objprop_has_widget(const struct objprop *op)
2749{
2750 if (!op) {
2751 return FALSE;
2752 }
2753 return op->flags & OPF_HAS_WIDGET;
2754}
2755
2756/************************************************************************/
2762static const char *objprop_get_attribute_type_string(const struct objprop *op)
2763{
2764 GType gtype;
2765
2766 if (!op) {
2767 return NULL;
2768 }
2769
2771 if (gtype == G_TYPE_INT || gtype == G_TYPE_STRING
2772 || gtype == G_TYPE_BOOLEAN) {
2773 return "text";
2774 } else if (gtype == GDK_TYPE_PIXBUF) {
2775 return "pixbuf";
2776 }
2777
2778 return NULL;
2779}
2780
2781/************************************************************************/
2787static void objprop_set_column_id(struct objprop *op, int col_id)
2788{
2789 if (!op) {
2790 return;
2791 }
2792 op->column_id = col_id;
2793}
2794
2795/************************************************************************/
2800static int objprop_get_column_id(const struct objprop *op)
2801{
2802 if (!op) {
2803 return -1;
2804 }
2805 return op->column_id;
2806}
2807
2808/************************************************************************/
2813{
2814 if (!op) {
2815 return;
2816 }
2817 op->view_column = col;
2818}
2819
2820/************************************************************************/
2825{
2826 if (!op) {
2827 return NULL;
2828 }
2829 return op->view_column;
2830}
2831
2832/************************************************************************/
2835static const char *objprop_get_name(const struct objprop *op)
2836{
2837 if (!op) {
2838 return NULL;
2839 }
2840 return op->name;
2841}
2842
2843/************************************************************************/
2846static const char *objprop_get_tooltip(const struct objprop *op)
2847{
2848 if (!op) {
2849 return NULL;
2850 }
2851 return op->tooltip;
2852}
2853
2854/************************************************************************/
2860{
2862 GType gtype;
2863
2865
2866 if (gtype == G_TYPE_INT || gtype == G_TYPE_STRING
2867 || gtype == G_TYPE_BOOLEAN) {
2869 } else if (gtype == GDK_TYPE_PIXBUF) {
2871 }
2872
2873 return cell;
2874}
2875
2876/************************************************************************/
2880static bool objprop_is_sortable(const struct objprop *op)
2881{
2882 GType gtype;
2883 if (!op) {
2884 return FALSE;
2885 }
2887 return gtype == G_TYPE_INT || gtype == G_TYPE_STRING;
2888}
2889
2890/************************************************************************/
2894static bool objprop_is_readonly(const struct objprop *op)
2895{
2896 if (!op) {
2897 return TRUE;
2898 }
2899 return !(op->flags & OPF_EDITABLE);
2900}
2901
2902/************************************************************************/
2906{
2907 struct objprop *op;
2908 struct property_page *pp;
2909 struct propval value = {{0,}, VALTYPE_STRING, FALSE};
2910
2911 op = userdata;
2914
2916}
2917
2918/************************************************************************/
2923{
2924 struct objprop *op;
2925 struct property_page *pp;
2926 struct propval value = {{0,}, VALTYPE_INT, FALSE};
2927
2928 op = userdata;
2931
2933}
2934
2935/************************************************************************/
2940{
2941 struct objprop *op;
2942 struct property_page *pp;
2943 struct propval value = {{0,}, VALTYPE_BOOL, FALSE};
2944
2945 op = userdata;
2948
2950}
2951
2952/************************************************************************/
2955static void objprop_setup_widget(struct objprop *op)
2956{
2957 GtkWidget *hbox, *hbox2, *label, *image, *text, *spin, *button;
2958 struct extviewer *ev = NULL;
2960
2961 if (!op) {
2962 return;
2963 }
2964
2965 if (!objprop_has_widget(op)) {
2966 return;
2967 }
2968
2970 op->widget = hbox;
2971
2975 gtk_box_append(GTK_BOX(hbox), label);
2976 objprop_set_child_widget(op, "name-label", label);
2977
2979
2980 switch (propid) {
2981 case OPID_TILE_INDEX:
2982 case OPID_TILE_X:
2983 case OPID_TILE_Y:
2984 case OPID_TILE_NAT_X:
2985 case OPID_TILE_NAT_Y:
2987 case OPID_TILE_TERRAIN:
2988 case OPID_TILE_RESOURCE:
2989 case OPID_TILE_XY:
2990 case OPID_STARTPOS_XY:
2991 case OPID_UNIT_ID:
2992 case OPID_UNIT_XY:
2993 case OPID_UNIT_TYPE:
2994 case OPID_CITY_ID:
2995 case OPID_CITY_XY:
2996 case OPID_PLAYER_AGE:
2997#ifdef FREECIV_DEBUG
2998 case OPID_TILE_ADDRESS:
2999 case OPID_UNIT_ADDRESS:
3000 case OPID_CITY_ADDRESS:
3002#endif /* FREECIV_DEBUG */
3003 label = gtk_label_new(NULL);
3007 gtk_box_append(GTK_BOX(hbox), label);
3008 objprop_set_child_widget(op, "value-label", label);
3009 return;
3010
3011 case OPID_TILE_IMAGE:
3013 case OPID_UNIT_IMAGE:
3014 case OPID_CITY_IMAGE:
3015 image = gtk_image_new();
3024 return;
3025
3026 case OPID_CITY_NAME:
3027 case OPID_PLAYER_NAME:
3029 case OPID_TILE_LABEL:
3030 text = gtk_text_new();
3034 g_signal_connect(text, "changed",
3036 gtk_box_append(GTK_BOX(hbox), text);
3037 objprop_set_child_widget(op, "text", text);
3038 return;
3039
3041 case OPID_CITY_SIZE:
3042 case OPID_CITY_HISTORY:
3046 case OPID_PLAYER_GOLD:
3048 spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
3051 g_signal_connect(spin, "value-changed",
3055 return;
3056
3057 case OPID_UNIT_FUEL:
3058 case OPID_UNIT_HP:
3059 case OPID_UNIT_VETERAN:
3065 spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
3066 g_signal_connect(spin, "value-changed",
3070 label = gtk_label_new(NULL);
3073 gtk_box_append(GTK_BOX(hbox2), label);
3074 objprop_set_child_widget(op, "max-value-label", label);
3075 return;
3076
3077 case OPID_TILE_SPECIALS:
3078 case OPID_TILE_ROADS:
3079 case OPID_TILE_BASES:
3080 case OPID_TILE_VISION:
3083 case OPID_PLAYER_NATION:
3084 case OPID_PLAYER_GOV:
3088 ev = extviewer_new(op);
3094 return;
3095
3097 case OPID_UNIT_MOVED:
3099 case OPID_UNIT_STAY:
3100 case OPID_GAME_SCENARIO:
3108 button = gtk_toggle_button_new();
3111 g_signal_connect(button, "toggled",
3113 op);
3114 gtk_box_append(GTK_BOX(hbox), button);
3115 objprop_set_child_widget(op, "togglebutton", button);
3116 return;
3117 }
3118
3119 log_error("%s(): Unhandled request to create widget for property %d (%s).",
3121}
3122
3123/************************************************************************/
3132 struct objbind *ob)
3133{
3134 GtkWidget *w, *label, *image, *text, *spin, *button;
3135 struct extviewer *ev;
3136 struct propval *pv;
3137 bool modified;
3139 double min, max, step, big_step;
3140 char buf[256];
3141 const char *newtext;
3142 GtkEntryBuffer *buffer;
3143
3144 if (!op || !objprop_has_widget(op)) {
3145 return;
3146 }
3147
3149 if (!w) {
3150 return;
3151 }
3152
3154
3155 /* NB: We must take care to propval_free() the return value of
3156 * objbind_get_value_from_object(), since it always makes a
3157 * copy, but to NOT free the result of objbind_get_modified_value()
3158 * since it returns its own stored value. */
3161
3162 if (pv && modified) {
3163 struct propval *pv_mod;
3164
3166 if (pv_mod) {
3167 if (propval_equal(pv, pv_mod)) {
3169 modified = FALSE;
3170 } else {
3172 pv = pv_mod;
3173 modified = TRUE;
3174 }
3175 } else {
3176 modified = FALSE;
3177 }
3178 }
3179
3180 switch (propid) {
3181 case OPID_TILE_IMAGE:
3183 case OPID_UNIT_IMAGE:
3184 case OPID_CITY_IMAGE:
3185 image = objprop_get_child_widget(op, "image");
3186 if (pv) {
3187 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pv->data.v_pixbuf);
3188 } else {
3190 }
3191 break;
3192
3193 case OPID_TILE_XY:
3194 case OPID_TILE_TERRAIN:
3195 case OPID_TILE_RESOURCE:
3196 case OPID_STARTPOS_XY:
3197 case OPID_UNIT_XY:
3198 case OPID_UNIT_TYPE:
3199 case OPID_CITY_XY:
3200#ifdef FREECIV_DEBUG
3201 case OPID_TILE_ADDRESS:
3202 case OPID_UNIT_ADDRESS:
3203 case OPID_CITY_ADDRESS:
3205#endif /* FREECIV_DEBUG */
3206 label = objprop_get_child_widget(op, "value-label");
3207 if (pv) {
3208 gtk_label_set_text(GTK_LABEL(label), pv->data.v_string);
3209 } else {
3211 }
3212 break;
3213
3214 case OPID_TILE_INDEX:
3215 case OPID_TILE_X:
3216 case OPID_TILE_Y:
3217 case OPID_TILE_NAT_X:
3218 case OPID_TILE_NAT_Y:
3220 case OPID_UNIT_ID:
3221 case OPID_CITY_ID:
3222 case OPID_PLAYER_AGE:
3223 label = objprop_get_child_widget(op, "value-label");
3224 if (pv) {
3225 char agebuf[16];
3226
3227 fc_snprintf(agebuf, sizeof(agebuf), "%d", pv->data.v_int);
3229 } else {
3231 }
3232 break;
3233
3234 case OPID_CITY_NAME:
3235 case OPID_PLAYER_NAME:
3237 case OPID_TILE_LABEL:
3238 text = objprop_get_child_widget(op, "text");
3239 if (pv) {
3240 /* Most of these are semantically in "v_const_string",
3241 * but this works as the address is the same regardless. */
3242 newtext = pv->data.v_string;
3243 } else {
3244 newtext = "";
3245 }
3246 buffer = gtk_text_get_buffer(GTK_TEXT(text));
3247
3248 /* Only set the text if it has changed. This breaks
3249 * recursive loop. */
3252 }
3254 break;
3255
3257 case OPID_CITY_SIZE:
3258 case OPID_CITY_HISTORY:
3262 case OPID_PLAYER_GOLD:
3264 spin = objprop_get_child_widget(op, "spin");
3265 if (pv) {
3268 if (objbind_get_allowed_value_span(ob, op, &min, &max,
3269 &step, &big_step)) {
3272 step, big_step);
3273 }
3277 }
3279 break;
3280
3281 case OPID_UNIT_FUEL:
3282 case OPID_UNIT_HP:
3283 case OPID_UNIT_VETERAN:
3285 spin = objprop_get_child_widget(op, "spin");
3286 label = objprop_get_child_widget(op, "max-value-label");
3287 if (pv) {
3290 if (objbind_get_allowed_value_span(ob, op, &min, &max,
3291 &step, &big_step)) {
3294 step, big_step);
3295 fc_snprintf(buf, sizeof(buf), "/%d", (int) max);
3297 } else {
3299 }
3303 } else {
3305 }
3307 break;
3308
3309 case OPID_TILE_SPECIALS:
3310 case OPID_TILE_ROADS:
3311 case OPID_TILE_BASES:
3312 case OPID_TILE_VISION:
3315 case OPID_PLAYER_NATION:
3316 case OPID_PLAYER_GOV:
3321 if (pv) {
3323 } else {
3325 }
3326 break;
3327
3329 case OPID_UNIT_MOVED:
3331 case OPID_UNIT_STAY:
3332 case OPID_GAME_SCENARIO:
3340 button = objprop_get_child_widget(op, "togglebutton");
3343 if (pv) {
3345 pv->data.v_bool);
3346 } else {
3348 }
3351 gtk_widget_set_sensitive(button, pv != NULL);
3352 break;
3353 }
3354
3355 if (!modified) {
3357 }
3358
3359 label = objprop_get_child_widget(op, "name-label");
3360 if (label) {
3361 const char *name = objprop_get_name(op);
3362 if (modified) {
3363 char namebuf[128];
3364
3365 fc_snprintf(namebuf, sizeof(namebuf),
3366 "<span foreground=\"red\">%s</span>", name);
3368 } else {
3370 }
3371 }
3372}
3373
3374/************************************************************************/
3379{
3380 if (!op) {
3381 return NULL;
3382 }
3383 if (!op->widget) {
3385 }
3386 return op->widget;
3387}
3388
3389/************************************************************************/
3394 const char *widget_name,
3396{
3397 GtkWidget *w;
3398
3399 if (!op || !widget_name || !widget) {
3400 return;
3401 }
3402
3404 if (!w) {
3405 log_error("Cannot store child widget %p under name "
3406 "\"%s\" using objprop_set_child_widget for object "
3407 "property %d (%s) because objprop_get_widget does "
3408 "not return a valid widget.",
3410 return;
3411 }
3412
3414}
3415
3416/************************************************************************/
3421 const char *widget_name)
3422{
3423 GtkWidget *w, *child;
3424
3425 if (!op || !widget_name) {
3426 return NULL;
3427 }
3428
3430 if (!w) {
3431 log_error("Cannot retrieve child widget under name "
3432 "\"%s\" using objprop_get_child_widget for object "
3433 "property %d (%s) because objprop_get_widget does "
3434 "not return a valid widget.",
3436 return NULL;
3437 }
3438
3440 if (!child) {
3441 log_error("Child widget \"%s\" not found for object "
3442 "property %d (%s) via objprop_get_child_widget.",
3444 return NULL;
3445 }
3446
3447 return child;
3448}
3449
3450/************************************************************************/
3454 struct extviewer *ev)
3455{
3456 if (!op) {
3457 return;
3458 }
3459 op->extviewer = ev;
3460}
3461
3462/************************************************************************/
3466{
3467 if (!op) {
3468 return NULL;
3469 }
3470 return op->extviewer;
3471}
3472
3473/************************************************************************/
3477{
3478 if (!op) {
3479 return NULL;
3480 }
3481 return op->parent_page;
3482}
3483
3484/************************************************************************/
3487static struct objprop *objprop_new(int id,
3488 const char *name,
3489 const char *tooltip,
3491 enum value_types valtype,
3492 struct property_page *parent)
3493{
3494 struct objprop *op;
3495
3496 op = fc_calloc(1, sizeof(*op));
3497 op->id = id;
3498 op->name = name;
3499 op->tooltip = tooltip;
3500 op->flags = flags;
3501 op->valtype = valtype;
3502 op->column_id = -1;
3503 op->parent_page = parent;
3504
3505 return op;
3506}
3507
3508/************************************************************************/
3512static struct extviewer *extviewer_new(struct objprop *op)
3513{
3514 struct extviewer *ev;
3515 GtkWidget *hbox, *vbox, *label, *button, *scrollwin, *image;
3516 GtkWidget *view = NULL;
3520 GType *gtypes;
3522 int num_cols;
3523
3524 if (!op) {
3525 return NULL;
3526 }
3527
3528 ev = fc_calloc(1, sizeof(*ev));
3529 ev->objprop = op;
3530
3532
3533
3534 /* Create the panel widget. */
3535
3536 switch (propid) {
3537 case OPID_TILE_SPECIALS:
3538 case OPID_TILE_ROADS:
3539 case OPID_TILE_BASES:
3546 ev->panel_widget = hbox;
3547
3548 label = gtk_label_new(NULL);
3551 gtk_box_append(GTK_BOX(hbox), label);
3552 ev->panel_label = label;
3553 break;
3554
3555 case OPID_PLAYER_NATION:
3556 case OPID_PLAYER_GOV:
3558 ev->panel_widget = vbox;
3559
3560 label = gtk_label_new(NULL);
3563 gtk_box_append(GTK_BOX(vbox), label);
3564 ev->panel_label = label;
3565
3567 gtk_box_append(GTK_BOX(vbox), hbox);
3568
3569 image = gtk_image_new();
3570 if (propid == OPID_PLAYER_GOV) {
3574 } else {
3575 /* propid OPID_PLAYER_NATION */
3577 }
3581 ev->panel_image = image;
3582 break;
3583
3584 case OPID_TILE_VISION:
3586 ev->panel_widget = hbox;
3587 break;
3588
3589 default:
3590 log_error("Unhandled request to create panel widget "
3591 "for property %d (%s) in extviewer_new().",
3594 ev->panel_widget = hbox;
3595 break;
3596 }
3597
3598 if (objprop_is_readonly(op)) {
3599 button = gtk_button_new_with_label(Q_("?verb:View"));
3600 } else {
3601 button = gtk_button_new_with_label(_("Edit"));
3602 }
3603 g_signal_connect(button, "clicked",
3605 gtk_box_append(GTK_BOX(hbox), button);
3606 ev->panel_button = button;
3607
3608
3609 /* Create the data store. */
3610
3611 switch (propid) {
3612 case OPID_TILE_SPECIALS:
3613 case OPID_TILE_ROADS:
3614 case OPID_TILE_BASES:
3618 break;
3619 case OPID_TILE_VISION:
3620 num_cols = 3 + 1 + V_COUNT;
3621 gtypes = fc_malloc(num_cols * sizeof(GType));
3622 gtypes[0] = G_TYPE_INT; /* player number */
3623 gtypes[1] = GDK_TYPE_PIXBUF; /* player flag */
3624 gtypes[2] = G_TYPE_STRING; /* player name */
3625 gtypes[3] = G_TYPE_BOOLEAN; /* tile_known */
3627 gtypes[4 + v] = G_TYPE_BOOLEAN; /* tile_seen[v] */
3630 free(gtypes);
3631 break;
3635 break;
3637 case OPID_PLAYER_NATION:
3638 case OPID_PLAYER_GOV:
3641 break;
3645 break;
3646 default:
3647 log_error("Unhandled request to create data store "
3648 "for property %d (%s) in extviewer_new().",
3650 break;
3651 }
3652
3653 ev->store = store;
3654 ev->textbuf = textbuf;
3655
3656 /* Create the view widget. */
3657
3659 ev->view_widget = vbox;
3660
3664 gtk_box_append(GTK_BOX(vbox), label);
3665 ev->view_label = label;
3666
3667 if (store || textbuf) {
3670 TRUE);
3675
3676 if (store) {
3680 } else {
3681 const bool editable = !objprop_is_readonly(op);
3682
3686 }
3689
3691 }
3692
3693 switch (propid) {
3694
3695 case OPID_TILE_SPECIALS:
3696 case OPID_TILE_ROADS:
3697 case OPID_TILE_BASES:
3698 /* TRANS: As in "this tile special is present". */
3699 add_column(view, 0, _("Present"), G_TYPE_BOOLEAN, TRUE, FALSE,
3701 add_column(view, 1, _("ID"), G_TYPE_INT,
3702 FALSE, FALSE, NULL, NULL);
3703 add_column(view, 2, _("Name"), G_TYPE_STRING,
3704 FALSE, FALSE, NULL, NULL);
3705 break;
3706
3707 case OPID_TILE_VISION:
3708 add_column(view, 0, _("ID"), G_TYPE_INT,
3709 FALSE, FALSE, NULL, NULL);
3710 add_column(view, 1, _("Nation"), GDK_TYPE_PIXBUF,
3711 FALSE, FALSE, NULL, NULL);
3712 add_column(view, 2, _("Name"), G_TYPE_STRING,
3713 FALSE, FALSE, NULL, NULL);
3714 add_column(view, 3, _("Known"), G_TYPE_BOOLEAN,
3715 FALSE, FALSE, NULL, NULL);
3720 break;
3721
3723 /* TRANS: As in "this building is present". */
3724 add_column(view, 0, _("Present"), G_TYPE_BOOLEAN, TRUE, FALSE,
3726 add_column(view, 1, _("ID"), G_TYPE_INT,
3727 FALSE, FALSE, NULL, NULL);
3728 add_column(view, 2, _("Name"), G_TYPE_STRING,
3729 FALSE, FALSE, NULL, NULL);
3730 /* TRANS: As in "the turn when this building was built". */
3731 add_column(view, 3, _("Turn Built"), G_TYPE_STRING,
3732 FALSE, FALSE, NULL, NULL);
3733 break;
3734
3736 /* TRANS: As in "the player has set this nation". */
3737 add_column(view, 0, _("Set"), G_TYPE_BOOLEAN, TRUE, FALSE,
3739 add_column(view, 1, _("ID"), G_TYPE_INT,
3740 FALSE, FALSE, NULL, NULL);
3741 add_column(view, 2, _("Flag"), GDK_TYPE_PIXBUF,
3742 FALSE, FALSE, NULL, NULL);
3743 add_column(view, 3, _("Name"), G_TYPE_STRING,
3744 FALSE, FALSE, NULL, NULL);
3745 break;
3746
3747 case OPID_PLAYER_NATION:
3748 case OPID_PLAYER_GOV:
3749 /* TRANS: As in "the player has set this nation". */
3750 add_column(view, 0, _("Set"), G_TYPE_BOOLEAN, TRUE, TRUE,
3752 add_column(view, 1, _("ID"), G_TYPE_INT,
3753 FALSE, FALSE, NULL, NULL);
3754 add_column(view, 2,
3755 propid == OPID_PLAYER_GOV ? _("Icon") : _("Flag"),
3757 FALSE, FALSE, NULL, NULL);
3758 add_column(view, 3, _("Name"), G_TYPE_STRING,
3759 FALSE, FALSE, NULL, NULL);
3760 break;
3761
3763 /* TRANS: As in "this invention is known". */
3764 add_column(view, 0, _("Known"), G_TYPE_BOOLEAN, TRUE, FALSE,
3766 add_column(view, 1, _("ID"), G_TYPE_INT,
3767 FALSE, FALSE, NULL, NULL);
3768 add_column(view, 2, _("Name"), G_TYPE_STRING,
3769 FALSE, FALSE, NULL, NULL);
3770 break;
3771
3774 g_signal_connect(textbuf, "changed",
3776 break;
3777
3778 default:
3779 log_error("Unhandled request to configure view widget "
3780 "for property %d (%s) in extviewer_new().",
3782 break;
3783 }
3784
3785 gtk_widget_set_visible(ev->panel_widget, TRUE);
3786 gtk_widget_set_visible(ev->view_widget, TRUE);
3787
3788 return ev;
3789}
3790
3791/************************************************************************/
3795{
3796 if (!ev) {
3797 return NULL;
3798 }
3799 return ev->objprop;
3800}
3801
3802/************************************************************************/
3807{
3808 if (!ev) {
3809 return NULL;
3810 }
3811 return ev->panel_widget;
3812}
3813
3814/************************************************************************/
3819{
3820 if (!ev) {
3821 return NULL;
3822 }
3823 return ev->view_widget;
3824}
3825
3826/************************************************************************/
3830 struct propval *pv)
3831{
3832 struct objprop *op;
3834 int id, turn_built;
3835 bool present, all;
3836 const char *name;
3838 GtkListStore *store;
3839 GtkTextBuffer *textbuf;
3841 gchar *buf;
3842
3843 if (!ev) {
3844 return;
3845 }
3846
3849
3850 if (propval_equal(pv, ev->pv_cached)) {
3851 return;
3852 }
3853 propval_free(ev->pv_cached);
3854 ev->pv_cached = propval_copy(pv);
3855 store = ev->store;
3856 textbuf = ev->textbuf;
3857
3858
3859 /* NB: Remember to have -1 as the last argument to
3860 * gtk_list_store_set() and to use the correct column
3861 * number when inserting data. :) */
3862 switch (propid) {
3863
3864 case OPID_TILE_SPECIALS:
3865 gtk_list_store_clear(store);
3867 id = spe->data.special_idx;
3869 present = BV_ISSET(pv->data.v_bv_special, id);
3870 gtk_list_store_append(store, &iter);
3871 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3874 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3875 g_free(buf);
3876 break;
3877
3878 case OPID_TILE_ROADS:
3879 gtk_list_store_clear(store);
3881 struct road_type *proad = extra_road_get(pextra);
3882
3883 id = road_number(proad);
3884 name = extra_name_translation(pextra);
3885 present = BV_ISSET(pv->data.v_bv_roads, id);
3886 gtk_list_store_append(store, &iter);
3887 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3890 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3891 g_free(buf);
3892 break;
3893
3894 case OPID_TILE_BASES:
3895 gtk_list_store_clear(store);
3897 struct base_type *pbase = extra_base_get(pextra);
3898
3899 id = base_number(pbase);
3900 name = extra_name_translation(pextra);
3901 present = BV_ISSET(pv->data.v_bv_bases, id);
3902 gtk_list_store_append(store, &iter);
3903 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3906 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3907 g_free(buf);
3908 break;
3909
3910 case OPID_TILE_VISION:
3911 gtk_list_store_clear(store);
3912 player_slots_iterate(pslot) {
3913 id = player_slot_index(pslot);
3914 if (player_slot_is_used(pslot)) {
3915 struct player *pplayer = player_slot_get_player(pslot);
3916
3917 name = player_name(pplayer);
3918 pixbuf = get_flag(pplayer->nation);
3919 } else {
3920 name = "";
3921 pixbuf = NULL;
3922 }
3923 gtk_list_store_append(store, &iter);
3924 gtk_list_store_set(store, &iter, 0, id, 2, name, -1);
3925 if (pixbuf) {
3926 gtk_list_store_set(store, &iter, 1, pixbuf, -1);
3928 pixbuf = NULL;
3929 }
3930 present = BV_ISSET(pv->data.v_tile_vision->tile_known, id);
3931 gtk_list_store_set(store, &iter, 3, present, -1);
3933 present = BV_ISSET(pv->data.v_tile_vision->tile_seen[v], id);
3934 gtk_list_store_set(store, &iter, 4 + v, present, -1);
3937 break;
3938
3940 gtk_list_store_clear(store);
3941 gtk_list_store_append(store, &iter);
3942 all = (0 == nation_hash_size(pv->data.v_nation_hash));
3943 gtk_list_store_set(store, &iter, 0, all, 1, -1, 3,
3944 _("All nations"), -1);
3945 nations_iterate(pnation) {
3947 && is_nation_playable(pnation)) {
3948 present = (!all && nation_hash_lookup(pv->data.v_nation_hash,
3949 pnation, NULL));
3950 id = nation_number(pnation);
3951 pixbuf = get_flag(pnation);
3953 gtk_list_store_append(store, &iter);
3954 gtk_list_store_set(store, &iter, 0, present, 1, id,
3955 2, pixbuf, 3, name, -1);
3956 if (pixbuf) {
3958 }
3959 }
3962 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3963 g_free(buf);
3964 break;
3965
3967 gtk_list_store_clear(store);
3968 improvement_iterate(pimprove) {
3969 if (is_special_improvement(pimprove)) {
3970 continue;
3971 }
3972 id = improvement_index(pimprove);
3974 turn_built = pv->data.v_built[id].turn;
3975 present = turn_built >= 0;
3976 buf = built_status_to_string(&pv->data.v_built[id]);
3977 gtk_list_store_append(store, &iter);
3978 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name,
3979 3, buf, -1);
3980 g_free(buf);
3983 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3984 g_free(buf);
3985 break;
3986
3987 case OPID_PLAYER_NATION:
3988 {
3989 enum barbarian_type barbarian_type
3990 = nation_barbarian_type(pv->data.v_nation);
3991
3992 gtk_list_store_clear(store);
3993 nations_iterate(pnation) {
3995 && nation_barbarian_type(pnation) == barbarian_type
3996 && (barbarian_type != NOT_A_BARBARIAN
3997 || is_nation_playable(pnation))) {
3998 present = (pnation == pv->data.v_nation);
3999 id = nation_index(pnation);
4000 pixbuf = get_flag(pnation);
4002 gtk_list_store_append(store, &iter);
4003 gtk_list_store_set(store, &iter, 0, present, 1, id,
4004 2, pixbuf, 3, name, -1);
4005 if (pixbuf) {
4007 }
4008 }
4010 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4011 nation_adjective_translation(pv->data.v_nation));
4012 pixbuf = get_flag(pv->data.v_nation);
4014 if (pixbuf) {
4016 }
4017 }
4018 break;
4019
4020 case OPID_PLAYER_GOV:
4021 {
4022 gtk_list_store_clear(store);
4024 present = (pgov == pv->data.v_gov);
4025 id = government_index(pgov);
4028 gtk_list_store_append(store, &iter);
4029 gtk_list_store_set(store, &iter, 0, present, 1, id,
4030 2, pixbuf, 3, name, -1);
4031 if (pixbuf) {
4033 }
4035 if (pv->data.v_gov != NULL) {
4036 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4037 government_name_translation(pv->data.v_gov));
4039 } else {
4040 gtk_label_set_text(GTK_LABEL(ev->panel_label), "?");
4043 }
4044
4046 if (pixbuf) {
4048 }
4049 }
4050 break;
4051
4053 gtk_list_store_clear(store);
4055 id = advance_index(padvance);
4056 present = BV_ISSET(pv->data.v_bv_inventions, id);
4058 gtk_list_store_append(store, &iter);
4059 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
4062 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4063 g_free(buf);
4064 break;
4065
4070 {
4071 GtkTextIter start, end;
4072 char *oldtext;
4073
4074 /* Don't re-set content if unchanged, to avoid moving cursor */
4075 gtk_text_buffer_get_bounds(textbuf, &start, &end);
4076 oldtext = gtk_text_buffer_get_text(textbuf, &start, &end, TRUE);
4077 if (strcmp(oldtext, pv->data.v_const_string) != 0) {
4078 gtk_text_buffer_set_text(textbuf, pv->data.v_const_string, -1);
4079 }
4080 }
4083 gtk_widget_set_sensitive(ev->view_widget, TRUE);
4085 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4086 g_free(buf);
4087 break;
4088
4089 default:
4090 log_error("Unhandled request to refresh widgets "
4091 "extviewer_refresh_widgets() for objprop id=%d "
4092 "name \"%s\".", propid, objprop_get_name(op));
4093 break;
4094 }
4095}
4096
4097/************************************************************************/
4101{
4102 struct objprop *op;
4104
4105 if (!ev) {
4106 return;
4107 }
4108
4111
4112 propval_free(ev->pv_cached);
4113 ev->pv_cached = NULL;
4114
4115 if (ev->panel_label != NULL) {
4116 gtk_label_set_text(GTK_LABEL(ev->panel_label), NULL);
4117 }
4118
4119 switch (propid) {
4120 case OPID_TILE_SPECIALS:
4121 case OPID_TILE_ROADS:
4122 case OPID_TILE_BASES:
4123 case OPID_TILE_VISION:
4127 gtk_list_store_clear(ev->store);
4128 break;
4129 case OPID_PLAYER_NATION:
4130 case OPID_PLAYER_GOV:
4131 gtk_list_store_clear(ev->store);
4133 break;
4138 gtk_text_buffer_set_text(ev->textbuf, "", -1);
4141 gtk_widget_set_sensitive(ev->view_widget, FALSE);
4142 break;
4143 default:
4144 log_error("Unhandled request to clear widgets "
4145 "in extviewer_clear_widgets() for objprop id=%d "
4146 "name \"%s\".", propid, objprop_get_name(op));
4147 break;
4148 }
4149}
4150
4151/************************************************************************/
4157{
4158 struct extviewer *ev;
4159 struct property_page *pp;
4160 struct objprop *op;
4161
4162 ev = userdata;
4163 if (!ev) {
4164 return;
4165 }
4166
4170}
4171
4172/************************************************************************/
4176 gchar *path,
4178{
4179 struct extviewer *ev;
4180 struct objprop *op;
4181 struct property_page *pp;
4183 GtkTreeModel *model;
4185 int id, old_id, turn_built;
4186 struct propval *pv;
4187 bool active, present;
4188 gchar *buf;
4190
4191 ev = userdata;
4192 if (!ev) {
4193 return;
4194 }
4195
4196 pv = ev->pv_cached;
4197 if (!pv) {
4198 return;
4199 }
4200
4205
4206 model = GTK_TREE_MODEL(ev->store);
4207 if (!gtk_tree_model_get_iter_from_string(model, &iter, path)) {
4208 return;
4209 }
4210 present = !active;
4211
4212
4213 switch (propid) {
4214
4215 case OPID_TILE_SPECIALS:
4216 gtk_tree_model_get(model, &iter, 1, &id, -1);
4218 return;
4219 }
4220 if (present) {
4221 BV_SET(pv->data.v_bv_special, id);
4222 } else {
4223 BV_CLR(pv->data.v_bv_special, id);
4224 }
4225 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4227 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4228 g_free(buf);
4229 break;
4230
4231 case OPID_TILE_ROADS:
4232 gtk_tree_model_get(model, &iter, 1, &id, -1);
4233 if (!(0 <= id && id < road_count())) {
4234 return;
4235 }
4236 if (present) {
4237 BV_SET(pv->data.v_bv_roads, id);
4238 } else {
4239 BV_CLR(pv->data.v_bv_roads, id);
4240 }
4241 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4243 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4244 g_free(buf);
4245 break;
4246
4247 case OPID_TILE_BASES:
4248 gtk_tree_model_get(model, &iter, 1, &id, -1);
4249 if (!(0 <= id && id < base_count())) {
4250 return;
4251 }
4252 if (present) {
4253 BV_SET(pv->data.v_bv_bases, id);
4254 } else {
4255 BV_CLR(pv->data.v_bv_bases, id);
4256 }
4257 gtk_list_store_set(ev->store, &iter, 0, present, -1);
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 (-1 > id && id >= nation_count()) {
4266 return;
4267 }
4268
4269 if (-1 == id) {
4270 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4272 if (present) {
4273 while (gtk_tree_model_iter_next(model, &iter)) {
4274 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4275 }
4276 nation_hash_clear(pv->data.v_nation_hash);
4277 } else {
4278 const struct nation_type *pnation;
4279 int id2;
4280
4282 gtk_tree_model_get(model, &iter, 0, &id2, -1);
4283 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4284 pnation = nation_by_number(id2);
4285 nation_hash_insert(pv->data.v_nation_hash, pnation, NULL);
4286 }
4287 } else {
4288 const struct nation_type *pnation;
4289 bool all;
4290
4291 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4292 pnation = nation_by_number(id);
4293 if (present) {
4294 nation_hash_insert(pv->data.v_nation_hash, pnation, NULL);
4295 } else {
4296 nation_hash_remove(pv->data.v_nation_hash, pnation);
4297 }
4299 all = (0 == nation_hash_size(pv->data.v_nation_hash));
4300 gtk_list_store_set(ev->store, &iter, 0, all, -1);
4301 }
4303 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4304 g_free(buf);
4305 break;
4306
4308 gtk_tree_model_get(model, &iter, 1, &id, -1);
4309 if (!(0 <= id && id < B_LAST)) {
4310 return;
4311 }
4312 turn_built = present ? game.info.turn : I_NEVER;
4313 pv->data.v_built[id].turn = turn_built;
4314 buf = built_status_to_string(&pv->data.v_built[id]);
4315 gtk_list_store_set(ev->store, &iter, 0, present, 3, buf, -1);
4316 g_free(buf);
4318 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4319 g_free(buf);
4320 break;
4321
4322 case OPID_PLAYER_NATION:
4323 gtk_tree_model_get(model, &iter, 1, &id, -1);
4324 if (!(0 <= id && id < nation_count()) || !present) {
4325 return;
4326 }
4327 old_id = nation_index(pv->data.v_nation);
4328 pv->data.v_nation = nation_by_number(id);
4329 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4331 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4332 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4333 nation_adjective_translation(pv->data.v_nation));
4334 pixbuf = get_flag(pv->data.v_nation);
4336 if (pixbuf) {
4338 }
4339 break;
4340
4341 case OPID_PLAYER_GOV:
4342 gtk_tree_model_get(model, &iter, 1, &id, -1);
4343 if (!(0 <= id && id < government_count()) || !present) {
4344 return;
4345 }
4346 if (pv->data.v_gov != NULL) {
4347 old_id = government_index(pv->data.v_gov);
4348 pv->data.v_gov = government_by_number(id);
4349 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4351 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4352 } else {
4353 pv->data.v_gov = government_by_number(id);
4354 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4355 }
4356
4357 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4358 government_name_translation(pv->data.v_gov));
4361 if (pixbuf) {
4363 }
4364 break;
4365
4367 gtk_tree_model_get(model, &iter, 1, &id, -1);
4368 if (!(A_FIRST <= id && id < advance_count())) {
4369 return;
4370 }
4371 if (present) {
4372 BV_SET(pv->data.v_bv_inventions, id);
4373 } else {
4374 BV_CLR(pv->data.v_bv_inventions, id);
4375 }
4376 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4378 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4379 g_free(buf);
4380 break;
4381
4382 default:
4383 log_error("Unhandled widget toggled signal in "
4384 "extviewer_view_cell_toggled() for objprop id=%d "
4385 "name \"%s\".", propid, objprop_get_name(op));
4386 return;
4387 break;
4388 }
4389
4391}
4392
4393/************************************************************************/
4398{
4399 struct extviewer *ev;
4400 struct objprop *op;
4401 struct property_page *pp;
4403 struct propval value = {{0,}, VALTYPE_STRING, FALSE}, *pv;
4404 GtkTextIter start, end;
4405 char *text;
4406 gchar *buf;
4407
4408 ev = userdata;
4409 if (!ev) {
4410 return;
4411 }
4412
4416
4417 gtk_text_buffer_get_start_iter(textbuf, &start);
4418 gtk_text_buffer_get_end_iter(textbuf, &end);
4419 text = gtk_text_buffer_get_text(textbuf, &start, &end, FALSE);
4420 value.data.v_const_string = text;
4421 pv = &value;
4422
4423 switch (propid) {
4427 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4428 g_free(buf);
4429 break;
4430 default:
4431 log_error("Unhandled widget modified signal in "
4432 "extviewer_textbuf_changed() for objprop id=%d "
4433 "name \"%s\".", propid, objprop_get_name(op));
4434 return;
4435 break;
4436 }
4437
4439 g_free(text);
4440}
4441
4442/************************************************************************/
4446{
4447#define ADDPROP(ARG_id, ARG_name, ARG_tooltip, ARG_flags, ARG_valtype) do { \
4448 struct objprop *MY_op = objprop_new(ARG_id, ARG_name, ARG_tooltip, \
4449 ARG_flags, ARG_valtype, pp); \
4450 objprop_hash_insert(pp->objprop_table, MY_op->id, MY_op); \
4451} while (FALSE)
4452
4453 switch (property_page_get_objtype(pp)) {
4454 case OBJTYPE_TILE:
4455 ADDPROP(OPID_TILE_IMAGE, _("Image"), NULL,
4457 ADDPROP(OPID_TILE_TERRAIN, _("Terrain"), NULL,
4459 ADDPROP(OPID_TILE_RESOURCE, _("Resource"), NULL,
4461 ADDPROP(OPID_TILE_INDEX, _("Index"), NULL,
4463 ADDPROP(OPID_TILE_X, Q_("?coordinate:X"), NULL,
4465 ADDPROP(OPID_TILE_Y, Q_("?coordinate:Y"), NULL,
4467 /* TRANS: The coordinate X in native coordinates.
4468 * The freeciv coordinate system is described in doc/HACKING. */
4469 ADDPROP(OPID_TILE_NAT_X, _("NAT X"), NULL,
4471 /* TRANS: The coordinate Y in native coordinates.
4472 * The freeciv coordinate system is described in doc/HACKING. */
4473 ADDPROP(OPID_TILE_NAT_Y, _("NAT Y"), NULL,
4475 ADDPROP(OPID_TILE_CONTINENT, _("Continent"), NULL,
4477 ADDPROP(OPID_TILE_XY, Q_("?coordinates:X,Y"), NULL,
4479 ADDPROP(OPID_TILE_SPECIALS, _("Specials"), NULL,
4482 ADDPROP(OPID_TILE_ROADS, _("Roads"), NULL,
4485 ADDPROP(OPID_TILE_BASES, _("Bases"), NULL,
4488#ifdef FREECIV_DEBUG
4489 ADDPROP(OPID_TILE_ADDRESS, _("Address"), NULL,
4491#endif /* FREECIV_DEBUG */
4492#if 0
4493 /* Disabled entirely for now as server is not sending other
4494 * players' vision information anyway. */
4495 ADDPROP(OPID_TILE_VISION, _("Vision"), NULL,
4497#endif
4498 /* TRANS: Tile property "Label" label in editor */
4499 ADDPROP(OPID_TILE_LABEL, Q_("?property:Label"), NULL,
4501 return;
4502
4503 case OBJTYPE_STARTPOS:
4504 ADDPROP(OPID_STARTPOS_IMAGE, _("Image"), NULL,
4506 ADDPROP(OPID_STARTPOS_XY, Q_("?coordinates:X,Y"), NULL,
4508 ADDPROP(OPID_STARTPOS_EXCLUDE, _("Exclude Nations"), NULL,
4510 ADDPROP(OPID_STARTPOS_NATIONS, _("Nations"), NULL,
4513 return;
4514
4515 case OBJTYPE_UNIT:
4516 ADDPROP(OPID_UNIT_IMAGE, _("Image"), NULL,
4518#ifdef FREECIV_DEBUG
4519 ADDPROP(OPID_UNIT_ADDRESS, _("Address"), NULL,
4521#endif /* FREECIV_DEBUG */
4522 ADDPROP(OPID_UNIT_TYPE, _("Type"), NULL,
4524 ADDPROP(OPID_UNIT_ID, _("ID"), NULL,
4526 ADDPROP(OPID_UNIT_XY, Q_("?coordinates:X,Y"), NULL,
4528 ADDPROP(OPID_UNIT_MOVES_LEFT, _("Moves Left"), NULL,
4530 ADDPROP(OPID_UNIT_FUEL, _("Fuel"), NULL,
4532 ADDPROP(OPID_UNIT_MOVED, _("Moved"), NULL,
4534 ADDPROP(OPID_UNIT_DONE_MOVING, _("Done Moving"), NULL,
4536 /* TRANS: HP = Hit Points of a unit. */
4537 ADDPROP(OPID_UNIT_HP, _("HP"), NULL,
4539 ADDPROP(OPID_UNIT_VETERAN, _("Veteran"), NULL,
4541 ADDPROP(OPID_UNIT_STAY, _("Stay put"), NULL,
4543 return;
4544
4545 case OBJTYPE_CITY:
4546 ADDPROP(OPID_CITY_IMAGE, _("Image"), NULL,
4548 ADDPROP(OPID_CITY_NAME, _("Name"), NULL,
4550#ifdef FREECIV_DEBUG
4551 ADDPROP(OPID_CITY_ADDRESS, _("Address"), NULL,
4553#endif /* FREECIV_DEBUG */
4554 ADDPROP(OPID_CITY_ID, _("ID"), NULL,
4556 ADDPROP(OPID_CITY_XY, Q_("?coordinates:X,Y"), NULL,
4558 ADDPROP(OPID_CITY_SIZE, _("Size"), NULL,
4560 ADDPROP(OPID_CITY_HISTORY, _("History"), NULL,
4562 ADDPROP(OPID_CITY_BUILDINGS, _("Buildings"), NULL,
4565 ADDPROP(OPID_CITY_FOOD_STOCK, _("Food Stock"), NULL,
4567 ADDPROP(OPID_CITY_SHIELD_STOCK, _("Shield Stock"), NULL,
4569 return;
4570
4571 case OBJTYPE_PLAYER:
4572 ADDPROP(OPID_PLAYER_NAME, _("Name"), NULL,
4575#ifdef FREECIV_DEBUG
4576 ADDPROP(OPID_PLAYER_ADDRESS, _("Address"), NULL,
4578#endif /* FREECIV_DEBUG */
4579 ADDPROP(OPID_PLAYER_NATION, _("Nation"), NULL,
4582 ADDPROP(OPID_PLAYER_GOV, _("Government"), NULL,
4584 VALTYPE_GOV);
4585 ADDPROP(OPID_PLAYER_AGE, _("Age"), NULL,
4587 ADDPROP(OPID_PLAYER_INVENTIONS, _("Inventions"), NULL,
4592 ADDPROP(OPID_PLAYER_SELECT_WEIGHT, _("Select Weight"),
4593 _("How likely user is to get this player by autoselect. '-1' for default behavior."),
4595 VALTYPE_INT);
4596 ADDPROP(OPID_PLAYER_SCIENCE, _("Science"), NULL,
4598 ADDPROP(OPID_PLAYER_GOLD, _("Gold"), NULL,
4600 VALTYPE_INT);
4601 ADDPROP(OPID_PLAYER_INFRAPOINTS, _("Infrapoints"), NULL,
4603 VALTYPE_INT);
4604 return;
4605
4606 case OBJTYPE_GAME:
4607 ADDPROP(OPID_GAME_SCENARIO, _("Scenario"), NULL,
4609 VALTYPE_BOOL);
4611 _("Scenario Name"), NULL,
4615 _("Scenario Authors"), NULL,
4619 _("Scenario Description"), NULL,
4623 _("Save Random Number State"), NULL,
4626 _("Save Players"), NULL,
4629 _("Nation Start Positions"), NULL,
4632 _("Prevent New Cities"), NULL,
4635 _("Saltwater Flooding Lakes"), NULL,
4638 _("Lock to current Ruleset"), NULL,
4640 return;
4641
4642 case NUM_OBJTYPES:
4643 break;
4644 }
4645
4646 log_error("%s(): Unhandled page object type %s (nb %d).", __FUNCTION__,
4649#undef ADDPROP
4650}
4651
4652/************************************************************************/
4675
4676/************************************************************************/
4681 GtkTreeModel *model,
4684 gpointer data)
4685{
4686 struct property_page *pp;
4687 struct objbind *ob = NULL, *old_ob;
4689
4690 pp = data;
4691 if (!pp || !sel_path) {
4692 return TRUE;
4693 }
4694
4695 if (!gtk_tree_model_get_iter(model, &iter, sel_path)) {
4696 return TRUE;
4697 }
4698
4700 gtk_tree_model_get(model, &iter, 0, &ob, -1);
4701 if (currently_selected) {
4702 if (ob == old_ob) {
4703 GList *rows, *p;
4704 GtkTreePath *path;
4705 struct objbind *new_ob = NULL;
4706
4708 for (p = rows; p != NULL; p = p->next) {
4709 path = p->data;
4710 if (gtk_tree_model_get_iter(model, &iter, path)) {
4711 struct objbind *test_ob = NULL;
4712 gtk_tree_model_get(model, &iter, 0, &test_ob, -1);
4713 if (test_ob == ob) {
4714 continue;
4715 }
4716 new_ob = test_ob;
4717 break;
4718 }
4719 }
4722
4724 }
4725 } else {
4727 }
4728
4729 return TRUE;
4730}
4731
4732/************************************************************************/
4737{
4738 struct property_page *pp;
4739 const gchar *text;
4740 GtkWidget *w;
4742 struct property_filter *pf;
4743 bool matched;
4744
4745 pp = userdata;
4747 pf = property_filter_new(text);
4748
4752 continue;
4753 }
4756 if (objprop_has_widget(op) && w != nullptr) {
4758 }
4760 if (objprop_show_in_listview(op) && col != nullptr) {
4762 }
4764
4766}
4767
4768/************************************************************************/
4772static struct property_page *
4774 struct property_editor *pe)
4775{
4776 struct property_page *pp;
4777 GtkWidget *vgrid, *vgrid2, *hgrid, *hgrid2, *paned, *frame, *w;
4778 GtkWidget *scrollwin, *view, *label, *entry, *notebook;
4779 GtkWidget *button, *hsep;
4784 int num_columns = 0;
4786 int col_id = 1;
4787 const char *attr_type_str, *name, *tooltip;
4788 gchar *title;
4789 int grid_row = 0;
4790 int grid2_row = 0;
4791 int grid_col = 0;
4792 int grid2_col = 0;
4793
4794 if (!(objtype < NUM_OBJTYPES)) {
4795 return NULL;
4796 }
4797
4798 pp = fc_calloc(1, sizeof(struct property_page));
4799 pp->objtype = objtype;
4800 pp->pe_parent = pe;
4801
4803
4804 pp->objprop_table = objprop_hash_new();
4806
4807 pp->objbind_table = objbind_hash_new();
4808
4809 pp->tag_table = stored_tag_hash_new();
4810
4813 num_columns++;
4814 }
4816
4817 /* Column zero in the store holds an objbind
4818 * pointer and is never displayed. */
4819 num_columns++;
4822
4827 col_id++;
4828 }
4830
4833
4836 pp->widget = paned;
4837
4838 /* Left side object list view. */
4839
4840 vgrid = gtk_grid_new();
4849
4852 TRUE);
4857
4861
4864 continue;
4865 }
4866
4868 if (!attr_type_str) {
4869 continue;
4870 }
4872 if (col_id < 0) {
4873 continue;
4874 }
4876 if (!name) {
4877 continue;
4878 }
4880 if (!cell) {
4881 continue;
4882 }
4883
4886 NULL);
4887
4891 if (objprop_is_sortable(op)) {
4894 } else {
4896 }
4899
4901
4904 g_signal_connect(sel, "changed",
4908
4910 pp->object_view = view;
4911
4913 hgrid = gtk_grid_new();
4916
4917 button = gtk_button_new();
4918 gtk_button_set_icon_name(GTK_BUTTON(button), "list-add");
4919 gtk_button_set_label(GTK_BUTTON(button), _("Create"));
4922 _("Pressing this button will create a new object of the "
4923 "same type as the current property page and add it to "
4924 "the page. The specific type and count of the objects "
4925 "is taken from the editor tool state. So for example, "
4926 "the \"tool value\" of the unit tool and its \"count\" "
4927 "parameter affect unit creation."));
4928 g_signal_connect(button, "clicked",
4930 gtk_grid_attach(GTK_GRID(hgrid), button, grid_col++, 0, 1, 1);
4931
4932 button = gtk_button_new();
4933 gtk_button_set_icon_name(GTK_BUTTON(button), "list-remove");
4934 gtk_button_set_label(GTK_BUTTON(button), _("Destroy"));
4937 _("Pressing this button will send a request to the server "
4938 "to destroy (i.e. erase) the objects selected in the object "
4939 "list."));
4940 g_signal_connect(button, "clicked",
4942 gtk_grid_attach(GTK_GRID(hgrid), button, grid_col++, 0, 1, 1);
4943 }
4944
4945 /* Right side properties panel. */
4946
4947 hgrid = gtk_grid_new();
4948 grid_col = 0;
4951
4952 vgrid = gtk_grid_new();
4961
4962 /* Extended property viewer to the right of the properties panel.
4963 * This needs to be created before property widgets, since some
4964 * might try to append themselves to this notebook. */
4965
4966 vgrid2 = gtk_grid_new();
4973
4974 notebook = gtk_notebook_new();
4975 gtk_widget_set_vexpand(notebook, TRUE);
4976 gtk_widget_set_size_request(notebook, 256, -1);
4979 gtk_grid_attach(GTK_GRID(vgrid2), notebook, 0, grid2_row++, 1, 1);
4980 pp->extviewer_notebook = notebook;
4981
4984
4985 hgrid2 = gtk_grid_new();
4991
4992 button = gtk_button_new_with_mnemonic(_("_Close"));
4994 g_signal_connect_swapped(button, "clicked",
4995 G_CALLBACK(gtk_window_close), pe->widget);
4996 gtk_grid_attach(GTK_GRID(hgrid2), button, grid2_col++, 0, 1, 1);
4997
4998 /* Now create the properties panel. */
4999
5000 /* TRANS: %s is a type of object that can be edited, such as "Tile",
5001 * "Unit", "Start Position", etc. */
5002 title = g_strdup_printf(_("%s Properties"),
5004 frame = gtk_frame_new(title);
5005 g_free(title);
5006 gtk_widget_set_size_request(frame, 256, -1);
5007 gtk_grid_attach(GTK_GRID(vgrid), frame, 0, grid_row++, 1, 1);
5008
5011 FALSE);
5016
5017 vgrid2 = gtk_grid_new();
5018 grid2_row = 0;
5028
5030 if (!objprop_has_widget(op)) {
5031 continue;
5032 }
5034 if (!w) {
5035 continue;
5036 }
5037 gtk_grid_attach(GTK_GRID(vgrid2), w, 0, grid2_row++, 1, 1);
5039 if (NULL != tooltip) {
5041 }
5043
5044 hgrid2 = gtk_grid_new();
5045 grid2_col = 0;
5050
5051 label = gtk_label_new(_("Filter:"));
5052 gtk_grid_attach(GTK_GRID(hgrid2), label, grid2_col++, 0, 1, 1);
5053
5054 entry = gtk_entry_new();
5056 _("Enter a filter string to limit which properties are shown. "
5057 "The filter is one or more text patterns separated by | "
5058 "(\"or\") or & (\"and\"). The symbol & has higher precedence "
5059 "than |. A pattern may also be negated by prefixing it with !."));
5060 g_signal_connect(entry, "changed",
5063
5064 hgrid2 = gtk_grid_new();
5065 grid2_col = 0;
5068
5069 button = gtk_button_new_with_mnemonic(_("_Refresh"));
5072 _("Pressing this button will reset all modified properties of "
5073 "the selected objects to their current values (the values "
5074 "they have on the server)."));
5075 g_signal_connect(button, "clicked",
5077 gtk_grid_attach(GTK_GRID(hgrid2), button, grid2_col++, 0, 1, 1);
5078
5079 button = gtk_button_new_with_mnemonic(_("_Apply"));
5082 _("Pressing this button will send all modified properties of "
5083 "the objects selected in the object list to the server. "
5084 "Modified properties' names are shown in red in the properties "
5085 "panel."));
5086 g_signal_connect(button, "clicked",
5088 gtk_grid_attach(GTK_GRID(hgrid2), button, grid2_col++, 0, 1, 1);
5089
5090 return pp;
5091}
5092
5093/************************************************************************/
5096static const char *property_page_get_name(const struct property_page *pp)
5097{
5098 if (!pp) {
5099 return "";
5100 }
5102}
5103
5104/************************************************************************/
5107static enum editor_object_type
5109{
5110 if (!pp) {
5111 return -1;
5112 }
5113 return pp->objtype;
5114}
5115
5116/************************************************************************/
5124static GdkPixbuf *create_tile_pixbuf(const struct tile *ptile)
5125{
5127}
5128
5129/************************************************************************/
5140
5141/************************************************************************/
5153
5154/************************************************************************/
5162static GdkPixbuf *create_pixbuf_from_layers(const struct tile *ptile,
5163 const struct unit *punit,
5164 const struct city *pcity,
5165 enum layer_category category)
5166{
5168 int h, fh, fw, canvas_x, canvas_y;
5170 cairo_t *cr;
5171
5175
5177
5180 cairo_paint(cr);
5181 cairo_destroy(cr);
5182
5183 canvas_x = 0;
5184 canvas_y = 0;
5185
5186 canvas_y += (fh - h);
5187
5188 mapview_layer_iterate(layer) {
5189 if (tileset_layer_in_category(layer, category)) {
5190 put_one_element(&canvas, 1.0, layer,
5191 ptile, NULL, NULL, punit, pcity,
5193 }
5197
5198 return pixbuf;
5199}
5200
5201/************************************************************************/
5205{
5206 if (!pp) {
5207 return;
5208 }
5209
5210 gtk_list_store_clear(pp->object_store);
5211 objbind_hash_clear(pp->objbind_table);
5213}
5214
5215/************************************************************************/
5221{
5222 struct objbind *ob;
5224 int id;
5225
5226 if (!pp) {
5227 return;
5228 }
5229
5232 if (id < 0) {
5233 return;
5234 }
5235
5236 if (objbind_hash_lookup(pp->objbind_table, id, NULL)) {
5237 /* Object already exists. */
5238 return;
5239 }
5240
5242 if (!ob) {
5243 return;
5244 }
5245
5247
5248 objbind_hash_insert(pp->objbind_table, ob->object_id, ob);
5249}
5250
5251/************************************************************************/
5256 const struct tile *ptile)
5257{
5258
5259 if (!pp || !ptile) {
5260 return;
5261 }
5262
5263 switch (property_page_get_objtype(pp)) {
5264 case OBJTYPE_TILE:
5266 return;
5267
5268 case OBJTYPE_STARTPOS:
5269 {
5270 struct startpos *psp = map_startpos_get(ptile);
5271
5272 if (NULL != psp) {
5274 }
5275 }
5276 return;
5277
5278 case OBJTYPE_UNIT:
5279 unit_list_iterate(ptile->units, punit) {
5282 return;
5283
5284 case OBJTYPE_CITY:
5285 if (tile_city(ptile)) {
5287 }
5288 return;
5289
5290 case OBJTYPE_PLAYER:
5291 case OBJTYPE_GAME:
5292 return;
5293
5294 case NUM_OBJTYPES:
5295 break;
5296 }
5297
5298 log_error("%s(): Unhandled page object type %s (nb %d).", __FUNCTION__,
5301}
5302
5303/************************************************************************/
5310 struct objprop *op,
5311 struct objbind *ob,
5313{
5314 int col_id;
5315 struct propval *pv;
5316 enum value_types valtype;
5317 char buf[128], *p;
5319 GtkListStore *store;
5320 gchar *buf2;
5321
5322 if (!pp || !pp->object_store || !op || !ob) {
5323 return FALSE;
5324 }
5325
5327 return FALSE;
5328 }
5329
5331 if (col_id < 0) {
5332 return FALSE;
5333 }
5334
5336 if (!pv) {
5337 return FALSE;
5338 }
5339
5341 store = pp->object_store;
5342
5343 switch (valtype) {
5344 case VALTYPE_NONE:
5345 break;
5346 case VALTYPE_INT:
5347 gtk_list_store_set(store, iter, col_id, pv->data.v_int, -1);
5348 break;
5349 case VALTYPE_BOOL:
5350 /* Set as translated string, not as untranslated G_TYPE_BOOLEAN */
5352 break;
5353 case VALTYPE_STRING:
5354 if (fc_strlcpy(buf, pv->data.v_string, 28) >= 28) {
5355 sz_strlcat(buf, "...");
5356 }
5357 for (p = buf; *p; p++) {
5358 if (*p == '\n' || *p == '\t' || *p == '\r') {
5359 *p = ' ';
5360 }
5361 }
5362 gtk_list_store_set(store, iter, col_id, buf, -1);
5363 break;
5364 case VALTYPE_PIXBUF:
5365 gtk_list_store_set(store, iter, col_id, pv->data.v_pixbuf, -1);
5366 break;
5369 case VALTYPE_BV_SPECIAL:
5370 case VALTYPE_BV_ROADS:
5371 case VALTYPE_BV_BASES:
5374 gtk_list_store_set(store, iter, col_id, buf2, -1);
5375 g_free(buf2);
5376 break;
5377 case VALTYPE_NATION:
5378 pixbuf = get_flag(pv->data.v_nation);
5379 gtk_list_store_set(store, iter, col_id, pixbuf, -1);
5380 if (pixbuf) {
5382 }
5383 break;
5384 case VALTYPE_GOV:
5385 if (pv->data.v_gov != NULL) {
5387 } else {
5390 }
5391 gtk_list_store_set(store, iter, col_id, pixbuf, -1);
5392 if (pixbuf) {
5394 }
5395 break;
5397 break;
5398 }
5399
5401
5402 return TRUE;
5403}
5404
5405/************************************************************************/
5410{
5411 struct objbind *focused;
5412
5413 if (!pp || !pp->objbind_table) {
5414 return;
5415 }
5416
5417 if (pp->object_store) {
5420 GtkTreeModel *model;
5421 GtkTreePath *path;
5422
5423 model = GTK_TREE_MODEL(pp->object_store);
5424
5426 if (objbind_get_rowref(ob)) {
5427 continue;
5428 }
5429 gtk_list_store_append(pp->object_store, &iter);
5430 gtk_list_store_set(pp->object_store, &iter, 0, ob, -1);
5431 path = gtk_tree_model_get_path(model, &iter);
5432 rr = gtk_tree_row_reference_new(model, path);
5433 gtk_tree_path_free(path);
5435
5440
5441 if (gtk_tree_model_get_iter_first(model, &iter)) {
5443
5446 }
5447 }
5448
5453}
5454
5455/************************************************************************/
5460{
5461 if (!pp) {
5462 return NULL;
5463 }
5464 return pp->focused_objbind;
5465}
5466
5467/************************************************************************/
5472 struct objbind *ob)
5473{
5474 if (!pp) {
5475 return;
5476 }
5477 pp->focused_objbind = ob;
5478}
5479
5480/************************************************************************/
5485 int object_id)
5486{
5487 struct objbind *ob;
5488
5489 if (!pp || !pp->objbind_table) {
5490 return NULL;
5491 }
5492
5493 objbind_hash_lookup(pp->objbind_table, object_id, &ob);
5494 return ob;
5495}
5496
5497/************************************************************************/
5502 const struct tile_list *tiles)
5503{
5504 if (!pp || !tiles) {
5505 return;
5506 }
5507
5508 tile_list_iterate(tiles, ptile) {
5511
5513}
5514
5515/************************************************************************/
5519{
5520 if (!pp || !pp->objbind_table) {
5521 return 0;
5522 }
5523 return objbind_hash_size(pp->objbind_table);
5524}
5525
5526/************************************************************************/
5531 struct objprop *op,
5532 struct propval *pv)
5533{
5535 GtkTreeModel *model;
5536 GList *rows, *p;
5537 GtkTreePath *path;
5539 struct objbind *ob;
5540 bool changed = FALSE;
5541
5542 if (!pp || !op || !pp->object_view) {
5543 return;
5544 }
5545
5546 if (objprop_is_readonly(op)) {
5547 return;
5548 }
5549
5552
5553 for (p = rows; p != NULL; p = p->next) {
5554 path = p->data;
5555 if (gtk_tree_model_get_iter(model, &iter, path)) {
5556 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5557 changed |= objbind_set_modified_value(ob, op, pv);
5558 }
5559 gtk_tree_path_free(path);
5560 }
5562
5563 if (changed) {
5566 }
5567}
5568
5569/************************************************************************/
5573{
5575 GtkTreeModel *model;
5576 GList *rows, *p;
5577 GtkTreePath *path;
5579 struct objbind *ob;
5580 union packetdata packet;
5581 struct connection *my_conn = &client.conn;
5582
5583 if (!pp || !pp->object_view) {
5584 return;
5585 }
5586
5589 return;
5590 }
5591
5592 packet = property_page_new_packet(pp);
5593 if (!packet.pointers.v_pointer1) {
5594 return;
5595 }
5596
5599 for (p = rows; p != NULL; p = p->next) {
5600 path = p->data;
5601 if (gtk_tree_model_get_iter(model, &iter, path)) {
5602 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5606 if (objprop_is_readonly(op)) {
5607 continue;
5608 }
5612 }
5613 }
5614 gtk_tree_path_free(path);
5615 }
5618
5620}
5621
5622/************************************************************************/
5627{
5628 union packetdata packet;
5629
5630 packet.pointers.v_pointer2 = NULL;
5631
5632 if (!pp) {
5633 packet.pointers.v_pointer1 = NULL;
5634 return packet;
5635 }
5636
5637 switch (property_page_get_objtype(pp)) {
5638 case OBJTYPE_TILE:
5639 packet.tile = fc_calloc(1, sizeof(*packet.tile));
5640 break;
5641 case OBJTYPE_STARTPOS:
5642 packet.startpos = fc_calloc(1, sizeof(*packet.startpos));
5643 break;
5644 case OBJTYPE_UNIT:
5645 packet.unit = fc_calloc(1, sizeof(*packet.unit));
5646 break;
5647 case OBJTYPE_CITY:
5648 packet.city = fc_calloc(1, sizeof(*packet.city));
5649 break;
5650 case OBJTYPE_PLAYER:
5651 packet.player = fc_calloc(1, sizeof(*packet.player));
5652 break;
5653 case OBJTYPE_GAME:
5654 packet.game.game = fc_calloc(1, sizeof(*packet.game.game));
5655 packet.game.desc = fc_calloc(1, sizeof(*packet.game.desc));
5656 break;
5657 case NUM_OBJTYPES:
5658 break;
5659 }
5660
5661 return packet;
5662}
5663
5664/************************************************************************/
5668 union packetdata packet)
5669{
5670 struct connection *my_conn = &client.conn;
5671
5672 if (!pp || !packet.pointers.v_pointer1) {
5673 return;
5674 }
5675
5676 switch (property_page_get_objtype(pp)) {
5677 case OBJTYPE_TILE:
5679 return;
5680 case OBJTYPE_STARTPOS:
5682 return;
5683 case OBJTYPE_UNIT:
5685 return;
5686 case OBJTYPE_CITY:
5688 return;
5689 case OBJTYPE_PLAYER:
5691 return;
5692 case OBJTYPE_GAME:
5693 send_packet_edit_game(my_conn, packet.game.game);
5695 return;
5696 case NUM_OBJTYPES:
5697 break;
5698 }
5699
5700 log_error("%s(): Unhandled object type %s (nb %d).",
5703}
5704
5705/************************************************************************/
5709 union packetdata packet)
5710{
5711 if (!packet.pointers.v_pointer1) {
5712 return;
5713 }
5714
5715 free(packet.pointers.v_pointer1);
5716 packet.pointers.v_pointer1 = NULL;
5717
5718 if (packet.pointers.v_pointer2 != NULL) {
5719 free(packet.pointers.v_pointer2);
5720 packet.pointers.v_pointer2 = NULL;
5721 }
5722}
5723
5724/************************************************************************/
5729{
5731 GtkTreeModel *model;
5733 GtkTreePath *path;
5734 GList *rows, *p;
5735 struct objbind *ob;
5736
5737 if (!pp || !pp->object_view) {
5738 return;
5739 }
5740
5743 return;
5744 }
5745
5747 for (p = rows; p != NULL; p = p->next) {
5748 path = p->data;
5749 if (gtk_tree_model_get_iter(model, &iter, path)) {
5750 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5755 }
5756 gtk_tree_path_free(path);
5757 }
5759
5764}
5765
5766/************************************************************************/
5770{
5772 GtkTreeModel *model;
5774 GtkTreePath *path;
5775 GList *rows, *p;
5776 struct objbind *ob;
5777 struct connection *my_conn = &client.conn;
5778
5779 if (!pp || !pp->object_view) {
5780 return;
5781 }
5782
5785 return;
5786 }
5787
5790 for (p = rows; p != NULL; p = p->next) {
5791 path = p->data;
5792 if (gtk_tree_model_get_iter(model, &iter, path)) {
5793 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5795 }
5796 gtk_tree_path_free(path);
5797 }
5800}
5801
5802/************************************************************************/
5809 struct tile_list *hint_tiles)
5810{
5812 int apno, value, count, size;
5813 int tag;
5814 struct connection *my_conn = &client.conn;
5815 struct tile *ptile = NULL;
5816 struct player *pplayer;
5817
5818 if (!pp) {
5819 return;
5820 }
5821
5824 return;
5825 }
5826
5827 tag = get_next_unique_tag();
5828 count = 1;
5829
5830 switch (objtype) {
5831 case OBJTYPE_STARTPOS:
5832 if (hint_tiles) {
5834 if (NULL == map_startpos_get(atile)) {
5835 ptile = atile;
5836 break;
5837 }
5839 }
5840
5841 if (NULL == ptile) {
5842 ptile = get_center_tile_mapcanvas();
5843 }
5844
5845 if (NULL == ptile) {
5846 break;
5847 }
5848
5850 break;
5851
5852 case OBJTYPE_UNIT:
5853 if (hint_tiles) {
5856 ptile = atile;
5857 break;
5858 }
5860 }
5861
5862 if (!ptile) {
5863 struct unit *punit;
5867 ptile = unit_tile(punit);
5868 break;
5869 }
5871 }
5872
5873 if (!ptile) {
5874 ptile = get_center_tile_mapcanvas();
5875 }
5876
5877 if (!ptile) {
5878 break;
5879 }
5880
5885 value, count, tag);
5886 break;
5887
5888 case OBJTYPE_CITY:
5890 pplayer = player_by_number(apno);
5891 if (pplayer && hint_tiles) {
5893 if (!is_enemy_unit_tile(atile, pplayer)
5895 nullptr, FALSE)) {
5896 ptile = atile;
5897 break;
5898 }
5900 }
5901
5902 if (!ptile) {
5903 ptile = get_center_tile_mapcanvas();
5904 }
5905
5906 if (!ptile) {
5907 break;
5908 }
5909
5912 size, tag);
5913 break;
5914
5915 case OBJTYPE_PLAYER:
5917 break;
5918
5919 case OBJTYPE_TILE:
5920 case OBJTYPE_GAME:
5921 case NUM_OBJTYPES:
5922 break;
5923 }
5924
5926}
5927
5928/************************************************************************/
5934 int object_id,
5935 bool removed)
5936{
5937 struct objbind *ob;
5939
5941 if (!ob) {
5942 return;
5943 }
5944
5947 GtkTreePath *path;
5949 GtkTreeModel *model;
5950
5951 model = GTK_TREE_MODEL(pp->object_store);
5953
5954 if (gtk_tree_model_get_iter(model, &iter, path)) {
5955 if (removed) {
5956 gtk_list_store_remove(pp->object_store, &iter);
5957 } else {
5961 }
5962 }
5963
5964 gtk_tree_path_free(path);
5965 }
5966
5967 if (removed) {
5968 objbind_hash_remove(pp->objbind_table, object_id);
5969 return;
5970 }
5971
5976 }
5977}
5978
5979/************************************************************************/
5986 int tag, int object_id)
5987{
5990
5991 if (!property_page_tag_is_known(pp, tag)) {
5992 return;
5993 }
5995
5998
5999 if (!object) {
6000 return;
6001 }
6002
6005}
6006
6007/************************************************************************/
6012 struct extviewer *ev)
6013{
6014 GtkWidget *w;
6015
6016 if (!pp || !ev) {
6017 return;
6018 }
6019
6021 if (!w) {
6022 return;
6023 }
6024 gtk_notebook_append_page(GTK_NOTEBOOK(pp->extviewer_notebook), w, NULL);
6025}
6026
6027/************************************************************************/
6032 struct extviewer *ev)
6033{
6034 GtkWidget *w;
6035 GtkNotebook *notebook;
6036 int page;
6037
6038 if (!pp || !ev) {
6039 return;
6040 }
6041
6043 if (!w) {
6044 return;
6045 }
6046
6047 notebook = GTK_NOTEBOOK(pp->extviewer_notebook);
6048 page = gtk_notebook_page_num(notebook, w);
6049 gtk_notebook_set_current_page(notebook, page);
6050}
6051
6052/************************************************************************/
6057 int tag, int count)
6058{
6059 if (!pp || !pp->tag_table) {
6060 return;
6061 }
6062
6063 if (stored_tag_hash_lookup(pp->tag_table, tag, NULL)) {
6064 log_error("Attempted to insert object creation tag %d "
6065 "twice into tag table for property page %p (%d %s).",
6068 return;
6069 }
6070
6071 stored_tag_hash_insert(pp->tag_table, tag, count);
6072}
6073
6074/************************************************************************/
6079 int tag)
6080{
6081 int count;
6082
6083 if (!pp || !pp->tag_table) {
6084 return;
6085 }
6086
6087 if (stored_tag_hash_lookup(pp->tag_table, tag, &count)) {
6088 if (0 >= --count) {
6089 stored_tag_hash_remove(pp->tag_table, tag);
6090 }
6091 }
6092}
6093
6094/************************************************************************/
6097static bool property_page_tag_is_known(struct property_page *pp, int tag)
6098{
6099 if (!pp || !pp->tag_table) {
6100 return FALSE;
6101 }
6102 return stored_tag_hash_lookup(pp->tag_table, tag, NULL);
6103}
6104
6105/************************************************************************/
6109{
6110 if (!pp || !pp->tag_table) {
6111 return;
6112 }
6113 stored_tag_hash_clear(pp->tag_table);
6114}
6115
6116/************************************************************************/
6125
6126/************************************************************************/
6136
6137/************************************************************************/
6142{
6143 struct property_page *pp = userdata, *tile_pp;
6144 struct tile_list *tiles = NULL;
6145 struct tile *ptile;
6146
6147 if (!pp) {
6148 return;
6149 }
6150
6152 tiles = tile_list_new();
6153
6155 ptile = objbind_get_object(ob);
6156 if (ptile) {
6157 tile_list_append(tiles, ptile);
6158 }
6160
6162 tile_list_destroy(tiles);
6163}
6164
6165/************************************************************************/
6174
6175/************************************************************************/
6181{
6182 struct property_page *pp;
6183 GtkWidget *label;
6184 const char *name;
6185
6186 if (!pe || !pe->notebook) {
6187 return FALSE;
6188 }
6189
6190 if (!(objtype < NUM_OBJTYPES)) {
6191 return FALSE;
6192 }
6193
6195 if (!pp) {
6196 return FALSE;
6197 }
6198
6200 label = gtk_label_new(name);
6202 pp->widget, label);
6203
6204 pe->property_pages[objtype] = pp;
6205
6206 return TRUE;
6207}
6208
6209/************************************************************************/
6212static struct property_page *
6215{
6216 if (!pe || !(objtype < NUM_OBJTYPES)) {
6217 return NULL;
6218 }
6219
6220 return pe->property_pages[objtype];
6221}
6222
6223/************************************************************************/
6227{
6228 struct property_editor *pe;
6229 GtkWidget *win, *notebook, *vgrid;
6231 int grid_row = 0;
6232
6233 pe = fc_calloc(1, sizeof(*pe));
6234
6235 /* The property editor dialog window. */
6236
6237 win = gtk_window_new();
6238 gtk_window_set_title(GTK_WINDOW(win), _("Property Editor"));
6248 pe->widget = win;
6249
6250 vgrid = gtk_grid_new();
6252
6253 /* Property pages. */
6254
6258 pe->notebook = notebook;
6259
6260 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6262 }
6263
6264 return pe;
6265}
6266
6267/************************************************************************/
6277
6278/************************************************************************/
6282 const struct tile_list *tiles)
6283{
6284 struct property_page *pp;
6286 int i;
6287 const enum editor_object_type preferred[] = {
6292 };
6293
6294 if (!pe || !tiles) {
6295 return;
6296 }
6297
6298 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6301 }
6302
6303 for (i = 0; i < ARRAY_SIZE(preferred) - 1; i++) {
6306 break;
6307 }
6308 }
6309 objtype = preferred[i];
6311}
6312
6313/************************************************************************/
6319{
6320 if (pe == nullptr || pe->widget == nullptr) {
6321 return;
6322 }
6323
6324 gtk_widget_set_visible(pe->widget, TRUE);
6325
6327 if (objtype < NUM_OBJTYPES) {
6329 }
6330}
6331
6332/************************************************************************/
6336{
6337 if (pe == nullptr || pe->widget == nullptr) {
6338 return;
6339 }
6340
6342}
6343
6344/************************************************************************/
6350 int object_id,
6351 bool remove)
6352{
6353 struct property_page *pp;
6354
6355 if (!pe) {
6356 return;
6357 }
6358
6359 if (!(objtype < NUM_OBJTYPES)) {
6360 return;
6361 }
6362
6365}
6366
6367/************************************************************************/
6371 int tag, int object_id)
6372{
6374 struct property_page *pp;
6375
6376 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6378 continue;
6379 }
6381 property_page_object_created(pp, tag, object_id);
6382 }
6383}
6384
6385/************************************************************************/
6389{
6391 struct property_page *pp;
6392
6393 if (!pe) {
6394 return;
6395 }
6396
6397 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6401 }
6402}
6403
6404/************************************************************************/
6410{
6411 struct property_page *pp;
6412
6413 if (!pe) {
6414 return;
6415 }
6416
6418 if (!pp) {
6419 return;
6420 }
6421
6423
6424 switch (objtype) {
6425 case OBJTYPE_PLAYER:
6426 players_iterate(pplayer) {
6427 property_page_add_objbind(pp, pplayer);
6429 break;
6430 case OBJTYPE_GAME:
6432 break;
6433 case OBJTYPE_TILE:
6434 case OBJTYPE_STARTPOS:
6435 case OBJTYPE_UNIT:
6436 case OBJTYPE_CITY:
6437 case NUM_OBJTYPES:
6438 break;
6439 }
6440
6443}
6444
6445/************************************************************************/
6456static struct property_filter *property_filter_new(const char *filter)
6457{
6458 struct property_filter *pf;
6459 struct pf_conjunction *pfc;
6460 struct pf_pattern *pfp;
6463 const char *pattern;
6464 int i, j;
6465
6466 pf = fc_calloc(1, sizeof(*pf));
6467
6468 if (!filter || filter[0] == '\0') {
6469 return pf;
6470 }
6471
6475
6476 for (i = 0; i < or_clause_count; i++) {
6477 if (or_clauses[i][0] == '\0') {
6478 continue;
6479 }
6480 pfc = &pf->disjunction[pf->count];
6481
6485
6486 for (j = 0; j < and_clause_count; j++) {
6487 if (and_clauses[j][0] == '\0') {
6488 continue;
6489 }
6490 pfp = &pfc->conjunction[pfc->count];
6491 pattern = and_clauses[j];
6492
6493 switch (pattern[0]) {
6494 case '!':
6495 pfp->negate = TRUE;
6496 pfp->text = fc_strdup(pattern + 1);
6497 break;
6498 default:
6499 pfp->text = fc_strdup(pattern);
6500 break;
6501 }
6502 pfc->count++;
6503 }
6505 pf->count++;
6506 }
6507
6509
6510 return pf;
6511}
6512
6513/************************************************************************/
6531 const struct objprop *op)
6532{
6533 struct pf_pattern *pfp;
6534 struct pf_conjunction *pfc;
6535 const char *name;
6536 bool match, or_result, and_result;
6537 int i, j;
6538
6539 if (!pf) {
6540 return TRUE;
6541 }
6542 if (!op) {
6543 return FALSE;
6544 }
6545
6547 if (!name) {
6548 return FALSE;
6549 }
6550
6551 if (pf->count < 1) {
6552 return TRUE;
6553 }
6554
6555 or_result = FALSE;
6556
6557 for (i = 0; i < pf->count; i++) {
6558 pfc = &pf->disjunction[i];
6559 and_result = TRUE;
6560 for (j = 0; j < pfc->count; j++) {
6561 pfp = &pfc->conjunction[j];
6562 match = (pfp->text[0] == '\0'
6563 || fc_strcasestr(name, pfp->text));
6564 if (pfp->negate) {
6565 match = !match;
6566 }
6567 and_result = and_result && match;
6568 if (!and_result) {
6569 break;
6570 }
6571 }
6573 if (or_result) {
6574 break;
6575 }
6576 }
6577
6578 return or_result;
6579}
6580
6581/************************************************************************/
6585{
6586 struct pf_pattern *pfp;
6587 struct pf_conjunction *pfc;
6588 int i, j;
6589
6590 if (!pf) {
6591 return;
6592 }
6593
6594 for (i = 0; i < pf->count; i++) {
6595 pfc = &pf->disjunction[i];
6596 for (j = 0; j < pfc->count; j++) {
6597 pfp = &pfc->conjunction[j];
6598 if (pfp->text != NULL) {
6599 free(pfp->text);
6600 pfp->text = NULL;
6601 }
6602 }
6603 pfc->count = 0;
6604 }
6605 pf->count = 0;
6606 free(pf);
6607}
6608
6609/************************************************************************/
6613{
6614 switch (vl) {
6615 case V_MAIN:
6616 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6617 return _("Seen (Main)");
6618 case V_INVIS:
6619 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6620 return _("Seen (Invis)");
6621 case V_SUBSURFACE:
6622 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6623 return _("Seen (Subsurface)");
6624 case V_COUNT:
6625 break;
6626 }
6627
6628 log_error("%s(): Unrecognized vision layer %d.", __FUNCTION__, vl);
6629 return _("Unknown");
6630}
Base_type_id base_number(const struct base_type *pbase)
Definition base.c:96
Base_type_id base_count(void)
Definition base.c:113
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:121
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
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:2132
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:1487
#define city_tile(_pcity_)
Definition city.h:561
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
#define city_owner(_pcity_)
Definition city.h:560
#define MAX_CITY_SIZE
Definition city.h:103
#define I_DESTROYED
Definition city.h:245
#define I_NEVER
Definition city.h:244
struct civclient client
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition climisc.c:1509
char * incite_cost
Definition comments.c:76
void connection_do_buffer(struct connection *pc)
Definition connection.c:324
void connection_do_unbuffer(struct connection *pc)
Definition connection.c:336
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:74
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 int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:249
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_index(_e_)
Definition extras.h:183
#define extra_base_get(_e_)
Definition extras.h:190
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
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:822
#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:61
struct world wld
Definition game.c:62
struct unit * game_unit_by_number(int id)
Definition game.c:115
struct city * game_city_by_number(int id)
Definition game.c:106
const char * government_name_translation(const struct government *pgovern)
Definition government.c:143
Government_type_id government_count(void)
Definition government.c:71
struct government * government_by_number(const Government_type_id gov)
Definition government.c:103
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
#define governments_iterate(NAME_pgov)
Definition government.h:124
#define governments_iterate_end
Definition government.h:127
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
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:820
static void property_page_reset_objbinds(struct property_page *pp)
Definition editprop.c:5705
static void property_page_send_values(struct property_page *pp)
Definition editprop.c:5549
static void objprop_setup_widget(struct objprop *op)
Definition editprop.c:2954
static void property_page_store_creation_tag(struct property_page *pp, int tag, int count)
Definition editprop.c:6032
static gchar * propval_as_string(struct propval *pv)
Definition editprop.c:862
static struct property_page * objprop_get_property_page(const struct objprop *op)
Definition editprop.c:3466
static const char * objprop_get_name(const struct objprop *op)
Definition editprop.c:2834
const char * vision_layer_get_name(enum vision_layer)
Definition editprop.c:6586
static int objbind_get_object_id(struct objbind *ob)
Definition editprop.c:1382
static void objprop_set_extviewer(struct objprop *op, struct extviewer *ev)
Definition editprop.c:3443
static GtkWidget * extviewer_get_panel_widget(struct extviewer *ev)
Definition editprop.c:3798
static gpointer objtype_get_object_from_id(enum editor_object_type objtype, int id)
Definition editprop.c:725
void property_editor_handle_object_changed(struct property_editor *pe, enum editor_object_type objtype, int object_id, bool remove)
Definition editprop.c:6322
static struct propstate * propstate_new(struct objprop *op, struct propval *pv)
Definition editprop.c:1266
static const char * valtype_get_name(enum value_types valtype)
Definition editprop.c:779
static void propstate_destroy(struct propstate *ps)
Definition editprop.c:1298
static bool objbind_set_modified_value(struct objbind *ob, struct objprop *op, struct propval *pv)
Definition editprop.c:2130
static GtkCellRenderer * objprop_create_cell_renderer(const struct objprop *op)
Definition editprop.c:2858
static void extviewer_clear_widgets(struct extviewer *ev)
Definition editprop.c:4091
value_types
Definition editprop.c:197
@ VALTYPE_STRING
Definition editprop.c:201
@ VALTYPE_BV_SPECIAL
Definition editprop.c:205
@ VALTYPE_BV_BASES
Definition editprop.c:207
@ VALTYPE_INT
Definition editprop.c:199
@ VALTYPE_INVENTIONS_ARRAY
Definition editprop.c:204
@ VALTYPE_BV_ROADS
Definition editprop.c:206
@ VALTYPE_PIXBUF
Definition editprop.c:202
@ VALTYPE_TILE_VISION_DATA
Definition editprop.c:211
@ VALTYPE_NONE
Definition editprop.c:198
@ VALTYPE_NATION_HASH
Definition editprop.c:209
@ VALTYPE_BOOL
Definition editprop.c:200
@ VALTYPE_NATION
Definition editprop.c:208
@ VALTYPE_GOV
Definition editprop.c:210
@ VALTYPE_BUILT_ARRAY
Definition editprop.c:203
static void objprop_set_child_widget(struct objprop *op, const char *widget_name, GtkWidget *widget)
Definition editprop.c:3383
static bool property_editor_add_page(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6155
static void propstate_clear_value(struct propstate *ps)
Definition editprop.c:1285
static void objbind_pack_modified_value(struct objbind *ob, struct objprop *op, union packetdata packet)
Definition editprop.c:2382
static struct objbind * property_page_get_focused_objbind(struct property_page *pp)
Definition editprop.c:5436
static bool objprop_has_widget(const struct objprop *op)
Definition editprop.c:2747
static int objtype_get_id_from_object(enum editor_object_type objtype, gpointer object)
Definition editprop.c:696
static enum editor_object_type objbind_get_objtype(const struct objbind *ob)
Definition editprop.c:2214
static struct extviewer * objprop_get_extviewer(struct objprop *op)
Definition editprop.c:3455
static void extviewer_refresh_widgets(struct extviewer *ev, struct propval *pv)
Definition editprop.c:3821
static enum editor_object_type property_page_get_objtype(const struct property_page *pp)
Definition editprop.c:5086
#define property_page_objbind_iterate_end
Definition editprop.c:641
static void property_page_show_extviewer(struct property_page *pp, struct extviewer *ev)
Definition editprop.c:6007
static gpointer objbind_get_object(struct objbind *ob)
Definition editprop.c:1366
static const char * property_page_get_name(const struct property_page *pp)
Definition editprop.c:5074
void property_editor_handle_object_created(struct property_editor *pe, int tag, int object_id)
Definition editprop.c:6344
static bool objbind_property_is_modified(struct objbind *ob, struct objprop *op)
Definition editprop.c:2085
static struct propval * propstate_get_value(struct propstate *ps)
Definition editprop.c:1328
static void property_page_clear_tags(struct property_page *pp)
Definition editprop.c:6084
static void property_page_object_created(struct property_page *pp, int tag, int object_id)
Definition editprop.c:5961
static bool property_page_tag_is_known(struct property_page *pp, int tag)
Definition editprop.c:6073
static void property_page_remove_creation_tag(struct property_page *pp, int tag)
Definition editprop.c:6054
static void property_page_load_tiles(struct property_page *pp, const struct tile_list *tiles)
Definition editprop.c:5478
static void property_page_create_objects(struct property_page *pp, struct tile_list *hint_tiles)
Definition editprop.c:5785
static void property_page_add_extviewer(struct property_page *pp, struct extviewer *ev)
Definition editprop.c:5987
static void property_page_refresh_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6106
static void property_page_set_focused_objbind(struct property_page *pp, struct objbind *ob)
Definition editprop.c:5448
static void property_page_setup_objprops(struct property_page *pp)
Definition editprop.c:4436
static void objbind_set_rowref(struct objbind *ob, GtkTreeRowReference *rr)
Definition editprop.c:2654
object_property_flags
Definition editprop.c:384
@ OPF_IN_LISTVIEW
Definition editprop.c:387
@ OPF_EDITABLE
Definition editprop.c:386
@ OPF_HAS_WIDGET
Definition editprop.c:388
@ OPF_NO_FLAGS
Definition editprop.c:385
static void objbind_clear_modified_value(struct objbind *ob, struct objprop *op)
Definition editprop.c:2071
static struct propval * objbind_get_value_from_object(struct objbind *ob, struct objprop *op)
Definition editprop.c:1443
static void propval_free(struct propval *pv)
Definition editprop.c:1128
static struct property_filter * property_filter_new(const char *filter)
Definition editprop.c:6430
static bool property_page_set_store_value(struct property_page *pp, struct objprop *op, struct objbind *ob, GtkTreeIter *iter)
Definition editprop.c:5287
static const char * objtype_get_name(enum editor_object_type objtype)
Definition editprop.c:667
static void objbind_clear_all_modified_values(struct objbind *ob)
Definition editprop.c:2116
static bool property_filter_match(struct property_filter *pf, const struct objprop *op)
Definition editprop.c:6504
void property_editor_popup(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6292
static void property_page_destroy_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6144
static struct objbind * objbind_new(enum editor_object_type objtype, gpointer object)
Definition editprop.c:1340
static gboolean property_page_selection_func(GtkTreeSelection *sel, GtkTreeModel *model, GtkTreePath *path, gboolean currently_selected, gpointer data)
Definition editprop.c:4671
static int property_page_get_num_objbinds(const struct property_page *pp)
Definition editprop.c:5495
static bool objprop_show_in_listview(const struct objprop *op)
Definition editprop.c:2736
static GType objprop_get_gtype(const struct objprop *op)
Definition editprop.c:2692
static void objprop_set_treeview_column(struct objprop *op, GtkTreeViewColumn *col)
Definition editprop.c:2810
static void objbind_pack_current_values(struct objbind *ob, union packetdata packet)
Definition editprop.c:2239
static const char * objprop_get_attribute_type_string(const struct objprop *op)
Definition editprop.c:2761
static struct propval * propval_copy(struct propval *pv)
Definition editprop.c:1046
struct property_editor * editprop_get_property_editor(void)
Definition editprop.c:6245
void property_editor_reload(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6382
static GdkPixbuf * create_unit_pixbuf(const struct unit *punit)
Definition editprop.c:5114
static void extviewer_view_cell_toggled(GtkCellRendererToggle *cell, gchar *path, gpointer userdata)
Definition editprop.c:4166
static struct property_editor * property_editor_new(void)
Definition editprop.c:6202
static void property_page_send_packet(struct property_page *pp, union packetdata packet)
Definition editprop.c:5644
static gchar * built_status_to_string(struct built_status *bs)
Definition editprop.c:981
static int objprop_get_id(const struct objprop *op)
Definition editprop.c:2677
object_property_ids
Definition editprop.c:305
@ OPID_STARTPOS_IMAGE
Definition editprop.c:325
@ OPID_TILE_Y
Definition editprop.c:308
@ OPID_TILE_BASES
Definition editprop.c:321
@ OPID_CITY_XY
Definition editprop.c:351
@ OPID_UNIT_ID
Definition editprop.c:335
@ OPID_CITY_BUILDINGS
Definition editprop.c:354
@ OPID_CITY_NAME
Definition editprop.c:346
@ OPID_TILE_NAT_Y
Definition editprop.c:310
@ OPID_CITY_SIZE
Definition editprop.c:352
@ OPID_UNIT_VETERAN
Definition editprop.c:342
@ OPID_CITY_IMAGE
Definition editprop.c:345
@ OPID_CITY_SHIELD_STOCK
Definition editprop.c:356
@ OPID_PLAYER_NAME
Definition editprop.c:358
@ OPID_PLAYER_AGE
Definition editprop.c:361
@ OPID_STARTPOS_NATIONS
Definition editprop.c:328
@ OPID_GAME_LAKE_FLOODING
Definition editprop.c:380
@ OPID_UNIT_IMAGE
Definition editprop.c:330
@ OPID_TILE_TERRAIN
Definition editprop.c:315
@ OPID_TILE_SPECIALS
Definition editprop.c:319
@ OPID_TILE_RESOURCE
Definition editprop.c:318
@ OPID_TILE_IMAGE
Definition editprop.c:306
@ OPID_TILE_VISION
Definition editprop.c:322
@ OPID_PLAYER_INVENTIONS
Definition editprop.c:365
@ OPID_GAME_SCENARIO_NAME
Definition editprop.c:373
@ OPID_PLAYER_SCIENCE
Definition editprop.c:368
@ OPID_TILE_CONTINENT
Definition editprop.c:311
@ OPID_CITY_HISTORY
Definition editprop.c:353
@ OPID_TILE_XY
Definition editprop.c:317
@ OPID_GAME_SCENARIO_AUTHORS
Definition editprop.c:374
@ OPID_PLAYER_SELECT_WEIGHT
Definition editprop.c:367
@ OPID_TILE_X
Definition editprop.c:307
@ OPID_TILE_NAT_X
Definition editprop.c:309
@ OPID_PLAYER_NATION
Definition editprop.c:359
@ OPID_GAME_PREVENT_CITIES
Definition editprop.c:379
@ OPID_STARTPOS_XY
Definition editprop.c:326
@ OPID_UNIT_MOVED
Definition editprop.c:339
@ OPID_TILE_LABEL
Definition editprop.c:323
@ OPID_CITY_FOOD_STOCK
Definition editprop.c:355
@ OPID_UNIT_DONE_MOVING
Definition editprop.c:340
@ OPID_UNIT_MOVES_LEFT
Definition editprop.c:337
@ OPID_GAME_SCENARIO_DESC
Definition editprop.c:375
@ OPID_GAME_STARTPOS_NATIONS
Definition editprop.c:378
@ OPID_UNIT_HP
Definition editprop.c:341
@ OPID_UNIT_FUEL
Definition editprop.c:338
@ OPID_PLAYER_SCENARIO_RESERVED
Definition editprop.c:366
@ OPID_TILE_ROADS
Definition editprop.c:320
@ OPID_PLAYER_GOLD
Definition editprop.c:369
@ OPID_CITY_ID
Definition editprop.c:350
@ OPID_GAME_SCENARIO_RANDSTATE
Definition editprop.c:376
@ OPID_PLAYER_INFRAPOINTS
Definition editprop.c:370
@ OPID_GAME_SCENARIO_PLAYERS
Definition editprop.c:377
@ OPID_UNIT_STAY
Definition editprop.c:343
@ OPID_PLAYER_GOV
Definition editprop.c:360
@ OPID_STARTPOS_EXCLUDE
Definition editprop.c:327
@ OPID_UNIT_TYPE
Definition editprop.c:334
@ OPID_GAME_SCENARIO
Definition editprop.c:372
@ OPID_GAME_RULESET_LOCKED
Definition editprop.c:381
@ OPID_UNIT_XY
Definition editprop.c:336
@ OPID_TILE_INDEX
Definition editprop.c:316
static enum value_types objprop_get_valtype(const struct objprop *op)
Definition editprop.c:2725
static int get_next_unique_tag(void)
Definition editprop.c:1035
static bool objprop_is_sortable(const struct objprop *op)
Definition editprop.c:2879
static void property_page_add_objbinds_from_tile(struct property_page *pp, const struct tile *ptile)
Definition editprop.c:5233
static const char * objprop_get_tooltip(const struct objprop *op)
Definition editprop.c:2845
static GtkTreeRowReference * objbind_get_rowref(struct objbind *ob)
Definition editprop.c:2666
static void property_filter_free(struct property_filter *pf)
Definition editprop.c:6558
static void objprop_widget_spin_button_changed(GtkSpinButton *spin, gpointer userdata)
Definition editprop.c:2920
#define PF_DISJUNCTION_SEPARATOR
Definition editprop.c:119
static GtkWidget * objprop_get_child_widget(struct objprop *op, const char *widget_name)
Definition editprop.c:3410
static void property_page_selection_changed(GtkTreeSelection *sel, gpointer userdata)
Definition editprop.c:4646
static bool objtype_is_conserved(enum editor_object_type objtype)
Definition editprop.c:756
static struct extviewer * extviewer_new(struct objprop *op)
Definition editprop.c:3502
static bool propval_equal(struct propval *pva, struct propval *pvb)
Definition editprop.c:1179
static void property_page_quick_find_entry_changed(GtkWidget *entry, gpointer userdata)
Definition editprop.c:4726
static void objprop_refresh_widget(struct objprop *op, struct objbind *ob)
Definition editprop.c:3132
#define PF_MAX_CLAUSES
Definition editprop.c:118
void property_editor_popdown(struct property_editor *pe)
Definition editprop.c:6310
static void objbind_destroy(struct objbind *ob)
Definition editprop.c:2195
static void property_page_add_objbind(struct property_page *pp, gpointer object_data)
Definition editprop.c:5197
static void objbind_request_destroy_object(struct objbind *ob)
Definition editprop.c:1395
static void property_page_create_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6116
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:5140
static union packetdata property_page_new_packet(struct property_page *pp)
Definition editprop.c:5603
static void propstate_set_value(struct propstate *ps, struct propval *pv)
Definition editprop.c:1313
static int objprop_get_column_id(const struct objprop *op)
Definition editprop.c:2799
static GdkPixbuf * create_tile_pixbuf(const struct tile *ptile)
Definition editprop.c:5102
static struct objprop * extviewer_get_objprop(struct extviewer *ev)
Definition editprop.c:3786
static bool can_create_unit_at_tile(struct tile *ptile)
Definition editprop.c:1002
static struct objbind * property_page_get_objbind(struct property_page *pp, int object_id)
Definition editprop.c:5461
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:1884
static void property_page_free_packet(struct property_page *pp, union packetdata packet)
Definition editprop.c:5685
static GdkPixbuf * create_city_pixbuf(const struct city *pcity)
Definition editprop.c:5126
#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:4146
static void property_page_destroy_objects(struct property_page *pp)
Definition editprop.c:5746
void property_editor_load_tiles(struct property_editor *pe, const struct tile_list *tiles)
Definition editprop.c:6256
static struct property_page * property_page_new(enum editor_object_type objtype, struct property_editor *parent)
Definition editprop.c:4768
#define property_page_objprop_iterate_end
Definition editprop.c:637
static void property_page_clear_objbinds(struct property_page *pp)
Definition editprop.c:5182
void property_editor_clear(struct property_editor *pe)
Definition editprop.c:6362
#define property_page_objprop_iterate(ARG_pp, NAME_op)
Definition editprop.c:635
static void objprop_set_column_id(struct objprop *op, int col_id)
Definition editprop.c:2786
static void objbind_bind_properties(struct objbind *ob, struct property_page *pp)
Definition editprop.c:2225
static void property_page_fill_widgets(struct property_page *pp)
Definition editprop.c:5387
static bool objbind_has_modified_properties(struct objbind *ob)
Definition editprop.c:2104
static void property_page_change_value(struct property_page *pp, struct objprop *op, struct propval *pv)
Definition editprop.c:5507
static void objprop_widget_toggle_button_changed(GtkToggleButton *button, gpointer userdata)
Definition editprop.c:2937
#define PF_CONJUNCTION_SEPARATOR
Definition editprop.c:120
static void property_page_apply_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6095
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:3477
static GtkWidget * extviewer_get_view_widget(struct extviewer *ev)
Definition editprop.c:3810
static GtkWidget * objprop_get_widget(struct objprop *op)
Definition editprop.c:3368
static void propval_free_data(struct propval *pv)
Definition editprop.c:1142
static void extviewer_textbuf_changed(GtkTextBuffer *textbuf, gpointer userdata)
Definition editprop.c:4387
static struct property_editor * the_property_editor
Definition editprop.c:661
static void property_page_object_changed(struct property_page *pp, int object_id, bool remove)
Definition editprop.c:5909
static bool objprop_is_readonly(const struct objprop *op)
Definition editprop.c:2893
#define property_page_objbind_iterate(ARG_pp, NAME_ob)
Definition editprop.c:639
static GtkTreeViewColumn * objprop_get_treeview_column(const struct objprop *op)
Definition editprop.c:2823
static struct property_page * property_editor_get_page(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6189
static struct propval * objbind_get_modified_value(struct objbind *ob, struct objprop *op)
Definition editprop.c:2176
GtkWidget * toplevel
Definition gui_main.c:126
void disable_gobject_callback(GObject *obj, GCallback cb)
Definition gui_stuff.c:1090
void enable_gobject_callback(GObject *obj, GCallback cb)
Definition gui_stuff.c:1106
GdkPixbuf * get_flag(const struct nation_type *nation)
Definition plrdlg.c:607
const char * tooltip
Definition repodlgs.c:1315
const char * title
Definition repodlgs.c:1314
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:2905
#define PF_MAX_CLAUSES
Definition editprop.c:118
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:195
#define log_error(message,...)
Definition log.h:104
struct startpos * map_startpos_get(const struct tile *ptile)
Definition map.c:2038
int startpos_number(const struct startpos *psp)
Definition map.c:1776
#define nat_x
#define nat_y
struct tile * startpos_tile(const struct startpos *psp)
Definition map.c:1820
const struct nation_hash * startpos_raw_nations(const struct startpos *psp)
Definition map.c:1916
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
Definition map.c:1854
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:471
bool startpos_is_excluding(const struct startpos *psp)
Definition map.c:1903
struct startpos * map_startpos_by_number(int id)
Definition map.c:1767
#define index_to_native_pos(pnat_x, pnat_y, mindex)
Definition map.h:161
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:229
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:318
#define MAX_MOVE_FRAGS
Definition movement.h:29
Nation_type_id nation_count(void)
Definition nation.c:507
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:486
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:149
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:475
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:200
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
#define nation_hash_iterate(nationhash, pnation)
Definition nation.h:93
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
#define nation_hash_iterate_end
Definition nation.h:95
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 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_remove_by_id(struct connection *pc, int id)
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)
int dsend_packet_edit_city_remove(struct connection *pc, int id)
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1996
int player_index(const struct player *pplayer)
Definition player.c:829
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
#define player_slots_iterate(_pslot)
Definition player.h:528
#define player_slots_iterate_end
Definition player.h:532
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
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
cairo_surface_t * surface
Definition canvas.h:23
Definition city.h:317
struct packet_game_info info
Definition game.h:89
struct government * government_during_revolution
Definition game.h:94
struct connection conn
Definition client_main.h:96
GtkWidget * view_widget
Definition editprop.c:523
GtkWidget * panel_button
Definition editprop.c:520
GtkWidget * view_label
Definition editprop.c:524
GtkWidget * panel_image
Definition editprop.c:521
GtkTextBuffer * textbuf
Definition editprop.c:527
struct objprop * objprop
Definition editprop.c:515
GtkWidget * panel_label
Definition editprop.c:519
struct propval * pv_cached
Definition editprop.c:516
GtkListStore * store
Definition editprop.c:526
GtkWidget * panel_widget
Definition editprop.c:518
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
int object_id
Definition editprop.c:460
struct propstate_hash * propstate_table
Definition editprop.c:462
struct property_page * parent_property_page
Definition editprop.c:461
GtkTreeRowReference * rowref
Definition editprop.c:463
enum editor_object_type objtype
Definition editprop.c:459
const char * name
Definition editprop.c:393
const char * tooltip
Definition editprop.c:394
GtkWidget * widget
Definition editprop.c:399
struct property_page * parent_page
Definition editprop.c:401
enum object_property_flags flags
Definition editprop.c:395
struct extviewer * extviewer
Definition editprop.c:400
int id
Definition editprop.c:392
enum value_types valtype
Definition editprop.c:396
int column_id
Definition editprop.c:397
GtkTreeViewColumn * view_column
Definition editprop.c:398
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]
struct pf_pattern conjunction[PF_MAX_CLAUSES]
Definition editprop.c:128
char * text
Definition editprop.c:124
bool negate
Definition editprop.c:123
int infra_points
Definition player.h:67
int autoselect_weight
Definition player.h:299
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:649
struct property_page * property_pages[NUM_OBJTYPES]
Definition editprop.c:651
GtkWidget * widget
Definition editprop.c:648
struct pf_conjunction disjunction[PF_MAX_CLAUSES]
Definition editprop.c:133
GtkListStore * object_store
Definition editprop.c:553
struct property_editor * pe_parent
Definition editprop.c:557
GtkWidget * extviewer_notebook
Definition editprop.c:555
GtkWidget * widget
Definition editprop.c:552
struct objbind_hash * objbind_table
Definition editprop.c:560
GtkWidget * object_view
Definition editprop.c:554
struct objbind * focused_objbind
Definition editprop.c:563
struct stored_tag_hash * tag_table
Definition editprop.c:561
enum editor_object_type objtype
Definition editprop.c:550
struct objprop_hash * objprop_table
Definition editprop.c:559
struct propval * property_value
Definition editprop.c:256
int property_id
Definition editprop.c:255
union propval_data data
Definition editprop.c:244
enum value_types valtype
Definition editprop.c:245
bool must_free
Definition editprop.c:246
Definition map.c:40
bv_player tile_known
Definition editprop.c:114
bv_player tile_seen[V_COUNT]
Definition editprop.c:114
Definition tile.h:50
char * label
Definition tile.h:66
Continent_id continent
Definition tile.h:54
Definition unit.h:140
int moves_left
Definition unit.h:152
int id
Definition unit.h:147
bool moved
Definition unit.h:176
int hp
Definition unit.h:153
int fuel
Definition unit.h:155
bool stay
Definition unit.h:208
bool done_moving
Definition unit.h:184
int veteran
Definition unit.h:154
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
char * fc_strcasestr(const char *haystack, const char *needle)
Definition support.c:437
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:300
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
#define advance_index_iterate_end
Definition tech.h:244
static Tech_type_id advance_count(void)
Definition tech.h:165
#define A_FIRST
Definition tech.h:44
#define advance_iterate(_p)
Definition tech.h:271
#define advance_iterate_end
Definition tech.h:272
#define advance_index_iterate(_start, _index)
Definition tech.h:240
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:89
#define tile_resource(_tile)
Definition tile.h:103
#define tile_list_iterate(tile_list, ptile)
Definition tile.h:74
#define tile_terrain(_tile)
Definition tile.h:111
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_list_iterate_end
Definition tile.h:76
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:121
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:7017
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:927
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:815
bool tileset_layer_in_category(enum mapview_layer layer, enum layer_category cat)
Definition tilespec.c:7557
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:963
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:802
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
#define mapview_layer_iterate(layer)
Definition tilespec.h:177
#define mapview_layer_iterate_end
Definition tilespec.h:185
layer_category
Definition tilespec.h:191
@ LAYER_CATEGORY_TILE
Definition tilespec.h:193
@ LAYER_CATEGORY_CITY
Definition tilespec.h:192
@ LAYER_CATEGORY_UNIT
Definition tilespec.h:194
gpointer v_pointer2
Definition editprop.c:99
struct packet_edit_tile * tile
Definition editprop.c:101
gpointer v_pointer1
Definition editprop.c:98
struct packet_edit_unit * unit
Definition editprop.c:104
struct packet_edit_player * player
Definition editprop.c:105
struct packetdata::@152 pointers
struct packet_edit_city * city
Definition editprop.c:103
struct packet_edit_game * game
Definition editprop.c:107
struct packet_edit_startpos_full * startpos
Definition editprop.c:102
struct government * v_gov
Definition editprop.c:238
bv_techs v_bv_inventions
Definition editprop.c:239
bv_max_extras v_bv_special
Definition editprop.c:233
struct tile_vision_data * v_tile_vision
Definition editprop.c:240
char * v_string
Definition editprop.c:229
struct built_status * v_built
Definition editprop.c:232
bv_max_extras v_bv_roads
Definition editprop.c:234
gpointer v_pointer
Definition editprop.c:226
struct nation_type * v_nation
Definition editprop.c:236
struct nation_hash * v_nation_hash
Definition editprop.c:237
bv_max_extras v_bv_bases
Definition editprop.c:235
GdkPixbuf * v_pixbuf
Definition editprop.c:231
const char * v_const_string
Definition editprop.c:230
#define unit_tile(_pu)
Definition unit.h:404
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:427
#define unit_owner(_pu)
Definition unit.h:403
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer, bool everyone_non_allied)
Definition unit.h:440
#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:2631
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:196
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1566
#define utype_fuel(ptype)
Definition unittype.h:846
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80