Freeciv-3.2
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 "nation.h"
25#include "packets.h"
26#include "victory.h"
27
28/* client */
29#include "client_main.h"
30#include "text.h"
31
32/* gui-sdl2 */
33#include "graphics.h"
34#include "gui_id.h"
35#include "gui_main.h"
36#include "gui_tilespec.h"
37#include "mapview.h"
38#include "widget.h"
39
40#include "spaceshipdlg.h"
41
42#define SPECLIST_TAG dialog
43#define SPECLIST_TYPE struct small_dialog
44#include "speclist.h"
45
46#define dialog_list_iterate(dialoglist, pdialog) \
47 TYPED_LIST_ITERATE(struct small_dialog, dialoglist, pdialog)
48#define dialog_list_iterate_end LIST_ITERATE_END
49
50static struct dialog_list *dialog_list = NULL;
52
53/**********************************************************************/
56static struct small_dialog *get_spaceship_dialog(struct player *pplayer)
57{
61 }
62
64 if (pdialog->end_widget_list->data.player == pplayer) {
65 return pdialog;
66 }
68
69 return NULL;
70}
71
72/**********************************************************************/
75static int space_dialog_window_callback(struct widget *pwindow)
76{
79 }
80
81 return -1;
82}
83
84/**********************************************************************/
87static int exit_space_dialog_callback(struct widget *pwidget)
88{
92 }
93
94 return -1;
95}
96
97/**********************************************************************/
100static int launch_spaceship_callback(struct widget *pwidget)
101{
104 }
105
106 return -1;
107}
108
109/**********************************************************************/
112void refresh_spaceship_dialog(struct player *pplayer)
113{
114 struct small_dialog *spaceship;
115 struct widget *pbuf;
116
117 if (!(spaceship = get_spaceship_dialog(pplayer))) {
118 return;
119 }
120
121 /* launch button */
122 pbuf = spaceship->end_widget_list->prev->prev;
124 && pplayer == client.conn.playing
125 && pplayer->spaceship.state == SSHIP_STARTED
126 && pplayer->spaceship.success_rate > 0.0) {
128 }
129
130 /* update text info */
131 pbuf = pbuf->prev;
132 copy_chars_to_utf8_str(pbuf->string_utf8,
133 get_spaceship_descr(&pplayer->spaceship));
134 /* ------------------------------------------ */
135
136 /* redraw */
137 redraw_group(spaceship->begin_widget_list, spaceship->end_widget_list, 0);
139
140 flush_dirty();
141}
142
143/**********************************************************************/
146void popup_spaceship_dialog(struct player *pplayer)
147{
148 struct small_dialog *spaceship;
149
150 if (!(spaceship = get_spaceship_dialog(pplayer))) {
151 struct widget *buf, *pwindow;
152 utf8_str *pstr;
153 char cbuf[128];
155
156 spaceship = fc_calloc(1, sizeof(struct small_dialog));
157
158 fc_snprintf(cbuf, sizeof(cbuf), _("The %s Spaceship"),
161 pstr->style |= TTF_STYLE_BOLD;
162
163 pwindow = create_window_skeleton(NULL, pstr, 0);
164
166 set_wstate(pwindow, FC_WS_NORMAL);
167 pwindow->data.player = pplayer;
168 pwindow->private_data.small_dlg = spaceship;
169 add_to_gui_list(ID_WINDOW, pwindow);
170 spaceship->end_widget_list = pwindow;
171
172 area = pwindow->area;
173
174 /* ---------- */
175 /* Create exit button */
176 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
179 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
181 buf->data.player = pplayer;
184 buf->key = SDLK_ESCAPE;
185 area.w = MAX(area.w, (buf->size.w + adj_size(10)));
186
188
190 pwindow->dst,
191 _("Launch"),
192 FONTO_ATTENTION, 0);
193
195 area.w = MAX(area.w, buf->size.w);
196 area.h += buf->size.h + adj_size(20);
198
201 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
203 area.w = MAX(area.w, buf->size.w);
204 area.h += buf->size.h + adj_size(20);
206
207 spaceship->begin_widget_list = buf;
208 /* -------------------------------------------------------- */
209
210 area.w = MAX(area.w, adj_size(300) - (pwindow->size.w - pwindow->area.w));
211
212 resize_window(pwindow, NULL, NULL,
213 (pwindow->size.w - pwindow->area.w) + area.w,
214 (pwindow->size.h - pwindow->area.h) + area.h);
215
216 area = pwindow->area;
217
218 widget_set_position(pwindow,
219 (main_window_width() - pwindow->size.w) / 2,
220 (main_window_height() - pwindow->size.h) / 2);
221
222 /* exit button */
223 buf = pwindow->prev;
224 buf->size.x = area.x + area.w - buf->size.w - 1;
225 buf->size.y = pwindow->size.y + adj_size(2);
226
227 /* launch button */
228 buf = buf->prev;
229 buf->size.x = area.x + (area.w - buf->size.w) / 2;
230 buf->size.y = area.y + area.h - buf->size.h - adj_size(7);
231
232 /* info label */
233 buf = buf->prev;
234 buf->size.x = area.x + (area.w - buf->size.w) / 2;
235 buf->size.y = area.y + adj_size(7);
236
238
240 } else {
242 spaceship->end_widget_list)) {
243 widget_flush(spaceship->end_widget_list);
244 }
245 }
246}
247
248/**********************************************************************/
251void popdown_spaceship_dialog(struct player *pplayer)
252{
253 struct small_dialog *spaceship;
254
255 if ((spaceship = get_spaceship_dialog(pplayer))) {
257 spaceship->end_widget_list);
259 FC_FREE(spaceship);
260 }
261}
struct civclient client
char * incite_cost
Definition comments.c:75
QString current_theme
Definition fc_client.cpp:65
@ VC_SPACERACE
Definition fc_types.h:1271
#define _(String)
Definition fcintl.h:67
void flush_dirty(void)
Definition mapview.c:468
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
@ ID_BUTTON
Definition gui_id.h:29
@ ID_LABEL
Definition gui_id.h:27
@ 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
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
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)
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
bool select_window_group_dialog(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:998
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
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)
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_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
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:151
double success_rate
Definition spaceship.h:115
enum spaceship_state state
Definition spaceship.h:108
struct player_spaceship spaceship
Definition player.h:284
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::@194 data
struct player * player
Definition widget.h:130
struct widget * prev
Definition widget.h:114
struct small_dialog * small_dlg
Definition widget.h:138
struct gui_layer * dst
Definition widget.h:116
int(* action)(struct widget *)
Definition widget.h:157
union widget::@195 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:974
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * get_spaceship_descr(struct player_spaceship *pship)
Definition text.c:1500
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26