23#include <gdk/gdkkeysyms.h>
68#define PLR_DLG_COL_STYLE (0 + num_player_dlg_columns)
69#define PLR_DLG_COL_WEIGHT (1 + num_player_dlg_columns)
70#define PLR_DLG_COL_ID (2 + num_player_dlg_columns)
71#define PLR_DLG_COL_TOOLTIP (3 + num_player_dlg_columns)
73#define PLR_DLG_COL_TOTAL (PLR_DLG_COL_TOOLTIP + 1)
85 GVariant *parameter, gpointer data);
131 cairo_surface_t *surface;
139 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
width,
height);
141 cr = cairo_create(surface);
155 cairo_surface_destroy(surface);
222 = GTK_TREE_VIEW(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
227 gtk_tree_view_get_cursor(
view, &path, NULL);
229 GtkTreeModel *model = gtk_tree_view_get_model(
view);
234 gtk_tree_model_get_iter(model, &it, path);
235 gtk_tree_path_free(path);
256 = GTK_TREE_VIEW(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
261 gtk_tree_view_get_cursor(
view, &path, NULL);
263 GtkTreeModel *model = gtk_tree_view_get_model(
view);
268 gtk_tree_model_get_iter(model, &it, path);
269 gtk_tree_path_free(path);
287 GtkTreeIter *a, GtkTreeIter *b, gpointer data)
289 GValue value = { 0, };
294 n = GPOINTER_TO_INT(data);
298 g_value_unset(&value);
302 g_value_unset(&value);
319 model_types[i] = GDK_TYPE_PIXBUF;
322 model_types[i] = GDK_TYPE_PIXBUF;
325 model_types[i] = G_TYPE_BOOLEAN;
329 model_types[i] = G_TYPE_STRING;
335 model_types[i++] = G_TYPE_INT;
336 model_types[i++] = G_TYPE_INT;
337 model_types[i++] = G_TYPE_INT;
338 model_types[i++] = G_TYPE_STRING;
340 store = gtk_list_store_newv(i, model_types);
345 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), i,
366 fc_snprintf(act_name,
sizeof(act_name),
"win.display%d(%s)",
367 pos, pcol->
show ?
"true" :
"false");
368 item = g_menu_item_new(pcol->
title, NULL);
369 g_menu_item_set_detailed_action(
item, act_name);
385 fc_snprintf(act_name,
sizeof(act_name),
"win.show_dead(%s)",
387 item = g_menu_item_new(
Q_(
"?show:Dead Players"), NULL);
388 g_menu_item_set_detailed_action(
item, act_name);
396static void toggle_view(GSimpleAction *act, GVariant *value, gpointer data)
398 int idx = GPOINTER_TO_INT(data);
417 int idx = GPOINTER_TO_INT(data);
442 act = g_simple_action_new(
"meet", NULL);
443 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
448 act = g_simple_action_new(
"cancel_treaty", NULL);
449 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
452 "win.cancel_treaty"));
455 act = g_simple_action_new(
"withdraw_vision", NULL);
456 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
459 "win.withdraw_vision"));
476 act = g_simple_action_new(
"report", NULL);
477 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
482 act = g_simple_action_new(
"wonders", NULL);
483 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
487 act = g_simple_action_new(
"spaceship", NULL);
488 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
501 GVariantType *bvart = g_variant_type_new(
"b");
512 var = g_variant_new(
"b",
TRUE);
513 fc_snprintf(act_name,
sizeof(act_name),
"display%d", i);
514 act = g_simple_action_new_stateful(act_name, bvart, var);
515 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
516 g_signal_connect(act,
"change-state", G_CALLBACK(
toggle_view), GINT_TO_POINTER(i));
521 var = g_variant_new(
"b",
TRUE);
522 act = g_simple_action_new_stateful(
"show_dead", bvart, var);
523 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
529 g_variant_type_free(bvart);
546 act = g_simple_action_new(
"ai_toggle", NULL);
547 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
548 g_signal_connect(act,
"activate",
556 const char *level_name = ai_level_translated_name(
level);
560 act = g_simple_action_new(act_name, NULL);
561 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
562 g_signal_connect(act,
"activate",
564 GUINT_TO_POINTER(
level));
582 GMenu *topmenu, *submenu;
585 GtkEventController *left_controller;
586 GtkEventController *right_controller;
602 players_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL
604 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(
players_list),
614 gesture = gtk_gesture_click_new();
615 left_controller = GTK_EVENT_CONTROLLER(gesture);
616 g_signal_connect(left_controller,
"pressed",
618 gtk_widget_add_controller(
players_list, left_controller);
619 gesture = gtk_gesture_click_new();
620 gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3);
621 right_controller = GTK_EVENT_CONTROLLER(gesture);
622 g_signal_connect(right_controller,
"pressed",
624 gtk_widget_add_controller(
players_list, right_controller);
628 GtkCellRenderer *renderer;
629 GtkTreeViewColumn *col;
634 switch (pcol->
type) {
636 renderer = gtk_cell_renderer_pixbuf_new();
638 col = gtk_tree_view_column_new_with_attributes(pcol->
title,
639 renderer,
"pixbuf", i, NULL);
642 renderer = gtk_cell_renderer_toggle_new();
644 col = gtk_tree_view_column_new_with_attributes(pcol->
title, renderer,
648 renderer = gtk_cell_renderer_pixbuf_new();
650 col = gtk_tree_view_column_new_with_attributes(pcol->
title, renderer,
654 renderer = gtk_cell_renderer_text_new();
655 g_object_set(renderer,
"style-set",
TRUE,
"weight-set",
TRUE, NULL);
657 col = gtk_tree_view_column_new_with_attributes(pcol->
title, renderer,
662 gtk_tree_view_column_set_sort_column_id(col, i);
665 renderer = gtk_cell_renderer_text_new();
666 g_object_set(renderer,
"style-set",
TRUE,
"weight-set",
TRUE, NULL);
668 col = gtk_tree_view_column_new_with_attributes(pcol->
title, renderer,
673 gtk_tree_view_column_set_sort_column_id(col, i);
674 g_object_set(renderer,
"xalign", 1.0, NULL);
675 gtk_tree_view_column_set_alignment(col, 1.0);
680 gtk_tree_view_append_column(GTK_TREE_VIEW(
players_list), col);
684 gtk_tree_view_set_search_column(GTK_TREE_VIEW(
players_list),
687 sw = gtk_scrolled_window_new();
688 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw),
TRUE);
689 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
690 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
691 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw),
players_list);
695 vgrid = gtk_grid_new();
696 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
697 GTK_ORIENTATION_VERTICAL);
699 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
700 gtk_grid_attach(GTK_GRID(vgrid), sep, 0, grid_row++, 1, 1);
703 gtk_grid_attach(GTK_GRID(vgrid), aux_menu, 0, grid_row++, 1, 1);
707 group = G_ACTION_GROUP(g_simple_action_group_new());
708 topmenu = g_menu_new();
722 gtk_widget_insert_action_group(aux_menu,
"win", group);
723 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(aux_menu), G_MENU_MODEL(topmenu));
736#define MIN_DIMENSION 5
745 int x0, y0, x1, y1, w, h;
766 im = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
TRUE, 8, w, h);
770 gdk_pixbuf_copy_area(pixbuf, x0, y0, w, h,
772 g_object_unref(G_OBJECT(pixbuf));
783static void fill_row(GtkListStore *store, GtkTreeIter *it,
784 const struct player *pplayer)
788 int style = PANGO_STYLE_NORMAL, weight = PANGO_WEIGHT_NORMAL;
793 switch (pcol->
type) {
796 gtk_list_store_set(store, it, k, pcol->
func(pplayer), -1);
800 if (pixbuf != NULL) {
801 gtk_list_store_set(store, it, k, pixbuf, -1);
802 g_object_unref(pixbuf);
807 if (pixbuf != NULL) {
808 gtk_list_store_set(store, it, k, pixbuf, -1);
809 g_object_unref(pixbuf);
813 gtk_list_store_set(store, it, k, pcol->
bool_func(pplayer), -1);
825 weight = PANGO_WEIGHT_NORMAL;
826 style = PANGO_STYLE_ITALIC;
830 weight = PANGO_WEIGHT_BOLD;
831 style = PANGO_STYLE_NORMAL;
837 weight = PANGO_WEIGHT_NORMAL;
838 style = PANGO_STYLE_NORMAL;
845 gtk_list_store_set(store, it,
922 char *
title,
char *question)
926 shell = gtk_message_dialog_new(NULL, 0,
927 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
929 gtk_window_set_title(GTK_WINDOW(
shell),
title);
931 gtk_dialog_set_default_response(GTK_DIALOG(
shell), GTK_RESPONSE_NO);
936 gtk_window_destroy(GTK_WINDOW(
shell));
954 enum diplstate_type oldstate, newstate;
964 astr_set(&
title,
_(
"Cancel %s"), diplstate_type_translated_name(oldstate));
966 if (newstate == DS_WAR) {
967 astr_set(&question,
_(
"Really declare war on the %s?"),
971 astr_set(&question,
_(
"Cancel %s %s? New diplomatic state will be %s."),
973 diplstate_type_translated_name(oldstate),
974 diplstate_type_translated_name(newstate));
1002 astr_set(&question,
_(
"Withdraw shared vision from the %s?"),
1017 GtkTreeModel *model;
1037 GtkTreeModel *model;
1055 GtkTreeModel *model;
1070 GVariant *parameter,
1073 GtkTreeModel *model;
1089 GVariant *parameter,
1092 GtkTreeModel *model;
1114 GtkTreeViewColumn *col;
1116 col = gtk_tree_view_get_column(GTK_TREE_VIEW(
players_list), i);
void astr_set(struct astring *astr, const char *format,...)
char * astr_to_str(struct astring *astr)
struct canvas int int struct sprite int int int int height
struct canvas int int struct sprite int int int width
int send_chat_printf(const char *format,...)
bool can_meet_with_player(const struct player *pplayer)
bool can_intel_with_player(const struct player *pplayer)
bool can_client_issue_orders(void)
bool client_has_player(void)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
bool player_has_color(const struct player *pplayer)
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
void gtk_tree_view_focus(GtkTreeView *view)
void gui_dialog_destroy(struct gui_dialog *dlg)
void gui_dialog_present(struct gui_dialog *dlg)
void gui_dialog_raise(struct gui_dialog *dlg)
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
void gui_dialog_show_all(struct gui_dialog *dlg)
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height)
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
void popup_intel_dialog(struct player *p)
void popup_intel_wonder_dialog(struct player *p)
static struct gui_dialog * shell
static GtkWidget * players_int_command
static void players_war_callback(GtkMenuItem *item, gpointer data)
void popdown_players_dialog(void)
static void fill_row(GtkListStore *store, GtkTreeIter *it, const struct player *pplayer)
static GtkTreeSelection * players_selection
static void update_views(void)
static GtkWidget * players_vision_command
static GtkWidget * players_list
static GtkWidget * players_sship_command
struct gui_dialog * players_dialog_shell
static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data)
static void players_sship_callback(GtkMenuItem *item, gpointer data)
#define PLR_DLG_COL_WEIGHT
#define PLR_DLG_COL_STYLE
void real_players_dialog_update(void *unused)
static GtkWidget * create_diplomacy_menu(void)
static bool player_should_be_shown(const struct player *pplayer)
#define PLR_DLG_COL_TOTAL
GdkPixbuf * create_player_icon(const struct player *plr)
static GtkWidget * create_intelligence_menu(void)
void popup_players_dialog(bool raise)
static GtkListStore * players_dialog_store
static void players_intel_wonder_callback(GtkMenuItem *item, gpointer data)
static void toggle_dead_players(GtkCheckMenuItem *item, gpointer data)
#define PLR_DLG_COL_TOOLTIP
static void players_meet_callback(GtkMenuItem *item, gpointer data)
static void confirm_cancel_pact(enum clause_type clause, int plrno, char *title, char *question)
static void players_vision_callback(GtkMenuItem *item, gpointer data)
static gint plrdlg_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
GdkPixbuf * get_flag(const struct nation_type *nation)
static GtkListStore * players_dialog_store_new(void)
static GtkWidget * players_meet_command
static void toggle_view(GtkCheckMenuItem *item, gpointer data)
static void players_ai_skill_callback(GtkMenuItem *item, gpointer data)
static void create_players_dialog(void)
static void players_intel_callback(GtkMenuItem *item, gpointer data)
static void update_players_menu(void)
static GtkWidget * create_show_menu(void)
static GtkWidget * players_war_command
static void selection_callback(GtkTreeSelection *selection, gpointer data)
void popup_spaceship_dialog(struct player *pplayer)
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
void sprite_get_bounding_box(struct sprite *sprite, int *start_x, int *start_y, int *end_x, int *end_y)
gint blocking_dialog(GtkWidget *dlg)
GtkWidget * aux_menu_new(void)
void gui_dialog_add_content_widget(struct gui_dialog *dlg, GtkWidget *wdg)
GtkWidget * gui_dialog_add_action_widget(struct gui_dialog *dlg, GtkWidget *widget)
#define submenu_append_unref(menu, name, submenu)
#define menu_item_insert_unref(menu, index, item)
#define menu_item_append_unref(menu, item)
static GMenu * display_menu
static GMenu * create_ai_menu(GActionGroup *group)
static gboolean right_button_press_callback(GtkGestureClick *gesture, int n_press, double x, double y)
static GMenuItem * create_plrdlg_display_menu_item(int pos)
static GMenuItem * create_dead_players_menu_item(void)
static gboolean left_button_press_callback(GtkGestureClick *gesture, int n_press, double x, double y)
#define fc_assert_ret(condition)
#define fc_assert_ret_val(condition, val)
const char * nation_adjective_for_player(const struct player *pplayer)
struct nation_type * nation_of_player(const struct player *pplayer)
const char * nation_plural_for_player(const struct player *pplayer)
struct client_options gui_options
int dsend_packet_diplomacy_cancel_pact(struct connection *pc, int other_player_id, enum clause_type clause)
int dsend_packet_diplomacy_init_meeting_req(struct connection *pc, int counterpart)
bool is_settable_ai_level(enum ai_level level)
struct player * player_by_number(const int player_id)
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
int player_number(const struct player *pplayer)
const char * player_name(const struct player *pplayer)
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
bool gives_shared_vision(const struct player *me, const struct player *them)
#define ai_level_cmd(_level_)
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
int player_dlg_default_sort_column(void)
struct player_dlg_column player_dlg_columns[]
const int num_player_dlg_columns
struct setting_list * level[OLEVELS_NUM]
bool player_dlg_show_dead_players
bool(* bool_func)(const struct player *)
plr_dlg_sort_func sort_func
const char *(* func)(const struct player *)
enum player_dlg_column_type type
enum spaceship_state state
struct player_spaceship spaceship
struct player_score score
int fc_snprintf(char *str, size_t n, const char *format,...)
const char * score_tooltip(const struct player *pplayer, int score)
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)