Freeciv-3.4
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-5.0 */
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
86 struct editbar *editbar_parent;
87
89
92};
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;
185
189 _("The current ruleset does not define any "
190 "objects corresponding to this editor tool."));
192 blocking_dialog(dialog);
194 } else {
196 }
197}
198
199/************************************************************************/
204{
205 gboolean active;
207
210
211 if (active) {
214 }
215}
216
217/************************************************************************/
225{
226 GtkListStore *store;
227 GdkPixbuf *flag;
229 GtkWidget *combo;
230 int index = -1, i;
231
232 if (eb == NULL || eb->player_pov_store == NULL) {
233 return;
234 }
235
236 store = eb->player_pov_store;
238
240 gtk_list_store_set(store, &iter, PPV_COL_NAME, _("Global Observer"),
241 PPV_COL_PLAYER_NO, -1, -1);
242
243 i = 1;
244 players_iterate(pplayer) {
247 PPV_COL_PLAYER_NO, player_number(pplayer), -1);
248
249 if (pplayer->nation != NO_NATION_SELECTED) {
250 flag = get_flag(pplayer->nation);
251
252 if (flag != NULL) {
253 gtk_list_store_set(store, &iter, PPV_COL_FLAG, flag, -1);
254 g_object_unref(flag);
255 }
256 }
257 if (pplayer == client_player()) {
258 index = i;
259 }
260 i++;
262
264 index = 0;
265 }
266
267 combo = eb->player_pov_combobox;
269}
270
271/************************************************************************/
279 gpointer user_data)
280{
281 struct editbar *eb = user_data;
282 int id;
283 struct player *pplayer;
285 GtkTreeModel *model;
286
287 if (eb == NULL || eb->widget == NULL
288 || !gtk_widget_get_visible(eb->widget)) {
289 return;
290 }
291
292 if (!gtk_combo_box_get_active_iter(combo, &iter)) {
293 return;
294 }
295
296 model = gtk_combo_box_get_model(combo);
297 gtk_tree_model_get(model, &iter, PPV_COL_PLAYER_NO, &id, -1);
298
299 if ((client_is_global_observer() && id == -1)
300 || client_player_number() == id) {
301 return;
302 }
303
304 /* Ugh... hard-coded server command strings. :( */
305 if (id == -1) {
306 send_chat("/observe");
307 return;
308 }
309
310 pplayer = player_by_number(id);
311 if (pplayer != NULL) {
312 send_chat_printf("/take \"%s\"", pplayer->name);
313 }
314}
315
316/************************************************************************/
321{
322 gint res;
323 GtkWidget *dialog;
326 GtkTreeModel *model;
327 int id;
328
329 if (tvs == nullptr) {
330 return -1;
331 }
332
333 dialog = tvs->dialog;
334 res = blocking_dialog(dialog);
336
337 if (res != GTK_RESPONSE_ACCEPT) {
338 return -1;
339 }
340
342 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) {
343 return -1;
344 }
345
346 gtk_tree_model_get(model, &iter, TVS_COL_ID, &id, -1);
347
348 return id;
349}
350
351/************************************************************************/
358{
359 struct editbar *eb;
360 struct tool_value_selector *tvs;
361 int res = -1;
362
364 if (eb == NULL || !(ett < NUM_EDITOR_TOOL_TYPES)) {
365 return FALSE;
366 }
367
369 return FALSE;
370 }
371
372 tvs = eb->tool_selectors[ett];
373 if (!tvs) {
374 return FALSE;
375 }
376
378
379 if (res >= 0) {
382 }
383
384 return TRUE;
385}
386
387/************************************************************************/
391 int n_press,
392 double x, double y, gpointer data)
393{
395}
396
397/************************************************************************/
403{
405 GtkWidget *pic, *button, *hbox;
407 struct sprite *sprite;
408 int i;
411
412 if (!eb || !(ett < NUM_EDITOR_TOOL_TYPES)) {
413 return;
414 }
415
416 for (i = 0; i < NUM_EDITOR_TOOL_TYPES; i++) {
417 if (eb->tool_buttons[i] != NULL) {
418 parent = GTK_TOGGLE_BUTTON(eb->tool_buttons[i]);
419 break;
420 }
421 }
422
423 if (parent == NULL) {
424 button = gtk_toggle_button_new();
425 } else {
426 button = gtk_toggle_button_new();
429 }
430
436
440 gtk_size_group_add_widget(eb->size_group, button);
443
444 g_signal_connect(button, "toggled",
447
451 g_signal_connect(controller, "pressed",
455
456 hbox = eb->widget;
457 gtk_box_append(GTK_BOX(hbox), button);
458 eb->tool_buttons[ett] = button;
459
461 eb->tool_selectors[ett] = create_tool_value_selector(eb, ett);
462 }
463}
464
465/************************************************************************/
478
479/************************************************************************/
485{
487 GtkWidget *pic, *button, *hbox;
488 struct sprite *sprite;
489 const char *tooltip;
490
491 if (!eb || !(etm < NUM_EDITOR_TOOL_MODES)) {
492 return;
493 }
494
495 button = gtk_toggle_button_new();
496
502
506 if (tooltip != NULL) {
508 }
509 gtk_size_group_add_widget(eb->size_group, button);
512
513 g_signal_connect(button, "toggled",
516
517 hbox = eb->widget;
518 gtk_box_append(GTK_BOX(hbox), button);
519 eb->mode_buttons[etm] = button;
520}
521
522/************************************************************************/
525static struct editbar *editbar_create(void)
526{
527 struct editbar *eb;
528 GtkWidget *hbox, *button, *combo, *pic, *separator, *vgrid;
529 GtkListStore *store;
532 const struct editor_sprites *sprites;
533 int grid_row = 0;
534
535 eb = fc_calloc(1, sizeof(struct editbar));
536
538 eb->widget = hbox;
540
541 sprites = get_editor_sprites(tileset);
542
544
547
558
561
562 /* Player POV indicator. */
567
571 G_TYPE_INT);
572 eb->player_pov_store = store;
573
575 gtk_widget_add_css_class(GTK_WIDGET(combo), "large-pixbufs");
576
580 cell, "pixbuf", PPV_COL_FLAG);
581
585 cell, "text", PPV_COL_NAME);
586
587 gtk_widget_set_size_request(combo, 140, -1);
588 g_signal_connect(combo, "changed",
590
592 _("Switch player point-of-view. Use this to edit "
593 "from the perspective of different players, or "
594 "even as a global observer."));
595 gtk_grid_attach(GTK_GRID(vgrid), combo, 0, grid_row++, 1, 1);
596 eb->player_pov_combobox = combo;
597
598 /* Property editor button. */
599 button = gtk_button_new();
604 gtk_widget_set_tooltip_text(button, _("Show the property editor."));
605 gtk_size_group_add_widget(eb->size_group, button);
608 g_signal_connect(button, "clicked",
610 gtk_box_append(GTK_BOX(hbox), button);
611
612 return eb;
613}
614
615/************************************************************************/
621{
624 GtkTreeModel *model;
625 int value, store_value;
626 struct tool_value_selector *tvs;
627
629 return;
630 }
631
632 tvs = eb->tool_selectors[ett];
633
634 if (!tvs) {
635 return;
636 }
637
638 value = editor_tool_get_value(ett);
639 model = GTK_TREE_MODEL(tvs->store);
640 if (!gtk_tree_model_get_iter_first(model, &iter)) {
641 return;
642 }
643
644 do {
646 if (value == store_value) {
649 break;
650 }
651 } while (gtk_tree_model_iter_next(model, &iter));
652}
653
654/************************************************************************/
659{
660 int ett;
661
662 if (!eb) {
663 return;
664 }
665
666 for (ett = 0; ett < NUM_EDITOR_TOOL_TYPES; ett++) {
669 }
670 }
671}
672
673/************************************************************************/
676static void editbar_refresh(struct editbar *eb)
677{
678 if (eb == nullptr || eb->widget == nullptr) {
679 return;
680 }
681
682 if (!editor_is_active()) {
684 return;
685 }
686
690
692}
693
694/************************************************************************/
703static GdkPixbuf *create_terrain_pixbuf(struct terrain *pterrain)
704{
705 int w, h, i;
708 cairo_t *cr;
709
712
714
717 cairo_paint(cr);
718 cairo_destroy(cr);
719
720 for (i = 0; i < 3; i++) {
721 struct drawn_sprite sprs[80];
723 i, pterrain);
724
725 put_drawn_sprites(&canvas, 1.0, 0, 0, count, sprs, FALSE);
726 }
727
730
731 return pixbuf;
732}
733
734/************************************************************************/
738{
740 GtkTreeModel *model = GTK_TREE_MODEL(store);
741
742 if (gtk_tree_model_get_iter_first(model, &iter)) {
743 do {
745
747 if (pixbuf != NULL) {
749 }
750 } while (gtk_tree_model_iter_next(model, &iter));
751 }
752
754}
755
756/************************************************************************/
759static void clear_tool_stores(struct editbar *eb)
760{
761 clear_tool_store(eb->tool_selectors[ETT_TERRAIN]->store);
762 clear_tool_store(eb->tool_selectors[ETT_TERRAIN_RESOURCE]->store);
763 clear_tool_store(eb->tool_selectors[ETT_TERRAIN_SPECIAL]->store);
764 clear_tool_store(eb->tool_selectors[ETT_ROAD]->store);
765 clear_tool_store(eb->tool_selectors[ETT_MILITARY_BASE]->store);
766 clear_tool_store(eb->tool_selectors[ETT_UNIT]->store);
767}
768
769/************************************************************************/
773{
775 GtkListStore *store;
777 struct sprite *sprite;
778 struct tool_value_selector *tvs;
779
780 if (eb == NULL || tileset == NULL) {
781 return;
782 }
783
785
786 /* Reload terrains. */
787
788 tvs = eb->tool_selectors[ETT_TERRAIN];
789 store = tvs->store;
790
791 terrain_type_iterate(pterrain) {
794 TVS_COL_ID, terrain_number(pterrain),
796 -1);
797 pixbuf = create_terrain_pixbuf(pterrain);
798 if (pixbuf != NULL) {
801 }
803
804
805 /* Reload terrain resources. */
806
807 tvs = eb->tool_selectors[ETT_TERRAIN_RESOURCE];
808 store = tvs->store;
809
813 TVS_COL_ID, extra_index(pextra),
815 -1);
816 pixbuf = create_extra_pixbuf(pextra);
817 if (pixbuf != NULL) {
820 }
822
823 /* Reload terrain specials. */
824
825 tvs = eb->tool_selectors[ETT_TERRAIN_SPECIAL];
826 store = tvs->store;
827
831 TVS_COL_ID, extra_index(pextra),
833 -1);
834 pixbuf = create_extra_pixbuf(pextra);
835 if (pixbuf != NULL) {
838 }
840
841 /* Reload roads. */
842
843 tvs = eb->tool_selectors[ETT_ROAD];
844 store = tvs->store;
845
849 TVS_COL_ID, extra_index(pextra),
851 -1);
852 pixbuf = create_extra_pixbuf(pextra);
853 if (pixbuf != NULL) {
856 }
858
859 /* Reload military bases. */
860
861 tvs = eb->tool_selectors[ETT_MILITARY_BASE];
862 store = tvs->store;
863
867 TVS_COL_ID, extra_index(pextra),
869 -1);
870 pixbuf = create_extra_pixbuf(pextra);
871 if (pixbuf != NULL) {
874 }
876
877
878 /* Reload unit types. */
879
880 tvs = eb->tool_selectors[ETT_UNIT];
881 store = tvs->store;
882
888 -1);
891 if (sprite == NULL) {
892 continue;
893 }
895 if (pixbuf != NULL) {
898 }
900}
901
902/************************************************************************/
906{
907 int modifiers = EKM_NONE;
908
911 }
914 }
917 }
918
919 return modifiers;
920}
921
922/************************************************************************/
938
939/************************************************************************/
954
955/************************************************************************/
968
969/************************************************************************/
981
982/************************************************************************/
985static struct tool_value_selector *
988{
989 struct tool_value_selector *tvs;
990 GtkWidget *vbox, *view, *scrollwin;
995
996 tvs = fc_calloc(1, sizeof(struct tool_value_selector));
997
998 tvs->editbar_parent = eb;
999
1000 tvs->dialog = gtk_dialog_new_with_buttons(_("Select Tool Value"),
1003 _("_OK"), GTK_RESPONSE_ACCEPT,
1004 _("_Cancel"), GTK_RESPONSE_REJECT,
1005 NULL);
1007
1010 G_TYPE_INT,
1012 tvs->store = store;
1013
1022
1026 gtk_widget_add_css_class(GTK_WIDGET(view), "large-pixbufs");
1027 g_signal_connect(view, "row-activated",
1029
1032
1035 cell, "pixbuf",
1042
1045 "text", TVS_COL_ID, NULL);
1052
1055 "text", TVS_COL_NAME, NULL);
1062
1064 tvs->view = view;
1065
1066 /* Show everything but the window itself. */
1068
1069 return tvs;
1070}
1071
1072/************************************************************************/
1077 int n_press,
1078 double x, double y)
1079{
1081
1082 return TRUE;
1083}
1084
1085/************************************************************************/
1090 int n_press,
1091 double x, double y)
1092{
1095
1096 return TRUE;
1097}
1098
1099/************************************************************************/
1104{
1105 struct editinfobox *ei;
1106 int which, value;
1107 enum editor_tool_type ett;
1108
1110
1111 if (!ei) {
1112 return;
1113 }
1114
1117 ett = editor_get_tool();
1118
1119 switch (which) {
1120 case SPIN_BUTTON_SIZE:
1121 editor_tool_set_size(ett, value);
1122 break;
1123 case SPIN_BUTTON_COUNT:
1124 editor_tool_set_count(ett, value);
1125 break;
1126 default:
1127 return;
1128 break;
1129 }
1130
1132}
1133
1134/************************************************************************/
1140{
1141 struct editinfobox *ei = userdata;
1143 GtkTreeModel *model;
1144 int player_no = -1;
1145
1146 if (ei == NULL) {
1147 return;
1148 }
1149
1150 if (!gtk_combo_box_get_active_iter(combo, &iter)) {
1151 return;
1152 }
1153
1154 model = gtk_combo_box_get_model(combo);
1155 gtk_tree_model_get(model, &iter, TAP_COL_PLAYER_NO, &player_no, -1);
1156
1158}
1159
1160/************************************************************************/
1164{
1165 GtkWidget *label, *vbox, *frame, *hgrid, *vbox2, *pic;
1166 GtkWidget *spin, *combo;
1167 GtkListStore *store;
1170 struct editinfobox *ei;
1171 char buf[128];
1172 int grid_col = 0;
1173
1174 ei = fc_calloc(1, sizeof(*ei));
1175
1176 /* If you turn this to something else than GtkFrame, also adjust
1177 * editgui.c replace_widget() code that replaces widget in it. */
1178 frame = gtk_frame_new(_("Editor Tool"));
1180 gtk_widget_set_margin_end(frame, 4);
1181 gtk_widget_set_margin_top(frame, 4);
1183 ei->widget = frame;
1184
1190 gtk_frame_set_child(GTK_FRAME(frame), vbox);
1191
1192 /* Tool section */
1193 hgrid = gtk_grid_new();
1196
1197 pic = gtk_picture_new();
1198 gtk_widget_set_tooltip_text(pic, _("Click to change value if applicable."));
1199
1201 g_signal_connect(controller, "pressed",
1203 NULL);
1205
1206 gtk_grid_attach(GTK_GRID(hgrid), pic, grid_col++, 0, 1, 1);
1207 ei->tool_pic = pic;
1208
1211
1212 label = gtk_label_new(NULL);
1215 gtk_box_append(GTK_BOX(vbox2), label);
1216 ei->tool_label = label;
1217
1218 label = gtk_label_new(NULL);
1221 gtk_box_append(GTK_BOX(vbox2), label);
1222 ei->tool_value_label = label;
1223
1224 /* Mode section */
1225 hgrid = gtk_grid_new();
1226 grid_col = 0;
1229
1230 pic = gtk_picture_new();
1231 gtk_widget_set_tooltip_text(pic, _("Click to change tool mode."));
1232
1234 g_signal_connect(controller, "pressed",
1236 NULL);
1238
1239 gtk_grid_attach(GTK_GRID(hgrid), pic, grid_col++, 0, 1, 1);
1240 ei->mode_pic = pic;
1241
1244
1245 label = gtk_label_new(NULL);
1246 fc_snprintf(buf, sizeof(buf), "<span weight=\"bold\">%s</span>",
1247 _("Mode"));
1251 gtk_box_append(GTK_BOX(vbox2), label);
1252
1253 label = gtk_label_new(NULL);
1256 gtk_box_append(GTK_BOX(vbox2), label);
1257 ei->mode_label = label;
1258
1259 /* Spinner section */
1260 hgrid = gtk_grid_new();
1261 grid_col = 0;
1264 ei->size_hbox = hgrid;
1267 _("Use this to change the \"size\" parameter for the tool. "
1268 "This parameter controls for example the half-width "
1269 "of the square of tiles that will be affected by the "
1270 "tool, or the size of a created city."));
1271 g_signal_connect(spin, "value-changed",
1275 ei->size_spin_button = spin;
1276 label = gtk_label_new(_("Size"));
1277 gtk_grid_attach(GTK_GRID(hgrid), label, grid_col++, 0, 1, 1);
1278
1279 hgrid = gtk_grid_new();
1280 grid_col = 0;
1283 ei->count_hbox = hgrid;
1286 _("Use this to change the tool's \"count\" parameter. "
1287 "This controls for example how many units are placed "
1288 "at once with the unit tool."));
1289 g_signal_connect(spin, "value-changed",
1293 ei->count_spin_button = spin;
1294 label = gtk_label_new(_("Count"));
1295 gtk_grid_attach(GTK_GRID(hgrid), label, grid_col++, 0, 1, 1);
1296
1297 /* combo section */
1301 G_TYPE_INT);
1302 ei->tool_applied_player_store = store;
1304 gtk_widget_add_css_class(GTK_WIDGET(combo), "large-pixbufs");
1305
1309 cell, "pixbuf", TAP_COL_FLAG);
1310
1314 cell, "text", TAP_COL_NAME);
1315
1316 gtk_widget_set_size_request(combo, 132, -1);
1317 g_signal_connect(combo, "changed",
1319
1321 _("Use this to change the \"applied player\" tool parameter. "
1322 "This controls for example under which player units and cities "
1323 "are created."));
1324 gtk_box_append(GTK_BOX(vbox), combo);
1325 ei->tool_applied_player_combobox = combo;
1326
1327 /* We add a ref to the editinfobox widget so that it is
1328 * not destroyed when replaced by the unit info box when
1329 * we leave edit mode. See editinfobox_refresh() call to replace_widget() */
1330 g_object_ref(ei->widget);
1331
1332 /* The edit info box starts with no parent, so we have to
1333 * show its internal widgets manually. */
1334 gtk_widget_set_visible(ei->widget, TRUE);
1335
1336 return ei;
1337}
1338
1339/************************************************************************/
1344{
1345 enum editor_tool_type ett;
1346 GtkListStore *store;
1347 GtkWidget *combo;
1349 GdkPixbuf *flag;
1350 int apno, index, i;
1351
1352 if (!ei) {
1353 return;
1354 }
1355
1356 ett = editor_get_tool();
1357 combo = ei->tool_applied_player_combobox;
1358 store = ei->tool_applied_player_store;
1359
1360 if (!combo || !store) {
1361 return;
1362 }
1363
1366 return;
1367 }
1368
1369 gtk_list_store_clear(store);
1370
1372 index = -1;
1373 i = 0;
1374
1375 players_iterate(pplayer) {
1376 gtk_list_store_append(store, &iter);
1377 gtk_list_store_set(store, &iter,
1379 TAP_COL_NAME, player_name(pplayer), -1);
1380
1381 if (pplayer->nation != NO_NATION_SELECTED) {
1382 flag = get_flag(pplayer->nation);
1383
1384 if (flag != NULL) {
1385 gtk_list_store_set(store, &iter, TAP_COL_FLAG, flag, -1);
1386 g_object_unref(flag);
1387 }
1388 }
1389 if (apno == player_number(pplayer)) {
1390 index = i;
1391 }
1392 i++;
1394
1395 if (index == -1) {
1396 if (player_count() > 0) {
1397 index = 0;
1398 }
1400 }
1403}
1404
1405/************************************************************************/
1412 int value)
1413{
1414 struct sprite *sprite = NULL;
1416 struct terrain *pterrain;
1417 struct unit_type *putype;
1418 const struct editor_sprites *sprites;
1419
1420 sprites = get_editor_sprites(tileset);
1421 if (!sprites) {
1422 return NULL;
1423 }
1424
1425 switch (ett) {
1426 case ETT_TERRAIN:
1427 pterrain = terrain_by_number(value);
1428 if (pterrain) {
1429 pixbuf = create_terrain_pixbuf(pterrain);
1430 }
1431 break;
1434 case ETT_ROAD:
1435 case ETT_MILITARY_BASE:
1436 if (value >= 0) {
1438 }
1439 break;
1440 case ETT_UNIT:
1441 putype = utype_by_number(value);
1442 if (putype) {
1445 }
1446 break;
1447 case ETT_CITY:
1448 sprite = sprites->city;
1449 break;
1450 case ETT_VISION:
1451 sprite = sprites->vision;
1452 break;
1453 case ETT_STARTPOS:
1454 sprite = sprites->startpos;
1455 break;
1456 case ETT_COPYPASTE:
1457 sprite = sprites->copypaste;
1458 break;
1459 default:
1460 break;
1461 }
1462
1463 if (sprite) {
1465 /*
1466 if (pixbuf) {
1467 g_object_ref(pixbuf);
1468 }
1469 */
1470 sprite = NULL;
1471 }
1472
1473 return pixbuf;
1474}
1475
1476/************************************************************************/
1483{
1484 struct sprite *sprite = NULL;
1486
1488
1489 if (sprite) {
1491 /*
1492 if (pixbuf) {
1493 g_object_ref(pixbuf);
1494 }
1495 */
1496 }
1497
1498 return pixbuf;
1499}
1500
1501/************************************************************************/
1507{
1509
1511 if (parent == nullptr) {
1512 return;
1513 }
1514
1516
1517 if (GTK_IS_FRAME(parent)) {
1519 } else {
1521
1524 }
1525
1527}
1528
1529/************************************************************************/
1533{
1535 GtkLabel *label;
1536 enum editor_tool_type ett;
1537 enum editor_tool_mode etm;
1538 int value;
1539 char buf[256];
1540
1541 if (ei == NULL) {
1542 return;
1543 }
1544
1545 if (!editor_is_active()) {
1547 return;
1548 }
1549
1550 ett = editor_get_tool();
1552 value = editor_tool_get_value(ett);
1553
1554 label = GTK_LABEL(ei->mode_label);
1556
1559 if (pixbuf) {
1561 pixbuf = NULL;
1562 }
1563
1564 fc_snprintf(buf, sizeof(buf), "<span weight=\"bold\">%s</span>",
1566 gtk_label_set_markup(GTK_LABEL(ei->tool_label), buf);
1567
1568 if (etm == ETM_COPY || etm == ETM_PASTE) {
1569 struct edit_buffer *ebuf;
1570 struct sprite *spr;
1571 char status[256];
1572
1574 edit_buffer_get_status_string(ebuf, status, sizeof(status));
1575 gtk_label_set_text(GTK_LABEL(ei->tool_value_label), status);
1576
1580 if (pixbuf) {
1582 pixbuf = NULL;
1583 }
1584 } else {
1587 if (pixbuf) {
1589 pixbuf = NULL;
1590 }
1591 gtk_label_set_text(GTK_LABEL(ei->tool_value_label),
1593 }
1594
1596
1598 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ei->size_spin_button),
1600 gtk_widget_set_visible(ei->size_hbox, TRUE);
1601 } else {
1602 gtk_widget_set_visible(ei->size_hbox, FALSE);
1603 }
1604
1606 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ei->count_spin_button),
1608 gtk_widget_set_visible(ei->count_hbox, TRUE);
1609 } else {
1610 gtk_widget_set_visible(ei->count_hbox, FALSE);
1611 }
1612
1614}
1615
1616/************************************************************************/
1621{
1622 return FALSE; /* Don't gobble. */
1623}
1624
1625/************************************************************************/
1629{
1630 enum editor_tool_type ett;
1631
1632 ett = editor_get_tool();
1633 switch (keyval) {
1634 case GDK_KEY_D:
1636 break;
1637 case GDK_KEY_C:
1640 break;
1641 case GDK_KEY_V:
1644 break;
1645 case GDK_KEY_T:
1647 break;
1648 case GDK_KEY_R:
1650 break;
1651 case GDK_KEY_S:
1653 break;
1654 case GDK_KEY_P:
1656 break;
1657 case GDK_KEY_M:
1659 break;
1660 case GDK_KEY_U:
1662 break;
1663 default:
1664 return TRUE; /* Gobble? */
1665 break;
1666 }
1667
1669
1670 return TRUE;
1671}
1672
1673/************************************************************************/
1677{
1679
1680 /* Check ctrl before shift - this is correct also for the case where
1681 * they are both active. */
1682 /* ACCL_MOD_MASK is GDK_META_MASK on Mac, else GDK_CONTROL_MASK */
1683 if (state & ACCL_MOD_MASK) {
1685 }
1686
1687 if (state & GDK_SHIFT_MASK) {
1689 }
1690
1691 ett = editor_get_tool();
1692
1693 switch (keyval) {
1694 case GDK_KEY_t:
1696 break;
1697 case GDK_KEY_r:
1699 break;
1700 case GDK_KEY_s:
1702 break;
1703 case GDK_KEY_p:
1704 new_ett = ETT_ROAD;
1705 break;
1706 case GDK_KEY_m:
1708 break;
1709 case GDK_KEY_u:
1710 new_ett = ETT_UNIT;
1711 break;
1712 case GDK_KEY_c:
1713 new_ett = ETT_CITY;
1714 break;
1715 case GDK_KEY_v:
1717 break;
1718 case GDK_KEY_b:
1720 break;
1721 case GDK_KEY_plus:
1722 case GDK_KEY_equal:
1723 case GDK_KEY_KP_Add:
1726
1728 } else if (editor_tool_has_count(ett)) {
1729 int count = editor_tool_get_count(ett);
1730
1731 editor_tool_set_count(ett, count + 1);
1732 }
1733 break;
1734 case GDK_KEY_minus:
1735 case GDK_KEY_underscore:
1739
1741 } else if (editor_tool_has_count(ett)) {
1742 int count = editor_tool_get_count(ett);
1743
1744 editor_tool_set_count(ett, count - 1);
1745 }
1746 break;
1747 case GDK_KEY_1:
1748 case GDK_KEY_2:
1749 case GDK_KEY_3:
1750 case GDK_KEY_4:
1751 case GDK_KEY_5:
1752 case GDK_KEY_6:
1753 case GDK_KEY_7:
1754 case GDK_KEY_8:
1755 case GDK_KEY_9:
1758 } else if (editor_tool_has_count(ett)) {
1760 }
1761 break;
1762 case GDK_KEY_space:
1764 break;
1765 case GDK_KEY_Tab:
1767 break;
1768 case GDK_KEY_F1:
1769 case GDK_KEY_F2:
1770 case GDK_KEY_F3:
1771 case GDK_KEY_F4:
1772 case GDK_KEY_F5:
1773 case GDK_KEY_F6:
1774 case GDK_KEY_F7:
1775 case GDK_KEY_F8:
1776 case GDK_KEY_F9:
1777 case GDK_KEY_F10:
1778 case GDK_KEY_F11:
1779 case GDK_KEY_F12:
1780 return FALSE; /* Allow default handler. */
1781 break;
1782 default:
1783 return TRUE; /* Gobbled... */
1784 break;
1785 }
1786
1789 }
1790
1792
1793 return TRUE;
1794}
1795
1796/************************************************************************/
1800{
1801 return editor_toolbar;
1802}
1803
1804/************************************************************************/
1808{
1809 struct property_editor *pe;
1810 struct editbar *eb;
1811 struct editinfobox *ei;
1812
1814 if (eb != NULL) {
1816 }
1817
1819 if (ei != NULL) {
1821 }
1822
1824 if (!editor_is_active()) {
1827 }
1828}
1829
1830/************************************************************************/
1834{
1835 if (editor_toolbar == NULL) {
1837 }
1838 if (editor_infobox == NULL) {
1840 }
1841}
1842
1843/************************************************************************/
1847{
1848 struct editbar *eb = editgui_get_editbar();
1850
1851 if (ei != NULL) {
1852 /* We have extra ref for ei->widget that has protected
1853 * it from getting destroyed when editinfobox_refresh()
1854 * moves widgets around. Free that extra ref here. */
1855 g_object_unref(ei->widget);
1856 }
1857
1859}
1860
1861/************************************************************************/
1865{
1866 return editor_infobox;
1867}
1868
1869/************************************************************************/
1878
1879/************************************************************************/
1897
1898/************************************************************************/
1902{
1903 struct property_editor *pe;
1904
1907 property_editor_clear(pe); /* And clear it. */
1908}
1909
1910/************************************************************************/
1918void editgui_notify_object_changed(int objtype, int object_id, bool removal)
1919{
1920 struct property_editor *pe;
1921
1922 if (!editor_is_active()) {
1923 return;
1924 }
1925
1927 property_editor_handle_object_changed(pe, objtype, object_id, removal);
1928}
1929
1930/************************************************************************/
1934{
1935 struct property_editor *pe;
1936
1937 if (!editor_is_active()) {
1938 return;
1939 }
1940
1943}
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:77
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
@ 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:809
#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:1877
void editgui_notify_object_created(int tag, int id)
Definition editgui.c:1924
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:1607
gboolean handle_edit_key_press(GdkEventKey *ev)
Definition editgui.c:1663
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:1824
static struct editbar * editbar_create(void)
Definition editgui.c:519
void editgui_popdown_all(void)
Definition editgui.c:1892
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:1615
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 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:1855
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:1798
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:1790
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:1864
void editgui_free(void)
Definition editgui.c:1837
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
static gboolean editbar_tool_right_button(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition editgui.c:390
#define ACCL_MOD_MASK
Definition gui_main.h:29
gint blocking_dialog(GtkWidget *dlg)
Definition gui_stuff.c:1136
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
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:837
int player_count(void)
Definition player.c:806
int player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
#define players_iterate_end
Definition player.h:552
#define players_iterate(_pplayer)
Definition player.h:547
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
cairo_surface_t * surface
Definition canvas.h:23
struct sprite * city
Definition tilespec.h:354
struct sprite * vision
Definition tilespec.h:355
struct sprite * copypaste
Definition tilespec.h:348
struct sprite * startpos
Definition tilespec.h:349
struct sprite * properties
Definition tilespec.h:357
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:240
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:157
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:148
#define terrain_type_iterate(_p)
Definition terrain.h:267
#define terrain_type_iterate_end
Definition terrain.h:273
int fill_basic_terrain_layer_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int layer, struct terrain *pterrain)
Definition tilespec.c:7429
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:7055
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:7207
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:114
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:102
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1586
#define unit_type_iterate(_p)
Definition unittype.h:863
#define unit_type_iterate_end
Definition unittype.h:870