62#define USDLG_COLUMNS_DEFAULT 3
64#define USDLG_COL_UTID USDLG_COLUMNS_DEFAULT + 0
65#define USDLG_COL_UID USDLG_COLUMNS_DEFAULT + 1
66#define USDLG_COL_LOCATION USDLG_COLUMNS_DEFAULT + 2
67#define USDLG_COL_ACTIVITY USDLG_COLUMNS_DEFAULT + 3
68#define USDLG_COL_ROW_TYPE USDLG_COLUMNS_DEFAULT + 4
69#define USDLG_COLUMNS_DEBUG USDLG_COLUMNS_DEFAULT + 5
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
76 #define USDLG_COLUMNS_SHOW USDLG_COLUMNS_DEBUG
78 #define USDLG_COLUMNS_SHOW USDLG_COLUMNS_DEFAULT
153 enum unit_select_location_mode
loc);
156 struct usdata_hash *ushash,
157 enum unit_select_location_mode
loc);
159 enum unit_select_location_mode
loc,
163 enum unit_select_location_mode
loc,
165 enum unit_activity act,
166 int count, GtkTreeIter *it,
167 GtkTreeIter *parent);
169 enum unit_select_location_mode
loc,
170 enum unit_activity act,
172 bool transported, GtkTreeIter *it,
173 GtkTreeIter *parent);
186 GtkTreeViewColumn *col, gpointer data);
203 gtk_widget_show(GTK_WIDGET(pdialog->
shell));
244 GtkWidget *close_cmd;
248 pdialog =
fc_calloc(1,
sizeof(*pdialog));
251 pdialog->
ptile = NULL;
254 pdialog->
shell = gtk_dialog_new();
255 gtk_window_set_title(GTK_WINDOW(pdialog->
shell),
_(
"Unit selection"));
257 g_signal_connect(pdialog->
shell,
"destroy",
259 gtk_widget_realize(pdialog->
shell);
261 vbox = gtk_dialog_get_content_area(GTK_DIALOG(pdialog->
shell));
264 pdialog->
notebook = gtk_notebook_new();
265 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(pdialog->
notebook),
267 gtk_box_insert_child_after(GTK_BOX(vbox), pdialog->
notebook, NULL);
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),
283 g_signal_connect(close_cmd,
"clicked",
322 }
else if (pdialog->
ptile == NULL) {
339 struct usdata_hash *ushash = NULL;
340 enum unit_select_location_mode
loc;
349 for (
loc = unit_select_location_mode_begin();
350 loc != unit_select_location_mode_end();
351 loc = unit_select_location_mode_next(
loc)) {
360 gtk_tree_view_expand_row(GTK_TREE_VIEW(pdialog->
tabs[
loc].
view),
362 gtk_tree_view_set_cursor(GTK_TREE_VIEW(pdialog->
tabs[
loc].
view),
388 enum unit_select_location_mode
loc)
390 GtkWidget *page, *label, *hgrid, *vgrid, *
view, *sw;
392 static bool titles_done;
398 page = gtk_grid_new();
399 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
400 GTK_ORIENTATION_VERTICAL);
401 gtk_widget_set_margin_start(page, 8);
402 gtk_widget_set_margin_end(page, 8);
403 gtk_widget_set_margin_top(page, 8);
404 gtk_widget_set_margin_bottom(page, 8);
407 label = gtk_label_new_with_mnemonic(
title);
408 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->
notebook), page, label);
410 hgrid = gtk_grid_new();
411 gtk_grid_attach(GTK_GRID(page), hgrid, 0, page_row++, 1, 1);
416 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
420 g_object_unref(store);
423 GINT_TO_POINTER(
loc));
424 g_signal_connect(
view,
"cursor-changed",
431 GtkTreeViewColumn *column = NULL;
432 GtkCellRenderer *renderer = NULL;
436 renderer = gtk_cell_renderer_pixbuf_new();
437 column = gtk_tree_view_column_new_with_attributes(
439 gtk_tree_view_column_set_expand(column,
FALSE);
442 renderer = gtk_cell_renderer_text_new();
443 column = gtk_tree_view_column_new_with_attributes(
446 gtk_tree_view_column_set_expand(column,
TRUE);
449 renderer = gtk_cell_renderer_text_new();
450 column = gtk_tree_view_column_new_with_attributes(
453 g_object_set(renderer,
"xalign", 1.0, NULL);
454 gtk_tree_view_column_set_alignment(column, 1.0);
455 gtk_tree_view_column_set_expand(column,
FALSE);
460 gtk_tree_view_append_column(GTK_TREE_VIEW(
view), column);
463 sw = gtk_scrolled_window_new();
464 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 300);
465 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw),
TRUE);
466 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
467 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
468 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw),
view);
469 gtk_grid_attach(GTK_GRID(hgrid), sw, grid_col++, 0, 1, 1);
471 vgrid = gtk_grid_new();
472 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
473 GTK_ORIENTATION_VERTICAL);
474 gtk_grid_attach(GTK_GRID(hgrid), vgrid, grid_col++, 0, 1, 1);
479 = gtk_button_new_with_mnemonic(
_(
"Ready"));
480 gtk_grid_attach(GTK_GRID(vgrid),
482 0, grid_row++, 1, 1);
485 gtk_widget_set_sensitive(
489 = gtk_button_new_with_mnemonic(
_(
"Sentry"));
490 gtk_widget_set_margin_bottom(
492 gtk_grid_attach(GTK_GRID(vgrid),
494 0, grid_row++, 1, 1);
497 gtk_widget_set_sensitive(
503 = gtk_button_new_with_mnemonic(
_(
"_Select"));
504 gtk_grid_attach(GTK_GRID(vgrid),
506 0, grid_row++, 1, 1);
509 gtk_widget_set_sensitive(
513 = gtk_button_new_with_mnemonic(
_(
"_Deselect"));
514 gtk_widget_set_margin_bottom(
516 gtk_grid_attach(GTK_GRID(vgrid),
518 0, grid_row++, 1, 1);
521 gtk_widget_set_sensitive(
527 = gtk_button_new_with_mnemonic(
_(
"C_enter"));
528 gtk_grid_attach(GTK_GRID(vgrid),
530 0, grid_row++, 1, 1);
533 gtk_widget_set_sensitive(
537 = gtk_button_new_with_mnemonic(
_(
"_Focus"));
538 gtk_grid_attach(GTK_GRID(vgrid),
540 0, grid_row++, 1, 1);
543 gtk_widget_set_sensitive(
559 model_types[i] = GDK_TYPE_PIXBUF;
562 model_types[i] = G_TYPE_STRING;
565 model_types[i] = G_TYPE_INT;
570 store = gtk_tree_store_newv(i, model_types);
579 struct usdata_hash *ushash,
580 enum unit_select_location_mode
loc)
591 gtk_tree_store_clear(GTK_TREE_STORE(store));
594 if (
loc == SELLOC_UNITS) {
606 if (unit_list_size(data->
units[
loc][act]) == 0) {
625 GtkTreeIter it_utype;
638 if (unit_list_size(data->
units[
loc][act]) == 0) {
651 act, unit_list_size(data->
units[
loc][act]),
663 count += unit_list_size(data->
units[
loc][act]);
666 gtk_tree_store_set(GTK_TREE_STORE(store), &it_utype, 2, count, -1);
670 = gtk_tree_model_get_path(GTK_TREE_MODEL(pdialog->
tabs[
loc].
store),
672 gtk_tree_view_expand_row(GTK_TREE_VIEW(pdialog->
tabs[
loc].
view), path,
674 gtk_tree_path_free(path);
689 enum unit_select_location_mode
loc,
700 gtk_tree_store_append(GTK_TREE_STORE(store), it, NULL);
706 canvas_store.
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
712 cairo_surface_destroy(canvas_store.
surface);
719 gtk_tree_store_set(GTK_TREE_STORE(store), it,
728 8, PANGO_STYLE_NORMAL,
729 9, PANGO_WEIGHT_BOLD,
738 enum unit_select_location_mode
loc,
740 enum unit_activity act,
741 int count, GtkTreeIter *it,
750 gtk_tree_store_append(GTK_TREE_STORE(store), it, parent);
756 gtk_tree_store_set(GTK_TREE_STORE(store), it,
765 8, PANGO_STYLE_NORMAL,
766 9, PANGO_WEIGHT_NORMAL,
780 canvas_store.
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
787 cairo_surface_destroy(canvas_store.
surface);
798 static char buf[248] =
"";
815 fc_snprintf(buf,
sizeof(buf),
"%s [Unit ID %d]\n(%s)\nCoordinates: (%d,%d)",
822 cat_snprintf(buf,
sizeof(buf),
"\nTransported by unit ID %d",
839 enum unit_select_location_mode
loc,
840 enum unit_activity act,
842 bool transported, GtkTreeIter *it,
848 int style = PANGO_STYLE_NORMAL;
849 int weight = PANGO_WEIGHT_NORMAL;
859 gtk_tree_store_append(GTK_TREE_STORE(store), it, parent);
867 weight = PANGO_WEIGHT_NORMAL;
868 style = PANGO_STYLE_ITALIC;
873 gtk_tree_store_set(GTK_TREE_STORE(store), it,
889 GtkTreeIter it_cargo;
904 = gtk_tree_model_get_path(GTK_TREE_MODEL(store), it);
946 enum unit_select_location_mode loc_mode
947 = (
enum unit_select_location_mode) GPOINTER_TO_INT(mode_data);
949 GtkTreeSelection *selection;
963 selection = gtk_tree_view_get_selection(
view);
965 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
975 struct usdata_hash *ushash;
984 usdata_hash_lookup(ushash, utid, &data);
987 if (unit_list_size(data->
units[
loc][act]) == 0) {
1003 gint
loc, act, utid;
1004 struct usdata_hash *ushash;
1013 usdata_hash_lookup(ushash, utid, &data);
1015 && unit_list_size(data->
units[
loc][act]) != 0) {
1036 log_debug(
"Unit vanished (Unit ID %d)!", uid);
1095 enum unit_select_location_mode
loc
1096 = (
enum unit_select_location_mode) GPOINTER_TO_INT(data);
1098 GtkTreeSelection *selection;
1099 GtkTreeModel *model;
1108 selection = gtk_tree_view_get_selection(
view);
1110 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1134 enum unit_select_location_mode
loc
1135 = (
enum unit_select_location_mode) GPOINTER_TO_INT(data);
1148 GtkTreeViewColumn *col, gpointer data)
1158 GtkTreeSelection *selection = gtk_tree_view_get_selection(
view);
1159 GtkTreeModel *model;
1167 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1192 enum unit_select_location_mode
loc
1193 = (
enum unit_select_location_mode) GPOINTER_TO_INT(data);
1194 GtkTreeSelection *selection;
1195 GtkTreeModel *model;
1205 if (pdialog == NULL) {
1210 selection = gtk_tree_view_get_selection(
view);
1211 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1294 cmd_status[cmd_id] =
FALSE;
1301 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->
tabs[
loc].
cmd[cmd_id]),
1302 cmd_status[cmd_id]);
const char * city_name_get(const struct city *pcity)
bool can_client_control(void)
bool client_is_global_observer(void)
bool can_client_change_view(void)
bool unit_is_in_focus(const struct unit *punit)
void unit_focus_add(struct unit *punit)
void unit_focus_set(struct unit *punit)
void unit_focus_remove(struct unit *punit)
struct unit * head_of_units_in_focus(void)
int get_num_units_in_focus(void)
void unit_focus_update(void)
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
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
struct unit * game_unit_by_number(int id)
struct city * game_city_by_number(int id)
#define FC_STATIC_CANVAS_INIT
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
void intl_slist(int n, const char **s, bool *done)
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
#define USDLG_COL_LOCATION
static void usdlg_cmd_ready(GObject *object, gpointer data)
static void usdlg_cmd_deselect(GObject *object, gpointer data)
static void usdlg_cmd_center(GObject *object, gpointer data)
#define USDLG_COL_ROW_TYPE
static void usdlg_cmd_cursor_changed(GtkTreeView *view, gpointer data)
GdkPixbuf * usdlg_get_unit_image(const struct unit *punit)
const char * usdlg_get_unit_descr(const struct unit *punit)
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)
static void usdlg_tile(struct unit_select_dialog *pdialog, struct tile *ptile)
static void usdlg_cmd_sentry(GObject *object, gpointer data)
static struct unit_select_dialog * usdlg_get(bool create)
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)
static struct unit_select_dialog * usdlg_create(void)
static void usdlg_cmd_focus(GObject *object, gpointer data)
#define USDLG_COL_ACTIVITY
static void usdlg_cmd_exec(GObject *object, gpointer mode_data, enum usdlg_cmd cmd)
#define USDLG_COLUMNS_ALL
static void usdlg_destroy_callback(GObject *object, gpointer data)
static void usdlg_cmd_select(GObject *object, gpointer data)
static const char * usdlg_col_titles[USDLG_COLUMNS_ALL]
static void usdlg_cmd_focus_real(GtkTreeView *view)
#define USDLG_COLUMNS_SHOW
static struct unit_select_dialog * unit_select_dlg
enum usdlg_column_types usdlg_col_types[USDLG_COLUMNS_ALL]
void unit_select_dialog_popup_main(struct tile *ptile, bool create)
static void usdlg_cmd_row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
void unit_select_dialog_popdown(void)
static void usdlg_tab_append_utype(GtkTreeStore *store, enum unit_select_location_mode loc, const struct unit_type *putype, GtkTreeIter *it)
static void usdlg_tab_select(struct unit_select_dialog *pdialog, const char *title, enum unit_select_location_mode loc)
static bool usdlg_tab_update(struct unit_select_dialog *pdialog, struct usdata_hash *ushash, enum unit_select_location_mode loc)
static void usdlg_refresh(struct unit_select_dialog *pdialog)
static void usdlg_destroy(void)
static GtkTreeStore * usdlg_tab_store_new(void)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
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)
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
cairo_surface_t * surface
GtkWidget * cmd[USDLG_CMD_LAST]
struct unit_select_dialog::@156 units
struct unit_select_dialog::@157 tabs[SELLOC_COUNT]
enum unit_activity activity
struct unit_list * units[SELLOC_COUNT][ACTIVITY_LAST]
const struct unit_type * utype
int fc_snprintf(char *str, size_t n, const char *format,...)
int cat_snprintf(char *str, size_t n, const char *format,...)
#define sz_strlcpy(dest, src)
int tileset_full_tile_height(const struct tileset *t)
int tileset_full_tile_width(const struct tileset *t)
int get_transporter_occupancy(const struct unit *ptrans)
struct unit * unit_transport_get(const struct unit *pcargo)
const char * get_activity_text(enum unit_activity activity)
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
#define activity_type_iterate(_act_)
#define activity_type_iterate_end
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
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)
const char * unit_name_translation(const struct unit *punit)
Unit_type_id utype_index(const struct unit_type *punittype)
const char * utype_name_translation(const struct unit_type *punittype)
#define unit_type_iterate(_p)
#define unit_type_iterate_end