Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-3.0/plrdlg.c Source File

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
58 struct gui_dialog *players_dialog_shell;
59 static GtkWidget *players_list;
60 static GtkTreeSelection *players_selection;
61 static GtkWidget *players_int_command;
62 static GtkWidget *players_meet_command;
63 static GtkWidget *players_war_command;
64 static GtkWidget *players_vision_command;
65 static GtkWidget *players_sship_command;
66
67 static 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/**********************************************************************/
91 void popup_players_dialog(bool raise)
92{
93 if (!players_dialog_shell) {
94 create_players_dialog();
95 }
96 gui_dialog_present(players_dialog_shell);
97 if (raise) {
98 gui_dialog_raise(players_dialog_shell);
99 }
100}
101
102/**********************************************************************/
105 void popdown_players_dialog(void)
106{
107 if (players_dialog_shell) {
108 gui_dialog_destroy(players_dialog_shell);
109 }
110}
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
141 color = get_player_color(tileset, plr);
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/**********************************************************************/
156 static 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,
178 can_client_issue_orders()
179 && pplayer_can_cancel_treaty(client_player(),
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,
187 can_client_issue_orders()
188 && gives_shared_vision(client.conn.playing, plr)
189 && !players_on_same_team(client.conn.playing, plr));
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/**********************************************************************/
203 static void selection_callback(GtkTreeSelection *selection, gpointer data)
204{
205 update_players_menu();
206}
207
208/**********************************************************************/
211 static 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)) {
231 popup_intel_dialog(plr);
232 }
233 } else if (can_meet_with_player(plr)) {
234 dsend_packet_diplomacy_init_meeting_req(&client.conn, id);
235 }
236 }
237 }
238 return FALSE;
239}
240
241/**********************************************************************/
244 static 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/**********************************************************************/
268 static 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/**********************************************************************/
315 static 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/**********************************************************************/
326 static void toggle_dead_players(GtkCheckMenuItem* item, gpointer data)
327{
328 gui_options.player_dlg_show_dead_players =
329 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
330 real_players_dialog_update(NULL);
331}
332
333/**********************************************************************/
337 static 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);
347 players_meet_command = 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);
353 players_war_command = 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);
359 players_vision_command = item;
360
361 return menu;
362}
363
364/**********************************************************************/
368 static 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);
378 players_int_command = 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);
389 players_sship_command = item;
390
391 return menu;
392}
393
394/**********************************************************************/
397 static 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),
419 gui_options.player_dlg_show_dead_players);
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/**********************************************************************/
429 void create_players_dialog(void)
430{
431 int i;
432 GtkWidget *sep, *sw;
433 GtkWidget *menubar, *menu, *item, *vbox;
434 enum ai_level level;
435
436 gui_dialog_new(&players_dialog_shell, GTK_NOTEBOOK(top_notebook), NULL,
437 TRUE);
438 /* TRANS: Nations report title */
439 gui_dialog_set_title(players_dialog_shell, _("Nations"));
440
441 gui_dialog_add_button(players_dialog_shell,
442 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
443
444 gui_dialog_set_default_size(players_dialog_shell, -1, 270);
445
446 players_dialog_store = players_dialog_store_new();
447
448 players_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL
449 (players_dialog_store));
450 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(players_list),
451 PLR_DLG_COL_TOOLTIP);
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),
522 player_dlg_default_sort_column());
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
544 gui_dialog_add_widget(players_dialog_shell, vbox);
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"));
552 menu = create_intelligence_menu();
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++) {
576 if (is_settable_ai_level(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
588 gui_dialog_show_all(players_dialog_shell);
589
590 real_players_dialog_update(NULL);
591
592 gui_dialog_set_default_response(players_dialog_shell,
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 */
629 fc_assert_ret_val(w >= MIN_DIMENSION && h >= MIN_DIMENSION, NULL);
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/**********************************************************************/
650 static 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,
715 PLR_DLG_COL_ID, player_number(pplayer),
716 -1);
717}
718
719/**********************************************************************/
722 static 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/**********************************************************************/
732 void real_players_dialog_update(void *unused)
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 }
760 } players_iterate_end;
761
762 update_views();
763}
764
765/**********************************************************************/
769 void 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
779 dsend_packet_diplomacy_init_meeting_req(&client.conn, plrno);
780 }
781}
782
783/**********************************************************************/
787 static 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);
796 setup_dialog(shell, toplevel);
797 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
798
799 if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
800 dsend_packet_diplomacy_cancel_pact(&client.conn, plrno, clause);
801 }
802 gtk_widget_destroy(shell);
803 FC_FREE(title);
804 FC_FREE(question);
805}
806
807/**********************************************************************/
810 void 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."),
837 nation_adjective_for_player(aplayer),
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/**********************************************************************/
851 void 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/**********************************************************************/
878 void 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
888 if (can_intel_with_player(player_by_number(plrno))) {
889 popup_intel_dialog(player_by_number(plrno));
890 }
891 }
892}
893
894/**********************************************************************/
897 void 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
907 popup_intel_wonder_dialog(player_by_number(plrno));
908 }
909}
910
911/**********************************************************************/
914 void 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);
923 popup_spaceship_dialog(player_by_number(plrno));
924 }
925}
926
927/**********************************************************************/
930 static 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/**********************************************************************/
947 static 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)),
959 player_name(player_by_number(plrno)));
960 }
961}
962
963/**********************************************************************/
966 static 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}
astr_set
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
astr_to_str
char * astr_to_str(struct astring *astr)
Definition astring.c:167
n
#define n
Definition astring.c:77
astring.h
ASTRING_INIT
#define ASTRING_INIT
Definition astring.h:44
height
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
width
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
send_chat_printf
int send_chat_printf(const char *format,...)
Definition chatline_common.c:55
can_meet_with_player
bool can_meet_with_player(const struct player *pplayer)
Definition client_main.c:1275
can_intel_with_player
bool can_intel_with_player(const struct player *pplayer)
Definition client_main.c:1286
client
struct civclient client
Definition client_main.c:149
can_client_issue_orders
bool can_client_issue_orders(void)
Definition client_main.c:1265
client_has_player
bool client_has_player(void)
Definition client_main.c:1365
client_main.h
client_player
#define client_player()
Definition client_main.h:106
climisc.h
get_player_color
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
Definition colors_common.c:125
player_has_color
bool player_has_color(const struct player *pplayer)
Definition colors_common.c:113
get_color
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
Definition colors_common.c:100
connectdlg_common.h
diptreaty.h
id
int int id
Definition editgui_g.h:28
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
_
#define _(String)
Definition fcintl.h:67
top_notebook
GtkWidget * top_notebook
Definition gui_main.c:128
toplevel
GtkWidget * toplevel
Definition gui_main.c:124
gtk_tree_view_focus
void gtk_tree_view_focus(GtkTreeView *view)
Definition gui_stuff.c:230
gui_dialog_destroy
void gui_dialog_destroy(struct gui_dialog *dlg)
Definition gui_stuff.c:951
gui_dialog_present
void gui_dialog_present(struct gui_dialog *dlg)
Definition gui_stuff.c:834
gui_dialog_set_default_response
void gui_dialog_set_default_response(struct gui_dialog *dlg, int response)
Definition gui_stuff.c:733
gui_dialog_raise
void gui_dialog_raise(struct gui_dialog *dlg)
Definition gui_stuff.c:864
gui_dialog_new
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
Definition gui_stuff.c:504
gui_dialog_add_widget
GtkWidget * gui_dialog_add_widget(struct gui_dialog *dlg, GtkWidget *widget)
Definition gui_stuff.c:721
gui_dialog_add_button
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
Definition gui_stuff.c:706
gui_dialog_show_all
void gui_dialog_show_all(struct gui_dialog *dlg)
Definition gui_stuff.c:794
gui_dialog_set_title
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
Definition gui_stuff.c:932
gui_dialog_set_default_size
void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height)
Definition gui_stuff.c:916
gtk_aux_menu_bar_new
GtkWidget * gtk_aux_menu_bar_new(void)
Definition gui_stuff.c:249
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
popup_intel_dialog
void popup_intel_dialog(struct player *p)
Definition inteldlg.c:166
popup_intel_wonder_dialog
void popup_intel_wonder_dialog(struct player *p)
Definition inteldlg.c:182
shell
static struct gui_dialog * shell
Definition messagedlg.c:39
players_int_command
static GtkWidget * players_int_command
Definition plrdlg.c:61
players_war_callback
static void players_war_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:810
popdown_players_dialog
void popdown_players_dialog(void)
Definition plrdlg.c:105
fill_row
static void fill_row(GtkListStore *store, GtkTreeIter *it, const struct player *pplayer)
Definition plrdlg.c:650
players_selection
static GtkTreeSelection * players_selection
Definition plrdlg.c:60
update_views
static void update_views(void)
Definition plrdlg.c:966
players_vision_command
static GtkWidget * players_vision_command
Definition plrdlg.c:64
players_list
static GtkWidget * players_list
Definition plrdlg.c:59
players_sship_command
static GtkWidget * players_sship_command
Definition plrdlg.c:65
players_dialog_shell
struct gui_dialog * players_dialog_shell
Definition plrdlg.c:58
players_ai_toggle_callback
static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:930
players_sship_callback
static void players_sship_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:914
PLR_DLG_COL_ID
#define PLR_DLG_COL_ID
Definition plrdlg.c:70
PLR_DLG_COL_WEIGHT
#define PLR_DLG_COL_WEIGHT
Definition plrdlg.c:69
PLR_DLG_COL_STYLE
#define PLR_DLG_COL_STYLE
Definition plrdlg.c:68
real_players_dialog_update
void real_players_dialog_update(void *unused)
Definition plrdlg.c:732
create_diplomacy_menu
static GtkWidget * create_diplomacy_menu(void)
Definition plrdlg.c:337
player_should_be_shown
static bool player_should_be_shown(const struct player *pplayer)
Definition plrdlg.c:722
PLR_DLG_COL_TOTAL
#define PLR_DLG_COL_TOTAL
Definition plrdlg.c:73
create_player_icon
GdkPixbuf * create_player_icon(const struct player *plr)
Definition plrdlg.c:117
create_intelligence_menu
static GtkWidget * create_intelligence_menu(void)
Definition plrdlg.c:368
button_press_callback
static gboolean button_press_callback(GtkTreeView *view, GdkEventButton *ev)
Definition plrdlg.c:211
popup_players_dialog
void popup_players_dialog(bool raise)
Definition plrdlg.c:91
players_dialog_store
static GtkListStore * players_dialog_store
Definition plrdlg.c:67
players_intel_wonder_callback
static void players_intel_wonder_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:897
toggle_dead_players
static void toggle_dead_players(GtkCheckMenuItem *item, gpointer data)
Definition plrdlg.c:326
PLR_DLG_COL_TOOLTIP
#define PLR_DLG_COL_TOOLTIP
Definition plrdlg.c:71
players_meet_callback
static void players_meet_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:769
confirm_cancel_pact
static void confirm_cancel_pact(enum clause_type clause, int plrno, char *title, char *question)
Definition plrdlg.c:787
players_vision_callback
static void players_vision_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:851
plrdlg_sort_func
static gint plrdlg_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
Definition plrdlg.c:244
get_flag
GdkPixbuf * get_flag(const struct nation_type *nation)
Definition plrdlg.c:609
MIN_DIMENSION
#define MIN_DIMENSION
Definition plrdlg.c:602
players_dialog_store_new
static GtkListStore * players_dialog_store_new(void)
Definition plrdlg.c:268
players_meet_command
static GtkWidget * players_meet_command
Definition plrdlg.c:62
toggle_view
static void toggle_view(GtkCheckMenuItem *item, gpointer data)
Definition plrdlg.c:315
players_ai_skill_callback
static void players_ai_skill_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:947
create_players_dialog
static void create_players_dialog(void)
Definition plrdlg.c:429
players_intel_callback
static void players_intel_callback(GtkMenuItem *item, gpointer data)
Definition plrdlg.c:878
update_players_menu
static void update_players_menu(void)
Definition plrdlg.c:156
create_show_menu
static GtkWidget * create_show_menu(void)
Definition plrdlg.c:397
players_war_command
static GtkWidget * players_war_command
Definition plrdlg.c:63
selection_callback
static void selection_callback(GtkTreeSelection *selection, gpointer data)
Definition plrdlg.c:203
title
const char * title
Definition repodlgs.c:1313
type
GType type
Definition repodlgs.c:1312
popup_spaceship_dialog
void popup_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.c:146
surface_get_pixbuf
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
Definition sprite.c:418
sprite_get_pixbuf
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
sprite_get_bounding_box
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
@ COL_TEXT
Definition unitselect.c:50
gui_stuff.h
chatline.h
colors.h
dialogs.h
graphics.h
gui_main.h
inteldlg.h
plrdlg.h
spaceshipdlg.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
nation.h
gui_options
struct client_options gui_options
Definition options.c:71
options.h
packets.h
dsend_packet_diplomacy_cancel_pact
int dsend_packet_diplomacy_cancel_pact(struct connection *pc, int other_player_id, enum clause_type clause)
Definition packets_gen.c:50551
dsend_packet_diplomacy_init_meeting_req
int dsend_packet_diplomacy_init_meeting_req(struct connection *pc, int counterpart)
Definition packets_gen.c:48268
is_settable_ai_level
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1883
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:840
players_on_same_team
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1452
cancel_pact_result
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:67
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:886
pplayer_can_cancel_treaty
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:92
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1461
player.h
ai_level_cmd
#define ai_level_cmd(_level_)
Definition player.h:565
players_iterate_end
#define players_iterate_end
Definition player.h:535
DIPL_ERROR
@ DIPL_ERROR
Definition player.h:195
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
player_dlg_default_sort_column
int player_dlg_default_sort_column(void)
Definition plrdlg_common.c:596
player_dlg_columns
struct player_dlg_column player_dlg_columns[]
Definition plrdlg_common.c:564
num_player_dlg_columns
const int num_player_dlg_columns
Definition plrdlg_common.c:591
COL_BOOLEAN
@ COL_BOOLEAN
Definition plrdlg_common.h:31
COL_FLAG
@ COL_FLAG
Definition plrdlg_common.h:29
COL_RIGHT_TEXT
@ COL_RIGHT_TEXT
Definition plrdlg_common.h:33
COL_COLOR
@ COL_COLOR
Definition plrdlg_common.h:30
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
SSHIP_NONE
@ SSHIP_NONE
Definition spaceship.h:84
astring
Definition astring.h:36
civclient::conn
struct connection conn
Definition client_main.h:96
client_options::player_dlg_show_dead_players
bool player_dlg_show_dead_players
Definition options.h:212
color
Definition colors.h:20
color::color
GdkRGBA color
Definition colors.h:21
connection::playing
struct player * playing
Definition connection.h:156
gui_dialog
Definition gui_stuff.h:69
gui_dialog::vbox
GtkWidget * vbox
Definition gui_stuff.h:71
item
Definition climisc.h:80
nation_type
Definition nation.h:97
player_diplstate::type
enum diplstate_type type
Definition player.h:201
player_dlg_column
Definition plrdlg_common.h:39
player_dlg_column::bool_func
bool(* bool_func)(const struct player *)
Definition plrdlg_common.h:44
player_dlg_column::show
bool show
Definition plrdlg_common.h:40
player_dlg_column::sort_func
plr_dlg_sort_func sort_func
Definition plrdlg_common.h:45
player_dlg_column::func
const char *(* func)(const struct player *)
Definition plrdlg_common.h:43
player_dlg_column::title
const char * title
Definition plrdlg_common.h:42
player_dlg_column::type
enum player_dlg_column_type type
Definition plrdlg_common.h:41
player_score::game
int game
Definition player.h:116
player_spaceship::state
enum spaceship_state state
Definition spaceship.h:108
player
Definition player.h:249
player::is_alive
bool is_alive
Definition player.h:268
player::spaceship
struct player_spaceship spaceship
Definition player.h:286
player::score
struct player_score score
Definition player.h:283
sprite
Definition sprite.h:22
tileset
Definition tilespec.c:459
view
Definition mapview_common.h:36
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
score_tooltip
const char * score_tooltip(const struct player *pplayer, int score)
Definition text.c:2157
text.h
get_nation_flag_sprite
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6471
tilespec.h
show
#define show(id)
Definition widget.h:235