Freeciv-3.3
Loading...
Searching...
No Matches
unitselect.c
Go to the documentation of this file.
1/*****************************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 <gtk/gtk.h>
19
20/* utility */
21#include "fcintl.h"
22
23/* common */
24#include "fc_types.h"
25#include "game.h"
26#include "player.h"
27#include "unit.h"
28#include "unitlist.h"
29#include "unittype.h"
30
31/* client */
32#include "client_main.h"
33#include "control.h"
34#include "goto.h"
35#include "tilespec.h"
36#include "unitselect_common.h"
37
38/* client/gui-gtk-3.22 */
39#include "graphics.h"
40#include "gui_stuff.h"
41#include "gui_main.h"
42
43#include "unitselect.h"
44
45/* Activate this to get more columns (see below) */
46#undef DEBUG_USDLG
47
53
60
61/* Basic data (Unit, description, count) */
62#define USDLG_COLUMNS_DEFAULT 3
63/* Additional data; shown if DEBUG_USDLG */
64#define USDLG_COL_UTID USDLG_COLUMNS_DEFAULT + 0 /* Unit type ID */
65#define USDLG_COL_UID USDLG_COLUMNS_DEFAULT + 1 /* Unit ID */
66#define USDLG_COL_LOCATION USDLG_COLUMNS_DEFAULT + 2 /* Unit location */
67#define USDLG_COL_ACTIVITY USDLG_COLUMNS_DEFAULT + 3 /* Unit activity */
68#define USDLG_COL_ROW_TYPE USDLG_COLUMNS_DEFAULT + 4 /* Row type */
69#define USDLG_COLUMNS_DEBUG USDLG_COLUMNS_DEFAULT + 5
70/* Layout options; never shown */
71#define USDLG_COL_STYLE USDLG_COLUMNS_DEBUG + 0
72#define USDLG_COL_WEIGHT USDLG_COLUMNS_DEBUG + 1
73#define USDLG_COLUMNS_ALL USDLG_COLUMNS_DEBUG + 2
74
75#ifdef DEBUG_USDLG
76 #define USDLG_COLUMNS_SHOW USDLG_COLUMNS_DEBUG
77#else
78 #define USDLG_COLUMNS_SHOW USDLG_COLUMNS_DEFAULT
79#endif /* DEBUG_USDLG */
80
82 COL_PIXBUF, /* Unit */
83 COL_TEXT, /* Description */
84 COL_INT, /* Count */
85 COL_INT, /* Debug: unit type */
86 COL_INT, /* Debug: unit ID */
87 COL_INT, /* Debug: location */
88 COL_INT, /* Debug: activity */
89 COL_INT, /* Debug: row type */
90 COL_INT, /* Layout: style */
91 COL_INT /* Layout: width */
92};
93
94static const char *usdlg_col_titles[USDLG_COLUMNS_ALL] = {
95 N_("Unit"),
96 N_("Description"),
97 N_("Count"),
98 "[Unittype]", /* Only for debug, no translation! */
99 "[Unit ID]",
100 "[Location]",
101 "[Activity]",
102 "[Row type]",
103 "[Style]",
104 "[Width]"
105};
106
116
132
133/* The unit selection dialog; should only be used in usdlg_get(). */
135
136static struct unit_select_dialog *usdlg_get(bool create);
137static struct unit_select_dialog *usdlg_create(void);
138static void usdlg_destroy(void);
139static void usdlg_destroy_callback(GObject *object, gpointer data);
140static void usdlg_tile(struct unit_select_dialog *pdialog,
141 struct tile *ptile);
142static void usdlg_refresh(struct unit_select_dialog *pdialog);
143
144static void usdlg_tab_select(struct unit_select_dialog *pdialog,
145 const char *title,
148static bool usdlg_tab_update(struct unit_select_dialog *pdialog,
149 struct usdata_hash *ushash,
153 const struct unit_type *putype,
154 GtkTreeIter *it);
157 const struct unit_type *putype,
158 enum unit_activity act,
159 int count, GtkTreeIter *it,
161static void usdlg_tab_append_units(struct unit_select_dialog *pdialog,
163 enum unit_activity act,
164 const struct unit *punit,
165 bool transported, GtkTreeIter *it,
167
168static void usdlg_cmd_ready(GObject *object, gpointer data);
169static void usdlg_cmd_sentry(GObject *object, gpointer data);
170static void usdlg_cmd_select(GObject *object, gpointer data);
171static void usdlg_cmd_deselect(GObject *object, gpointer data);
172static void usdlg_cmd_exec(GObject *object, gpointer mode_data,
173 enum usdlg_cmd cmd);
174static void usdlg_cmd_exec_unit(struct unit *punit, enum usdlg_cmd cmd);
175static void usdlg_cmd_center(GObject *object, gpointer data);
176static void usdlg_cmd_focus(GObject *object, gpointer data);
181
182
183/*************************************************************************/
186void unit_select_dialog_popup_main(struct tile *ptile, bool create)
187{
188 struct unit_select_dialog *pdialog;
189
190 /* Create the dialog if it is requested. */
191 pdialog = usdlg_get(create);
192
193 /* Present the unit selection dialog if it exists. */
194 if (pdialog) {
195 /* Show all. */
197 /* Update tile. */
198 usdlg_tile(pdialog, ptile);
199 /* Refresh data and hide unused tabs. */
200 usdlg_refresh(pdialog);
201 }
202}
203
204/*************************************************************************/
208{
210}
211
212/*************************************************************************/
216static struct unit_select_dialog *usdlg_get(bool create)
217{
218 if (unit_select_dlg) {
219 /* Return existing dialog. */
220 return unit_select_dlg;
221 } else if (create) {
222 /* Create new dialog. */
224 return unit_select_dlg;
225 } else {
226 /* Nothing. */
227 return NULL;
228 }
229}
230
231/*************************************************************************/
235{
236 GtkWidget *vbox;
238 struct unit_select_dialog *pdialog;
239
240 /* Create a container for the dialog. */
241 pdialog = fc_calloc(1, sizeof(*pdialog));
242
243 /* No tile defined. */
244 pdialog->ptile = NULL;
245
246 /* Create the dialog. */
247 pdialog->shell = gtk_dialog_new();
248 gtk_window_set_title(GTK_WINDOW(pdialog->shell), _("Unit selection"));
249 setup_dialog(pdialog->shell, toplevel);
250 g_signal_connect(pdialog->shell, "destroy",
253 gtk_widget_realize(pdialog->shell);
254
256
257 /* Notebook. */
258 pdialog->notebook = gtk_notebook_new();
261 gtk_box_pack_start(GTK_BOX(vbox), pdialog->notebook, TRUE, TRUE, 0);
262
263 /* Append pages. */
264 usdlg_tab_select(pdialog, _("_Units"), SELLOC_UNITS);
265 usdlg_tab_select(pdialog, _("_Tile"), SELLOC_TILE);
266 usdlg_tab_select(pdialog, _("C_ontinent"), SELLOC_CONT);
267 usdlg_tab_select(pdialog, _("_Land"), SELLOC_LAND);
268 usdlg_tab_select(pdialog, _("_Sea"), SELLOC_SEA);
269 usdlg_tab_select(pdialog, _("_Both"), SELLOC_BOTH);
270 usdlg_tab_select(pdialog, _("_World"), SELLOC_WORLD);
271
272 /* Buttons. */
274 _("_Close"), GTK_RESPONSE_CLOSE);
277 g_signal_connect(close_cmd, "clicked",
279
280 return pdialog;
281}
282
283/*************************************************************************/
294
295/*************************************************************************/
298static void usdlg_destroy_callback(GObject *object, gpointer data)
299{
301}
302
303/*************************************************************************/
306static void usdlg_tile(struct unit_select_dialog *pdialog,
307 struct tile *ptile)
308{
309 if (!pdialog) {
310 return;
311 }
312
313 /* Check for a valid tile. */
314 if (ptile != NULL) {
315 pdialog->ptile = ptile;
316 } else if (pdialog->ptile == NULL) {
318
319 if (punit) {
320 pdialog->ptile = unit_tile(punit);
322 } else {
323 pdialog->ptile = get_center_tile_mapcanvas();
324 }
325 }
326}
327
328/*************************************************************************/
331static void usdlg_refresh(struct unit_select_dialog *pdialog)
332{
333 struct usdata_hash *ushash = NULL;
335
336 if (!pdialog) {
337 return;
338 }
339
340 /* Sort units into the hash. */
341 ushash = usdlg_data_new(pdialog->ptile);
342 /* Update all tabs. */
346 bool show = usdlg_tab_update(pdialog, ushash, loc);
347
348 if (!show) {
349 gtk_widget_hide(pdialog->tabs[loc].page);
350 } else {
351 gtk_widget_show(pdialog->tabs[loc].page);
352
353 if (pdialog->tabs[loc].path) {
355 pdialog->tabs[loc].path,FALSE);
357 pdialog->tabs[loc].path, NULL, FALSE);
358 gtk_tree_path_free(pdialog->tabs[loc].path);
359 pdialog->tabs[loc].path = NULL;
360 }
361 }
362 }
363 /* Destroy the hash. */
365}
366
367/*************************************************************************/
380static void usdlg_tab_select(struct unit_select_dialog *pdialog,
381 const char *title,
383{
384 GtkWidget *page, *label, *hbox, *vbox, *view, *sw;
385 GtkTreeStore *store;
386 static bool titles_done;
387 int i;
388
389 page = gtk_grid_new();
393 pdialog->tabs[loc].page = page;
394
396 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
397
398 hbox = gtk_grid_new();
400
401 store = usdlg_tab_store_new();
402 pdialog->tabs[loc].store = store;
403
407 pdialog->tabs[loc].view = view;
408 g_object_unref(store);
409
412 g_signal_connect(view, "cursor-changed",
414
415 /* Translate titles. */
417
418 for (i = 0; i < USDLG_COLUMNS_SHOW; i++) {
420 GtkCellRenderer *renderer = NULL;
421
422 switch (usdlg_col_types[i]) {
423 case COL_PIXBUF:
424 renderer = gtk_cell_renderer_pixbuf_new();
426 usdlg_col_titles[i], renderer, "pixbuf", i, NULL);
428 break;
429 case COL_TEXT:
430 renderer = gtk_cell_renderer_text_new();
432 usdlg_col_titles[i], renderer, "text", i,
433 "style", USDLG_COL_STYLE, "weight", USDLG_COL_WEIGHT, NULL);
435 break;
436 case COL_INT:
437 renderer = gtk_cell_renderer_text_new();
439 usdlg_col_titles[i], renderer, "text", i,
440 "style", USDLG_COL_STYLE, "weight", USDLG_COL_WEIGHT, NULL);
441 g_object_set(renderer, "xalign", 1.0, NULL);
444 break;
445 }
446
449 }
450
459
460 vbox = gtk_grid_new();
464
465 /* button box 1: ready, sentry */
466
467 pdialog->tabs[loc].cmd[USDLG_CMD_READY]
470 pdialog->tabs[loc].cmd[USDLG_CMD_READY]);
471 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_READY], "clicked",
475
476 pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY]
477 = gtk_button_new_with_mnemonic(_("Sentry"));
479 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY]), 10);
481 pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY]);
482 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY], "clicked",
486
487 /* button box 2: select, deselect */
488
489 pdialog->tabs[loc].cmd[USDLG_CMD_SELECT]
490 = gtk_button_new_with_mnemonic(_("_Select"));
492 pdialog->tabs[loc].cmd[USDLG_CMD_SELECT]);
493 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_SELECT], "clicked",
497
498 pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT]
499 = gtk_button_new_with_mnemonic(_("_Deselect"));
501 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT]), 10);
503 pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT]);
504 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT], "clicked",
508
509 /* button box 3: center, focus */
510
511 pdialog->tabs[loc].cmd[USDLG_CMD_CENTER]
512 = gtk_button_new_with_mnemonic(_("C_enter"));
514 pdialog->tabs[loc].cmd[USDLG_CMD_CENTER]);
515 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_CENTER], "clicked",
519
520 pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS]
521 = gtk_button_new_with_mnemonic(_("_Focus"));
523 pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS]);
524 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS], "clicked",
528}
529
530/*************************************************************************/
534{
535 GtkTreeStore *store;
537 int i;
538
539 for (i = 0; i < USDLG_COLUMNS_ALL; i++) {
540 switch (usdlg_col_types[i]) {
541 case COL_PIXBUF:
543 break;
544 case COL_TEXT:
546 break;
547 case COL_INT:
549 break;
550 }
551 }
552
554
555 return store;
556}
557
558/*************************************************************************/
561static bool usdlg_tab_update(struct unit_select_dialog *pdialog,
562 struct usdata_hash *ushash,
564{
565 bool show = FALSE;
566 GtkTreeStore *store;
567
569 fc_assert_ret_val(pdialog != NULL, FALSE);
570
571 store = pdialog->tabs[loc].store;
572
573 /* clear current store. */
575
576 /* Iterate over all unit types. */
577 if (loc == SELLOC_UNITS) {
578 /* Special case - show all units on this tile in their transports. */
579 unit_type_iterate(utype) {
580 struct usdata *data;
581
583
584 if (!data) {
585 continue;
586 }
587
589 if (unit_list_size(data->units[loc][act]) == 0) {
590 continue;
591 }
592
593 unit_list_iterate(data->units[loc][act], punit) {
595
596 usdlg_tab_append_units(pdialog, loc, act, punit, FALSE,
597 &it_unit, NULL);
599
600 /* Show this tab. */
601 show = TRUE;
604 } else {
606 struct usdata *data;
607 bool first = TRUE;
609 GtkTreePath *path;
610 int count = 0;
611
613
614 if (!data) {
615 continue;
616 }
617
620
621 if (unit_list_size(data->units[loc][act]) == 0) {
622 continue;
623 }
624
625 /* Level 1: Display unit type. */
626 if (first) {
628 &it_utype);
629 first = FALSE;
630 }
631
632 /* Level 2: Display unit activities. */
634 act, unit_list_size(data->units[loc][act]),
635 &it_act, &it_utype);
636
637 /* Level 3: Display all units with this activity
638 * (and transported units in further level(s)). */
639 unit_list_iterate(data->units[loc][act], punit) {
641
642 usdlg_tab_append_units(pdialog, loc, act, punit, FALSE,
643 &it_unit, &it_act);
645
646 count += unit_list_size(data->units[loc][act]);
647
648 /* Update sum of units with this type. */
649 gtk_tree_store_set(GTK_TREE_STORE(store), &it_utype, 2, count, -1);
650
651 /* Expand to the activities. */
652 path
654 &it_utype);
656 FALSE);
657 gtk_tree_path_free(path);
658
659 /* Show this tab. */
660 show = TRUE;
663 }
664
665 return show;
666}
667
668/*************************************************************************/
673 const struct unit_type *putype,
674 GtkTreeIter *it)
675{
676 GdkPixbuf *pix;
677 char buf[128];
678
679 fc_assert_ret(store != NULL);
681
682 /* Add this item. */
684
685 /* Create a icon */
686 {
688
691
692 put_unittype(putype, &canvas_store, 1.0, 0, 0);
696 }
697
698 /* The name of the unit. */
700
701 /* Add it to the tree. */
703 0, pix, /* Unit pixmap */
704 1, buf, /* Text */
705 2, -1, /* will be set later */ /* Number of units */
706 3, utype_index(putype), /* Unit type ID */
707 /* 4: not set */ /* Unit ID */
708 5, loc, /* Unit location */
709 /* 6: not set */ /* Unit activity */
710 7, ROW_UNITTYPE, /* Row type */
711 8, PANGO_STYLE_NORMAL, /* Style */
712 9, PANGO_WEIGHT_BOLD, /* Weight */
713 -1);
714 g_object_unref(pix);
715}
716
717/*************************************************************************/
722 const struct unit_type *putype,
723 enum unit_activity act,
724 int count, GtkTreeIter *it,
726{
727 char buf[128] = "";
728
729 fc_assert_ret(store != NULL);
731
732 /* Add this item. */
734
735 /* The activity. */
736 fc_snprintf(buf, sizeof(buf), "%s", get_activity_text(act));
737
738 /* Add it to the tree. */
740 /* 0: not set */ /* Unit pixmap */
741 1, buf, /* Text */
742 2, count, /* Number of units */
743 3, utype_index(putype), /* Unit type ID */
744 /* 4: not set */ /* Unit ID */
745 5, loc, /* Unit location */
746 6, act, /* Unit activity */
747 7, ROW_ACTIVITY, /* Row type */
748 8, PANGO_STYLE_NORMAL, /* Style */
749 9, PANGO_WEIGHT_NORMAL, /* Weight */
750 -1);
751}
752
753/*************************************************************************/
774
775/*************************************************************************/
779const char *usdlg_get_unit_descr(const struct unit *punit)
780{
781 static char buf[248] = "";
782 char buf2[248] = "";
783 struct city *phome;
784
786 if (phome) {
787 fc_snprintf(buf2, sizeof(buf2), "%s", city_name_get(phome));
788 } else if (unit_owner(punit) == client_player()
790 /* TRANS: used in place of unit home city name */
791 sz_strlcpy(buf2, _("no home city"));
792 } else {
793 /* TRANS: used in place of unit home city name */
794 sz_strlcpy(buf2, _("unknown"));
795 }
796#ifdef FREECIV_DEBUG
797 /* Strings only used in debug builds, don't bother with i18n */
798 fc_snprintf(buf, sizeof(buf), "%s [Unit ID %d]\n(%s)\nCoordinates: (%d,%d)",
801 {
803
804 if (ptrans) {
805 cat_snprintf(buf, sizeof(buf), "\nTransported by unit ID %d",
806 ptrans->id);
807 }
808 }
809#else /* FREECIV_DEBUG */
810 /* TRANS: unit type and home city, e.g. "Transport\n(New Orleans)" */
811 fc_snprintf(buf, sizeof(buf), _("%s\n(%s)"), unit_name_translation(punit),
812 buf2);
813#endif /* FREECIV_DEBUG */
814
815 return buf;
816}
817
818/*************************************************************************/
821static void usdlg_tab_append_units(struct unit_select_dialog *pdialog,
823 enum unit_activity act,
824 const struct unit *punit,
825 bool transported, GtkTreeIter *it,
827{
828 const char *text;
829 GdkPixbuf *pix;
831 int style = PANGO_STYLE_NORMAL;
832 int weight = PANGO_WEIGHT_NORMAL;
833 GtkTreeStore *store;
834
835 fc_assert_ret(pdialog != NULL);
837
838 store = pdialog->tabs[loc].store;
839
840
841 /* Add this item. */
843
844 /* Unit gfx */
846
848
849 if (transported) {
850 weight = PANGO_WEIGHT_NORMAL;
851 style = PANGO_STYLE_ITALIC;
853 }
854
855 /* Add it to the tree. */
857 0, pix, /* Unit pixmap */
858 1, text, /* Text */
859 2, 1, /* Number of units */
860 3, utype_index(unit_type_get(punit)), /* Unit type ID */
861 4, punit->id, /* Unit ID */
862 5, loc, /* Unit location */
863 6, act, /* Unit activity */
864 7, row, /* Row type */
865 8, style, /* Style */
866 9, weight, /* Weight */
867 -1);
868 g_object_unref(pix);
869
873
874 usdlg_tab_append_units(pdialog, loc, act, pcargo, TRUE, &it_cargo, it);
876 }
877
878 if (!transported && unit_is_in_focus(punit)
879 && get_num_units_in_focus() == 1) {
880 /* Put the keyboard focus on the selected unit. It isn't transported.
881 * Selection maps to keyboard focus since it alone is selected. */
882 fc_assert_action(pdialog->tabs[loc].path == NULL,
883 /* Don't leak memory. */
884 gtk_tree_path_free(pdialog->tabs[loc].path));
885
886 pdialog->tabs[loc].path
888 }
889}
890
891/*************************************************************************/
894static void usdlg_cmd_ready(GObject *object, gpointer data)
895{
896 usdlg_cmd_exec(object, data, USDLG_CMD_READY);
897}
898
899/*************************************************************************/
902static void usdlg_cmd_sentry(GObject *object, gpointer data)
903{
904 usdlg_cmd_exec(object, data, USDLG_CMD_SENTRY);
905}
906
907/*************************************************************************/
910static void usdlg_cmd_select(GObject *object, gpointer data)
911{
912 usdlg_cmd_exec(object, data, USDLG_CMD_SELECT);
913}
914
915/*************************************************************************/
918static void usdlg_cmd_deselect(GObject *object, gpointer data)
919{
920 usdlg_cmd_exec(object, data, USDLG_CMD_DESELECT);
921}
922
923/*************************************************************************/
927 enum usdlg_cmd cmd)
928{
932 GtkTreeSelection *selection;
933 GtkTreeModel *model;
934 GtkTreeIter it;
935 gint row;
936 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
937
938 fc_assert_ret(pdialog != NULL);
940
942 return;
943 }
944
945 view = GTK_TREE_VIEW(pdialog->tabs[loc_mode].view);
947
948 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
949 log_debug("No selection");
950 return;
951 }
952 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, -1);
953
954 switch (row) {
955 case ROW_UNITTYPE:
956 {
957 gint loc, utid;
958 struct usdata_hash *ushash;
959 struct usdata *data;
960
962 USDLG_COL_UTID, &utid, -1);
963
964 /* We can't be sure that all units still exists - recalc the data. */
965 ushash = usdlg_data_new(pdialog->ptile);
966
968 if (data != NULL) {
970 if (unit_list_size(data->units[loc][act]) == 0) {
971 continue;
972 }
973
974 unit_list_iterate(data->units[loc][act], punit) {
978 }
979
980 /* Destroy the hash. */
982 }
983 break;
984 case ROW_ACTIVITY:
985 {
986 gint loc, act, utid;
987 struct usdata_hash *ushash;
988 struct usdata *data;
989
990 gtk_tree_model_get(model, &it, USDLG_COL_ACTIVITY, &act,
992
993 /* We can't be sure that all units still exists - recalc the data. */
994 ushash = usdlg_data_new(pdialog->ptile);
995
997 if (data != NULL
998 && unit_list_size(data->units[loc][act]) != 0) {
999 unit_list_iterate(data->units[loc][act], punit) {
1002 }
1003
1004 /* Destroy the hash. */
1006 }
1007 break;
1008 case ROW_UNIT:
1010 {
1011 gint uid;
1012 struct unit *punit;
1013
1014 gtk_tree_model_get(model, &it, USDLG_COL_UID, &uid, -1);
1015
1017
1018 if (!punit) {
1019 log_debug("Unit vanished (Unit ID %d)!", uid);
1020 return;
1021 }
1022
1024 }
1025 break;
1026 }
1027
1028 /* Update focus. */
1030 /* Refresh dialog. */
1031 usdlg_refresh(pdialog);
1032}
1033
1034/*************************************************************************/
1037static void usdlg_cmd_exec_unit(struct unit *punit, enum usdlg_cmd cmd)
1038{
1040
1041 switch (cmd) {
1042 case USDLG_CMD_SELECT:
1043 if (!unit_is_in_focus(punit)) {
1045 }
1046 break;
1047 case USDLG_CMD_DESELECT:
1048 if (unit_is_in_focus(punit)) {
1050 }
1051 break;
1052 case USDLG_CMD_READY:
1053 if (punit->activity != ACTIVITY_IDLE) {
1055 }
1056 break;
1057 case USDLG_CMD_SENTRY:
1058 if (punit->activity != ACTIVITY_SENTRY) {
1060 }
1061 break;
1062 case USDLG_CMD_CENTER:
1063 case USDLG_CMD_FOCUS:
1064 /* Nothing here. It is done in its own functions. */
1065 break;
1066 case USDLG_CMD_LAST:
1067 /* Should never happen. */
1069 break;
1070 }
1071}
1072
1073/*************************************************************************/
1076static void usdlg_cmd_center(GObject *object, gpointer data)
1077{
1081 GtkTreeSelection *selection;
1082 GtkTreeModel *model;
1083 GtkTreeIter it;
1084 gint row;
1085 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
1086
1087 fc_assert_ret(pdialog != NULL);
1089
1090 view = GTK_TREE_VIEW(pdialog->tabs[loc].view);
1091 selection = gtk_tree_view_get_selection(view);
1092
1093 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1094 log_debug("No selection");
1095 return;
1096 }
1097 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, -1);
1098
1099 if (row == ROW_UNIT || row == ROW_UNIT_TRANSPORTED) {
1100 gint uid;
1101 struct unit *punit;
1102
1103 gtk_tree_model_get(model, &it, USDLG_COL_UID, &uid, -1);
1104
1106 if (punit) {
1108 }
1109 }
1110}
1111
1112/*************************************************************************/
1115static void usdlg_cmd_focus(GObject *object, gpointer data)
1116{
1119 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
1120
1121 fc_assert_ret(pdialog != NULL);
1123
1125}
1126
1127/*************************************************************************/
1135
1136/*************************************************************************/
1140{
1142 GtkTreeModel *model;
1143 GtkTreeIter it;
1144 gint row;
1145
1147 return;
1148 }
1149
1150 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1151 log_debug("No selection");
1152 return;
1153 }
1154 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, -1);
1155
1156 if (row == ROW_UNIT || row == ROW_UNIT_TRANSPORTED) {
1157 gint uid;
1158 struct unit *punit;
1159
1160 gtk_tree_model_get(model, &it, USDLG_COL_UID, &uid, -1);
1161
1163 if (punit && unit_owner(punit) == client_player()) {
1165 usdlg_destroy();
1166 }
1167 }
1168}
1169
1170/*************************************************************************/
1174{
1177 GtkTreeSelection *selection;
1178 GtkTreeModel *model;
1179 GtkTreeIter it;
1180 gint row, uid;
1181 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
1182 struct unit *punit;
1184 int cmd_id;
1185
1187
1188 if (pdialog == NULL) {
1189 /* Dialog closed, nothing we can do */
1190 return;
1191 }
1192
1193 selection = gtk_tree_view_get_selection(view);
1194 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1195 log_debug("No selection");
1196 return;
1197 }
1199 &uid, -1);
1200
1201 switch (row) {
1202 case ROW_UNITTYPE:
1203 case ROW_ACTIVITY:
1204 /* Button status for rows unittype and activity:
1205 * player observer
1206 * ready TRUE FALSE
1207 * sentry TRUE FALSE
1208 * select TRUE FALSE
1209 * deselect TRUE FALSE
1210 * center FALSE FALSE
1211 * focus FALSE FALSE */
1217 } else {
1222 }
1223
1226 break;
1227 case ROW_UNIT:
1229 /* Button status for rows unit and unit (transported):
1230 * player observer
1231 * ready !IDLE FALSE
1232 * sentry !SENTRY FALSE
1233 * select !FOCUS FALSE
1234 * deselect FOCUS FALSE
1235 * center TRUE TRUE
1236 * focus !FOCUS FALSE */
1238
1240 if (punit->activity == ACTIVITY_IDLE) {
1242 } else {
1244 }
1245
1246 if (punit->activity == ACTIVITY_SENTRY) {
1248 } else {
1250 }
1251
1252 if (!unit_is_in_focus(punit)) {
1256 } else {
1260 }
1261 } else {
1264
1267
1269 }
1270
1272 break;
1273
1274 default:
1276 for (cmd_id = 0; cmd_id < USDLG_CMD_LAST; cmd_id++) {
1278 }
1279 break;
1280 }
1281
1282 /* Set widget status. */
1283 for (cmd_id = 0; cmd_id < USDLG_CMD_LAST; cmd_id++) {
1286 }
1287}
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool can_client_control(void)
bool client_is_global_observer(void)
bool can_client_change_view(void)
#define client_player()
char * incite_cost
Definition comments.c:76
bool unit_is_in_focus(const struct unit *punit)
Definition control.c:388
void unit_focus_add(struct unit *punit)
Definition control.c:573
void unit_focus_set(struct unit *punit)
Definition control.c:518
void unit_focus_remove(struct unit *punit)
Definition control.c:603
struct unit * head_of_units_in_focus(void)
Definition control.c:410
int get_num_units_in_focus(void)
Definition control.c:185
void unit_focus_update(void)
Definition control.c:801
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
Definition control.c:1941
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
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct unit * game_unit_by_number(int id)
Definition game.c:115
struct city * game_city_by_number(int id)
Definition game.c:106
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
struct tile * loc
Definition citydlg.c:227
GtkWidget * toplevel
Definition gui_main.c:126
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
void intl_slist(int n, const char **s, bool *done)
Definition gui_stuff.c:111
const char * title
Definition repodlgs.c:1314
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
Definition sprite.c:418
#define USDLG_COL_LOCATION
Definition unitselect.c:66
static void usdlg_cmd_ready(GObject *object, gpointer data)
Definition unitselect.c:894
static void usdlg_cmd_deselect(GObject *object, gpointer data)
Definition unitselect.c:918
static void usdlg_cmd_center(GObject *object, gpointer data)
#define USDLG_COL_ROW_TYPE
Definition unitselect.c:68
static void usdlg_cmd_cursor_changed(GtkTreeView *view, gpointer data)
GdkPixbuf * usdlg_get_unit_image(const struct unit *punit)
Definition unitselect.c:758
const char * usdlg_get_unit_descr(const struct unit *punit)
Definition unitselect.c:779
static void usdlg_tab_append_units(struct unit_select_dialog *pdialog, enum unit_select_location_mode loc, enum unit_activity act, const struct unit *punit, bool transported, GtkTreeIter *it, GtkTreeIter *parent)
Definition unitselect.c:821
static void usdlg_tile(struct unit_select_dialog *pdialog, struct tile *ptile)
Definition unitselect.c:306
#define USDLG_COL_UTID
Definition unitselect.c:64
static void usdlg_cmd_sentry(GObject *object, gpointer data)
Definition unitselect.c:902
static struct unit_select_dialog * usdlg_get(bool create)
Definition unitselect.c:216
#define USDLG_COL_STYLE
Definition unitselect.c:71
#define USDLG_COL_UID
Definition unitselect.c:65
static void usdlg_cmd_exec_unit(struct unit *punit, enum usdlg_cmd cmd)
static void usdlg_tab_append_activity(GtkTreeStore *store, enum unit_select_location_mode loc, const struct unit_type *putype, enum unit_activity act, int count, GtkTreeIter *it, GtkTreeIter *parent)
Definition unitselect.c:720
static struct unit_select_dialog * usdlg_create(void)
Definition unitselect.c:234
static void usdlg_cmd_focus(GObject *object, gpointer data)
#define USDLG_COL_ACTIVITY
Definition unitselect.c:67
static void usdlg_cmd_exec(GObject *object, gpointer mode_data, enum usdlg_cmd cmd)
Definition unitselect.c:926
#define USDLG_COLUMNS_ALL
Definition unitselect.c:73
static void usdlg_destroy_callback(GObject *object, gpointer data)
Definition unitselect.c:298
usdlg_row_types
Definition unitselect.c:54
@ ROW_UNITTYPE
Definition unitselect.c:55
@ ROW_UNIT_TRANSPORTED
Definition unitselect.c:58
@ ROW_UNIT
Definition unitselect.c:57
@ ROW_ACTIVITY
Definition unitselect.c:56
static void usdlg_cmd_select(GObject *object, gpointer data)
Definition unitselect.c:910
static const char * usdlg_col_titles[USDLG_COLUMNS_ALL]
Definition unitselect.c:94
static void usdlg_cmd_focus_real(GtkTreeView *view)
#define USDLG_COLUMNS_SHOW
Definition unitselect.c:78
static struct unit_select_dialog * unit_select_dlg
Definition unitselect.c:134
enum usdlg_column_types usdlg_col_types[USDLG_COLUMNS_ALL]
Definition unitselect.c:81
void unit_select_dialog_popup_main(struct tile *ptile, bool create)
Definition unitselect.c:186
static void usdlg_cmd_row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
void unit_select_dialog_popdown(void)
Definition unitselect.c:207
static void usdlg_tab_append_utype(GtkTreeStore *store, enum unit_select_location_mode loc, const struct unit_type *putype, GtkTreeIter *it)
Definition unitselect.c:671
#define USDLG_COL_WEIGHT
Definition unitselect.c:72
static void usdlg_tab_select(struct unit_select_dialog *pdialog, const char *title, enum unit_select_location_mode loc)
Definition unitselect.c:380
static bool usdlg_tab_update(struct unit_select_dialog *pdialog, struct usdata_hash *ushash, enum unit_select_location_mode loc)
Definition unitselect.c:561
static void usdlg_refresh(struct unit_select_dialog *pdialog)
Definition unitselect.c:331
usdlg_column_types
Definition unitselect.c:48
@ COL_INT
Definition unitselect.c:51
@ COL_TEXT
Definition unitselect.c:50
@ COL_PIXBUF
Definition unitselect.c:49
usdlg_cmd
Definition unitselect.c:107
@ USDLG_CMD_FOCUS
Definition unitselect.c:113
@ USDLG_CMD_SENTRY
Definition unitselect.c:111
@ USDLG_CMD_LAST
Definition unitselect.c:114
@ USDLG_CMD_CENTER
Definition unitselect.c:112
@ USDLG_CMD_READY
Definition unitselect.c:110
@ USDLG_CMD_DESELECT
Definition unitselect.c:109
@ USDLG_CMD_SELECT
Definition unitselect.c:108
static void usdlg_destroy(void)
Definition unitselect.c:286
static GtkTreeStore * usdlg_tab_store_new(void)
Definition unitselect.c:533
#define show(id)
Definition widget.h:235
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
struct tile * get_center_tile_mapcanvas(void)
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void center_tile_mapcanvas(const struct tile *ptile)
#define fc_calloc(n, esz)
Definition mem.h:38
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
#define ARRAY_SIZE(x)
Definition shared.h:85
cairo_surface_t * surface
Definition canvas.h:23
Definition city.h:317
Definition tile.h:50
struct tile * ptile
Definition unitselect.c:118
GtkTreePath * path
Definition unitselect.c:127
GtkWidget * shell
Definition unitselect.c:120
GtkWidget * view
Definition unitselect.c:126
GtkWidget * cmd[USDLG_CMD_LAST]
Definition unitselect.c:129
GtkWidget * notebook
Definition unitselect.c:121
GtkTreeStore * store
Definition unitselect.c:124
struct unit_select_dialog::@163 tabs[SELLOC_COUNT]
GtkWidget * page
Definition unitselect.c:125
Definition unit.h:140
enum unit_activity activity
Definition unit.h:159
int id
Definition unit.h:147
int homecity
Definition unit.h:148
struct unit_list * units[SELLOC_COUNT][ACTIVITY_LAST]
const struct unit_type * utype
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define TILE_XY(ptile)
Definition tile.h:43
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:815
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:802
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1846
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2544
const char * get_activity_text(enum unit_activity activity)
Definition unit.c:656
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2554
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
#define activity_type_iterate(_act_)
Definition unit.h:287
#define activity_type_iterate_end
Definition unit.h:292
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
struct usdata_hash * usdlg_data_new(const struct tile *ptile)
void usdlg_data_destroy(struct usdata_hash *ushash)
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1573
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1564
#define unit_type_iterate(_p)
Definition unittype.h:860
#define unit_type_iterate_end
Definition unittype.h:867