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/>.
10 /** @file intro_gui.cpp The main menu GUI. */
15 #include "window_gui.h"
16 #include "textbuf_gui.h"
17 #include "network/network.h"
19 #include "network/network_gui.h"
20 #include "network/network_content.h"
21 #include "landscape_type.h"
22 #include "strings_func.h"
24 #include "ai/ai_gui.hpp"
26 #include "core/geometry_func.hpp"
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 (const WindowDesc
*desc
) : Window(desc
)
40 this->CreateNestedTree();
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 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
);
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 (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
72 SetDParam(0, _missing_extra_graphics
);
73 DrawStringMultiLine (dpi
, 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 (dpi
, r
.left
, r
.right
, r
.top
, r
.bottom
, STR_INTRO_TRANSLATION
, TC_FROMSTRING
, SA_CENTER
);
83 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
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 virtual void OnClick(Point pt
, int widget
, int click_count
)
114 #ifdef ENABLE_NETWORK
115 /* Do not create a network server when you (just) have closed one of the game
116 * creation/load windows for the network server. */
117 if (IsInsideMM(widget
, WID_SGI_GENERATE_GAME
, WID_SGI_EDIT_SCENARIO
+ 1)) _is_network_server
= false;
118 #endif /* ENABLE_NETWORK */
121 case WID_SGI_GENERATE_GAME
:
123 StartNewGameWithoutGUI(GENERATE_NEW_SEED
);
125 ShowGenerateLandscape();
129 case WID_SGI_LOAD_GAME
: ShowSaveLoadDialog (FT_SAVEGAME
); break;
130 case WID_SGI_PLAY_SCENARIO
: ShowSaveLoadDialog (FT_SCENARIO
); break;
131 case WID_SGI_PLAY_HEIGHTMAP
: ShowSaveLoadDialog (FT_HEIGHTMAP
); break;
132 case WID_SGI_EDIT_SCENARIO
: StartScenarioEditor(); break;
134 case WID_SGI_PLAY_NETWORK
:
135 if (!_network_available
) {
136 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE
, INVALID_STRING_ID
, WL_ERROR
);
138 ShowNetworkGameWindow();
142 case WID_SGI_TEMPERATE_LANDSCAPE
: case WID_SGI_ARCTIC_LANDSCAPE
:
143 case WID_SGI_TROPIC_LANDSCAPE
: case WID_SGI_TOYLAND_LANDSCAPE
:
144 SetNewLandscapeType(widget
- WID_SGI_TEMPERATE_LANDSCAPE
);
147 case WID_SGI_OPTIONS
: ShowGameOptions(); break;
148 case WID_SGI_HIGHSCORE
: ShowHighscoreTable(); break;
149 case WID_SGI_SETTINGS_OPTIONS
:ShowGameSettings(); break;
150 case WID_SGI_GRF_SETTINGS
: ShowNewGRFSettings(true, true, false, &_grfconfig_newgame
); break;
151 case WID_SGI_CONTENT_DOWNLOAD
:
152 if (!_network_available
) {
153 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE
, INVALID_STRING_ID
, WL_ERROR
);
155 ShowNetworkContentListWindow();
158 case WID_SGI_AI_SETTINGS
: ShowAIConfigWindow(); break;
159 case WID_SGI_EXIT
: HandleExitGameRequest(); break;
164 static const NWidgetPart _nested_select_game_widgets
[] = {
165 NWidget(WWT_CAPTION
, COLOUR_BROWN
), SetDataTip(STR_INTRO_CAPTION
, STR_NULL
),
166 NWidget(WWT_PANEL
, COLOUR_BROWN
),
167 NWidget(NWID_SPACER
), SetMinimalSize(0, 8),
169 /* 'generate game' and 'load game' buttons */
170 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
171 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_GENERATE_GAME
), SetMinimalSize(158, 12),
172 SetDataTip(STR_INTRO_NEW_GAME
, STR_INTRO_TOOLTIP_NEW_GAME
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
173 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_LOAD_GAME
), SetMinimalSize(158, 12),
174 SetDataTip(STR_INTRO_LOAD_GAME
, STR_INTRO_TOOLTIP_LOAD_GAME
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
177 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
179 /* 'play scenario' and 'play heightmap' buttons */
180 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
181 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_PLAY_SCENARIO
), SetMinimalSize(158, 12),
182 SetDataTip(STR_INTRO_PLAY_SCENARIO
, STR_INTRO_TOOLTIP_PLAY_SCENARIO
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
183 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_PLAY_HEIGHTMAP
), SetMinimalSize(158, 12),
184 SetDataTip(STR_INTRO_PLAY_HEIGHTMAP
, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
187 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
189 /* 'edit scenario' and 'play multiplayer' buttons */
190 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
191 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_EDIT_SCENARIO
), SetMinimalSize(158, 12),
192 SetDataTip(STR_INTRO_SCENARIO_EDITOR
, STR_INTRO_TOOLTIP_SCENARIO_EDITOR
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
193 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_PLAY_NETWORK
), SetMinimalSize(158, 12),
194 SetDataTip(STR_INTRO_MULTIPLAYER
, STR_INTRO_TOOLTIP_MULTIPLAYER
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
197 NWidget(NWID_SPACER
), SetMinimalSize(0, 7),
199 /* climate selection buttons */
200 NWidget(NWID_HORIZONTAL
),
201 NWidget(NWID_SPACER
), SetMinimalSize(10, 0), SetFill(1, 0),
202 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_TEMPERATE_LANDSCAPE
), SetMinimalSize(76, 54),
203 SetDataTip(SPR_SELECT_TEMPERATE
, STR_INTRO_TOOLTIP_TEMPERATE
),
204 NWidget(NWID_SPACER
), SetMinimalSize(4, 0), SetFill(1, 0),
205 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_ARCTIC_LANDSCAPE
), SetMinimalSize(76, 54),
206 SetDataTip(SPR_SELECT_SUB_ARCTIC
, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE
),
207 NWidget(NWID_SPACER
), SetMinimalSize(4, 0), SetFill(1, 0),
208 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_TROPIC_LANDSCAPE
), SetMinimalSize(76, 54),
209 SetDataTip(SPR_SELECT_SUB_TROPICAL
, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE
),
210 NWidget(NWID_SPACER
), SetMinimalSize(4, 0), SetFill(1, 0),
211 NWidget(WWT_IMGBTN_2
, COLOUR_ORANGE
, WID_SGI_TOYLAND_LANDSCAPE
), SetMinimalSize(76, 54),
212 SetDataTip(SPR_SELECT_TOYLAND
, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE
),
213 NWidget(NWID_SPACER
), SetMinimalSize(10, 0), SetFill(1, 0),
216 NWidget(NWID_SPACER
), SetMinimalSize(0, 7),
217 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SGI_BASESET_SELECTION
),
218 NWidget(NWID_VERTICAL
),
219 NWidget(WWT_EMPTY
, COLOUR_ORANGE
, WID_SGI_BASESET
), SetMinimalSize(316, 12), SetFill(1, 0), SetPadding(0, 10, 7, 10),
222 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SGI_TRANSLATION_SELECTION
),
223 NWidget(NWID_VERTICAL
),
224 NWidget(WWT_EMPTY
, COLOUR_ORANGE
, WID_SGI_TRANSLATION
), SetMinimalSize(316, 12), SetFill(1, 0), SetPadding(0, 10, 7, 10),
228 /* 'game options' and 'advanced settings' buttons */
229 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
230 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_OPTIONS
), SetMinimalSize(158, 12),
231 SetDataTip(STR_INTRO_GAME_OPTIONS
, STR_INTRO_TOOLTIP_GAME_OPTIONS
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
232 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_SETTINGS_OPTIONS
), SetMinimalSize(158, 12),
233 SetDataTip(STR_INTRO_CONFIG_SETTINGS_TREE
, STR_INTRO_TOOLTIP_CONFIG_SETTINGS_TREE
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
236 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
238 /* 'script settings' and 'newgrf settings' buttons */
239 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
240 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_AI_SETTINGS
), SetMinimalSize(158, 12),
241 SetDataTip(STR_INTRO_SCRIPT_SETTINGS
, STR_INTRO_TOOLTIP_SCRIPT_SETTINGS
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
242 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_GRF_SETTINGS
), SetMinimalSize(158, 12),
243 SetDataTip(STR_INTRO_NEWGRF_SETTINGS
, STR_INTRO_TOOLTIP_NEWGRF_SETTINGS
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
246 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
248 /* 'online content' and 'highscore' buttons */
249 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
250 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_CONTENT_DOWNLOAD
), SetMinimalSize(158, 12),
251 SetDataTip(STR_INTRO_ONLINE_CONTENT
, STR_INTRO_TOOLTIP_ONLINE_CONTENT
), SetPadding(0, 0, 0, 10), SetFill(1, 0),
252 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_HIGHSCORE
), SetMinimalSize(158, 12),
253 SetDataTip(STR_INTRO_HIGHSCORE
, STR_INTRO_TOOLTIP_HIGHSCORE
), SetPadding(0, 10, 0, 0), SetFill(1, 0),
256 NWidget(NWID_SPACER
), SetMinimalSize(0, 6),
258 /* 'exit program' button */
259 NWidget(NWID_HORIZONTAL
),
260 NWidget(NWID_SPACER
), SetFill(1, 0),
261 NWidget(WWT_PUSHTXTBTN
, COLOUR_ORANGE
, WID_SGI_EXIT
), SetMinimalSize(128, 12),
262 SetDataTip(STR_INTRO_QUIT
, STR_INTRO_TOOLTIP_QUIT
),
263 NWidget(NWID_SPACER
), SetFill(1, 0),
266 NWidget(NWID_SPACER
), SetMinimalSize(0, 8),
271 static const WindowDesc
_select_game_desc(
273 WC_SELECT_GAME
, WC_NONE
,
275 _nested_select_game_widgets
, lengthof(_nested_select_game_widgets
)
278 void ShowSelectGameWindow()
280 new SelectGameWindow(&_select_game_desc
);
283 static void AskExitGameCallback(Window
*w
, bool confirmed
)
285 if (confirmed
) _exit_game
= true;
291 SetDParam(0, STR_OSNAME_WINDOWS
);
292 #elif defined(__APPLE__)
293 SetDParam(0, STR_OSNAME_OSX
);
294 #elif defined(__BEOS__)
295 SetDParam(0, STR_OSNAME_BEOS
);
296 #elif defined(__HAIKU__)
297 SetDParam(0, STR_OSNAME_HAIKU
);
298 #elif defined(__MORPHOS__)
299 SetDParam(0, STR_OSNAME_MORPHOS
);
300 #elif defined(__AMIGA__)
301 SetDParam(0, STR_OSNAME_AMIGAOS
);
302 #elif defined(__OS2__)
303 SetDParam(0, STR_OSNAME_OS2
);
305 SetDParam(0, STR_OSNAME_SUNOS
);
307 SetDParam(0, STR_OSNAME_DOS
);
309 SetDParam(0, STR_OSNAME_UNIX
);
313 STR_QUIT_ARE_YOU_SURE_YOU_WANT_TO_EXIT_OPENTTD
,
320 static void AskExitToGameMenuCallback(Window
*w
, bool confirmed
)
323 _switch_mode
= SM_MENU
;
324 ClearErrorMessages();
328 void AskExitToGameMenu()
331 STR_ABANDON_GAME_CAPTION
,
332 (_game_mode
!= GM_EDITOR
) ? STR_ABANDON_GAME_QUERY
: STR_ABANDON_SCENARIO_QUERY
,
334 AskExitToGameMenuCallback