Freeciv-3.3
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#include "pages_g.h"
29
30/* gui-sdl3 */
31#include "chatline.h"
32#include "colors.h"
33#include "connectdlg.h"
34#include "graphics.h"
35#include "gui_id.h"
36#include "gui_tilespec.h"
37#include "mapctrl.h"
38#include "mapview.h"
39#include "menu.h"
40#include "messagewin.h"
41#include "optiondlg.h"
42#include "themespec.h"
43#include "widget.h"
44
45
47
48/**************************************************************************
49 MAIN PAGE
50**************************************************************************/
51static struct small_dialog *start_menu = NULL;
52
53static void popdown_start_menu(void);
54
55/**********************************************************************/
58static int start_new_game_callback(struct widget *pwidget)
59{
62 if (!is_server_running()) {
64
65 /* Saved settings are sent in client/options.c
66 * resend_desired_settable_options() */
67 }
68 }
69
70 return -1;
71}
72
73/**********************************************************************/
76static int load_game_callback(struct widget *pwidget)
77{
80 }
81
82 return -1;
83}
84
85/**********************************************************************/
88static int join_game_callback(struct widget *pwidget)
89{
92 }
93
94 return -1;
95}
96
97/**********************************************************************/
100static int servers_callback(struct widget *pwidget)
101{
103 bool lan_scan = (pwidget->id != ID_JOIN_META_GAME);
104
107 }
108
109 return -1;
110}
111
112/**********************************************************************/
115static int options_callback(struct widget *pwidget)
116{
118 queue_flush();
121 }
122
123 return -1;
124}
125
126/**********************************************************************/
129static int quit_callback(struct widget *pwidget)
130{
133 }
134
135 return 0;/* exit from main game loop */
136}
137
138/**********************************************************************/
141static 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;
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,
168
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,
182
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"),
196
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
206
207 /* Load Game */
208 pwidget = create_iconlabel_from_chars_fonto(NULL, pwindow->dst,
209 _("Load Game"),
212
213 pwidget->action = load_game_callback;
214 pwidget->string_utf8->style |= SF_CENTER;
215 set_wstate(pwidget, FC_WS_NORMAL);
216
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"),
228
229 pwidget->action = join_game_callback;
230 pwidget->string_utf8->style |= SF_CENTER;
231 set_wstate(pwidget, FC_WS_NORMAL);
232
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"),
244
245 pwidget->action = servers_callback;
246 pwidget->string_utf8->style |= SF_CENTER;
247 set_wstate(pwidget, FC_WS_NORMAL);
248
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"),
260
261 pwidget->action = servers_callback;
262 pwidget->string_utf8->style |= SF_CENTER;
263 set_wstate(pwidget, FC_WS_NORMAL);
264
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"),
276
277 pwidget->action = options_callback;
278 pwidget->string_utf8->style |= SF_CENTER;
279 set_wstate(pwidget, FC_WS_NORMAL);
280
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"),
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
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
335
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
347#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
348
350 if (rev_ver != NULL) {
351 char buffer[512];
352
353 fc_snprintf(buffer, sizeof(buffer), _("Commit: %s"), rev_ver);
355 }
356
358
360
361 flush_all();
362}
363
364/**********************************************************************/
376
377/**************************************************************************
378 PUBLIC FUNCTIONS
379**************************************************************************/
380
381/**********************************************************************/
386{
387 switch (old_page) {
388 case PAGE_MAIN:
390 break;
391 case PAGE_LOAD:
393 break;
394 case PAGE_NETWORK:
396 break;
397 case PAGE_START:
399 break;
400 case PAGE_GAME:
402 break;
403 default:
404 break;
405 }
406
407 old_page = page;
408
409 switch (page) {
410 case PAGE_MAIN:
412 break;
413 case PAGE_LOAD:
415 break;
416 case PAGE_NETWORK:
418 break;
419 case PAGE_START:
421 break;
422 case PAGE_GAME:
430 menus_update();
431 break;
432 default:
433 break;
434 }
435}
436
437/**********************************************************************/
442void set_rulesets(int num_rulesets, char **rulesets)
443{
444 /* PORTME */
445}
446
447/**********************************************************************/
451{
452 return old_page;
453}
454
455/**********************************************************************/
459{
461}
void chat_welcome_message(bool gui_has_copying_mitem)
char * incite_cost
Definition comments.c:76
bool is_server_running(void)
bool client_start_server(void)
struct unit_list * get_units_in_focus(void)
Definition control.c:177
void unit_focus_update(void)
Definition control.c:789
#define _(String)
Definition fcintl.h:67
void close_connection_dialog(void)
Definition connectdlg.c:52
const char * client_string
Definition gui_main.c:106
void flush_dirty(void)
Definition mapview.c:468
void update_info_label(void)
Definition mapview.c:138
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:275
void meswin_dialog_popup(bool raise)
Definition messagewin.c:417
void set_rulesets(int num_rulesets, char **rulesets)
Definition pages.c:3586
enum client_pages get_current_client_page(void)
Definition pages.c:3345
static struct server_scan_timer_data lan_scan
Definition pages.c:87
void real_set_client_page(enum client_pages new_page)
Definition pages.c:3353
static void start_new_game_callback(GtkWidget *w, gpointer data)
Definition pages.c:102
void update_start_page(void)
Definition pages.c:1675
bool popdown_conn_list_dialog(void)
Definition chatline.c:876
void popdown_load_game_dialog(void)
Definition chatline.c:102
#define set_output_window_text(_pstr_)
Definition chatline.h:31
void popup_join_game_dialog(void)
Definition connectdlg.c:539
void popup_connection_dialog(bool lan_scan)
Definition connectdlg.c:219
int main_window_width(void)
Definition graphics.c:685
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:865
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1381
struct sdl2_data main_data
Definition graphics.c:57
int main_window_height(void)
Definition graphics.c:693
#define FREESURFACE(ptr)
Definition graphics.h:322
@ ID_JOIN_META_GAME
Definition gui_id.h:43
@ ID_CLIENT_OPTIONS_BUTTON
Definition gui_id.h:44
@ ID_JOIN_GAME
Definition gui_id.h:42
@ ID_QUIT
Definition gui_id.h:45
@ ID_LOAD_GAME
Definition gui_id.h:41
@ ID_LABEL
Definition gui_id.h:27
@ ID_WINDOW
Definition gui_id.h:30
@ ID_START_NEW_GAME
Definition gui_id.h:40
#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_HEADING
Definition gui_string.h:69
@ FONTO_ATTENTION
Definition gui_string.h:67
void draw_intro_gfx(void)
void enable_main_widgets(void)
Definition mapctrl.c:2180
void close_game_page(void)
Definition mapctrl.c:2021
void show_game_page(void)
Definition mapctrl.c:1958
void refresh_overview(void)
Definition mapview.c:1124
void queue_flush(void)
Definition mapview.c:152
void flush_all(void)
Definition mapview.c:201
void popup_optiondlg(void)
Definition optiondlg.c:1432
static int join_game_callback(struct widget *pwidget)
Definition pages.c:88
static int quit_callback(struct widget *pwidget)
Definition pages.c:129
static struct small_dialog * start_menu
Definition pages.c:51
static enum client_pages old_page
Definition pages.c:46
static void popdown_start_menu(void)
Definition pages.c:367
static int options_callback(struct widget *pwidget)
Definition pages.c:115
static void show_main_page(void)
Definition pages.c:141
static int load_game_callback(struct widget *pwidget)
Definition pages.c:76
static int servers_callback(struct widget *pwidget)
Definition pages.c:100
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
@ BACKGROUND_STARTMENU
struct theme * active_theme
Definition themespec.c:154
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
void group_set_area(struct widget *begin_group_widget_list, struct widget *end_group_widget_list, SDL_Rect area)
Definition widget.c:953
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
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
@ FC_WS_NORMAL
Definition widget.h:96
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
@ WF_FREE_DATA
Definition widget.h:78
@ WF_SELECT_WITHOUT_BAR
Definition widget.h:89
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
#define create_iconlabel_from_chars_fonto(picon, pdest, chars, fonto, 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)
void conn_list_dialog_update(void)
void update_turn_done_button_state(void)
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
void menus_update(void)
#define MAX(x, y)
Definition shared.h:54
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
Uint8 style
Definition gui_string.h:53
SDL_Keycode key
Definition widget.h:153
struct widget * prev
Definition widget.h:114
utf8_str * string_utf8
Definition widget.h:121
int(* action)(struct widget *)
Definition widget.h:157
SDL_Rect area
Definition widget.h:149
Uint16 id
Definition widget.h:155
SDL_Rect size
Definition widget.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void set_client_page(enum client_pages page)
const char * fc_git_revision(void)
Definition version.c:75
const char * unstable_message(void)
Definition version.c:160