Silence uninitialised variable warnings in SSE blitters
[openttd/fttd.git] / src / intro_gui.cpp
blob5d13058944071c6a3693c4ca4c2f8e92217b970b
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file intro_gui.cpp The main menu GUI. */
12 #include "stdafx.h"
13 #include "error.h"
14 #include "gui.h"
15 #include "window_gui.h"
16 #include "textbuf_gui.h"
17 #include "network/network.h"
18 #include "genworld.h"
19 #include "network/network_gui.h"
20 #include "network/network_content.h"
21 #include "landscape_type.h"
22 #include "strings_func.h"
23 #include "fios.h"
24 #include "ai/ai_gui.hpp"
25 #include "gfx_func.h"
26 #include "core/geometry_func.hpp"
27 #include "language.h"
28 #include "rev.h"
29 #include "highscore.h"
31 #include "widgets/intro_widget.h"
33 #include "table/strings.h"
34 #include "table/sprites.h"
36 struct SelectGameWindow : public Window {
38 SelectGameWindow(WindowDesc *desc) : Window(desc)
40 this->CreateNestedTree();
41 this->FinishInitNested(0);
42 this->OnInvalidateData();
45 /**
46 * Some data on this window has become invalid.
47 * @param data Information about the changed data.
48 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
50 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
52 if (!gui_scope) return;
53 this->SetWidgetLoweredState(WID_SGI_TEMPERATE_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
54 this->SetWidgetLoweredState(WID_SGI_ARCTIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_ARCTIC);
55 this->SetWidgetLoweredState(WID_SGI_TROPIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TROPIC);
56 this->SetWidgetLoweredState(WID_SGI_TOYLAND_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TOYLAND);
59 virtual void OnInit()
61 bool missing = _current_language->missing >= _settings_client.gui.missing_strings_threshold && !IsReleasedVersion();
62 this->GetWidget<NWidgetStacked>(WID_SGI_TRANSLATION_SELECTION)->SetDisplayedPlane(missing ? 0 : SZSP_NONE);
65 virtual void DrawWidget(const Rect &r, int widget) const
67 switch (widget) {
68 case WID_SGI_TRANSLATION:
69 SetDParam(0, _current_language->missing);
70 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_INTRO_TRANSLATION, TC_FROMSTRING, SA_CENTER);
71 break;
75 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
77 switch (widget) {
78 case WID_SGI_TRANSLATION: {
79 SetDParam(0, _current_language->missing);
80 int height = GetStringHeight(STR_INTRO_TRANSLATION, size->width);
81 if (height > 3 * FONT_HEIGHT_NORMAL) {
82 /* Don't let the window become too high. */
83 Dimension textdim = GetStringBoundingBox(STR_INTRO_TRANSLATION);
84 textdim.height *= 3;
85 textdim.width -= textdim.width / 2;
86 *size = maxdim(*size, textdim);
87 } else {
88 size->height = height + padding.height;
90 break;
95 virtual void OnClick(Point pt, int widget, int click_count)
97 #ifdef ENABLE_NETWORK
98 /* Do not create a network server when you (just) have closed one of the game
99 * creation/load windows for the network server. */
100 if (IsInsideMM(widget, WID_SGI_GENERATE_GAME, WID_SGI_EDIT_SCENARIO + 1)) _is_network_server = false;
101 #endif /* ENABLE_NETWORK */
103 switch (widget) {
104 case WID_SGI_GENERATE_GAME:
105 if (_ctrl_pressed) {
106 StartNewGameWithoutGUI(GENERATE_NEW_SEED);
107 } else {
108 ShowGenerateLandscape();
110 break;
112 case WID_SGI_LOAD_GAME: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
113 case WID_SGI_PLAY_SCENARIO: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
114 case WID_SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
115 case WID_SGI_EDIT_SCENARIO: StartScenarioEditor(); break;
117 case WID_SGI_PLAY_NETWORK:
118 if (!_network_available) {
119 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
120 } else {
121 ShowNetworkGameWindow();
123 break;
125 case WID_SGI_TEMPERATE_LANDSCAPE: case WID_SGI_ARCTIC_LANDSCAPE:
126 case WID_SGI_TROPIC_LANDSCAPE: case WID_SGI_TOYLAND_LANDSCAPE:
127 SetNewLandscapeType(widget - WID_SGI_TEMPERATE_LANDSCAPE);
128 break;
130 case WID_SGI_OPTIONS: ShowGameOptions(); break;
131 case WID_SGI_HIGHSCORE: ShowHighscoreTable(); break;
132 case WID_SGI_SETTINGS_OPTIONS:ShowGameSettings(); break;
133 case WID_SGI_GRF_SETTINGS: ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); break;
134 case WID_SGI_CONTENT_DOWNLOAD:
135 if (!_network_available) {
136 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
137 } else {
138 ShowNetworkContentListWindow();
140 break;
141 case WID_SGI_AI_SETTINGS: ShowAIConfigWindow(); break;
142 case WID_SGI_EXIT: HandleExitGameRequest(); break;
147 static const NWidgetPart _nested_select_game_widgets[] = {
148 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_INTRO_CAPTION, STR_NULL),
149 NWidget(WWT_PANEL, COLOUR_BROWN),
150 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
152 /* 'generate game' and 'load game' buttons */
153 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
154 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_GENERATE_GAME), SetMinimalSize(158, 12),
155 SetDataTip(STR_INTRO_NEW_GAME, STR_INTRO_TOOLTIP_NEW_GAME), SetPadding(0, 0, 0, 10), SetFill(1, 0),
156 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_LOAD_GAME), SetMinimalSize(158, 12),
157 SetDataTip(STR_INTRO_LOAD_GAME, STR_INTRO_TOOLTIP_LOAD_GAME), SetPadding(0, 10, 0, 0), SetFill(1, 0),
158 EndContainer(),
160 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
162 /* 'play scenario' and 'play heightmap' buttons */
163 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
164 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_PLAY_SCENARIO), SetMinimalSize(158, 12),
165 SetDataTip(STR_INTRO_PLAY_SCENARIO, STR_INTRO_TOOLTIP_PLAY_SCENARIO), SetPadding(0, 0, 0, 10), SetFill(1, 0),
166 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_PLAY_HEIGHTMAP), SetMinimalSize(158, 12),
167 SetDataTip(STR_INTRO_PLAY_HEIGHTMAP, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP), SetPadding(0, 10, 0, 0), SetFill(1, 0),
168 EndContainer(),
170 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
172 /* 'edit scenario' and 'play multiplayer' buttons */
173 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
174 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_EDIT_SCENARIO), SetMinimalSize(158, 12),
175 SetDataTip(STR_INTRO_SCENARIO_EDITOR, STR_INTRO_TOOLTIP_SCENARIO_EDITOR), SetPadding(0, 0, 0, 10), SetFill(1, 0),
176 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_PLAY_NETWORK), SetMinimalSize(158, 12),
177 SetDataTip(STR_INTRO_MULTIPLAYER, STR_INTRO_TOOLTIP_MULTIPLAYER), SetPadding(0, 10, 0, 0), SetFill(1, 0),
178 EndContainer(),
180 NWidget(NWID_SPACER), SetMinimalSize(0, 7),
182 /* climate selection buttons */
183 NWidget(NWID_HORIZONTAL),
184 NWidget(NWID_SPACER), SetMinimalSize(10, 0), SetFill(1, 0),
185 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_TEMPERATE_LANDSCAPE), SetMinimalSize(77, 55),
186 SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
187 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
188 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_ARCTIC_LANDSCAPE), SetMinimalSize(77, 55),
189 SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
190 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
191 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_TROPIC_LANDSCAPE), SetMinimalSize(77, 55),
192 SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
193 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
194 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_TOYLAND_LANDSCAPE), SetMinimalSize(77, 55),
195 SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
196 NWidget(NWID_SPACER), SetMinimalSize(10, 0), SetFill(1, 0),
197 EndContainer(),
199 NWidget(NWID_SPACER), SetMinimalSize(0, 7),
200 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SGI_TRANSLATION_SELECTION),
201 NWidget(NWID_VERTICAL),
202 NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_SGI_TRANSLATION), SetMinimalSize(316, 12), SetFill(1, 0), SetPadding(0, 10, 7, 10),
203 EndContainer(),
204 EndContainer(),
206 /* 'game options' and 'advanced settings' buttons */
207 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
208 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_OPTIONS), SetMinimalSize(158, 12),
209 SetDataTip(STR_INTRO_GAME_OPTIONS, STR_INTRO_TOOLTIP_GAME_OPTIONS), SetPadding(0, 0, 0, 10), SetFill(1, 0),
210 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_SETTINGS_OPTIONS), SetMinimalSize(158, 12),
211 SetDataTip(STR_INTRO_ADVANCED_SETTINGS, STR_INTRO_TOOLTIP_ADVANCED_SETTINGS), SetPadding(0, 10, 0, 0), SetFill(1, 0),
212 EndContainer(),
214 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
216 /* 'script settings' and 'newgrf settings' buttons */
217 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
218 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_AI_SETTINGS), SetMinimalSize(158, 12),
219 SetDataTip(STR_INTRO_SCRIPT_SETTINGS, STR_INTRO_TOOLTIP_SCRIPT_SETTINGS), SetPadding(0, 0, 0, 10), SetFill(1, 0),
220 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_GRF_SETTINGS), SetMinimalSize(158, 12),
221 SetDataTip(STR_INTRO_NEWGRF_SETTINGS, STR_INTRO_TOOLTIP_NEWGRF_SETTINGS), SetPadding(0, 10, 0, 0), SetFill(1, 0),
222 EndContainer(),
224 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
226 /* 'online content' and 'highscore' buttons */
227 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
228 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_CONTENT_DOWNLOAD), SetMinimalSize(158, 12),
229 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT), SetPadding(0, 0, 0, 10), SetFill(1, 0),
230 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_HIGHSCORE), SetMinimalSize(158, 12),
231 SetDataTip(STR_INTRO_HIGHSCORE, STR_INTRO_TOOLTIP_HIGHSCORE), SetPadding(0, 10, 0, 0), SetFill(1, 0),
232 EndContainer(),
234 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
236 /* 'exit program' button */
237 NWidget(NWID_HORIZONTAL),
238 NWidget(NWID_SPACER), SetFill(1, 0),
239 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_EXIT), SetMinimalSize(128, 12),
240 SetDataTip(STR_INTRO_QUIT, STR_INTRO_TOOLTIP_QUIT),
241 NWidget(NWID_SPACER), SetFill(1, 0),
242 EndContainer(),
244 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
246 EndContainer(),
249 static WindowDesc _select_game_desc(
250 WDP_CENTER, NULL, 0, 0,
251 WC_SELECT_GAME, WC_NONE,
253 _nested_select_game_widgets, lengthof(_nested_select_game_widgets)
256 void ShowSelectGameWindow()
258 new SelectGameWindow(&_select_game_desc);
261 static void AskExitGameCallback(Window *w, bool confirmed)
263 if (confirmed) _exit_game = true;
266 void AskExitGame()
268 #if defined(_WIN32)
269 SetDParam(0, STR_OSNAME_WINDOWS);
270 #elif defined(__APPLE__)
271 SetDParam(0, STR_OSNAME_OSX);
272 #elif defined(__BEOS__)
273 SetDParam(0, STR_OSNAME_BEOS);
274 #elif defined(__HAIKU__)
275 SetDParam(0, STR_OSNAME_HAIKU);
276 #elif defined(__MORPHOS__)
277 SetDParam(0, STR_OSNAME_MORPHOS);
278 #elif defined(__AMIGA__)
279 SetDParam(0, STR_OSNAME_AMIGAOS);
280 #elif defined(__OS2__)
281 SetDParam(0, STR_OSNAME_OS2);
282 #elif defined(SUNOS)
283 SetDParam(0, STR_OSNAME_SUNOS);
284 #elif defined(DOS)
285 SetDParam(0, STR_OSNAME_DOS);
286 #else
287 SetDParam(0, STR_OSNAME_UNIX);
288 #endif
289 ShowQuery(
290 STR_QUIT_CAPTION,
291 STR_QUIT_ARE_YOU_SURE_YOU_WANT_TO_EXIT_OPENTTD,
292 NULL,
293 AskExitGameCallback
298 static void AskExitToGameMenuCallback(Window *w, bool confirmed)
300 if (confirmed) {
301 _switch_mode = SM_MENU;
302 ClearErrorMessages();
306 void AskExitToGameMenu()
308 ShowQuery(
309 STR_ABANDON_GAME_CAPTION,
310 (_game_mode != GM_EDITOR) ? STR_ABANDON_GAME_QUERY : STR_ABANDON_SCENARIO_QUERY,
311 NULL,
312 AskExitToGameMenuCallback