Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-gtk-4.0/unitselect.c Source File

Freeciv-3.2

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-4.0 */
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
48 enum usdlg_column_types {
49 COL_PIXBUF,
50 COL_TEXT,
51 COL_INT
52};
53
54 enum usdlg_row_types {
55 ROW_UNITTYPE,
56 ROW_ACTIVITY,
57 ROW_UNIT,
58 ROW_UNIT_TRANSPORTED
59};
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
81 enum usdlg_column_types usdlg_col_types[USDLG_COLUMNS_ALL] = {
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
94 static 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
107 enum usdlg_cmd {
108 USDLG_CMD_SELECT,
109 USDLG_CMD_DESELECT,
110 USDLG_CMD_READY,
111 USDLG_CMD_SENTRY,
112 USDLG_CMD_CENTER,
113 USDLG_CMD_FOCUS,
114 USDLG_CMD_LAST
115};
116
117struct unit_select_dialog {
118 struct tile *ptile;
119 int unit_id_focus;
120
121 GtkWidget *shell;
122 GtkWidget *notebook;
123
124 struct {
125 GtkTreeStore *store;
126 GtkWidget *view;
127 GtkTreePath *path;
128 } units;
129
130 struct {
131 GtkTreeStore *store;
132 GtkWidget *page;
133 GtkWidget *view;
134 GtkTreePath *path;
135
136 GtkWidget *cmd[USDLG_CMD_LAST];
137 } tabs[SELLOC_COUNT];
138};
139
140/* The unit selection dialog; should only be used in usdlg_get(). */
141 static struct unit_select_dialog *unit_select_dlg = NULL;
142
143static struct unit_select_dialog *usdlg_get(bool create);
144static struct unit_select_dialog *usdlg_create(void);
145static void usdlg_destroy(void);
146static void usdlg_destroy_callback(GObject *object, gpointer data);
147static void usdlg_tile(struct unit_select_dialog *pdialog,
148 struct tile *ptile);
149static void usdlg_refresh(struct unit_select_dialog *pdialog);
150
151static void usdlg_tab_select(struct unit_select_dialog *pdialog,
152 const char *title,
153 enum unit_select_location_mode loc);
154static GtkTreeStore *usdlg_tab_store_new(void);
155static bool usdlg_tab_update(struct unit_select_dialog *pdialog,
156 struct usdata_hash *ushash,
157 enum unit_select_location_mode loc);
158static void usdlg_tab_append_utype(GtkTreeStore *store,
159 enum unit_select_location_mode loc,
160 const struct unit_type *putype,
161 GtkTreeIter *it);
162static void usdlg_tab_append_activity(GtkTreeStore *store,
163 enum unit_select_location_mode loc,
164 const struct unit_type *putype,
165 enum unit_activity act,
166 int count, GtkTreeIter *it,
167 GtkTreeIter *parent);
168static void usdlg_tab_append_units(struct unit_select_dialog *pdialog,
169 enum unit_select_location_mode loc,
170 enum unit_activity act,
171 const struct unit *punit,
172 bool transported, GtkTreeIter *it,
173 GtkTreeIter *parent);
174
175static void usdlg_cmd_ready(GObject *object, gpointer data);
176static void usdlg_cmd_sentry(GObject *object, gpointer data);
177static void usdlg_cmd_select(GObject *object, gpointer data);
178static void usdlg_cmd_deselect(GObject *object, gpointer data);
179static void usdlg_cmd_exec(GObject *object, gpointer mode_data,
180 enum usdlg_cmd cmd);
181static void usdlg_cmd_exec_unit(struct unit *punit, enum usdlg_cmd cmd);
182static void usdlg_cmd_center(GObject *object, gpointer data);
183static void usdlg_cmd_focus(GObject *object, gpointer data);
184static void usdlg_cmd_focus_real(GtkTreeView *view);
185static void usdlg_cmd_row_activated(GtkTreeView *view, GtkTreePath *path,
186 GtkTreeViewColumn *col, gpointer data);
187static void usdlg_cmd_cursor_changed(GtkTreeView *view, gpointer data);
188
189
190/*************************************************************************/
193 void unit_select_dialog_popup_main(struct tile *ptile, bool create)
194{
195 struct unit_select_dialog *pdialog;
196
197 /* Create the dialog if it is requested. */
198 pdialog = usdlg_get(create);
199
200 /* Present the unit selection dialog if it exists. */
201 if (pdialog) {
202 /* Show all. */
203 gtk_widget_set_visible(GTK_WIDGET(pdialog->shell), TRUE);
204 /* Update tile. */
205 usdlg_tile(pdialog, ptile);
206 /* Refresh data and hide unused tabs. */
207 usdlg_refresh(pdialog);
208 }
209}
210
211/*************************************************************************/
214 void unit_select_dialog_popdown(void)
215{
216 usdlg_destroy();
217}
218
219/*************************************************************************/
223 static struct unit_select_dialog *usdlg_get(bool create)
224{
225 if (unit_select_dlg) {
226 /* Return existing dialog. */
227 return unit_select_dlg;
228 } else if (create) {
229 /* Create new dialog. */
230 unit_select_dlg = usdlg_create();
231 return unit_select_dlg;
232 } else {
233 /* Nothing. */
234 return NULL;
235 }
236}
237
238/*************************************************************************/
241 static struct unit_select_dialog *usdlg_create(void)
242{
243 GtkWidget *vbox;
244 GtkWidget *close_cmd;
245 struct unit_select_dialog *pdialog;
246
247 /* Create a container for the dialog. */
248 pdialog = fc_calloc(1, sizeof(*pdialog));
249
250 /* No tile defined. */
251 pdialog->ptile = NULL;
252
253 /* Create the dialog. */
254 pdialog->shell = gtk_dialog_new();
255 gtk_window_set_title(GTK_WINDOW(pdialog->shell), _("Unit selection"));
256 setup_dialog(pdialog->shell, toplevel);
257 g_signal_connect(pdialog->shell, "destroy",
258 G_CALLBACK(usdlg_destroy_callback), pdialog);
259 gtk_widget_realize(pdialog->shell);
260
261 vbox = gtk_dialog_get_content_area(GTK_DIALOG(pdialog->shell));
262
263 /* Notebook. */
264 pdialog->notebook = gtk_notebook_new();
265 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(pdialog->notebook),
266 GTK_POS_BOTTOM);
267 gtk_box_insert_child_after(GTK_BOX(vbox), pdialog->notebook, NULL);
268
269 /* Append pages. */
270 usdlg_tab_select(pdialog, _("_Units"), SELLOC_UNITS);
271 usdlg_tab_select(pdialog, _("_Tile"), SELLOC_TILE);
272 usdlg_tab_select(pdialog, _("C_ontinent"), SELLOC_CONT);
273 usdlg_tab_select(pdialog, _("_Land"), SELLOC_LAND);
274 usdlg_tab_select(pdialog, _("_Sea"), SELLOC_SEA);
275 usdlg_tab_select(pdialog, _("_Both"), SELLOC_BOTH);
276 usdlg_tab_select(pdialog, _("_World"), SELLOC_WORLD);
277
278 /* Buttons. */
279 close_cmd = gtk_dialog_add_button(GTK_DIALOG(pdialog->shell),
280 _("_Close"), GTK_RESPONSE_CLOSE);
281 gtk_dialog_set_default_response(GTK_DIALOG(pdialog->shell),
282 GTK_RESPONSE_CLOSE);
283 g_signal_connect(close_cmd, "clicked",
284 G_CALLBACK(usdlg_destroy_callback), pdialog);
285
286 return pdialog;
287}
288
289/*************************************************************************/
292 static void usdlg_destroy(void)
293{
294 if (unit_select_dlg) {
295 gtk_window_destroy(GTK_WINDOW(unit_select_dlg->shell));
296 free(unit_select_dlg);
297 }
298 unit_select_dlg = NULL;
299}
300
301/*************************************************************************/
304 static void usdlg_destroy_callback(GObject *object, gpointer data)
305{
306 usdlg_destroy();
307}
308
309/*************************************************************************/
312 static void usdlg_tile(struct unit_select_dialog *pdialog,
313 struct tile *ptile)
314{
315 if (!pdialog) {
316 return;
317 }
318
319 /* Check for a valid tile. */
320 if (ptile != NULL) {
321 pdialog->ptile = ptile;
322 } else if (pdialog->ptile == NULL) {
323 struct unit *punit = head_of_units_in_focus();
324
325 if (punit) {
326 pdialog->ptile = unit_tile(punit);
327 center_tile_mapcanvas(pdialog->ptile);
328 } else {
329 pdialog->ptile = get_center_tile_mapcanvas();
330 }
331 }
332}
333
334/*************************************************************************/
337 static void usdlg_refresh(struct unit_select_dialog *pdialog)
338{
339 struct usdata_hash *ushash = NULL;
340 enum unit_select_location_mode loc;
341
342 if (!pdialog) {
343 return;
344 }
345
346 /* Sort units into the hash. */
347 ushash = usdlg_data_new(pdialog->ptile);
348 /* Update all tabs. */
349 for (loc = unit_select_location_mode_begin();
350 loc != unit_select_location_mode_end();
351 loc = unit_select_location_mode_next(loc)) {
352 bool show = usdlg_tab_update(pdialog, ushash, loc);
353
354 if (!show) {
355 gtk_widget_set_visible(pdialog->tabs[loc].page, FALSE);
356 } else {
357 gtk_widget_set_visible(pdialog->tabs[loc].page, TRUE);
358
359 if (pdialog->tabs[loc].path) {
360 gtk_tree_view_expand_row(GTK_TREE_VIEW(pdialog->tabs[loc].view),
361 pdialog->tabs[loc].path,FALSE);
362 gtk_tree_view_set_cursor(GTK_TREE_VIEW(pdialog->tabs[loc].view),
363 pdialog->tabs[loc].path, NULL, FALSE);
364 gtk_tree_path_free(pdialog->tabs[loc].path);
365 pdialog->tabs[loc].path = NULL;
366 }
367 }
368 }
369
370 /* Destroy the hash. */
371 usdlg_data_destroy(ushash);
372}
373
374/*************************************************************************/
387 static void usdlg_tab_select(struct unit_select_dialog *pdialog,
388 const char *title,
389 enum unit_select_location_mode loc)
390{
391 GtkWidget *page, *label, *hgrid, *vgrid, *view, *sw;
392 GtkTreeStore *store;
393 static bool titles_done;
394 int i;
395 int page_row = 0;
396 int grid_col = 0;
397 int grid_row = 0;
398
399 page = gtk_grid_new();
400 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
401 GTK_ORIENTATION_VERTICAL);
402 gtk_widget_set_margin_start(page, 8);
403 gtk_widget_set_margin_end(page, 8);
404 gtk_widget_set_margin_top(page, 8);
405 gtk_widget_set_margin_bottom(page, 8);
406 pdialog->tabs[loc].page = page;
407
408 label = gtk_label_new_with_mnemonic(title);
409 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
410
411 hgrid = gtk_grid_new();
412 gtk_grid_attach(GTK_GRID(page), hgrid, 0, page_row++, 1, 1);
413
414 store = usdlg_tab_store_new();
415 pdialog->tabs[loc].store = store;
416
417 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
418 gtk_widget_set_hexpand(view, TRUE);
419 gtk_widget_set_vexpand(view, TRUE);
420 pdialog->tabs[loc].view = view;
421 g_object_unref(store);
422
423 g_signal_connect(view, "row-activated", G_CALLBACK(usdlg_cmd_row_activated),
424 GINT_TO_POINTER(loc));
425 g_signal_connect(view, "cursor-changed",
426 G_CALLBACK(usdlg_cmd_cursor_changed), GINT_TO_POINTER(loc));
427
428 /* Translate titles. */
429 intl_slist(ARRAY_SIZE(usdlg_col_titles), usdlg_col_titles, &titles_done);
430
431 for (i = 0; i < USDLG_COLUMNS_SHOW; i++) {
432 GtkTreeViewColumn *column = NULL;
433 GtkCellRenderer *renderer = NULL;
434
435 switch (usdlg_col_types[i]) {
436 case COL_PIXBUF:
437 renderer = gtk_cell_renderer_pixbuf_new();
438 column = gtk_tree_view_column_new_with_attributes(
439 usdlg_col_titles[i], renderer, "pixbuf", i, NULL);
440 gtk_tree_view_column_set_expand(column, FALSE);
441 break;
442 case COL_TEXT:
443 renderer = gtk_cell_renderer_text_new();
444 column = gtk_tree_view_column_new_with_attributes(
445 usdlg_col_titles[i], renderer, "text", i,
446 "style", USDLG_COL_STYLE, "weight", USDLG_COL_WEIGHT, NULL);
447 gtk_tree_view_column_set_expand(column, TRUE);
448 break;
449 case COL_INT:
450 renderer = gtk_cell_renderer_text_new();
451 column = gtk_tree_view_column_new_with_attributes(
452 usdlg_col_titles[i], renderer, "text", i,
453 "style", USDLG_COL_STYLE, "weight", USDLG_COL_WEIGHT, NULL);
454 g_object_set(renderer, "xalign", 1.0, NULL);
455 gtk_tree_view_column_set_alignment(column, 1.0);
456 gtk_tree_view_column_set_expand(column, FALSE);
457 break;
458 }
459
460 fc_assert_ret(column != NULL);
461 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
462 }
463
464 sw = gtk_scrolled_window_new();
465 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 300);
466 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
467 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
468 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
469 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
470 gtk_grid_attach(GTK_GRID(hgrid), sw, grid_col++, 0, 1, 1);
471
472 vgrid = gtk_grid_new();
473 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
474 GTK_ORIENTATION_VERTICAL);
475 gtk_grid_attach(GTK_GRID(hgrid), vgrid, grid_col++, 0, 1, 1);
476
477 /* button box 1: ready, sentry */
478
479 pdialog->tabs[loc].cmd[USDLG_CMD_READY]
480 = gtk_button_new_with_mnemonic(_("Ready"));
481 gtk_grid_attach(GTK_GRID(vgrid),
482 pdialog->tabs[loc].cmd[USDLG_CMD_READY],
483 0, grid_row++, 1, 1);
484 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_READY], "clicked",
485 G_CALLBACK(usdlg_cmd_ready), GINT_TO_POINTER(loc));
486 gtk_widget_set_sensitive(
487 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_READY]), FALSE);
488
489 pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY]
490 = gtk_button_new_with_mnemonic(_("Sentry"));
491 gtk_widget_set_margin_bottom(
492 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY]), 10);
493 gtk_grid_attach(GTK_GRID(vgrid),
494 pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY],
495 0, grid_row++, 1, 1);
496 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY], "clicked",
497 G_CALLBACK(usdlg_cmd_sentry), GINT_TO_POINTER(loc));
498 gtk_widget_set_sensitive(
499 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_SENTRY]), FALSE);
500
501 /* button box 2: select, deselect */
502
503 pdialog->tabs[loc].cmd[USDLG_CMD_SELECT]
504 = gtk_button_new_with_mnemonic(_("_Select"));
505 gtk_grid_attach(GTK_GRID(vgrid),
506 pdialog->tabs[loc].cmd[USDLG_CMD_SELECT],
507 0, grid_row++, 1, 1);
508 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_SELECT], "clicked",
509 G_CALLBACK(usdlg_cmd_select), GINT_TO_POINTER(loc));
510 gtk_widget_set_sensitive(
511 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_SELECT]), FALSE);
512
513 pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT]
514 = gtk_button_new_with_mnemonic(_("_Deselect"));
515 gtk_widget_set_margin_bottom(
516 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT]), 10);
517 gtk_grid_attach(GTK_GRID(vgrid),
518 pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT],
519 0, grid_row++, 1, 1);
520 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT], "clicked",
521 G_CALLBACK(usdlg_cmd_deselect), GINT_TO_POINTER(loc));
522 gtk_widget_set_sensitive(
523 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_DESELECT]), FALSE);
524
525 /* button box 3: center, focus */
526
527 pdialog->tabs[loc].cmd[USDLG_CMD_CENTER]
528 = gtk_button_new_with_mnemonic(_("C_enter"));
529 gtk_grid_attach(GTK_GRID(vgrid),
530 pdialog->tabs[loc].cmd[USDLG_CMD_CENTER],
531 0, grid_row++, 1, 1);
532 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_CENTER], "clicked",
533 G_CALLBACK(usdlg_cmd_center), GINT_TO_POINTER(loc));
534 gtk_widget_set_sensitive(
535 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_CENTER]), FALSE);
536
537 pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS]
538 = gtk_button_new_with_mnemonic(_("_Focus"));
539 gtk_grid_attach(GTK_GRID(vgrid),
540 pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS],
541 0, grid_row++, 1, 1);
542 g_signal_connect(pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS], "clicked",
543 G_CALLBACK(usdlg_cmd_focus), GINT_TO_POINTER(loc));
544 gtk_widget_set_sensitive(
545 GTK_WIDGET(pdialog->tabs[loc].cmd[USDLG_CMD_FOCUS]), FALSE);
546}
547
548/*************************************************************************/
551 static GtkTreeStore *usdlg_tab_store_new(void)
552{
553 GtkTreeStore *store;
554 GType model_types[USDLG_COLUMNS_ALL];
555 int i;
556
557 for (i = 0; i < USDLG_COLUMNS_ALL; i++) {
558 switch (usdlg_col_types[i]) {
559 case COL_PIXBUF:
560 model_types[i] = GDK_TYPE_PIXBUF;
561 break;
562 case COL_TEXT:
563 model_types[i] = G_TYPE_STRING;
564 break;
565 case COL_INT:
566 model_types[i] = G_TYPE_INT;
567 break;
568 }
569 }
570
571 store = gtk_tree_store_newv(i, model_types);
572
573 return store;
574}
575
576/*************************************************************************/
579 static bool usdlg_tab_update(struct unit_select_dialog *pdialog,
580 struct usdata_hash *ushash,
581 enum unit_select_location_mode loc)
582{
583 bool show = FALSE;
584 GtkTreeStore *store;
585
586 fc_assert_ret_val(ushash, FALSE);
587 fc_assert_ret_val(pdialog != NULL, FALSE);
588
589 store = pdialog->tabs[loc].store;
590
591 /* clear current store. */
592 gtk_tree_store_clear(GTK_TREE_STORE(store));
593
594 /* Iterate over all unit types. */
595 if (loc == SELLOC_UNITS) {
596 /* Special case - show all units on this tile in their transports. */
597 unit_type_iterate(utype) {
598 struct usdata *data;
599
600 usdata_hash_lookup(ushash, utype_index(utype), &data);
601
602 if (!data) {
603 continue;
604 }
605
606 activity_type_iterate(act) {
607 if (unit_list_size(data->units[loc][act]) == 0) {
608 continue;
609 }
610
611 unit_list_iterate(data->units[loc][act], punit) {
612 GtkTreeIter it_unit;
613
614 usdlg_tab_append_units(pdialog, loc, act, punit, FALSE,
615 &it_unit, NULL);
616 } unit_list_iterate_end;
617
618 /* Show this tab. */
619 show = TRUE;
620 } activity_type_iterate_end;
621 } unit_type_iterate_end;
622 } else {
623 unit_type_iterate(utype) {
624 struct usdata *data;
625 bool first = TRUE;
626 GtkTreeIter it_utype;
627 GtkTreePath *path;
628 int count = 0;
629
630 usdata_hash_lookup(ushash, utype_index(utype), &data);
631
632 if (!data) {
633 continue;
634 }
635
636 activity_type_iterate(act) {
637 GtkTreeIter it_act;
638
639 if (unit_list_size(data->units[loc][act]) == 0) {
640 continue;
641 }
642
643 /* Level 1: Display unit type. */
644 if (first) {
645 usdlg_tab_append_utype(GTK_TREE_STORE(store), loc, data->utype,
646 &it_utype);
647 first = FALSE;
648 }
649
650 /* Level 2: Display unit activities. */
651 usdlg_tab_append_activity(GTK_TREE_STORE(store), loc, data->utype,
652 act, unit_list_size(data->units[loc][act]),
653 &it_act, &it_utype);
654
655 /* Level 3: Display all units with this activitiy
656 * (and transported units in further level(s)). */
657 unit_list_iterate(data->units[loc][act], punit) {
658 GtkTreeIter it_unit;
659
660 usdlg_tab_append_units(pdialog, loc, act, punit, FALSE,
661 &it_unit, &it_act);
662 } unit_list_iterate_end;
663
664 count += unit_list_size(data->units[loc][act]);
665
666 /* Update sum of units with this type. */
667 gtk_tree_store_set(GTK_TREE_STORE(store), &it_utype, 2, count, -1);
668
669 /* Expand to the activities. */
670 path
671 = gtk_tree_model_get_path(GTK_TREE_MODEL(pdialog->tabs[loc].store),
672 &it_utype);
673 gtk_tree_view_expand_row(GTK_TREE_VIEW(pdialog->tabs[loc].view), path,
674 FALSE);
675 gtk_tree_path_free(path);
676
677 /* Show this tab. */
678 show = TRUE;
679 } activity_type_iterate_end;
680 } unit_type_iterate_end;
681 }
682
683 return show;
684}
685
686/*************************************************************************/
689 static void usdlg_tab_append_utype(GtkTreeStore *store,
690 enum unit_select_location_mode loc,
691 const struct unit_type *putype,
692 GtkTreeIter *it)
693{
694 GdkPixbuf *pix;
695 char buf[128];
696
697 fc_assert_ret(store != NULL);
698 fc_assert_ret(putype != NULL);
699
700 /* Add this item. */
701 gtk_tree_store_append(GTK_TREE_STORE(store), it, NULL);
702
703 /* Create a icon */
704 {
705 struct canvas canvas_store = FC_STATIC_CANVAS_INIT;
706
707 canvas_store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
708 tileset_full_tile_width(tileset), tileset_full_tile_height(tileset));
709
710 put_unittype(putype, &canvas_store, 1.0, 0, 0);
711 pix = surface_get_pixbuf(canvas_store.surface, tileset_full_tile_width(tileset),
712 tileset_full_tile_height(tileset));
713 cairo_surface_destroy(canvas_store.surface);
714 }
715
716 /* The name of the unit. */
717 fc_snprintf(buf, sizeof(buf), "%s", utype_name_translation(putype));
718
719 /* Add it to the tree. */
720 gtk_tree_store_set(GTK_TREE_STORE(store), it,
721 0, pix, /* Unit pixmap */
722 1, buf, /* Text */
723 2, -1, /* will be set later */ /* Number of units */
724 3, utype_index(putype), /* Unit type ID */
725 /* 4: not set */ /* Unit ID */
726 5, loc, /* Unit location */
727 /* 6: not set */ /* Unit activity */
728 7, ROW_UNITTYPE, /* Row type */
729 8, PANGO_STYLE_NORMAL, /* Style */
730 9, PANGO_WEIGHT_BOLD, /* Weight */
731 -1);
732 g_object_unref(pix);
733}
734
735/*************************************************************************/
738 static void usdlg_tab_append_activity(GtkTreeStore *store,
739 enum unit_select_location_mode loc,
740 const struct unit_type *putype,
741 enum unit_activity act,
742 int count, GtkTreeIter *it,
743 GtkTreeIter *parent)
744{
745 char buf[128] = "";
746
747 fc_assert_ret(store != NULL);
748 fc_assert_ret(putype != NULL);
749
750 /* Add this item. */
751 gtk_tree_store_append(GTK_TREE_STORE(store), it, parent);
752
753 /* The activity. */
754 fc_snprintf(buf, sizeof(buf), "%s", get_activity_text(act));
755
756 /* Add it to the tree. */
757 gtk_tree_store_set(GTK_TREE_STORE(store), it,
758 /* 0: not set */ /* Unit pixmap */
759 1, buf, /* Text */
760 2, count, /* Number of units */
761 3, utype_index(putype), /* Unit type ID */
762 /* 4: not set */ /* Unit ID */
763 5, loc, /* Unit location */
764 6, act, /* Unit activity */
765 7, ROW_ACTIVITY, /* Row type */
766 8, PANGO_STYLE_NORMAL, /* Style */
767 9, PANGO_WEIGHT_NORMAL, /* Weight */
768 -1);
769}
770
771/*************************************************************************/
776 GdkPixbuf *usdlg_get_unit_image(const struct unit *punit)
777{
778 GdkPixbuf *out;
779 struct canvas canvas_store = FC_STATIC_CANVAS_INIT;
780
781 canvas_store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
782 tileset_full_tile_width(tileset), tileset_full_tile_height(tileset));
783
784 put_unit(punit, &canvas_store, 1.0, 0, 0);
785 out = surface_get_pixbuf(canvas_store.surface,
786 tileset_full_tile_width(tileset),
787 tileset_full_tile_height(tileset));
788 cairo_surface_destroy(canvas_store.surface);
789
790 return out;
791}
792
793/*************************************************************************/
797 const char *usdlg_get_unit_descr(const struct unit *punit)
798{
799 static char buf[248] = "";
800 char buf2[248] = "";
801 struct city *phome;
802
803 phome = game_city_by_number(punit->homecity);
804 if (phome) {
805 fc_snprintf(buf2, sizeof(buf2), "%s", city_name_get(phome));
806 } else if (unit_owner(punit) == client_player()
807 || client_is_global_observer()) {
808 /* TRANS: used in place of unit home city name */
809 sz_strlcpy(buf2, _("no home city"));
810 } else {
811 /* TRANS: used in place of unit home city name */
812 sz_strlcpy(buf2, _("unknown"));
813 }
814#ifdef FREECIV_DEBUG
815 /* Strings only used in debug builds, don't bother with i18n */
816 fc_snprintf(buf, sizeof(buf), "%s [Unit ID %d]\n(%s)\nCoordinates: (%d,%d)",
817 unit_name_translation(punit), punit->id, buf2,
818 TILE_XY(unit_tile(punit)));
819 {
820 struct unit *ptrans = unit_transport_get(punit);
821
822 if (ptrans) {
823 cat_snprintf(buf, sizeof(buf), "\nTransported by unit ID %d",
824 ptrans->id);
825 }
826 }
827#else /* FREECIV_DEBUG */
828 /* TRANS: unit type and home city, e.g. "Transport\n(New Orleans)" */
829 fc_snprintf(buf, sizeof(buf), _("%s\n(%s)"), unit_name_translation(punit),
830 buf2);
831#endif /* FREECIV_DEBUG */
832
833 return buf;
834}
835
836/*************************************************************************/
839 static void usdlg_tab_append_units(struct unit_select_dialog *pdialog,
840 enum unit_select_location_mode loc,
841 enum unit_activity act,
842 const struct unit *punit,
843 bool transported, GtkTreeIter *it,
844 GtkTreeIter *parent)
845{
846 const char *text;
847 GdkPixbuf *pix;
848 enum usdlg_row_types row = ROW_UNIT;
849 int style = PANGO_STYLE_NORMAL;
850 int weight = PANGO_WEIGHT_NORMAL;
851 GtkTreeStore *store;
852
853 fc_assert_ret(pdialog != NULL);
854 fc_assert_ret(punit != NULL);
855
856 store = pdialog->tabs[loc].store;
857
858
859 /* Add this item. */
860 gtk_tree_store_append(GTK_TREE_STORE(store), it, parent);
861
862 /* Unit gfx */
863 pix = usdlg_get_unit_image(punit);
864
865 text = usdlg_get_unit_descr(punit);
866
867 if (transported) {
868 weight = PANGO_WEIGHT_NORMAL;
869 style = PANGO_STYLE_ITALIC;
870 row = ROW_UNIT_TRANSPORTED;
871 }
872
873 /* Add it to the tree. */
874 gtk_tree_store_set(GTK_TREE_STORE(store), it,
875 0, pix, /* Unit pixmap */
876 1, text, /* Text */
877 2, 1, /* Number of units */
878 3, utype_index(unit_type_get(punit)), /* Unit type ID */
879 4, punit->id, /* Unit ID */
880 5, loc, /* Unit location */
881 6, act, /* Unit activity */
882 7, row, /* Row type */
883 8, style, /* Style */
884 9, weight, /* Weight */
885 -1);
886 g_object_unref(pix);
887
888 if (get_transporter_occupancy(punit) > 0) {
889 unit_list_iterate(unit_transport_cargo(punit), pcargo) {
890 GtkTreeIter it_cargo;
891
892 usdlg_tab_append_units(pdialog, loc, act, pcargo, TRUE, &it_cargo, it);
893 } unit_list_iterate_end;
894 }
895
896 if (!transported && unit_is_in_focus(punit)
897 && get_num_units_in_focus() == 1) {
898 /* Put the keyboard focus on the selected unit. It isn't transported.
899 * Selection maps to keyboard focus since it alone is selected. */
900 fc_assert_action(pdialog->tabs[loc].path == NULL,
901 /* Don't leak memory. */
902 gtk_tree_path_free(pdialog->tabs[loc].path));
903
904 pdialog->tabs[loc].path
905 = gtk_tree_model_get_path(GTK_TREE_MODEL(store), it);
906 }
907}
908
909/*************************************************************************/
912 static void usdlg_cmd_ready(GObject *object, gpointer data)
913{
914 usdlg_cmd_exec(object, data, USDLG_CMD_READY);
915}
916
917/*************************************************************************/
920 static void usdlg_cmd_sentry(GObject *object, gpointer data)
921{
922 usdlg_cmd_exec(object, data, USDLG_CMD_SENTRY);
923}
924
925/*************************************************************************/
928 static void usdlg_cmd_select(GObject *object, gpointer data)
929{
930 usdlg_cmd_exec(object, data, USDLG_CMD_SELECT);
931}
932
933/*************************************************************************/
936 static void usdlg_cmd_deselect(GObject *object, gpointer data)
937{
938 usdlg_cmd_exec(object, data, USDLG_CMD_DESELECT);
939}
940
941/*************************************************************************/
944 static void usdlg_cmd_exec(GObject *object, gpointer mode_data,
945 enum usdlg_cmd cmd)
946{
947 enum unit_select_location_mode loc_mode
948 = (enum unit_select_location_mode) GPOINTER_TO_INT(mode_data);
949 GtkTreeView *view;
950 GtkTreeSelection *selection;
951 GtkTreeModel *model;
952 GtkTreeIter it;
953 gint row;
954 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
955
956 fc_assert_ret(pdialog != NULL);
957 fc_assert_ret(unit_select_location_mode_is_valid(loc_mode));
958
959 if (!can_client_change_view() || !can_client_control()) {
960 return;
961 }
962
963 view = GTK_TREE_VIEW(pdialog->tabs[loc_mode].view);
964 selection = gtk_tree_view_get_selection(view);
965
966 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
967 log_debug("No selection");
968 return;
969 }
970 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, -1);
971
972 switch (row) {
973 case ROW_UNITTYPE:
974 {
975 gint loc, utid;
976 struct usdata_hash *ushash;
977 struct usdata *data;
978
979 gtk_tree_model_get(model, &it, USDLG_COL_LOCATION, &loc,
980 USDLG_COL_UTID, &utid, -1);
981
982 /* We can't be sure that all units still exists - recalc the data. */
983 ushash = usdlg_data_new(pdialog->ptile);
984
985 usdata_hash_lookup(ushash, utid, &data);
986 if (data != NULL) {
987 activity_type_iterate(act) {
988 if (unit_list_size(data->units[loc][act]) == 0) {
989 continue;
990 }
991
992 unit_list_iterate(data->units[loc][act], punit) {
993 usdlg_cmd_exec_unit(punit, cmd);
994 } unit_list_iterate_end;
995 } activity_type_iterate_end;
996 }
997
998 /* Destroy the hash. */
999 usdlg_data_destroy(ushash);
1000 }
1001 break;
1002 case ROW_ACTIVITY:
1003 {
1004 gint loc, act, utid;
1005 struct usdata_hash *ushash;
1006 struct usdata *data;
1007
1008 gtk_tree_model_get(model, &it, USDLG_COL_ACTIVITY, &act,
1009 USDLG_COL_LOCATION, &loc, USDLG_COL_UTID, &utid, -1);
1010
1011 /* We can't be sure that all units still exists - recalc the data. */
1012 ushash = usdlg_data_new(pdialog->ptile);
1013
1014 usdata_hash_lookup(ushash, utid, &data);
1015 if (data != NULL
1016 && unit_list_size(data->units[loc][act]) != 0) {
1017 unit_list_iterate(data->units[loc][act], punit) {
1018 usdlg_cmd_exec_unit(punit, cmd);
1019 } unit_list_iterate_end;
1020 }
1021
1022 /* Destroy the hash. */
1023 usdlg_data_destroy(ushash);
1024 }
1025 break;
1026 case ROW_UNIT:
1027 case ROW_UNIT_TRANSPORTED:
1028 {
1029 gint uid;
1030 struct unit *punit;
1031
1032 gtk_tree_model_get(model, &it, USDLG_COL_UID, &uid, -1);
1033
1034 punit = game_unit_by_number(uid);
1035
1036 if (!punit) {
1037 log_debug("Unit vanished (Unit ID %d)!", uid);
1038 return;
1039 }
1040
1041 usdlg_cmd_exec_unit(punit, cmd);
1042 }
1043 break;
1044 }
1045
1046 /* Update focus. */
1047 unit_focus_update();
1048 /* Refresh dialog. */
1049 usdlg_refresh(pdialog);
1050}
1051
1052/*************************************************************************/
1055 static void usdlg_cmd_exec_unit(struct unit *punit, enum usdlg_cmd cmd)
1056{
1057 fc_assert_ret(punit);
1058
1059 switch (cmd) {
1060 case USDLG_CMD_SELECT:
1061 if (!unit_is_in_focus(punit)) {
1062 unit_focus_add(punit);
1063 }
1064 break;
1065 case USDLG_CMD_DESELECT:
1066 if (unit_is_in_focus(punit)) {
1067 unit_focus_remove(punit);
1068 }
1069 break;
1070 case USDLG_CMD_READY:
1071 if (punit->activity != ACTIVITY_IDLE) {
1072 request_new_unit_activity(punit, ACTIVITY_IDLE);
1073 }
1074 break;
1075 case USDLG_CMD_SENTRY:
1076 if (punit->activity != ACTIVITY_SENTRY) {
1077 request_new_unit_activity(punit, ACTIVITY_SENTRY);
1078 }
1079 break;
1080 case USDLG_CMD_CENTER:
1081 case USDLG_CMD_FOCUS:
1082 /* Nothing here. It is done in its own functions. */
1083 break;
1084 case USDLG_CMD_LAST:
1085 /* Should never happen. */
1086 fc_assert_ret(cmd != USDLG_CMD_LAST);
1087 break;
1088 }
1089}
1090
1091/*************************************************************************/
1094 static void usdlg_cmd_center(GObject *object, gpointer data)
1095{
1096 enum unit_select_location_mode loc
1097 = (enum unit_select_location_mode) GPOINTER_TO_INT(data);
1098 GtkTreeView *view;
1099 GtkTreeSelection *selection;
1100 GtkTreeModel *model;
1101 GtkTreeIter it;
1102 gint row;
1103 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
1104
1105 fc_assert_ret(pdialog != NULL);
1106 fc_assert_ret(unit_select_location_mode_is_valid(loc));
1107
1108 view = GTK_TREE_VIEW(pdialog->tabs[loc].view);
1109 selection = gtk_tree_view_get_selection(view);
1110
1111 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1112 log_debug("No selection");
1113 return;
1114 }
1115 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, -1);
1116
1117 if (row == ROW_UNIT || row == ROW_UNIT_TRANSPORTED) {
1118 gint uid;
1119 struct unit *punit;
1120
1121 gtk_tree_model_get(model, &it, USDLG_COL_UID, &uid, -1);
1122
1123 punit = player_unit_by_number(client_player(), uid);
1124 if (punit) {
1125 center_tile_mapcanvas(unit_tile(punit));
1126 }
1127 }
1128}
1129
1130/*************************************************************************/
1133 static void usdlg_cmd_focus(GObject *object, gpointer data)
1134{
1135 enum unit_select_location_mode loc
1136 = (enum unit_select_location_mode) GPOINTER_TO_INT(data);
1137 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
1138
1139 fc_assert_ret(pdialog != NULL);
1140 fc_assert_ret(unit_select_location_mode_is_valid(loc));
1141
1142 usdlg_cmd_focus_real(GTK_TREE_VIEW(pdialog->tabs[loc].view));
1143}
1144
1145/*************************************************************************/
1148 static void usdlg_cmd_row_activated(GtkTreeView *view, GtkTreePath *path,
1149 GtkTreeViewColumn *col, gpointer data)
1150{
1151 usdlg_cmd_focus_real(view);
1152}
1153
1154/*************************************************************************/
1157 static void usdlg_cmd_focus_real(GtkTreeView *view)
1158{
1159 GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
1160 GtkTreeModel *model;
1161 GtkTreeIter it;
1162 gint row;
1163
1164 if (!can_client_change_view() || !can_client_control()) {
1165 return;
1166 }
1167
1168 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1169 log_debug("No selection");
1170 return;
1171 }
1172 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, -1);
1173
1174 if (row == ROW_UNIT || row == ROW_UNIT_TRANSPORTED) {
1175 gint uid;
1176 struct unit *punit;
1177
1178 gtk_tree_model_get(model, &it, USDLG_COL_UID, &uid, -1);
1179
1180 punit = player_unit_by_number(client_player(), uid);
1181 if (punit && unit_owner(punit) == client_player()) {
1182 unit_focus_set(punit);
1183 usdlg_destroy();
1184 }
1185 }
1186}
1187
1188/*************************************************************************/
1191 static void usdlg_cmd_cursor_changed(GtkTreeView *view, gpointer data)
1192{
1193 enum unit_select_location_mode loc
1194 = (enum unit_select_location_mode) GPOINTER_TO_INT(data);
1195 GtkTreeSelection *selection;
1196 GtkTreeModel *model;
1197 GtkTreeIter it;
1198 gint row, uid;
1199 struct unit_select_dialog *pdialog = usdlg_get(FALSE);
1200 struct unit *punit;
1201 bool cmd_status[USDLG_CMD_LAST];
1202 int cmd_id;
1203
1204 fc_assert_ret(unit_select_location_mode_is_valid(loc));
1205
1206 if (pdialog == NULL) {
1207 /* Dialog closed, nothing we can do */
1208 return;
1209 }
1210
1211 selection = gtk_tree_view_get_selection(view);
1212 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1213 log_debug("No selection");
1214 return;
1215 }
1216 gtk_tree_model_get(model, &it, USDLG_COL_ROW_TYPE, &row, USDLG_COL_UID,
1217 &uid, -1);
1218
1219 switch (row) {
1220 case ROW_UNITTYPE:
1221 case ROW_ACTIVITY:
1222 /* Button status for rows unittype and activity:
1223 * player observer
1224 * ready TRUE FALSE
1225 * sentry TRUE FALSE
1226 * select TRUE FALSE
1227 * deselect TRUE FALSE
1228 * center FALSE FALSE
1229 * focus FALSE FALSE */
1230 if (can_client_change_view() && can_client_control()) {
1231 cmd_status[USDLG_CMD_READY] = TRUE;
1232 cmd_status[USDLG_CMD_SENTRY] = TRUE;
1233 cmd_status[USDLG_CMD_SELECT] = TRUE;
1234 cmd_status[USDLG_CMD_DESELECT] = TRUE;
1235 } else {
1236 cmd_status[USDLG_CMD_READY] = FALSE;
1237 cmd_status[USDLG_CMD_SENTRY] = FALSE;
1238 cmd_status[USDLG_CMD_SELECT] = FALSE;
1239 cmd_status[USDLG_CMD_DESELECT] = FALSE;
1240 }
1241
1242 cmd_status[USDLG_CMD_CENTER] = FALSE;
1243 cmd_status[USDLG_CMD_FOCUS] = FALSE;
1244 break;
1245 case ROW_UNIT:
1246 case ROW_UNIT_TRANSPORTED:
1247 /* Button status for rows unit and unit (transported):
1248 * player observer
1249 * ready !IDLE FALSE
1250 * sentry !SENTRY FALSE
1251 * select !FOCUS FALSE
1252 * deselect FOCUS FALSE
1253 * center TRUE TRUE
1254 * focus !FOCUS FALSE */
1255 punit = player_unit_by_number(client_player(), uid);
1256
1257 if (punit && can_client_change_view() && can_client_control()) {
1258 if (punit->activity == ACTIVITY_IDLE) {
1259 cmd_status[USDLG_CMD_READY] = FALSE;
1260 } else {
1261 cmd_status[USDLG_CMD_READY] = TRUE;
1262 }
1263
1264 if (punit->activity == ACTIVITY_SENTRY) {
1265 cmd_status[USDLG_CMD_SENTRY] = FALSE;
1266 } else {
1267 cmd_status[USDLG_CMD_SENTRY] = TRUE;
1268 }
1269
1270 if (!unit_is_in_focus(punit)) {
1271 cmd_status[USDLG_CMD_SELECT] = TRUE;
1272 cmd_status[USDLG_CMD_DESELECT] = FALSE;
1273 cmd_status[USDLG_CMD_FOCUS] = TRUE;
1274 } else {
1275 cmd_status[USDLG_CMD_SELECT] = FALSE;
1276 cmd_status[USDLG_CMD_DESELECT] = TRUE;
1277 cmd_status[USDLG_CMD_FOCUS] = FALSE;
1278 }
1279 } else {
1280 cmd_status[USDLG_CMD_READY] = FALSE;
1281 cmd_status[USDLG_CMD_SENTRY] = FALSE;
1282
1283 cmd_status[USDLG_CMD_SELECT] = FALSE;
1284 cmd_status[USDLG_CMD_DESELECT] = FALSE;
1285
1286 cmd_status[USDLG_CMD_FOCUS] = FALSE;
1287 }
1288
1289 cmd_status[USDLG_CMD_CENTER] = TRUE;
1290 break;
1291
1292 default:
1293 fc_assert(FALSE);
1294 for (cmd_id = 0; cmd_id < USDLG_CMD_LAST; cmd_id++) {
1295 cmd_status[cmd_id] = FALSE;
1296 }
1297 break;
1298 }
1299
1300 /* Set widget status. */
1301 for (cmd_id = 0; cmd_id < USDLG_CMD_LAST; cmd_id++) {
1302 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->tabs[loc].cmd[cmd_id]),
1303 cmd_status[cmd_id]);
1304 }
1305}
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
can_client_control
bool can_client_control(void)
Definition client_main.c:1253
client_is_global_observer
bool client_is_global_observer(void)
Definition client_main.c:1345
can_client_change_view
bool can_client_change_view(void)
Definition client_main.c:1312
client_main.h
client_player
#define client_player()
Definition client_main.h:106
incite_cost
char * incite_cost
Definition comments.c:74
unit_is_in_focus
bool unit_is_in_focus(const struct unit *punit)
Definition control.c:383
unit_focus_add
void unit_focus_add(struct unit *punit)
Definition control.c:556
unit_focus_set
void unit_focus_set(struct unit *punit)
Definition control.c:501
unit_focus_remove
void unit_focus_remove(struct unit *punit)
Definition control.c:586
head_of_units_in_focus
struct unit * head_of_units_in_focus(void)
Definition control.c:405
get_num_units_in_focus
int get_num_units_in_focus(void)
Definition control.c:185
unit_focus_update
void unit_focus_update(void)
Definition control.c:771
request_new_unit_activity
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
Definition control.c:1903
control.h
punit
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
fc_types.h
fcintl.h
_
#define _(String)
Definition fcintl.h:67
N_
#define N_(String)
Definition fcintl.h:69
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:116
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:107
game.h
goto.h
FC_STATIC_CANVAS_INIT
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
loc
struct tile * loc
Definition citydlg.c:221
toplevel
GtkWidget * toplevel
Definition gui_main.c:125
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
intl_slist
void intl_slist(int n, const char **s, bool *done)
Definition gui_stuff.c:111
title
const char * title
Definition repodlgs.c:1314
surface_get_pixbuf
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
Definition sprite.c:418
USDLG_COL_LOCATION
#define USDLG_COL_LOCATION
Definition unitselect.c:66
usdlg_cmd_ready
static void usdlg_cmd_ready(GObject *object, gpointer data)
Definition unitselect.c:901
usdlg_cmd_deselect
static void usdlg_cmd_deselect(GObject *object, gpointer data)
Definition unitselect.c:925
usdlg_cmd_center
static void usdlg_cmd_center(GObject *object, gpointer data)
Definition unitselect.c:1083
USDLG_COL_ROW_TYPE
#define USDLG_COL_ROW_TYPE
Definition unitselect.c:68
usdlg_cmd_cursor_changed
static void usdlg_cmd_cursor_changed(GtkTreeView *view, gpointer data)
Definition unitselect.c:1180
usdlg_get_unit_image
GdkPixbuf * usdlg_get_unit_image(const struct unit *punit)
Definition unitselect.c:765
usdlg_get_unit_descr
const char * usdlg_get_unit_descr(const struct unit *punit)
Definition unitselect.c:786
usdlg_tab_append_units
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:828
usdlg_tile
static void usdlg_tile(struct unit_select_dialog *pdialog, struct tile *ptile)
Definition unitselect.c:313
USDLG_COL_UTID
#define USDLG_COL_UTID
Definition unitselect.c:64
usdlg_cmd_sentry
static void usdlg_cmd_sentry(GObject *object, gpointer data)
Definition unitselect.c:909
usdlg_get
static struct unit_select_dialog * usdlg_get(bool create)
Definition unitselect.c:223
USDLG_COL_STYLE
#define USDLG_COL_STYLE
Definition unitselect.c:71
USDLG_COL_UID
#define USDLG_COL_UID
Definition unitselect.c:65
usdlg_cmd_exec_unit
static void usdlg_cmd_exec_unit(struct unit *punit, enum usdlg_cmd cmd)
Definition unitselect.c:1044
usdlg_tab_append_activity
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:727
usdlg_create
static struct unit_select_dialog * usdlg_create(void)
Definition unitselect.c:241
usdlg_cmd_focus
static void usdlg_cmd_focus(GObject *object, gpointer data)
Definition unitselect.c:1122
USDLG_COL_ACTIVITY
#define USDLG_COL_ACTIVITY
Definition unitselect.c:67
usdlg_cmd_exec
static void usdlg_cmd_exec(GObject *object, gpointer mode_data, enum usdlg_cmd cmd)
Definition unitselect.c:933
USDLG_COLUMNS_ALL
#define USDLG_COLUMNS_ALL
Definition unitselect.c:73
usdlg_destroy_callback
static void usdlg_destroy_callback(GObject *object, gpointer data)
Definition unitselect.c:305
usdlg_row_types
usdlg_row_types
Definition unitselect.c:54
ROW_UNITTYPE
@ ROW_UNITTYPE
Definition unitselect.c:55
ROW_UNIT_TRANSPORTED
@ ROW_UNIT_TRANSPORTED
Definition unitselect.c:58
ROW_UNIT
@ ROW_UNIT
Definition unitselect.c:57
ROW_ACTIVITY
@ ROW_ACTIVITY
Definition unitselect.c:56
usdlg_cmd_select
static void usdlg_cmd_select(GObject *object, gpointer data)
Definition unitselect.c:917
usdlg_col_titles
static const char * usdlg_col_titles[USDLG_COLUMNS_ALL]
Definition unitselect.c:94
usdlg_cmd_focus_real
static void usdlg_cmd_focus_real(GtkTreeView *view)
Definition unitselect.c:1146
USDLG_COLUMNS_SHOW
#define USDLG_COLUMNS_SHOW
Definition unitselect.c:78
unit_select_dlg
static struct unit_select_dialog * unit_select_dlg
Definition unitselect.c:141
usdlg_col_types
enum usdlg_column_types usdlg_col_types[USDLG_COLUMNS_ALL]
Definition unitselect.c:81
unit_select_dialog_popup_main
void unit_select_dialog_popup_main(struct tile *ptile, bool create)
Definition unitselect.c:193
usdlg_cmd_row_activated
static void usdlg_cmd_row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
Definition unitselect.c:1137
unit_select_dialog_popdown
void unit_select_dialog_popdown(void)
Definition unitselect.c:214
usdlg_tab_append_utype
static void usdlg_tab_append_utype(GtkTreeStore *store, enum unit_select_location_mode loc, const struct unit_type *putype, GtkTreeIter *it)
Definition unitselect.c:678
USDLG_COL_WEIGHT
#define USDLG_COL_WEIGHT
Definition unitselect.c:72
usdlg_tab_select
static void usdlg_tab_select(struct unit_select_dialog *pdialog, const char *title, enum unit_select_location_mode loc)
Definition unitselect.c:387
usdlg_tab_update
static bool usdlg_tab_update(struct unit_select_dialog *pdialog, struct usdata_hash *ushash, enum unit_select_location_mode loc)
Definition unitselect.c:568
usdlg_refresh
static void usdlg_refresh(struct unit_select_dialog *pdialog)
Definition unitselect.c:338
usdlg_column_types
usdlg_column_types
Definition unitselect.c:48
COL_INT
@ COL_INT
Definition unitselect.c:51
COL_TEXT
@ COL_TEXT
Definition unitselect.c:50
COL_PIXBUF
@ COL_PIXBUF
Definition unitselect.c:49
usdlg_cmd
usdlg_cmd
Definition unitselect.c:107
USDLG_CMD_FOCUS
@ USDLG_CMD_FOCUS
Definition unitselect.c:113
USDLG_CMD_SENTRY
@ USDLG_CMD_SENTRY
Definition unitselect.c:111
USDLG_CMD_LAST
@ USDLG_CMD_LAST
Definition unitselect.c:114
USDLG_CMD_CENTER
@ USDLG_CMD_CENTER
Definition unitselect.c:112
USDLG_CMD_READY
@ USDLG_CMD_READY
Definition unitselect.c:110
USDLG_CMD_DESELECT
@ USDLG_CMD_DESELECT
Definition unitselect.c:109
USDLG_CMD_SELECT
@ USDLG_CMD_SELECT
Definition unitselect.c:108
usdlg_destroy
static void usdlg_destroy(void)
Definition unitselect.c:293
usdlg_tab_store_new
static GtkTreeStore * usdlg_tab_store_new(void)
Definition unitselect.c:540
gui_stuff.h
USDLG_CMD_LAST
@ USDLG_CMD_LAST
Definition unitselect.c:114
unitselect.h
show
#define show(id)
Definition widget.h:235
graphics.h
gui_main.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
log_debug
#define log_debug(message,...)
Definition log.h:115
get_center_tile_mapcanvas
struct tile * get_center_tile_mapcanvas(void)
Definition mapview_common.c:1227
put_unit
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
Definition mapview_common.c:1389
put_unittype
void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
Definition mapview_common.c:1403
center_tile_mapcanvas
void center_tile_mapcanvas(const struct tile *ptile)
Definition mapview_common.c:1237
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
player_unit_by_number
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
player.h
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
canvas
Definition canvas.h:22
canvas::surface
cairo_surface_t * surface
Definition canvas.h:23
city
Definition city.h:320
tile
Definition tile.h:50
tileset
Definition tilespec.c:481
unit_select_dialog
Definition unitselect.c:117
unit_select_dialog::ptile
struct tile * ptile
Definition unitselect.c:118
unit_select_dialog::path
GtkTreePath * path
Definition unitselect.c:127
unit_select_dialog::units
struct unit_select_dialog::@158 units
unit_select_dialog::shell
GtkWidget * shell
Definition unitselect.c:121
unit_select_dialog::view
GtkWidget * view
Definition unitselect.c:126
unit_select_dialog::unit_id_focus
int unit_id_focus
Definition unitselect.c:119
unit_select_dialog::cmd
GtkWidget * cmd[USDLG_CMD_LAST]
Definition unitselect.c:136
unit_select_dialog::notebook
GtkWidget * notebook
Definition unitselect.c:122
unit_select_dialog::store
GtkTreeStore * store
Definition unitselect.c:125
unit_select_dialog::tabs
struct unit_select_dialog::@159 tabs[SELLOC_COUNT]
unit_select_dialog::page
GtkWidget * page
Definition unitselect.c:132
unit_type
Definition unittype.h:500
unit
Definition unit.h:138
unit::activity
enum unit_activity activity
Definition unit.h:157
unit::id
int id
Definition unit.h:145
unit::homecity
int homecity
Definition unit.h:146
usdata
Definition unitselect_common.h:24
usdata::units
struct unit_list * units[SELLOC_COUNT][ACTIVITY_LAST]
Definition unitselect_common.h:26
usdata::utype
const struct unit_type * utype
Definition unitselect_common.h:25
view
Definition mapview_common.h:36
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:43
tileset_full_tile_height
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:789
tileset_full_tile_width
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:776
tilespec.h
get_transporter_occupancy
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1779
unit_transport_get
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2437
get_activity_text
const char * get_activity_text(enum unit_activity activity)
Definition unit.c:610
unit_transport_cargo
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2447
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:390
unit_owner
#define unit_owner(_pu)
Definition unit.h:389
activity_type_iterate
#define activity_type_iterate(_act_)
Definition unit.h:284
activity_type_iterate_end
#define activity_type_iterate_end
Definition unit.h:289
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
usdlg_data_new
struct usdata_hash * usdlg_data_new(const struct tile *ptile)
Definition unitselect_common.c:94
usdlg_data_destroy
void usdlg_data_destroy(struct usdata_hash *ushash)
Definition unitselect_common.c:138
unitselect_common.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_name_translation
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1569
utype_index
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
utype_name_translation
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560
unittype.h
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:852
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:859