Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-sdl3/pages.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
pages.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2004 - The Freeciv Team
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 "fc_types.h"
24#include "version.h"
25
26/* client */
27#include "connectdlg_common.h"
28
29/* gui-sdl3 */
30#include "chatline.h"
31#include "colors.h"
32#include "connectdlg.h"
33#include "graphics.h"
34#include "gui_id.h"
35#include "gui_tilespec.h"
36#include "mapctrl.h"
37#include "mapview.h"
38#include "menu.h"
39#include "messagewin.h"
40#include "optiondlg.h"
41#include "themespec.h"
42#include "widget.h"
43
44#include "pages.h"
45
46 static enum client_pages old_page = PAGE_MAIN;
47
48/**************************************************************************
49 MAIN PAGE
50**************************************************************************/
51 static struct small_dialog *start_menu = NULL;
52
53static void popdown_start_menu(void);
54
55/**********************************************************************/
58 static int start_new_game_callback(struct widget *pwidget)
59{
60 if (PRESSED_EVENT(main_data.event)) {
61 popdown_start_menu();
62 if (!is_server_running()) {
63 client_start_server();
64
65 /* Saved settings are sent in client/options.c
66 * resend_desired_settable_options() */
67 }
68 }
69
70 return -1;
71}
72
73/**********************************************************************/
76 static int load_game_callback(struct widget *pwidget)
77{
78 if (PRESSED_EVENT(main_data.event)) {
79 set_client_page(PAGE_LOAD);
80 }
81
82 return -1;
83}
84
85/**********************************************************************/
88 static int join_game_callback(struct widget *pwidget)
89{
90 if (PRESSED_EVENT(main_data.event)) {
91 set_client_page(PAGE_NETWORK);
92 }
93
94 return -1;
95}
96
97/**********************************************************************/
100 static int servers_callback(struct widget *pwidget)
101{
102 if (PRESSED_EVENT(main_data.event)) {
103 bool lan_scan = (pwidget->id != ID_JOIN_META_GAME);
104
105 popdown_start_menu();
106 popup_connection_dialog(lan_scan);
107 }
108
109 return -1;
110}
111
112/**********************************************************************/
115 static int options_callback(struct widget *pwidget)
116{
117 if (PRESSED_EVENT(main_data.event)) {
118 queue_flush();
119 popdown_start_menu();
120 popup_optiondlg();
121 }
122
123 return -1;
124}
125
126/**********************************************************************/
129 static int quit_callback(struct widget *pwidget)
130{
131 if (PRESSED_EVENT(main_data.event)) {
132 popdown_start_menu();
133 }
134
135 return 0;/* exit from main game loop */
136}
137
138/**********************************************************************/
141 static void show_main_page(void)
142{
143 SDL_Color bg_color = {255, 255, 255, 96};
144 SDL_Color line_color = {128, 128, 128, 255};
145 int count = 0;
146 struct widget *pwidget = NULL, *pwindow = NULL;
147 SDL_Surface *background;
148 int h = 0;
149 SDL_Rect area;
150 char verbuf[200];
151 const char *rev_ver;
152
153 /* create dialog */
154 start_menu = fc_calloc(1, sizeof(struct small_dialog));
155
156 pwindow = create_window_skeleton(NULL, NULL, 0);
157 add_to_gui_list(ID_WINDOW, pwindow);
158 start_menu->end_widget_list = pwindow;
159
160 area = pwindow->area;
161
162 /* Freeciv version */
163 /* TRANS: Freeciv 3.2.0 */
164 fc_snprintf(verbuf, sizeof(verbuf), _("Freeciv %s"), VERSION_STRING);
165 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst, verbuf,
166 FONTO_ATTENTION,
167 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));
168
169 pwidget->string_utf8->style |= SF_CENTER | TTF_STYLE_BOLD;
170
171 area.w = MAX(area.w, pwidget->size.w);
172 h = MAX(h, pwidget->size.h);
173 count++;
174
175 add_to_gui_list(ID_LABEL, pwidget);
176
177 /* TRANS: gui-sdl3 client */
178 fc_snprintf(verbuf, sizeof(verbuf), _("%s client"), client_string);
179 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst, verbuf,
180 FONTO_ATTENTION,
181 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));
182
183 pwidget->string_utf8->style |= SF_CENTER | TTF_STYLE_BOLD;
184
185 area.w = MAX(area.w, pwidget->size.w);
186 h = MAX(h, pwidget->size.h);
187 count++;
188
189 add_to_gui_list(ID_LABEL, pwidget);
190
191 /* Start New Game */
192 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
193 _("Start New Game"),
194 FONTO_HEADING,
195 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));
196
197 pwidget->action = start_new_game_callback;
198 pwidget->string_utf8->style |= SF_CENTER;
199 set_wstate(pwidget, FC_WS_NORMAL);
200
201 area.w = MAX(area.w, pwidget->size.w);
202 h = MAX(h, pwidget->size.h);
203 count++;
204
205 add_to_gui_list(ID_START_NEW_GAME, pwidget);
206
207 /* Load Game */
208 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
209 _("Load Game"),
210 FONTO_HEADING,
211 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND));
212
213 pwidget->action = load_game_callback;
214 pwidget->string_utf8->style |= SF_CENTER;
215 set_wstate(pwidget, FC_WS_NORMAL);
216
217 add_to_gui_list(ID_LOAD_GAME, pwidget);
218
219 area.w = MAX(area.w, pwidget->size.w);
220 h = MAX(h, pwidget->size.h);
221 count++;
222
223 /* Join Game */
224 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
225 _("Join Game"),
226 FONTO_HEADING,
227 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
228
229 pwidget->action = join_game_callback;
230 pwidget->string_utf8->style |= SF_CENTER;
231 set_wstate(pwidget, FC_WS_NORMAL);
232
233 add_to_gui_list(ID_JOIN_GAME, pwidget);
234
235 area.w = MAX(area.w, pwidget->size.w);
236 h = MAX(h, pwidget->size.h);
237 count++;
238
239 /* Join Pubserver */
240 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
241 _("Join Pubserver"),
242 FONTO_HEADING,
243 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
244
245 pwidget->action = servers_callback;
246 pwidget->string_utf8->style |= SF_CENTER;
247 set_wstate(pwidget, FC_WS_NORMAL);
248
249 add_to_gui_list(ID_JOIN_META_GAME, pwidget);
250
251 area.w = MAX(area.w, pwidget->size.w);
252 h = MAX(h, pwidget->size.h);
253 count++;
254
255 /* Join LAN Server */
256 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
257 _("Join LAN Server"),
258 FONTO_HEADING,
259 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
260
261 pwidget->action = servers_callback;
262 pwidget->string_utf8->style |= SF_CENTER;
263 set_wstate(pwidget, FC_WS_NORMAL);
264
265 add_to_gui_list(ID_JOIN_GAME, pwidget);
266
267 area.w = MAX(area.w, pwidget->size.w);
268 h = MAX(h, pwidget->size.h);
269 count++;
270
271 /* Options */
272 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
273 _("Options"),
274 FONTO_HEADING,
275 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
276
277 pwidget->action = options_callback;
278 pwidget->string_utf8->style |= SF_CENTER;
279 set_wstate(pwidget, FC_WS_NORMAL);
280
281 add_to_gui_list(ID_CLIENT_OPTIONS_BUTTON, pwidget);
282
283 area.w = MAX(area.w, pwidget->size.w);
284 h = MAX(h, pwidget->size.h);
285 count++;
286
287 /* Quit */
288 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
289 _("Quit"),
290 FONTO_HEADING,
291 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
292
293 pwidget->action = quit_callback;
294 pwidget->string_utf8->style |= SF_CENTER;
295 pwidget->key = SDLK_ESCAPE;
296 set_wstate(pwidget, FC_WS_NORMAL);
297 add_to_gui_list(ID_QUIT, pwidget);
298
299 area.w = MAX(area.w, pwidget->size.w);
300 h = MAX(h, pwidget->size.h);
301 count++;
302
303 start_menu->begin_widget_list = pwidget;
304
305 /* ------*/
306
307 area.w += adj_size(30);
308 h += adj_size(6);
309
310 area.h = MAX(area.h, h * count);
311
312 /* ------*/
313
314 background = theme_get_background(active_theme, BACKGROUND_STARTMENU);
315 if (resize_window(pwindow, background, NULL,
316 (pwindow->size.w - pwindow->area.w) + area.w,
317 (pwindow->size.h - pwindow->area.h) + area.h)) {
318 FREESURFACE(background);
319 }
320
321 area = pwindow->area;
322
323 group_set_area(pwidget, pwindow->prev, area);
324
325 setup_vertical_widgets_position(1, area.x, area.y, area.w, h, pwidget, pwindow->prev);
326
327 area.h = h * 2;
328 fill_rect_alpha(pwindow->theme, &area, &bg_color);
329
330 widget_set_position(pwindow,
331 (main_window_width() - pwindow->size.w) - adj_size(20),
332 (main_window_height() - pwindow->size.h) - adj_size(20));
333
334 draw_intro_gfx();
335
336 redraw_group(start_menu->begin_widget_list, start_menu->end_widget_list, FALSE);
337
338 create_line(pwindow->dst->surface,
339 area.x, area.y + (h * 2 - 1),
340 area.x + area.w - 1, area.y + (h * 2 - 1),
341 &line_color);
342
343 set_output_window_text(_("SDL3-client welcomes you..."));
344
345#if IS_BETA_VERSION || IS_DEVEL_VERSION
346 set_output_window_text(unstable_message());
347#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
348
349 rev_ver = fc_git_revision();
350 if (rev_ver != NULL) {
351 char buffer[512];
352
353 fc_snprintf(buffer, sizeof(buffer), _("Commit: %s"), rev_ver);
354 set_output_window_text(buffer);
355 }
356
357 chat_welcome_message(FALSE);
358
359 meswin_dialog_popup(TRUE);
360
361 flush_all();
362}
363
364/**********************************************************************/
367 static void popdown_start_menu(void)
368{
369 if (start_menu) {
370 popdown_window_group_dialog(start_menu->begin_widget_list,
371 start_menu->end_widget_list);
372 FC_FREE(start_menu);
373 flush_dirty();
374 }
375}
376
377/**************************************************************************
378 PUBLIC FUNCTIONS
379**************************************************************************/
380
381/**********************************************************************/
385 void real_set_client_page(enum client_pages page)
386{
387 switch (old_page) {
388 case PAGE_MAIN:
389 popdown_start_menu();
390 break;
391 case PAGE_LOAD:
392 popdown_load_game_dialog();
393 break;
394 case PAGE_NETWORK:
395 close_connection_dialog();
396 break;
397 case PAGE_START:
398 popdown_conn_list_dialog();
399 break;
400 case PAGE_GAME:
401 close_game_page();
402 break;
403 default:
404 break;
405 }
406
407 old_page = page;
408
409 switch (page) {
410 case PAGE_MAIN:
411 show_main_page();
412 break;
413 case PAGE_LOAD:
414 client_start_server();
415 break;
416 case PAGE_NETWORK:
417 popup_join_game_dialog();
418 break;
419 case PAGE_START:
420 conn_list_dialog_update();
421 break;
422 case PAGE_GAME:
423 show_game_page();
424 enable_main_widgets();
425 update_info_label();
426 unit_focus_update();
427 update_unit_info_label(get_units_in_focus());
428 update_turn_done_button_state();
429 refresh_overview();
430 menus_update();
431 break;
432 default:
433 break;
434 }
435}
436
437/**********************************************************************/
442 void set_rulesets(int num_rulesets, char **rulesets)
443{
444 /* PORTME */
445}
446
447/**********************************************************************/
450 enum client_pages get_current_client_page(void)
451{
452 return old_page;
453}
454
455/**********************************************************************/
458 void update_start_page(void)
459{
460 conn_list_dialog_update();
461}
chat_welcome_message
void chat_welcome_message(bool gui_has_copying_mitem)
Definition chatline_common.c:177
incite_cost
char * incite_cost
Definition comments.c:74
is_server_running
bool is_server_running(void)
Definition connectdlg_common.c:124
client_start_server
bool client_start_server(void)
Definition connectdlg_common.c:224
connectdlg_common.h
get_units_in_focus
struct unit_list * get_units_in_focus(void)
Definition control.c:177
unit_focus_update
void unit_focus_update(void)
Definition control.c:771
fc_types.h
fcintl.h
_
#define _(String)
Definition fcintl.h:67
close_connection_dialog
void close_connection_dialog(void)
Definition connectdlg.c:52
client_string
const char * client_string
Definition gui_main.c:105
flush_dirty
void flush_dirty(void)
Definition mapview.c:468
update_info_label
void update_info_label(void)
Definition mapview.c:138
update_unit_info_label
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:275
meswin_dialog_popup
void meswin_dialog_popup(bool raise)
Definition messagewin.c:417
set_rulesets
void set_rulesets(int num_rulesets, char **rulesets)
Definition pages.c:3570
get_current_client_page
enum client_pages get_current_client_page(void)
Definition pages.c:3329
lan_scan
static struct server_scan_timer_data lan_scan
Definition pages.c:87
real_set_client_page
void real_set_client_page(enum client_pages new_page)
Definition pages.c:3337
start_new_game_callback
static void start_new_game_callback(GtkWidget *w, gpointer data)
Definition pages.c:102
update_start_page
void update_start_page(void)
Definition pages.c:1659
popdown_conn_list_dialog
bool popdown_conn_list_dialog(void)
Definition chatline.c:875
popdown_load_game_dialog
void popdown_load_game_dialog(void)
Definition chatline.c:101
set_output_window_text
#define set_output_window_text(_pstr_)
Definition chatline.h:31
popup_join_game_dialog
void popup_join_game_dialog(void)
Definition connectdlg.c:539
popup_connection_dialog
void popup_connection_dialog(bool lan_scan)
Definition connectdlg.c:219
main_window_width
int main_window_width(void)
Definition graphics.c:685
fill_rect_alpha
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:865
create_line
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1379
main_data
struct sdl2_data main_data
Definition graphics.c:57
main_window_height
int main_window_height(void)
Definition graphics.c:693
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
ID_JOIN_META_GAME
@ ID_JOIN_META_GAME
Definition gui_id.h:43
ID_CLIENT_OPTIONS_BUTTON
@ ID_CLIENT_OPTIONS_BUTTON
Definition gui_id.h:44
ID_JOIN_GAME
@ ID_JOIN_GAME
Definition gui_id.h:42
ID_QUIT
@ ID_QUIT
Definition gui_id.h:45
ID_LOAD_GAME
@ ID_LOAD_GAME
Definition gui_id.h:41
ID_LABEL
@ ID_LABEL
Definition gui_id.h:27
ID_WINDOW
@ ID_WINDOW
Definition gui_id.h:30
ID_START_NEW_GAME
@ ID_START_NEW_GAME
Definition gui_id.h:40
adj_size
#define adj_size(size)
Definition gui_main.h:141
PRESSED_EVENT
#define PRESSED_EVENT(event)
Definition gui_main.h:71
SF_CENTER
#define SF_CENTER
Definition gui_string.h:40
FONTO_HEADING
@ FONTO_HEADING
Definition gui_string.h:69
FONTO_ATTENTION
@ FONTO_ATTENTION
Definition gui_string.h:67
draw_intro_gfx
void draw_intro_gfx(void)
Definition gui_tilespec.c:484
enable_main_widgets
void enable_main_widgets(void)
Definition mapctrl.c:2180
close_game_page
void close_game_page(void)
Definition mapctrl.c:2021
show_game_page
void show_game_page(void)
Definition mapctrl.c:1958
refresh_overview
void refresh_overview(void)
Definition mapview.c:1119
queue_flush
void queue_flush(void)
Definition mapview.c:152
flush_all
void flush_all(void)
Definition mapview.c:201
popup_optiondlg
void popup_optiondlg(void)
Definition optiondlg.c:1432
join_game_callback
static int join_game_callback(struct widget *pwidget)
Definition pages.c:88
quit_callback
static int quit_callback(struct widget *pwidget)
Definition pages.c:129
start_menu
static struct small_dialog * start_menu
Definition pages.c:51
old_page
static enum client_pages old_page
Definition pages.c:46
popdown_start_menu
static void popdown_start_menu(void)
Definition pages.c:367
options_callback
static int options_callback(struct widget *pwidget)
Definition pages.c:115
show_main_page
static void show_main_page(void)
Definition pages.c:141
load_game_callback
static int load_game_callback(struct widget *pwidget)
Definition pages.c:76
servers_callback
static int servers_callback(struct widget *pwidget)
Definition pages.c:100
theme_get_background
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
Definition themebackgrounds.c:94
BACKGROUND_STARTMENU
@ BACKGROUND_STARTMENU
Definition themebackgrounds.h:47
active_theme
struct theme * active_theme
Definition themespec.c:154
add_to_gui_list
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
group_set_area
void group_set_area(struct widget *begin_group_widget_list, struct widget *end_group_widget_list, SDL_Rect area)
Definition widget.c:953
setup_vertical_widgets_position
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
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
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
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
WF_FREE_DATA
@ WF_FREE_DATA
Definition widget.h:78
WF_SELECT_WITHOUT_BAR
@ WF_SELECT_WITHOUT_BAR
Definition widget.h:89
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
create_iconlabel_from_chars_fonto
#define create_iconlabel_from_chars_fonto(picon, pdest, chars, fonto, flags)
Definition widget_label.h:20
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
themespec.h
widget.h
chatline.h
colors.h
connectdlg.h
graphics.h
mapctrl.h
mapview.h
menu.h
messagewin.h
optiondlg.h
pages.h
conn_list_dialog_update
void conn_list_dialog_update(void)
Definition update_queue.c:650
log.h
update_turn_done_button_state
void update_turn_done_button_state(void)
Definition mapctrl_common.c:648
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
menus_update
void menus_update(void)
Definition update_queue.c:562
set_client_page
void set_client_page(enum client_pages page)
Definition update_queue.c:496
MAX
#define MAX(x, y)
Definition shared.h:54
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::style
Uint8 style
Definition gui_string.h:53
widget
Definition widget.h:112
widget::key
SDL_Keycode key
Definition widget.h:153
widget::prev
struct widget * prev
Definition widget.h:114
widget::string_utf8
utf8_str * string_utf8
Definition widget.h:121
widget::action
int(* action)(struct widget *)
Definition widget.h:157
widget::area
SDL_Rect area
Definition widget.h:149
widget::id
Uint16 id
Definition widget.h:155
widget::size
SDL_Rect size
Definition widget.h:145
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc_git_revision
const char * fc_git_revision(void)
Definition version.c:75
unstable_message
const char * unstable_message(void)
Definition version.c:160
version.h