Freeciv-3.3
Loading...
Searching...
No Matches
editgui.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 <math.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23#include <gtk/gtk.h>
24#include <gdk/gdkkeysyms.h>
25
26/* utility */
27#include "fcintl.h"
28#include "log.h"
29#include "shared.h"
30#include "support.h"
31
32/* common */
33#include "connection.h"
34#include "game.h"
35#include "government.h"
36#include "packets.h"
37
38/* client */
39#include "chatline_common.h"
40#include "client_main.h"
41#include "dialogs_g.h"
42#include "editor.h"
43#include "mapview_common.h"
44#include "tilespec.h"
45
46/* client/gui-gtk-3.22 */
47#include "canvas.h"
48#include "editgui.h"
49#include "editprop.h"
50#include "gui_main.h"
51#include "gui_stuff.h"
52#include "plrdlg.h"
53#include "sprite.h"
54
55
63
71
79
84
93
94static struct tool_value_selector *
97static void editinfobox_refresh(struct editinfobox *ei);
99 gpointer user_data);
105
106static struct editbar *editor_toolbar;
108
109/************************************************************************/
113static void refresh_all_buttons(struct editbar *eb)
114{
117 GtkWidget *tb = NULL;
118 int i;
119
120 if (eb == NULL) {
121 return;
122 }
123
126
127 for (i = 0; i < NUM_EDITOR_TOOL_MODES; i++) {
128 tb = eb->mode_buttons[i];
129 if (tb == NULL) {
130 continue;
131 }
138 }
139
141 && eb->tool_buttons[ett] != NULL) {
142 tb = eb->tool_buttons[ett];
148 }
149}
150
151/************************************************************************/
156{
157 gboolean active;
160
162 if (!(etm < NUM_EDITOR_TOOL_MODES)) {
163 return;
164 }
165
168
171}
172
173/************************************************************************/
178{
179 if (!(ett < NUM_EDITOR_TOOL_TYPES)) {
180 return;
181 }
182
184 GtkWidget *dialog;
188 _("The current ruleset does not define any "
189 "objects corresponding to this editor tool."));
191 gtk_dialog_run(GTK_DIALOG(dialog));
192 gtk_widget_destroy(dialog);
193 } else {
195 }
196}
197
198/************************************************************************/
203{
204 gboolean active;
206
209
210 if (active) {
213 }
214}
215
216/************************************************************************/
224{
225 GtkListStore *store;
226 GdkPixbuf *flag;
228 GtkWidget *combo;
229 int index = -1, i;
230
231 if (eb == NULL || eb->player_pov_store == NULL) {
232 return;
233 }
234
235 store = eb->player_pov_store;
237
239 gtk_list_store_set(store, &iter, PPV_COL_NAME, _("Global Observer"),
240 PPV_COL_PLAYER_NO, -1, -1);
241
242 i = 1;
243 players_iterate(pplayer) {
246 PPV_COL_PLAYER_NO, player_number(pplayer), -1);
247
248 if (pplayer->nation != NO_NATION_SELECTED) {
249 flag = get_flag(pplayer->nation);
250
251 if (flag != NULL) {
252 gtk_list_store_set(store, &iter, PPV_COL_FLAG, flag, -1);
253 g_object_unref(flag);
254 }
255 }
256 if (pplayer == client_player()) {
257 index = i;
258 }
259 i++;
261
263 index = 0;
264 }
265
266 combo = eb->player_pov_combobox;
268}
269
270/************************************************************************/
278 gpointer user_data)
279{
280 struct editbar *eb = user_data;
281 int id;
282 struct player *pplayer;
284 GtkTreeModel *model;
285
286 if (eb == NULL || eb->widget == NULL
287 || !gtk_widget_get_visible(eb->widget)) {
288 return;
289 }
290
291 if (!gtk_combo_box_get_active_iter(combo, &iter)) {
292 return;
293 }
294
295 model = gtk_combo_box_get_model(combo);
296 gtk_tree_model_get(model, &iter, PPV_COL_PLAYER_NO, &id, -1);
297
298 if ((client_is_global_observer() && id == -1)
299 || client_player_number() == id) {
300 return;
301 }
302
303 /* Ugh... hard-coded server command strings. :( */
304 if (id == -1) {
305 send_chat("/observe");
306 return;
307 }
308
309 pplayer = player_by_number(id);
310 if (pplayer != NULL) {
311 send_chat_printf("/take \"%s\"", pplayer->name);
312 }
313}
314
315/************************************************************************/
320{
321 gint res;
322 GtkWidget *dialog;
325 GtkTreeModel *model;
326 int id;
327
328 if (tvs == NULL) {
329 return -1;
330 }
331
332 dialog = tvs->dialog;
333 res = gtk_dialog_run(GTK_DIALOG(dialog));
334 gtk_widget_hide(dialog);
335
336 if (res != GTK_RESPONSE_ACCEPT) {
337 return -1;
338 }
339
341 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) {
342 return -1;
343 }
344
345 gtk_tree_model_get(model, &iter, TVS_COL_ID, &id, -1);
346
347 return id;
348}
349
350/************************************************************************/
357{
358 struct editbar *eb;
359 struct tool_value_selector *tvs;
360 int res = -1;
361
363 if (eb == NULL || !(ett < NUM_EDITOR_TOOL_TYPES)) {
364 return FALSE;
365 }
366
368 return FALSE;
369 }
370
371 tvs = eb->tool_selectors[ett];
372 if (!tvs) {
373 return FALSE;
374 }
375
377
378 if (res >= 0) {
381 }
382
383 return TRUE;
384}
385
386/************************************************************************/
392{
393 int ett;
394
395 if (ev->button != 3) {
396 return FALSE; /* Propagate event further. */
397 }
398
401}
402
403/************************************************************************/
409{
411 GtkWidget *image, *button, *hbox;
413 struct sprite *sprite;
414 int i;
415
416 if (!eb || !(ett < NUM_EDITOR_TOOL_TYPES)) {
417 return;
418 }
419
420 for (i = 0; i < NUM_EDITOR_TOOL_TYPES; i++) {
421 if (eb->tool_buttons[i] != NULL) {
422 parent = GTK_RADIO_BUTTON(eb->tool_buttons[i]);
423 break;
424 }
425 }
426
427 if (parent == NULL) {
428 button = gtk_radio_button_new(NULL);
429 } else {
431 }
432
438
442 gtk_size_group_add_widget(eb->size_group, button);
445
446 g_signal_connect(button, "toggled",
448 g_signal_connect(button, "button_press_event",
450
451 hbox = eb->widget;
453 eb->tool_buttons[ett] = button;
454
456 eb->tool_selectors[ett] = create_tool_value_selector(eb, ett);
457 }
458}
459
460/************************************************************************/
473
474/************************************************************************/
480{
482 GtkWidget *image, *button, *hbox;
483 struct sprite *sprite;
484 const char *tooltip;
485
486 if (!eb || !(etm < NUM_EDITOR_TOOL_MODES)) {
487 return;
488 }
489
490 button = gtk_toggle_button_new();
491
497
501 if (tooltip != NULL) {
503 }
504 gtk_size_group_add_widget(eb->size_group, button);
507
508 g_signal_connect(button, "toggled",
510
511 hbox = eb->widget;
513 eb->mode_buttons[etm] = button;
514}
515
516/************************************************************************/
519static struct editbar *editbar_create(void)
520{
521 struct editbar *eb;
522 GtkWidget *hbox, *button, *combo, *image, *separator, *vbox;
523 GtkListStore *store;
526 const struct editor_sprites *sprites;
527
528 eb = fc_calloc(1, sizeof(struct editbar));
529
530 hbox = gtk_grid_new();
532 eb->widget = hbox;
534
535 sprites = get_editor_sprites(tileset);
536
538
541
552
555
556 /* Player POV indicator. */
557 vbox = gtk_grid_new();
561
565 G_TYPE_INT);
566 eb->player_pov_store = store;
567
569
573 cell, "pixbuf", PPV_COL_FLAG);
574
578 cell, "text", PPV_COL_NAME);
579
580 gtk_widget_set_size_request(combo, 140, -1);
581 g_signal_connect(combo, "changed",
583
585 _("Switch player point-of-view. Use this to edit "
586 "from the perspective of different players, or "
587 "even as a global observer."));
588 gtk_container_add(GTK_CONTAINER(vbox), combo);
589 eb->player_pov_combobox = combo;
590
591 /* Property editor button. */
592 button = gtk_button_new();
597 gtk_widget_set_tooltip_text(button, _("Show the property editor."));
598 gtk_size_group_add_widget(eb->size_group, button);
601 g_signal_connect(button, "clicked",
604
605 return eb;
606}
607
608/************************************************************************/
614{
617 GtkTreeModel *model;
618 int value, store_value;
619 struct tool_value_selector *tvs;
620
622 return;
623 }
624
625 tvs = eb->tool_selectors[ett];
626
627 if (!tvs) {
628 return;
629 }
630
631 value = editor_tool_get_value(ett);
632 model = GTK_TREE_MODEL(tvs->store);
633 if (!gtk_tree_model_get_iter_first(model, &iter)) {
634 return;
635 }
636
637 do {
639 if (value == store_value) {
642 break;
643 }
644 } while (gtk_tree_model_iter_next(model, &iter));
645}
646
647/************************************************************************/
652{
653 int ett;
654
655 if (!eb) {
656 return;
657 }
658
659 for (ett = 0; ett < NUM_EDITOR_TOOL_TYPES; ett++) {
662 }
663 }
664}
665
666/************************************************************************/
669static void editbar_refresh(struct editbar *eb)
670{
671 if (eb == NULL || eb->widget == NULL) {
672 return;
673 }
674
675 if (!editor_is_active()) {
676 gtk_widget_hide(eb->widget);
677 return;
678 }
679
683
684 gtk_widget_show_all(eb->widget);
685}
686
687/************************************************************************/
696static GdkPixbuf *create_terrain_pixbuf(struct terrain *pterrain)
697{
698 int w, h, i;
701 cairo_t *cr;
702
705
707
710 cairo_paint(cr);
711 cairo_destroy(cr);
712
713 for (i = 0; i < 3; i++) {
714 struct drawn_sprite sprs[80];
716 i, pterrain);
717
718 put_drawn_sprites(&canvas, 1.0, 0, 0, count, sprs, FALSE);
719 }
720
723
724 return pixbuf;
725}
726
727/************************************************************************/
731{
733 GtkTreeModel *model = GTK_TREE_MODEL(store);
734
735 if (gtk_tree_model_get_iter_first(model, &iter)) {
736 do {
738
740 if (pixbuf != NULL) {
742 }
743 } while (gtk_tree_model_iter_next(model, &iter));
744 }
745
747}
748
749/************************************************************************/
752static void clear_tool_stores(struct editbar *eb)
753{
754 clear_tool_store(eb->tool_selectors[ETT_TERRAIN]->store);
755 clear_tool_store(eb->tool_selectors[ETT_TERRAIN_RESOURCE]->store);
756 clear_tool_store(eb->tool_selectors[ETT_TERRAIN_SPECIAL]->store);
757 clear_tool_store(eb->tool_selectors[ETT_ROAD]->store);
758 clear_tool_store(eb->tool_selectors[ETT_MILITARY_BASE]->store);
759 clear_tool_store(eb->tool_selectors[ETT_UNIT]->store);
760}
761
762/************************************************************************/
766{
768 GtkListStore *store;
770 struct sprite *sprite;
771 struct tool_value_selector *tvs;
772
773 if (eb == NULL || tileset == NULL) {
774 return;
775 }
776
778
779 /* Reload terrains. */
780
781 tvs = eb->tool_selectors[ETT_TERRAIN];
782 store = tvs->store;
783
784 terrain_type_iterate(pterrain) {
787 TVS_COL_ID, terrain_number(pterrain),
789 -1);
790 pixbuf = create_terrain_pixbuf(pterrain);
791 if (pixbuf != NULL) {
794 }
796
797
798 /* Reload terrain resources. */
799
800 tvs = eb->tool_selectors[ETT_TERRAIN_RESOURCE];
801 store = tvs->store;
802
806 TVS_COL_ID, extra_index(pextra),
808 -1);
809 pixbuf = create_extra_pixbuf(pextra);
810 if (pixbuf != NULL) {
813 }
815
816 /* Reload terrain specials. */
817
818 tvs = eb->tool_selectors[ETT_TERRAIN_SPECIAL];
819 store = tvs->store;
820
824 TVS_COL_ID, extra_index(pextra),
826 -1);
827 pixbuf = create_extra_pixbuf(pextra);
828 if (pixbuf != NULL) {
831 }
833
834 /* Reload roads. */
835
836 tvs = eb->tool_selectors[ETT_ROAD];
837 store = tvs->store;
838
842 TVS_COL_ID, extra_index(pextra),
844 -1);
845 pixbuf = create_extra_pixbuf(pextra);
846 if (pixbuf != NULL) {
849 }
851
852 /* Reload military bases. */
853
854 tvs = eb->tool_selectors[ETT_MILITARY_BASE];
855 store = tvs->store;
856
860 TVS_COL_ID, extra_index(pextra),
862 -1);
863 pixbuf = create_extra_pixbuf(pextra);
864 if (pixbuf != NULL) {
867 }
869
870
871 /* Reload unit types. */
872
873 tvs = eb->tool_selectors[ETT_UNIT];
874 store = tvs->store;
875
881 -1);
884 if (sprite == NULL) {
885 continue;
886 }
888 if (pixbuf != NULL) {
891 }
893}
894
895/************************************************************************/
899{
900 int modifiers = EKM_NONE;
901
904 }
907 }
910 }
911
912 return modifiers;
913}
914
915/************************************************************************/
919{
920 switch (gdk_mouse_button) {
921 case 1:
922 return MOUSE_BUTTON_LEFT;
923 break;
924 case 2:
925 return MOUSE_BUTTON_MIDDLE;
926 break;
927 case 3:
928 return MOUSE_BUTTON_RIGHT;
929 break;
930 default:
931 break;
932 }
933
934 return MOUSE_BUTTON_OTHER;
935}
936
937/************************************************************************/
941{
942 if (ev->type != GDK_BUTTON_PRESS) {
943 return TRUE;
944 }
945
947 convert_mouse_button(ev->button),
948 convert_modifiers(ev->state));
949
950 return TRUE;
951}
952
953/************************************************************************/
957{
958 if (ev->type != GDK_BUTTON_RELEASE) {
959 return TRUE;
960 }
961
963 convert_mouse_button(ev->button),
964 convert_modifiers(ev->state));
965 return TRUE;
966}
967
968/************************************************************************/
976
977/************************************************************************/
989
990/************************************************************************/
993static struct tool_value_selector *
996{
997 struct tool_value_selector *tvs;
998 GtkWidget *vbox, *view, *scrollwin;
1003
1004 tvs = fc_calloc(1, sizeof(struct tool_value_selector));
1005
1006 tvs->editbar_parent = eb;
1007
1008 tvs->dialog = gtk_dialog_new_with_buttons(_("Select Tool Value"),
1010 _("_OK"), GTK_RESPONSE_ACCEPT,
1011 _("_Cancel"), GTK_RESPONSE_REJECT,
1012 NULL);
1014
1017 G_TYPE_INT,
1019 tvs->store = store;
1020
1030
1034 g_signal_connect(view, "row-activated",
1036
1039
1042 cell, "pixbuf",
1049
1052 "text", TVS_COL_ID, NULL);
1059
1062 "text", TVS_COL_NAME, NULL);
1069
1071 tvs->view = view;
1072
1073 /* Show everything but the window itself. */
1074 gtk_widget_show_all(vbox);
1075
1076 return tvs;
1077}
1078
1079/************************************************************************/
1089
1090/************************************************************************/
1102
1103/************************************************************************/
1108{
1109 struct editinfobox *ei;
1110 int which, value;
1111 enum editor_tool_type ett;
1112
1114
1115 if (!ei) {
1116 return;
1117 }
1118
1121 ett = editor_get_tool();
1122
1123 switch (which) {
1124 case SPIN_BUTTON_SIZE:
1125 editor_tool_set_size(ett, value);
1126 break;
1127 case SPIN_BUTTON_COUNT:
1128 editor_tool_set_count(ett, value);
1129 break;
1130 default:
1131 return;
1132 break;
1133 }
1134
1136}
1137
1138/************************************************************************/
1144{
1145 struct editinfobox *ei = userdata;
1147 GtkTreeModel *model;
1148 int player_no = -1;
1149
1150 if (ei == NULL) {
1151 return;
1152 }
1153
1154 if (!gtk_combo_box_get_active_iter(combo, &iter)) {
1155 return;
1156 }
1157
1158 model = gtk_combo_box_get_model(combo);
1159 gtk_tree_model_get(model, &iter, TAP_COL_PLAYER_NO, &player_no, -1);
1160
1162}
1163
1164/************************************************************************/
1168{
1169 GtkWidget *label, *vbox, *frame, *hbox, *vbox2, *image, *evbox;
1170 GtkWidget *spin, *combo;
1171 GtkListStore *store;
1173 struct editinfobox *ei;
1174 char buf[128];
1175
1176 ei = fc_calloc(1, sizeof(*ei));
1177
1178 frame = gtk_frame_new(_("Editor Tool"));
1180 ei->widget = frame;
1181
1182 vbox = gtk_grid_new();
1187 gtk_container_add(GTK_CONTAINER(frame), vbox);
1188
1189 /* tool section */
1190 hbox = gtk_grid_new();
1193
1195 gtk_widget_set_tooltip_text(evbox, _("Click to change value if applicable."));
1196 g_signal_connect(evbox, "button_press_event",
1199
1200 image = gtk_image_new();
1202 ei->tool_image = image;
1203
1204 vbox2 = gtk_grid_new();
1209
1210 label = gtk_label_new(NULL);
1214 ei->tool_label = label;
1215
1216 label = gtk_label_new(NULL);
1220 ei->tool_value_label = label;
1221
1222 /* mode section */
1223 hbox = gtk_grid_new();
1226
1228 gtk_widget_set_tooltip_text(evbox, _("Click to change tool mode."));
1229 g_signal_connect(evbox, "button_press_event",
1232
1233 image = gtk_image_new();
1235 ei->mode_image = image;
1236
1237 vbox2 = gtk_grid_new();
1242
1243 label = gtk_label_new(NULL);
1244 fc_snprintf(buf, sizeof(buf), "<span weight=\"bold\">%s</span>",
1245 _("Mode"));
1250
1251 label = gtk_label_new(NULL);
1255 ei->mode_label = label;
1256
1257 /* spinner section */
1258 hbox = gtk_grid_new();
1261 ei->size_hbox = hbox;
1264 _("Use this to change the \"size\" parameter for the tool. "
1265 "This parameter controls for example the half-width "
1266 "of the square of tiles that will be affected by the "
1267 "tool, or the size of a created city."));
1268 g_signal_connect(spin, "value-changed",
1272 ei->size_spin_button = spin;
1273 label = gtk_label_new(_("Size"));
1275
1276 hbox = gtk_grid_new();
1279 ei->count_hbox = hbox;
1282 _("Use this to change the tool's \"count\" parameter. "
1283 "This controls for example how many units are placed "
1284 "at once with the unit tool."));
1285 g_signal_connect(spin, "value-changed",
1289 ei->count_spin_button = spin;
1290 label = gtk_label_new(_("Count"));
1292
1293 /* combo section */
1297 G_TYPE_INT);
1298 ei->tool_applied_player_store = store;
1300
1304 cell, "pixbuf", TAP_COL_FLAG);
1305
1309 cell, "text", TAP_COL_NAME);
1310
1311 gtk_widget_set_size_request(combo, 132, -1);
1312 g_signal_connect(combo, "changed",
1314
1316 _("Use this to change the \"applied player\" tool parameter. "
1317 "This controls for example under which player units and cities "
1318 "are created."));
1319 gtk_container_add(GTK_CONTAINER(vbox), combo);
1320 ei->tool_applied_player_combobox = combo;
1321
1322 /* We add a ref to the editinfobox widget so that it is
1323 * not destroyed when replaced by the unit info box when
1324 * we leave edit mode. See editinfobox_refresh(). */
1325 g_object_ref(ei->widget);
1326
1327 /* The edit info box starts with no parent, so we have to
1328 * show its internal widgets manually. */
1329 gtk_widget_show_all(ei->widget);
1330
1331 return ei;
1332}
1333
1334/************************************************************************/
1339{
1340 enum editor_tool_type ett;
1341 GtkListStore *store;
1342 GtkWidget *combo;
1344 GdkPixbuf *flag;
1345 int apno, index, i;
1346
1347 if (!ei) {
1348 return;
1349 }
1350
1351 ett = editor_get_tool();
1352 combo = ei->tool_applied_player_combobox;
1353 store = ei->tool_applied_player_store;
1354
1355 if (!combo || !store) {
1356 return;
1357 }
1358
1360 gtk_widget_hide(combo);
1361 return;
1362 }
1363
1364 gtk_list_store_clear(store);
1365
1367 index = -1;
1368 i = 0;
1369
1370 players_iterate(pplayer) {
1371 gtk_list_store_append(store, &iter);
1372 gtk_list_store_set(store, &iter,
1374 TAP_COL_NAME, player_name(pplayer), -1);
1375
1376 if (pplayer->nation != NO_NATION_SELECTED) {
1377 flag = get_flag(pplayer->nation);
1378
1379 if (flag != NULL) {
1380 gtk_list_store_set(store, &iter, TAP_COL_FLAG, flag, -1);
1381 g_object_unref(flag);
1382 }
1383 }
1384 if (apno == player_number(pplayer)) {
1385 index = i;
1386 }
1387 i++;
1389
1390 if (index == -1) {
1391 if (player_count() > 0) {
1392 index = 0;
1393 }
1395 }
1397 gtk_widget_show(combo);
1398}
1399
1400/************************************************************************/
1407 int value)
1408{
1409 struct sprite *sprite = NULL;
1411 struct terrain *pterrain;
1412 struct unit_type *putype;
1413 const struct editor_sprites *sprites;
1414
1415 sprites = get_editor_sprites(tileset);
1416 if (!sprites) {
1417 return NULL;
1418 }
1419
1420 switch (ett) {
1421 case ETT_TERRAIN:
1422 pterrain = terrain_by_number(value);
1423 if (pterrain) {
1424 pixbuf = create_terrain_pixbuf(pterrain);
1425 }
1426 break;
1429 case ETT_ROAD:
1430 case ETT_MILITARY_BASE:
1431 if (value >= 0) {
1433 }
1434 break;
1435 case ETT_UNIT:
1436 putype = utype_by_number(value);
1437 if (putype) {
1440 }
1441 break;
1442 case ETT_CITY:
1443 sprite = sprites->city;
1444 break;
1445 case ETT_VISION:
1446 sprite = sprites->vision;
1447 break;
1448 case ETT_STARTPOS:
1449 sprite = sprites->startpos;
1450 break;
1451 case ETT_COPYPASTE:
1452 sprite = sprites->copypaste;
1453 break;
1454 default:
1455 break;
1456 }
1457
1458 if (sprite) {
1460 /*
1461 if (pixbuf) {
1462 g_object_ref(pixbuf);
1463 }
1464 */
1465 sprite = NULL;
1466 }
1467
1468 return pixbuf;
1469}
1470
1471/************************************************************************/
1478{
1479 struct sprite *sprite = NULL;
1481
1483
1484 if (sprite) {
1486 /*
1487 if (pixbuf) {
1488 g_object_ref(pixbuf);
1489 }
1490 */
1491 }
1492
1493 return pixbuf;
1494}
1495
1496/************************************************************************/
1502{
1504
1506 if (!parent) {
1507 return;
1508 }
1509
1514}
1515
1516/************************************************************************/
1520{
1522 GtkLabel *label;
1523 enum editor_tool_type ett;
1524 enum editor_tool_mode etm;
1525 int value;
1526 char buf[256];
1527
1528 if (ei == NULL) {
1529 return;
1530 }
1531
1532 if (!editor_is_active()) {
1534 return;
1535 }
1536
1537 ett = editor_get_tool();
1539 value = editor_tool_get_value(ett);
1540
1541 label = GTK_LABEL(ei->mode_label);
1543
1546 if (pixbuf) {
1548 pixbuf = NULL;
1549 }
1550
1551 fc_snprintf(buf, sizeof(buf), "<span weight=\"bold\">%s</span>",
1553 gtk_label_set_markup(GTK_LABEL(ei->tool_label), buf);
1554
1555 if (etm == ETM_COPY || etm == ETM_PASTE) {
1556 struct edit_buffer *ebuf;
1557 struct sprite *spr;
1558 char status[256];
1559
1561 edit_buffer_get_status_string(ebuf, status, sizeof(status));
1562 gtk_label_set_text(GTK_LABEL(ei->tool_value_label), status);
1563
1567 if (pixbuf) {
1569 pixbuf = NULL;
1570 }
1571 } else {
1574 if (pixbuf) {
1576 pixbuf = NULL;
1577 }
1578 gtk_label_set_text(GTK_LABEL(ei->tool_value_label),
1580 }
1581
1583
1585 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ei->size_spin_button),
1587 gtk_widget_show(ei->size_hbox);
1588 } else {
1589 gtk_widget_hide(ei->size_hbox);
1590 }
1591
1593 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ei->count_spin_button),
1595 gtk_widget_show(ei->count_hbox);
1596 } else {
1597 gtk_widget_hide(ei->count_hbox);
1598 }
1599
1601}
1602
1603/************************************************************************/
1607{
1608 return FALSE; /* Don't gobble. */
1609}
1610
1611/************************************************************************/
1615{
1616 enum editor_tool_type ett;
1617
1618 ett = editor_get_tool();
1619 switch (ev->keyval) {
1620 case GDK_KEY_D:
1622 break;
1623 case GDK_KEY_C:
1626 break;
1627 case GDK_KEY_V:
1630 break;
1631 case GDK_KEY_T:
1633 break;
1634 case GDK_KEY_R:
1636 break;
1637 case GDK_KEY_S:
1639 break;
1640 case GDK_KEY_P:
1642 break;
1643 case GDK_KEY_M:
1645 break;
1646 case GDK_KEY_U:
1648 break;
1649 default:
1650 return TRUE; /* Gobble? */
1651 break;
1652 }
1653
1655
1656 return TRUE;
1657}
1658
1659/************************************************************************/
1663{
1665
1666 /* Check ctrl before shift - this is correct also for the case where
1667 * they are both active. */
1668 if (ev->state & GDK_CONTROL_MASK) {
1670 }
1671
1672 if (ev->state & GDK_SHIFT_MASK) {
1674 }
1675
1676 ett = editor_get_tool();
1677
1678 switch (ev->keyval) {
1679 case GDK_KEY_t:
1681 break;
1682 case GDK_KEY_r:
1684 break;
1685 case GDK_KEY_s:
1687 break;
1688 case GDK_KEY_p:
1689 new_ett = ETT_ROAD;
1690 break;
1691 case GDK_KEY_m:
1693 break;
1694 case GDK_KEY_u:
1695 new_ett = ETT_UNIT;
1696 break;
1697 case GDK_KEY_c:
1698 new_ett = ETT_CITY;
1699 break;
1700 case GDK_KEY_v:
1702 break;
1703 case GDK_KEY_b:
1705 break;
1706 case GDK_KEY_plus:
1707 case GDK_KEY_equal:
1708 case GDK_KEY_KP_Add:
1712 } else if (editor_tool_has_count(ett)) {
1713 int count = editor_tool_get_count(ett);
1714 editor_tool_set_count(ett, count + 1);
1715 }
1716 break;
1717 case GDK_KEY_minus:
1718 case GDK_KEY_underscore:
1723 } else if (editor_tool_has_count(ett)) {
1724 int count = editor_tool_get_count(ett);
1725 editor_tool_set_count(ett, count - 1);
1726 }
1727 break;
1728 case GDK_KEY_1:
1729 case GDK_KEY_2:
1730 case GDK_KEY_3:
1731 case GDK_KEY_4:
1732 case GDK_KEY_5:
1733 case GDK_KEY_6:
1734 case GDK_KEY_7:
1735 case GDK_KEY_8:
1736 case GDK_KEY_9:
1738 editor_tool_set_size(ett, ev->keyval - GDK_KEY_1 + 1);
1739 } else if (editor_tool_has_count(ett)) {
1740 editor_tool_set_count(ett, ev->keyval - GDK_KEY_1 + 1);
1741 }
1742 break;
1743 case GDK_KEY_space:
1745 break;
1746 case GDK_KEY_Tab:
1748 break;
1749 case GDK_KEY_F1:
1750 case GDK_KEY_F2:
1751 case GDK_KEY_F3:
1752 case GDK_KEY_F4:
1753 case GDK_KEY_F5:
1754 case GDK_KEY_F6:
1755 case GDK_KEY_F7:
1756 case GDK_KEY_F8:
1757 case GDK_KEY_F9:
1758 case GDK_KEY_F10:
1759 case GDK_KEY_F11:
1760 case GDK_KEY_F12:
1761 return FALSE; /* Allow default handler. */
1762 break;
1763 default:
1764 return TRUE; /* Gobbled... */
1765 break;
1766 }
1767
1770 }
1771
1773
1774 return TRUE;
1775}
1776
1777/************************************************************************/
1784
1785/************************************************************************/
1789{
1790 return editor_toolbar;
1791}
1792
1793/************************************************************************/
1797{
1798 struct property_editor *pe;
1799 struct editbar *eb;
1800 struct editinfobox *ei;
1801
1803 if (eb != NULL) {
1805 }
1806
1808 if (ei != NULL) {
1810 }
1811
1813 if (!editor_is_active()) {
1816 }
1817}
1818
1819/************************************************************************/
1823{
1824 if (editor_toolbar == NULL) {
1826 }
1827 if (editor_infobox == NULL) {
1829 }
1830}
1831
1832/************************************************************************/
1836{
1837 struct editbar *eb = editgui_get_editbar();
1839
1840 if (ei != NULL) {
1841 /* We have extra ref for ei->widget that has protected
1842 * it from getting destroyed when editinfobox_refresh()
1843 * moves widgets around. Free that extra ref here. */
1844 g_object_unref(ei->widget);
1845 }
1846
1848}
1849
1850/************************************************************************/
1854{
1855 return editor_infobox;
1856}
1857
1858/************************************************************************/
1867
1868/************************************************************************/
1886
1887/************************************************************************/
1891{
1892 struct property_editor *pe;
1893
1896 property_editor_clear(pe); /* And clear it. */
1897}
1898
1899/************************************************************************/
1907void editgui_notify_object_changed(int objtype, int object_id, bool removal)
1908{
1909 struct property_editor *pe;
1910
1911 if (!editor_is_active()) {
1912 return;
1913 }
1914
1916 property_editor_handle_object_changed(pe, objtype, object_id, removal);
1917}
1918
1919/************************************************************************/
1923{
1924 struct property_editor *pe;
1925
1926 if (!editor_is_active()) {
1927 return;
1928 }
1929
1932}
int send_chat_printf(const char *format,...)
int send_chat(const char *message)
bool client_is_global_observer(void)
int client_player_number(void)
#define client_player()
char * incite_cost
Definition comments.c:76
int objtype
Definition editgui_g.h:28
editgui_notify_object_changed
Definition editgui_g.h:27
int int id
Definition editgui_g.h:28
int edit_buffer_get_status_string(const struct edit_buffer *ebuf, char *buf, int buflen)
Definition editor.c:1870
bool editor_is_active(void)
Definition editor.c:346
int editor_tool_get_size(enum editor_tool_type ett)
Definition editor.c:1218
void editor_set_tool(enum editor_tool_type ett)
Definition editor.c:270
void editor_mouse_button_press(int canvas_x, int canvas_y, int button, int modifiers)
Definition editor.c:661
void editor_mouse_move(int canvas_x, int canvas_y, int modifiers)
Definition editor.c:866
enum editor_tool_mode editor_tool_get_mode(enum editor_tool_type ett)
Definition editor.c:335
void editor_tool_set_count(enum editor_tool_type ett, int count)
Definition editor.c:1263
void editor_tool_toggle_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:1041
const char * editor_tool_get_value_name(enum editor_tool_type emt, int value)
Definition editor.c:1172
int editor_tool_get_value(enum editor_tool_type ett)
Definition editor.c:409
struct edit_buffer * editor_get_copy_buffer(void)
Definition editor.c:1767
void editor_tool_set_applied_player(enum editor_tool_type ett, int player_no)
Definition editor.c:1352
const char * editor_tool_get_mode_name(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:1778
void editor_tool_cycle_mode(enum editor_tool_type ett)
Definition editor.c:1058
int editor_tool_get_count(enum editor_tool_type ett)
Definition editor.c:1252
void editor_tool_set_size(enum editor_tool_type ett, int size)
Definition editor.c:1229
const char * editor_get_mode_tooltip(enum editor_tool_mode etm)
Definition editor.c:1815
bool editor_tool_is_usable(enum editor_tool_type ett)
Definition editor.c:359
enum editor_tool_type editor_get_tool(void)
Definition editor.c:286
bool editor_tool_has_applied_player(enum editor_tool_type ett)
Definition editor.c:1365
bool editor_tool_has_size(enum editor_tool_type ett)
Definition editor.c:1207
void editor_tool_set_value(enum editor_tool_type ett, int value)
Definition editor.c:397
bool editor_tool_has_value(enum editor_tool_type ett)
Definition editor.c:385
const char * editor_tool_get_tooltip(enum editor_tool_type ett)
Definition editor.c:1327
void editor_mouse_button_release(int canvas_x, int canvas_y, int button, int modifiers)
Definition editor.c:798
struct sprite * editor_tool_get_sprite(enum editor_tool_type ett)
Definition editor.c:1275
void editor_apply_tool_to_selection(void)
Definition editor.c:1128
bool editor_tool_has_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:313
int editor_tool_get_applied_player(enum editor_tool_type ett)
Definition editor.c:1341
bool editor_tool_has_count(enum editor_tool_type ett)
Definition editor.c:1241
struct sprite * editor_get_mode_sprite(enum editor_tool_mode etm)
Definition editor.c:1837
const char * editor_tool_get_name(enum editor_tool_type ett)
Definition editor.c:1159
void editor_tool_set_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:298
editor_tool_mode
Definition editor.h:52
@ ETM_PASTE
Definition editor.h:56
@ NUM_EDITOR_TOOL_MODES
Definition editor.h:58
@ ETM_ERASE
Definition editor.h:54
@ ETM_PAINT
Definition editor.h:53
@ ETM_COPY
Definition editor.h:55
@ MOUSE_BUTTON_OTHER
Definition editor.h:124
@ MOUSE_BUTTON_LEFT
Definition editor.h:126
@ MOUSE_BUTTON_RIGHT
Definition editor.h:128
@ MOUSE_BUTTON_MIDDLE
Definition editor.h:127
@ OBJTYPE_PLAYER
Definition editor.h:30
@ OBJTYPE_GAME
Definition editor.h:31
@ EKM_CTRL
Definition editor.h:120
@ EKM_SHIFT
Definition editor.h:118
@ EKM_ALT
Definition editor.h:119
@ EKM_NONE
Definition editor.h:117
editor_tool_type
Definition editor.h:36
@ ETT_ROAD
Definition editor.h:40
@ ETT_TERRAIN_SPECIAL
Definition editor.h:39
@ ETT_UNIT
Definition editor.h:42
@ ETT_VISION
Definition editor.h:44
@ ETT_STARTPOS
Definition editor.h:46
@ NUM_EDITOR_TOOL_TYPES
Definition editor.h:49
@ ETT_CITY
Definition editor.h:43
@ ETT_COPYPASTE
Definition editor.h:47
@ ETT_TERRAIN_RESOURCE
Definition editor.h:38
@ ETT_MILITARY_BASE
Definition editor.h:41
@ ETT_TERRAIN
Definition editor.h:37
struct extra_type * extra_by_number(int id)
Definition extras.c:183
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_index(_e_)
Definition extras.h:183
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
#define EC_SPECIAL
Definition fc_types.h:822
#define _(String)
Definition fcintl.h:67
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
static void refresh_all_buttons(struct editbar *eb)
Definition editgui.c:113
static void editbar_player_properties_button_clicked(GtkButton *b, gpointer userdata)
Definition editgui.c:463
tool_applied_player_columns
Definition editgui.c:72
@ TAP_COL_FLAG
Definition editgui.c:73
@ TAP_COL_NAME
Definition editgui.c:74
@ TAP_COL_PLAYER_NO
Definition editgui.c:75
@ TAP_NUM_COLS
Definition editgui.c:77
static bool editgui_run_tool_selection(enum editor_tool_type ett)
Definition editgui.c:356
static void editinfobox_refresh(struct editinfobox *ei)
Definition editgui.c:1519
void editgui_popup_properties(const struct tile_list *tiles, int objtype)
Definition editgui.c:1875
void editgui_notify_object_created(int tag, int id)
Definition editgui.c:1922
gboolean handle_edit_key_release(GdkEventKey *ev)
Definition editgui.c:1780
static void clear_tool_stores(struct editbar *eb)
Definition editgui.c:752
static int convert_modifiers(int gdk_event_state)
Definition editgui.c:898
static void try_to_set_editor_tool(enum editor_tool_type ett)
Definition editgui.c:177
static void clear_tool_store(GtkListStore *store)
Definition editgui.c:730
gboolean handle_edit_mouse_button_release(GdkEventButton *ev)
Definition editgui.c:956
static gboolean handle_edit_key_press_with_ctrl(GdkEventKey *ev)
Definition editgui.c:1606
gboolean handle_edit_key_press(GdkEventKey *ev)
Definition editgui.c:1662
static int tool_value_selector_run(struct tool_value_selector *tvs)
Definition editgui.c:319
static void editbar_add_mode_button(struct editbar *eb, enum editor_tool_mode etm)
Definition editgui.c:478
static void editbar_tool_button_toggled(GtkToggleButton *tb, gpointer userdata)
Definition editgui.c:201
static void editbar_add_tool_button(struct editbar *eb, enum editor_tool_type ett)
Definition editgui.c:407
void editgui_create_widgets(void)
Definition editgui.c:1822
static struct editbar * editbar_create(void)
Definition editgui.c:519
void editgui_popdown_all(void)
Definition editgui.c:1890
static void editbar_reload_tileset(struct editbar *eb)
Definition editgui.c:765
static void tool_value_selector_treeview_row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data)
Definition editgui.c:980
static void editinfobox_spin_button_value_changed(GtkSpinButton *spinbutton, gpointer userdata)
Definition editgui.c:1106
static void refresh_tool_applied_player_combo(struct editinfobox *ei)
Definition editgui.c:1338
static void editbar_mode_button_toggled(GtkToggleButton *tb, gpointer userdata)
Definition editgui.c:154
static void editinfobox_tool_applied_player_changed(GtkComboBox *combo, gpointer userdata)
Definition editgui.c:1142
static gboolean handle_edit_key_press_with_shift(GdkEventKey *ev)
Definition editgui.c:1614
static void refresh_all_tool_value_selectors(struct editbar *eb)
Definition editgui.c:651
spin_button_types
Definition editgui.c:80
@ SPIN_BUTTON_COUNT
Definition editgui.c:82
@ SPIN_BUTTON_SIZE
Definition editgui.c:81
gboolean handle_edit_mouse_button_press(GdkEventButton *ev)
Definition editgui.c:940
static struct tool_value_selector * create_tool_value_selector(struct editbar *eb_parent, enum editor_tool_type ett)
Definition editgui.c:994
static GdkPixbuf * create_terrain_pixbuf(struct terrain *pterrain)
Definition editgui.c:696
static gboolean editbar_tool_button_mouse_click(GtkWidget *w, GdkEventButton *ev, gpointer userdata)
Definition editgui.c:389
static void replace_widget(GtkWidget *old, GtkWidget *new)
Definition editgui.c:1501
static void editbar_player_pov_combobox_changed(GtkComboBox *combo, gpointer user_data)
Definition editgui.c:277
struct editinfobox * editgui_get_editinfobox(void)
Definition editgui.c:1853
static int convert_mouse_button(int gdk_mouse_button)
Definition editgui.c:918
gboolean handle_edit_mouse_move(GdkEventMotion *ev)
Definition editgui.c:971
tool_value_selector_columns
Definition editgui.c:56
@ TVS_COL_ID
Definition editgui.c:58
@ TVS_COL_NAME
Definition editgui.c:59
@ TVS_COL_IMAGE
Definition editgui.c:57
@ TVS_NUM_COLS
Definition editgui.c:61
player_pov_combo_columns
Definition editgui.c:64
@ PPV_COL_FLAG
Definition editgui.c:65
@ PPV_COL_PLAYER_NO
Definition editgui.c:67
@ PPV_COL_NAME
Definition editgui.c:66
@ PPV_NUM_COLS
Definition editgui.c:69
void editgui_refresh(void)
Definition editgui.c:1796
static void editbar_refresh(struct editbar *eb)
Definition editgui.c:669
static struct editinfobox * editor_infobox
Definition editgui.c:107
static struct editbar * editor_toolbar
Definition editgui.c:106
static gboolean editinfobox_handle_tool_image_button_press(GtkWidget *evbox, GdkEventButton *ev, gpointer data)
Definition editgui.c:1082
struct editbar * editgui_get_editbar(void)
Definition editgui.c:1788
static void refresh_tool_value_selector(struct editbar *eb, enum editor_tool_type ett)
Definition editgui.c:612
static struct editinfobox * editinfobox_create(void)
Definition editgui.c:1167
static void refresh_player_pov_indicator(struct editbar *eb)
Definition editgui.c:223
void editgui_tileset_changed(void)
Definition editgui.c:1862
void editgui_free(void)
Definition editgui.c:1835
static gboolean editinfobox_handle_mode_image_button_press(GtkWidget *evbox, GdkEventButton *ev, gpointer data)
Definition editgui.c:1093
static GdkPixbuf * get_tool_value_pixbuf(enum editor_tool_type ett, int value)
Definition editgui.c:1406
static GdkPixbuf * get_tool_mode_pixbuf(enum editor_tool_mode etm)
Definition editgui.c:1477
void property_editor_handle_object_changed(struct property_editor *pe, enum editor_object_type objtype, int object_id, bool remove)
Definition editprop.c:6322
void property_editor_handle_object_created(struct property_editor *pe, int tag, int object_id)
Definition editprop.c:6344
void property_editor_popup(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6292
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
void property_editor_popdown(struct property_editor *pe)
Definition editprop.c:6310
void property_editor_load_tiles(struct property_editor *pe, const struct tile_list *tiles)
Definition editprop.c:6256
void property_editor_clear(struct property_editor *pe)
Definition editprop.c:6362
GtkWidget * unit_info_box
Definition gui_main.c:153
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
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
GdkPixbuf * create_extra_pixbuf(const struct extra_type *pextra)
Definition sprite.c:494
#define fc_assert_ret(condition)
Definition log.h:192
void put_drawn_sprites(struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y, int count, struct drawn_sprite *pdrawn, bool fog)
#define fc_calloc(n, esz)
Definition mem.h:38
#define NO_NATION_SELECTED
Definition nation.h:30
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_count(void)
Definition player.c:817
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
size_t size
Definition specvec.h:72
cairo_surface_t * surface
Definition canvas.h:23
struct sprite * city
Definition tilespec.h:353
struct sprite * vision
Definition tilespec.h:354
struct sprite * copypaste
Definition tilespec.h:347
struct sprite * startpos
Definition tilespec.h:348
struct sprite * properties
Definition tilespec.h:356
char name[MAX_LEN_NAME]
Definition player.h:251
GtkWidget * view
Definition editgui.c:91
struct editbar * editbar_parent
Definition editgui.c:86
GtkListStore * store
Definition editgui.c:90
GtkWidget * dialog
Definition editgui.c:88
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
#define terrain_type_iterate(_p)
Definition terrain.h:266
#define terrain_type_iterate_end
Definition terrain.h:272
int fill_basic_terrain_layer_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int layer, struct terrain *pterrain)
Definition tilespec.c:7395
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7029
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
const struct editor_sprites * get_editor_sprites(const struct tileset *t)
Definition tilespec.c:7173
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1566
#define unit_type_iterate(_p)
Definition unittype.h:862
#define unit_type_iterate_end
Definition unittype.h:869