Freeciv-3.3
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#include "nation.h"
34
35/* client */
36#include "zoom.h"
37
38/* gui-sdl2 */
39#include "colors.h"
40#include "graphics.h"
41#include "gui_id.h"
42#include "gui_main.h"
43#include "gui_tilespec.h"
44#include "mapctrl.h"
45#include "mapview.h"
46#include "sprite.h"
47#include "widget.h"
48
49#include "finddlg.h"
50
51/* ====================================================================== */
52/* ============================= FIND CITY MENU ========================= */
53/* ====================================================================== */
55
56/**********************************************************************/
59static int find_city_window_dlg_callback(struct widget *pwindow)
60{
63 }
64
65 return -1;
66}
67
68/**********************************************************************/
71static int exit_find_city_dlg_callback(struct widget *pwidget)
72{
74 int orginal_x = pwidget->data.cont->id0;
75 int orginal_y = pwidget->data.cont->id1;
76
78
80
82 }
83
84 return -1;
85}
86
87/**********************************************************************/
90static int find_city_callback(struct widget *pwidget)
91{
93 struct city *pcity = pwidget->data.city;
94
95 if (pcity) {
97 if (main_data.event.button.button == SDL_BUTTON_RIGHT) {
99 }
100 flush_dirty();
101 }
102 }
103
104 return -1;
105}
106
107/**********************************************************************/
120
121/**********************************************************************/
125{
126 struct widget *pwindow = NULL, *buf = NULL;
128 utf8_str *pstr;
129 char cbuf[128];
130 int h = 0, n = 0, w = 0, units_h = 0;
131 struct player *owner = NULL;
132 struct tile *original;
133 int window_x = 0, window_y = 0;
134 bool mouse = (main_data.event.type == SDL_MOUSEBUTTONDOWN);
135 SDL_Rect area;
136
137 /* check that there are any cities to find */
138 players_iterate(pplayer) {
139 h = city_list_size(pplayer->cities);
140 if (h > 0) {
141 break;
142 }
144
145 if (find_city_dlg && !h) {
146 return;
147 }
148
149 original = canvas_pos_to_tile(main_data.map->w / 2, main_data.map->h / 2, map_zoom);
150
151 find_city_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
152
154 pstr->style |= TTF_STYLE_BOLD;
155
156 pwindow = create_window_skeleton(NULL, pstr, 0);
157
159 set_wstate(pwindow , FC_WS_NORMAL);
160
163
164 area = pwindow->area;
165
166 /* ---------- */
167 /* Exit button */
168 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
170 | WF_FREE_DATA);
171 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
173 area.w = MAX(area.w, buf->size.w + adj_size(10));
176 buf->key = SDLK_ESCAPE;
177 buf->data.cont = fc_calloc(1, sizeof(struct container));
178 buf->data.cont->id0 = index_to_map_pos_x(tile_index(original));
179 buf->data.cont->id1 = index_to_map_pos_y(tile_index(original));
180
182 /* ---------- */
183
184 players_iterate(pplayer) {
185 city_list_iterate(pplayer->cities, pcity) {
186 fc_snprintf(cbuf , sizeof(cbuf), "%s (%d)", city_name_get(pcity),
188
190 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
191
195 }
196
197 buf = create_iconlabel(logo, pwindow->dst, pstr,
199
203 }
204
205 buf->string_utf8->style &= ~SF_CENTER;
206 buf->string_utf8->fgcol = *(get_player_color(tileset, city_owner(pcity))->color);
207 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
208
209 buf->data.city = pcity;
210
213
215
216 area.w = MAX(area.w, buf->size.w);
217 area.h += buf->size.h;
218
219 if (n > 19) {
221 }
222
223 n++;
226
231
232
233 /* ---------- */
234 if (n > 20) {
237
238 n = units_h;
239 area.w += n;
240
241 units_h = 20 * buf->size.h + adj_size(2);
242
243 } else {
244 units_h = area.h;
245 }
246
247 /* ---------- */
248
249 area.h = units_h;
250
251 resize_window(pwindow , NULL, NULL,
252 (pwindow->size.w - pwindow->area.w) + area.w,
253 (pwindow->size.h - pwindow->area.h) + area.h);
254
255 area = pwindow->area;
256
257 if (!mouse) {
258 window_x = adj_size(10);
259 window_y = (main_window_height() - pwindow->size.h) / 2;
260 } else {
261 window_x = (main_data.event.motion.x + pwindow->size.w + adj_size(10) < main_window_width()) ?
262 (main_data.event.motion.x + adj_size(10)) :
263 (main_window_width() - pwindow->size.w - adj_size(10));
264 window_y = (main_data.event.motion.y - adj_size(2) + pwindow->size.h < main_window_height()) ?
265 (main_data.event.motion.y - adj_size(2)) :
266 (main_window_height() - pwindow->size.h - adj_size(10));
267 }
268
270
271 w = area.w;
272
273 if (find_city_dlg->scroll) {
274 w -= n;
275 }
276
277 /* exit button */
278 buf = pwindow->prev;
279
280 buf->size.x = area.x + area.w - buf->size.w - 1;
281 buf->size.y = pwindow->size.y + adj_size(2);
282
283 /* cities */
284 buf = buf->prev;
285 setup_vertical_widgets_position(1, area.x, area.y, w, 0,
287 buf);
288
289 if (find_city_dlg->scroll) {
291 area.x + area.w, area.y,
292 area.h, TRUE);
293 }
294
295 /* -------------------- */
296 /* redraw */
298 widget_mark_dirty(pwindow);
299
300 flush_dirty();
301}
#define n
Definition astring.c:77
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_list_iterate(citylist, pcity)
Definition city.h:505
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
#define city_owner(_pcity_)
Definition city.h:560
#define city_list_iterate_end
Definition city.h:507
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
char * incite_cost
Definition comments.c:76
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 int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
QString current_theme
Definition fc_client.cpp:64
#define _(String)
Definition fcintl.h:67
struct world wld
Definition game.c:62
struct city * owner
Definition citydlg.c:226
void popup_find_dialog(void)
Definition finddlg.c:58
void flush_dirty(void)
Definition mapview.c:468
static int find_city_window_dlg_callback(struct widget *pwindow)
Definition finddlg.c:59
static struct advanced_dialog * find_city_dlg
Definition finddlg.c:54
void popdown_find_dialog(void)
Definition finddlg.c:110
static int find_city_callback(struct widget *pwidget)
Definition finddlg.c:90
static int exit_find_city_dlg_callback(struct widget *pwidget)
Definition finddlg.c:71
int main_window_width(void)
Definition graphics.c:685
SDL_Surface * crop_visible_part_from_surface(SDL_Surface *psrc)
Definition graphics.c:1225
struct sdl2_data main_data
Definition graphics.c:57
int main_window_height(void)
Definition graphics.c:693
@ ID_TERRAIN_ADV_DLG_WINDOW
Definition gui_id.h:201
@ ID_TERRAIN_ADV_DLG_EXIT_BUTTON
Definition gui_id.h:202
@ ID_LABEL
Definition gui_id.h:27
#define adj_size(size)
Definition gui_main.h:141
#define PRESSED_EVENT(event)
Definition gui_main.h:71
#define SF_CENTER
Definition gui_string.h:40
@ 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
static SDL_Surface * get_nation_flag_surface(const struct nation_type *pnation)
void enable_and_redraw_find_city_button(void)
Definition mapctrl.c:2235
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
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_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)
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)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
static int index_to_map_pos_y(int mindex)
Definition map.h:752
static int index_to_map_pos_x(int mindex)
Definition map.h:743
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:444
bool player_owns_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:261
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
#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
GdkRGBA color
Definition colors.h:22
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:50
enum gen_action action
Definition unit.h:160
struct tile * tile
Definition unit.h:142
union widget::@223 data
struct widget * prev
Definition widget.h:114
struct gui_layer * dst
Definition widget.h:116
struct city * city
Definition widget.h:128
struct container * cont
Definition widget.h:127
int(* action)(struct widget *)
Definition widget.h:157
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:960
#define TRUE
Definition support.h:46
#define tile_index(_pt_)
Definition tile.h:89
float map_zoom
Definition zoom.c:25