Freeciv-3.2
Loading...
Searching...
No Matches
gotodlg.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdlib.h>
19
20/* SDL3 */
21#include <SDL3/SDL.h>
22
23/* utility */
24#include "bitvector.h"
25#include "fcintl.h"
26#include "log.h"
27
28/* common */
29#include "game.h"
30#include "fc_types.h" /* bv_player */
31#include "nation.h"
32#include "unitlist.h"
33
34/* client */
35#include "client_main.h"
36#include "control.h"
37#include "goto.h"
38
39/* gui-sdl3 */
40#include "colors.h"
41#include "graphics.h"
42#include "gui_id.h"
43#include "gui_main.h"
44#include "gui_tilespec.h"
45#include "mapview.h"
46#include "sprite.h"
47#include "widget.h"
48
49#include "gotodlg.h"
50
51static struct advanced_dialog *goto_dlg = NULL;
53static bool GOTO = TRUE;
54
55static void update_goto_dialog(void);
56
57/**********************************************************************/
60static int goto_dialog_window_callback(struct widget *pwindow)
61{
64 }
65
66 return -1;
67}
68
69/**********************************************************************/
72static int exit_goto_dialog_callback(struct widget *pwidget)
73{
77 }
78
79 return -1;
80}
81
82/**********************************************************************/
86{
88 int plr_id = player_index(player_by_number(MAX_ID - pwidget->id));
89
92 } else {
94 }
96 }
97
98 return -1;
99}
100
101/**********************************************************************/
104static int goto_city_callback(struct widget *pwidget)
105{
107 struct city *pdestcity = game_city_by_number(MAX_ID - pwidget->id);
108
109 if (pdestcity) {
111
112 if (punit) {
113 if (GOTO) {
115 } else {
117 }
118 }
119 }
120
122 flush_dirty();
123 }
124
125 return -1;
126}
127
128/**********************************************************************/
131static void update_goto_dialog(void)
132{
133 struct widget *buf = NULL, *add_dock, *last;
135 utf8_str *pstr;
136 char cbuf[128];
137 int n = 0;
138 struct player *owner = NULL;
139
146 } else {
148 }
149
150 last = add_dock;
151
152 players_iterate(pplayer) {
153 if (!BV_ISSET(all_players, player_index(pplayer))) {
154 continue;
155 }
156
157 city_list_iterate(pplayer->cities, pcity) {
158
159 /* FIXME: Should use unit_can_airlift_to(). */
160 if (!GOTO && !pcity->airlift) {
161 continue;
162 }
163
164 fc_snprintf(cbuf, sizeof(cbuf), "%s (%d)", city_name_get(pcity),
165 city_size_get(pcity));
166
168 pstr->style |= TTF_STYLE_BOLD;
169
170 if (!player_owns_city(owner, pcity)) {
173 }
174
177
178 if (!player_owns_city(owner, pcity)) {
180 owner = city_owner(pcity);
181 }
182
183 buf->string_utf8->fgcol =
185 buf->action = goto_city_callback;
186
187 if (GOTO || pcity->airlift) {
189 }
190
191 fc_assert((MAX_ID - pcity->id) > 0);
192 buf->id = MAX_ID - pcity->id;
193
195 add_dock = buf;
196
197 if (n > (goto_dlg->scroll->active - 1)) {
199 }
200
201 n++;
204
205 if (n > 0) {
207
212
213 if (n > goto_dlg->scroll->active) {
218 } else {
220 }
221
229
230 } else {
232 }
233
234 /* Redraw */
237}
238
239/**********************************************************************/
243{
244 SDL_Color bg_color = {0, 0, 0, 96};
245 struct widget *buf, *pwindow;
246 utf8_str *pstr;
247 SDL_Surface *flag, *enabled, *disabled;
249 int i, col, block_x, x, y;
251
252 if (goto_dlg) {
253 return;
254 }
255
256 goto_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
257
258 pstr = create_utf8_from_char_fonto(_("Select destination"),
260 pstr->style |= TTF_STYLE_BOLD;
261
262 pwindow = create_window_skeleton(NULL, pstr, 0);
263
265 set_wstate(pwindow, FC_WS_NORMAL);
266
267 add_to_gui_list(ID_WINDOW, pwindow);
268 goto_dlg->end_widget_list = pwindow;
269
270 area = pwindow->area;
271
272 /* ---------- */
273 /* Create exit button */
274 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
276 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
280 buf->key = SDLK_ESCAPE;
281 area.w = MAX(area.w, buf->size.w) + adj_size(10);
282
284
285 col = 0;
286 /* --------------------------------------------- */
287 players_iterate(pplayer) {
288 if (pplayer != client.conn.playing
290 continue;
291 }
292
293 flag = resize_surface_box(get_nation_flag_surface(pplayer->nation),
294 adj_size(30), adj_size(30), 1, TRUE, FALSE);
295
296 enabled = create_icon_theme_surf(flag);
298 disabled = create_icon_theme_surf(flag);
299 FREESURFACE(flag);
300
301 buf = create_checkbox(pwindow->dst,
305 set_new_checkbox_theme(buf, enabled, disabled);
306
307 buf->info_label
310 buf->info_label->style &= ~SF_CENTER;
312
315 col++;
317
319
322
323 area.w = MAX(area.w, adj_size(300));
324 area.h = adj_size(320);
325
326 resize_window(pwindow, NULL, NULL,
327 (pwindow->size.w - pwindow->area.w) + area.w,
328 (pwindow->size.h - pwindow->area.h) + area.h);
329
330 /* background */
331 col = (col + 15) / 16; /* number of flag columns */
332
333 flag = resize_surface(current_theme->block,
334 (col * buf->size.w + (col - 1) * adj_size(5) + adj_size(10)),
335 area.h, 1);
336
337 block_x = dst.x = area.x + area.w - flag->w;
338 dst.y = area.y;
339 alphablit(flag, NULL, pwindow->theme, &dst, 255);
340 FREESURFACE(flag);
341
342 widget_set_position(pwindow,
343 (main_window_width() - pwindow->size.w) / 2,
344 (main_window_height() - pwindow->size.h) / 2);
345
346 /* exit button */
347 buf = pwindow->prev;
348 buf->size.x = area.x + area.w - buf->size.w - 1;
349 buf->size.y = pwindow->size.y + adj_size(2);
350
351 /* nations buttons */
352 buf = buf->prev;
353 i = 0;
354 x = block_x + adj_size(5);
355 y = area.y + adj_size(1);
356 fc_assert(col > 0);
357 if (col > 0) {
358 while (buf) {
359 buf->size.x = x;
360 buf->size.y = y;
361
362 if (!((i + 1) % col)) {
363 x = block_x + adj_size(5);
364 y += buf->size.h + adj_size(1);
365 } else {
366 x += buf->size.w + adj_size(5);
367 }
368
370 break;
371 }
372
373 i++;
374 buf = buf->prev;
375 }
376 }
377
379 block_x, area.y,
380 area.h, TRUE);
381
383}
384
385
386/**********************************************************************/
390{
392 return;
393 }
394
397 /* FIXME: Should we include allies in all_players */
399}
400
401/**********************************************************************/
405{
407 return;
408 }
409
412 /* FIXME: Should we include allies in all_players */
413 GOTO = FALSE;
415}
416
417/**********************************************************************/
#define n
Definition astring.c:77
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_list_iterate(citylist, pcity)
Definition city.h:508
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
struct civclient client
bool can_client_issue_orders(void)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
char * incite_cost
Definition comments.c:75
void request_unit_airlift(struct unit *punit, struct city *pcity)
Definition control.c:1543
struct unit * head_of_units_in_focus(void)
Definition control.c:410
int get_num_units_in_focus(void)
Definition control.c:185
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
QString current_theme
Definition fc_client.cpp:65
#define _(String)
Definition fcintl.h:67
struct city * game_city_by_number(int id)
Definition game.c:107
bool send_goto_tile(struct unit *punit, struct tile *ptile)
Definition goto.c:1551
struct city * owner
Definition citydlg.c:226
void popup_goto_dialog(void)
Definition gotodlg.c:258
void flush_dirty(void)
Definition mapview.c:468
static void popup_goto_airlift_dialog(void)
Definition gotodlg.c:246
void popdown_goto_airlift_dialog(void)
Definition gotodlg.c:424
static int goto_dialog_window_callback(struct widget *pwindow)
Definition gotodlg.c:64
static int exit_goto_dialog_callback(struct widget *pwidget)
Definition gotodlg.c:76
static int goto_city_callback(struct widget *pwidget)
Definition gotodlg.c:108
static struct advanced_dialog * goto_dlg
Definition gotodlg.c:55
void popup_airlift_dialog(void)
Definition gotodlg.c:408
bv_player all_players
Definition gotodlg.c:56
static int toggle_goto_nations_cities_dialog_callback(struct widget *pwidget)
Definition gotodlg.c:89
static bool GOTO
Definition gotodlg.c:57
static void update_goto_dialog(void)
Definition gotodlg.c:135
SDL_Surface * resize_surface(const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth)
Definition graphics.c:1237
int main_window_width(void)
Definition graphics.c:685
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:865
SDL_Surface * crop_visible_part_from_surface(SDL_Surface *psrc)
Definition graphics.c:1225
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
SDL_Surface * resize_surface_box(const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth, bool scale_up, bool absolute_dimensions)
Definition graphics.c:1257
#define FREESURFACE(ptr)
Definition graphics.h:322
@ ID_BUTTON
Definition gui_id.h:29
@ 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
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
static SDL_Surface * get_nation_flag_surface(const struct nation_type *pnation)
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock)
Definition widget.c:602
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
#define MAX_ID
Definition widget.h:38
@ FC_WS_NORMAL
Definition widget.h:96
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
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
@ WF_DRAW_TEXT_LABEL_WITH_SPACE
Definition widget.h:87
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
#define del_group(begin_group_widget_list, end_group_widget_list)
Definition widget.h:389
int set_new_checkbox_theme(struct widget *cbox, SDL_Surface *true_surf, SDL_Surface *false_surf)
struct widget * create_checkbox(struct gui_layer *pdest, bool state, Uint32 flags)
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
SDL_Surface * create_icon_theme_surf(SDL_Surface *icon)
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, 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)
#define hide_scrollbar(scrollbar)
#define show_scrollbar(scrollbar)
#define scrollbar_size(scroll)
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)
#define fc_assert(condition)
Definition log.h:176
#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
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_number(const struct player *pplayer)
Definition player.c:837
int player_index(const struct player *pplayer)
Definition player.c:829
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
bool player_owns_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:261
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
#define MAX(x, y)
Definition shared.h:54
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
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:320
struct connection conn
Definition client_main.h:96
GdkRGBA color
Definition colors.h:22
struct player * playing
Definition connection.h:151
enum diplstate_type type
Definition player.h:197
struct widget * up_left_button
struct widget * pscroll_bar
SDL_Event event
Definition graphics.h:217
Definition unit.h:138
struct tile * tile
Definition unit.h:140
SDL_Surface * theme
Definition widget.h:118
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
struct widget * next
Definition widget.h:113
Uint16 id
Definition widget.h:155
SDL_Rect size
Definition widget.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47