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/* SDL3 */
21#include <SDL3/SDL.h>
22
23/* utility */
24#include "fcintl.h"
25#include "log.h"
26
27/* common */
28#include "game.h"
29#include "nation.h"
30
31/* client */
32#include "zoom.h"
33
34/* gui-sdl3 */
35#include "colors.h"
36#include "graphics.h"
37#include "gui_id.h"
38#include "gui_main.h"
39#include "gui_tilespec.h"
40#include "mapctrl.h"
41#include "mapview.h"
42#include "sprite.h"
43#include "widget.h"
44
45#include "finddlg.h"
46
47/* ====================================================================== */
48/* ============================= FIND CITY MENU ========================= */
49/* ====================================================================== */
51
52/**********************************************************************/
55static int find_city_window_dlg_callback(struct widget *pwindow)
56{
59 }
60
61 return -1;
62}
63
64/**********************************************************************/
67static int exit_find_city_dlg_callback(struct widget *pwidget)
68{
70 int orginal_x = pwidget->data.cont->id0;
71 int orginal_y = pwidget->data.cont->id1;
72
74
76
78 }
79
80 return -1;
81}
82
83/**********************************************************************/
86static int find_city_callback(struct widget *pwidget)
87{
89 struct city *pcity = pwidget->data.city;
90
91 if (pcity) {
93 if (main_data.event.button.button == SDL_BUTTON_RIGHT) {
95 }
97 }
98 }
99
100 return -1;
101}
102
103/**********************************************************************/
116
117/**********************************************************************/
121{
122 struct widget *pwindow = NULL, *buf = NULL;
124 utf8_str *pstr;
125 char cbuf[128];
126 int h = 0, n = 0, w = 0, units_h = 0;
127 struct player *owner = NULL;
128 struct tile *original;
129 int window_x = 0, window_y = 0;
130 bool mouse = (main_data.event.type == SDL_EVENT_MOUSE_BUTTON_DOWN);
131 SDL_Rect area;
132
133 /* check that there are any cities to find */
134 players_iterate(pplayer) {
135 h = city_list_size(pplayer->cities);
136 if (h > 0) {
137 break;
138 }
140
141 if (find_city_dlg && !h) {
142 return;
143 }
144
145 original = canvas_pos_to_tile(main_data.map->w / 2, main_data.map->h / 2, map_zoom);
146
147 find_city_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
148
150 pstr->style |= TTF_STYLE_BOLD;
151
152 pwindow = create_window_skeleton(NULL, pstr, 0);
153
155 set_wstate(pwindow , FC_WS_NORMAL);
156
159
160 area = pwindow->area;
161
162 /* ---------- */
163 /* Exit button */
164 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
166 | WF_FREE_DATA);
167 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
169 area.w = MAX(area.w, buf->size.w + adj_size(10));
172 buf->key = SDLK_ESCAPE;
173 buf->data.cont = fc_calloc(1, sizeof(struct container));
174 buf->data.cont->id0 = index_to_map_pos_x(tile_index(original));
175 buf->data.cont->id1 = index_to_map_pos_y(tile_index(original));
176
178 /* ---------- */
179
180 players_iterate(pplayer) {
181 city_list_iterate(pplayer->cities, pcity) {
182 fc_snprintf(cbuf , sizeof(cbuf), "%s (%d)", city_name_get(pcity),
184
186 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
187
191 }
192
193 buf = create_iconlabel(logo, pwindow->dst, pstr,
195
199 }
200
201 buf->string_utf8->style &= ~SF_CENTER;
202 buf->string_utf8->fgcol = *(get_player_color(tileset, city_owner(pcity))->color);
203 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
204
205 buf->data.city = pcity;
206
209
211
212 area.w = MAX(area.w, buf->size.w);
213 area.h += buf->size.h;
214
215 if (n > 19) {
217 }
218
219 n++;
222
227
228
229 /* ---------- */
230 if (n > 20) {
233
234 n = units_h;
235 area.w += n;
236
237 units_h = 20 * buf->size.h + adj_size(2);
238
239 } else {
240 units_h = area.h;
241 }
242
243 /* ---------- */
244
245 area.h = units_h;
246
247 resize_window(pwindow , NULL, NULL,
248 (pwindow->size.w - pwindow->area.w) + area.w,
249 (pwindow->size.h - pwindow->area.h) + area.h);
250
251 area = pwindow->area;
252
253 if (!mouse) {
254 window_x = adj_size(10);
255 window_y = (main_window_height() - pwindow->size.h) / 2;
256 } else {
257 window_x = (main_data.event.motion.x + pwindow->size.w + adj_size(10) < main_window_width()) ?
258 (main_data.event.motion.x + adj_size(10)) :
259 (main_window_width() - pwindow->size.w - adj_size(10));
260 window_y = (main_data.event.motion.y - adj_size(2) + pwindow->size.h < main_window_height()) ?
261 (main_data.event.motion.y - adj_size(2)) :
262 (main_window_height() - pwindow->size.h - adj_size(10));
263 }
264
266
267 w = area.w;
268
269 if (find_city_dlg->scroll) {
270 w -= n;
271 }
272
273 /* exit button */
274 buf = pwindow->prev;
275
276 buf->size.x = area.x + area.w - buf->size.w - 1;
277 buf->size.y = pwindow->size.y + adj_size(2);
278
279 /* cities */
280 buf = buf->prev;
281 setup_vertical_widgets_position(1, area.x, area.y, w, 0,
283 buf);
284
285 if (find_city_dlg->scroll) {
287 area.x + area.w, area.y,
288 area.h, TRUE);
289 }
290
291 /* -------------------- */
292 /* redraw */
294 widget_mark_dirty(pwindow);
295
296 flush_dirty();
297}
#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