Freeciv-3.1
Loading...
Searching...
No Matches
plrdlg.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 <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include <gtk/gtk.h>
23#include <gdk/gdkkeysyms.h>
24
25/* utility */
26#include "astring.h"
27#include "fcintl.h"
28#include "support.h"
29
30/* common */
31#include "diptreaty.h"
32#include "packets.h"
33#include "nation.h"
34#include "player.h"
35
36/* client */
37#include "client_main.h"
38#include "climisc.h"
39#include "connectdlg_common.h"
40#include "tilespec.h"
41#include "colors.h"
42#include "graphics.h"
43#include "options.h"
44#include "text.h"
45
46/* client/gui-gtk-3.22 */
47#include "chatline.h"
48#include "dialogs.h"
49#include "gui_main.h"
50#include "gui_stuff.h"
51#include "inteldlg.h"
52#include "spaceshipdlg.h"
53#include "colors.h"
54#include "graphics.h"
55
56#include "plrdlg.h"
57
59static GtkWidget *players_list;
60static GtkTreeSelection *players_selection;
61static GtkWidget *players_int_command;
62static GtkWidget *players_meet_command;
63static GtkWidget *players_war_command;
64static GtkWidget *players_vision_command;
65static GtkWidget *players_sship_command;
66
67static GtkListStore *players_dialog_store;
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)
72
73#define PLR_DLG_COL_TOTAL (PLR_DLG_COL_TOOLTIP + 1)
74
75static void create_players_dialog(void);
76static void players_meet_callback(GtkMenuItem *item, gpointer data);
77static void players_war_callback(GtkMenuItem *item, gpointer data);
78static void players_vision_callback(GtkMenuItem *item, gpointer data);
79static void players_intel_callback(GtkMenuItem *item, gpointer data);
80static void players_intel_wonder_callback(GtkMenuItem *item, gpointer data);
81static void players_sship_callback(GtkMenuItem *item, gpointer data);
82static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data);
83static void players_ai_skill_callback(GtkMenuItem *item, gpointer data);
84
85
86static void update_views(void);
87
88/**********************************************************************/
101
102/**********************************************************************/
111
112/**********************************************************************/
117GdkPixbuf *create_player_icon(const struct player *plr)
118{
119 int width, height;
120 GdkPixbuf *tmp;
121 cairo_surface_t *surface;
122 struct color *color;
123 cairo_t *cr;
124
125 if (!player_has_color(plr)) {
126 return NULL;
127 }
128
129 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
130 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
131
132 cr = cairo_create(surface);
133
134 color = get_color(tileset, COLOR_PLAYER_COLOR_BACKGROUND);
135 gdk_cairo_set_source_rgba(cr, &color->color);
136 cairo_rectangle(cr, 0, 0, width, height);
137 cairo_fill(cr);
138
140 gdk_cairo_set_source_rgba(cr, &color->color);
141 cairo_rectangle(cr, 1, 1, width - 2, height - 2);
142 cairo_fill(cr);
143
144 cairo_destroy(cr);
145 tmp = surface_get_pixbuf(surface, width, height);
146 cairo_surface_destroy(surface);
147
148 return tmp;
149}
150
151/**********************************************************************/
154static void update_players_menu(void)
155{
156 GtkTreeModel *model;
157 GtkTreeIter it;
158
159 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
160 struct player *plr;
161 gint plrno;
162
163 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
164 plr = player_by_number(plrno);
165
166 if (plr->spaceship.state != SSHIP_NONE) {
167 gtk_widget_set_sensitive(players_sship_command, TRUE);
168 } else {
169 gtk_widget_set_sensitive(players_sship_command, FALSE);
170 }
171
172 if (NULL != client.conn.playing) {
173 /* We keep button sensitive in case of DIPL_SENATE_BLOCKING, so that player
174 * can request server side to check requirements of those effects with omniscience */
175 gtk_widget_set_sensitive(players_war_command,
178 player_by_number(plrno))
179 != DIPL_ERROR);
180 } else {
181 gtk_widget_set_sensitive(players_war_command, FALSE);
182 }
183
184 gtk_widget_set_sensitive(players_vision_command,
188
189 gtk_widget_set_sensitive(players_meet_command, can_meet_with_player(plr));
190 gtk_widget_set_sensitive(players_int_command, can_intel_with_player(plr));
191 return;
192 }
193
194 gtk_widget_set_sensitive(players_meet_command, FALSE);
195 gtk_widget_set_sensitive(players_int_command, FALSE);
196}
197
198/**********************************************************************/
201static void selection_callback(GtkTreeSelection *selection, gpointer data)
202{
204}
205
206/**********************************************************************/
209static gboolean button_press_callback(GtkTreeView *view, GdkEventButton *ev)
210{
211 if (ev->type == GDK_2BUTTON_PRESS) {
212 GtkTreePath *path;
213
214 gtk_tree_view_get_cursor(view, &path, NULL);
215 if (path) {
216 GtkTreeModel *model = gtk_tree_view_get_model(view);
217 GtkTreeIter it;
218 gint id;
219 struct player *plr;
220
221 gtk_tree_model_get_iter(model, &it, path);
222 gtk_tree_path_free(path);
223
224 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &id, -1);
225 plr = player_by_number(id);
226
227 if (ev->button == 1) {
228 if (can_intel_with_player(plr)) {
230 }
231 } else if (can_meet_with_player(plr)) {
233 }
234 }
235 }
236 return FALSE;
237}
238
239/**********************************************************************/
242static gint plrdlg_sort_func(GtkTreeModel *model,
243 GtkTreeIter *a, GtkTreeIter *b, gpointer data)
244{
245 GValue value = { 0, };
246 struct player *player1;
247 struct player *player2;
248 gint n;
249
250 n = GPOINTER_TO_INT(data);
251
252 gtk_tree_model_get_value(model, a, PLR_DLG_COL_ID, &value);
253 player1 = player_by_number(g_value_get_int(&value));
254 g_value_unset(&value);
255
256 gtk_tree_model_get_value(model, b, PLR_DLG_COL_ID, &value);
257 player2 = player_by_number(g_value_get_int(&value));
258 g_value_unset(&value);
259
260 return player_dlg_columns[n].sort_func(player1, player2);
261}
262
263/**********************************************************************/
266static GtkListStore *players_dialog_store_new(void)
267{
268 GtkListStore *store;
269 GType model_types[num_player_dlg_columns + PLR_DLG_COL_TOTAL];
270 int i;
271
272 for (i = 0; i < num_player_dlg_columns; i++) {
273 switch (player_dlg_columns[i].type) {
274 case COL_FLAG:
275 model_types[i] = GDK_TYPE_PIXBUF;
276 break;
277 case COL_COLOR:
278 model_types[i] = GDK_TYPE_PIXBUF;
279 break;
280 case COL_BOOLEAN:
281 model_types[i] = G_TYPE_BOOLEAN;
282 break;
283 case COL_TEXT:
284 case COL_RIGHT_TEXT:
285 model_types[i] = G_TYPE_STRING;
286 break;
287 }
288 }
289
290 /* Special (invisible rows) - Text style, weight and player id */
291 model_types[i++] = G_TYPE_INT; /* PLR_DLG_COL_STYLE. */
292 model_types[i++] = G_TYPE_INT; /* PLR_DLG_COL_WEIGHT. */
293 model_types[i++] = G_TYPE_INT; /* PLR_DLG_COL_ID. */
294 model_types[i++] = G_TYPE_STRING; /* PLR_DLG_COL_TOOLTIP */
295
296 store = gtk_list_store_newv(i, model_types);
297
298 /* Set sort order */
299 for (i = 0; i < num_player_dlg_columns; i++) {
300 if (player_dlg_columns[i].sort_func != NULL) {
301 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), i,
302 plrdlg_sort_func, GINT_TO_POINTER(i),
303 NULL);
304 }
305 }
306
307 return store;
308}
309
310/**********************************************************************/
313static void toggle_view(GtkCheckMenuItem* item, gpointer data)
314{
315 struct player_dlg_column* pcol = data;
316
317 pcol->show = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
318 update_views();
319}
320
321/**********************************************************************/
324static void toggle_dead_players(GtkCheckMenuItem* item, gpointer data)
325{
327 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
329}
330
331/**********************************************************************/
335static GtkWidget *create_diplomacy_menu(void)
336{
337 GtkWidget *menu, *item;
338
339 menu = gtk_menu_new();
340
341 item = gtk_menu_item_new_with_mnemonic(_("_Meet"));
342 g_signal_connect(item, "activate",
343 G_CALLBACK(players_meet_callback), NULL);
344 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
346
347 item = gtk_menu_item_new_with_mnemonic(_("Cancel _Treaty"));
348 g_signal_connect(item, "activate",
349 G_CALLBACK(players_war_callback), NULL);
350 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
352
353 item = gtk_menu_item_new_with_mnemonic(_("_Withdraw Vision"));
354 g_signal_connect(item, "activate",
355 G_CALLBACK(players_vision_callback), NULL);
356 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
358
359 return menu;
360}
361
362/**********************************************************************/
366static GtkWidget *create_intelligence_menu(void)
367{
368 GtkWidget *menu, *item;
369
370 menu = gtk_menu_new();
371
372 item = gtk_menu_item_new_with_mnemonic(_("_Report"));
373 g_signal_connect(item, "activate",
374 G_CALLBACK(players_intel_callback), NULL);
375 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
377
378 item = gtk_menu_item_new_with_mnemonic(_("_Wonders"));
379 g_signal_connect(item, "activate",
380 G_CALLBACK(players_intel_wonder_callback), NULL);
381 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
382
383 item = gtk_menu_item_new_with_mnemonic(_("_Spaceship"));
384 g_signal_connect(item, "activate",
385 G_CALLBACK(players_sship_callback), NULL);
386 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
388
389 return menu;
390}
391
392/**********************************************************************/
395static GtkWidget* create_show_menu(void)
396{
397 int i;
398 GtkWidget *menu = gtk_menu_new();
399 GtkWidget *item;
400
401 /* Index starting at one (1) here to force playername to always be shown */
402 for (i = 1; i < num_player_dlg_columns; i++) {
403 struct player_dlg_column *pcol;
404
405 pcol = &player_dlg_columns[i];
406 item = gtk_check_menu_item_new_with_label(pcol->title);
407 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), pcol->show);
408 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
409 g_signal_connect(item, "toggled", G_CALLBACK(toggle_view), pcol);
410 }
411
412 item = gtk_separator_menu_item_new();
413 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
414
415 item = gtk_check_menu_item_new_with_label(Q_("?show:Dead Players"));
416 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
418 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
419 g_signal_connect(item, "toggled", G_CALLBACK(toggle_dead_players), NULL);
420
421 return menu;
422}
423
424/**********************************************************************/
428{
429 int i;
430 GtkWidget *sep, *sw;
431 GtkWidget *menubar, *menu, *item, *vbox;
432 enum ai_level level;
433
435 TRUE);
436 /* TRANS: Nations report title */
438
439 gui_dialog_add_button(players_dialog_shell, "window-close", _("_Close"),
440 GTK_RESPONSE_CLOSE);
441
443
445
446 players_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL
448 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(players_list),
450 gtk_widget_set_hexpand(players_list, TRUE);
451 gtk_widget_set_vexpand(players_list, TRUE);
452 g_object_unref(players_dialog_store);
453 gtk_widget_set_name(players_list, "small_font");
454
455 players_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(players_list));
456 g_signal_connect(players_selection, "changed",
457 G_CALLBACK(selection_callback), NULL);
458 g_signal_connect(players_list, "button_press_event",
459 G_CALLBACK(button_press_callback), NULL);
460
461 for (i = 0; i < num_player_dlg_columns; i++) {
462 struct player_dlg_column *pcol;
463 GtkCellRenderer *renderer;
464 GtkTreeViewColumn *col;
465
466 pcol = &player_dlg_columns[i];
467 col = NULL;
468
469 switch (pcol->type) {
470 case COL_FLAG:
471 renderer = gtk_cell_renderer_pixbuf_new();
472
473 col = gtk_tree_view_column_new_with_attributes(pcol->title,
474 renderer, "pixbuf", i, NULL);
475 break;
476 case COL_BOOLEAN:
477 renderer = gtk_cell_renderer_toggle_new();
478
479 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
480 "active", i, NULL);
481 break;
482 case COL_COLOR:
483 renderer = gtk_cell_renderer_pixbuf_new();
484
485 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
486 "pixbuf", i, NULL);
487 break;
488 case COL_TEXT:
489 renderer = gtk_cell_renderer_text_new();
490 g_object_set(renderer, "style-set", TRUE, "weight-set", TRUE, NULL);
491
492 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
493 "text", i,
494 "style", PLR_DLG_COL_STYLE,
495 "weight", PLR_DLG_COL_WEIGHT,
496 NULL);
497 gtk_tree_view_column_set_sort_column_id(col, i);
498 break;
499 case COL_RIGHT_TEXT:
500 renderer = gtk_cell_renderer_text_new();
501 g_object_set(renderer, "style-set", TRUE, "weight-set", TRUE, NULL);
502
503 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
504 "text", i,
505 "style", PLR_DLG_COL_STYLE,
506 "weight", PLR_DLG_COL_WEIGHT,
507 NULL);
508 gtk_tree_view_column_set_sort_column_id(col, i);
509 g_object_set(renderer, "xalign", 1.0, NULL);
510 gtk_tree_view_column_set_alignment(col, 1.0);
511 break;
512 }
513
514 if (col) {
515 gtk_tree_view_append_column(GTK_TREE_VIEW(players_list), col);
516 }
517 }
518
519 gtk_tree_view_set_search_column(GTK_TREE_VIEW(players_list),
521
522 sw = gtk_scrolled_window_new(NULL, NULL);
523 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
524 GTK_SHADOW_ETCHED_IN);
525 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
526 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
527 gtk_container_add(GTK_CONTAINER(sw), players_list);
528
529 gtk_container_add(GTK_CONTAINER(players_dialog_shell->vbox), sw);
530
531 vbox = gtk_grid_new();
532 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
533 GTK_ORIENTATION_VERTICAL);
534
535 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
536 gtk_container_add(GTK_CONTAINER(vbox), sep);
537
538 menubar = gtk_aux_menu_bar_new();
539 gtk_container_add(GTK_CONTAINER(vbox), menubar);
540
541
543
544 item = gtk_menu_item_new_with_mnemonic(_("Di_plomacy"));
545 menu = create_diplomacy_menu();
546 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
547 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
548
549 item = gtk_menu_item_new_with_mnemonic(_("_Intelligence"));
551 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
552 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
553
554 item = gtk_menu_item_new_with_mnemonic(_("_Display"));
555 menu = create_show_menu();
556 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
557 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
558
559 item = gtk_menu_item_new_with_mnemonic(_("_AI"));
560 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
561
562 menu = gtk_menu_new();
563 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
564
565 item = gtk_menu_item_new_with_mnemonic(_("_Toggle AI Mode"));
566 g_signal_connect(item, "activate",
567 G_CALLBACK(players_ai_toggle_callback), NULL);
568 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
569
570 sep = gtk_separator_menu_item_new();
571 gtk_menu_shell_append(GTK_MENU_SHELL(menu), sep);
572
573 for (level = 0; level < AI_LEVEL_COUNT; level++) {
575 const char *level_name = ai_level_translated_name(level);
576
577 item = gtk_menu_item_new_with_label(level_name);
578 g_signal_connect(item, "activate",
579 G_CALLBACK(players_ai_skill_callback),
580 GUINT_TO_POINTER(level));
581 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
582 }
583 }
584 gtk_widget_show_all(menu);
585
587
589
591 GTK_RESPONSE_CLOSE);
592
593 gtk_tree_view_focus(GTK_TREE_VIEW(players_list));
594}
595
596
597/**************************************************************************
598...
599**************************************************************************/
600#define MIN_DIMENSION 5
601
602/**********************************************************************/
607GdkPixbuf *get_flag(const struct nation_type *nation)
608{
609 int x0, y0, x1, y1, w, h;
610 GdkPixbuf *im;
611 struct sprite *flag;
612
613 flag = get_nation_flag_sprite(tileset, nation);
614
615 /* calculate the bounding box ... */
616 sprite_get_bounding_box(flag, &x0, &y0, &x1, &y1);
617
618 fc_assert_ret_val(x0 != -1, NULL);
619 fc_assert_ret_val(y0 != -1, NULL);
620 fc_assert_ret_val(x1 != -1, NULL);
621 fc_assert_ret_val(y1 != -1, NULL);
622
623 w = (x1 - x0) + 1;
624 h = (y1 - y0) + 1;
625
626 /* if the flag is smaller then 5 x 5, something is wrong */
628
629 /* croping */
630 im = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
631 if (im != NULL) {
632 GdkPixbuf *pixbuf = sprite_get_pixbuf(flag);
633
634 gdk_pixbuf_copy_area(pixbuf, x0, y0, w, h,
635 im, 0, 0);
636 g_object_unref(G_OBJECT(pixbuf));
637 }
638
639 /* and finally store the scaled flag pixbuf in the static flags array */
640 return im;
641}
642
643
644/**********************************************************************/
648static void fill_row(GtkListStore *store, GtkTreeIter *it,
649 const struct player *pplayer)
650{
651 struct player_dlg_column* pcol;
652 GdkPixbuf *pixbuf;
653 int style = PANGO_STYLE_NORMAL, weight = PANGO_WEIGHT_NORMAL;
654 int k;
655
656 for (k = 0; k < num_player_dlg_columns; k++) {
657 pcol = &player_dlg_columns[k];
658 switch (pcol->type) {
659 case COL_TEXT:
660 case COL_RIGHT_TEXT:
661 gtk_list_store_set(store, it, k, pcol->func(pplayer), -1);
662 break;
663 case COL_FLAG:
664 pixbuf = get_flag(nation_of_player(pplayer));
665 if (pixbuf != NULL) {
666 gtk_list_store_set(store, it, k, pixbuf, -1);
667 g_object_unref(pixbuf);
668 }
669 break;
670 case COL_COLOR:
671 pixbuf = create_player_icon(pplayer);
672 if (pixbuf != NULL) {
673 gtk_list_store_set(store, it, k, pixbuf, -1);
674 g_object_unref(pixbuf);
675 }
676 break;
677 case COL_BOOLEAN:
678 gtk_list_store_set(store, it, k, pcol->bool_func(pplayer), -1);
679 break;
680 }
681 }
682
683 gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP,
684 score_tooltip(pplayer, pplayer->score.game), -1);
685
686 /* Now add some eye candy ... */
687 if (client_has_player()) {
688 switch (player_diplstate_get(client_player(), pplayer)->type) {
689 case DS_WAR:
690 weight = PANGO_WEIGHT_NORMAL;
691 style = PANGO_STYLE_ITALIC;
692 break;
693 case DS_ALLIANCE:
694 case DS_TEAM:
695 weight = PANGO_WEIGHT_BOLD;
696 style = PANGO_STYLE_NORMAL;
697 break;
698 case DS_ARMISTICE:
699 case DS_CEASEFIRE:
700 case DS_PEACE:
701 case DS_NO_CONTACT:
702 weight = PANGO_WEIGHT_NORMAL;
703 style = PANGO_STYLE_NORMAL;
704 break;
705 case DS_LAST:
706 break;
707 }
708 }
709
710 gtk_list_store_set(store, it,
711 PLR_DLG_COL_STYLE, style,
712 PLR_DLG_COL_WEIGHT, weight,
714 -1);
715}
716
717/**********************************************************************/
720static bool player_should_be_shown(const struct player *pplayer)
721{
722 return NULL != pplayer && (gui_options.player_dlg_show_dead_players
723 || pplayer->is_alive)
724 && (!is_barbarian(pplayer));
725}
726
727/**********************************************************************/
731{
732 GtkTreeModel *model;
733 GtkTreeIter iter;
734 int selected;
735
736 if (NULL == players_dialog_shell) {
737 return;
738 }
739
740 /* Save the selection. */
741 if (gtk_tree_selection_get_selected(players_selection, &model, &iter)) {
742 gtk_tree_model_get(model, &iter, PLR_DLG_COL_ID, &selected, -1);
743 } else {
744 selected = -1;
745 }
746
747 gtk_list_store_clear(players_dialog_store);
748 players_iterate(pplayer) {
749 if (!player_should_be_shown(pplayer)) {
750 continue;
751 }
752 gtk_list_store_append(players_dialog_store, &iter);
753 fill_row(players_dialog_store, &iter, pplayer);
754 if (player_number(pplayer) == selected) {
755 /* Restore the selection. */
756 gtk_tree_selection_select_iter(players_selection, &iter);
757 }
759
760 update_views();
761}
762
763/**********************************************************************/
767void players_meet_callback(GtkMenuItem *item, gpointer data)
768{
769 GtkTreeModel *model;
770 GtkTreeIter it;
771
772 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
773 gint plrno;
774
775 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
776
778 }
779}
780
781/**********************************************************************/
785static void confirm_cancel_pact(enum clause_type clause, int plrno,
786 char *title, char *question)
787{
788 GtkWidget *shell;
789
790 shell = gtk_message_dialog_new(NULL, 0,
791 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
792 "%s", question);
793 gtk_window_set_title(GTK_WINDOW(shell), title);
795 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
796
797 if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
799 }
800 gtk_widget_destroy(shell);
801 FC_FREE(title);
802 FC_FREE(question);
803}
804
805/**********************************************************************/
808void players_war_callback(GtkMenuItem *item, gpointer data)
809{
810 GtkTreeModel *model;
811 GtkTreeIter it;
812
813 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
814 struct astring title = ASTRING_INIT, question = ASTRING_INIT;
815 gint plrno;
816 struct player *aplayer;
817 enum diplstate_type oldstate, newstate;
818
819 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
820 aplayer = player_by_number(plrno);
821 fc_assert_ret(aplayer != NULL);
822
823 oldstate = player_diplstate_get(client_player(), aplayer)->type;
824 newstate = cancel_pact_result(oldstate);
825
826 /* TRANS: %s is a diplomatic state: "Cancel Cease-fire" */
827 astr_set(&title, _("Cancel %s"), diplstate_type_translated_name(oldstate));
828
829 if (newstate == DS_WAR) {
830 astr_set(&question, _("Really declare war on the %s?"),
831 nation_plural_for_player(aplayer));
832 } else {
833 /* TRANS: "Cancel Belgian Alliance? ... will be Armistice." */
834 astr_set(&question, _("Cancel %s %s? New diplomatic state will be %s."),
836 diplstate_type_translated_name(oldstate),
837 diplstate_type_translated_name(newstate));
838 }
839
840 /* can be any pact clause */
841 confirm_cancel_pact(CLAUSE_CEASEFIRE, plrno,
842 astr_to_str(&title), astr_to_str(&question));
843 }
844}
845
846/**********************************************************************/
849void players_vision_callback(GtkMenuItem *item, gpointer data)
850{
851 GtkTreeModel *model;
852 GtkTreeIter it;
853
854 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
855 struct astring question = ASTRING_INIT;
856 gint plrno;
857 struct player *aplayer;
858
859 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
860 aplayer = player_by_number(plrno);
861 fc_assert_ret(aplayer != NULL);
862
863 /* TRANS: "...from the Belgians?" */
864 astr_set(&question, _("Withdraw shared vision from the %s?"),
865 nation_plural_for_player(aplayer));
866
867 confirm_cancel_pact(CLAUSE_VISION, plrno,
868 fc_strdup(_("Withdraw Shared Vision")),
869 astr_to_str(&question));
870 }
871}
872
873/**********************************************************************/
876void players_intel_callback(GtkMenuItem *item, gpointer data)
877{
878 GtkTreeModel *model;
879 GtkTreeIter it;
880
881 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
882 gint plrno;
883
884 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
885
888 }
889 }
890}
891
892/**********************************************************************/
895void players_intel_wonder_callback(GtkMenuItem *item, gpointer data)
896{
897 GtkTreeModel *model;
898 GtkTreeIter it;
899
900 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
901 gint plrno;
902
903 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
904
906 }
907}
908
909/**********************************************************************/
912void players_sship_callback(GtkMenuItem *item, gpointer data)
913{
914 GtkTreeModel *model;
915 GtkTreeIter it;
916
917 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
918 gint plrno;
919
920 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
922 }
923}
924
925/**********************************************************************/
928static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data)
929{
930 GtkTreeModel *model;
931 GtkTreeIter it;
932
933 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
934 gint plrno;
935
936 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
937
938 send_chat_printf("/aitoggle \"%s\"", player_name(player_by_number(plrno)));
939 }
940}
941
942/**********************************************************************/
945static void players_ai_skill_callback(GtkMenuItem *item, gpointer data)
946{
947 GtkTreeModel *model;
948 GtkTreeIter it;
949
950 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
951 gint plrno;
952
953 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
954
955 send_chat_printf("/%s %s",
956 ai_level_cmd(GPOINTER_TO_UINT(data)),
958 }
959}
960
961/**********************************************************************/
964static void update_views(void)
965{
966 int i;
967
968 for (i = 0; i < num_player_dlg_columns; i++) {
969 GtkTreeViewColumn *col;
970
971 col = gtk_tree_view_get_column(GTK_TREE_VIEW(players_list), i);
972 gtk_tree_view_column_set_visible(col, player_dlg_columns[i].show);
973 }
974}
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
char * astr_to_str(struct astring *astr)
Definition astring.c:167
#define n
Definition astring.c:77
#define ASTRING_INIT
Definition astring.h:44
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
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)
struct civclient client
bool can_client_issue_orders(void)
bool client_has_player(void)
#define client_player()
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)
int int id
Definition editgui_g.h:28
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
GtkWidget * top_notebook
Definition gui_main.c:128
GtkWidget * toplevel
Definition gui_main.c:124
void gtk_tree_view_focus(GtkTreeView *view)
Definition gui_stuff.c:230
void gui_dialog_destroy(struct gui_dialog *dlg)
Definition gui_stuff.c:951
void gui_dialog_present(struct gui_dialog *dlg)
Definition gui_stuff.c:834
void gui_dialog_set_default_response(struct gui_dialog *dlg, int response)
Definition gui_stuff.c:733
void gui_dialog_raise(struct gui_dialog *dlg)
Definition gui_stuff.c:864
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
Definition gui_stuff.c:504
GtkWidget * gui_dialog_add_widget(struct gui_dialog *dlg, GtkWidget *widget)
Definition gui_stuff.c:721
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
Definition gui_stuff.c:706
void gui_dialog_show_all(struct gui_dialog *dlg)
Definition gui_stuff.c:794
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
Definition gui_stuff.c:932
void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height)
Definition gui_stuff.c:916
GtkWidget * gtk_aux_menu_bar_new(void)
Definition gui_stuff.c:249
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
void popup_intel_dialog(struct player *p)
Definition inteldlg.c:166
void popup_intel_wonder_dialog(struct player *p)
Definition inteldlg.c:182
static struct gui_dialog * shell
Definition messagedlg.c:39
static GtkWidget * players_int_command
Definition plrdlg.c:61
static void players_war_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:810
void popdown_players_dialog(void)
Definition plrdlg.c:105
static void fill_row(GtkListStore *store, GtkTreeIter *it, const struct player *pplayer)
Definition plrdlg.c:650
static GtkTreeSelection * players_selection
Definition plrdlg.c:60
static void update_views(void)
Definition plrdlg.c:966
static GtkWidget * players_vision_command
Definition plrdlg.c:64
static GtkWidget * players_list
Definition plrdlg.c:59
static GtkWidget * players_sship_command
Definition plrdlg.c:65
struct gui_dialog * players_dialog_shell
Definition plrdlg.c:58
static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:930
static void players_sship_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:914
#define PLR_DLG_COL_ID
Definition plrdlg.c:70
#define PLR_DLG_COL_WEIGHT
Definition plrdlg.c:69
#define PLR_DLG_COL_STYLE
Definition plrdlg.c:68
void real_players_dialog_update(void *unused)
Definition plrdlg.c:732
static GtkWidget * create_diplomacy_menu(void)
Definition plrdlg.c:337
static bool player_should_be_shown(const struct player *pplayer)
Definition plrdlg.c:722
#define PLR_DLG_COL_TOTAL
Definition plrdlg.c:73
GdkPixbuf * create_player_icon(const struct player *plr)
Definition plrdlg.c:117
static GtkWidget * create_intelligence_menu(void)
Definition plrdlg.c:368
static gboolean button_press_callback(GtkTreeView *view, GdkEventButton *ev)
Definition plrdlg.c:211
void popup_players_dialog(bool raise)
Definition plrdlg.c:91
static GtkListStore * players_dialog_store
Definition plrdlg.c:67
static void players_intel_wonder_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:897
static void toggle_dead_players(GtkCheckMenuItem *item, gpointer data)
Definition plrdlg.c:326
#define PLR_DLG_COL_TOOLTIP
Definition plrdlg.c:71
static void players_meet_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:769
static void confirm_cancel_pact(enum clause_type clause, int plrno, char *title, char *question)
Definition plrdlg.c:787
static void players_vision_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:851
static gint plrdlg_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
Definition plrdlg.c:244
GdkPixbuf * get_flag(const struct nation_type *nation)
Definition plrdlg.c:609
#define MIN_DIMENSION
Definition plrdlg.c:602
static GtkListStore * players_dialog_store_new(void)
Definition plrdlg.c:268
static GtkWidget * players_meet_command
Definition plrdlg.c:62
static void toggle_view(GtkCheckMenuItem *item, gpointer data)
Definition plrdlg.c:315
static void players_ai_skill_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:947
static void create_players_dialog(void)
Definition plrdlg.c:429
static void players_intel_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:878
static void update_players_menu(void)
Definition plrdlg.c:156
static GtkWidget * create_show_menu(void)
Definition plrdlg.c:397
static GtkWidget * players_war_command
Definition plrdlg.c:63
static void selection_callback(GtkTreeSelection *selection, gpointer data)
Definition plrdlg.c:203
const char * title
Definition repodlgs.c:1313
GType type
Definition repodlgs.c:1312
void popup_spaceship_dialog(struct player *pplayer)
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
Definition sprite.c:418
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
void sprite_get_bounding_box(struct sprite *sprite, int *start_x, int *start_y, int *end_x, int *end_y)
Definition sprite.c:321
@ COL_TEXT
Definition unitselect.c:50
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
struct client_options gui_options
Definition options.c:71
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)
Definition player.c:1883
struct player * player_by_number(const int player_id)
Definition player.c:840
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1452
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:67
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:92
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1461
#define ai_level_cmd(_level_)
Definition player.h:565
#define players_iterate_end
Definition player.h:535
@ DIPL_ERROR
Definition player.h:195
#define players_iterate(_pplayer)
Definition player.h:530
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
int player_dlg_default_sort_column(void)
struct player_dlg_column player_dlg_columns[]
const int num_player_dlg_columns
@ COL_BOOLEAN
@ COL_FLAG
@ COL_RIGHT_TEXT
@ COL_COLOR
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
@ SSHIP_NONE
Definition spaceship.h:84
struct connection conn
Definition client_main.h:96
bool player_dlg_show_dead_players
Definition options.h:212
Definition colors.h:20
GdkRGBA color
Definition colors.h:21
struct player * playing
Definition connection.h:156
GtkWidget * vbox
Definition gui_stuff.h:71
Definition climisc.h:82
enum diplstate_type type
Definition player.h:201
bool(* bool_func)(const struct player *)
plr_dlg_sort_func sort_func
const char *(* func)(const struct player *)
const char * title
enum player_dlg_column_type type
enum spaceship_state state
Definition spaceship.h:108
bool is_alive
Definition player.h:268
struct player_spaceship spaceship
Definition player.h:286
struct player_score score
Definition player.h:283
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * score_tooltip(const struct player *pplayer, int score)
Definition text.c:2157
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6467
#define show(id)
Definition widget.h:235