Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-3.22/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.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
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(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
139 color = get_player_color(tileset, plr);
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/**********************************************************************/
154 static 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,
176 can_client_issue_orders()
177 && pplayer_can_cancel_treaty(client_player(),
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,
185 can_client_issue_orders()
186 && gives_shared_vision(client.conn.playing, plr)
187 && !players_on_same_team(client.conn.playing, plr));
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/**********************************************************************/
201 static void selection_callback(GtkTreeSelection *selection, gpointer data)
202{
203 update_players_menu();
204}
205
206/**********************************************************************/
209 static 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)) {
229 popup_intel_dialog(plr);
230 }
231 } else if (can_meet_with_player(plr)) {
232 dsend_packet_diplomacy_init_meeting_req(&client.conn, id);
233 }
234 }
235 }
236 return FALSE;
237}
238
239/**********************************************************************/
242 static 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/**********************************************************************/
266 static 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/**********************************************************************/
313 static 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/**********************************************************************/
324 static void toggle_dead_players(GtkCheckMenuItem* item, gpointer data)
325{
326 gui_options.player_dlg_show_dead_players =
327 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
328 real_players_dialog_update(NULL);
329}
330
331/**********************************************************************/
335 static 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);
345 players_meet_command = 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);
351 players_war_command = 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);
357 players_vision_command = item;
358
359 return menu;
360}
361
362/**********************************************************************/
366 static 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);
376 players_int_command = 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);
387 players_sship_command = item;
388
389 return menu;
390}
391
392/**********************************************************************/
395 static 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),
417 gui_options.player_dlg_show_dead_players);
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/**********************************************************************/
427 void create_players_dialog(void)
428{
429 int i;
430 GtkWidget *sep, *sw;
431 GtkWidget *menubar, *menu, *item, *vbox;
432 enum ai_level level;
433
434 gui_dialog_new(&players_dialog_shell, GTK_NOTEBOOK(top_notebook), NULL,
435 TRUE);
436 /* TRANS: Nations report title */
437 gui_dialog_set_title(players_dialog_shell, _("Nations"));
438
439 gui_dialog_add_button(players_dialog_shell, "window-close", _("_Close"),
440 GTK_RESPONSE_CLOSE);
441
442 gui_dialog_set_default_size(players_dialog_shell, -1, 270);
443
444 players_dialog_store = players_dialog_store_new();
445
446 players_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL
447 (players_dialog_store));
448 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(players_list),
449 PLR_DLG_COL_TOOLTIP);
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),
520 player_dlg_default_sort_column());
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
542 gui_dialog_add_widget(players_dialog_shell, vbox);
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"));
550 menu = create_intelligence_menu();
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++) {
574 if (is_settable_ai_level(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
586 gui_dialog_show_all(players_dialog_shell);
587
588 real_players_dialog_update(NULL);
589
590 gui_dialog_set_default_response(players_dialog_shell,
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 */
627 fc_assert_ret_val(w >= MIN_DIMENSION && h >= MIN_DIMENSION, NULL);
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/**********************************************************************/
648 static 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,
713 PLR_DLG_COL_ID, player_number(pplayer),
714 -1);
715}
716
717/**********************************************************************/
720 static 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/**********************************************************************/
730 void real_players_dialog_update(void *unused)
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 }
758 } players_iterate_end;
759
760 update_views();
761}
762
763/**********************************************************************/
767 void 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
777 dsend_packet_diplomacy_init_meeting_req(&client.conn, plrno);
778 }
779}
780
781/**********************************************************************/
785 static 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);
794 setup_dialog(shell, toplevel);
795 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
796
797 if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
798 dsend_packet_diplomacy_cancel_pact(&client.conn, plrno, clause);
799 }
800 gtk_widget_destroy(shell);
801 FC_FREE(title);
802 FC_FREE(question);
803}
804
805/**********************************************************************/
808 void 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."),
835 nation_adjective_for_player(aplayer),
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/**********************************************************************/
849 void 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/**********************************************************************/
876 void 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
886 if (can_intel_with_player(player_by_number(plrno))) {
887 popup_intel_dialog(player_by_number(plrno));
888 }
889 }
890}
891
892/**********************************************************************/
895 void 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
905 popup_intel_wonder_dialog(player_by_number(plrno));
906 }
907}
908
909/**********************************************************************/
912 void 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);
921 popup_spaceship_dialog(player_by_number(plrno));
922 }
923}
924
925/**********************************************************************/
928 static 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/**********************************************************************/
945 static 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)),
957 player_name(player_by_number(plrno)));
958 }
959}
960
961/**********************************************************************/
964 static 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}
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