Freeciv-3.3
Loading...
Searching...
No Matches
inteldlg.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/* SDL3 */
19#include <SDL3/SDL.h>
20
21/* utility */
22#include "fcintl.h"
23#include "log.h"
24
25/* common */
26#include "government.h"
27#include "nation.h"
28#include "research.h"
29
30/* client */
31#include "client_main.h"
32#include "spaceshipdlg_g.h"
33
34/* gui-sdl3 */
35#include "graphics.h"
36#include "gui_id.h"
37#include "gui_main.h"
38#include "gui_tilespec.h"
39#include "mapview.h"
40#include "repodlgs.h"
41#include "sprite.h"
42#include "widget.h"
43
44#include "inteldlg.h"
45
46struct intel_dialog {
47 struct player *pplayer;
49 int pos_x, pos_y;
50};
51
52#define SPECLIST_TAG dialog
53#define SPECLIST_TYPE struct intel_dialog
54#include "speclist.h"
55
56#define dialog_list_iterate(dialoglist, pdialog) \
57 TYPED_LIST_ITERATE(struct intel_dialog, dialoglist, pdialog)
58#define dialog_list_iterate_end LIST_ITERATE_END
59
60static struct dialog_list *dialog_list;
61static struct intel_dialog *create_intel_dialog(struct player *p);
62
63/**********************************************************************/
70
71/**********************************************************************/
78
79/**********************************************************************/
83{
85 if (pdialog->pplayer == pplayer) {
86 return pdialog;
87 }
89
90 return NULL;
91}
92
93/**********************************************************************/
96static int intel_window_dlg_callback(struct widget *pwindow)
97{
100
101 move_window_group(selected_dialog->pdialog->begin_widget_list, pwindow);
102 }
103
104 return -1;
105}
106
107/**********************************************************************/
110static int tech_callback(struct widget *pwidget)
111{
112 /* get tech help - PORT ME */
113 return -1;
114}
115
116/**********************************************************************/
119static int spaceship_callback(struct widget *pwidget)
120{
122 struct player *pplayer = pwidget->data.player;
123
124 popdown_intel_dialog(pplayer);
125 popup_spaceship_dialog(pplayer);
126 }
127
128 return -1;
129}
130
131/**********************************************************************/
134static int exit_intel_dlg_callback(struct widget *pwidget)
135{
138 flush_dirty();
139 }
140
141 return -1;
142}
143
144/**********************************************************************/
148{
150}
151
152/**********************************************************************/
156{
157 struct intel_dialog *pdialog = fc_calloc(1, sizeof(struct intel_dialog));
158
159 pdialog->pplayer = pplayer;
160
161 pdialog->pdialog = fc_calloc(1, sizeof(struct advanced_dialog));
162
163 pdialog->pos_x = 0;
164 pdialog->pos_y = 0;
165
167
168 return pdialog;
169}
170
171/**********************************************************************/
175{
177
178 if (pdialog == NULL) {
180 } else {
181 /* Bring existing dialog to front */
183 pdialog->pdialog->end_widget_list);
184 }
185
187}
188
189/**********************************************************************/
193{
195
196 if (pdialog) {
198 pdialog->pdialog->end_widget_list);
199
201
202 FC_FREE(pdialog->pdialog->scroll);
203 FC_FREE(pdialog->pdialog);
205 }
206}
207
208/**********************************************************************/
217
218/**********************************************************************/
223{
224 const struct research *mresearch, *presearch;
226 struct widget *pwindow = NULL, *buf = NULL, *last;
228 SDL_Surface *text1, *info, *text2 = NULL, *text3 = NULL;
229 utf8_str *pstr;
231 char cbuf[2560], plr_buf[4 * MAX_LEN_NAME];
232 int ntech = 0, count = 0, col;
233 int nwonder = 0;
234 struct city *pcapital;
235 SDL_Rect area;
236 struct research *research;
237
238 if (pdialog) {
239 /* save window position and delete old content */
240 if (pdialog->pdialog->end_widget_list) {
241 pdialog->pos_x = pdialog->pdialog->end_widget_list->size.x;
242 pdialog->pos_y = pdialog->pdialog->end_widget_list->size.y;
243
245 pdialog->pdialog->end_widget_list);
246 }
247
248 pstr = create_utf8_from_char_fonto(_("Foreign Intelligence Report"),
250 pstr->style |= TTF_STYLE_BOLD;
251
252 pwindow = create_window_skeleton(NULL, pstr, 0);
253
255 set_wstate(pwindow , FC_WS_NORMAL);
256 pwindow->data.player = p;
257
258 add_to_gui_list(ID_WINDOW, pwindow);
259 pdialog->pdialog->end_widget_list = pwindow;
260
261 area = pwindow->area;
262
263 /* ---------- */
264 /* Exit button */
265 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
268 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
270 area.w = MAX(area.w, buf->size.w + adj_size(10));
273 buf->data.player = p;
274 buf->key = SDLK_ESCAPE;
275
277 /* ---------- */
278
280
281 {
282 double zoom = DEFAULT_ZOOM * 60.0 / logo->h;
283
284 text1 = zoomSurface(logo, zoom, zoom, 1);
285 }
286
287 logo = text1;
288
289 buf = create_icon2(logo, pwindow->dst,
291 | WF_FREE_THEME);
292 buf->action = spaceship_callback;
294 buf->data.player = p;
295 fc_snprintf(cbuf, sizeof(cbuf),
296 _("Intelligence Information about the %s Spaceship"),
299
301
302 /* ---------- */
303 fc_snprintf(cbuf, sizeof(cbuf),
304 _("Intelligence Information for the %s Empire"),
306
308 pstr->style |= TTF_STYLE_BOLD;
309 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
310
312 area.w = MAX(area.w, text1->w + adj_size(20));
313 area.h += text1->h + adj_size(20);
314
315 /* ---------- */
316
320 pstr->style &= ~TTF_STYLE_BOLD;
321
322 /* FIXME: these should use common gui code, and avoid duplication! */
324 switch (research->researching) {
325 case A_UNKNOWN:
326 case A_UNSET:
327 fc_snprintf(cbuf, sizeof(cbuf),
328 _("Ruler: %s Government: %s\n"
329 "Capital: %s Gold: %d\n"
330 "Tax: %d%% Science: %d%% Luxury: %d%%\n"
331 "Researching: %s\n"
332 "Culture: %d"),
335 /* TRANS: "unknown" location */
336 NULL != pcapital ? city_name_get(pcapital) : _("(Unknown)"),
337 p->economic.gold, p->economic.tax,
339 research->researching == A_UNSET ? _("(none)") : _("(Unknown)"),
340 p->client.culture);
341 break;
342 default:
343 fc_snprintf(cbuf, sizeof(cbuf),
344 _("Ruler: %s Government: %s\n"
345 "Capital: %s Gold: %d\n"
346 "Tax: %d%% Science: %d%% Luxury: %d%%\n"
347 "Researching: %s(%d/%d)\n"
348 "Culture: %d"),
351 /* TRANS: "unknown" location */
352 NULL != pcapital ? city_name_get(pcapital) : _("(Unknown)"),
354 p->economic.luxury,
359 break;
360 };
361 } else {
362 fc_snprintf(cbuf, sizeof(cbuf),
363 _("Ruler: %s Government: %s\n"
364 "Capital: %s Gold: %d\n"
365 "Tax rates unknown\n"
366 "Researching: (Unknown)\n"
367 "Culture: (Unknown)"),
370 /* TRANS: "unknown" location */
371 NULL != pcapital ? city_name_get(pcapital) : _("(Unknown)"),
372 p->economic.gold);
373 }
374
377 area.w = MAX(area.w, logo->w + adj_size(10) + info->w + adj_size(20));
378
379 /* ---------- */
381 col = area.w / (tmp_surf->w + adj_size(4));
383 ntech = 0;
384 last = buf;
391
392 buf = create_icon2(get_tech_icon(i), pwindow->dst,
394 | WF_FREE_THEME);
395 buf->action = tech_callback;
397
398 buf->info_label
402
404
405 if (ntech > ((2 * col) - 1)) {
407 }
408
409 ntech++;
410 }
412
413 pdialog->pdialog->begin_widget_list = buf;
414
415 if (ntech > 0) {
416 pdialog->pdialog->end_active_widget_list = last->prev;
418 if (ntech > 2 * col) {
420 count = create_vertical_scrollbar(pdialog->pdialog, col, 2, TRUE, TRUE);
421 area.h += (2 * buf->size.h + adj_size(10));
422 } else {
423 count = 0;
424 if (ntech > col) {
425 area.h += buf->size.h;
426 }
427 area.h += (adj_size(10) + buf->size.h);
428 }
429
430 area.w = MAX(area.w, col * buf->size.w + count);
431
432 fc_snprintf(cbuf, sizeof(cbuf), _("Their techs that we don't have :"));
434 pstr->style |= TTF_STYLE_BOLD;
436 }
437
438 nwonder = 0;
439 cbuf[0] = '\0';
440 improvement_iterate(impr) {
441 if (is_wonder(impr)) {
442 const char *cityname;
443 const char *notes = NULL;
444
445 if (wonder_is_built(p, impr)) {
446 struct city *wcity = city_from_wonder(p, impr);
447
448 if (wcity != NULL) {
449 cityname = city_name_get(wcity);
450 } else {
451 cityname = _("(unknown city)");
452 }
453 if (improvement_obsolete(p, impr, NULL)) {
454 notes = _(" (obsolete)");
455 }
456 } else if (wonder_is_lost(p, impr)) {
457 cityname = _("(lost)");
458 } else {
459 continue;
460 }
461
462 cat_snprintf(cbuf, sizeof(cbuf), "%s: %s%s\n",
463 improvement_name_translation(impr), cityname,
464 notes != NULL ? notes : "");
465
466 nwonder++;
467 }
469
470 if (nwonder > 0) {
473 area.h += MAX(logo->h + adj_size(20), info->h + text3->h + adj_size(20));
474 } else {
475 area.h += MAX(logo->h + adj_size(20), info->h + adj_size(20));
476 }
477
479
480 resize_window(pwindow, NULL, NULL,
481 (pwindow->size.w - pwindow->area.w) + area.w,
482 (pwindow->size.h - pwindow->area.h) + area.h);
483
484 area = pwindow->area;
485
486 /* ------------------------ */
487 widget_set_position(pwindow,
488 (pdialog->pos_x) ? (pdialog->pos_x) : ((main_window_width() - pwindow->size.w) / 2),
489 (pdialog->pos_y) ? (pdialog->pos_y) : ((main_window_height() - pwindow->size.h) / 2));
490
491 /* exit button */
492 buf = pwindow->prev;
493 buf->size.x = area.x + area.w - buf->size.w - 1;
494 buf->size.y = pwindow->size.y + adj_size(2);
495
496 dst.x = area.x + (area.w - text1->w) / 2;
497 dst.y = area.y + adj_size(8);
498
499 alphablit(text1, NULL, pwindow->theme, &dst, 255);
500 dst.y += text1->h + adj_size(10);
502
503 /* spaceship button */
504 buf = buf->prev;
505 dst.x = area.x + (area.w - (buf->size.w + adj_size(10) + info->w)) / 2;
506 buf->size.x = dst.x;
507 buf->size.y = dst.y;
508
509 dst.x += buf->size.w + adj_size(10);
510 alphablit(info, NULL, pwindow->theme, &dst, 255);
511 dst.y += info->h + adj_size(10);
512 FREESURFACE(info);
513
514 /* --------------------- */
515
516 if (ntech > 0) {
517 dst.x = area.x + adj_size(5);
518 alphablit(text2, NULL, pwindow->theme, &dst, 255);
519 dst.y += text2->h + adj_size(2);
521 }
522
523 if (nwonder > 0) {
524 dst.x = area.x + adj_size(5);
525 alphablit(text3, NULL, pwindow->theme, &dst, 255);
526 dst.y += text3->h + adj_size(2);
528 }
529
530 if (ntech > 0 || nwonder > 0) {
531 setup_vertical_widgets_position(col, area.x, dst.y, 0, 0,
534
535 if (pdialog->pdialog->scroll) {
537 area.x + area.w, dst.y,
538 area.h - (dst.y + 1), TRUE);
539 }
540 }
541
543 widget_mark_dirty(pwindow);
544
545 flush_dirty();
546 }
547}
SDL_Surface * zoomSurface(SDL_Surface *src, double zoomx, double zoomy, int smooth)
Zoom a surface by independent horizontal and vertical factors with optional smoothing.
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool client_is_global_observer(void)
#define client_player()
char * incite_cost
Definition comments.c:76
QString current_theme
Definition fc_client.cpp:64
#define MAX_LEN_NAME
Definition fc_types.h:66
#define _(String)
Definition fcintl.h:67
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:391
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
void popup_intel_dialog(struct player *p)
Definition inteldlg.c:167
static struct intel_dialog * get_intel_dialog(struct player *pplayer)
Definition inteldlg.c:138
void close_intel_dialog(struct player *p)
Definition inteldlg.c:223
#define dialog_list_iterate_end
Definition inteldlg.c:93
#define dialog_list_iterate(dialoglist, pdialog)
Definition inteldlg.c:91
void intel_dialog_done(void)
Definition inteldlg.c:128
static struct dialog_list * dialog_list
Definition inteldlg.c:111
void intel_dialog_init(void)
Definition inteldlg.c:119
static struct intel_dialog * create_intel_dialog(struct player *p)
Definition inteldlg.c:244
void update_intel_dialog(struct player *p)
Definition inteldlg.c:462
void flush_dirty(void)
Definition mapview.c:468
void popup_spaceship_dialog(struct player *pplayer)
int main_window_width(void)
Definition graphics.c:685
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
struct sdl2_data main_data
Definition graphics.c:57
int main_window_height(void)
Definition graphics.c:693
#define DEFAULT_ZOOM
Definition graphics.h:198
#define FREESURFACE(ptr)
Definition graphics.h:322
@ ID_BUTTON
Definition gui_id.h:29
@ ID_ICON
Definition gui_id.h:33
@ ID_WINDOW
Definition gui_id.h:30
#define adj_size(size)
Definition gui_main.h:141
#define PRESSED_EVENT(event)
Definition gui_main.h:71
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
void change_fonto_utf8(utf8_str *pstr, enum font_origin origin)
Definition gui_string.c:584
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
@ FONTO_HEADING
Definition gui_string.h:69
@ FONTO_DEFAULT
Definition gui_string.h:65
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
SDL_Surface * get_tech_icon(Tech_type_id tech)
static SDL_Surface * get_nation_flag_surface(const struct nation_type *pnation)
void popdown_intel_dialog(struct player *p)
Definition inteldlg.c:196
static int intel_window_dlg_callback(struct widget *pwindow)
Definition inteldlg.c:100
void popdown_intel_dialogs(void)
Definition inteldlg.c:215
static int tech_callback(struct widget *pwidget)
Definition inteldlg.c:114
static int spaceship_callback(struct widget *pwidget)
Definition inteldlg.c:123
static int exit_intel_dlg_callback(struct widget *pwidget)
Definition inteldlg.c:138
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
bool select_window_group_dialog(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:998
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
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
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1039
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
@ FC_WS_NORMAL
Definition widget.h:96
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_HIDDEN
Definition widget.h:68
@ WF_FREE_THEME
Definition widget.h:72
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
struct widget * create_icon2(SDL_Surface *icon, struct gui_layer *pdest, Uint32 flags)
void setup_vertical_scrollbar_area(struct scroll_bar *scroll, Sint16 start_x, Sint16 start_y, Uint16 height, bool swap_start_x)
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
bool resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1337
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Definition research.c:668
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
#define MAX(x, y)
Definition shared.h:54
struct widget * begin_active_widget_list
Definition widget.h:184
struct widget * end_widget_list
Definition widget.h:182
struct widget * end_active_widget_list
Definition widget.h:185
struct widget * active_widget_list
Definition widget.h:186
struct scroll_bar * scroll
Definition widget.h:187
struct widget * begin_widget_list
Definition widget.h:181
Definition city.h:317
struct advanced_dialog * pdialog
Definition inteldlg.c:52
struct player * pplayer
Definition inteldlg.c:79
struct player_economic economic
Definition player.h:284
int culture
Definition player.h:367
struct player::@73::@76 client
Tech_type_id researching
Definition research.h:52
struct research::@79::@81 client
int researching_cost
Definition research.h:96
int bulbs_researched
Definition research.h:53
SDL_Event event
Definition graphics.h:217
Definition team.c:40
SDL_Surface * theme
Definition widget.h:118
struct player * player
Definition widget.h:130
union widget::@223 data
struct widget * prev
Definition widget.h:114
struct gui_layer * dst
Definition widget.h:116
int(* action)(struct widget *)
Definition widget.h:157
SDL_Rect area
Definition widget.h:149
SDL_Rect size
Definition widget.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
#define TRUE
Definition support.h:46
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:300
#define advance_index_iterate_end
Definition tech.h:244
#define A_FIRST
Definition tech.h:44
#define A_UNSET
Definition tech.h:48
#define A_UNKNOWN
Definition tech.h:49
#define advance_index_iterate(_start, _index)
Definition tech.h:240