Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl2/spaceshipdlg.c Source File

Freeciv-3.3

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 "spaceshipdlg_g.h"
31#include "text.h"
32
33/* gui-sdl2 */
34#include "graphics.h"
35#include "gui_id.h"
36#include "gui_main.h"
37#include "gui_tilespec.h"
38#include "mapview.h"
39#include "widget.h"
40
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
50 static struct dialog_list *dialog_list = NULL;
51 static bool dialog_list_has_been_initialised = FALSE;
52
53/**********************************************************************/
56 static struct small_dialog *get_spaceship_dialog(struct player *pplayer)
57{
58 if (!dialog_list_has_been_initialised) {
59 dialog_list = dialog_list_new();
60 dialog_list_has_been_initialised = TRUE;
61 }
62
63 dialog_list_iterate(dialog_list, pdialog) {
64 if (pdialog->end_widget_list->data.player == pplayer) {
65 return pdialog;
66 }
67 } dialog_list_iterate_end;
68
69 return NULL;
70}
71
72/**********************************************************************/
75 static int space_dialog_window_callback(struct widget *pwindow)
76{
77 if (PRESSED_EVENT(main_data.event)) {
78 move_window_group(pwindow->private_data.small_dlg->begin_widget_list, pwindow);
79 }
80
81 return -1;
82}
83
84/**********************************************************************/
87 static int exit_space_dialog_callback(struct widget *pwidget)
88{
89 if (PRESSED_EVENT(main_data.event)) {
90 popdown_spaceship_dialog(pwidget->data.player);
91 flush_dirty();
92 }
93
94 return -1;
95}
96
97/**********************************************************************/
100 static int launch_spaceship_callback(struct widget *pwidget)
101{
102 if (PRESSED_EVENT(main_data.event)) {
103 send_packet_spaceship_launch(&client.conn);
104 }
105
106 return -1;
107}
108
109/**********************************************************************/
112 void 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;
123 if (victory_enabled(VC_SPACERACE)
124 && pplayer == client.conn.playing
125 && pplayer->spaceship.state == SSHIP_STARTED
126 && pplayer->spaceship.success_rate > 0.0) {
127 set_wstate(pbuf, FC_WS_NORMAL);
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);
138 widget_mark_dirty(spaceship->end_widget_list);
139
140 flush_dirty();
141}
142
143/**********************************************************************/
146 void 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];
154 SDL_Rect area;
155
156 spaceship = fc_calloc(1, sizeof(struct small_dialog));
157
158 fc_snprintf(cbuf, sizeof(cbuf), _("The %s Spaceship"),
159 nation_adjective_for_player(pplayer));
160 pstr = create_utf8_from_char_fonto(cbuf, FONTO_ATTENTION);
161 pstr->style |= TTF_STYLE_BOLD;
162
163 pwindow = create_window_skeleton(NULL, pstr, 0);
164
165 pwindow->action = space_dialog_window_callback;
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,
177 WF_WIDGET_HAS_INFO_LABEL
178 | WF_RESTORE_BACKGROUND);
179 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
180 FONTO_ATTENTION);
181 buf->data.player = pplayer;
182 buf->action = exit_space_dialog_callback;
183 set_wstate(buf, FC_WS_NORMAL);
184 buf->key = SDLK_ESCAPE;
185 area.w = MAX(area.w, (buf->size.w + adj_size(10)));
186
187 add_to_gui_list(ID_BUTTON, buf);
188
189 buf = create_themeicon_button_from_chars_fonto(current_theme->ok_icon,
190 pwindow->dst,
191 _("Launch"),
192 FONTO_ATTENTION, 0);
193
194 buf->action = launch_spaceship_callback;
195 area.w = MAX(area.w, buf->size.w);
196 area.h += buf->size.h + adj_size(20);
197 add_to_gui_list(ID_BUTTON, buf);
198
199 pstr = create_utf8_from_char_fonto(get_spaceship_descr(NULL),
200 FONTO_ATTENTION);
201 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
202 buf = create_iconlabel(NULL, pwindow->dst, pstr, WF_RESTORE_BACKGROUND);
203 area.w = MAX(area.w, buf->size.w);
204 area.h += buf->size.h + adj_size(20);
205 add_to_gui_list(ID_LABEL, buf);
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
237 dialog_list_prepend(dialog_list, spaceship);
238
239 refresh_spaceship_dialog(pplayer);
240 } else {
241 if (select_window_group_dialog(spaceship->begin_widget_list,
242 spaceship->end_widget_list)) {
243 widget_flush(spaceship->end_widget_list);
244 }
245 }
246}
247
248/**********************************************************************/
251 void popdown_spaceship_dialog(struct player *pplayer)
252{
253 struct small_dialog *spaceship;
254
255 if ((spaceship = get_spaceship_dialog(pplayer))) {
256 popdown_window_group_dialog(spaceship->begin_widget_list,
257 spaceship->end_widget_list);
258 dialog_list_remove(dialog_list, spaceship);
259 FC_FREE(spaceship);
260 }
261}
client
struct civclient client
Definition client_main.c:153
client_main.h
incite_cost
char * incite_cost
Definition comments.c:74
current_theme
QString current_theme
Definition fc_client.cpp:64
VC_SPACERACE
@ VC_SPACERACE
Definition fc_types.h:1251
fcintl.h
_
#define _(String)
Definition fcintl.h:67
game.h
flush_dirty
void flush_dirty(void)
Definition mapview.c:468
get_spaceship_dialog
static struct spaceship_dialog * get_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.c:103
popdown_spaceship_dialog
void popdown_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.c:160
dialog_list_iterate_end
#define dialog_list_iterate_end
Definition spaceshipdlg.c:73
dialog_list_iterate
#define dialog_list_iterate(dialoglist, pdialog)
Definition spaceshipdlg.c:71
dialog_list
static struct dialog_list * dialog_list
Definition spaceshipdlg.c:75
popup_spaceship_dialog
void popup_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.c:146
refresh_spaceship_dialog
void refresh_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.c:117
main_window_width
int main_window_width(void)
Definition graphics.c:685
main_data
struct sdl2_data main_data
Definition graphics.c:57
main_window_height
int main_window_height(void)
Definition graphics.c:693
ID_BUTTON
@ ID_BUTTON
Definition gui_id.h:29
ID_LABEL
@ ID_LABEL
Definition gui_id.h:27
ID_WINDOW
@ ID_WINDOW
Definition gui_id.h:30
adj_size
#define adj_size(size)
Definition gui_main.h:141
PRESSED_EVENT
#define PRESSED_EVENT(event)
Definition gui_main.h:71
copy_chars_to_utf8_str
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
FONTO_ATTENTION
@ FONTO_ATTENTION
Definition gui_string.h:67
create_utf8_from_char_fonto
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
dialog_list_has_been_initialised
static bool dialog_list_has_been_initialised
Definition spaceshipdlg.c:51
exit_space_dialog_callback
static int exit_space_dialog_callback(struct widget *pwidget)
Definition spaceshipdlg.c:87
space_dialog_window_callback
static int space_dialog_window_callback(struct widget *pwindow)
Definition spaceshipdlg.c:75
launch_spaceship_callback
static int launch_spaceship_callback(struct widget *pwidget)
Definition spaceshipdlg.c:100
add_to_gui_list
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
select_window_group_dialog
bool select_window_group_dialog(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:998
redraw_group
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
popdown_window_group_dialog
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
move_window_group
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1039
widget_set_position
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
FC_WS_NORMAL
@ FC_WS_NORMAL
Definition widget.h:96
widget_mark_dirty
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
WF_WIDGET_HAS_INFO_LABEL
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
create_themeicon_button_from_chars_fonto
#define create_themeicon_button_from_chars_fonto(icon_theme, pdest, char_string, fonto, flags)
Definition widget_button.h:36
create_themeicon
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
Definition widget_icon.c:212
create_iconlabel
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
Definition widget_label.c:215
resize_window
bool resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
Definition widget_window.c:255
create_window_skeleton
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
Definition widget_window.c:180
gui_id.h
gui_tilespec.h
widget.h
graphics.h
gui_main.h
mapview.h
log.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
nation.h
packets.h
send_packet_spaceship_launch
int send_packet_spaceship_launch(struct connection *pc)
Definition packets_gen.c:45638
MAX
#define MAX(x, y)
Definition shared.h:54
SSHIP_STARTED
@ SSHIP_STARTED
Definition spaceship.h:84
spaceshipdlg_g.h
speclist.h
civclient::conn
struct connection conn
Definition client_main.h:96
connection::playing
struct player * playing
Definition connection.h:151
player_spaceship::success_rate
double success_rate
Definition spaceship.h:115
player_spaceship::state
enum spaceship_state state
Definition spaceship.h:108
player
Definition player.h:249
player::spaceship
struct player_spaceship spaceship
Definition player.h:286
sdl2_data::event
SDL_Event event
Definition graphics.h:217
small_dialog
Definition widget.h:174
small_dialog::begin_widget_list
struct widget * begin_widget_list
Definition widget.h:175
small_dialog::end_widget_list
struct widget * end_widget_list
Definition widget.h:176
utf8_str
Definition gui_string.h:52
widget
Definition widget.h:112
widget::player
struct player * player
Definition widget.h:130
widget::prev
struct widget * prev
Definition widget.h:114
widget::small_dlg
struct small_dialog * small_dlg
Definition widget.h:138
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::action
int(* action)(struct widget *)
Definition widget.h:157
widget::area
SDL_Rect area
Definition widget.h:149
widget::size
SDL_Rect size
Definition widget.h:145
widget::private_data
union widget::@218 private_data
widget::data
union widget::@217 data
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
get_spaceship_descr
const char * get_spaceship_descr(struct player_spaceship *pship)
Definition text.c:1513
text.h
victory_enabled
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
victory.h