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.0 */
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_for_settings(
130 gtk_settings_get_for_screen(gtk_widget_get_screen(top_notebook)),
131 GTK_ICON_SIZE_MENU, &width, &height);
132 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
133
134 cr = cairo_create(surface);
135
136 color = get_color(tileset, COLOR_PLAYER_COLOR_BACKGROUND);
137 gdk_cairo_set_source_rgba(cr, &color->color);
138 cairo_rectangle(cr, 0, 0, width, height);
139 cairo_fill(cr);
140
142 gdk_cairo_set_source_rgba(cr, &color->color);
143 cairo_rectangle(cr, 1, 1, width - 2, height - 2);
144 cairo_fill(cr);
145
146 cairo_destroy(cr);
147 tmp = surface_get_pixbuf(surface, width, height);
148 cairo_surface_destroy(surface);
149
150 return tmp;
151}
152
153/**********************************************************************/
156static void update_players_menu(void)
157{
158 GtkTreeModel *model;
159 GtkTreeIter it;
160
161 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
162 struct player *plr;
163 gint plrno;
164
165 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
166 plr = player_by_number(plrno);
167
168 if (plr->spaceship.state != SSHIP_NONE) {
169 gtk_widget_set_sensitive(players_sship_command, TRUE);
170 } else {
171 gtk_widget_set_sensitive(players_sship_command, FALSE);
172 }
173
174 if (NULL != client.conn.playing) {
175 /* We keep button sensitive in case of DIPL_SENATE_BLOCKING, so that player
176 * can request server side to check requirements of those effects with omniscience */
177 gtk_widget_set_sensitive(players_war_command,
180 player_by_number(plrno))
181 != DIPL_ERROR);
182 } else {
183 gtk_widget_set_sensitive(players_war_command, FALSE);
184 }
185
186 gtk_widget_set_sensitive(players_vision_command,
190
191 gtk_widget_set_sensitive(players_meet_command, can_meet_with_player(plr));
192 gtk_widget_set_sensitive(players_int_command, can_intel_with_player(plr));
193 return;
194 }
195
196 gtk_widget_set_sensitive(players_meet_command, FALSE);
197 gtk_widget_set_sensitive(players_int_command, FALSE);
198}
199
200/**********************************************************************/
203static void selection_callback(GtkTreeSelection *selection, gpointer data)
204{
206}
207
208/**********************************************************************/
211static gboolean button_press_callback(GtkTreeView *view, GdkEventButton *ev)
212{
213 if (ev->type == GDK_2BUTTON_PRESS) {
214 GtkTreePath *path;
215
216 gtk_tree_view_get_cursor(view, &path, NULL);
217 if (path) {
218 GtkTreeModel *model = gtk_tree_view_get_model(view);
219 GtkTreeIter it;
220 gint id;
221 struct player *plr;
222
223 gtk_tree_model_get_iter(model, &it, path);
224 gtk_tree_path_free(path);
225
226 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &id, -1);
227 plr = player_by_number(id);
228
229 if (ev->button == 1) {
230 if (can_intel_with_player(plr)) {
232 }
233 } else if (can_meet_with_player(plr)) {
235 }
236 }
237 }
238 return FALSE;
239}
240
241/**********************************************************************/
244static gint plrdlg_sort_func(GtkTreeModel *model,
245 GtkTreeIter *a, GtkTreeIter *b, gpointer data)
246{
247 GValue value = { 0, };
248 struct player *player1;
249 struct player *player2;
250 gint n;
251
252 n = GPOINTER_TO_INT(data);
253
254 gtk_tree_model_get_value(model, a, PLR_DLG_COL_ID, &value);
255 player1 = player_by_number(g_value_get_int(&value));
256 g_value_unset(&value);
257
258 gtk_tree_model_get_value(model, b, PLR_DLG_COL_ID, &value);
259 player2 = player_by_number(g_value_get_int(&value));
260 g_value_unset(&value);
261
262 return player_dlg_columns[n].sort_func(player1, player2);
263}
264
265/**********************************************************************/
268static GtkListStore *players_dialog_store_new(void)
269{
270 GtkListStore *store;
271 GType model_types[num_player_dlg_columns + PLR_DLG_COL_TOTAL];
272 int i;
273
274 for (i = 0; i < num_player_dlg_columns; i++) {
275 switch (player_dlg_columns[i].type) {
276 case COL_FLAG:
277 model_types[i] = GDK_TYPE_PIXBUF;
278 break;
279 case COL_COLOR:
280 model_types[i] = GDK_TYPE_PIXBUF;
281 break;
282 case COL_BOOLEAN:
283 model_types[i] = G_TYPE_BOOLEAN;
284 break;
285 case COL_TEXT:
286 case COL_RIGHT_TEXT:
287 model_types[i] = G_TYPE_STRING;
288 break;
289 }
290 }
291
292 /* Special (invisible rows) - Text style, weight and player id */
293 model_types[i++] = G_TYPE_INT; /* PLR_DLG_COL_STYLE. */
294 model_types[i++] = G_TYPE_INT; /* PLR_DLG_COL_WEIGHT. */
295 model_types[i++] = G_TYPE_INT; /* PLR_DLG_COL_ID. */
296 model_types[i++] = G_TYPE_STRING; /* PLR_DLG_COL_TOOLTIP */
297
298 store = gtk_list_store_newv(i, model_types);
299
300 /* Set sort order */
301 for (i = 0; i < num_player_dlg_columns; i++) {
302 if (player_dlg_columns[i].sort_func != NULL) {
303 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), i,
304 plrdlg_sort_func, GINT_TO_POINTER(i),
305 NULL);
306 }
307 }
308
309 return store;
310}
311
312/**********************************************************************/
315static void toggle_view(GtkCheckMenuItem* item, gpointer data)
316{
317 struct player_dlg_column* pcol = data;
318
319 pcol->show = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
320 update_views();
321}
322
323/**********************************************************************/
326static void toggle_dead_players(GtkCheckMenuItem* item, gpointer data)
327{
329 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
331}
332
333/**********************************************************************/
337static GtkWidget *create_diplomacy_menu(void)
338{
339 GtkWidget *menu, *item;
340
341 menu = gtk_menu_new();
342
343 item = gtk_menu_item_new_with_mnemonic(_("_Meet"));
344 g_signal_connect(item, "activate",
345 G_CALLBACK(players_meet_callback), NULL);
346 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
348
349 item = gtk_menu_item_new_with_mnemonic(_("Cancel _Treaty"));
350 g_signal_connect(item, "activate",
351 G_CALLBACK(players_war_callback), NULL);
352 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
354
355 item = gtk_menu_item_new_with_mnemonic(_("_Withdraw Vision"));
356 g_signal_connect(item, "activate",
357 G_CALLBACK(players_vision_callback), NULL);
358 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
360
361 return menu;
362}
363
364/**********************************************************************/
368static GtkWidget *create_intelligence_menu(void)
369{
370 GtkWidget *menu, *item;
371
372 menu = gtk_menu_new();
373
374 item = gtk_menu_item_new_with_mnemonic(_("_Report"));
375 g_signal_connect(item, "activate",
376 G_CALLBACK(players_intel_callback), NULL);
377 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
379
380 item = gtk_menu_item_new_with_mnemonic(_("_Wonders"));
381 g_signal_connect(item, "activate",
382 G_CALLBACK(players_intel_wonder_callback), NULL);
383 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
384
385 item = gtk_menu_item_new_with_mnemonic(_("_Spaceship"));
386 g_signal_connect(item, "activate",
387 G_CALLBACK(players_sship_callback), NULL);
388 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
390
391 return menu;
392}
393
394/**********************************************************************/
397static GtkWidget* create_show_menu(void)
398{
399 int i;
400 GtkWidget *menu = gtk_menu_new();
401 GtkWidget *item;
402
403 /* Index starting at one (1) here to force playername to always be shown */
404 for (i = 1; i < num_player_dlg_columns; i++) {
405 struct player_dlg_column *pcol;
406
407 pcol = &player_dlg_columns[i];
408 item = gtk_check_menu_item_new_with_label(pcol->title);
409 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), pcol->show);
410 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
411 g_signal_connect(item, "toggled", G_CALLBACK(toggle_view), pcol);
412 }
413
414 item = gtk_separator_menu_item_new();
415 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
416
417 item = gtk_check_menu_item_new_with_label(Q_("?show:Dead Players"));
418 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
420 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
421 g_signal_connect(item, "toggled", G_CALLBACK(toggle_dead_players), NULL);
422
423 return menu;
424}
425
426/**********************************************************************/
430{
431 int i;
432 GtkWidget *sep, *sw;
433 GtkWidget *menubar, *menu, *item, *vbox;
434 enum ai_level level;
435
437 TRUE);
438 /* TRANS: Nations report title */
440
442 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
443
445
447
448 players_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL
450 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(players_list),
452 gtk_widget_set_hexpand(players_list, TRUE);
453 gtk_widget_set_vexpand(players_list, TRUE);
454 g_object_unref(players_dialog_store);
455 gtk_widget_set_name(players_list, "small_font");
456
457 players_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(players_list));
458 g_signal_connect(players_selection, "changed",
459 G_CALLBACK(selection_callback), NULL);
460 g_signal_connect(players_list, "button_press_event",
461 G_CALLBACK(button_press_callback), NULL);
462
463 for (i = 0; i < num_player_dlg_columns; i++) {
464 struct player_dlg_column *pcol;
465 GtkCellRenderer *renderer;
466 GtkTreeViewColumn *col;
467
468 pcol = &player_dlg_columns[i];
469 col = NULL;
470
471 switch (pcol->type) {
472 case COL_FLAG:
473 renderer = gtk_cell_renderer_pixbuf_new();
474
475 col = gtk_tree_view_column_new_with_attributes(pcol->title,
476 renderer, "pixbuf", i, NULL);
477 break;
478 case COL_BOOLEAN:
479 renderer = gtk_cell_renderer_toggle_new();
480
481 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
482 "active", i, NULL);
483 break;
484 case COL_COLOR:
485 renderer = gtk_cell_renderer_pixbuf_new();
486
487 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
488 "pixbuf", i, NULL);
489 break;
490 case COL_TEXT:
491 renderer = gtk_cell_renderer_text_new();
492 g_object_set(renderer, "style-set", TRUE, "weight-set", TRUE, NULL);
493
494 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
495 "text", i,
496 "style", PLR_DLG_COL_STYLE,
497 "weight", PLR_DLG_COL_WEIGHT,
498 NULL);
499 gtk_tree_view_column_set_sort_column_id(col, i);
500 break;
501 case COL_RIGHT_TEXT:
502 renderer = gtk_cell_renderer_text_new();
503 g_object_set(renderer, "style-set", TRUE, "weight-set", TRUE, NULL);
504
505 col = gtk_tree_view_column_new_with_attributes(pcol->title, renderer,
506 "text", i,
507 "style", PLR_DLG_COL_STYLE,
508 "weight", PLR_DLG_COL_WEIGHT,
509 NULL);
510 gtk_tree_view_column_set_sort_column_id(col, i);
511 g_object_set(renderer, "xalign", 1.0, NULL);
512 gtk_tree_view_column_set_alignment(col, 1.0);
513 break;
514 }
515
516 if (col) {
517 gtk_tree_view_append_column(GTK_TREE_VIEW(players_list), col);
518 }
519 }
520
521 gtk_tree_view_set_search_column(GTK_TREE_VIEW(players_list),
523
524 sw = gtk_scrolled_window_new(NULL, NULL);
525 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
526 GTK_SHADOW_ETCHED_IN);
527 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
528 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
529 gtk_container_add(GTK_CONTAINER(sw), players_list);
530
531 gtk_container_add(GTK_CONTAINER(players_dialog_shell->vbox), sw);
532
533 vbox = gtk_grid_new();
534 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
535 GTK_ORIENTATION_VERTICAL);
536
537 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
538 gtk_container_add(GTK_CONTAINER(vbox), sep);
539
540 menubar = gtk_aux_menu_bar_new();
541 gtk_container_add(GTK_CONTAINER(vbox), menubar);
542
543
545
546 item = gtk_menu_item_new_with_mnemonic(_("Di_plomacy"));
547 menu = create_diplomacy_menu();
548 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
549 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
550
551 item = gtk_menu_item_new_with_mnemonic(_("_Intelligence"));
553 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
554 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
555
556 item = gtk_menu_item_new_with_mnemonic(_("_Display"));
557 menu = create_show_menu();
558 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
559 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
560
561 item = gtk_menu_item_new_with_mnemonic(_("_AI"));
562 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
563
564 menu = gtk_menu_new();
565 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
566
567 item = gtk_menu_item_new_with_mnemonic(_("_Toggle AI Mode"));
568 g_signal_connect(item, "activate",
569 G_CALLBACK(players_ai_toggle_callback), NULL);
570 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
571
572 sep = gtk_separator_menu_item_new();
573 gtk_menu_shell_append(GTK_MENU_SHELL(menu), sep);
574
575 for (level = 0; level < AI_LEVEL_COUNT; level++) {
577 const char *level_name = ai_level_translated_name(level);
578
579 item = gtk_menu_item_new_with_label(level_name);
580 g_signal_connect(item, "activate",
581 G_CALLBACK(players_ai_skill_callback),
582 GUINT_TO_POINTER(level));
583 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
584 }
585 }
586 gtk_widget_show_all(menu);
587
589
591
593 GTK_RESPONSE_CLOSE);
594
595 gtk_tree_view_focus(GTK_TREE_VIEW(players_list));
596}
597
598
599/**************************************************************************
600...
601**************************************************************************/
602#define MIN_DIMENSION 5
603
604/**********************************************************************/
609GdkPixbuf *get_flag(const struct nation_type *nation)
610{
611 int x0, y0, x1, y1, w, h;
612 GdkPixbuf *im;
613 struct sprite *flag;
614
615 flag = get_nation_flag_sprite(tileset, nation);
616
617 /* calculate the bounding box ... */
618 sprite_get_bounding_box(flag, &x0, &y0, &x1, &y1);
619
620 fc_assert_ret_val(x0 != -1, NULL);
621 fc_assert_ret_val(y0 != -1, NULL);
622 fc_assert_ret_val(x1 != -1, NULL);
623 fc_assert_ret_val(y1 != -1, NULL);
624
625 w = (x1 - x0) + 1;
626 h = (y1 - y0) + 1;
627
628 /* if the flag is smaller then 5 x 5, something is wrong */
630
631 /* croping */
632 im = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
633 if (im != NULL) {
634 GdkPixbuf *pixbuf = sprite_get_pixbuf(flag);
635
636 gdk_pixbuf_copy_area(pixbuf, x0, y0, w, h,
637 im, 0, 0);
638 g_object_unref(G_OBJECT(pixbuf));
639 }
640
641 /* and finally store the scaled flag pixbuf in the static flags array */
642 return im;
643}
644
645
646/**********************************************************************/
650static void fill_row(GtkListStore *store, GtkTreeIter *it,
651 const struct player *pplayer)
652{
653 struct player_dlg_column* pcol;
654 GdkPixbuf *pixbuf;
655 int style = PANGO_STYLE_NORMAL, weight = PANGO_WEIGHT_NORMAL;
656 int k;
657
658 for (k = 0; k < num_player_dlg_columns; k++) {
659 pcol = &player_dlg_columns[k];
660 switch (pcol->type) {
661 case COL_TEXT:
662 case COL_RIGHT_TEXT:
663 gtk_list_store_set(store, it, k, pcol->func(pplayer), -1);
664 break;
665 case COL_FLAG:
666 pixbuf = get_flag(nation_of_player(pplayer));
667 if (pixbuf != NULL) {
668 gtk_list_store_set(store, it, k, pixbuf, -1);
669 g_object_unref(pixbuf);
670 }
671 break;
672 case COL_COLOR:
673 pixbuf = create_player_icon(pplayer);
674 if (pixbuf != NULL) {
675 gtk_list_store_set(store, it, k, pixbuf, -1);
676 g_object_unref(pixbuf);
677 }
678 break;
679 case COL_BOOLEAN:
680 gtk_list_store_set(store, it, k, pcol->bool_func(pplayer), -1);
681 break;
682 }
683 }
684
685 gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP,
686 score_tooltip(pplayer, pplayer->score.game), -1);
687
688 /* Now add some eye candy ... */
689 if (client_has_player()) {
690 switch (player_diplstate_get(client_player(), pplayer)->type) {
691 case DS_WAR:
692 weight = PANGO_WEIGHT_NORMAL;
693 style = PANGO_STYLE_ITALIC;
694 break;
695 case DS_ALLIANCE:
696 case DS_TEAM:
697 weight = PANGO_WEIGHT_BOLD;
698 style = PANGO_STYLE_NORMAL;
699 break;
700 case DS_ARMISTICE:
701 case DS_CEASEFIRE:
702 case DS_PEACE:
703 case DS_NO_CONTACT:
704 weight = PANGO_WEIGHT_NORMAL;
705 style = PANGO_STYLE_NORMAL;
706 break;
707 case DS_LAST:
708 break;
709 }
710 }
711
712 gtk_list_store_set(store, it,
713 PLR_DLG_COL_STYLE, style,
714 PLR_DLG_COL_WEIGHT, weight,
716 -1);
717}
718
719/**********************************************************************/
722static bool player_should_be_shown(const struct player *pplayer)
723{
724 return NULL != pplayer && (gui_options.player_dlg_show_dead_players
725 || pplayer->is_alive)
726 && (!is_barbarian(pplayer));
727}
728
729/**********************************************************************/
733{
734 GtkTreeModel *model;
735 GtkTreeIter iter;
736 int selected;
737
738 if (NULL == players_dialog_shell) {
739 return;
740 }
741
742 /* Save the selection. */
743 if (gtk_tree_selection_get_selected(players_selection, &model, &iter)) {
744 gtk_tree_model_get(model, &iter, PLR_DLG_COL_ID, &selected, -1);
745 } else {
746 selected = -1;
747 }
748
749 gtk_list_store_clear(players_dialog_store);
750 players_iterate(pplayer) {
751 if (!player_should_be_shown(pplayer)) {
752 continue;
753 }
754 gtk_list_store_append(players_dialog_store, &iter);
755 fill_row(players_dialog_store, &iter, pplayer);
756 if (player_number(pplayer) == selected) {
757 /* Restore the selection. */
758 gtk_tree_selection_select_iter(players_selection, &iter);
759 }
761
762 update_views();
763}
764
765/**********************************************************************/
769void players_meet_callback(GtkMenuItem *item, gpointer data)
770{
771 GtkTreeModel *model;
772 GtkTreeIter it;
773
774 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
775 gint plrno;
776
777 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
778
780 }
781}
782
783/**********************************************************************/
787static void confirm_cancel_pact(enum clause_type clause, int plrno,
788 char *title, char *question)
789{
790 GtkWidget *shell;
791
792 shell = gtk_message_dialog_new(NULL, 0,
793 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
794 "%s", question);
795 gtk_window_set_title(GTK_WINDOW(shell), title);
797 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
798
799 if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
801 }
802 gtk_widget_destroy(shell);
803 FC_FREE(title);
804 FC_FREE(question);
805}
806
807/**********************************************************************/
810void players_war_callback(GtkMenuItem *item, gpointer data)
811{
812 GtkTreeModel *model;
813 GtkTreeIter it;
814
815 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
816 struct astring title = ASTRING_INIT, question = ASTRING_INIT;
817 gint plrno;
818 struct player *aplayer;
819 enum diplstate_type oldstate, newstate;
820
821 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
822 aplayer = player_by_number(plrno);
823 fc_assert_ret(aplayer != NULL);
824
825 oldstate = player_diplstate_get(client_player(), aplayer)->type;
826 newstate = cancel_pact_result(oldstate);
827
828 /* TRANS: %s is a diplomatic state: "Cancel Cease-fire" */
829 astr_set(&title, _("Cancel %s"), diplstate_type_translated_name(oldstate));
830
831 if (newstate == DS_WAR) {
832 astr_set(&question, _("Really declare war on the %s?"),
833 nation_plural_for_player(aplayer));
834 } else {
835 /* TRANS: "Cancel Belgian Alliance? ... will be Armistice." */
836 astr_set(&question, _("Cancel %s %s? New diplomatic state will be %s."),
838 diplstate_type_translated_name(oldstate),
839 diplstate_type_translated_name(newstate));
840 }
841
842 /* can be any pact clause */
843 confirm_cancel_pact(CLAUSE_CEASEFIRE, plrno,
844 astr_to_str(&title), astr_to_str(&question));
845 }
846}
847
848/**********************************************************************/
851void players_vision_callback(GtkMenuItem *item, gpointer data)
852{
853 GtkTreeModel *model;
854 GtkTreeIter it;
855
856 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
857 struct astring question = ASTRING_INIT;
858 gint plrno;
859 struct player *aplayer;
860
861 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
862 aplayer = player_by_number(plrno);
863 fc_assert_ret(aplayer != NULL);
864
865 /* TRANS: "...from the Belgians?" */
866 astr_set(&question, _("Withdraw shared vision from the %s?"),
867 nation_plural_for_player(aplayer));
868
869 confirm_cancel_pact(CLAUSE_VISION, plrno,
870 fc_strdup(_("Withdraw Shared Vision")),
871 astr_to_str(&question));
872 }
873}
874
875/**********************************************************************/
878void players_intel_callback(GtkMenuItem *item, gpointer data)
879{
880 GtkTreeModel *model;
881 GtkTreeIter it;
882
883 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
884 gint plrno;
885
886 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
887
890 }
891 }
892}
893
894/**********************************************************************/
897void players_intel_wonder_callback(GtkMenuItem *item, gpointer data)
898{
899 GtkTreeModel *model;
900 GtkTreeIter it;
901
902 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
903 gint plrno;
904
905 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
906
908 }
909}
910
911/**********************************************************************/
914void players_sship_callback(GtkMenuItem *item, gpointer data)
915{
916 GtkTreeModel *model;
917 GtkTreeIter it;
918
919 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
920 gint plrno;
921
922 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
924 }
925}
926
927/**********************************************************************/
930static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data)
931{
932 GtkTreeModel *model;
933 GtkTreeIter it;
934
935 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
936 gint plrno;
937
938 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
939
940 send_chat_printf("/aitoggle \"%s\"", player_name(player_by_number(plrno)));
941 }
942}
943
944/**********************************************************************/
947static void players_ai_skill_callback(GtkMenuItem *item, gpointer data)
948{
949 GtkTreeModel *model;
950 GtkTreeIter it;
951
952 if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
953 gint plrno;
954
955 gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
956
957 send_chat_printf("/%s %s",
958 ai_level_cmd(GPOINTER_TO_UINT(data)),
960 }
961}
962
963/**********************************************************************/
966static void update_views(void)
967{
968 int i;
969
970 for (i = 0; i < num_player_dlg_columns; i++) {
971 GtkTreeViewColumn *col;
972
973 col = gtk_tree_view_get_column(GTK_TREE_VIEW(players_list), i);
974 gtk_tree_view_column_set_visible(col, player_dlg_columns[i].show);
975 }
976}
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