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)
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 ***********************************************************************/
15 #include <fc_config.h>
27 #include "connectdlg_common.h"
32 #include "connectdlg.h"
35 #include "gui_tilespec.h"
39 #include "messagewin.h"
40 #include "optiondlg.h"
41 #include "themespec.h"
46 static enum client_pages old_page
= PAGE_MAIN
;
48 /**************************************************************************
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
) {
62 if (is_server_running() || client_start_server()) {
63 /* saved settings are sent in client/options.c load_settable_options() */
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
);
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
);
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
);
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
) {
116 popdown_start_menu();
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};
143 struct widget
*pWidget
= NULL
, *pWindow
= NULL
;
144 SDL_Surface
*pBackground
;
148 const char *rev_ver
= fc_svn_revision();
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
);
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
,
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
);
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
,
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
);
191 add_to_gui_list(ID_LABEL
, pWidget
);
194 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Start New Game"),
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
);
206 add_to_gui_list(ID_START_NEW_GAME
, pWidget
);
209 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Load Game"),
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
);
224 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Join Game"),
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
);
239 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Join Pubserver"),
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
);
253 /* Join LAN Server */
254 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Join LAN Server"),
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
);
269 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Options"),
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
);
284 pWidget
= create_iconlabel_from_chars(NULL
, pWindow
->dst
, _("Quit"),
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
);
298 pStartMenu
->pBeginWidgetList
= pWidget
;
302 area
.w
+= adj_size(30);
305 area
.h
= MAX(area
.h
, h
* count
);
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
);
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));
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),
338 set_output_window_text(_("SDL2-client welcomes you..."));
341 set_output_window_text(beta_message());
342 #endif /* IS_BETA_VERSION */
344 rev_ver
= fc_git_revision();
345 if (rev_ver
!= NULL
) {
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
);
359 /**************************************************************************
361 **************************************************************************/
362 static void popdown_start_menu()
365 popdown_window_group_dialog(pStartMenu
->pBeginWidgetList
,
366 pStartMenu
->pEndWidgetList
);
372 /**************************************************************************
374 **************************************************************************/
376 /**************************************************************************
377 Sets the "page" that the client should show. See documentation in
379 **************************************************************************/
380 void real_set_client_page(enum client_pages page
)
384 popdown_start_menu();
387 popdown_load_game_dialog();
390 close_connection_dialog();
393 popdown_conn_list_dialog();
409 client_start_server();
412 popup_join_game_dialog();
415 conn_list_dialog_update();
419 enable_main_widgets();
422 update_unit_info_label(get_units_in_focus());
423 update_turn_done_button_state();
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
436 ****************************************************************************/
437 void set_rulesets(int num_rulesets
, char **rulesets
)
442 /**************************************************************************
443 Returns current client page
444 **************************************************************************/
445 enum client_pages
get_current_client_page(void)
450 /**************************************************************************
451 update the start page.
452 **************************************************************************/
453 void update_start_page(void)