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