2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file intro_gui.cpp The main menu GUI. */
13 #include "window_gui.h"
14 #include "textbuf_gui.h"
15 #include "network/network.h"
17 #include "network/network_gui.h"
18 #include "network/network_content.h"
19 #include "landscape_type.h"
20 #include "strings_func.h"
22 #include "ai/ai_gui.hpp"
24 #include "core/geometry_func.hpp"
27 #include "highscore.h"
29 #include "widgets/intro_widget.h"
31 #include "table/strings.h"
32 #include "table/sprites.h"
34 #include "safeguards.h"
36 struct SelectGameWindow
: public Window
{
38 SelectGameWindow(WindowDesc
*desc
) : Window(desc
)
40 this->CreateNestedTree();
41 this->FinishInitNested(0);
42 this->OnInvalidateData();
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 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
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 void OnInit() override
61 bool missing_sprites
= _missing_extra_graphics
> 0 && !IsReleasedVersion();
62 this->GetWidget
<NWidgetStacked
>(WID_SGI_BASESET_SELECTION
)->SetDisplayedPlane(missing_sprites
? 0 : SZSP_NONE
);
64 bool missing_lang
= _current_language
->missing
>= _settings_client
.gui
.missing_strings_threshold
&& !IsReleasedVersion();
65 this->GetWidget
<NWidgetStacked
>(WID_SGI_TRANSLATION_SELECTION
)->SetDisplayedPlane(missing_lang
? 0 : SZSP_NONE
);
68 void DrawWidget(const Rect
&r
, int widget
) const override
72 SetDParam(0, _missing_extra_graphics
);
73 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_INTRO_BASESET
, TC_FROMSTRING
, SA_CENTER
);
76 case WID_SGI_TRANSLATION
:
77 SetDParam(0, _current_language
->missing
);
78 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_INTRO_TRANSLATION
, TC_FROMSTRING
, SA_CENTER
);
83 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
88 SetDParam(0, _missing_extra_graphics
);
89 str
= STR_INTRO_BASESET
;
92 case WID_SGI_TRANSLATION
:
93 SetDParam(0, _current_language
->missing
);
94 str
= STR_INTRO_TRANSLATION
;
99 int height
= GetStringHeight(str
, size
->width
);
100 if (height
> 3 * FONT_HEIGHT_NORMAL
) {
101 /* Don't let the window become too high. */
102 Dimension textdim
= GetStringBoundingBox(str
);
104 textdim
.width
-= textdim
.width
/ 2;
105 *size
= maxdim(*size
, textdim
);
107 size
->height
= height
+ padding
.height
;
112 void OnClick(Point pt
, int widget
, int click_count
) override
114 /* Do not create a network server when you (just) have closed one of the game
115 * creation/load windows for the network server. */
116 if (IsInsideMM(widget
, WID_SGI_GENERATE_GAME
, WID_SGI_EDIT_SCENARIO
+ 1)) _is_network_server
= false;
119 case WID_SGI_GENERATE_GAME
:
121 StartNewGameWithoutGUI(GENERATE_NEW_SEED
);
123 ShowGenerateLandscape();
127 case WID_SGI_LOAD_GAME
: ShowSaveLoadDialog(FT_SAVEGAME
, SLO_LOAD
); break;
128 case WID_SGI_PLAY_SCENARIO
: ShowSaveLoadDialog(FT_SCENARIO
, SLO_LOAD
); break;
129 case WID_SGI_PLAY_HEIGHTMAP
: ShowSaveLoadDialog(FT_HEIGHTMAP
,SLO_LOAD
); break;
130 case WID_SGI_EDIT_SCENARIO
: StartScenarioEditor(); break;
132 case WID_SGI_PLAY_NETWORK
:
133 if (!_network_available
) {
134 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE
, INVALID_STRING_ID
, WL_ERROR
);
136 ShowNetworkGameWindow();
140 case WID_SGI_TEMPERATE_LANDSCAPE
: case WID_SGI_ARCTIC_LANDSCAPE
:
141 case WID_SGI_TROPIC_LANDSCAPE
: case WID_SGI_TOYLAND_LANDSCAPE
:
142 SetNewLandscapeType(widget
- WID_SGI_TEMPERATE_LANDSCAPE
);
145 case WID_SGI_OPTIONS
: ShowGameOptions(); break;
146 case WID_SGI_HIGHSCORE
: ShowHighscoreTable(); break;
147 case WID_SGI_SETTINGS_OPTIONS
:ShowGameSettings(); break;
148 case WID_SGI_GRF_SETTINGS
: ShowNewGRFSettings(true, true, false, &_grfconfig_newgame
); break;
149 case WID_SGI_CONTENT_DOWNLOAD
:
150 if (!_network_available
) {
151 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE
, INVALID_STRING_ID
, WL_ERROR
);
153 ShowNetworkContentListWindow();
156 case WID_SGI_AI_SETTINGS
: ShowAIConfigWindow(); break;
157 case WID_SGI_EXIT
: HandleExitGameRequest(); break;
162 static const NWidgetPart _nested_select_game_widgets
[] = {
163 NWidget(WWT_CAPTION
, COLOUR_BROWN
), SetDataTip(STR_INTRO_CAPTION
, STR_NULL
),
164 NWidget(WWT_PANEL
, COLOUR_BROWN
),
165 NWidget(NWID_SPACER
), SetMinimalSize(0, 8),
167 /* 'generate game' and 'load game' buttons */
168 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
169 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_GENERATE_GAME
), SetMinimalSize(158, 12),
170 SetDataTip(STR_INTRO_NEW_GAME
, STR_INTRO_TOOLTIP_NEW_GAME
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
171 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_LOAD_GAME
), SetMinimalSize(158, 12),
172 SetDataTip(STR_INTRO_LOAD_GAME
, STR_INTRO_TOOLTIP_LOAD_GAME
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
175 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
177 /* 'play scenario' and 'play heightmap' buttons */
178 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
179 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_PLAY_SCENARIO
), SetMinimalSize(158, 12),
180 SetDataTip(STR_INTRO_PLAY_SCENARIO
, STR_INTRO_TOOLTIP_PLAY_SCENARIO
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
181 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_PLAY_HEIGHTMAP
), SetMinimalSize(158, 12),
182 SetDataTip(STR_INTRO_PLAY_HEIGHTMAP
, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
185 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
187 /* 'edit scenario' and 'play multiplayer' buttons */
188 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
189 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_EDIT_SCENARIO
), SetMinimalSize(158, 12),
190 SetDataTip(STR_INTRO_SCENARIO_EDITOR
, STR_INTRO_TOOLTIP_SCENARIO_EDITOR
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
191 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_PLAY_NETWORK
), SetMinimalSize(158, 12),
192 SetDataTip(STR_INTRO_MULTIPLAYER
, STR_INTRO_TOOLTIP_MULTIPLAYER
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
195 NWidget(NWID_SPACER
), SetMinimalSize(0, 7),
197 /* climate selection buttons */
198 NWidget(NWID_HORIZONTAL
),
199 NWidget(NWID_SPACER
), SetMinimalSize(10, 0), SetFill(1, 0),
200 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_TEMPERATE_LANDSCAPE
), SetMinimalSize(77, 55),
201 SetDataTip(SPR_SELECT_TEMPERATE
, STR_INTRO_TOOLTIP_TEMPERATE
),
202 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
203 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_ARCTIC_LANDSCAPE
), SetMinimalSize(77, 55),
204 SetDataTip(SPR_SELECT_SUB_ARCTIC
, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE
),
205 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
206 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_TROPIC_LANDSCAPE
), SetMinimalSize(77, 55),
207 SetDataTip(SPR_SELECT_SUB_TROPICAL
, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE
),
208 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
209 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_TOYLAND_LANDSCAPE
), SetMinimalSize(77, 55),
210 SetDataTip(SPR_SELECT_TOYLAND
, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE
),
211 NWidget(NWID_SPACER
), SetMinimalSize(10, 0), SetFill(1, 0),
214 NWidget(NWID_SPACER
), SetMinimalSize(0, 7),
215 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SGI_BASESET_SELECTION
),
216 NWidget(NWID_VERTICAL
),
217 NWidget(WWT_EMPTY
, COLOUR_ORANGE
, WID_SGI_BASESET
), SetMinimalSize(316, 12), SetFill(1, 0), SetPadding(0, 10, 7, 10),
220 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SGI_TRANSLATION_SELECTION
),
221 NWidget(NWID_VERTICAL
),
222 NWidget(WWT_EMPTY
, COLOUR_ORANGE
, WID_SGI_TRANSLATION
), SetMinimalSize(316, 12), SetFill(1, 0), SetPadding(0, 10, 7, 10),
226 /* 'game options' and 'advanced settings' buttons */
227 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
228 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_OPTIONS
), SetMinimalSize(158, 12),
229 SetDataTip(STR_INTRO_GAME_OPTIONS
, STR_INTRO_TOOLTIP_GAME_OPTIONS
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
230 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_SETTINGS_OPTIONS
), SetMinimalSize(158, 12),
231 SetDataTip(STR_INTRO_CONFIG_SETTINGS_TREE
, STR_INTRO_TOOLTIP_CONFIG_SETTINGS_TREE
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
234 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
236 /* 'script settings' and 'newgrf settings' buttons */
237 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
238 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_AI_SETTINGS
), SetMinimalSize(158, 12),
239 SetDataTip(STR_INTRO_SCRIPT_SETTINGS
, STR_INTRO_TOOLTIP_SCRIPT_SETTINGS
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
240 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_GRF_SETTINGS
), SetMinimalSize(158, 12),
241 SetDataTip(STR_INTRO_NEWGRF_SETTINGS
, STR_INTRO_TOOLTIP_NEWGRF_SETTINGS
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
244 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
246 /* 'online content' and 'highscore' buttons */
247 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
248 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_CONTENT_DOWNLOAD
), SetMinimalSize(158, 12),
249 SetDataTip(STR_INTRO_ONLINE_CONTENT
, STR_INTRO_TOOLTIP_ONLINE_CONTENT
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
250 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_HIGHSCORE
), SetMinimalSize(158, 12),
251 SetDataTip(STR_INTRO_HIGHSCORE
, STR_INTRO_TOOLTIP_HIGHSCORE
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
254 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
256 /* 'exit program' button */
257 NWidget(NWID_HORIZONTAL
),
258 NWidget(NWID_SPACER
), SetFill(1, 0),
259 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_EXIT
), SetMinimalSize(128, 12),
260 SetDataTip(STR_INTRO_QUIT
, STR_INTRO_TOOLTIP_QUIT
),
261 NWidget(NWID_SPACER
), SetFill(1, 0),
264 NWidget(NWID_SPACER
), SetMinimalSize(0, 8),
269 static WindowDesc
_select_game_desc(
270 WDP_CENTER
, nullptr, 0, 0,
271 WC_SELECT_GAME
, WC_NONE
,
273 _nested_select_game_widgets
, lengthof(_nested_select_game_widgets
)
276 void ShowSelectGameWindow()
278 new SelectGameWindow(&_select_game_desc
);
281 static void AskExitGameCallback(Window
*w
, bool confirmed
)
283 if (confirmed
) _exit_game
= true;
289 SetDParam(0, STR_OSNAME_WINDOWS
);
290 #elif defined(__APPLE__)
291 SetDParam(0, STR_OSNAME_OSX
);
292 #elif defined(__HAIKU__)
293 SetDParam(0, STR_OSNAME_HAIKU
);
294 #elif defined(__OS2__)
295 SetDParam(0, STR_OSNAME_OS2
);
297 SetDParam(0, STR_OSNAME_SUNOS
);
299 SetDParam(0, STR_OSNAME_UNIX
);
303 STR_QUIT_ARE_YOU_SURE_YOU_WANT_TO_EXIT_OPENTTD
,
310 static void AskExitToGameMenuCallback(Window
*w
, bool confirmed
)
313 _switch_mode
= SM_MENU
;
314 ClearErrorMessages();
318 void AskExitToGameMenu()
321 STR_ABANDON_GAME_CAPTION
,
322 (_game_mode
!= GM_EDITOR
) ? STR_ABANDON_GAME_QUERY
: STR_ABANDON_SCENARIO_QUERY
,
324 AskExitToGameMenuCallback