webperimental: Mountain vision bonus.
[freeciv.git] / client / gui-sdl2 / pages.c
blob6e95704d90e9bc0ca685d6c71b1c9d07a338b4b2
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "fcintl.h"
20 #include "log.h"
22 /* common */
23 #include "fc_types.h"
24 #include "version.h"
26 /* client */
27 #include "connectdlg_common.h"
29 /* gui-sdl2 */
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"
44 #include "pages.h"
46 static enum client_pages old_page = PAGE_MAIN;
48 /**************************************************************************
49 MAIN PAGE
50 **************************************************************************/
51 static struct SMALL_DLG *pStartMenu = NULL;
53 static void popdown_start_menu(void);
55 /**************************************************************************
56 User interacted with the Start New Game button.
57 **************************************************************************/
58 static int start_new_game_callback(struct widget *pWidget)
60 if (Main.event.button.button == SDL_BUTTON_LEFT) {
61 popdown_start_menu();
62 if (is_server_running() || client_start_server()) {
63 /* saved settings are sent in client/options.c load_settable_options() */
67 return -1;
70 /**************************************************************************
71 User interacted with the Load Game button.
72 **************************************************************************/
73 static int load_game_callback(struct widget *pWidget)
75 if (Main.event.button.button == SDL_BUTTON_LEFT) {
76 set_client_page(PAGE_LOAD);
79 return -1;
82 /**************************************************************************
83 User interacted with the Join Game button.
84 **************************************************************************/
85 static int join_game_callback(struct widget *pWidget)
87 if (Main.event.button.button == SDL_BUTTON_LEFT) {
88 set_client_page(PAGE_NETWORK);
91 return -1;
94 /**************************************************************************
95 User interacted with the Join Pubserver button - open connection dialog.
96 **************************************************************************/
97 static int servers_callback(struct widget *pWidget)
99 if (Main.event.button.button == SDL_BUTTON_LEFT) {
100 bool lan_scan = (pWidget->ID != ID_JOIN_META_GAME);
102 popdown_start_menu();
103 popup_connection_dialog(lan_scan);
106 return -1;
109 /**************************************************************************
110 User interacted with the Options button - open options dialog.
111 **************************************************************************/
112 static int options_callback(struct widget *pWidget)
114 if (Main.event.button.button == SDL_BUTTON_LEFT) {
115 queue_flush();
116 popdown_start_menu();
117 popup_optiondlg();
120 return -1;
123 /**************************************************************************
124 User interacted with the Quit button.
125 **************************************************************************/
126 static int quit_callback(struct widget *pWidget)
128 if (Main.event.button.button == SDL_BUTTON_LEFT) {
129 popdown_start_menu();
132 return 0;/* exit from main game loop */
135 /**************************************************************************
136 Update view to show main page.
137 **************************************************************************/
138 static void show_main_page(void)
140 SDL_Color bg_color = {255, 255, 255, 96};
141 SDL_Color line_color = {128, 128, 128, 255};
142 int count = 0;
143 struct widget *pWidget = NULL, *pWindow = NULL;
144 SDL_Surface *pBackground;
145 int h = 0;
146 SDL_Rect area;
147 char verbuf[200];
148 const char *rev_ver = fc_svn_revision();
150 /* create dialog */
151 pStartMenu = fc_calloc(1, sizeof(struct SMALL_DLG));
153 pWindow = create_window_skeleton(NULL, NULL, 0);
154 add_to_gui_list(ID_WINDOW, pWindow);
155 pStartMenu->pEndWidgetList = pWindow;
157 area = pWindow->area;
159 /* Freeciv version */
160 if (rev_ver == NULL) {
161 /* TRANS: Freeciv 2.4.0 */
162 fc_snprintf(verbuf, sizeof(verbuf), _("Freeciv %s"), VERSION_STRING);
163 } else {
164 /* TRANS: Freeciv 2.4.0 (r25000) */
165 fc_snprintf(verbuf, sizeof(verbuf), _("Freeciv %s (%s)"), VERSION_STRING, rev_ver);
167 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, verbuf,
168 adj_font(12),
169 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));
171 pWidget->string_utf8->style |= SF_CENTER | TTF_STYLE_BOLD;
173 area.w = MAX(area.w, pWidget->size.w);
174 h = MAX(h, pWidget->size.h);
175 count++;
177 add_to_gui_list(ID_LABEL, pWidget);
179 /* TRANS: gui-sdl2 client */
180 fc_snprintf(verbuf, sizeof(verbuf), _("%s client"), client_string);
181 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, verbuf,
182 adj_font(12),
183 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));
185 pWidget->string_utf8->style |= SF_CENTER | TTF_STYLE_BOLD;
187 area.w = MAX(area.w, pWidget->size.w);
188 h = MAX(h, pWidget->size.h);
189 count++;
191 add_to_gui_list(ID_LABEL, pWidget);
193 /* Start New Game */
194 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Start New Game"),
195 adj_font(14),
196 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));
198 pWidget->action = start_new_game_callback;
199 pWidget->string_utf8->style |= SF_CENTER;
200 set_wstate(pWidget, FC_WS_NORMAL);
202 area.w = MAX(area.w, pWidget->size.w);
203 h = MAX(h, pWidget->size.h);
204 count++;
206 add_to_gui_list(ID_START_NEW_GAME, pWidget);
208 /* Load Game */
209 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Load Game"),
210 adj_font(14),
211 (WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND));
213 pWidget->action = load_game_callback;
214 pWidget->string_utf8->style |= SF_CENTER;
215 set_wstate(pWidget, FC_WS_NORMAL);
217 add_to_gui_list(ID_LOAD_GAME, pWidget);
219 area.w = MAX(area.w, pWidget->size.w);
220 h = MAX(h, pWidget->size.h);
221 count++;
223 /* Join Game */
224 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join Game"),
225 adj_font(14),
226 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
228 pWidget->action = join_game_callback;
229 pWidget->string_utf8->style |= SF_CENTER;
230 set_wstate(pWidget, FC_WS_NORMAL);
232 add_to_gui_list(ID_JOIN_GAME, pWidget);
234 area.w = MAX(area.w, pWidget->size.w);
235 h = MAX(h, pWidget->size.h);
236 count++;
238 /* Join Pubserver */
239 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join Pubserver"),
240 adj_font(14),
241 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
243 pWidget->action = servers_callback;
244 pWidget->string_utf8->style |= SF_CENTER;
245 set_wstate(pWidget, FC_WS_NORMAL);
247 add_to_gui_list(ID_JOIN_META_GAME, pWidget);
249 area.w = MAX(area.w, pWidget->size.w);
250 h = MAX(h, pWidget->size.h);
251 count++;
253 /* Join LAN Server */
254 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join LAN Server"),
255 adj_font(14),
256 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
258 pWidget->action = servers_callback;
259 pWidget->string_utf8->style |= SF_CENTER;
260 set_wstate(pWidget, FC_WS_NORMAL);
262 add_to_gui_list(ID_JOIN_GAME, pWidget);
264 area.w = MAX(area.w, pWidget->size.w);
265 h = MAX(h, pWidget->size.h);
266 count++;
268 /* Options */
269 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Options"),
270 adj_font(14),
271 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
273 pWidget->action = options_callback;
274 pWidget->string_utf8->style |= SF_CENTER;
275 set_wstate(pWidget, FC_WS_NORMAL);
277 add_to_gui_list(ID_CLIENT_OPTIONS_BUTTON, pWidget);
279 area.w = MAX(area.w, pWidget->size.w);
280 h = MAX(h, pWidget->size.h);
281 count++;
283 /* Quit */
284 pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Quit"),
285 adj_font(14),
286 WF_SELECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
288 pWidget->action = quit_callback;
289 pWidget->string_utf8->style |= SF_CENTER;
290 pWidget->key = SDLK_ESCAPE;
291 set_wstate(pWidget, FC_WS_NORMAL);
292 add_to_gui_list(ID_QUIT, pWidget);
294 area.w = MAX(area.w, pWidget->size.w);
295 h = MAX(h, pWidget->size.h);
296 count++;
298 pStartMenu->pBeginWidgetList = pWidget;
300 /* ------*/
302 area.w += adj_size(30);
303 h += adj_size(6);
305 area.h = MAX(area.h, h * count);
307 /* ------*/
309 pBackground = theme_get_background(theme, BACKGROUND_STARTMENU);
310 if (resize_window(pWindow, pBackground, NULL,
311 (pWindow->size.w - pWindow->area.w) + area.w,
312 (pWindow->size.h - pWindow->area.h) + area.h)) {
313 FREESURFACE(pBackground);
316 area = pWindow->area;
318 group_set_area(pWidget, pWindow->prev, area);
320 setup_vertical_widgets_position(1, area.x, area.y, area.w, h, pWidget, pWindow->prev);
322 area.h = h * 2;
323 fill_rect_alpha(pWindow->theme, &area, &bg_color);
325 widget_set_position(pWindow,
326 (main_window_width() - pWindow->size.w) - adj_size(20),
327 (main_window_height() - pWindow->size.h) - adj_size(20));
329 draw_intro_gfx();
331 redraw_group(pStartMenu->pBeginWidgetList, pStartMenu->pEndWidgetList, FALSE);
333 create_line(pWindow->dst->surface,
334 area.x, area.y + (h * 2 - 1),
335 area.x + area.w - 1, area.y + (h * 2 - 1),
336 &line_color);
338 set_output_window_text(_("SDL2-client welcomes you..."));
340 #if IS_BETA_VERSION
341 set_output_window_text(beta_message());
342 #endif /* IS_BETA_VERSION */
344 rev_ver = fc_git_revision();
345 if (rev_ver != NULL) {
346 char buffer[512];
348 fc_snprintf(buffer, sizeof(buffer), _("Commit: %s"), rev_ver);
349 set_output_window_text(buffer);
352 chat_welcome_message(FALSE);
354 meswin_dialog_popup(TRUE);
356 flush_all();
359 /**************************************************************************
360 Close start menu
361 **************************************************************************/
362 static void popdown_start_menu()
364 if (pStartMenu) {
365 popdown_window_group_dialog(pStartMenu->pBeginWidgetList,
366 pStartMenu->pEndWidgetList);
367 FC_FREE(pStartMenu);
368 flush_dirty();
372 /**************************************************************************
373 PUBLIC FUNCTIONS
374 **************************************************************************/
376 /**************************************************************************
377 Sets the "page" that the client should show. See documentation in
378 pages_g.h.
379 **************************************************************************/
380 void real_set_client_page(enum client_pages page)
382 switch (old_page) {
383 case PAGE_MAIN:
384 popdown_start_menu();
385 break;
386 case PAGE_LOAD:
387 popdown_load_game_dialog();
388 break;
389 case PAGE_NETWORK:
390 close_connection_dialog();
391 break;
392 case PAGE_START:
393 popdown_conn_list_dialog();
394 break;
395 case PAGE_GAME:
396 close_game_page();
397 break;
398 default:
399 break;
402 old_page = page;
404 switch (page) {
405 case PAGE_MAIN:
406 show_main_page();
407 break;
408 case PAGE_LOAD:
409 client_start_server();
410 break;
411 case PAGE_NETWORK:
412 popup_join_game_dialog();
413 break;
414 case PAGE_START:
415 conn_list_dialog_update();
416 break;
417 case PAGE_GAME:
418 show_game_page();
419 enable_main_widgets();
420 update_info_label();
421 unit_focus_update();
422 update_unit_info_label(get_units_in_focus());
423 update_turn_done_button_state();
424 refresh_overview();
425 menus_update();
426 break;
427 default:
428 break;
432 /****************************************************************************
433 Set the list of available rulesets. The default ruleset should be
434 "default", and if the user changes this then set_ruleset() should be
435 called.
436 ****************************************************************************/
437 void set_rulesets(int num_rulesets, char **rulesets)
439 /* PORTME */
442 /**************************************************************************
443 Returns current client page
444 **************************************************************************/
445 enum client_pages get_current_client_page(void)
447 return old_page;
450 /**************************************************************************
451 update the start page.
452 **************************************************************************/
453 void update_start_page(void)
455 /* PORTME*/