Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-sdl2/plrdlg.c Source File

Freeciv-3.2

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/* SDL2 */
19#ifdef SDL2_PLAIN_INCLUDE
20#include <SDL.h>
21#else /* SDL2_PLAIN_INCLUDE */
22#include <SDL2/SDL.h>
23#endif /* SDL2_PLAIN_INCLUDE */
24
25/* utility */
26#include "astring.h"
27#include "fcintl.h"
28
29/* common */
30#include "nation.h"
31
32/* client */
33#include "client_main.h"
34#include "climisc.h"
35
36/* gui-sdl2 */
37#include "chatline.h"
38#include "colors.h"
39#include "diplodlg.h"
40#include "graphics.h"
41#include "gui_id.h"
42#include "gui_main.h"
43#include "gui_tilespec.h"
44#include "inteldlg.h"
45#include "mapview.h"
46#include "sprite.h"
47#include "themespec.h"
48#include "widget.h"
49
50#include "plrdlg.h"
51
52#ifndef M_PI
53#define M_PI 3.14159265358979323846 /* pi */
54#endif
55#ifndef M_PI_2
56#define M_PI_2 1.57079632679489661923 /* pi/2 */
57#endif
58
59 static struct small_dialog *pplayers_dlg = NULL;
60
61static int player_nation_callback(struct widget *pwidget);
62
63/**********************************************************************/
66 static int exit_players_dlg_callback(struct widget *pwidget)
67{
68 if (PRESSED_EVENT(main_data.event)) {
69 popdown_players_dialog();
70 flush_dirty();
71 }
72
73 return -1;
74}
75
76/**********************************************************************/
79 static int player_callback(struct widget *pwidget)
80{
81 /* We want exactly same functionality that the small dialog has. */
82 return player_nation_callback(pwidget);
83}
84
85/**********************************************************************/
88 static int players_window_dlg_callback(struct widget *pwindow)
89{
90 if (PRESSED_EVENT(main_data.event)) {
91 if (move_window_group_dialog(pplayers_dlg->begin_widget_list, pwindow)) {
92 select_window_group_dialog(pplayers_dlg->begin_widget_list, pwindow);
93 players_dialog_update();
94 } else {
95 if (select_window_group_dialog(pplayers_dlg->begin_widget_list, pwindow)) {
96 widget_flush(pwindow);
97 }
98 }
99 }
100
101 return -1;
102}
103
104/**********************************************************************/
107 static int toggle_draw_war_status_callback(struct widget *pwidget)
108{
109 if (PRESSED_EVENT(main_data.event)) {
110 /* exit button -> neutral -> war -> casefire -> peace -> alliance */
111 struct widget *pplayer = pplayers_dlg->end_widget_list->prev->prev->prev->prev->prev->prev;
112
113 sdl2_client_flags ^= CF_DRAW_PLAYERS_WAR_STATUS;
114 do {
115 pplayer = pplayer->prev;
116 FREESURFACE(pplayer->gfx);
117 } while (pplayer != pplayers_dlg->begin_widget_list);
118
119 players_dialog_update();
120 }
121
122 return -1;
123}
124
125/**********************************************************************/
128 static int toggle_draw_ceasefire_status_callback(struct widget *pwidget)
129{
130 if (PRESSED_EVENT(main_data.event)) {
131 /* exit button -> neutral -> war -> casefire -> peace -> alliance */
132 struct widget *pplayer = pplayers_dlg->end_widget_list->prev->prev->prev->prev->prev->prev;
133
134 sdl2_client_flags ^= CF_DRAW_PLAYERS_CEASEFIRE_STATUS;
135 do {
136 pplayer = pplayer->prev;
137 FREESURFACE(pplayer->gfx);
138 } while (pplayer != pplayers_dlg->begin_widget_list);
139
140 players_dialog_update();
141 }
142
143 return -1;
144}
145
146/**********************************************************************/
149 static int toggle_draw_peace_status_callback(struct widget *pwidget)
150{
151 if (PRESSED_EVENT(main_data.event)) {
152 /* exit button -> neutral -> war -> casefire -> peace -> alliance */
153 struct widget *pplayer = pplayers_dlg->end_widget_list->prev->prev->prev->prev->prev->prev;
154
155 sdl2_client_flags ^= CF_DRAW_PLAYERS_PEACE_STATUS;
156 do {
157 pplayer = pplayer->prev;
158 FREESURFACE(pplayer->gfx);
159 } while (pplayer != pplayers_dlg->begin_widget_list);
160
161 players_dialog_update();
162 }
163
164 return -1;
165}
166
167/**********************************************************************/
170 static int toggle_draw_alliance_status_callback(struct widget *pwidget)
171{
172 if (PRESSED_EVENT(main_data.event)) {
173 /* exit button -> neutral -> war -> casefire -> peace -> alliance */
174 struct widget *pplayer = pplayers_dlg->end_widget_list->prev->prev->prev->prev->prev->prev;
175
176 sdl2_client_flags ^= CF_DRAW_PLAYERS_ALLIANCE_STATUS;
177 do {
178 pplayer = pplayer->prev;
179 FREESURFACE(pplayer->gfx);
180 } while (pplayer != pplayers_dlg->begin_widget_list);
181
182 players_dialog_update();
183 }
184
185 return -1;
186}
187
188/**********************************************************************/
191 static int toggle_draw_neutral_status_callback(struct widget *pwidget)
192{
193 if (PRESSED_EVENT(main_data.event)) {
194 /* exit button -> neutral -> war -> casefire -> peace -> alliance */
195 struct widget *pplayer = pplayers_dlg->end_widget_list->prev->prev->prev->prev->prev->prev;
196
197 sdl2_client_flags ^= CF_DRAW_PLAYERS_NEUTRAL_STATUS;
198 do {
199 pplayer = pplayer->prev;
200 FREESURFACE(pplayer->gfx);
201 } while (pplayer != pplayers_dlg->begin_widget_list);
202
203 players_dialog_update();
204 }
205
206 return -1;
207}
208
209/**********************************************************************/
212 static bool have_diplomat_info_about(struct player *pplayer)
213{
214 return (pplayer == client.conn.playing
215 || (pplayer != client.conn.playing
216 && team_has_embassy(client.conn.playing->team, pplayer)));
217}
218
219/**********************************************************************/
222 void real_players_dialog_update(void *unused)
223{
224 if (pplayers_dlg) {
225 struct widget *pplayer0, *pplayer1;
226 struct player *pplayer;
227 int i;
228 struct astring astr = ASTRING_INIT;
229
230 /* redraw window */
231 widget_redraw(pplayers_dlg->end_widget_list);
232
233 /* exit button -> neutral -> war -> casefire -> peace -> alliance */
234 pplayer0 = pplayers_dlg->end_widget_list->prev->prev->prev->prev->prev->prev;
235 do {
236 pplayer0 = pplayer0->prev;
237 pplayer1 = pplayer0;
238 pplayer = pplayer0->data.player;
239
240 for (i = 0; i < num_player_dlg_columns; i++) {
241 if (player_dlg_columns[i].show) {
242 switch (player_dlg_columns[i].type) {
243 case COL_TEXT:
244 case COL_RIGHT_TEXT:
245 astr_add_line(&astr, "%s: %s", player_dlg_columns[i].title,
246 player_dlg_columns[i].func(pplayer));
247 break;
248 case COL_BOOLEAN:
249 astr_add_line(&astr, "%s: %s", player_dlg_columns[i].title,
250 player_dlg_columns[i].bool_func(pplayer) ?
251 _("Yes") : _("No"));
252 break;
253 default:
254 break;
255 }
256 }
257 }
258
259 copy_chars_to_utf8_str(pplayer0->info_label, astr_str(&astr));
260
261 astr_free(&astr);
262
263 /* now add some eye candy ... */
264 if (pplayer1 != pplayers_dlg->begin_widget_list) {
265 SDL_Rect dst0, dst1;
266
267 dst0.x = pplayer0->size.x + pplayer0->size.w / 2;
268 dst0.y = pplayer0->size.y + pplayer0->size.h / 2;
269
270 do {
271 pplayer1 = pplayer1->prev;
272 if (have_diplomat_info_about(pplayer)
273 || have_diplomat_info_about(pplayer1->data.player)) {
274
275 dst1.x = pplayer1->size.x + pplayer1->size.w / 2;
276 dst1.y = pplayer1->size.y + pplayer1->size.h / 2;
277
278 switch (player_diplstate_get(pplayer,
279 pplayer1->data.player)->type) {
280 case DS_ARMISTICE:
281 if (sdl2_client_flags & CF_DRAW_PLAYERS_NEUTRAL_STATUS) {
282 create_line(pplayer1->dst->surface,
283 dst0.x, dst0.y, dst1.x, dst1.y,
284 get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE));
285 }
286 break;
287 case DS_WAR:
288 if (sdl2_client_flags & CF_DRAW_PLAYERS_WAR_STATUS) {
289 create_line(pplayer1->dst->surface,
290 dst0.x, dst0.y, dst1.x, dst1.y,
291 get_theme_color(COLOR_THEME_PLRDLG_WAR));
292 }
293 break;
294 case DS_CEASEFIRE:
295 if (sdl2_client_flags & CF_DRAW_PLAYERS_CEASEFIRE_STATUS) {
296 create_line(pplayer1->dst->surface,
297 dst0.x, dst0.y, dst1.x, dst1.y,
298 get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE));
299 }
300 break;
301 case DS_PEACE:
302 if (sdl2_client_flags & CF_DRAW_PLAYERS_PEACE_STATUS) {
303 create_line(pplayer1->dst->surface,
304 dst0.x, dst0.y, dst1.x, dst1.y,
305 get_theme_color(COLOR_THEME_PLRDLG_PEACE));
306 }
307 break;
308 case DS_ALLIANCE:
309 if (sdl2_client_flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS) {
310 create_line(pplayer1->dst->surface,
311 dst0.x, dst0.y, dst1.x, dst1.y,
312 get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE));
313 }
314 break;
315 default:
316 /* no contact */
317 break;
318 }
319 }
320 } while (pplayer1 != pplayers_dlg->begin_widget_list);
321 }
322 } while (pplayer0 != pplayers_dlg->begin_widget_list);
323
324 /* -------------------- */
325 /* redraw */
326 redraw_group(pplayers_dlg->begin_widget_list,
327 pplayers_dlg->end_widget_list->prev, 0);
328 widget_mark_dirty(pplayers_dlg->end_widget_list);
329
330 flush_dirty();
331 }
332}
333
334/**********************************************************************/
337 void popup_players_dialog(bool raise)
338{
339 struct widget *pwindow = NULL, *buf = NULL;
340 SDL_Surface *logo = NULL, *zoomed = NULL;
341 utf8_str *pstr;
342 SDL_Rect dst;
343 int i, n, h;
344 double a, b, r;
345 SDL_Rect area;
346
347 if (pplayers_dlg) {
348 return;
349 }
350
351 n = 0;
352 players_iterate(pplayer) {
353 if (is_barbarian(pplayer)) {
354 continue;
355 }
356 n++;
357 } players_iterate_end;
358
359 if (n < 2) {
360 return;
361 }
362
363 pplayers_dlg = fc_calloc(1, sizeof(struct small_dialog));
364
365 pstr = create_utf8_from_char_fonto(Q_("?header:Players"),
366 FONTO_ATTENTION);
367 pstr->style |= TTF_STYLE_BOLD;
368
369 pwindow = create_window_skeleton(NULL, pstr, 0);
370
371 pwindow->action = players_window_dlg_callback;
372 set_wstate(pwindow, FC_WS_NORMAL);
373
374 add_to_gui_list(ID_WINDOW, pwindow);
375 pplayers_dlg->end_widget_list = pwindow;
376 /* ---------- */
377 /* Exit button */
378 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
379 WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
380 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
381 FONTO_ATTENTION);
382 buf->action = exit_players_dlg_callback;
383 set_wstate(buf, FC_WS_NORMAL);
384 buf->key = SDLK_ESCAPE;
385
386 add_to_gui_list(ID_BUTTON, buf);
387 /* ---------- */
388
389 for (i = 0; i < DS_LAST; i++) {
390 switch (i) {
391 case DS_ARMISTICE:
392 buf = create_checkbox(pwindow->dst,
393 (sdl2_client_flags & CF_DRAW_PLAYERS_NEUTRAL_STATUS),
394 WF_RESTORE_BACKGROUND);
395 buf->action = toggle_draw_neutral_status_callback;
396 buf->key = SDLK_n;
397 break;
398 case DS_WAR:
399 buf = create_checkbox(pwindow->dst,
400 (sdl2_client_flags & CF_DRAW_PLAYERS_WAR_STATUS),
401 WF_RESTORE_BACKGROUND);
402 buf->action = toggle_draw_war_status_callback;
403 buf->key = SDLK_w;
404 break;
405 case DS_CEASEFIRE:
406 buf = create_checkbox(pwindow->dst,
407 (sdl2_client_flags & CF_DRAW_PLAYERS_CEASEFIRE_STATUS),
408 WF_RESTORE_BACKGROUND);
409 buf->action = toggle_draw_ceasefire_status_callback;
410 buf->key = SDLK_c;
411 break;
412 case DS_PEACE:
413 buf = create_checkbox(pwindow->dst,
414 (sdl2_client_flags & CF_DRAW_PLAYERS_PEACE_STATUS),
415 WF_RESTORE_BACKGROUND);
416 buf->action = toggle_draw_peace_status_callback;
417 buf->key = SDLK_p;
418 break;
419 case DS_ALLIANCE:
420 buf = create_checkbox(pwindow->dst,
421 (sdl2_client_flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS),
422 WF_RESTORE_BACKGROUND);
423 buf->action = toggle_draw_alliance_status_callback;
424 buf->key = SDLK_a;
425 break;
426 default:
427 /* no contact */
428 continue;
429 break;
430 }
431 set_wstate(buf, FC_WS_NORMAL);
432 add_to_gui_list(ID_CHECKBOX, buf);
433 }
434 /* ---------- */
435
436 players_iterate(pplayer) {
437 if (is_barbarian(pplayer)) {
438 continue;
439 }
440
441 pstr = create_utf8_str_fonto(NULL, 0, FONTO_DEFAULT);
442 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
443
444 logo = get_nation_flag_surface(nation_of_player(pplayer));
445 {
446 /* Aim for a flag height of 60 pixels, but draw smaller flags if there
447 * are more players */
448 double zoom = DEFAULT_ZOOM * (60.0 - n) / logo->h;
449
450 zoomed = zoomSurface(logo, zoom, zoom, 1);
451 }
452
453 buf = create_icon2(zoomed, pwindow->dst,
454 WF_RESTORE_BACKGROUND | WF_WIDGET_HAS_INFO_LABEL
455 | WF_FREE_THEME);
456 buf->info_label = pstr;
457
458 if (!pplayer->is_alive) {
459 pstr = create_utf8_from_char_fonto(_("R.I.P."), FONTO_DEFAULT);
460 pstr->style |= TTF_STYLE_BOLD;
461 pstr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_TEXT);
462 logo = create_text_surf_from_utf8(pstr);
463 FREEUTF8STR(pstr);
464
465 dst.x = (zoomed->w - logo->w) / 2;
466 dst.y = (zoomed->h - logo->h) / 2;
467 alphablit(logo, NULL, zoomed, &dst, 255);
468 FREESURFACE(logo);
469 }
470
471 if (pplayer->is_alive) {
472 set_wstate(buf, FC_WS_NORMAL);
473 }
474
475 buf->data.player = pplayer;
476
477 buf->action = player_callback;
478
479 add_to_gui_list(ID_LABEL, buf);
480
481 } players_iterate_end;
482
483 pplayers_dlg->begin_widget_list = buf;
484
485 resize_window(pwindow, NULL, NULL, adj_size(500), adj_size(400));
486
487 area = pwindow->area;
488
489 r = MIN(area.w, area.h);
490 r -= ((MAX(buf->size.w, buf->size.h) * 2));
491 r /= 2;
492 a = (2.0 * M_PI) / n;
493
494 widget_set_position(pwindow,
495 (main_window_width() - pwindow->size.w) / 2,
496 (main_window_height() - pwindow->size.h) / 2);
497
498 /* exit button */
499 buf = pwindow->prev;
500
501 buf->size.x = area.x + area.w - buf->size.w - 1;
502 buf->size.y = pwindow->size.y + adj_size(2);
503
504 n = area.y;
505 pstr = create_utf8_str_fonto(NULL, 0, FONTO_DEFAULT);
506 pstr->style |= TTF_STYLE_BOLD;
507 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
508
509 for (i = 0; i < DS_LAST; i++) {
510 switch (i) {
511 case DS_ARMISTICE:
512 pstr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE);
513 break;
514 case DS_WAR:
515 pstr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR);
516 break;
517 case DS_CEASEFIRE:
518 pstr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE);
519 break;
520 case DS_PEACE:
521 pstr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE);
522 break;
523 case DS_ALLIANCE:
524 pstr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE);
525 break;
526 default:
527 /* no contact */
528 continue;
529 break;
530 }
531
532 copy_chars_to_utf8_str(pstr, diplstate_type_translated_name(i));
533 logo = create_text_surf_from_utf8(pstr);
534
535 buf = buf->prev;
536 h = MAX(buf->size.h, logo->h);
537 buf->size.x = area.x + adj_size(5);
538 buf->size.y = n + (h - buf->size.h) / 2;
539
540 dst.x = adj_size(5) + buf->size.w + adj_size(6);
541 dst.y = n + (h - logo->h) / 2;
542 alphablit(logo, NULL, pwindow->theme, &dst, 255);
543 n += h;
544 FREESURFACE(logo);
545 }
546 FREEUTF8STR(pstr);
547
548 /* first player shield */
549 buf = buf->prev;
550 buf->size.x = area.x + area.w / 2 - buf->size.w / 2;
551 buf->size.y = area.y + area.h / 2 - r - buf->size.h / 2;
552
553 n = 1;
554 if (buf != pplayers_dlg->begin_widget_list) {
555 do {
556 buf = buf->prev;
557 b = M_PI_2 + n * a;
558 buf->size.x = area.x + area.w / 2 - r * cos(b) - buf->size.w / 2;
559 buf->size.y = area.y + area.h / 2 - r * sin(b) - buf->size.h / 2;
560 n++;
561 } while (buf != pplayers_dlg->begin_widget_list);
562 }
563
564 players_dialog_update();
565}
566
567/**********************************************************************/
570 void popdown_players_dialog(void)
571{
572 if (pplayers_dlg) {
573 popdown_window_group_dialog(pplayers_dlg->begin_widget_list,
574 pplayers_dlg->end_widget_list);
575 FC_FREE(pplayers_dlg);
576 }
577}
578
579
580/* ============================== SHORT =============================== */
581 static struct advanced_dialog *short_players_dlg = NULL;
582
583/**********************************************************************/
586 static int players_nations_window_dlg_callback(struct widget *pwindow)
587{
588 return -1;
589}
590
591/**********************************************************************/
594 static int exit_players_nations_dlg_callback(struct widget *pwidget)
595{
596 if (PRESSED_EVENT(main_data.event)) {
597 popdown_players_nations_dialog();
598 flush_dirty();
599 }
600
601 return -1;
602}
603
604/**********************************************************************/
607 static int player_nation_callback(struct widget *pwidget)
608{
609 struct player *pplayer = pwidget->data.player;
610 bool try_dlg = FALSE;
611 bool popdown = FALSE;
612
613 if (main_data.event.type == SDL_MOUSEBUTTONDOWN) {
614 switch (main_data.event.button.button) {
615#if 0
616 case SDL_BUTTON_LEFT:
617
618 break;
619 case SDL_BUTTON_MIDDLE:
620
621 break;
622#endif /* 0 */
623 case SDL_BUTTON_RIGHT:
624 popup_intel_dialog(pplayer);
625
626 popdown = TRUE;
627 break;
628 default:
629 try_dlg = TRUE;
630 break;
631 }
632 } else if (PRESSED_EVENT(main_data.event)) {
633 try_dlg = TRUE;
634 }
635
636 if (try_dlg && pplayer != client_player()) {
637 const struct player_diplstate *ds;
638
639 ds = player_diplstate_get(client_player(), pplayer);
640
641 if (ds->type != DS_NO_CONTACT
642 && (ds->type != DS_WAR
643 || can_meet_with_player(pplayer)
644 || can_intel_with_player(pplayer))) {
645 popup_diplomacy_dialog(pplayer);
646
647 popdown = TRUE;
648 } else {
649 set_output_window_text(_("You cannot interact with that player "
650 "with your current contact state - "
651 "Try right mouse button for intelligence."));
652 }
653 }
654
655 if (popdown) {
656 /* We came from one of these dialogs. Just try to pop down both -
657 * the one open will react. */
658 popdown_players_nations_dialog();
659 popdown_players_dialog();
660 }
661
662 return -1;
663}
664
665/**********************************************************************/
668 void popup_players_nations_dialog(void)
669{
670 struct widget *pwindow = NULL, *buf = NULL;
671 SDL_Surface *logo = NULL;
672 utf8_str *pstr;
673 char cbuf[128], *state;
674 int n = 0, w = 0, units_h = 0;
675 SDL_Rect area;
676
677 if (short_players_dlg) {
678 return;
679 }
680
681 short_players_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
682
683 /* TRANS: Nations report title */
684 pstr = create_utf8_from_char_fonto(_("Nations"), FONTO_ATTENTION);
685 pstr->style |= TTF_STYLE_BOLD;
686
687 pwindow = create_window_skeleton(NULL, pstr, 0);
688
689 pwindow->action = players_nations_window_dlg_callback;
690 set_wstate(pwindow, FC_WS_NORMAL);
691
692 add_to_gui_list(ID_WINDOW, pwindow);
693 short_players_dlg->end_widget_list = pwindow;
694
695 area = pwindow->area;
696
697 /* ---------- */
698 /* Exit button */
699 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
700 WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
701 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
702 FONTO_ATTENTION);
703 area.w = MAX(area.w, buf->size.w + adj_size(10));
704 buf->action = exit_players_nations_dlg_callback;
705 set_wstate(buf, FC_WS_NORMAL);
706 buf->key = SDLK_ESCAPE;
707
708 add_to_gui_list(ID_BUTTON, buf);
709 /* ---------- */
710
711 players_iterate(pplayer) {
712 if (pplayer != client.conn.playing) {
713 const struct player_diplstate *ds;
714
715 if (!pplayer->is_alive || is_barbarian(pplayer)) {
716 continue;
717 }
718
719 ds = player_diplstate_get(client.conn.playing, pplayer);
720
721 if (is_ai(pplayer)) {
722 state = _("AI");
723 } else {
724 if (pplayer->is_connected) {
725 if (pplayer->phase_done) {
726 state = _("done");
727 } else {
728 state = _("moving");
729 }
730 } else {
731 state = _("disconnected");
732 }
733 }
734
735 if (ds->type == DS_CEASEFIRE) {
736 fc_snprintf(cbuf, sizeof(cbuf), "%s(%s) - %d %s",
737 nation_adjective_for_player(pplayer),
738 state,
739 ds->turns_left, PL_("turn", "turns", ds->turns_left));
740 } else {
741 fc_snprintf(cbuf, sizeof(cbuf), "%s(%s)",
742 nation_adjective_for_player(pplayer),
743 state);
744 }
745
746 pstr = create_utf8_from_char_fonto(cbuf, FONTO_DEFAULT);
747 pstr->style |= TTF_STYLE_BOLD;
748
749 logo = get_nation_flag_surface(nation_of_player(pplayer));
750
751 buf = create_iconlabel(logo, pwindow->dst, pstr,
752 (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE));
753
754 /* At least RMB works always */
755 set_wstate(buf, FC_WS_NORMAL);
756
757 /* Now add some eye candy ... */
758 switch (ds->type) {
759 case DS_ARMISTICE:
760 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE);
761 break;
762 case DS_WAR:
763 if (can_meet_with_player(pplayer) || can_intel_with_player(pplayer)) {
764 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR);
765 } else {
766 buf->string_utf8->fgcol = *(get_theme_color(COLOR_THEME_PLRDLG_WAR_RESTRICTED));
767 }
768 break;
769 case DS_CEASEFIRE:
770 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE);
771 break;
772 case DS_PEACE:
773 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE);
774 break;
775 case DS_ALLIANCE:
776 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE);
777 break;
778 case DS_NO_CONTACT:
779 /* TODO: Add a color for this. Widget is not disabled! */
780 buf->string_utf8->fgcol = *(get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT));
781 break;
782 case DS_TEAM:
783 case DS_LAST:
784 break;
785 }
786
787 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
788
789 buf->data.player = pplayer;
790
791 buf->action = player_nation_callback;
792
793 add_to_gui_list(ID_LABEL, buf);
794
795 area.w = MAX(w, buf->size.w);
796 area.h += buf->size.h;
797
798 if (n > 19) {
799 set_wflag(buf, WF_HIDDEN);
800 }
801
802 n++;
803 }
804 } players_iterate_end;
805
806 short_players_dlg->begin_widget_list = buf;
807 short_players_dlg->begin_active_widget_list = short_players_dlg->begin_widget_list;
808 short_players_dlg->end_active_widget_list = pwindow->prev->prev;
809 short_players_dlg->active_widget_list = short_players_dlg->end_active_widget_list;
810
811
812 /* ---------- */
813 if (n > 20) {
814 units_h = create_vertical_scrollbar(short_players_dlg, 1, 20, TRUE, TRUE);
815 short_players_dlg->scroll->count = n;
816
817 n = units_h;
818 area.w += n;
819
820 units_h = 20 * buf->size.h;
821
822 } else {
823 units_h = area.h;
824 }
825
826 /* ---------- */
827
828 area.h = units_h;
829
830 resize_window(pwindow, NULL, NULL,
831 (pwindow->size.w - pwindow->area.w) + area.w,
832 (pwindow->size.h + pwindow->area.h) + area.h);
833
834 area = pwindow->area;
835
836 widget_set_position(pwindow,
837 ((main_data.event.motion.x + pwindow->size.w + adj_size(10) < main_window_width()) ?
838 (main_data.event.motion.x + adj_size(10)) :
839 (main_window_width() - pwindow->size.w - adj_size(10))),
840 ((main_data.event.motion.y - adj_size(2) + pwindow->size.h < main_window_height()) ?
841 (main_data.event.motion.y - adj_size(2)) :
842 (main_window_height() - pwindow->size.h - adj_size(10))));
843
844 w = area.w;
845
846 if (short_players_dlg->scroll) {
847 w -= n;
848 }
849
850 /* exit button */
851 buf = pwindow->prev;
852 buf->size.x = area.x + area.w - buf->size.w - 1;
853 buf->size.y = pwindow->size.y + adj_size(2);
854
855 /* cities */
856 buf = buf->prev;
857 setup_vertical_widgets_position(1, area.x, area.y, w, 0,
858 short_players_dlg->begin_active_widget_list,
859 buf);
860
861 if (short_players_dlg->scroll) {
862 setup_vertical_scrollbar_area(short_players_dlg->scroll,
863 area.x + area.w, area.y,
864 area.h, TRUE);
865 }
866
867 /* -------------------- */
868 /* redraw */
869 redraw_group(short_players_dlg->begin_widget_list, pwindow, 0);
870 widget_mark_dirty(pwindow);
871
872 flush_dirty();
873}
874
875/**********************************************************************/
878 void popdown_players_nations_dialog(void)
879{
880 if (short_players_dlg) {
881 popdown_window_group_dialog(short_players_dlg->begin_widget_list,
882 short_players_dlg->end_widget_list);
883 FC_FREE(short_players_dlg->scroll);
884 FC_FREE(short_players_dlg);
885 }
886}
astr_free
void astr_free(struct astring *astr)
Definition astring.c:153
astr_add_line
void astr_add_line(struct astring *astr, const char *format,...)
Definition astring.c:299
n
#define n
Definition astring.c:77
astring.h
astr_str
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
ASTRING_INIT
#define ASTRING_INIT
Definition astring.h:44
can_meet_with_player
bool can_meet_with_player(const struct player *pplayer)
Definition client_main.c:1274
can_intel_with_player
bool can_intel_with_player(const struct player *pplayer)
Definition client_main.c:1285
client
struct civclient client
Definition client_main.c:150
client_main.h
client_player
#define client_player()
Definition client_main.h:106
climisc.h
incite_cost
char * incite_cost
Definition comments.c:74
current_theme
QString current_theme
Definition fc_client.cpp:65
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
popup_diplomacy_dialog
static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they, struct player *initiator)
Definition diplodlg.c:205
popup_intel_dialog
void popup_intel_dialog(struct player *p)
Definition inteldlg.c:167
flush_dirty
void flush_dirty(void)
Definition mapview.c:468
popdown_players_dialog
void popdown_players_dialog(void)
Definition plrdlg.c:105
real_players_dialog_update
void real_players_dialog_update(void *unused)
Definition plrdlg.c:730
popup_players_dialog
void popup_players_dialog(bool raise)
Definition plrdlg.c:91
title
const char * title
Definition repodlgs.c:1314
type
GType type
Definition repodlgs.c:1313
COL_TEXT
@ COL_TEXT
Definition unitselect.c:50
set_output_window_text
#define set_output_window_text(_pstr_)
Definition chatline.h:31
get_theme_color
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
main_window_width
int main_window_width(void)
Definition graphics.c:685
create_line
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1379
alphablit
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
main_data
struct sdl2_data main_data
Definition graphics.c:57
main_window_height
int main_window_height(void)
Definition graphics.c:693
DEFAULT_ZOOM
#define DEFAULT_ZOOM
Definition graphics.h:198
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
ID_BUTTON
@ ID_BUTTON
Definition gui_id.h:29
ID_LABEL
@ ID_LABEL
Definition gui_id.h:27
ID_CHECKBOX
@ ID_CHECKBOX
Definition gui_id.h:35
ID_WINDOW
@ ID_WINDOW
Definition gui_id.h:30
sdl2_client_flags
Uint32 sdl2_client_flags
Definition gui_main.c:97
CF_DRAW_PLAYERS_ALLIANCE_STATUS
#define CF_DRAW_PLAYERS_ALLIANCE_STATUS
Definition gui_main.h:62
CF_DRAW_PLAYERS_CEASEFIRE_STATUS
#define CF_DRAW_PLAYERS_CEASEFIRE_STATUS
Definition gui_main.h:60
CF_DRAW_PLAYERS_PEACE_STATUS
#define CF_DRAW_PLAYERS_PEACE_STATUS
Definition gui_main.h:61
CF_DRAW_PLAYERS_NEUTRAL_STATUS
#define CF_DRAW_PLAYERS_NEUTRAL_STATUS
Definition gui_main.h:63
adj_size
#define adj_size(size)
Definition gui_main.h:141
CF_DRAW_PLAYERS_WAR_STATUS
#define CF_DRAW_PLAYERS_WAR_STATUS
Definition gui_main.h:59
PRESSED_EVENT
#define PRESSED_EVENT(event)
Definition gui_main.h:71
copy_chars_to_utf8_str
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
create_text_surf_from_utf8
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
create_utf8_str_fonto
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
FREEUTF8STR
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
SF_CENTER
#define SF_CENTER
Definition gui_string.h:40
FONTO_DEFAULT
@ FONTO_DEFAULT
Definition gui_string.h:65
FONTO_ATTENTION
@ FONTO_ATTENTION
Definition gui_string.h:67
create_utf8_from_char_fonto
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
get_nation_flag_surface
static SDL_Surface * get_nation_flag_surface(const struct nation_type *pnation)
Definition gui_tilespec.h:227
short_players_dlg
static struct advanced_dialog * short_players_dlg
Definition plrdlg.c:581
popdown_players_nations_dialog
void popdown_players_nations_dialog(void)
Definition plrdlg.c:878
toggle_draw_alliance_status_callback
static int toggle_draw_alliance_status_callback(struct widget *pwidget)
Definition plrdlg.c:170
popup_players_nations_dialog
void popup_players_nations_dialog(void)
Definition plrdlg.c:668
exit_players_nations_dlg_callback
static int exit_players_nations_dlg_callback(struct widget *pwidget)
Definition plrdlg.c:594
player_callback
static int player_callback(struct widget *pwidget)
Definition plrdlg.c:79
toggle_draw_neutral_status_callback
static int toggle_draw_neutral_status_callback(struct widget *pwidget)
Definition plrdlg.c:191
players_window_dlg_callback
static int players_window_dlg_callback(struct widget *pwindow)
Definition plrdlg.c:88
toggle_draw_war_status_callback
static int toggle_draw_war_status_callback(struct widget *pwidget)
Definition plrdlg.c:107
toggle_draw_peace_status_callback
static int toggle_draw_peace_status_callback(struct widget *pwidget)
Definition plrdlg.c:149
exit_players_dlg_callback
static int exit_players_dlg_callback(struct widget *pwidget)
Definition plrdlg.c:66
M_PI_2
#define M_PI_2
Definition plrdlg.c:56
player_nation_callback
static int player_nation_callback(struct widget *pwidget)
Definition plrdlg.c:607
M_PI
#define M_PI
Definition plrdlg.c:53
players_nations_window_dlg_callback
static int players_nations_window_dlg_callback(struct widget *pwindow)
Definition plrdlg.c:586
toggle_draw_ceasefire_status_callback
static int toggle_draw_ceasefire_status_callback(struct widget *pwidget)
Definition plrdlg.c:128
have_diplomat_info_about
static bool have_diplomat_info_about(struct player *pplayer)
Definition plrdlg.c:212
pplayers_dlg
static struct small_dialog * pplayers_dlg
Definition plrdlg.c:59
COLOR_THEME_PLRDLG_CEASEFIRE
@ COLOR_THEME_PLRDLG_CEASEFIRE
Definition themecolors.h:108
COLOR_THEME_PLRDLG_ALLIANCE
@ COLOR_THEME_PLRDLG_ALLIANCE
Definition themecolors.h:106
COLOR_THEME_WIDGET_DISABLED_TEXT
@ COLOR_THEME_WIDGET_DISABLED_TEXT
Definition themecolors.h:42
COLOR_THEME_PLRDLG_PEACE
@ COLOR_THEME_PLRDLG_PEACE
Definition themecolors.h:110
COLOR_THEME_PLRDLG_TEXT
@ COLOR_THEME_PLRDLG_TEXT
Definition themecolors.h:111
COLOR_THEME_PLRDLG_WAR_RESTRICTED
@ COLOR_THEME_PLRDLG_WAR_RESTRICTED
Definition themecolors.h:113
COLOR_THEME_PLRDLG_WAR
@ COLOR_THEME_PLRDLG_WAR
Definition themecolors.h:112
COLOR_THEME_PLRDLG_ARMISTICE
@ COLOR_THEME_PLRDLG_ARMISTICE
Definition themecolors.h:107
add_to_gui_list
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
move_window_group_dialog
bool move_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:1016
select_window_group_dialog
bool select_window_group_dialog(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:998
setup_vertical_widgets_position
int setup_vertical_widgets_position(int step, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h, struct widget *begin, struct widget *end)
Definition widget.c:1051
redraw_group
Uint16 redraw_group(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, int add_to_update)
Definition widget.c:720
popdown_window_group_dialog
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
widget_set_position
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
FC_WS_NORMAL
@ FC_WS_NORMAL
Definition widget.h:96
widget_mark_dirty
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
WF_WIDGET_HAS_INFO_LABEL
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
WF_HIDDEN
@ WF_HIDDEN
Definition widget.h:68
WF_FREE_THEME
@ WF_FREE_THEME
Definition widget.h:72
WF_DRAW_TEXT_LABEL_WITH_SPACE
@ WF_DRAW_TEXT_LABEL_WITH_SPACE
Definition widget.h:87
show
#define show(id)
Definition widget.h:235
widget_redraw
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
set_wflag
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
create_checkbox
struct widget * create_checkbox(struct gui_layer *pdest, bool state, Uint32 flags)
Definition widget_checkbox.c:115
create_themeicon
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
Definition widget_icon.c:212
create_icon2
struct widget * create_icon2(SDL_Surface *icon, struct gui_layer *pdest, Uint32 flags)
Definition widget_icon.c:337
create_iconlabel
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
Definition widget_label.c:215
setup_vertical_scrollbar_area
void setup_vertical_scrollbar_area(struct scroll_bar *scroll, Sint16 start_x, Sint16 start_y, Uint16 height, bool swap_start_x)
Definition widget_scrollbar.c:567
create_vertical_scrollbar
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
Definition widget_scrollbar.c:486
resize_window
bool resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
Definition widget_window.c:255
create_window_skeleton
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
Definition widget_window.c:180
gui_id.h
gui_tilespec.h
themespec.h
widget.h
chatline.h
colors.h
diplodlg.h
graphics.h
gui_main.h
inteldlg.h
mapview.h
plrdlg.h
sprite.h
func
get_token_fn_t func
Definition inputfile.c:128
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
nation.h
team_has_embassy
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
players_iterate_end
#define players_iterate_end
Definition player.h:537
players_iterate
#define players_iterate(_pplayer)
Definition player.h:532
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
is_ai
#define is_ai(plr)
Definition player.h:230
player_dlg_columns
struct player_dlg_column player_dlg_columns[]
Definition plrdlg_common.c:574
num_player_dlg_columns
const int num_player_dlg_columns
Definition plrdlg_common.c:601
COL_BOOLEAN
@ COL_BOOLEAN
Definition plrdlg_common.h:31
COL_RIGHT_TEXT
@ COL_RIGHT_TEXT
Definition plrdlg_common.h:33
players_dialog_update
void players_dialog_update(void)
Definition update_queue.c:658
MIN
#define MIN(x, y)
Definition shared.h:55
MAX
#define MAX(x, y)
Definition shared.h:54
advanced_dialog
Definition widget.h:180
advanced_dialog::begin_active_widget_list
struct widget * begin_active_widget_list
Definition widget.h:184
advanced_dialog::end_widget_list
struct widget * end_widget_list
Definition widget.h:182
advanced_dialog::end_active_widget_list
struct widget * end_active_widget_list
Definition widget.h:185
advanced_dialog::active_widget_list
struct widget * active_widget_list
Definition widget.h:186
advanced_dialog::scroll
struct scroll_bar * scroll
Definition widget.h:187
advanced_dialog::begin_widget_list
struct widget * begin_widget_list
Definition widget.h:181
astring
Definition astring.h:36
civclient::conn
struct connection conn
Definition client_main.h:96
connection::playing
struct player * playing
Definition connection.h:151
player_diplstate
Definition player.h:196
player_diplstate::type
enum diplstate_type type
Definition player.h:197
player
Definition player.h:247
player::team
struct team * team
Definition player.h:259
scroll_bar::count
Uint16 count
Definition widget_scrollbar.h:27
sdl2_data::event
SDL_Event event
Definition graphics.h:217
small_dialog
Definition widget.h:174
small_dialog::begin_widget_list
struct widget * begin_widget_list
Definition widget.h:175
small_dialog::end_widget_list
struct widget * end_widget_list
Definition widget.h:176
utf8_str
Definition gui_string.h:52
widget
Definition widget.h:112
widget::theme
SDL_Surface * theme
Definition widget.h:118
widget::player
struct player * player
Definition widget.h:130
widget::data
union widget::@192 data
widget::prev
struct widget * prev
Definition widget.h:114
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::action
int(* action)(struct widget *)
Definition widget.h:157
widget::area
SDL_Rect area
Definition widget.h:149
widget::gfx
SDL_Surface * gfx
Definition widget.h:120
widget::size
SDL_Rect size
Definition widget.h:145
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47