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_all(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_window_set_position(GTK_WINDOW(pdialog->
shell), GTK_WIN_POS_MOUSE);
260 gtk_widget_realize(pdialog->
shell);
262 vbox = gtk_dialog_get_content_area(GTK_DIALOG(pdialog->
shell));
265 pdialog->
notebook = gtk_notebook_new();
266 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(pdialog->
notebook),
280 close_cmd = gtk_dialog_add_button(GTK_DIALOG(pdialog->
shell),
281 _(
"_Close"), GTK_RESPONSE_CLOSE);
282 gtk_dialog_set_default_response(GTK_DIALOG(pdialog->
shell),
284 g_signal_connect(close_cmd,
"clicked",
323 }
else if (pdialog->
ptile == NULL) {
340 struct usdata_hash *ushash = NULL;
341 enum unit_select_location_mode
loc;
350 for (
loc = unit_select_location_mode_begin();
351 loc != unit_select_location_mode_end();
352 loc = unit_select_location_mode_next(
loc)) {
361 gtk_tree_view_expand_row(GTK_TREE_VIEW(pdialog->
tabs[
loc].
view),
363 gtk_tree_view_set_cursor(GTK_TREE_VIEW(pdialog->
tabs[
loc].
view),
389 enum unit_select_location_mode
loc)
391 GtkWidget *page, *label, *hbox, *vbox, *
view, *sw;
393 static bool titles_done;
396 page = gtk_grid_new();
397 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
398 GTK_ORIENTATION_VERTICAL);
399 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
402 label = gtk_label_new_with_mnemonic(
title);
403 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->
notebook), page, label);
405 hbox = gtk_grid_new();
406 gtk_container_add(GTK_CONTAINER(page), hbox);
411 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
415 g_object_unref(store);
418 GINT_TO_POINTER(
loc));
419 g_signal_connect(
view,
"cursor-changed",
426 GtkTreeViewColumn *column = NULL;
427 GtkCellRenderer *renderer = NULL;
431 renderer = gtk_cell_renderer_pixbuf_new();
432 column = gtk_tree_view_column_new_with_attributes(
434 gtk_tree_view_column_set_expand(column,
FALSE);
437 renderer = gtk_cell_renderer_text_new();
438 column = gtk_tree_view_column_new_with_attributes(
441 gtk_tree_view_column_set_expand(column,
TRUE);
444 renderer = gtk_cell_renderer_text_new();
445 column = gtk_tree_view_column_new_with_attributes(
448 g_object_set(renderer,
"xalign", 1.0, NULL);
449 gtk_tree_view_column_set_alignment(column, 1.0);
450 gtk_tree_view_column_set_expand(column,
FALSE);
455 gtk_tree_view_append_column(GTK_TREE_VIEW(
view), column);
458 sw = gtk_scrolled_window_new(NULL, NULL);
459 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 300);
460 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
461 GTK_SHADOW_ETCHED_IN);
462 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
463 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
464 gtk_container_add(GTK_CONTAINER(sw),
view);
465 gtk_container_add(GTK_CONTAINER(hbox), sw);
467 vbox = gtk_grid_new();
468 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
469 GTK_ORIENTATION_VERTICAL);
470 gtk_container_add(GTK_CONTAINER(hbox), vbox);
475 = gtk_button_new_with_mnemonic(
_(
"Ready"));
476 gtk_container_add(GTK_CONTAINER(vbox),
480 gtk_widget_set_sensitive(
484 = gtk_button_new_with_mnemonic(
_(
"Sentry"));
485 gtk_widget_set_margin_bottom(
487 gtk_container_add(GTK_CONTAINER(vbox),
491 gtk_widget_set_sensitive(
497 = gtk_button_new_with_mnemonic(
_(
"_Select"));
498 gtk_container_add(GTK_CONTAINER(vbox),
502 gtk_widget_set_sensitive(
506 = gtk_button_new_with_mnemonic(
_(
"_Deselect"));
507 gtk_widget_set_margin_bottom(
509 gtk_container_add(GTK_CONTAINER(vbox),
513 gtk_widget_set_sensitive(
519 = gtk_button_new_with_mnemonic(
_(
"C_enter"));
520 gtk_container_add(GTK_CONTAINER(vbox),
524 gtk_widget_set_sensitive(
528 = gtk_button_new_with_mnemonic(
_(
"_Focus"));
529 gtk_container_add(GTK_CONTAINER(vbox),
533 gtk_widget_set_sensitive(
549 model_types[i] = GDK_TYPE_PIXBUF;
552 model_types[i] = G_TYPE_STRING;
555 model_types[i] = G_TYPE_INT;
560 store = gtk_tree_store_newv(i, model_types);
569 struct usdata_hash *ushash,
570 enum unit_select_location_mode
loc)
581 gtk_tree_store_clear(GTK_TREE_STORE(store));
584 if (
loc == SELLOC_UNITS) {
596 if (unit_list_size(data->
units[
loc][act]) == 0) {
615 GtkTreeIter it_utype;
628 if (unit_list_size(data->
units[
loc][act]) == 0) {
641 act, unit_list_size(data->
units[
loc][act]),
653 count += unit_list_size(data->
units[
loc][act]);
656 gtk_tree_store_set(GTK_TREE_STORE(store), &it_utype, 2, count, -1);
660 = gtk_tree_model_get_path(GTK_TREE_MODEL(pdialog->
tabs[
loc].
store),
662 gtk_tree_view_expand_row(GTK_TREE_VIEW(pdialog->
tabs[
loc].
view), path,
664 gtk_tree_path_free(path);
679 enum unit_select_location_mode
loc,
690 gtk_tree_store_append(GTK_TREE_STORE(store), it, NULL);
696 canvas_store.
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
702 cairo_surface_destroy(canvas_store.
surface);
709 gtk_tree_store_set(GTK_TREE_STORE(store), it,
718 8, PANGO_STYLE_NORMAL,
719 9, PANGO_WEIGHT_BOLD,
728 enum unit_select_location_mode
loc,
730 enum unit_activity act,
731 int count, GtkTreeIter *it,
740 gtk_tree_store_append(GTK_TREE_STORE(store), it, parent);
746 gtk_tree_store_set(GTK_TREE_STORE(store), it,
755 8, PANGO_STYLE_NORMAL,
756 9, PANGO_WEIGHT_NORMAL,
770 canvas_store.
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
777 cairo_surface_destroy(canvas_store.
surface);
788 static char buf[248] =
"";
805 fc_snprintf(buf,
sizeof(buf),
"%s [Unit ID %d]\n(%s)\nCoordinates: (%d,%d)",
812 cat_snprintf(buf,
sizeof(buf),
"\nTransported by unit ID %d",
829 enum unit_select_location_mode
loc,
830 enum unit_activity act,
832 bool transported, GtkTreeIter *it,
838 int style = PANGO_STYLE_NORMAL;
839 int weight = PANGO_WEIGHT_NORMAL;
849 gtk_tree_store_append(GTK_TREE_STORE(store), it, parent);
857 weight = PANGO_WEIGHT_NORMAL;
858 style = PANGO_STYLE_ITALIC;
863 gtk_tree_store_set(GTK_TREE_STORE(store), it,
879 GtkTreeIter it_cargo;
894 = gtk_tree_model_get_path(GTK_TREE_MODEL(store), it);
936 enum unit_select_location_mode loc_mode
937 = (
enum unit_select_location_mode) GPOINTER_TO_INT(mode_data);
939 GtkTreeSelection *selection;
953 selection = gtk_tree_view_get_selection(
view);
955 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
965 struct usdata_hash *ushash;
974 usdata_hash_lookup(ushash, utid, &data);
977 if (unit_list_size(data->
units[
loc][act]) == 0) {
994 struct usdata_hash *ushash;
1003 usdata_hash_lookup(ushash, utid, &data);
1005 && unit_list_size(data->
units[
loc][act]) != 0) {
1026 log_debug(
"Unit vanished (Unit ID %d)!", uid);
1085 enum unit_select_location_mode
loc
1086 = (
enum unit_select_location_mode) GPOINTER_TO_INT(data);
1088 GtkTreeSelection *selection;
1089 GtkTreeModel *model;
1098 selection = gtk_tree_view_get_selection(
view);
1100 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1124 enum unit_select_location_mode
loc
1125 = (
enum unit_select_location_mode) GPOINTER_TO_INT(data);
1138 GtkTreeViewColumn *col, gpointer data)
1148 GtkTreeSelection *selection = gtk_tree_view_get_selection(
view);
1149 GtkTreeModel *model;
1157 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1182 enum unit_select_location_mode
loc
1183 = (
enum unit_select_location_mode) GPOINTER_TO_INT(data);
1184 GtkTreeSelection *selection;
1185 GtkTreeModel *model;
1195 if (pdialog == NULL) {
1200 selection = gtk_tree_view_get_selection(
view);
1201 if (!gtk_tree_selection_get_selected(selection, &model, &it)) {
1284 cmd_status[cmd_id] =
FALSE;
1291 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->
tabs[
loc].
cmd[cmd_id]),
1292 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