Freeciv-3.1
Loading...
Searching...
No Matches
finddlg.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 "fcintl.h"
29#include "log.h"
30
31/* common */
32#include "game.h"
33
34/* client */
35#include "zoom.h"
36
37/* gui-sdl2 */
38#include "colors.h"
39#include "graphics.h"
40#include "gui_id.h"
41#include "gui_main.h"
42#include "gui_tilespec.h"
43#include "mapctrl.h"
44#include "mapview.h"
45#include "sprite.h"
46#include "widget.h"
47
48#include "finddlg.h"
49
50/* ====================================================================== */
51/* ============================= FIND CITY MENU ========================= */
52/* ====================================================================== */
53static struct advanced_dialog *find_city_dlg = NULL;
54
55/**********************************************************************/
58static int find_city_window_dlg_callback(struct widget *pwindow)
59{
62 }
63
64 return -1;
65}
66
67/**********************************************************************/
70static int exit_find_city_dlg_callback(struct widget *pwidget)
71{
73 int orginal_x = pwidget->data.cont->id0;
74 int orginal_y = pwidget->data.cont->id1;
75
77
78 center_tile_mapcanvas(map_pos_to_tile(&(wld.map), orginal_x, orginal_y));
79
81 }
82
83 return -1;
84}
85
86/**********************************************************************/
89static int find_city_callback(struct widget *pwidget)
90{
92 struct city *pcity = pwidget->data.city;
93
94 if (pcity) {
96 if (main_data.event.button.button == SDL_BUTTON_RIGHT) {
98 }
100 }
101 }
102
103 return -1;
104}
105
106/**********************************************************************/
119
120/**********************************************************************/
124{
125 struct widget *pwindow = NULL, *buf = NULL;
127 utf8_str *pstr;
128 char cbuf[128];
129 int h = 0, n = 0, w = 0, units_h = 0;
130 struct player *owner = NULL;
131 struct tile *original;
132 int window_x = 0, window_y = 0;
133 bool mouse = (main_data.event.type == SDL_MOUSEBUTTONDOWN);
134 SDL_Rect area;
135
136 /* check that there are any cities to find */
137 players_iterate(pplayer) {
138 h = city_list_size(pplayer->cities);
139 if (h > 0) {
140 break;
141 }
143
144 if (find_city_dlg && !h) {
145 return;
146 }
147
148 original = canvas_pos_to_tile(main_data.map->w / 2, main_data.map->h / 2, map_zoom);
149
150 find_city_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
151
152 pstr = create_utf8_from_char_fonto(_("Find City"), FONTO_ATTENTION);
153 pstr->style |= TTF_STYLE_BOLD;
154
155 pwindow = create_window_skeleton(NULL, pstr, 0);
156
158 set_wstate(pwindow , FC_WS_NORMAL);
159
162
163 area = pwindow->area;
164
165 /* ---------- */
166 /* Exit button */
167 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
169 | WF_FREE_DATA);
170 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
172 area.w = MAX(area.w, buf->size.w + adj_size(10));
173 buf->action = exit_find_city_dlg_callback;
175 buf->key = SDLK_ESCAPE;
176 buf->data.cont = fc_calloc(1, sizeof(struct container));
177 buf->data.cont->id0 = index_to_map_pos_x(tile_index(original));
178 buf->data.cont->id1 = index_to_map_pos_y(tile_index(original));
179
181 /* ---------- */
182
183 players_iterate(pplayer) {
184 city_list_iterate(pplayer->cities, pcity) {
185 fc_snprintf(cbuf , sizeof(cbuf), "%s (%d)", city_name_get(pcity),
186 city_size_get(pcity));
187
189 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
190
191 if (!player_owns_city(owner, pcity)) {
194 }
195
196 buf = create_iconlabel(logo, pwindow->dst, pstr,
198
199 if (!player_owns_city(owner, pcity)) {
201 owner = city_owner(pcity);
202 }
203
204 buf->string_utf8->style &= ~SF_CENTER;
205 buf->string_utf8->fgcol = *(get_player_color(tileset, city_owner(pcity))->color);
206 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
207
208 buf->data.city = pcity;
209
210 buf->action = find_city_callback;
212
214
215 area.w = MAX(area.w, buf->size.w);
216 area.h += buf->size.h;
217
218 if (n > 19) {
219 set_wflag(buf , WF_HIDDEN);
220 }
221
222 n++;
225
230
231
232 /* ---------- */
233 if (n > 20) {
236
237 n = units_h;
238 area.w += n;
239
240 units_h = 20 * buf->size.h + adj_size(2);
241
242 } else {
243 units_h = area.h;
244 }
245
246 /* ---------- */
247
248 area.h = units_h;
249
250 resize_window(pwindow , NULL, NULL,
251 (pwindow->size.w - pwindow->area.w) + area.w,
252 (pwindow->size.h - pwindow->area.h) + area.h);
253
254 area = pwindow->area;
255
256 if (!mouse) {
257 window_x = adj_size(10);
258 window_y = (main_window_height() - pwindow->size.h) / 2;
259 } else {
260 window_x = (main_data.event.motion.x + pwindow->size.w + adj_size(10) < main_window_width()) ?
261 (main_data.event.motion.x + adj_size(10)) :
262 (main_window_width() - pwindow->size.w - adj_size(10));
263 window_y = (main_data.event.motion.y - adj_size(2) + pwindow->size.h < main_window_height()) ?
264 (main_data.event.motion.y - adj_size(2)) :
265 (main_window_height() - pwindow->size.h - adj_size(10));
266 }
267
268 widget_set_position(pwindow, window_x, window_y);
269
270 w = area.w;
271
272 if (find_city_dlg->scroll) {
273 w -= n;
274 }
275
276 /* exit button */
277 buf = pwindow->prev;
278
279 buf->size.x = area.x + area.w - buf->size.w - 1;
280 buf->size.y = pwindow->size.y + adj_size(2);
281
282 /* cities */
283 buf = buf->prev;
284 setup_vertical_widgets_position(1, area.x, area.y, w, 0,
286 buf);
287
288 if (find_city_dlg->scroll) {
290 area.x + area.w, area.y,
291 area.h, TRUE);
292 }
293
294 /* -------------------- */
295 /* redraw */
297 widget_mark_dirty(pwindow);
298
299 flush_dirty();
300}
#define n
Definition astring.c:77
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 color * get_player_color(const struct tileset *t, const struct player *pplayer)
QString current_theme
Definition fc_client.cpp:65
#define _(String)
Definition fcintl.h:67
struct world wld
Definition game.c:58
struct city * owner
Definition citydlg.c:219
void popup_find_dialog(void)
Definition finddlg.c:58
void flush_dirty(void)
Definition mapview.c:450
static int find_city_window_dlg_callback(struct widget *pwindow)
Definition finddlg.c:58
static struct advanced_dialog * find_city_dlg
Definition finddlg.c:53
void popdown_find_dialog(void)
Definition finddlg.c:109
static int find_city_callback(struct widget *pwidget)
Definition finddlg.c:89
static int exit_find_city_dlg_callback(struct widget *pwidget)
Definition finddlg.c:70
int main_window_width(void)
Definition graphics.c:685
SDL_Surface * crop_visible_part_from_surface(SDL_Surface *psrc)
Definition graphics.c:1226
struct sdl2_data main_data
Definition graphics.c:57
int main_window_height(void)
Definition graphics.c:693
#define adj_size(size)
Definition gui_main.h:138
#define PRESSED_EVENT(event)
Definition gui_main.h:68
void enable_and_redraw_find_city_button(void)
Definition mapctrl.c:2235
@ ID_TERRAIN_ADV_DLG_WINDOW
Definition gui_id.h:202
@ ID_TERRAIN_ADV_DLG_EXIT_BUTTON
Definition gui_id.h:203
@ ID_LABEL
Definition gui_id.h:27
#define SF_CENTER
Definition gui_string.h:40
@ FONTO_DEFAULT
Definition gui_string.h:64
@ 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)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:417
static int index_to_map_pos_y(int mindex)
Definition map.h:696
static int index_to_map_pos_x(int mindex)
Definition map.h:687
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
void center_tile_mapcanvas(const struct tile *ptile)
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
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
GdkRGBA color
Definition colors.h:21
int id1
Definition widget.h:104
int id0
Definition widget.h:103
SDL_Event event
Definition graphics.h:217
SDL_Surface * map
Definition graphics.h:210
Definition tile.h:49
Uint8 style
Definition gui_string.h:53
union widget::@214 data
struct gui_layer * dst
Definition widget.h:116
struct widget * prev
Definition widget.h:114
int(* action)(struct widget *)
Definition widget.h:157
struct city * city
Definition widget.h:128
struct container * cont
Definition widget.h:127
SDL_Rect area
Definition widget.h:149
SDL_Rect size
Definition widget.h:145
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define TRUE
Definition support.h:46
#define tile_index(_pt_)
Definition tile.h:87
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:585
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
@ 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_FREE_DATA
Definition widget.h:78
@ 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
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
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)
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)
float map_zoom
Definition zoom.c:25