Freeciv-3.1
Loading...
Searching...
No Matches
spaceshipdlg.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/* utility */
19#include "fcintl.h"
20#include "log.h"
21
22/* common */
23#include "game.h"
24#include "packets.h"
25#include "victory.h"
26
27/* client */
28#include "client_main.h"
29#include "text.h"
30
31/* gui-sdl2 */
32#include "graphics.h"
33#include "gui_id.h"
34#include "gui_main.h"
35#include "gui_tilespec.h"
36#include "mapview.h"
37#include "widget.h"
38
39#include "spaceshipdlg.h"
40
41#define SPECLIST_TAG dialog
42#define SPECLIST_TYPE struct small_dialog
43#include "speclist.h"
44
45#define dialog_list_iterate(dialoglist, pdialog) \
46 TYPED_LIST_ITERATE(struct small_dialog, dialoglist, pdialog)
47#define dialog_list_iterate_end LIST_ITERATE_END
48
49static struct dialog_list *dialog_list = NULL;
51
52/**********************************************************************/
55static struct small_dialog *get_spaceship_dialog(struct player *pplayer)
56{
58 dialog_list = dialog_list_new();
60 }
61
63 if (pdialog->end_widget_list->data.player == pplayer) {
64 return pdialog;
65 }
67
68 return NULL;
69}
70
71/**********************************************************************/
74static int space_dialog_window_callback(struct widget *pwindow)
75{
78 }
79
80 return -1;
81}
82
83/**********************************************************************/
86static int exit_space_dialog_callback(struct widget *pwidget)
87{
91 }
92
93 return -1;
94}
95
96/**********************************************************************/
99static int launch_spaceship_callback(struct widget *pwidget)
100{
103 }
104
105 return -1;
106}
107
108/**********************************************************************/
111void refresh_spaceship_dialog(struct player *pplayer)
112{
113 struct small_dialog *spaceship;
114 struct widget *pbuf;
115
116 if (!(spaceship = get_spaceship_dialog(pplayer))) {
117 return;
118 }
119
120 /* launch button */
121 pbuf = spaceship->end_widget_list->prev->prev;
123 && pplayer == client.conn.playing
124 && pplayer->spaceship.state == SSHIP_STARTED
125 && pplayer->spaceship.success_rate > 0.0) {
127 }
128
129 /* update text info */
130 pbuf = pbuf->prev;
131 copy_chars_to_utf8_str(pbuf->string_utf8,
132 get_spaceship_descr(&pplayer->spaceship));
133 /* ------------------------------------------ */
134
135 /* redraw */
136 redraw_group(spaceship->begin_widget_list, spaceship->end_widget_list, 0);
138
139 flush_dirty();
140}
141
142/**********************************************************************/
145void popup_spaceship_dialog(struct player *pplayer)
146{
147 struct small_dialog *spaceship;
148
149 if (!(spaceship = get_spaceship_dialog(pplayer))) {
150 struct widget *buf, *pwindow;
151 utf8_str *pstr;
152 char cbuf[128];
154
155 spaceship = fc_calloc(1, sizeof(struct small_dialog));
156
157 fc_snprintf(cbuf, sizeof(cbuf), _("The %s Spaceship"),
160 pstr->style |= TTF_STYLE_BOLD;
161
162 pwindow = create_window_skeleton(NULL, pstr, 0);
163
165 set_wstate(pwindow, FC_WS_NORMAL);
166 pwindow->data.player = pplayer;
167 pwindow->private_data.small_dlg = spaceship;
168 add_to_gui_list(ID_WINDOW, pwindow);
169 spaceship->end_widget_list = pwindow;
170
171 area = pwindow->area;
172
173 /* ---------- */
174 /* Create exit button */
175 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
178 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
180 buf->data.player = pplayer;
183 buf->key = SDLK_ESCAPE;
184 area.w = MAX(area.w, (buf->size.w + adj_size(10)));
185
187
189 pwindow->dst,
190 _("Launch"),
191 FONTO_ATTENTION, 0);
192
194 area.w = MAX(area.w, buf->size.w);
195 area.h += buf->size.h + adj_size(20);
197
200 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
202 area.w = MAX(area.w, buf->size.w);
203 area.h += buf->size.h + adj_size(20);
205
206 spaceship->begin_widget_list = buf;
207 /* -------------------------------------------------------- */
208
209 area.w = MAX(area.w, adj_size(300) - (pwindow->size.w - pwindow->area.w));
210
211 resize_window(pwindow, NULL, NULL,
212 (pwindow->size.w - pwindow->area.w) + area.w,
213 (pwindow->size.h - pwindow->area.h) + area.h);
214
215 area = pwindow->area;
216
217 widget_set_position(pwindow,
218 (main_window_width() - pwindow->size.w) / 2,
219 (main_window_height() - pwindow->size.h) / 2);
220
221 /* exit button */
222 buf = pwindow->prev;
223 buf->size.x = area.x + area.w - buf->size.w - 1;
224 buf->size.y = pwindow->size.y + adj_size(2);
225
226 /* launch button */
227 buf = buf->prev;
228 buf->size.x = area.x + (area.w - buf->size.w) / 2;
229 buf->size.y = area.y + area.h - buf->size.h - adj_size(7);
230
231 /* info label */
232 buf = buf->prev;
233 buf->size.x = area.x + (area.w - buf->size.w) / 2;
234 buf->size.y = area.y + adj_size(7);
235
237
239 } else {
241 spaceship->end_widget_list)) {
242 widget_flush(spaceship->end_widget_list);
243 }
244 }
245}
246
247/**********************************************************************/
250void popdown_spaceship_dialog(struct player *pplayer)
251{
252 struct small_dialog *spaceship;
253
254 if ((spaceship = get_spaceship_dialog(pplayer))) {
256 spaceship->end_widget_list);
257 dialog_list_remove(dialog_list, spaceship);
258 FC_FREE(spaceship);
259 }
260}
struct civclient client
QString current_theme
Definition fc_client.cpp:65
@ VC_SPACERACE
Definition fc_types.h:1123
#define _(String)
Definition fcintl.h:67
void flush_dirty(void)
Definition mapview.c:450
static struct spaceship_dialog * get_spaceship_dialog(struct player *pplayer)
void popdown_spaceship_dialog(struct player *pplayer)
#define dialog_list_iterate_end
#define dialog_list_iterate(dialoglist, pdialog)
static struct dialog_list * dialog_list
void popup_spaceship_dialog(struct player *pplayer)
void refresh_spaceship_dialog(struct player *pplayer)
int main_window_width(void)
Definition graphics.c:685
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
static bool dialog_list_has_been_initialised
static int exit_space_dialog_callback(struct widget *pwidget)
static int space_dialog_window_callback(struct widget *pwindow)
static int launch_spaceship_callback(struct widget *pwidget)
@ ID_BUTTON
Definition gui_id.h:29
@ ID_LABEL
Definition gui_id.h:27
@ ID_WINDOW
Definition gui_id.h:30
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
@ FONTO_ATTENTION
Definition gui_string.h:66
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:107
#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
int send_packet_spaceship_launch(struct connection *pc)
#define MAX(x, y)
Definition shared.h:54
@ SSHIP_STARTED
Definition spaceship.h:84
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:156
double success_rate
Definition spaceship.h:115
enum spaceship_state state
Definition spaceship.h:108
struct player_spaceship spaceship
Definition player.h:286
SDL_Event event
Definition graphics.h:217
struct widget * begin_widget_list
Definition widget.h:175
struct widget * end_widget_list
Definition widget.h:176
union widget::@214 data
struct player * player
Definition widget.h:130
struct gui_layer * dst
Definition widget.h:116
struct widget * prev
Definition widget.h:114
struct small_dialog * small_dlg
Definition widget.h:138
int(* action)(struct widget *)
Definition widget.h:157
struct container * cont
Definition widget.h:127
union widget::@215 private_data
SDL_Rect area
Definition widget.h:149
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
const char * get_spaceship_descr(struct player_spaceship *pship)
Definition text.c:1533
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:585
bool select_window_group_dialog(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:997
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
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
#define create_themeicon_button_from_chars_fonto(icon_theme, pdest, char_string, fonto, flags)
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)
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)