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/* 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 "nation.h"
36#include "unitlist.h"
37
38/* client */
39#include "client_main.h"
40#include "control.h"
41#include "goto.h"
42
43/* gui-sdl2 */
44#include "colors.h"
45#include "graphics.h"
46#include "gui_id.h"
47#include "gui_main.h"
48#include "gui_tilespec.h"
49#include "mapview.h"
50#include "sprite.h"
51#include "widget.h"
52
53#include "gotodlg.h"
54
55static struct advanced_dialog *goto_dlg = NULL;
57static bool GOTO = TRUE;
58
59static void update_goto_dialog(void);
60
61/**********************************************************************/
64static int goto_dialog_window_callback(struct widget *pwindow)
65{
68 }
69
70 return -1;
71}
72
73/**********************************************************************/
76static int exit_goto_dialog_callback(struct widget *pwidget)
77{
81 }
82
83 return -1;
84}
85
86/**********************************************************************/
90{
92 int plr_id = player_index(player_by_number(MAX_ID - pwidget->id));
93
96 } else {
98 }
100 }
101
102 return -1;
103}
104
105/**********************************************************************/
108static int goto_city_callback(struct widget *pwidget)
109{
111 struct city *pdestcity = game_city_by_number(MAX_ID - pwidget->id);
112
113 if (pdestcity) {
115
116 if (punit) {
117 if (GOTO) {
119 } else {
121 }
122 }
123 }
124
126 flush_dirty();
127 }
128
129 return -1;
130}
131
132/**********************************************************************/
135static void update_goto_dialog(void)
136{
137 struct widget *buf = NULL, *add_dock, *last;
139 utf8_str *pstr;
140 char cbuf[128];
141 int n = 0;
142 struct player *owner = NULL;
143
150 } else {
152 }
153
154 last = add_dock;
155
156 players_iterate(pplayer) {
157 if (!BV_ISSET(all_players, player_index(pplayer))) {
158 continue;
159 }
160
161 city_list_iterate(pplayer->cities, pcity) {
162
163 /* FIXME: Should use unit_can_airlift_to(). */
164 if (!GOTO && !pcity->airlift) {
165 continue;
166 }
167
168 fc_snprintf(cbuf, sizeof(cbuf), "%s (%d)", city_name_get(pcity),
169 city_size_get(pcity));
170
172 pstr->style |= TTF_STYLE_BOLD;
173
174 if (!player_owns_city(owner, pcity)) {
177 }
178
181
182 if (!player_owns_city(owner, pcity)) {
184 owner = city_owner(pcity);
185 }
186
187 buf->string_utf8->fgcol =
189 buf->action = goto_city_callback;
190
191 if (GOTO || pcity->airlift) {
193 }
194
195 fc_assert((MAX_ID - pcity->id) > 0);
196 buf->id = MAX_ID - pcity->id;
197
199 add_dock = buf;
200
201 if (n > (goto_dlg->scroll->active - 1)) {
203 }
204
205 n++;
208
209 if (n > 0) {
211
216
217 if (n > goto_dlg->scroll->active) {
222 } else {
224 }
225
233
234 } else {
236 }
237
238 /* Redraw */
241}
242
243/**********************************************************************/
247{
248 SDL_Color bg_color = {0, 0, 0, 96};
249 struct widget *buf, *pwindow;
250 utf8_str *pstr;
251 SDL_Surface *flag, *enabled, *disabled;
253 int i, col, block_x, x, y;
255
256 if (goto_dlg) {
257 return;
258 }
259
260 goto_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
261
262 pstr = create_utf8_from_char_fonto(_("Select destination"),
264 pstr->style |= TTF_STYLE_BOLD;
265
266 pwindow = create_window_skeleton(NULL, pstr, 0);
267
269 set_wstate(pwindow, FC_WS_NORMAL);
270
271 add_to_gui_list(ID_WINDOW, pwindow);
272 goto_dlg->end_widget_list = pwindow;
273
274 area = pwindow->area;
275
276 /* ---------- */
277 /* Create exit button */
278 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
280 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
284 buf->key = SDLK_ESCAPE;
285 area.w = MAX(area.w, buf->size.w) + adj_size(10);
286
288
289 col = 0;
290 /* --------------------------------------------- */
291 players_iterate(pplayer) {
292 if (pplayer != client.conn.playing
294 continue;
295 }
296
297 flag = resize_surface_box(get_nation_flag_surface(pplayer->nation),
298 adj_size(30), adj_size(30), 1, TRUE, FALSE);
299
300 enabled = create_icon_theme_surf(flag);
302 disabled = create_icon_theme_surf(flag);
303 FREESURFACE(flag);
304
305 buf = create_checkbox(pwindow->dst,
309 set_new_checkbox_theme(buf, enabled, disabled);
310
311 buf->info_label
314 buf->info_label->style &= ~SF_CENTER;
316
319 col++;
321
323
326
327 area.w = MAX(area.w, adj_size(300));
328 area.h = adj_size(320);
329
330 resize_window(pwindow, NULL, NULL,
331 (pwindow->size.w - pwindow->area.w) + area.w,
332 (pwindow->size.h - pwindow->area.h) + area.h);
333
334 /* background */
335 col = (col + 15) / 16; /* number of flag columns */
336
337 flag = resize_surface(current_theme->block,
338 (col * buf->size.w + (col - 1) * adj_size(5) + adj_size(10)),
339 area.h, 1);
340
341 block_x = dst.x = area.x + area.w - flag->w;
342 dst.y = area.y;
343 alphablit(flag, NULL, pwindow->theme, &dst, 255);
344 FREESURFACE(flag);
345
346 widget_set_position(pwindow,
347 (main_window_width() - pwindow->size.w) / 2,
348 (main_window_height() - pwindow->size.h) / 2);
349
350 /* exit button */
351 buf = pwindow->prev;
352 buf->size.x = area.x + area.w - buf->size.w - 1;
353 buf->size.y = pwindow->size.y + adj_size(2);
354
355 /* nations buttons */
356 buf = buf->prev;
357 i = 0;
358 x = block_x + adj_size(5);
359 y = area.y + adj_size(1);
360 fc_assert(col > 0);
361 if (col > 0) {
362 while (buf) {
363 buf->size.x = x;
364 buf->size.y = y;
365
366 if (!((i + 1) % col)) {
367 x = block_x + adj_size(5);
368 y += buf->size.h + adj_size(1);
369 } else {
370 x += buf->size.w + adj_size(5);
371 }
372
374 break;
375 }
376
377 i++;
378 buf = buf->prev;
379 }
380 }
381
383 block_x, area.y,
384 area.h, TRUE);
385
387}
388
389
390/**********************************************************************/
394{
396 return;
397 }
398
401 /* FIXME: Should we include allies in all_players */
403}
404
405/**********************************************************************/
409{
411 return;
412 }
413
416 /* FIXME: Should we include allies in all_players */
417 GOTO = FALSE;
419}
420
421/**********************************************************************/
#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