Freeciv-3.1
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/* SDL2 */
21#ifdef SDL2_PLAIN_INCLUDE
22#include <SDL.h>
23#else /* SDL2_PLAIN_INCLUDE */
24#include <SDL2/SDL.h>
25#endif /* SDL2_PLAIN_INCLUDE */
26
27/* utility */
28#include "bitvector.h"
29#include "fcintl.h"
30#include "log.h"
31
32/* common */
33#include "game.h"
34#include "fc_types.h" /* bv_player */
35#include "unitlist.h"
36
37/* client */
38#include "client_main.h"
39#include "control.h"
40#include "goto.h"
41
42/* gui-sdl2 */
43#include "colors.h"
44#include "graphics.h"
45#include "gui_id.h"
46#include "gui_main.h"
47#include "gui_tilespec.h"
48#include "mapview.h"
49#include "sprite.h"
50#include "widget.h"
51
52#include "gotodlg.h"
53
54static struct advanced_dialog *goto_dlg = NULL;
55bv_player all_players;
56static bool GOTO = TRUE;
57
58static void update_goto_dialog(void);
59
60/**********************************************************************/
63static int goto_dialog_window_callback(struct widget *pwindow)
64{
67 }
68
69 return -1;
70}
71
72/**********************************************************************/
75static int exit_goto_dialog_callback(struct widget *pwidget)
76{
80 }
81
82 return -1;
83}
84
85/**********************************************************************/
89{
91 int plr_id = player_index(player_by_number(MAX_ID - pwidget->id));
92
93 if (BV_ISSET(all_players, plr_id)) {
94 BV_CLR(all_players, plr_id);
95 } else {
96 BV_SET(all_players, plr_id);
97 }
99 }
100
101 return -1;
102}
103
104/**********************************************************************/
107static int goto_city_callback(struct widget *pwidget)
108{
110 struct city *pdestcity = game_city_by_number(MAX_ID - pwidget->id);
111
112 if (pdestcity) {
114
115 if (punit) {
116 if (GOTO) {
117 send_goto_tile(punit, pdestcity->tile);
118 } else {
119 request_unit_airlift(punit, pdestcity);
120 }
121 }
122 }
123
125 flush_dirty();
126 }
127
128 return -1;
129}
130
131/**********************************************************************/
134static void update_goto_dialog(void)
135{
136 struct widget *buf = NULL, *add_dock, *last;
138 utf8_str *pstr;
139 char cbuf[128];
140 int n = 0;
141 struct player *owner = NULL;
142
145 goto_dlg->begin_widget_list = add_dock;
149 } else {
150 add_dock = goto_dlg->begin_widget_list;
151 }
152
153 last = add_dock;
154
155 players_iterate(pplayer) {
156 if (!BV_ISSET(all_players, player_index(pplayer))) {
157 continue;
158 }
159
160 city_list_iterate(pplayer->cities, pcity) {
161
162 /* FIXME: Should use unit_can_airlift_to(). */
163 if (!GOTO && !pcity->airlift) {
164 continue;
165 }
166
167 fc_snprintf(cbuf, sizeof(cbuf), "%s (%d)", city_name_get(pcity),
168 city_size_get(pcity));
169
171 pstr->style |= TTF_STYLE_BOLD;
172
173 if (!player_owns_city(owner, pcity)) {
176 }
177
178 buf = create_iconlabel(logo, goto_dlg->end_widget_list->dst, pstr,
180
181 if (!player_owns_city(owner, pcity)) {
183 owner = city_owner(pcity);
184 }
185
186 buf->string_utf8->fgcol =
189
190 if (GOTO || pcity->airlift) {
192 }
193
194 fc_assert((MAX_ID - pcity->id) > 0);
195 buf->id = MAX_ID - pcity->id;
196
197 widget_add_as_prev(buf, add_dock);
198 add_dock = buf;
199
200 if (n > (goto_dlg->scroll->active - 1)) {
201 set_wflag(buf, WF_HIDDEN);
202 }
203
204 n++;
207
208 if (n > 0) {
210
215
216 if (n > goto_dlg->scroll->active) {
221 } else {
223 }
224
232
233 } else {
235 }
236
237 /* Redraw */
240}
241
242/**********************************************************************/
246{
247 SDL_Color bg_color = {0, 0, 0, 96};
248 struct widget *buf, *pwindow;
249 utf8_str *pstr;
250 SDL_Surface *flag, *enabled, *disabled;
252 int i, col, block_x, x, y;
254
255 if (goto_dlg) {
256 return;
257 }
258
259 goto_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
260
261 pstr = create_utf8_from_char_fonto(_("Select destination"),
263 pstr->style |= TTF_STYLE_BOLD;
264
265 pwindow = create_window_skeleton(NULL, pstr, 0);
266
268 set_wstate(pwindow, FC_WS_NORMAL);
269
270 add_to_gui_list(ID_WINDOW, pwindow);
271 goto_dlg->end_widget_list = pwindow;
272
273 area = pwindow->area;
274
275 /* ---------- */
276 /* Create exit button */
277 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
279 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
283 buf->key = SDLK_ESCAPE;
284 area.w = MAX(area.w, buf->size.w) + adj_size(10);
285
287
288 col = 0;
289 /* --------------------------------------------- */
290 players_iterate(pplayer) {
291 if (pplayer != client.conn.playing
293 continue;
294 }
295
296 flag = resize_surface_box(get_nation_flag_surface(pplayer->nation),
297 adj_size(30), adj_size(30), 1, TRUE, FALSE);
298
299 enabled = create_icon_theme_surf(flag);
301 disabled = create_icon_theme_surf(flag);
302 FREESURFACE(flag);
303
304 buf = create_checkbox(pwindow->dst,
308 set_new_checkbox_theme(buf, enabled, disabled);
309
310 buf->info_label
313 buf->info_label->style &= ~SF_CENTER;
315
318 col++;
320
322
325
326 area.w = MAX(area.w, adj_size(300));
327 area.h = adj_size(320);
328
329 resize_window(pwindow, NULL, NULL,
330 (pwindow->size.w - pwindow->area.w) + area.w,
331 (pwindow->size.h - pwindow->area.h) + area.h);
332
333 /* background */
334 col = (col + 15) / 16; /* number of flag columns */
335
336 flag = resize_surface(current_theme->block,
337 (col * buf->size.w + (col - 1) * adj_size(5) + adj_size(10)),
338 area.h, 1);
339
340 block_x = dst.x = area.x + area.w - flag->w;
341 dst.y = area.y;
342 alphablit(flag, NULL, pwindow->theme, &dst, 255);
343 FREESURFACE(flag);
344
345 widget_set_position(pwindow,
346 (main_window_width() - pwindow->size.w) / 2,
347 (main_window_height() - pwindow->size.h) / 2);
348
349 /* exit button */
350 buf = pwindow->prev;
351 buf->size.x = area.x + area.w - buf->size.w - 1;
352 buf->size.y = pwindow->size.y + adj_size(2);
353
354 /* nations buttons */
355 buf = buf->prev;
356 i = 0;
357 x = block_x + adj_size(5);
358 y = area.y + adj_size(1);
359 fc_assert(col > 0);
360 if (col > 0) {
361 while (buf) {
362 buf->size.x = x;
363 buf->size.y = y;
364
365 if (!((i + 1) % col)) {
366 x = block_x + adj_size(5);
367 y += buf->size.h + adj_size(1);
368 } else {
369 x += buf->size.w + adj_size(5);
370 }
371
373 break;
374 }
375
376 i++;
377 buf = buf->prev;
378 }
379 }
380
382 block_x, area.y,
383 area.h, TRUE);
384
386}
387
388
389/**********************************************************************/
393{
395 return;
396 }
397
400 /* FIXME: Should we include allies in all_players */
402}
403
404/**********************************************************************/
408{
410 return;
411 }
412
415 /* FIXME: Should we include allies in all_players */
416 GOTO = FALSE;
418}
419
420/**********************************************************************/
#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:1115
#define city_list_iterate(citylist, pcity)
Definition city.h:488
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
#define city_owner(_pcity_)
Definition city.h:543
#define city_list_iterate_end
Definition city.h:490
struct civclient client
bool can_client_issue_orders(void)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
void request_unit_airlift(struct unit *punit, struct city *pcity)
Definition control.c:1538
struct unit * head_of_units_in_focus(void)
Definition control.c:411
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:73
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:102
bool send_goto_tile(struct unit *punit, struct tile *ptile)
Definition goto.c:1551
struct city * owner
Definition citydlg.c:219
void popup_goto_dialog(void)
Definition gotodlg.c:257
void flush_dirty(void)
Definition mapview.c:450
static void popup_goto_airlift_dialog(void)
Definition gotodlg.c:245
void popdown_goto_airlift_dialog(void)
Definition gotodlg.c:423
static int goto_dialog_window_callback(struct widget *pwindow)
Definition gotodlg.c:63
static int exit_goto_dialog_callback(struct widget *pwidget)
Definition gotodlg.c:75
static int goto_city_callback(struct widget *pwidget)
Definition gotodlg.c:107
static struct advanced_dialog * goto_dlg
Definition gotodlg.c:54
void popup_airlift_dialog(void)
Definition gotodlg.c:407
bv_player all_players
Definition gotodlg.c:55
static int toggle_goto_nations_cities_dialog_callback(struct widget *pwidget)
Definition gotodlg.c:88
static bool GOTO
Definition gotodlg.c:56
static void update_goto_dialog(void)
Definition gotodlg.c:134
SDL_Surface * resize_surface(const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth)
Definition graphics.c:1236
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:1226
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:1256
#define FREESURFACE(ptr)
Definition graphics.h:322
#define adj_size(size)
Definition gui_main.h:138
#define PRESSED_EVENT(event)
Definition gui_main.h:68
@ ID_BUTTON
Definition gui_id.h:29
@ ID_WINDOW
Definition gui_id.h:30
@ FONTO_ATTENTION
Definition gui_string.h:66
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:107
static SDL_Surface * get_nation_flag_surface(const struct nation_type *pnation)
#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:168
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
struct player * player_by_number(const int player_id)
Definition player.c:840
int player_number(const struct player *pplayer)
Definition player.c:828
int player_index(const struct player *pplayer)
Definition player.c:820
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
bool player_owns_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:255
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
#define MAX(x, y)
Definition shared.h:54
struct widget * active_widget_list
Definition widget.h:186
struct widget * end_widget_list
Definition widget.h:182
struct widget * begin_widget_list
Definition widget.h:181
struct widget * begin_active_widget_list
Definition widget.h:184
struct widget * end_active_widget_list
Definition widget.h:185
struct scroll_bar * scroll
Definition widget.h:187
Definition city.h:309
struct tile * tile
Definition city.h:311
struct connection conn
Definition client_main.h:96
GdkRGBA color
Definition colors.h:21
struct player * playing
Definition connection.h:156
enum diplstate_type type
Definition player.h:201
struct widget * up_left_button
struct widget * pscroll_bar
SDL_Event event
Definition graphics.h:217
Definition unit.h:138
Uint8 style
Definition gui_string.h:53
SDL_Color fgcol
Definition gui_string.h:57
struct widget * next
Definition widget.h:113
struct gui_layer * dst
Definition widget.h:116
struct widget * prev
Definition widget.h:114
int(* action)(struct widget *)
Definition widget.h:157
struct container * cont
Definition widget.h:127
SDL_Surface * theme
Definition widget.h:118
utf8_str * string_utf8
Definition widget.h:121
SDL_Rect area
Definition widget.h:149
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:969
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:585
void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock)
Definition widget.c:601
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
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
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:982
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1038
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)
int 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)