OpenTTD Source 20261112-master-gbcbec5e63f
genworld_gui.cpp
Go to the documentation of this file.
1/*
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "heightmap.h"
12#include "debug.h"
13#include "genworld.h"
14#include "network/network.h"
15#include "strings_func.h"
16#include "window_func.h"
17#include "textbuf_gui.h"
19#include "sound_func.h"
20#include "dropdown_type.h"
21#include "dropdown_func.h"
22#include "town.h"
24#include "core/random_func.hpp"
26#include "progress.h"
27#include "error.h"
28#include "newgrf_townname.h"
30#include "ai/ai_gui.hpp"
31#include "game/game_gui.hpp"
32#include "industry.h"
34
36
37#include "table/strings.h"
38
40
41#include "safeguards.h"
42
43
44extern void MakeNewgameSettingsLive();
45
52
57static uint GetMapHeightLimit()
58{
59 if (_settings_newgame.construction.map_height_limit == 0) return MAX_MAP_HEIGHT_LIMIT;
60 return _settings_newgame.construction.map_height_limit;
61}
62
68{
69 _settings_newgame.game_creation.landscape = landscape;
70 InvalidateWindowClassesData(WindowClass::SelectGame);
71 InvalidateWindowClassesData(WindowClass::GenerateLandscape);
72}
73
75static constexpr std::initializer_list<NWidgetPart> _nested_generate_landscape_widgets = {
78 NWidget(WWT_CAPTION, Colours::Brown), SetStringTip(STR_MAPGEN_WORLD_GENERATION_CAPTION),
82 /* Landscape selection. */
85 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_GL_ARCTIC), SetSpriteTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
86 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_GL_TROPICAL), SetSpriteTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
87 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_GL_TOYLAND), SetSpriteTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
89
90 /* Generation options. */
92 /* Left half (land generation options) */
94 /* Labels on the left side (global column 1). */
96 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
97 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_TERRAIN_TYPE, STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT), SetFill(1, 1),
98 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_AVERAGE_HEIGHT, STR_CONFIG_SETTING_AVERAGE_HEIGHT_HELPTEXT), SetFill(1, 1),
99 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_VARIETY, STR_CONFIG_SETTING_VARIETY_HELPTEXT), SetFill(1, 1),
100 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SMOOTHNESS, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT), SetFill(1, 1),
101 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
102 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BORDER_TYPE, STR_MAPGEN_BORDER_TYPE_TOOLTIP), SetFill(1, 1),
103 EndContainer(),
104
105 /* Widgets on the right side (global column 2). */
107 /* Mapsize X * Y. */
112 EndContainer(),
113 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_MAX_HEIGHT_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT), SetFill(1, 1),
114 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_AVERAGE_HEIGHT_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_AVERAGE_HEIGHT_HELPTEXT), SetFill(1, 1),
115 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_VARIETY_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_VARIETY_HELPTEXT), SetFill(1, 1),
116 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_SMOOTHNESS_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT), SetFill(1, 1),
117 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_RIVER_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
118 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_BORDERS_PULLDOWN), SetToolTip(STR_MAPGEN_BORDER_TYPE_TOOLTIP), SetFill(1, 1),
119 EndContainer(),
120 EndContainer(),
121
122 /* Right half (all other options) */
124 /* Labels on the left side (global column 3). */
127 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SNOW_COVERAGE, STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
128 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_DESERT_COVERAGE, STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
130 EndContainer(),
131 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_DATE, STR_MAPGEN_DATE_TOOLTIP), SetFill(1, 1),
132 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_TOWN_NAME_LABEL, STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
133 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
134 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
135 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SEA_LEVEL, STR_MAPGEN_SEA_LEVEL_TOOLTIP), SetFill(1, 1),
136 /* Spacer due to fewer items in columns 3-4 than in 1-2. */
138 EndContainer(),
139
140 /* Widgets on the right side (global column 4). */
142 /* Climate selector. */
144 /* Snow coverage. */
146 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_SNOW_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
147 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_SNOW_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
148 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_SNOW_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
149 EndContainer(),
150 /* Desert coverage. */
152 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_DESERT_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
153 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_DESERT_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
154 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_DESERT_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
155 EndContainer(),
156 /* Temperate/Toyland spacer. */
158 EndContainer(),
159 /* Starting date. */
161 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_START_DATE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
163 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_START_DATE_UP), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
164 EndContainer(),
165 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_TOWNNAME_DROPDOWN), SetToolTip(STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
166 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_TOWN_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
167 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_INDUSTRY_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
168 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_WATER_PULLDOWN), SetToolTip(STR_MAPGEN_SEA_LEVEL_TOOLTIP), SetFill(1, 1),
169 /* Spacer due to fewer items in columns 3-4 than in 1-2. */
171 EndContainer(),
172 EndContainer(),
173 EndContainer(),
174
175 /* Map borders buttons for each edge. */
179 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_NW), SetToolTip(STR_MAPGEN_NORTHWEST_TOOLTIP), SetFill(1, 1),
180 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_NE), SetToolTip(STR_MAPGEN_NORTHEAST_TOOLTIP), SetFill(1, 1),
181 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NORTHEAST), SetPadding(0, 0, 0, WidgetDimensions::unscaled.hsep_normal), SetFill(1, 1),
182 EndContainer(),
185 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_SW), SetToolTip(STR_MAPGEN_SOUTHWEST_TOOLTIP), SetFill(1, 1),
186 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_WATER_SE), SetToolTip(STR_MAPGEN_SOUTHEAST_TOOLTIP), SetFill(1, 1),
187 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SOUTHEAST), SetPadding(0, 0, 0, WidgetDimensions::unscaled.hsep_normal), SetFill(1, 1),
188 EndContainer(),
189 EndContainer(),
190
191 /* AI, GS, and NewGRF settings */
193 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_GL_AI_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_AI_SETTINGS, STR_MAPGEN_AI_SETTINGS_TOOLTIP), SetFill(1, 0),
194 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_GL_GS_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_GS_SETTINGS, STR_MAPGEN_GS_SETTINGS_TOOLTIP), SetFill(1, 0),
195 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_GL_NEWGRF_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0),
196 EndContainer(),
197
198 /* Generate */
199 NWidget(WWT_PUSHTXTBTN, Colours::Green, WID_GL_GENERATE_BUTTON), SetMinimalTextLines(3, 0), SetStringTip(STR_MAPGEN_GENERATE, STR_MAPGEN_GENERATE_TOOLTIP), SetFill(1, 1),
200 EndContainer(),
201 EndContainer(),
202};
203
205static constexpr std::initializer_list<NWidgetPart> _nested_heightmap_load_widgets = {
206 /* Window header. */
209 NWidget(WWT_CAPTION, Colours::Brown), SetStringTip(STR_MAPGEN_WORLD_GENERATION_CAPTION),
210 EndContainer(),
213 /* Landscape selection. */
216 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_GL_ARCTIC), SetSpriteTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
217 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_GL_TROPICAL), SetSpriteTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
218 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_GL_TOYLAND), SetSpriteTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
219 EndContainer(),
220
222 /* Heightmap name label. */
223 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_MAPGEN_HEIGHTMAP_NAME_TOOLTIP),
225 EndContainer(),
226
227 /* Generation options. */
229 /* Left half (land generation options) */
231 /* Labels on the left side (global column 1). */
233 /* Land generation option labels. */
234 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_MAPGEN_HEIGHTMAP_SIZE_LABEL_TOOLTIP), SetFill(1, 1),
235 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
236 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_TOOLTIP), SetFill(1, 1),
237 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_HEIGHTMAP_HEIGHT, STR_MAPGEN_HEIGHTMAP_HEIGHT_TOOLTIP), SetFill(1, 1),
238 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
239 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_BORDER_TYPE, STR_MAPGEN_BORDER_TYPE_TOOLTIP), SetFill(1, 1),
240 EndContainer(),
241
242 /* Left half widgets (global column 2) */
244 NWidget(WWT_TEXT, Colours::Invalid, WID_GL_HEIGHTMAP_SIZE_TEXT), SetStringTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_MAPGEN_HEIGHTMAP_SIZE_LABEL_TOOLTIP), SetFill(1, 1),
245 /* Mapsize X * Y. */
250 EndContainer(),
251 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_TOOLTIP), SetFill(1, 1),
252 /* Heightmap highest peak. */
254 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_HEIGHTMAP_HEIGHT_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_HEIGHTMAP_HEIGHT_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
255 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_HEIGHTMAP_HEIGHT_TEXT), SetToolTip(STR_MAPGEN_HEIGHTMAP_HEIGHT_TOOLTIP), SetFill(1, 1),
256 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_HEIGHTMAP_HEIGHT_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_HEIGHTMAP_HEIGHT_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
257 EndContainer(),
258 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_RIVER_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
259 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_BORDERS_PULLDOWN), SetToolTip(STR_MAPGEN_BORDER_TYPE_TOOLTIP), SetFill(1, 1),
260 EndContainer(),
261 EndContainer(),
262
263 /* Right half (all other options) */
265 /* Right half labels (global column 3) */
268 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_SNOW_COVERAGE, STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
269 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_DESERT_COVERAGE, STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
271 EndContainer(),
272 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_DATE, STR_MAPGEN_DATE_TOOLTIP), SetFill(1, 1),
273 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_TOWN_NAME_LABEL, STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
274 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
275 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
277 EndContainer(),
278
279 /* Right half widgets (global column 4) */
281 /* Climate selector. */
283 /* Snow coverage. */
285 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_SNOW_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
286 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_SNOW_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
287 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_SNOW_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
288 EndContainer(),
289 /* Desert coverage. */
291 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_DESERT_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
292 NWidget(WWT_TEXTBTN, Colours::Orange, WID_GL_DESERT_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
293 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_DESERT_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
294 EndContainer(),
295 /* Temperate/Toyland spacer. */
297 EndContainer(),
298 /* Starting date. */
300 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_START_DATE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
302 NWidget(WWT_IMGBTN, Colours::Orange, WID_GL_START_DATE_UP), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
303 EndContainer(),
304 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_TOWNNAME_DROPDOWN), SetToolTip(STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
305 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_TOWN_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
306 NWidget(WWT_DROPDOWN, Colours::Orange, WID_GL_INDUSTRY_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
308 EndContainer(),
309 EndContainer(),
310 EndContainer(),
311
312 /* AI, GS, and NewGRF settings */
314 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_GL_AI_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_AI_SETTINGS, STR_MAPGEN_AI_SETTINGS_TOOLTIP), SetFill(1, 0),
315 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_GL_GS_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_GS_SETTINGS, STR_MAPGEN_GS_SETTINGS_TOOLTIP), SetFill(1, 0),
316 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_GL_NEWGRF_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0),
317 EndContainer(),
318
319 /* Generate */
320 NWidget(WWT_PUSHTXTBTN, Colours::Green, WID_GL_GENERATE_BUTTON), SetMinimalTextLines(3, 0), SetStringTip(STR_MAPGEN_GENERATE, STR_MAPGEN_GENERATE_TOOLTIP), SetFill(1, 1),
321 EndContainer(),
322 EndContainer(),
323};
324
325static void StartGeneratingLandscape(GenerateLandscapeWindowMode mode)
326{
329
330 /* Copy all XXX_newgame to XXX when coming from outside the editor */
331 MakeNewgameSettingsLive();
332 ResetGRFConfig(true);
333
335 switch (mode) {
339 default: NOT_REACHED();
340 }
341}
342
343static void LandscapeGenerationCallback(Window *w, bool confirmed)
344{
345 if (confirmed) StartGeneratingLandscape(w->window_number);
346}
347
348static DropDownList BuildMapsizeDropDown()
349{
350 DropDownList list;
351
352 for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
353 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_INT, 1ULL << i), i));
354 }
355
356 return list;
357}
358
359static DropDownList BuildTownNameDropDown()
360{
361 DropDownList list;
362
363 /* Add and sort newgrf townnames generators */
364 const auto &grf_names = GetGRFTownNameList();
365 for (uint i = 0; i < grf_names.size(); i++) {
366 list.push_back(MakeDropDownListStringItem(grf_names[i], BUILTIN_TOWNNAME_GENERATOR_COUNT + i));
367 }
368 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
369
370 size_t newgrf_size = list.size();
371 /* Insert newgrf_names at the top of the list */
372 if (newgrf_size > 0) {
373 list.push_back(MakeDropDownListDividerItem()); // separator line
374 newgrf_size++;
375 }
376
377 /* Add and sort original townnames generators */
378 for (uint i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) {
379 list.push_back(MakeDropDownListStringItem(STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + i, i));
380 }
381 std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
382
383 return list;
384}
385
386
387static const StringID _max_height[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, STR_TERRAIN_TYPE_CUSTOM};
388static const StringID _sea_lakes[] = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM};
389static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT};
390static const StringID _borders[] = {STR_MAPGEN_BORDER_RANDOMIZE, STR_MAPGEN_BORDER_MANUAL, STR_MAPGEN_BORDER_INFINITE_WATER};
391static const StringID _smoothness[] = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH};
392static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE};
393static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM};
394static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM};
395static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH};
396static const StringID _average_height[] = {STR_CONFIG_SETTING_AVERAGE_HEIGHT_AUTO, STR_CONFIG_SETTING_AVERAGE_HEIGHT_LOWLANDS, STR_CONFIG_SETTING_AVERAGE_HEIGHT_NORMAL, STR_CONFIG_SETTING_AVERAGE_HEIGHT_PLATEAUS};
397
398static_assert(std::size(_num_inds) == to_underlying(IndustryDensity::End));
399
400struct GenerateLandscapeWindow : public Window {
401 WidgetID widget_id{};
402 uint x = 0;
403 uint y = 0;
404 EncodedString name{};
406
407 GenerateLandscapeWindow(WindowDesc &desc, WindowNumber number = 0) : Window(desc)
408 {
409 this->InitNested(number);
410
411 this->LowerWidget(to_underlying(_settings_newgame.game_creation.landscape) + WID_GL_TEMPERATE);
412
413 this->mode = this->window_number;
414
415 /* Disable town and industry in SE */
418
419 /* In case the map_height_limit is changed, clamp heightmap_height and custom_terrain_type. */
420 _settings_newgame.game_creation.heightmap_height = Clamp(_settings_newgame.game_creation.heightmap_height, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
421 _settings_newgame.game_creation.custom_terrain_type = Clamp(_settings_newgame.game_creation.custom_terrain_type, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
422
423 /* If original landgenerator is selected and alpinist terrain_type was selected, revert to mountainous. */
424 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
425 _settings_newgame.difficulty.terrain_type = Clamp(_settings_newgame.difficulty.terrain_type, GenworldMaxHeight::VeryFlat, GenworldMaxHeight::Mountainous);
426 }
427
428 this->OnInvalidateData();
429 }
430
431
432 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
433 {
434 switch (widget) {
435 case WID_GL_START_DATE_TEXT: return GetString(STR_JUST_DATE_LONG, TimerGameCalendar::ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
436 case WID_GL_MAPSIZE_X_PULLDOWN: return GetString(STR_JUST_INT, 1LL << _settings_newgame.game_creation.map_x);
437 case WID_GL_MAPSIZE_Y_PULLDOWN: return GetString(STR_JUST_INT, 1LL << _settings_newgame.game_creation.map_y);
438 case WID_GL_HEIGHTMAP_HEIGHT_TEXT: return GetString(STR_JUST_INT, _settings_newgame.game_creation.heightmap_height);
439 case WID_GL_SNOW_COVERAGE_TEXT: return GetString(STR_MAPGEN_SNOW_COVERAGE_TEXT, _settings_newgame.game_creation.snow_coverage);
440 case WID_GL_DESERT_COVERAGE_TEXT: return GetString(STR_MAPGEN_DESERT_COVERAGE_TEXT, _settings_newgame.game_creation.desert_coverage);
441
443 if (_game_mode == GameMode::Editor) {
444 return GetString(STR_CONFIG_SETTING_OFF);
445 }
446 if (_settings_newgame.difficulty.number_towns == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
447 return GetString(STR_NUM_CUSTOM_NUMBER, _settings_newgame.game_creation.custom_town_number);
448 }
449 return GetString(_num_towns[_settings_newgame.difficulty.number_towns]);
450
452 uint gen = _settings_newgame.game_creation.town_name;
454 STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + gen :
455 GetGRFTownNameName(gen - BUILTIN_TOWNNAME_GENERATOR_COUNT);
456 return GetString(name);
457 }
458
460 if (_game_mode == GameMode::Editor) {
461 return GetString(STR_CONFIG_SETTING_OFF);
462 }
463 if (_settings_newgame.difficulty.industry_density == IndustryDensity::Custom) {
464 return GetString(STR_NUM_CUSTOM_NUMBER, _settings_newgame.game_creation.custom_industry_number);
465 }
466 return GetString(_num_inds[to_underlying(_settings_newgame.difficulty.industry_density)]);
467
469 if (_settings_newgame.difficulty.terrain_type == GenworldMaxHeight::Custom) {
470 return GetString(STR_TERRAIN_TYPE_CUSTOM_VALUE, _settings_newgame.game_creation.custom_terrain_type);
471 }
472 return GetString(_max_height[to_underlying(_settings_newgame.difficulty.terrain_type)]);
473
475 if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
476 return GetString(STR_SEA_LEVEL_CUSTOM_PERCENTAGE, _settings_newgame.game_creation.custom_sea_level);
477 }
478 return GetString(_sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
479
480 case WID_GL_HEIGHTMAP_NAME_TEXT: return this->name.GetDecodedString();
481 case WID_GL_RIVER_PULLDOWN: return GetString(_rivers[_settings_newgame.game_creation.amount_of_rivers]);
482 case WID_GL_SMOOTHNESS_PULLDOWN: return GetString(_smoothness[_settings_newgame.game_creation.tgen_smoothness]);
483 case WID_GL_VARIETY_PULLDOWN: return GetString(_variety[_settings_newgame.game_creation.variety]);
484 case WID_GL_AVERAGE_HEIGHT_PULLDOWN: return GetString(_average_height[to_underlying(_settings_newgame.game_creation.average_height)]);
485 case WID_GL_BORDERS_PULLDOWN: return GetString(_borders[to_underlying(_settings_newgame.game_creation.water_border_presets)]);
486 case WID_GL_WATER_NE: return GetString((_settings_newgame.game_creation.water_borders == BorderFlag::Random) ? STR_MAPGEN_BORDER_RANDOM : _settings_newgame.game_creation.water_borders.Test(BorderFlag::NorthEast) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM);
487 case WID_GL_WATER_NW: return GetString((_settings_newgame.game_creation.water_borders == BorderFlag::Random) ? STR_MAPGEN_BORDER_RANDOM : _settings_newgame.game_creation.water_borders.Test(BorderFlag::NorthWest) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM);
488 case WID_GL_WATER_SE: return GetString((_settings_newgame.game_creation.water_borders == BorderFlag::Random) ? STR_MAPGEN_BORDER_RANDOM : _settings_newgame.game_creation.water_borders.Test(BorderFlag::SouthEast) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM);
489 case WID_GL_WATER_SW: return GetString((_settings_newgame.game_creation.water_borders == BorderFlag::Random) ? STR_MAPGEN_BORDER_RANDOM : _settings_newgame.game_creation.water_borders.Test(BorderFlag::SouthWest) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM);
490 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: return GetString(_rotation[_settings_newgame.game_creation.heightmap_rotation]);
491
493 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
494 return GetString(STR_MAPGEN_HEIGHTMAP_SIZE, this->y, this->x);
495 }
496 return GetString(STR_MAPGEN_HEIGHTMAP_SIZE, this->x, this->y);
497
498 default:
499 return this->Window::GetWidgetString(widget, stringid);
500 }
501 }
502
508 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
509 {
510 if (!gui_scope) return;
511 /* Update the climate buttons */
516
517 /* You can't select smoothness / non-water borders if not terragenesis */
518 if (mode == GLWM_GENERATE) {
519 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL,
521 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BorderFlag::Random,
523
524 this->SetWidgetLoweredState(WID_GL_WATER_NW, _settings_newgame.game_creation.water_borders.Test(BorderFlag::NorthWest));
525 this->SetWidgetLoweredState(WID_GL_WATER_NE, _settings_newgame.game_creation.water_borders.Test(BorderFlag::NorthEast));
526 this->SetWidgetLoweredState(WID_GL_WATER_SE, _settings_newgame.game_creation.water_borders.Test(BorderFlag::SouthEast));
527 this->SetWidgetLoweredState(WID_GL_WATER_SW, _settings_newgame.game_creation.water_borders.Test(BorderFlag::SouthWest));
528
529 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL && (_settings_newgame.game_creation.landscape == LandscapeType::Arctic || _settings_newgame.game_creation.landscape == LandscapeType::Tropic),
531 }
532
533 /* Disable snowline if not arctic */
535 /* Disable desert if not tropic */
537
538 /* Set snow/rainforest selections */
539 int climate_plane = 0;
540 switch (_settings_newgame.game_creation.landscape) {
541 case LandscapeType::Temperate: climate_plane = 2; break;
542 case LandscapeType::Arctic: climate_plane = 0; break;
543 case LandscapeType::Tropic: climate_plane = 1; break;
544 case LandscapeType::Toyland: climate_plane = 2; break;
545 }
546 this->GetWidget<NWidgetStacked>(WID_GL_CLIMATE_SEL_LABEL)->SetDisplayedPlane(climate_plane);
547 this->GetWidget<NWidgetStacked>(WID_GL_CLIMATE_SEL_SELECTOR)->SetDisplayedPlane(climate_plane);
548
549 /* Update availability of decreasing / increasing start date and snow level */
550 if (mode == GLWM_HEIGHTMAP) {
553 }
556 this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_DOWN, _settings_newgame.game_creation.snow_coverage <= 0 || _settings_newgame.game_creation.landscape != LandscapeType::Arctic);
557 this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_UP, _settings_newgame.game_creation.snow_coverage >= 100 || _settings_newgame.game_creation.landscape != LandscapeType::Arctic);
558 this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_DOWN, _settings_newgame.game_creation.desert_coverage <= 0 || _settings_newgame.game_creation.landscape != LandscapeType::Tropic);
559 this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_UP, _settings_newgame.game_creation.desert_coverage >= 100 || _settings_newgame.game_creation.landscape != LandscapeType::Tropic);
560
561 /* Do not allow a custom sea level or terrain type with the original land generator. */
562 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
563 if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
564 _settings_newgame.difficulty.quantity_sea_lakes = 1;
565 }
566 if (_settings_newgame.difficulty.terrain_type == GenworldMaxHeight::Custom) {
567 _settings_newgame.difficulty.terrain_type = GenworldMaxHeight::Flat;
568 }
569 }
570
571 }
572
573 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
574 {
576 std::span<const StringID> strs;
577 switch (widget) {
580 size.width += WidgetDimensions::scaled.fullbevel.Horizontal();
581 size.height += WidgetDimensions::scaled.fullbevel.Vertical();
582 break;
583
586 break;
587
590 break;
591
595 break;
596
598 d = GetStringBoundingBox(GetString(STR_MAPGEN_SNOW_COVERAGE_TEXT, GetParamMaxValue(MAX_TILE_HEIGHT)));
599 break;
600
602 d = GetStringBoundingBox(GetString(STR_MAPGEN_DESERT_COVERAGE_TEXT, GetParamMaxValue(MAX_TILE_HEIGHT)));
603 break;
604
606 d = GetStringBoundingBox(GetString(STR_MAPGEN_HEIGHTMAP_SIZE, this->x, this->y));
607 break;
608
610 strs = _num_towns;
612 break;
613
615 strs = _num_inds;
617 break;
618
620 strs = _max_height;
621 d = GetStringBoundingBox(GetString(STR_TERRAIN_TYPE_CUSTOM_VALUE, GetParamMaxValue(MAX_MAP_HEIGHT_LIMIT)));
622 break;
623
625 strs = _sea_lakes;
627 break;
628
629 case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
630 case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
631 case WID_GL_AVERAGE_HEIGHT_PULLDOWN: strs = _variety; break;
632 case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
633 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
634 case WID_GL_BORDERS_PULLDOWN: strs = _borders; break;
635 case WID_GL_WATER_NE:
636 case WID_GL_WATER_NW:
637 case WID_GL_WATER_SE:
638 case WID_GL_WATER_SW:
639 d = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
640 break;
641
643 size.width = 0;
644 break;
645
646 default:
647 return;
648 }
649 d = maxdim(d, GetStringListBoundingBox(strs));
650 d.width += padding.width;
651 d.height += padding.height;
652 size = maxdim(size, d);
653 }
654
655 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
656 {
657 switch (widget) {
658 case WID_GL_TEMPERATE:
659 case WID_GL_ARCTIC:
660 case WID_GL_TROPICAL:
661 case WID_GL_TOYLAND:
663 SndClickBeep();
664 break;
665
666 case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
667 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
668 break;
669
670 case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
671 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
672 break;
673
674 case WID_GL_TOWN_PULLDOWN: // Number of towns
675 ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
676 break;
677
678 case WID_GL_TOWNNAME_DROPDOWN: // Townname generator
679 ShowDropDownList(this, BuildTownNameDropDown(), _settings_newgame.game_creation.town_name, WID_GL_TOWNNAME_DROPDOWN);
680 break;
681
682 case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
683 ShowDropDownMenu(this, _num_inds, to_underlying(_settings_newgame.difficulty.industry_density), WID_GL_INDUSTRY_PULLDOWN, 0, 0);
684 break;
685
686 case WID_GL_GENERATE_BUTTON: { // Generate
687 /* Get rotated map size. */
688 uint map_x;
689 uint map_y;
690 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
691 map_x = this->y;
692 map_y = this->x;
693 } else {
694 map_x = this->x;
695 map_y = this->y;
696 }
697 if (mode == GLWM_HEIGHTMAP &&
698 (map_x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
699 map_x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
700 map_y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
701 map_y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
702 ShowQuery(
703 GetEncodedString(STR_WARNING_HEIGHTMAP_SCALE_CAPTION),
704 GetEncodedString(STR_WARNING_HEIGHTMAP_SCALE_MESSAGE),
705 this,
706 LandscapeGenerationCallback);
707 } else {
708 StartGeneratingLandscape(mode);
709 }
710 break;
711 }
712
714 case WID_GL_HEIGHTMAP_HEIGHT_UP: // Height level buttons
715 /* Don't allow too fast scrolling */
716 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
717 this->HandleButtonClick(widget);
718
719 _settings_newgame.game_creation.heightmap_height = Clamp(_settings_newgame.game_creation.heightmap_height + widget - WID_GL_HEIGHTMAP_HEIGHT_TEXT, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
720 this->InvalidateData();
721 }
723 break;
724
725 case WID_GL_HEIGHTMAP_HEIGHT_TEXT: // Height level text
726 this->widget_id = WID_GL_HEIGHTMAP_HEIGHT_TEXT;
727 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.heightmap_height), STR_MAPGEN_HEIGHTMAP_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QueryStringFlag::EnableDefault);
728 SndClickBeep();
729 break;
730
731
733 case WID_GL_START_DATE_UP: // Year buttons
734 /* Don't allow too fast scrolling */
735 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
736 this->HandleButtonClick(widget);
737
738 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
739 this->InvalidateData();
740 }
742 break;
743
744 case WID_GL_START_DATE_TEXT: // Year text
745 this->widget_id = WID_GL_START_DATE_TEXT;
746 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::EnableDefault);
747 break;
748
750 case WID_GL_SNOW_COVERAGE_UP: // Snow coverage buttons
751 /* Don't allow too fast scrolling */
752 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
753 this->HandleButtonClick(widget);
754
755 _settings_newgame.game_creation.snow_coverage = Clamp(_settings_newgame.game_creation.snow_coverage + (widget - WID_GL_SNOW_COVERAGE_TEXT) * 10, 0, 100);
756 this->InvalidateData();
757 }
759 break;
760
761 case WID_GL_SNOW_COVERAGE_TEXT: // Snow coverage text
762 this->widget_id = WID_GL_SNOW_COVERAGE_TEXT;
763 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.snow_coverage), STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QueryStringFlag::EnableDefault);
764 SndClickBeep();
765 break;
766
768 case WID_GL_DESERT_COVERAGE_UP: // Desert coverage buttons
769 /* Don't allow too fast scrolling */
770 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
771 this->HandleButtonClick(widget);
772
773 _settings_newgame.game_creation.desert_coverage = Clamp(_settings_newgame.game_creation.desert_coverage + (widget - WID_GL_DESERT_COVERAGE_TEXT) * 10, 0, 100);
774 this->InvalidateData();
775 }
777 break;
778
779 case WID_GL_DESERT_COVERAGE_TEXT: // Desert line text
780 this->widget_id = WID_GL_DESERT_COVERAGE_TEXT;
781 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.desert_coverage), STR_MAPGEN_DESERT_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QueryStringFlag::EnableDefault);
782 SndClickBeep();
783 break;
784
785 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
786 ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
787 break;
788
789 case WID_GL_MAX_HEIGHT_PULLDOWN: // Max height
790 /* For the original map generation only the first four are valid. */
791 ShowDropDownMenu(this, _max_height, to_underlying(_settings_newgame.difficulty.terrain_type), WID_GL_MAX_HEIGHT_PULLDOWN, 0, _settings_newgame.game_creation.land_generator == LG_ORIGINAL ? ~0xF : 0);
792 break;
793
794 case WID_GL_WATER_PULLDOWN: { // Water quantity
795 uint32_t hidden_mask = 0;
796 /* Disable custom water level when the original map generator is active. */
797 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
799 }
800 ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
801 break;
802 }
803
804 case WID_GL_RIVER_PULLDOWN: // Amount of rivers
805 ShowDropDownMenu(this, _rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
806 break;
807
808 case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
809 ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
810 break;
811
812 case WID_GL_VARIETY_PULLDOWN: // Map variety
813 ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
814 break;
815
816 case WID_GL_AVERAGE_HEIGHT_PULLDOWN: // Average height
817 ShowDropDownMenu(this, _average_height, to_underlying(_settings_newgame.game_creation.average_height), WID_GL_AVERAGE_HEIGHT_PULLDOWN, 0, 0);
818 break;
819
820 /* Map borders */
822 /* WHen loading a heightmap, hide the first option "Random". */
823 ShowDropDownMenu(this, _borders, to_underlying(_settings_newgame.game_creation.water_border_presets), WID_GL_BORDERS_PULLDOWN, 0, mode == GLWM_HEIGHTMAP ? (1U << 0) : 0);
824 break;
825
826 case WID_GL_WATER_NW:
827 _settings_newgame.game_creation.water_borders.Flip(BorderFlag::NorthWest);
828 SndClickBeep();
829 this->InvalidateData();
830 break;
831
832 case WID_GL_WATER_NE:
833 _settings_newgame.game_creation.water_borders.Flip(BorderFlag::NorthEast);
834 SndClickBeep();
835 this->InvalidateData();
836 break;
837
838 case WID_GL_WATER_SE:
839 _settings_newgame.game_creation.water_borders.Flip(BorderFlag::SouthEast);
840 SndClickBeep();
841 this->InvalidateData();
842 break;
843
844 case WID_GL_WATER_SW:
845 _settings_newgame.game_creation.water_borders.Flip(BorderFlag::SouthWest);
846 SndClickBeep();
847 this->InvalidateData();
848 break;
849
850 case WID_GL_AI_BUTTON:
852 break;
853
854 case WID_GL_GS_BUTTON:
856 break;
857
859 ShowNewGRFSettings(true, true, false, _grfconfig_newgame);
860 break;
861 }
862 }
863
872
873 void OnDropdownSelect(WidgetID widget, int index, int) override
874 {
875 switch (widget) {
876 case WID_GL_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
877 case WID_GL_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
878 case WID_GL_RIVER_PULLDOWN: _settings_newgame.game_creation.amount_of_rivers = index; break;
879 case WID_GL_SMOOTHNESS_PULLDOWN: _settings_newgame.game_creation.tgen_smoothness = index; break;
880 case WID_GL_VARIETY_PULLDOWN: _settings_newgame.game_creation.variety = index; break;
881 case WID_GL_AVERAGE_HEIGHT_PULLDOWN: _settings_newgame.game_creation.average_height = static_cast<GenworldAverageHeight>(index); break;
882
883 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
884
886 if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
887 this->widget_id = widget;
888 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_town_number), STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, {});
889 }
890 _settings_newgame.difficulty.number_towns = index;
891 break;
892
893 case WID_GL_TOWNNAME_DROPDOWN: // Town names
894 if (_game_mode == GameMode::Menu || Town::GetNumItems() == 0) {
895 _settings_newgame.game_creation.town_name = index;
896 SetWindowDirty(WindowClass::GameOptions, GameOptionsWindowNumber::GameOptions);
897 }
898 break;
899
901 if (static_cast<IndustryDensity>(index) == IndustryDensity::Custom) {
902 this->widget_id = widget;
903 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_industry_number), STR_MAPGEN_NUMBER_OF_INDUSTRIES, 5, this, CS_NUMERAL, {});
904 }
905 _settings_newgame.difficulty.industry_density = static_cast<IndustryDensity>(index);
906 break;
907
909 if (static_cast<GenworldMaxHeight>(index) == GenworldMaxHeight::Custom) {
910 this->widget_id = widget;
911 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_terrain_type), STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT, 4, this, CS_NUMERAL, {});
912 }
913 _settings_newgame.difficulty.terrain_type = static_cast<GenworldMaxHeight>(index);
914 break;
915 }
916
918 switch (static_cast<BorderFlagPresets>(index)) {
919 case BorderFlagPresets::Random:
920 _settings_newgame.game_creation.water_borders = BorderFlag::Random;
921 _settings_newgame.construction.freeform_edges = true;
922 break;
923 case BorderFlagPresets::Manual:
924 _settings_newgame.game_creation.water_borders = {};
925 _settings_newgame.construction.freeform_edges = true;
926 break;
927 case BorderFlagPresets::InfiniteWater:
928 _settings_newgame.game_creation.water_borders = BORDERFLAGS_ALL;
929 _settings_newgame.construction.freeform_edges = false;
930 break;
931 }
932 _settings_newgame.game_creation.water_border_presets = static_cast<BorderFlagPresets>(index);
933 break;
934 }
935
937 if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
938 this->widget_id = widget;
939 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.custom_sea_level), STR_MAPGEN_SEA_LEVEL, 3, this, CS_NUMERAL, {});
940 }
941 _settings_newgame.difficulty.quantity_sea_lakes = index;
942 break;
943 }
944 }
945 this->InvalidateData();
946 }
947
948 void OnQueryTextFinished(std::optional<std::string> str) override
949 {
950 /* Was 'cancel' pressed? */
951 if (!str.has_value()) return;
952
953 int32_t value;
954 if (!str->empty()) {
955 auto val = ParseInteger<int32_t>(*str, 10, true);
956 if (!val.has_value()) return;
957 value = *val;
958 } else {
959 /* An empty string means revert to the default */
960 switch (this->widget_id) {
962 case WID_GL_START_DATE_TEXT: value = CalendarTime::DEF_START_YEAR.base(); break;
963 case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break;
965 case WID_GL_TOWN_PULLDOWN: value = 1; break;
966 case WID_GL_INDUSTRY_PULLDOWN: value = 1; break;
969 default: NOT_REACHED();
970 }
971 }
972
973 switch (this->widget_id) {
976 _settings_newgame.game_creation.heightmap_height = Clamp(value, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
977 break;
978
982 break;
983
986 _settings_newgame.game_creation.snow_coverage = Clamp(value, 0, 100);
987 break;
988
991 _settings_newgame.game_creation.desert_coverage = Clamp(value, 0, 100);
992 break;
993
995 _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
996 break;
997
999 _settings_newgame.game_creation.custom_industry_number = Clamp(value, 1, IndustryPool::MAX_SIZE);
1000 break;
1001
1003 _settings_newgame.game_creation.custom_terrain_type = Clamp(value, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
1004 break;
1005
1008 break;
1009 }
1010
1011 this->InvalidateData();
1012 }
1013};
1014
1017 WindowPosition::Center, {}, 0, 0,
1018 WindowClass::GenerateLandscape, WindowClass::None,
1019 {},
1021);
1022
1025 WindowPosition::Center, {}, 0, 0,
1026 WindowClass::GenerateLandscape, WindowClass::None,
1027 {},
1029);
1030
1031static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
1032{
1033 uint x = 0;
1034 uint y = 0;
1035
1036 CloseWindowByClass(WindowClass::GenerateLandscape);
1037
1038 /* Generate a new seed when opening the window */
1039 _settings_newgame.game_creation.generation_seed = InteractiveRandom();
1040
1041 if (mode == GLWM_HEIGHTMAP) {
1042 /* If the function returns negative, it means there was a problem loading the heightmap */
1043 if (!GetHeightmapDimensions(_file_to_saveload.ftype.detailed, _file_to_saveload.name, &x, &y)) return;
1044 }
1045
1048
1049 if (mode == GLWM_HEIGHTMAP) {
1050 w->x = x;
1051 w->y = y;
1052 w->name = _file_to_saveload.title;
1053 }
1054
1055 SetWindowDirty(WindowClass::GenerateLandscape, mode);
1056}
1057
1060{
1061 _ShowGenerateLandscape(GLWM_GENERATE);
1062}
1063
1066{
1067 _ShowGenerateLandscape(GLWM_HEIGHTMAP);
1068}
1069
1072{
1073 StartGeneratingLandscape(GLWM_SCENARIO);
1074}
1075
1080void StartNewGameWithoutGUI(uint32_t seed)
1081{
1082 /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
1083 _settings_newgame.game_creation.generation_seed = seed;
1084
1085 StartGeneratingLandscape(GLWM_GENERATE);
1086}
1087
1088struct CreateScenarioWindow : public Window
1089{
1090 WidgetID widget_id{};
1091
1092 CreateScenarioWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
1093 {
1094 this->InitNested(window_number);
1095 this->LowerWidget(to_underlying(_settings_newgame.game_creation.landscape) + WID_CS_TEMPERATE);
1096 }
1097
1098 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1099 {
1100 switch (widget) {
1102 return GetString(STR_JUST_DATE_LONG, TimerGameCalendar::ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
1103
1105 return GetString(STR_JUST_INT, 1LL << _settings_newgame.game_creation.map_x);
1106
1108 return GetString(STR_JUST_INT, 1LL << _settings_newgame.game_creation.map_y);
1109
1111 return GetString(STR_JUST_INT, _settings_newgame.game_creation.se_flat_world_height);
1112
1113 default:
1114 return this->Window::GetWidgetString(widget, stringid);
1115 }
1116 }
1117
1118 void OnPaint() override
1119 {
1122 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
1123 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP, _settings_newgame.game_creation.se_flat_world_height >= GetMapHeightLimit());
1124
1129
1130 this->DrawWidgets();
1131 }
1132
1133 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1134 {
1135 std::string str;
1136 switch (widget) {
1139 size.width += WidgetDimensions::scaled.fullbevel.Horizontal();
1140 size.height += WidgetDimensions::scaled.fullbevel.Vertical();
1141 return;
1142
1145 break;
1146
1149 str = GetString(STR_JUST_INT, GetParamMaxValue(MAX_MAP_SIZE));
1150 break;
1151
1153 str = GetString(STR_JUST_INT, GetParamMaxValue(MAX_TILE_HEIGHT));
1154 break;
1155
1156 default:
1157 return;
1158 }
1160 d.width += padding.width;
1161 d.height += padding.height;
1162 size = maxdim(size, d);
1163 }
1164
1165 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1166 {
1167 switch (widget) {
1168 case WID_CS_TEMPERATE:
1169 case WID_CS_ARCTIC:
1170 case WID_CS_TROPICAL:
1171 case WID_CS_TOYLAND:
1172 this->RaiseWidget(to_underlying(_settings_newgame.game_creation.landscape) + WID_CS_TEMPERATE);
1174 break;
1175
1176 case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
1177 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
1178 break;
1179
1180 case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
1181 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
1182 break;
1183
1184 case WID_CS_EMPTY_WORLD: // Empty world / flat world
1185 StartGeneratingLandscape(GLWM_SCENARIO);
1186 break;
1187
1188 case WID_CS_RANDOM_WORLD: // Generate
1190 break;
1191
1193 case WID_CS_START_DATE_UP: // Year buttons
1194 /* Don't allow too fast scrolling */
1195 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
1196 this->HandleButtonClick(widget);
1197 this->SetDirty();
1198
1199 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
1200 }
1202 break;
1203
1204 case WID_CS_START_DATE_TEXT: // Year text
1205 this->widget_id = WID_CS_START_DATE_TEXT;
1206 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, {});
1207 break;
1208
1210 case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
1211 /* Don't allow too fast scrolling */
1212 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
1213 this->HandleButtonClick(widget);
1214 this->SetDirty();
1215
1216 _settings_newgame.game_creation.se_flat_world_height = Clamp(_settings_newgame.game_creation.se_flat_world_height + widget - WID_CS_FLAT_LAND_HEIGHT_TEXT, 0, GetMapHeightLimit());
1217 }
1219 break;
1220
1221 case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
1222 this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1223 ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.se_flat_world_height), STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, {});
1224 break;
1225 }
1226 }
1227
1232
1233 void OnDropdownSelect(WidgetID widget, int index, int) override
1234 {
1235 switch (widget) {
1236 case WID_CS_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
1237 case WID_CS_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
1238 }
1239 this->SetDirty();
1240 }
1241
1242 void OnQueryTextFinished(std::optional<std::string> str) override
1243 {
1244 if (!str.has_value()) return;
1245
1246 auto value = ParseInteger<int32_t>(*str, 10, true);
1247 if (!value.has_value()) return;
1248
1249 switch (this->widget_id) {
1253 break;
1254
1257 _settings_newgame.game_creation.se_flat_world_height = Clamp(*value, 0, GetMapHeightLimit());
1258 break;
1259 }
1260
1261 this->SetDirty();
1262 }
1263};
1264
1265static constexpr std::initializer_list<NWidgetPart> _nested_create_scenario_widgets = {
1268 NWidget(WWT_CAPTION, Colours::Brown), SetStringTip(STR_SE_MAPGEN_CAPTION),
1269 EndContainer(),
1272 /* Landscape style selection. */
1275 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_CS_ARCTIC), SetSpriteTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1276 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_CS_TROPICAL), SetSpriteTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1277 NWidget(WWT_IMGBTN_2, Colours::Orange, WID_CS_TOYLAND), SetSpriteTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1278 EndContainer(),
1279
1281 /* Green generation type buttons: 'Flat land' and 'Random land'. */
1283 NWidget(WWT_PUSHTXTBTN, Colours::Green, WID_CS_EMPTY_WORLD), SetStringTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1284 NWidget(WWT_PUSHTXTBTN, Colours::Green, WID_CS_RANDOM_WORLD), SetStringTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1285 EndContainer(),
1286
1287 /* Labels + setting drop-downs */
1289 /* Labels. */
1291 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(0, 1),
1292 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_DATE, STR_MAPGEN_DATE_TOOLTIP), SetFill(0, 1),
1293 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_TOOLTIP), SetFill(0, 1),
1294 EndContainer(),
1295
1297 /* Map size. */
1299 NWidget(WWT_DROPDOWN, Colours::Orange, WID_CS_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
1301 NWidget(WWT_DROPDOWN, Colours::Orange, WID_CS_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
1302 EndContainer(),
1303
1304 /* Date. */
1306 NWidget(WWT_IMGBTN, Colours::Orange, WID_CS_START_DATE_DOWN), SetFill(0, 1), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1308 NWidget(WWT_IMGBTN, Colours::Orange, WID_CS_START_DATE_UP), SetFill(0, 1), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1309 EndContainer(),
1310
1311 /* Flat map height. */
1313 NWidget(WWT_IMGBTN, Colours::Orange, WID_CS_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetSpriteTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1314 NWidget(WWT_PUSHTXTBTN, Colours::Orange, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetFill(1, 1), SetToolTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_TOOLTIP),
1315 NWidget(WWT_IMGBTN, Colours::Orange, WID_CS_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetSpriteTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1316 EndContainer(),
1317 EndContainer(),
1318 EndContainer(),
1319 EndContainer(),
1320 EndContainer(),
1321 EndContainer(),
1322};
1323
1326 WindowPosition::Center, {}, 0, 0,
1327 WindowClass::GenerateLandscape, WindowClass::None,
1328 {},
1329 _nested_create_scenario_widgets
1330);
1331
1334{
1335 CloseWindowByClass(WindowClass::GenerateLandscape);
1337}
1338
1339static constexpr std::initializer_list<NWidgetPart> _nested_generate_progress_widgets = {
1340 NWidget(WWT_CAPTION, Colours::Grey), SetStringTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1345 NWidget(WWT_TEXTBTN, Colours::White, WID_GP_ABORT), SetStringTip(STR_GENERATION_ABORT), SetFill(1, 0),
1346 EndContainer(),
1347 EndContainer(),
1348};
1349
1350
1353 WindowPosition::Center, {}, 0, 0,
1354 WindowClass::ModalProgress, WindowClass::None,
1356 _nested_generate_progress_widgets
1357);
1358
1360 static inline uint percent;
1361 static inline StringID cls;
1362 static inline uint current;
1363 static inline uint total;
1364};
1365
1368 STR_GENERATION_WORLD_GENERATION,
1369 STR_GENERATION_LANDSCAPE_GENERATION,
1370 STR_GENERATION_RIVER_GENERATION,
1371 STR_GENERATION_CLEARING_TILES,
1372 STR_GENERATION_TOWN_GENERATION,
1373 STR_GENERATION_LAND_INDUSTRY_GENERATION,
1374 STR_GENERATION_WATER_INDUSTRY_GENERATION,
1375 STR_GENERATION_OBJECT_GENERATION,
1376 STR_GENERATION_TREE_GENERATION,
1377 STR_GENERATION_SETTINGUP_GAME,
1378 STR_GENERATION_PREPARING_TILELOOP,
1379 STR_GENERATION_PREPARING_SCRIPT,
1380 STR_GENERATION_PREPARING_GAME
1381};
1382
1383static void AbortGeneratingWorldCallback(Window *, bool confirmed)
1384{
1385 if (confirmed) {
1387 } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1388 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1389 }
1390}
1391
1392struct GenerateProgressWindow : public Window {
1393
1394 GenerateProgressWindow() : Window(_generate_progress_desc)
1395 {
1396 this->InitNested();
1397 }
1398
1399 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1400 {
1401 switch (widget) {
1402 case WID_GP_ABORT:
1403 SetMouseCursorBusy(false);
1404 ShowQuery(
1405 GetEncodedString(STR_GENERATION_ABORT_CAPTION),
1406 GetEncodedString(STR_GENERATION_ABORT_MESSAGE),
1407 this,
1408 AbortGeneratingWorldCallback
1409 );
1410 break;
1411 }
1412 }
1413
1414 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1415 {
1416 switch (widget) {
1417 case WID_GP_PROGRESS_BAR: {
1418 size = GetStringBoundingBox(GetString(STR_GENERATION_PROGRESS, GetParamMaxValue(100)));
1419 /* We need some spacing for the 'border' */
1420 size.height += WidgetDimensions::scaled.frametext.Horizontal();
1421 size.width += WidgetDimensions::scaled.frametext.Vertical();
1422 break;
1423 }
1424
1426 for (StringID str : _generation_class_table) {
1427 size.width = std::max(size.width, GetStringBoundingBox(str).width + padding.width);
1428 }
1430 break;
1431 }
1432 }
1433
1434 void DrawWidget(const Rect &r, WidgetID widget) const override
1435 {
1436 switch (widget) {
1437 case WID_GP_PROGRESS_BAR: {
1438 /* Draw the % complete with a bar and a text */
1440 Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
1441 DrawFrameRect(br.WithWidth(br.Width() * GenWorldStatus::percent / 100, _current_text_dir == TD_RTL), Colours::Mauve, {});
1442 DrawString(br.CentreToHeight(GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TextColour::FromString, AlignmentH::Centre);
1443 break;
1444 }
1445
1447 /* Tell which class we are generating */
1448 DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TextColour::FromString, AlignmentH::Centre);
1449
1450 /* And say where we are in that class */
1451 DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal,
1452 GetString(STR_GENERATION_PROGRESS_NUM, GenWorldStatus::current, GenWorldStatus::total), TextColour::FromString, AlignmentH::Centre);
1453 }
1454 }
1455};
1456
1461{
1462 GenWorldStatus::cls = STR_GENERATION_WORLD_GENERATION;
1463 GenWorldStatus::current = 0;
1464 GenWorldStatus::total = 0;
1465 GenWorldStatus::percent = 0;
1466}
1467
1472{
1473 if (BringWindowToFrontById(WindowClass::ModalProgress, 0)) return;
1475}
1476
1477static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1478{
1479 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 55, 60, 65, 80, 85, 95, 99, 100 };
1480 static_assert(lengthof(percent_table) == to_underlying(GenWorldProgress::End) + 1);
1481 assert(cls < GenWorldProgress::End);
1482
1483 /* Check if we really are generating the world.
1484 * For example, placing trees via the SE also calls this function, but
1485 * shouldn't try to update the progress.
1486 */
1487 if (!HasModalProgress()) return;
1488
1491 return;
1492 }
1493
1494 if (total == 0) {
1495 assert(GenWorldStatus::cls == _generation_class_table[cls]);
1496 GenWorldStatus::current += progress;
1497 assert(GenWorldStatus::current <= GenWorldStatus::total);
1498 } else {
1499 GenWorldStatus::cls = _generation_class_table[cls];
1500 GenWorldStatus::current = progress;
1501 GenWorldStatus::total = total;
1502 GenWorldStatus::percent = percent_table[to_underlying(cls)];
1503 }
1504
1505 /* Percentage is about the number of completed tasks, so 'current - 1' */
1506 GenWorldStatus::percent = percent_table[to_underlying(cls)] + (percent_table[to_underlying(cls) + 1] - percent_table[to_underlying(cls)]) * (GenWorldStatus::current == 0 ? 0 : GenWorldStatus::current - 1) / GenWorldStatus::total;
1507
1508 if (_network_dedicated) {
1509 static uint last_percent = 0;
1510
1511 /* Never display 0% */
1512 if (GenWorldStatus::percent == 0) return;
1513 /* Reset if percent is lower than the last recorded */
1514 if (GenWorldStatus::percent < last_percent) last_percent = 0;
1515 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1516 if (GenWorldStatus::percent % 5 != 0 && GenWorldStatus::percent <= last_percent + 5) return;
1517 /* Never show steps smaller than 2%, even if it is a mod 5% */
1518 if (GenWorldStatus::percent <= last_percent + 2) return;
1519
1520 Debug(Facility::Net, Severity::Notice, "Map generation percentage complete: {}", GenWorldStatus::percent);
1521 last_percent = GenWorldStatus::percent;
1522
1523 return;
1524 }
1525
1526 SetWindowDirty(WindowClass::ModalProgress, 0);
1527
1529}
1530
1540{
1541 if (total == 0) return;
1542
1543 _SetGeneratingWorldProgress(cls, 0, total);
1544}
1545
1554{
1555 /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1556 _SetGeneratingWorldProgress(cls, 1, 0);
1557}
void ShowAIConfigWindow()
Open the AI config window.
Definition ai_gui.cpp:338
Window for configuring the AIs.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Container for an encoded string, created by GetEncodedString.
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:206
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
static constexpr TimerGame< struct Calendar >::Year DEF_START_YEAR
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
StrongType::Typedef< int32_t, struct YearTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Year
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
void GameLoopPause()
Pause the game-loop for a bit, releasing the game-state lock.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:36
@ Net
Net message facility.
Definition debug_type.h:33
@ Notice
Notice.
Definition debug_type.h:18
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:633
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
Definition dropdown.cpp:36
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:591
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Functions related to errors.
void ClearErrorMessages()
Clear all errors from the queue.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:428
Window for configuring GS.
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition genworld.cpp:274
void AbortGeneratingWorld()
Initializes the abortion process.
Definition genworld.cpp:257
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition genworld.cpp:266
Functions related to world/map generation.
static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM
When map height limit is auto, make this the lowest possible map height limit.
Definition genworld.h:50
@ LG_ORIGINAL
The original landscape generator.
Definition genworld.h:19
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
Maximum percentage a user can specify for custom sea level.
Definition genworld.h:46
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition genworld.h:44
GenWorldProgress
Current stage of world generation process.
Definition genworld.h:57
@ End
End marker.
Definition genworld.h:71
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition genworld.h:45
static constexpr std::initializer_list< NWidgetPart > _nested_generate_landscape_widgets
Widgets of GenerateLandscapeWindow when generating world.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
void ShowGenerateLandscape()
Start with a normal game.
void ShowCreateScenario()
Show the window to create a scenario.
static constexpr std::initializer_list< NWidgetPart > _nested_heightmap_load_widgets
Widgets of GenerateLandscapeWindow when loading heightmap.
static const EnumIndexArray< StringID, GenWorldProgress, GenWorldProgress::End > _generation_class_table
Strings used for the steps of the world generation progress bar.
static WindowDesc _generate_landscape_desc(WindowPosition::Center, {}, 0, 0, WindowClass::GenerateLandscape, WindowClass::None, {}, _nested_generate_landscape_widgets)
Window definition for the landscape generation window.
static uint GetMapHeightLimit()
Get the map height limit, or if set to "auto", the absolute limit.
static WindowDesc _generate_progress_desc(WindowPosition::Center, {}, 0, 0, WindowClass::ModalProgress, WindowClass::None, WindowDefaultFlag::NoClose, _nested_generate_progress_widgets)
Window definition for the map generation progress window.
static WindowDesc _heightmap_load_desc(WindowPosition::Center, {}, 0, 0, WindowClass::GenerateLandscape, WindowClass::None, {}, _nested_heightmap_load_widgets)
Window definition for the heightmap configuration window.
void SetNewLandscapeType(LandscapeType landscape)
Changes landscape type and sets genworld window dirty.
void StartScenarioEditor()
Start with a scenario editor.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
void PrepareGenerateWorldProgress()
Initializes the progress counters to the starting point.
static WindowDesc _create_scenario_desc(WindowPosition::Center, {}, 0, 0, WindowClass::GenerateLandscape, WindowClass::None, {}, _nested_create_scenario_widgets)
Window definition for the create scenario window.
GenerateLandscapeWindowMode
Enum for the modes we can generate in.
@ GLWM_GENERATE
Generate new game.
@ GLWM_HEIGHTMAP
Load from heightmap.
@ GLWM_SCENARIO
Generate flat land.
void ShowHeightmapLoad()
Start with loading a heightmap.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
Types related to the genworld widgets.
@ WID_CS_TROPICAL
Select tropical landscape style.
@ WID_CS_TEMPERATE
Select temperate landscape style.
@ WID_CS_MAPSIZE_X_PULLDOWN
Pull-down arrow for x map size.
@ WID_CS_TOYLAND
Select toy-land landscape style.
@ WID_CS_FLAT_LAND_HEIGHT_TEXT
Clickable flat land height value.
@ WID_CS_START_DATE_TEXT
Clickable start date value.
@ WID_CS_START_DATE_DOWN
Decrease start year (start earlier).
@ WID_CS_EMPTY_WORLD
Generate an empty flat world.
@ WID_CS_ARCTIC
Select arctic landscape style.
@ WID_CS_MAPSIZE_Y_PULLDOWN
Pull-down arrow for y map size.
@ WID_CS_FLAT_LAND_HEIGHT_DOWN
Decrease flat land height.
@ WID_CS_FLAT_LAND_HEIGHT_UP
Increase flat land height.
@ WID_CS_RANDOM_WORLD
Generate random land button.
@ WID_CS_START_DATE_UP
Increase start year (start later).
@ WID_GL_TOWNNAME_DROPDOWN
Dropdown 'Townnames'.
@ WID_GL_WATER_SE
SE 'Water'/'Freeform'.
@ WID_GL_WATER_PULLDOWN
Dropdown 'Sea level'.
@ WID_GL_MAPSIZE_X_PULLDOWN
Dropdown 'map X size'.
@ WID_GL_SNOW_COVERAGE_TEXT
Snow coverage.
@ WID_GL_WATER_NE
NE 'Water'/'Freeform'.
@ WID_GL_VARIETY_PULLDOWN
Dropdown 'Variety distribution'.
@ WID_GL_TOYLAND
Button with icon "Toyland".
@ WID_GL_GENERATE_BUTTON
'Generate' button.
@ WID_GL_ARCTIC
Button with icon "Arctic".
@ WID_GL_HEIGHTMAP_HEIGHT_TEXT
Max. heightmap highest mountain.
@ WID_GL_HEIGHTMAP_ROTATION_PULLDOWN
Dropdown 'Heightmap rotation'.
@ WID_GL_MAPSIZE_Y_PULLDOWN
Dropdown 'map Y size'.
@ WID_GL_TROPICAL
Button with icon "Tropical".
@ WID_GL_HEIGHTMAP_NAME_TEXT
Heightmap name.
@ WID_GL_RIVER_PULLDOWN
Dropdown 'Rivers'.
@ WID_GL_DESERT_COVERAGE_TEXT
Desert coverage.
@ WID_GL_AI_BUTTON
'AI Settings' button.
@ WID_GL_SNOW_COVERAGE_DOWN
Decrease snow coverage.
@ WID_GL_HEIGHTMAP_HEIGHT_UP
Increase max. heightmap highest mountain.
@ WID_GL_NEWGRF_BUTTON
'NewGRF Settings' button.
@ WID_GL_CLIMATE_SEL_LABEL
NWID_SELECTION for snow or desert coverage label.
@ WID_GL_HEIGHTMAP_SIZE_TEXT
Size of heightmap.
@ WID_GL_AVERAGE_HEIGHT_PULLDOWN
Dropdown 'Average height'.
@ WID_GL_WATER_NW
NW 'Water'/'Freeform'.
@ WID_GL_BORDERS_PULLDOWN
Dropdown 'Map edges'.
@ WID_GL_TEMPERATE
Button with icon "Temperate".
@ WID_GL_SMOOTHNESS_PULLDOWN
Dropdown 'Smoothness'.
@ WID_GL_GS_BUTTON
'Game Script Settings' button.
@ WID_GL_START_DATE_DOWN
Decrease start year.
@ WID_GL_START_DATE_TEXT
Start year.
@ WID_GL_CLIMATE_SEL_SELECTOR
NWID_SELECTION for snow or desert coverage selector.
@ WID_GL_DESERT_COVERAGE_UP
Increase desert coverage.
@ WID_GL_TOWN_PULLDOWN
Dropdown 'No. of towns'.
@ WID_GL_MAX_HEIGHT_PULLDOWN
Dropdown 'Maximum height'.
@ WID_GL_HEIGHTMAP_HEIGHT_DOWN
Decrease heightmap highest mountain.
@ WID_GL_WATER_SW
SW 'Water'/'Freeform'.
@ WID_GL_SNOW_COVERAGE_UP
Increase snow coverage.
@ WID_GL_INDUSTRY_PULLDOWN
Dropdown 'No. of industries'.
@ WID_GL_DESERT_COVERAGE_DOWN
Decrease desert coverage.
@ WID_GL_START_DATE_UP
Increase start year.
@ WID_GP_PROGRESS_TEXT
Text with the progress bar.
@ WID_GP_PROGRESS_BAR
Progress bar.
@ WID_GP_ABORT
Abort button.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
@ Middle
Align to the middle.
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition gfx.cpp:1705
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:933
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition gfx.cpp:1689
ControlInputs _input_clicked
Control inputs that have been actioned.
Definition gfx.cpp:35
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:45
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ White
White.
Definition gfx_type.h:300
@ Mauve
Mauve.
Definition gfx_type.h:295
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Orange
Orange.
Definition gfx_type.h:297
@ Grey
Grey.
Definition gfx_type.h:299
@ Green
Green.
Definition gfx_type.h:291
@ Brown
Brown.
Definition gfx_type.h:298
@ FromString
Marker for telling to use the colour from the string.
Definition gfx_type.h:317
@ Orange
Orange colour.
Definition gfx_type.h:324
@ Left
Left mouse button is pressed.
Definition gfx_type.h:444
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetAlignment(Alignment align)
Widget part function for setting the alignment of text/images.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
static const CursorID SPR_CURSOR_ZZZ
Definition sprites.h:1569
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
bool GetHeightmapDimensions(DetailedFileType dft, std::string_view filename, uint *x, uint *y)
Get the dimensions of a heightmap.
Functions related to creating heightmaps from files.
@ HM_CLOCKWISE
Rotate the map clockwise 45 degrees.
Definition heightmap.h:21
Base of all industries.
static constexpr BorderFlags BORDERFLAGS_ALL
Border on all sides.
LandscapeType
Landscape types.
@ Arctic
Landscape with snow levels.
@ Toyland
Landscape with funky industries and vehicles.
@ Tropic
Landscape with distinct rainforests and deserts,.
@ Temperate
Base landscape.
@ NorthWest
Border on North West.
@ Random
Randomise borders.
@ NorthEast
Border on North East.
@ SouthEast
Border on South East.
@ SouthWest
Border on South West.
#define Point
Macro that prevents name conflicts between included headers.
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
Definition map_type.h:37
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition map_type.h:40
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
Definition map_type.h:38
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:66
Basic functions/variables used all over the place.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
GRFConfigList _grfconfig_newgame
First item in list of default GRF set up.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
Setup the NewGRF gui.
Header of Action 0F "universal holder" structure and functions.
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Menu
In the main menu.
Definition openttd.h:19
SwitchMode
Mode which defines what mode we're switching to.
Definition openttd.h:26
@ StartHeightmap
Load a heightmap and start a new game from it.
Definition openttd.h:38
@ NewGame
New Game --> 'Random game'.
Definition openttd.h:28
@ Editor
Switch to scenario editor.
Definition openttd.h:31
@ GenerateRandomLand
Generate random land within scenario editor.
Definition openttd.h:36
@ LoadHeightmap
Load heightmap from scenario editor.
Definition openttd.h:39
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition progress.h:17
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:81
Functions related to saving and loading games.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:62
IndustryDensity
Available industry map generation densities.
@ End
Number of industry density settings.
@ Custom
Custom number of industries.
BorderFlagPresets
Possible options for the Borders pulldown in the Genworld GUI.
GenworldAverageHeight
Possible options for the Average Height pulldown in the Genworld GUI.
GenworldMaxHeight
Possible options for the Maximum Height pulldown in the Genworld GUI.
void SndConfirmBeep()
Play a beep sound for a confirm event if enabled in settings.
Definition sound.cpp:260
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:252
Functions related to sound.
static const SpriteID SPR_SELECT_TEMPERATE
Definition sprites.h:1554
static const SpriteID SPR_SELECT_SUB_ARCTIC
Definition sprites.h:1556
static const SpriteID SPR_ARROW_DOWN
Definition sprites.h:85
static const SpriteID SPR_SELECT_TOYLAND
Definition sprites.h:1560
static const SpriteID SPR_ARROW_UP
Definition sprites.h:86
static const SpriteID SPR_SELECT_SUB_TROPICAL
Definition sprites.h:1558
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:261
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:235
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
static constexpr uint16_t BUILTIN_TOWNNAME_GENERATOR_COUNT
The number of builtin generators for town names.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
void OnTimeout() override
Called when this window's timeout has been reached.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static constexpr size_t MAX_SIZE
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
High level window description.
Definition window_gui.h:171
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:272
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3317
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:468
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:514
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
void RaiseWidgetsWhenLowered(Args... widgets)
Raises the widgets and sets widgets dirty that are lowered.
Definition window_gui.h:535
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:459
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition window.cpp:604
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1869
WindowFlags flags
Window flags.
Definition window_gui.h:299
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Definition textbuf_gui.h:20
static constexpr uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition tile_type.h:24
static constexpr uint MIN_CUSTOM_TERRAIN_TYPE
Lowest possible peak value for world generation.
Definition tile_type.h:27
static constexpr uint DEF_DESERT_COVERAGE
Default desert coverage.
Definition tile_type.h:37
static constexpr uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings).
Definition tile_type.h:29
static constexpr uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings).
Definition tile_type.h:30
static constexpr uint MIN_HEIGHTMAP_HEIGHT
Lowest possible peak value for heightmap creation.
Definition tile_type.h:26
static constexpr uint DEF_SNOW_COVERAGE
Default snow coverage.
Definition tile_type.h:36
Definition of the game-calendar-timer.
Base of the town class.
static const uint CUSTOM_TOWN_MAX_NUMBER
this is the maximum number of towns a user can specify in customisation
Definition town.h:30
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
Definition town.h:29
Base of all video drivers.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:308
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:42
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ EqualSize
Containers should keep all their (resizing) children equally large.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1326
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3439
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3255
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3395
Window functions not directly related to making/drawing windows.
@ NoClose
This window can't be interactively closed.
Definition window_gui.h:157
@ BorderOnly
Draw border only, no background.
Definition window_gui.h:25
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Definition window_gui.h:26
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Timeout
Window timeout counter.
Definition window_gui.h:223
@ Center
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:21
@ GameOptions
Game options.
Definition window_type.h:32