OpenTTD Source: src/genworld_gui.cpp Source File

OpenTTD Source 13.1

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 <http://www.gnu.org/licenses/>.
6 */
7
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 "date_func.h"
18 #include "sound_func.h"
19 #include "fios.h"
20 #include "string_func.h"
21 #include "widgets/dropdown_type.h"
22 #include "widgets/dropdown_func.h"
23 #include "querystring_gui.h"
24 #include "town.h"
25 #include "core/geometry_func.hpp"
26 #include "core/random_func.hpp"
27 #include "saveload/saveload.h"
28 #include "progress.h"
29 #include "error.h"
30 #include "newgrf_townname.h"
31 #include "townname_type.h"
32 #include "video/video_driver.hpp"
33 #include "ai/ai_gui.hpp"
34 #include "game/game_gui.hpp"
35 #include "industry.h"
36
37 #include "widgets/genworld_widget.h"
38
39 #include "safeguards.h"
40
41
42 extern void MakeNewgameSettingsLive();
43
45 enum GenerateLandscapeWindowMode {
46 GLWM_GENERATE,
47 GLWM_HEIGHTMAP,
48 GLWM_SCENARIO,
49 };
50
54 static uint GetMapHeightLimit()
55 {
56 if (_settings_newgame.construction.map_height_limit == 0) return MAX_MAP_HEIGHT_LIMIT;
57 return _settings_newgame.construction.map_height_limit;
58 }
59
64 void SetNewLandscapeType(byte landscape)
65 {
66 _settings_newgame.game_creation.landscape = landscape;
67 InvalidateWindowClassesData(WC_SELECT_GAME);
68 InvalidateWindowClassesData(WC_GENERATE_LANDSCAPE);
69 }
70
72 static const NWidgetPart _nested_generate_landscape_widgets[] = {
73 NWidget(NWID_HORIZONTAL),
74 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
75 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
76 EndContainer(),
77 NWidget(WWT_PANEL, COLOUR_BROWN),
78 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
79 /* Landscape selection. */
80 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
81 NWidget(NWID_SPACER), SetFill(1, 0),
82 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
83 NWidget(NWID_SPACER), SetFill(1, 0),
84 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
85 NWidget(NWID_SPACER), SetFill(1, 0),
86 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
87 NWidget(NWID_SPACER), SetFill(1, 0),
88 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
89 NWidget(NWID_SPACER), SetFill(1, 0),
90 EndContainer(),
91 NWidget(NWID_SPACER), SetMinimalSize(0, 11),
92 /* Generation options. */
93 NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
94 /* Left half (land generation options) */
95 NWidget(NWID_VERTICAL),
96 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
97 /* Labels on the left side (global column 1). */
98 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
99 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
100 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_LAND_GENERATOR, STR_NULL), SetFill(1, 1),
101 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
102 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_VARIETY, STR_NULL), SetFill(1, 1),
103 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
104 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
105 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BORDER_TYPE, STR_NULL), SetFill(1, 1),
106 EndContainer(),
107 /* Widgets on the right side (global column 2). */
108 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
109 /* Mapsize X * Y. */
110 NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
111 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 0),
112 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
113 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 0),
114 EndContainer(),
115 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_LANDSCAPE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
116 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TERRAIN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
117 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_VARIETY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
118 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
119 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
120 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_BORDERS_RANDOM), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
121 EndContainer(),
122 EndContainer(),
123 EndContainer(),
124 /* Right half (all other options) */
125 NWidget(NWID_VERTICAL),
126 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
127 /* Labels on the left side (global column 3). */
128 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
129 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_LABEL),
130 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_COVERAGE, STR_NULL), SetFill(1, 1),
131 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DESERT_COVERAGE, STR_NULL), SetFill(1, 1),
132 NWidget(NWID_SPACER),
133 EndContainer(),
134 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
135 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TOWN_NAME_LABEL, STR_NULL), SetFill(1, 1),
136 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
137 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
138 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SEA_LEVEL, STR_NULL), SetFill(1, 1),
139 EndContainer(),
140 /* Widgets on the right side (global column 4). */
141 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
142 /* Climate selector. */
143 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_SELECTOR),
144 /* Snow coverage. */
145 NWidget(NWID_HORIZONTAL),
146 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN), SetFill(0, 1),
147 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_TEXT), SetDataTip(STR_MAPGEN_SNOW_COVERAGE_TEXT, STR_NULL), SetFill(1, 0),
148 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP), SetFill(0, 1),
149 EndContainer(),
150 /* Desert coverage. */
151 NWidget(NWID_HORIZONTAL),
152 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_COVERAGE_DOWN), SetFill(0, 1),
153 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_TEXT), SetDataTip(STR_MAPGEN_DESERT_COVERAGE_TEXT, STR_NULL), SetFill(1, 0),
154 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_COVERAGE_UP), SetFill(0, 1),
155 EndContainer(),
156 /* Temperate/Toyland spacer. */
157 NWidget(NWID_SPACER),
158 EndContainer(),
159 /* Starting date. */
160 NWidget(NWID_HORIZONTAL),
161 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
162 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
163 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
164 EndContainer(),
165 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWNNAME_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 0),
166 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
167 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
168 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_WATER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
169 EndContainer(),
170 EndContainer(),
171 EndContainer(),
172 EndContainer(),
173 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
174 /* Map borders buttons for each edge. */
175 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
176 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
177 NWidget(NWID_SPACER), SetFill(1, 1),
178 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
179 EndContainer(),
180 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
181 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
182 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
183 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
184 NWidget(NWID_SPACER), SetFill(1, 1),
185 EndContainer(),
186 EndContainer(),
187 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
188 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
189 NWidget(NWID_SPACER), SetFill(1, 1),
190 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
191 EndContainer(),
192 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
193 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
194 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
195 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
196 NWidget(NWID_SPACER), SetFill(1, 1),
197 EndContainer(),
198 EndContainer(),
199 NWidget(NWID_SPACER), SetMinimalSize(0, 6), SetFill(1, 1),
200 /* AI, GS, and NewGRF settings */
201 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
202 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_AI_BUTTON), SetMinimalSize(0, 24), SetDataTip(STR_MAPGEN_AI_SETTINGS, STR_MAPGEN_AI_SETTINGS_TOOLTIP), SetFill(1, 0),
203 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_GS_BUTTON), SetMinimalSize(0, 24), SetDataTip(STR_MAPGEN_GS_SETTINGS, STR_MAPGEN_GS_SETTINGS_TOOLTIP), SetFill(1, 0),
204 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_NEWGRF_BUTTON), SetMinimalSize(0, 24), SetDataTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0),
205 EndContainer(),
206 NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetFill(1, 1),
207 /* Generate */
208 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 36), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetPadding(0, 10, 0, 10), SetFill(1, 1),
209 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
210 EndContainer(),
211 };
212
214 static const NWidgetPart _nested_heightmap_load_widgets[] = {
215 /* Window header. */
216 NWidget(NWID_HORIZONTAL),
217 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
218 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
219 EndContainer(),
220 NWidget(WWT_PANEL, COLOUR_BROWN),
221 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
222 /* Landscape selection. */
223 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
224 NWidget(NWID_SPACER), SetFill(1, 0),
225 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
226 NWidget(NWID_SPACER), SetFill(1, 0),
227 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
228 NWidget(NWID_SPACER), SetFill(1, 0),
229 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
230 NWidget(NWID_SPACER), SetFill(1, 0),
231 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
232 NWidget(NWID_SPACER), SetFill(1, 0),
233 EndContainer(),
234 NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
235 /* Generation options. */
236 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
237 /* Left half labels (global column 1) and heightmap name label */
238 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
239 /* Heightmap name label. */
240 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
241 /* Land generation option labels */
242 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_NULL), SetFill(1, 1),
243 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
244 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
245 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_HEIGHT, STR_NULL), SetFill(1, 1),
246 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
247 EndContainer(),
248 /* All other columns. */
249 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
250 NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextColour(TC_ORANGE), SetDataTip(STR_JUST_RAW_STRING, STR_EMPTY), SetFill(1, 0),
251 NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
252 /* Left half widgets (global column 2) */
253 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
254 NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
255 /* Mapsize X * Y. */
256 NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
257 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
258 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
259 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
260 EndContainer(),
261 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
262 /* Heightmap highest peak. */
263 NWidget(NWID_HORIZONTAL),
264 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_HEIGHT_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_HEIGHTMAP_HEIGHT_DOWN), SetFill(0, 1),
265 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
266 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_HEIGHT_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_HEIGHTMAP_HEIGHT_UP), SetFill(0, 1),
267 EndContainer(),
268 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
269 EndContainer(),
270 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
271 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
272 /* Right half labels (global column 3) */
273 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
274 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_LABEL),
275 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_COVERAGE, STR_NULL), SetFill(1, 1),
276 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DESERT_COVERAGE, STR_NULL), SetFill(1, 1),
277 NWidget(NWID_SPACER),
278 EndContainer(),
279 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
280 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TOWN_NAME_LABEL, STR_NULL), SetFill(1, 1),
281 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
282 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
283 EndContainer(),
284 /* Right half widgets (global column 4) */
285 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
286 /* Climate selector. */
287 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_SELECTOR),
288 /* Snow coverage. */
289 NWidget(NWID_HORIZONTAL),
290 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN), SetFill(0, 1),
291 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_TEXT), SetDataTip(STR_MAPGEN_SNOW_COVERAGE_TEXT, STR_NULL), SetFill(1, 0),
292 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP), SetFill(0, 1),
293 EndContainer(),
294 /* Desert coverage. */
295 NWidget(NWID_HORIZONTAL),
296 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_COVERAGE_DOWN), SetFill(0, 1),
297 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_TEXT), SetDataTip(STR_MAPGEN_DESERT_COVERAGE_TEXT, STR_NULL), SetFill(1, 0),
298 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_COVERAGE_UP), SetFill(0, 1),
299 EndContainer(),
300 /* Temperate/Toyland spacer. */
301 NWidget(NWID_SPACER),
302 EndContainer(),
303 /* Starting date. */
304 NWidget(NWID_HORIZONTAL),
305 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
306 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
307 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
308 EndContainer(),
309 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWNNAME_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 0),
310 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
311 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
312 EndContainer(),
313 EndContainer(),
314 EndContainer(),
315 EndContainer(),
316 EndContainer(),
317 EndContainer(),
318 NWidget(NWID_SPACER), SetMinimalSize(0, 6), SetFill(1, 1),
319 /* AI, GS, and NewGRF settings */
320 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
321 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_AI_BUTTON), SetMinimalSize(0, 24), SetDataTip(STR_MAPGEN_AI_SETTINGS, STR_MAPGEN_AI_SETTINGS_TOOLTIP), SetFill(1, 0),
322 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_GS_BUTTON), SetMinimalSize(0, 24), SetDataTip(STR_MAPGEN_GS_SETTINGS, STR_MAPGEN_GS_SETTINGS_TOOLTIP), SetFill(1, 0),
323 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_NEWGRF_BUTTON), SetMinimalSize(0, 24), SetDataTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0),
324 EndContainer(),
325 NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetFill(1, 1),
326 /* Generate */
327 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 36), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetPadding(0, 10, 0, 10), SetFill(1, 1),
328 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
329 EndContainer(),
330 };
331
332 static void StartGeneratingLandscape(GenerateLandscapeWindowMode mode)
333 {
334 CloseAllNonVitalWindows();
335 ClearErrorMessages();
336
337 /* Copy all XXX_newgame to XXX when coming from outside the editor */
338 MakeNewgameSettingsLive();
339 ResetGRFConfig(true);
340
341 if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
342 switch (mode) {
343 case GLWM_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break;
344 case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
345 case GLWM_SCENARIO: _switch_mode = SM_EDITOR; break;
346 default: NOT_REACHED();
347 }
348 }
349
350 static void LandscapeGenerationCallback(Window *w, bool confirmed)
351 {
352 if (confirmed) StartGeneratingLandscape((GenerateLandscapeWindowMode)w->window_number);
353 }
354
355 static DropDownList BuildMapsizeDropDown()
356 {
357 DropDownList list;
358
359 for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
360 DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
361 item->SetParam(0, 1LL << i);
362 list.emplace_back(item);
363 }
364
365 return list;
366 }
367
368 static DropDownList BuildTownNameDropDown()
369 {
370 DropDownList list;
371
372 /* Add and sort newgrf townnames generators */
373 const auto &grf_names = GetGRFTownNameList();
374 for (uint i = 0; i < grf_names.size(); i++) {
375 list.emplace_back(new DropDownListStringItem(grf_names[i], BUILTIN_TOWNNAME_GENERATOR_COUNT + i, false));
376 }
377 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
378
379 size_t newgrf_size = list.size();
380 /* Insert newgrf_names at the top of the list */
381 if (newgrf_size > 0) {
382 list.emplace_back(new DropDownListItem(-1, false)); // separator line
383 newgrf_size++;
384 }
385
386 /* Add and sort original townnames generators */
387 for (uint i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) {
388 list.emplace_back(new DropDownListStringItem(STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + i, i, false));
389 }
390 std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
391
392 return list;
393 }
394
395
396 static const StringID _elevations[] = {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, INVALID_STRING_ID};
397 static 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, INVALID_STRING_ID};
398 static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
399 static 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, INVALID_STRING_ID};
400 static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
401 static const StringID _landscape[] = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
402 static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
403 static 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, INVALID_STRING_ID};
404 static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID};
405
406 static_assert(lengthof(_num_inds) == ID_END + 1);
407
408 struct GenerateLandscapeWindow : public Window {
409 uint widget_id;
410 uint x;
411 uint y;
412 char name[64];
413 GenerateLandscapeWindowMode mode;
414
415 GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc)
416 {
417 this->InitNested(number);
418
419 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_GL_TEMPERATE);
420
421 this->mode = (GenerateLandscapeWindowMode)this->window_number;
422
423 /* Disable town and industry in SE */
424 this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
425 this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
426
427 /* In case the map_height_limit is changed, clamp heightmap_height and custom_terrain_type. */
428 _settings_newgame.game_creation.heightmap_height = Clamp(_settings_newgame.game_creation.heightmap_height, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
429 _settings_newgame.game_creation.custom_terrain_type = Clamp(_settings_newgame.game_creation.custom_terrain_type, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
430
431 this->OnInvalidateData();
432 }
433
434
435 void SetStringParameters(int widget) const override
436 {
437 switch (widget) {
438 case WID_GL_START_DATE_TEXT: SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
439 case WID_GL_MAPSIZE_X_PULLDOWN: SetDParam(0, 1LL << _settings_newgame.game_creation.map_x); break;
440 case WID_GL_MAPSIZE_Y_PULLDOWN: SetDParam(0, 1LL << _settings_newgame.game_creation.map_y); break;
441 case WID_GL_HEIGHTMAP_HEIGHT_TEXT: SetDParam(0, _settings_newgame.game_creation.heightmap_height); break;
442 case WID_GL_SNOW_COVERAGE_TEXT: SetDParam(0, _settings_newgame.game_creation.snow_coverage); break;
443 case WID_GL_DESERT_COVERAGE_TEXT: SetDParam(0, _settings_newgame.game_creation.desert_coverage); break;
444
445 case WID_GL_TOWN_PULLDOWN:
446 if (_game_mode == GM_EDITOR) {
447 SetDParam(0, STR_CONFIG_SETTING_OFF);
448 } else if (_settings_newgame.difficulty.number_towns == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
449 SetDParam(0, STR_NUM_CUSTOM_NUMBER);
450 SetDParam(1, _settings_newgame.game_creation.custom_town_number);
451 } else {
452 SetDParam(0, _num_towns[_settings_newgame.difficulty.number_towns]);
453 }
454 break;
455
456 case WID_GL_TOWNNAME_DROPDOWN: {
457 uint gen = _settings_newgame.game_creation.town_name;
458 StringID name = gen < BUILTIN_TOWNNAME_GENERATOR_COUNT ?
459 STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + gen :
460 GetGRFTownNameName(gen - BUILTIN_TOWNNAME_GENERATOR_COUNT);
461 SetDParam(0, name);
462 break;
463 }
464
465 case WID_GL_INDUSTRY_PULLDOWN:
466 if (_game_mode == GM_EDITOR) {
467 SetDParam(0, STR_CONFIG_SETTING_OFF);
468 } else if (_settings_newgame.difficulty.industry_density == ID_CUSTOM) {
469 SetDParam(0, STR_NUM_CUSTOM_NUMBER);
470 SetDParam(1, _settings_newgame.game_creation.custom_industry_number);
471 } else {
472 SetDParam(0, _num_inds[_settings_newgame.difficulty.industry_density]);
473 }
474 break;
475
476 case WID_GL_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
477
478 case WID_GL_TERRAIN_PULLDOWN:
479 if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
480 SetDParam(0, STR_TERRAIN_TYPE_CUSTOM_VALUE);
481 SetDParam(1, _settings_newgame.game_creation.custom_terrain_type);
482 } else {
483 SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
484 }
485 break;
486
487 case WID_GL_WATER_PULLDOWN:
488 if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
489 SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
490 SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
491 } else {
492 SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
493 }
494 break;
495
496 case WID_GL_HEIGHTMAP_NAME_TEXT: SetDParamStr(0, this->name); break;
497 case WID_GL_RIVER_PULLDOWN: SetDParam(0, _rivers[_settings_newgame.game_creation.amount_of_rivers]); break;
498 case WID_GL_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
499 case WID_GL_VARIETY_PULLDOWN: SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
500 case WID_GL_BORDERS_RANDOM: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
501 case WID_GL_WATER_NE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
502 case WID_GL_WATER_NW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
503 case WID_GL_WATER_SE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
504 case WID_GL_WATER_SW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
505 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: SetDParam(0, _rotation[_settings_newgame.game_creation.heightmap_rotation]); break;
506
507 case WID_GL_HEIGHTMAP_SIZE_TEXT:
508 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
509 SetDParam(0, this->y);
510 SetDParam(1, this->x);
511 } else {
512 SetDParam(0, this->x);
513 SetDParam(1, this->y);
514 }
515 break;
516 }
517 }
518
524 void OnInvalidateData(int data = 0, bool gui_scope = true) override
525 {
526 if (!gui_scope) return;
527 /* Update the climate buttons */
528 this->SetWidgetLoweredState(WID_GL_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
529 this->SetWidgetLoweredState(WID_GL_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
530 this->SetWidgetLoweredState(WID_GL_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
531 this->SetWidgetLoweredState(WID_GL_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
532
533 /* You can't select smoothness / non-water borders if not terragenesis */
534 if (mode == GLWM_GENERATE) {
535 this->SetWidgetDisabledState(WID_GL_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == LG_ORIGINAL);
536 this->SetWidgetDisabledState(WID_GL_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == LG_ORIGINAL);
537 this->SetWidgetDisabledState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges);
538 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
539 WID_GL_WATER_NW, WID_GL_WATER_NE, WID_GL_WATER_SE, WID_GL_WATER_SW, WIDGET_LIST_END);
540
541 this->SetWidgetLoweredState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
542
543 this->SetWidgetLoweredState(WID_GL_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
544 this->SetWidgetLoweredState(WID_GL_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
545 this->SetWidgetLoweredState(WID_GL_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
546 this->SetWidgetLoweredState(WID_GL_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
547
548 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL && (_settings_newgame.game_creation.landscape == LT_ARCTIC || _settings_newgame.game_creation.landscape == LT_TROPIC),
549 WID_GL_TERRAIN_PULLDOWN, WID_GL_WATER_PULLDOWN, WIDGET_LIST_END);
550 }
551
552 /* Disable snowline if not arctic */
553 this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
554 /* Disable desert if not tropic */
555 this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_TEXT, _settings_newgame.game_creation.landscape != LT_TROPIC);
556
557 /* Set snow/rainforest selections */
558 int climate_plane = 0;
559 switch (_settings_newgame.game_creation.landscape) {
560 case LT_TEMPERATE: climate_plane = 2; break;
561 case LT_ARCTIC: climate_plane = 0; break;
562 case LT_TROPIC: climate_plane = 1; break;
563 case LT_TOYLAND: climate_plane = 2; break;
564 }
565 this->GetWidget<NWidgetStacked>(WID_GL_CLIMATE_SEL_LABEL)->SetDisplayedPlane(climate_plane);
566 this->GetWidget<NWidgetStacked>(WID_GL_CLIMATE_SEL_SELECTOR)->SetDisplayedPlane(climate_plane);
567
568 /* Update availability of decreasing / increasing start date and snow level */
569 if (mode == GLWM_HEIGHTMAP) {
570 this->SetWidgetDisabledState(WID_GL_HEIGHTMAP_HEIGHT_DOWN, _settings_newgame.game_creation.heightmap_height <= MIN_HEIGHTMAP_HEIGHT);
571 this->SetWidgetDisabledState(WID_GL_HEIGHTMAP_HEIGHT_UP, _settings_newgame.game_creation.heightmap_height >= GetMapHeightLimit());
572 }
573 this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
574 this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
575 this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_DOWN, _settings_newgame.game_creation.snow_coverage <= 0 || _settings_newgame.game_creation.landscape != LT_ARCTIC);
576 this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_UP, _settings_newgame.game_creation.snow_coverage >= 100 || _settings_newgame.game_creation.landscape != LT_ARCTIC);
577 this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_DOWN, _settings_newgame.game_creation.desert_coverage <= 0 || _settings_newgame.game_creation.landscape != LT_TROPIC);
578 this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_UP, _settings_newgame.game_creation.desert_coverage >= 100 || _settings_newgame.game_creation.landscape != LT_TROPIC);
579
580 /* Do not allow a custom sea level or terrain type with the original land generator. */
581 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
582 if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
583 _settings_newgame.difficulty.quantity_sea_lakes = 1;
584 }
585 if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
586 _settings_newgame.difficulty.terrain_type = 1;
587 }
588 }
589
590 }
591
592 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
593 {
594 const StringID *strs = nullptr;
595 switch (widget) {
596 case WID_GL_HEIGHTMAP_HEIGHT_TEXT:
597 SetDParam(0, MAX_TILE_HEIGHT);
598 *size = GetStringBoundingBox(STR_JUST_INT);
599 break;
600
601 case WID_GL_START_DATE_TEXT:
602 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
603 *size = maxdim(*size, GetStringBoundingBox(STR_BLACK_DATE_LONG));
604 break;
605
606 case WID_GL_MAPSIZE_X_PULLDOWN:
607 case WID_GL_MAPSIZE_Y_PULLDOWN:
608 SetDParamMaxValue(0, MAX_MAP_SIZE);
609 *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
610 break;
611
612 case WID_GL_SNOW_COVERAGE_TEXT:
613 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
614 *size = maxdim(*size, GetStringBoundingBox(STR_MAPGEN_SNOW_COVERAGE_TEXT));
615 break;
616
617 case WID_GL_DESERT_COVERAGE_TEXT:
618 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
619 *size = maxdim(*size, GetStringBoundingBox(STR_MAPGEN_DESERT_COVERAGE_TEXT));
620 break;
621
622 case WID_GL_HEIGHTMAP_SIZE_TEXT:
623 SetDParam(0, this->x);
624 SetDParam(1, this->y);
625 *size = maxdim(*size, GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE));
626 break;
627
628 case WID_GL_TOWN_PULLDOWN:
629 strs = _num_towns;
630 SetDParamMaxValue(0, CUSTOM_TOWN_MAX_NUMBER);
631 *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
632 break;
633
634 case WID_GL_INDUSTRY_PULLDOWN:
635 strs = _num_inds;
636 SetDParamMaxValue(0, IndustryPool::MAX_SIZE);
637 *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
638 break;
639
640 case WID_GL_LANDSCAPE_PULLDOWN: strs = _landscape; break;
641
642 case WID_GL_TERRAIN_PULLDOWN:
643 strs = _elevations;
644 SetDParamMaxValue(0, MAX_MAP_HEIGHT_LIMIT);
645 *size = maxdim(*size, GetStringBoundingBox(STR_TERRAIN_TYPE_CUSTOM_VALUE));
646 break;
647
648 case WID_GL_WATER_PULLDOWN:
649 strs = _sea_lakes;
650 SetDParamMaxValue(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
651 *size = maxdim(*size, GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE));
652 break;
653
654 case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
655 case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
656 case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
657 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
658 case WID_GL_BORDERS_RANDOM:
659 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
660 break;
661
662 case WID_GL_WATER_NE:
663 case WID_GL_WATER_NW:
664 case WID_GL_WATER_SE:
665 case WID_GL_WATER_SW:
666 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
667 break;
668
669 case WID_GL_HEIGHTMAP_NAME_TEXT:
670 size->width = 0;
671 break;
672
673 default:
674 return;
675 }
676 if (strs != nullptr) {
677 while (*strs != INVALID_STRING_ID) {
678 *size = maxdim(*size, GetStringBoundingBox(*strs++));
679 }
680 }
681 size->width += padding.width;
682 size->height = std::max(size->height, (uint)(FONT_HEIGHT_NORMAL + padding.height));
683 }
684
685 void OnClick(Point pt, int widget, int click_count) override
686 {
687 switch (widget) {
688 case WID_GL_TEMPERATE:
689 case WID_GL_ARCTIC:
690 case WID_GL_TROPICAL:
691 case WID_GL_TOYLAND:
692 SetNewLandscapeType(widget - WID_GL_TEMPERATE);
693 break;
694
695 case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
696 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
697 break;
698
699 case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
700 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
701 break;
702
703 case WID_GL_TOWN_PULLDOWN: // Number of towns
704 ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
705 break;
706
707 case WID_GL_TOWNNAME_DROPDOWN: // Townname generator
708 ShowDropDownList(this, BuildTownNameDropDown(), _settings_newgame.game_creation.town_name, WID_GL_TOWNNAME_DROPDOWN);
709 break;
710
711 case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
712 ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
713 break;
714
715 case WID_GL_GENERATE_BUTTON: { // Generate
716 /* Get rotated map size. */
717 uint map_x;
718 uint map_y;
719 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
720 map_x = this->y;
721 map_y = this->x;
722 } else {
723 map_x = this->x;
724 map_y = this->y;
725 }
726 if (mode == GLWM_HEIGHTMAP &&
727 (map_x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
728 map_x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
729 map_y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
730 map_y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
731 ShowQuery(
732 STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
733 STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
734 this,
735 LandscapeGenerationCallback);
736 } else {
737 StartGeneratingLandscape(mode);
738 }
739 break;
740 }
741
742 case WID_GL_HEIGHTMAP_HEIGHT_DOWN:
743 case WID_GL_HEIGHTMAP_HEIGHT_UP: // Height level buttons
744 /* Don't allow too fast scrolling */
745 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
746 this->HandleButtonClick(widget);
747
748 _settings_newgame.game_creation.heightmap_height = Clamp(_settings_newgame.game_creation.heightmap_height + widget - WID_GL_HEIGHTMAP_HEIGHT_TEXT, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
749 this->InvalidateData();
750 }
751 _left_button_clicked = false;
752 break;
753
754 case WID_GL_HEIGHTMAP_HEIGHT_TEXT: // Height level text
755 this->widget_id = WID_GL_HEIGHTMAP_HEIGHT_TEXT;
756 SetDParam(0, _settings_newgame.game_creation.heightmap_height);
757 ShowQueryString(STR_JUST_INT, STR_MAPGEN_HEIGHTMAP_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
758 break;
759
760
761 case WID_GL_START_DATE_DOWN:
762 case WID_GL_START_DATE_UP: // Year buttons
763 /* Don't allow too fast scrolling */
764 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
765 this->HandleButtonClick(widget);
766
767 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
768 this->InvalidateData();
769 }
770 _left_button_clicked = false;
771 break;
772
773 case WID_GL_START_DATE_TEXT: // Year text
774 this->widget_id = WID_GL_START_DATE_TEXT;
775 SetDParam(0, _settings_newgame.game_creation.starting_year);
776 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
777 break;
778
779 case WID_GL_SNOW_COVERAGE_DOWN:
780 case WID_GL_SNOW_COVERAGE_UP: // Snow coverage buttons
781 /* Don't allow too fast scrolling */
782 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
783 this->HandleButtonClick(widget);
784
785 _settings_newgame.game_creation.snow_coverage = Clamp(_settings_newgame.game_creation.snow_coverage + (widget - WID_GL_SNOW_COVERAGE_TEXT) * 10, 0, 100);
786 this->InvalidateData();
787 }
788 _left_button_clicked = false;
789 break;
790
791 case WID_GL_SNOW_COVERAGE_TEXT: // Snow coverage text
792 this->widget_id = WID_GL_SNOW_COVERAGE_TEXT;
793 SetDParam(0, _settings_newgame.game_creation.snow_coverage);
794 ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
795 break;
796
797 case WID_GL_DESERT_COVERAGE_DOWN:
798 case WID_GL_DESERT_COVERAGE_UP: // Desert coverage buttons
799 /* Don't allow too fast scrolling */
800 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
801 this->HandleButtonClick(widget);
802
803 _settings_newgame.game_creation.desert_coverage = Clamp(_settings_newgame.game_creation.desert_coverage + (widget - WID_GL_DESERT_COVERAGE_TEXT) * 10, 0, 100);
804 this->InvalidateData();
805 }
806 _left_button_clicked = false;
807 break;
808
809 case WID_GL_DESERT_COVERAGE_TEXT: // Desert line text
810 this->widget_id = WID_GL_DESERT_COVERAGE_TEXT;
811 SetDParam(0, _settings_newgame.game_creation.desert_coverage);
812 ShowQueryString(STR_JUST_INT, STR_MAPGEN_DESERT_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
813 break;
814
815 case WID_GL_LANDSCAPE_PULLDOWN: // Landscape generator
816 ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, WID_GL_LANDSCAPE_PULLDOWN, 0, 0);
817 break;
818
819 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
820 ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
821 break;
822
823 case WID_GL_TERRAIN_PULLDOWN: // Terrain type
824 /* For the original map generation only the first four are valid. */
825 ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, WID_GL_TERRAIN_PULLDOWN, 0, _settings_newgame.game_creation.land_generator == LG_ORIGINAL ? ~0xF : 0);
826 break;
827
828 case WID_GL_WATER_PULLDOWN: { // Water quantity
829 uint32 hidden_mask = 0;
830 /* Disable custom water level when the original map generator is active. */
831 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
832 SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
833 }
834 ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
835 break;
836 }
837
838 case WID_GL_RIVER_PULLDOWN: // Amount of rivers
839 ShowDropDownMenu(this, _rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
840 break;
841
842 case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
843 ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
844 break;
845
846 case WID_GL_VARIETY_PULLDOWN: // Map variety
847 ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
848 break;
849
850 /* Freetype map borders */
851 case WID_GL_WATER_NW:
852 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
853 this->InvalidateData();
854 break;
855
856 case WID_GL_WATER_NE:
857 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
858 this->InvalidateData();
859 break;
860
861 case WID_GL_WATER_SE:
862 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
863 this->InvalidateData();
864 break;
865
866 case WID_GL_WATER_SW:
867 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
868 this->InvalidateData();
869 break;
870
871 case WID_GL_BORDERS_RANDOM:
872 _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
873 this->InvalidateData();
874 break;
875
876 case WID_GL_AI_BUTTON:
877 ShowAIConfigWindow();
878 break;
879
880 case WID_GL_GS_BUTTON:
881 ShowGSConfigWindow();
882 break;
883
884 case WID_GL_NEWGRF_BUTTON:
885 ShowNewGRFSettings(true, true, false, &_grfconfig_newgame);
886 break;
887 }
888 }
889
890 void OnTimeout() override
891 {
892 static const int newgame_raise_widgets[] = {WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN, WIDGET_LIST_END};
893 static const int heightmap_raise_widgets[] = {WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN, WIDGET_LIST_END};
894
895 const int *widget = (mode == GLWM_HEIGHTMAP) ? heightmap_raise_widgets : newgame_raise_widgets;
896
897 for (; *widget != WIDGET_LIST_END; widget++) {
898 if (this->IsWidgetLowered(*widget)) {
899 this->RaiseWidget(*widget);
900 this->SetWidgetDirty(*widget);
901 }
902 }
903 }
904
905 void OnDropdownSelect(int widget, int index) override
906 {
907 switch (widget) {
908 case WID_GL_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
909 case WID_GL_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
910 case WID_GL_RIVER_PULLDOWN: _settings_newgame.game_creation.amount_of_rivers = index; break;
911 case WID_GL_SMOOTHNESS_PULLDOWN: _settings_newgame.game_creation.tgen_smoothness = index; break;
912 case WID_GL_VARIETY_PULLDOWN: _settings_newgame.game_creation.variety = index; break;
913
914 case WID_GL_LANDSCAPE_PULLDOWN: _settings_newgame.game_creation.land_generator = index;
915 /* If original landgenerator is selected and alpinist terrain_type was selected, revert to mountainous. */
916 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
917 _settings_newgame.difficulty.terrain_type = Clamp(_settings_newgame.difficulty.terrain_type, 0, 3);
918 }
919 break;
920
921 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
922
923 case WID_GL_TOWN_PULLDOWN:
924 if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
925 this->widget_id = widget;
926 SetDParam(0, _settings_newgame.game_creation.custom_town_number);
927 ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE);
928 }
929 _settings_newgame.difficulty.number_towns = index;
930 break;
931
932 case WID_GL_TOWNNAME_DROPDOWN: // Town names
933 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
934 _settings_newgame.game_creation.town_name = index;
935 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
936 }
937 break;
938
939 case WID_GL_INDUSTRY_PULLDOWN:
940 if ((uint)index == ID_CUSTOM) {
941 this->widget_id = widget;
942 SetDParam(0, _settings_newgame.game_creation.custom_industry_number);
943 ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_INDUSTRIES, 5, this, CS_NUMERAL, QSF_NONE);
944 }
945 _settings_newgame.difficulty.industry_density = index;
946 break;
947
948 case WID_GL_TERRAIN_PULLDOWN: {
949 if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
950 this->widget_id = widget;
951 SetDParam(0, _settings_newgame.game_creation.custom_terrain_type);
952 ShowQueryString(STR_JUST_INT, STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
953 }
954 _settings_newgame.difficulty.terrain_type = index;
955 break;
956 }
957
958 case WID_GL_WATER_PULLDOWN: {
959 if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
960 this->widget_id = widget;
961 SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
962 ShowQueryString(STR_JUST_INT, STR_MAPGEN_SEA_LEVEL, 3, this, CS_NUMERAL, QSF_NONE);
963 }
964 _settings_newgame.difficulty.quantity_sea_lakes = index;
965 break;
966 }
967 }
968 this->InvalidateData();
969 }
970
971 void OnQueryTextFinished(char *str) override
972 {
973 /* Was 'cancel' pressed? */
974 if (str == nullptr) return;
975
976 int32 value;
977 if (!StrEmpty(str)) {
978 value = atoi(str);
979 } else {
980 /* An empty string means revert to the default */
981 switch (this->widget_id) {
982 case WID_GL_HEIGHTMAP_HEIGHT_TEXT: value = MAP_HEIGHT_LIMIT_AUTO_MINIMUM; break;
983 case WID_GL_START_DATE_TEXT: value = DEF_START_YEAR; break;
984 case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break;
985 case WID_GL_DESERT_COVERAGE_TEXT: value = DEF_DESERT_COVERAGE; break;
986 case WID_GL_TOWN_PULLDOWN: value = 1; break;
987 case WID_GL_INDUSTRY_PULLDOWN: value = 1; break;
988 case WID_GL_TERRAIN_PULLDOWN: value = MIN_MAP_HEIGHT_LIMIT; break;
989 case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
990 default: NOT_REACHED();
991 }
992 }
993
994 switch (this->widget_id) {
995 case WID_GL_HEIGHTMAP_HEIGHT_TEXT:
996 this->SetWidgetDirty(WID_GL_HEIGHTMAP_HEIGHT_TEXT);
997 _settings_newgame.game_creation.heightmap_height = Clamp(value, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
998 break;
999
1000 case WID_GL_START_DATE_TEXT:
1001 this->SetWidgetDirty(WID_GL_START_DATE_TEXT);
1002 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
1003 break;
1004
1005 case WID_GL_SNOW_COVERAGE_TEXT:
1006 this->SetWidgetDirty(WID_GL_SNOW_COVERAGE_TEXT);
1007 _settings_newgame.game_creation.snow_coverage = Clamp(value, 0, 100);
1008 break;
1009
1010 case WID_GL_DESERT_COVERAGE_TEXT:
1011 this->SetWidgetDirty(WID_GL_DESERT_COVERAGE_TEXT);
1012 _settings_newgame.game_creation.desert_coverage = Clamp(value, 0, 100);
1013 break;
1014
1015 case WID_GL_TOWN_PULLDOWN:
1016 _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
1017 break;
1018
1019 case WID_GL_INDUSTRY_PULLDOWN:
1020 _settings_newgame.game_creation.custom_industry_number = Clamp(value, 1, IndustryPool::MAX_SIZE);
1021 break;
1022
1023 case WID_GL_TERRAIN_PULLDOWN:
1024 _settings_newgame.game_creation.custom_terrain_type = Clamp(value, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
1025 break;
1026
1027 case WID_GL_WATER_PULLDOWN:
1028 _settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
1029 break;
1030 }
1031
1032 this->InvalidateData();
1033 }
1034 };
1035
1036 static WindowDesc _generate_landscape_desc(
1037 WDP_CENTER, nullptr, 0, 0,
1038 WC_GENERATE_LANDSCAPE, WC_NONE,
1039 0,
1040 _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
1041 );
1042
1043 static WindowDesc _heightmap_load_desc(
1044 WDP_CENTER, nullptr, 0, 0,
1045 WC_GENERATE_LANDSCAPE, WC_NONE,
1046 0,
1047 _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
1048 );
1049
1050 static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
1051 {
1052 uint x = 0;
1053 uint y = 0;
1054
1055 CloseWindowByClass(WC_GENERATE_LANDSCAPE);
1056
1057 /* Generate a new seed when opening the window */
1058 _settings_newgame.game_creation.generation_seed = InteractiveRandom();
1059
1060 if (mode == GLWM_HEIGHTMAP) {
1061 /* If the function returns negative, it means there was a problem loading the heightmap */
1062 if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name.c_str(), &x, &y)) return;
1063 }
1064
1065 WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;
1066 GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
1067
1068 if (mode == GLWM_HEIGHTMAP) {
1069 w->x = x;
1070 w->y = y;
1071 strecpy(w->name, _file_to_saveload.title, lastof(w->name));
1072 }
1073
1074 SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
1075 }
1076
1078 void ShowGenerateLandscape()
1079 {
1080 _ShowGenerateLandscape(GLWM_GENERATE);
1081 }
1082
1084 void ShowHeightmapLoad()
1085 {
1086 _ShowGenerateLandscape(GLWM_HEIGHTMAP);
1087 }
1088
1090 void StartScenarioEditor()
1091 {
1092 StartGeneratingLandscape(GLWM_SCENARIO);
1093 }
1094
1099 void StartNewGameWithoutGUI(uint32 seed)
1100 {
1101 /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
1102 _settings_newgame.game_creation.generation_seed = seed;
1103
1104 StartGeneratingLandscape(GLWM_GENERATE);
1105 }
1106
1107 struct CreateScenarioWindow : public Window
1108 {
1109 uint widget_id;
1110
1111 CreateScenarioWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
1112 {
1113 this->InitNested(window_number);
1114 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
1115 }
1116
1117 void SetStringParameters(int widget) const override
1118 {
1119 switch (widget) {
1120 case WID_CS_START_DATE_TEXT:
1121 SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
1122 break;
1123
1124 case WID_CS_MAPSIZE_X_PULLDOWN:
1125 SetDParam(0, 1LL << _settings_newgame.game_creation.map_x);
1126 break;
1127
1128 case WID_CS_MAPSIZE_Y_PULLDOWN:
1129 SetDParam(0, 1LL << _settings_newgame.game_creation.map_y);
1130 break;
1131
1132 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
1133 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
1134 break;
1135 }
1136 }
1137
1138 void OnPaint() override
1139 {
1140 this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
1141 this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
1142 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
1143 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP, _settings_newgame.game_creation.se_flat_world_height >= GetMapHeightLimit());
1144
1145 this->SetWidgetLoweredState(WID_CS_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
1146 this->SetWidgetLoweredState(WID_CS_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
1147 this->SetWidgetLoweredState(WID_CS_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
1148 this->SetWidgetLoweredState(WID_CS_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
1149
1150 this->DrawWidgets();
1151 }
1152
1153 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1154 {
1155 StringID str = STR_JUST_INT;
1156 switch (widget) {
1157 case WID_CS_START_DATE_TEXT:
1158 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
1159 str = STR_BLACK_DATE_LONG;
1160 break;
1161
1162 case WID_CS_MAPSIZE_X_PULLDOWN:
1163 case WID_CS_MAPSIZE_Y_PULLDOWN:
1164 SetDParamMaxValue(0, MAX_MAP_SIZE);
1165 break;
1166
1167 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
1168 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
1169 break;
1170
1171 default:
1172 return;
1173 }
1174 *size = maxdim(*size, GetStringBoundingBox(str));
1175 size->width += padding.width;
1176 size->height += padding.height;
1177 }
1178
1179 void OnClick(Point pt, int widget, int click_count) override
1180 {
1181 switch (widget) {
1182 case WID_CS_TEMPERATE:
1183 case WID_CS_ARCTIC:
1184 case WID_CS_TROPICAL:
1185 case WID_CS_TOYLAND:
1186 this->RaiseWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
1187 SetNewLandscapeType(widget - WID_CS_TEMPERATE);
1188 break;
1189
1190 case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
1191 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
1192 break;
1193
1194 case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
1195 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
1196 break;
1197
1198 case WID_CS_EMPTY_WORLD: // Empty world / flat world
1199 StartGeneratingLandscape(GLWM_SCENARIO);
1200 break;
1201
1202 case WID_CS_RANDOM_WORLD: // Generate
1203 ShowGenerateLandscape();
1204 break;
1205
1206 case WID_CS_START_DATE_DOWN:
1207 case WID_CS_START_DATE_UP: // Year buttons
1208 /* Don't allow too fast scrolling */
1209 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1210 this->HandleButtonClick(widget);
1211 this->SetDirty();
1212
1213 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
1214 }
1215 _left_button_clicked = false;
1216 break;
1217
1218 case WID_CS_START_DATE_TEXT: // Year text
1219 this->widget_id = WID_CS_START_DATE_TEXT;
1220 SetDParam(0, _settings_newgame.game_creation.starting_year);
1221 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE);
1222 break;
1223
1224 case WID_CS_FLAT_LAND_HEIGHT_DOWN:
1225 case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
1226 /* Don't allow too fast scrolling */
1227 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1228 this->HandleButtonClick(widget);
1229 this->SetDirty();
1230
1231 _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());
1232 }
1233 _left_button_clicked = false;
1234 break;
1235
1236 case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
1237 this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1238 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
1239 ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
1240 break;
1241 }
1242 }
1243
1244 void OnTimeout() override
1245 {
1246 static const int raise_widgets[] = {WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP, WIDGET_LIST_END};
1247 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
1248 if (this->IsWidgetLowered(*widget)) {
1249 this->RaiseWidget(*widget);
1250 this->SetWidgetDirty(*widget);
1251 }
1252 }
1253 }
1254
1255 void OnDropdownSelect(int widget, int index) override
1256 {
1257 switch (widget) {
1258 case WID_CS_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
1259 case WID_CS_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
1260 }
1261 this->SetDirty();
1262 }
1263
1264 void OnQueryTextFinished(char *str) override
1265 {
1266 if (!StrEmpty(str)) {
1267 int32 value = atoi(str);
1268
1269 switch (this->widget_id) {
1270 case WID_CS_START_DATE_TEXT:
1271 this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
1272 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
1273 break;
1274
1275 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
1276 this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
1277 _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMapHeightLimit());
1278 break;
1279 }
1280
1281 this->SetDirty();
1282 }
1283 }
1284 };
1285
1286 static const NWidgetPart _nested_create_scenario_widgets[] = {
1287 NWidget(NWID_HORIZONTAL),
1288 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1289 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
1290 EndContainer(),
1291 NWidget(WWT_PANEL, COLOUR_BROWN),
1292 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
1293 /* Landscape style selection. */
1294 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
1295 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
1296 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1297 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1298 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1299 EndContainer(),
1300 NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
1301 /* Green generation type buttons: 'Flat land' and 'Random land'. */
1302 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1303 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1304 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1305 EndContainer(),
1306 /* Labels + setting drop-downs */
1307 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1308 /* Map size. */
1309 NWidget(NWID_HORIZONTAL),
1310 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
1311 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1312 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
1313 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
1314 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
1315 EndContainer(),
1316 /* Date. */
1317 NWidget(NWID_HORIZONTAL),
1318 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
1319 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1320 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_START_DATE_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
1321 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
1322 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_START_DATE_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
1323 EndContainer(),
1324 /* Flat map height. */
1325 NWidget(NWID_HORIZONTAL),
1326 NWidget(WWT_TEXT, COLOUR_ORANGE),
1327 SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
1328 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1329 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN),
1330 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
1331 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP),
1332 EndContainer(),
1333 EndContainer(),
1334 EndContainer(),
1335 EndContainer(),
1336 };
1337
1338 static WindowDesc _create_scenario_desc(
1339 WDP_CENTER, nullptr, 0, 0,
1340 WC_GENERATE_LANDSCAPE, WC_NONE,
1341 0,
1342 _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
1343 );
1344
1346 void ShowCreateScenario()
1347 {
1348 CloseWindowByClass(WC_GENERATE_LANDSCAPE);
1349 new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
1350 }
1351
1352 static const NWidgetPart _nested_generate_progress_widgets[] = {
1353 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1354 NWidget(WWT_PANEL, COLOUR_GREY),
1355 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
1356 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
1357 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
1358 NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
1359 EndContainer(),
1360 EndContainer(),
1361 };
1362
1363
1364 static WindowDesc _generate_progress_desc(
1365 WDP_CENTER, nullptr, 0, 0,
1366 WC_MODAL_PROGRESS, WC_NONE,
1367 0,
1368 _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
1369 );
1370
1371 struct GenWorldStatus {
1372 uint percent;
1373 StringID cls;
1374 uint current;
1375 uint total;
1376 std::chrono::steady_clock::time_point next_update;
1377 };
1378
1379 static GenWorldStatus _gws;
1380
1381 static const StringID _generation_class_table[] = {
1382 STR_GENERATION_WORLD_GENERATION,
1383 STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
1384 STR_GENERATION_RIVER_GENERATION,
1385 STR_GENERATION_CLEARING_TILES,
1386 STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
1387 STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
1388 STR_GENERATION_OBJECT_GENERATION,
1389 STR_GENERATION_TREE_GENERATION,
1390 STR_GENERATION_SETTINGUP_GAME,
1391 STR_GENERATION_PREPARING_TILELOOP,
1392 STR_GENERATION_PREPARING_SCRIPT,
1393 STR_GENERATION_PREPARING_GAME
1394 };
1395 static_assert(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
1396
1397
1398 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
1399 {
1400 if (confirmed) {
1401 AbortGeneratingWorld();
1402 } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1403 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1404 }
1405 }
1406
1407 struct GenerateProgressWindow : public Window {
1408
1409 GenerateProgressWindow() : Window(&_generate_progress_desc)
1410 {
1411 this->InitNested();
1412 }
1413
1414 void OnClick(Point pt, int widget, int click_count) override
1415 {
1416 switch (widget) {
1417 case WID_GP_ABORT:
1418 SetMouseCursorBusy(false);
1419 ShowQuery(
1420 STR_GENERATION_ABORT_CAPTION,
1421 STR_GENERATION_ABORT_MESSAGE,
1422 this,
1423 AbortGeneratingWorldCallback
1424 );
1425 break;
1426 }
1427 }
1428
1429 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1430 {
1431 switch (widget) {
1432 case WID_GP_PROGRESS_BAR: {
1433 SetDParamMaxValue(0, 100);
1434 *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
1435 /* We need some spacing for the 'border' */
1436 size->height += WidgetDimensions::scaled.frametext.Horizontal();
1437 size->width += WidgetDimensions::scaled.frametext.Vertical();
1438 break;
1439 }
1440
1441 case WID_GP_PROGRESS_TEXT:
1442 for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
1443 size->width = std::max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
1444 }
1445 size->height = FONT_HEIGHT_NORMAL * 2 + WidgetDimensions::scaled.vsep_normal;
1446 break;
1447 }
1448 }
1449
1450 void DrawWidget(const Rect &r, int widget) const override
1451 {
1452 switch (widget) {
1453 case WID_GP_PROGRESS_BAR: {
1454 /* Draw the % complete with a bar and a text */
1455 DrawFrameRect(r, COLOUR_GREY, FR_BORDERONLY | FR_LOWERED);
1456 Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
1457 DrawFrameRect(br.WithWidth(br.Width() * _gws.percent / 100, false), COLOUR_MAUVE, FR_NONE);
1458 SetDParam(0, _gws.percent);
1459 DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, FONT_HEIGHT_NORMAL), STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
1460 break;
1461 }
1462
1463 case WID_GP_PROGRESS_TEXT:
1464 /* Tell which class we are generating */
1465 DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
1466
1467 /* And say where we are in that class */
1468 SetDParam(0, _gws.current);
1469 SetDParam(1, _gws.total);
1470 DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
1471 }
1472 }
1473 };
1474
1478 void PrepareGenerateWorldProgress()
1479 {
1480 _gws.cls = STR_GENERATION_WORLD_GENERATION;
1481 _gws.current = 0;
1482 _gws.total = 0;
1483 _gws.percent = 0;
1484 _gws.next_update = std::chrono::steady_clock::now();
1485 }
1486
1490 void ShowGenerateWorldProgress()
1491 {
1492 if (BringWindowToFrontById(WC_MODAL_PROGRESS, 0)) return;
1493 new GenerateProgressWindow();
1494 }
1495
1496 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1497 {
1498 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
1499 static_assert(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1500 assert(cls < GWP_CLASS_COUNT);
1501
1502 /* Check if we really are generating the world.
1503 * For example, placing trees via the SE also calls this function, but
1504 * shouldn't try to update the progress.
1505 */
1506 if (!HasModalProgress()) return;
1507
1508 if (IsGeneratingWorldAborted()) {
1509 HandleGeneratingWorldAbortion();
1510 return;
1511 }
1512
1513 if (total == 0) {
1514 assert(_gws.cls == _generation_class_table[cls]);
1515 _gws.current += progress;
1516 assert(_gws.current <= _gws.total);
1517 } else {
1518 _gws.cls = _generation_class_table[cls];
1519 _gws.current = progress;
1520 _gws.total = total;
1521 _gws.percent = percent_table[cls];
1522 }
1523
1524 /* Percentage is about the number of completed tasks, so 'current - 1' */
1525 _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
1526
1527 if (_network_dedicated) {
1528 static uint last_percent = 0;
1529
1530 /* Never display 0% */
1531 if (_gws.percent == 0) return;
1532 /* Reset if percent is lower than the last recorded */
1533 if (_gws.percent < last_percent) last_percent = 0;
1534 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1535 if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
1536 /* Never show steps smaller than 2%, even if it is a mod 5% */
1537 if (_gws.percent <= last_percent + 2) return;
1538
1539 Debug(net, 3, "Map generation percentage complete: {}", _gws.percent);
1540 last_percent = _gws.percent;
1541
1542 return;
1543 }
1544
1545 SetWindowDirty(WC_MODAL_PROGRESS, 0);
1546
1547 VideoDriver::GetInstance()->GameLoopPause();
1548 }
1549
1558 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
1559 {
1560 if (total == 0) return;
1561
1562 _SetGeneratingWorldProgress(cls, 0, total);
1563 }
1564
1572 void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
1573 {
1574 /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1575 _SetGeneratingWorldProgress(cls, 1, 0);
1576 }
FileToSaveLoad::title
char title[255]
Internal name of the game.
Definition: saveload.h:364
ShowNewGRFSettings
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
Definition: newgrf_gui.cpp:1999
WID_GL_SNOW_COVERAGE_DOWN
@ WID_GL_SNOW_COVERAGE_DOWN
Decrease snow coverage.
Definition: genworld_widget.h:37
SetMouseCursorBusy
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition: gfx.cpp:1908
sound_func.h
GameCreationSettings::generation_seed
uint32 generation_seed
noise seed for world generation
Definition: settings_type.h:312
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
GenerateProgressWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: genworld_gui.cpp:1450
SetNewLandscapeType
void SetNewLandscapeType(byte landscape)
Changes landscape type and sets genworld window dirty.
Definition: genworld_gui.cpp:64
Window::timeout_timer
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:243
WID_GL_DESERT_COVERAGE_UP
@ WID_GL_DESERT_COVERAGE_UP
Increase desert coverage.
Definition: genworld_widget.h:43
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3154
querystring_gui.h
DropDownListParamStringItem
String list item with parameters.
Definition: dropdown_type.h:56
SM_START_HEIGHTMAP
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition: openttd.h:37
GenerateProgressWindow
Definition: genworld_gui.cpp:1407
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
GameCreationSettings::custom_sea_level
byte custom_sea_level
manually entered percentage of water in the map
Definition: settings_type.h:334
ShowCreateScenario
void ShowCreateScenario()
Show the window to create a scenario.
Definition: genworld_gui.cpp:1346
AbortGeneratingWorld
void AbortGeneratingWorld()
Initializes the abortion process.
Definition: genworld.cpp:237
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1141
GameCreationSettings::map_y
uint8 map_y
Y size of map.
Definition: settings_type.h:316
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
ID_CUSTOM
@ ID_CUSTOM
Custom number of industries.
Definition: settings_type.h:61
GameCreationSettings::tgen_smoothness
byte tgen_smoothness
how rough is the terrain from 0-3
Definition: settings_type.h:323
WID_GP_PROGRESS_BAR
@ WID_GP_PROGRESS_BAR
Progress bar.
Definition: genworld_widget.h:91
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:48
WID_CS_TOYLAND
@ WID_CS_TOYLAND
Select toy-land landscape style.
Definition: genworld_widget.h:76
GenerateLandscapeWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: genworld_gui.cpp:905
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
WC_SELECT_GAME
@ WC_SELECT_GAME
Select game window; Window numbers:
Definition: window_type.h:435
WID_GL_TEMPERATE
@ WID_GL_TEMPERATE
Button with icon "Temperate".
Definition: genworld_widget.h:15
HM_CLOCKWISE
@ HM_CLOCKWISE
Rotate the map clockwise 45 degrees.
Definition: heightmap.h:21
SM_EDITOR
@ SM_EDITOR
Switch to scenario editor.
Definition: openttd.h:30
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:50
WID_CS_START_DATE_TEXT
@ WID_CS_START_DATE_TEXT
Clickable start date value.
Definition: genworld_widget.h:82
MIN_MAP_SIZE_BITS
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
Definition: map_type.h:63
FileToSaveLoad::name
std::string name
Name of the file.
Definition: saveload.h:363
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
ConstructionSettings::map_height_limit
uint8 map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:342
WID_GL_CLIMATE_SEL_SELECTOR
@ WID_GL_CLIMATE_SEL_SELECTOR
NWID_SELECTION for snow or desert coverage selector.
Definition: genworld_widget.h:68
WID_GL_WATER_SE
@ WID_GL_WATER_SE
SE 'Water'/'Freeform'.
Definition: genworld_widget.h:60
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
WID_CS_FLAT_LAND_HEIGHT_DOWN
@ WID_CS_FLAT_LAND_HEIGHT_DOWN
Decrease flat land height.
Definition: genworld_widget.h:84
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
LG_ORIGINAL
@ LG_ORIGINAL
The original landscape generator.
Definition: genworld.h:20
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:586
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ai_gui.hpp
GameCreationSettings::variety
byte variety
variety level applied to TGP
Definition: settings_type.h:332
WID_GL_HEIGHTMAP_SIZE_TEXT
@ WID_GL_HEIGHTMAP_SIZE_TEXT
Size of heightmap.
Definition: genworld_widget.h:48
GenerateProgressWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: genworld_gui.cpp:1414
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
saveload.h
GameCreationSettings::town_name
byte town_name
the town name generator used for town names
Definition: settings_type.h:327
WID_GL_HEIGHTMAP_ROTATION_PULLDOWN
@ WID_GL_HEIGHTMAP_ROTATION_PULLDOWN
Dropdown 'Heightmap rotation'.
Definition: genworld_widget.h:49
WC_GENERATE_LANDSCAPE
@ WC_GENERATE_LANDSCAPE
Generate landscape (newgame); Window numbers:
Definition: window_type.h:449
DropDownListItem
Base list item class from which others are derived.
Definition: dropdown_type.h:22
newgrf_townname.h
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
MIN_CUSTOM_TERRAIN_TYPE
static const uint MIN_CUSTOM_TERRAIN_TYPE
Lowest possible peak value for world generation.
Definition: tile_type.h:27
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
town.h
WID_GL_WATER_PULLDOWN
@ WID_GL_WATER_PULLDOWN
Dropdown 'Sea level'.
Definition: genworld_widget.h:52
CreateScenarioWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: genworld_gui.cpp:1179
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:34
MAX_TILE_HEIGHT
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition: tile_type.h:24
Window::HandleButtonClick
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:657
fios.h
WID_GL_HEIGHTMAP_HEIGHT_DOWN
@ WID_GL_HEIGHTMAP_HEIGHT_DOWN
Decrease heightmap highest mountain.
Definition: genworld_widget.h:29
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1810
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
WID_GL_TROPICAL
@ WID_GL_TROPICAL
Button with icon "Tropical".
Definition: genworld_widget.h:17
genworld.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
GameCreationSettings::heightmap_height
byte heightmap_height
highest mountain for heightmap (towards what it scales)
Definition: settings_type.h:322
WID_GL_START_DATE_UP
@ WID_GL_START_DATE_UP
Increase start year.
Definition: genworld_widget.h:35
WID_GL_TOYLAND
@ WID_GL_TOYLAND
Button with icon "Toyland".
Definition: genworld_widget.h:18
townname_type.h
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
CreateScenarioWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: genworld_gui.cpp:1153
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
_nested_heightmap_load_widgets
static const NWidgetPart _nested_heightmap_load_widgets[]
Widgets of GenerateLandscapeWindow when loading heightmap.
Definition: genworld_gui.cpp:214
WN_GAME_OPTIONS_GAME_OPTIONS
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition: window_type.h:19
WindowDesc
High level window description.
Definition: window_gui.h:102
Pool::MAX_SIZE
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:85
WC_MODAL_PROGRESS
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Definition: window_type.h:456
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:467
WID_GL_GENERATE_BUTTON
@ WID_GL_GENERATE_BUTTON
'Generate' button.
Definition: genworld_widget.h:27
PrepareGenerateWorldProgress
void PrepareGenerateWorldProgress()
Initializes the progress counters to the starting point.
Definition: genworld_gui.cpp:1478
heightmap.h
CUSTOM_TOWN_MAX_NUMBER
static const uint CUSTOM_TOWN_MAX_NUMBER
this is the maximum number of towns a user can specify in customisation
Definition: town.h:27
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:335
WID_GL_GS_BUTTON
@ WID_GL_GS_BUTTON
'Game Script Settings' button.
Definition: genworld_widget.h:64
WID_GL_BORDERS_RANDOM
@ WID_GL_BORDERS_RANDOM
'Random'/'Manual' borders.
Definition: genworld_widget.h:57
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
WID_GL_SMOOTHNESS_PULLDOWN
@ WID_GL_SMOOTHNESS_PULLDOWN
Dropdown 'Smoothness'.
Definition: genworld_widget.h:54
GenerateLandscapeWindowMode
GenerateLandscapeWindowMode
Enum for the modes we can generate in.
Definition: genworld_gui.cpp:45
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
SetMouseCursor
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition: gfx.cpp:1923
ShowGenerateLandscape
void ShowGenerateLandscape()
Start with a normal game.
Definition: genworld_gui.cpp:1078
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1800
SM_NEWGAME
@ SM_NEWGAME
New Game --> 'Random game'.
Definition: openttd.h:27
MIN_YEAR
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:84
MAX_MAP_HEIGHT_LIMIT
static const uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:30
DifficultySettings::terrain_type
byte terrain_type
the mountainousness of the landscape
Definition: settings_type.h:89
game_gui.hpp
GameCreationSettings::custom_town_number
uint16 custom_town_number
manually entered number of towns
Definition: settings_type.h:330
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
WID_GP_PROGRESS_TEXT
@ WID_GP_PROGRESS_TEXT
Text with the progress bar.
Definition: genworld_widget.h:92
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
WID_GL_MAPSIZE_Y_PULLDOWN
@ WID_GL_MAPSIZE_Y_PULLDOWN
Dropdown 'map Y size'.
Definition: genworld_widget.h:21
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
DEF_DESERT_COVERAGE
static const uint DEF_DESERT_COVERAGE
Default desert coverage.
Definition: tile_type.h:37
GameCreationSettings::water_borders
byte water_borders
bitset of the borders that are water
Definition: settings_type.h:329
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:450
WID_CS_TROPICAL
@ WID_CS_TROPICAL
Select tropical landscape style.
Definition: genworld_widget.h:75
WID_GL_SNOW_COVERAGE_UP
@ WID_GL_SNOW_COVERAGE_UP
Increase snow coverage.
Definition: genworld_widget.h:39
WID_GL_TOWN_PULLDOWN
@ WID_GL_TOWN_PULLDOWN
Dropdown 'No. of towns'.
Definition: genworld_widget.h:23
dropdown_type.h
CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
Maximum percentage a user can specify for custom sea level.
Definition: genworld.h:49
MAP_HEIGHT_LIMIT_AUTO_MINIMUM
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:51
WID_GL_HEIGHTMAP_HEIGHT_UP
@ WID_GL_HEIGHTMAP_HEIGHT_UP
Increase max. heightmap highest mountain.
Definition: genworld_widget.h:31
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
industry.h
safeguards.h
GenerateLandscapeWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: genworld_gui.cpp:890
WID_GL_START_DATE_TEXT
@ WID_GL_START_DATE_TEXT
Start year.
Definition: genworld_widget.h:34
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1115
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
GameCreationSettings::custom_terrain_type
byte custom_terrain_type
manually entered height for TGP to aim for
Definition: settings_type.h:333
WID_GL_TERRAIN_PULLDOWN
@ WID_GL_TERRAIN_PULLDOWN
Dropdown 'Terrain type'.
Definition: genworld_widget.h:51
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:354
WF_TIMEOUT
@ WF_TIMEOUT
Window timeout counter.
Definition: window_gui.h:168
CreateScenarioWindow
Definition: genworld_gui.cpp:1107
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
DifficultySettings::quantity_sea_lakes
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:90
DifficultySettings::industry_density
byte industry_density
The industry density.
Definition: settings_type.h:80
GameCreationSettings::se_flat_world_height
byte se_flat_world_height
land height a flat world gets in SE
Definition: settings_type.h:326
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
GenWorldStatus
Definition: genworld_gui.cpp:1371
GLWM_SCENARIO
@ GLWM_SCENARIO
Generate flat land.
Definition: genworld_gui.cpp:48
WID_CS_TEMPERATE
@ WID_CS_TEMPERATE
Select temperate landscape style.
Definition: genworld_widget.h:73
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:487
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:61
date_func.h
stdafx.h
SM_GENRANDLAND
@ SM_GENRANDLAND
Generate random land within scenario editor.
Definition: openttd.h:35
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
ShowGSConfigWindow
void ShowGSConfigWindow()
Open the GS config window.
Definition: game_gui.cpp:461
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition: genworld_gui.cpp:1572
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3192
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:202
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:336
BUILTIN_TOWNNAME_GENERATOR_COUNT
static constexpr uint BUILTIN_TOWNNAME_GENERATOR_COUNT
Number of built-in town name generators.
Definition: townname_type.h:24
ShowHeightmapLoad
void ShowHeightmapLoad()
Start with loading a heightmap.
Definition: genworld_gui.cpp:1084
GetHeightmapDimensions
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
Get the dimensions of a heightmap.
Definition: heightmap.cpp:511
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
StartNewGameWithoutGUI
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
Definition: genworld_gui.cpp:1099
GenerateProgressWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: genworld_gui.cpp:1429
SM_LOAD_HEIGHTMAP
@ SM_LOAD_HEIGHTMAP
Load heightmap from scenario editor.
Definition: openttd.h:38
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
GenWorldProgress
GenWorldProgress
Current stage of world generation process.
Definition: genworld.h:69
VideoDriver::GameLoopPause
void GameLoopPause()
Pause the game-loop for a bit, releasing the game-state lock.
Definition: video_driver.cpp:64
WID_GL_INDUSTRY_PULLDOWN
@ WID_GL_INDUSTRY_PULLDOWN
Dropdown 'No. of industries'.
Definition: genworld_widget.h:25
string_func.h
MIN_HEIGHTMAP_HEIGHT
static const uint MIN_HEIGHTMAP_HEIGHT
Lowest possible peak value for heightmap creation.
Definition: tile_type.h:26
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:49
GLWM_HEIGHTMAP
@ GLWM_HEIGHTMAP
Load from heightmap.
Definition: genworld_gui.cpp:47
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GenerateLandscapeWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: genworld_gui.cpp:592
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1266
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:216
GameCreationSettings::heightmap_rotation
byte heightmap_rotation
rotation director for the heightmap
Definition: settings_type.h:325
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
strings_func.h
WID_GL_NEWGRF_BUTTON
@ WID_GL_NEWGRF_BUTTON
'NewGRF Settings' button.
Definition: genworld_widget.h:65
WID_GL_START_DATE_DOWN
@ WID_GL_START_DATE_DOWN
Decrease start year.
Definition: genworld_widget.h:33
WID_CS_MAPSIZE_Y_PULLDOWN
@ WID_CS_MAPSIZE_Y_PULLDOWN
Pull-down arrow for y map size.
Definition: genworld_widget.h:80
MIN_MAP_HEIGHT_LIMIT
static const uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:29
MAX_MAP_SIZE_BITS
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
Definition: map_type.h:64
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:367
WID_GL_HEIGHTMAP_HEIGHT_TEXT
@ WID_GL_HEIGHTMAP_HEIGHT_TEXT
Max. heightmap highest mountain.
Definition: genworld_widget.h:30
ShowGenerateWorldProgress
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
Definition: genworld_gui.cpp:1490
GenerateLandscapeWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: genworld_gui.cpp:435
HandleGeneratingWorldAbortion
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition: genworld.cpp:254
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
GameCreationSettings::map_x
uint8 map_x
X size of map.
Definition: settings_type.h:315
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
GameCreationSettings::desert_coverage
byte desert_coverage
the amount of desert coverage on the map
Definition: settings_type.h:321
GameCreationSettings::amount_of_rivers
byte amount_of_rivers
the amount of rivers
Definition: settings_type.h:337
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:317
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
video_driver.hpp
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
geometry_func.hpp
CreateScenarioWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: genworld_gui.cpp:1244
WID_GL_ARCTIC
@ WID_GL_ARCTIC
Button with icon "Arctic".
Definition: genworld_widget.h:16
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:95
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1199
InvalidateWindowClassesData
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:3269
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:63
GenerateLandscapeWindow
Definition: genworld_gui.cpp:408
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_GL_AI_BUTTON
@ WID_GL_AI_BUTTON
'AI Settings' button.
Definition: genworld_widget.h:63
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:558
CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY
static const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY
Value for custom terrain type in difficulty settings.
Definition: genworld.h:45
WID_GL_HEIGHTMAP_NAME_TEXT
@ WID_GL_HEIGHTMAP_NAME_TEXT
Heightmap name.
Definition: genworld_widget.h:47
GenerateLandscapeWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: genworld_gui.cpp:685
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:422
CreateScenarioWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: genworld_gui.cpp:1264
GameCreationSettings::custom_industry_number
uint16 custom_industry_number
manually entered number of industries
Definition: settings_type.h:331
GLWM_GENERATE
@ GLWM_GENERATE
Generate new game.
Definition: genworld_gui.cpp:46
progress.h
WID_GL_WATER_NW
@ WID_GL_WATER_NW
NW 'Water'/'Freeform'.
Definition: genworld_widget.h:58
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:313
WID_CS_EMPTY_WORLD
@ WID_CS_EMPTY_WORLD
Generate an empty flat world.
Definition: genworld_widget.h:77
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
WID_GL_MAPSIZE_X_PULLDOWN
@ WID_GL_MAPSIZE_X_PULLDOWN
Dropdown 'map X size'.
Definition: genworld_widget.h:20
WID_GL_VARIETY_PULLDOWN
@ WID_GL_VARIETY_PULLDOWN
Dropdown 'Variety distribution'.
Definition: genworld_widget.h:55
WID_GP_ABORT
@ WID_GP_ABORT
Abort button.
Definition: genworld_widget.h:93
DEF_START_YEAR
static const Year DEF_START_YEAR
The default starting year.
Definition: date_type.h:87
WID_GL_TOWNNAME_DROPDOWN
@ WID_GL_TOWNNAME_DROPDOWN
Dropdown 'Townnames'.
Definition: genworld_widget.h:24
WID_GL_LANDSCAPE_PULLDOWN
@ WID_GL_LANDSCAPE_PULLDOWN
Dropdown 'Land generator'.
Definition: genworld_widget.h:45
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:414
WID_CS_MAPSIZE_X_PULLDOWN
@ WID_CS_MAPSIZE_X_PULLDOWN
Pull-down arrow for x map size.
Definition: genworld_widget.h:79
network.h
window_func.h
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:178
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
WID_GL_SNOW_COVERAGE_TEXT
@ WID_GL_SNOW_COVERAGE_TEXT
Snow coverage.
Definition: genworld_widget.h:38
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
random_func.hpp
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1189
IsGeneratingWorldAborted
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition: genworld.cpp:246
GameCreationSettings::snow_coverage
byte snow_coverage
the amount of snow coverage on the map
Definition: settings_type.h:320
_nested_generate_landscape_widgets
static const NWidgetPart _nested_generate_landscape_widgets[]
Widgets of GenerateLandscapeWindow when generating world.
Definition: genworld_gui.cpp:72
StartScenarioEditor
void StartScenarioEditor()
Start with a scenario editor.
Definition: genworld_gui.cpp:1090
WID_GL_WATER_SW
@ WID_GL_WATER_SW
SW 'Water'/'Freeform'.
Definition: genworld_widget.h:61
WID_GL_CLIMATE_SEL_LABEL
@ WID_GL_CLIMATE_SEL_LABEL
NWID_SELECTION for snow or desert coverage label.
Definition: genworld_widget.h:67
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
ID_END
@ ID_END
Number of industry density settings.
Definition: settings_type.h:63
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1558
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
SetTextColour
static NWidgetPart SetTextColour(TextColour colour)
Widget part function for setting the text colour.
Definition: widget_type.h:1047
WID_CS_FLAT_LAND_HEIGHT_TEXT
@ WID_CS_FLAT_LAND_HEIGHT_TEXT
Clickable flat land height value.
Definition: genworld_widget.h:85
CloseAllNonVitalWindows
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition: window.cpp:3317
Window
Data structure for an opened window.
Definition: window_gui.h:213
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:361
GetMapHeightLimit
static uint GetMapHeightLimit()
Get the map height limit, or if set to "auto", the absolute limit.
Definition: genworld_gui.cpp:54
ResetGRFConfig
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
Definition: newgrf_config.cpp:495
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:412
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
MAX_MAP_SIZE
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition: map_type.h:66
WID_CS_START_DATE_UP
@ WID_CS_START_DATE_UP
Increase start year (start later).
Definition: genworld_widget.h:83
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
WID_CS_ARCTIC
@ WID_CS_ARCTIC
Select arctic landscape style.
Definition: genworld_widget.h:74
CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:47
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:619
ShowAIConfigWindow
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:911
WID_GL_DESERT_COVERAGE_DOWN
@ WID_GL_DESERT_COVERAGE_DOWN
Decrease desert coverage.
Definition: genworld_widget.h:41
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:403
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1270
WID_CS_START_DATE_DOWN
@ WID_CS_START_DATE_DOWN
Decrease start year (start earlier).
Definition: genworld_widget.h:81
DifficultySettings::number_towns
byte number_towns
the amount of towns
Definition: settings_type.h:79
WID_GL_RIVER_PULLDOWN
@ WID_GL_RIVER_PULLDOWN
Dropdown 'Rivers'.
Definition: genworld_widget.h:53
WID_CS_RANDOM_WORLD
@ WID_CS_RANDOM_WORLD
Generate random land button.
Definition: genworld_widget.h:78
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
CreateScenarioWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: genworld_gui.cpp:1138
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
GenerateLandscapeWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: genworld_gui.cpp:971
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:42
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
CreateScenarioWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: genworld_gui.cpp:1117
CreateScenarioWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: genworld_gui.cpp:1255
CUSTOM_TOWN_NUMBER_DIFFICULTY
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
Definition: town.h:26
WID_GL_WATER_NE
@ WID_GL_WATER_NE
NE 'Water'/'Freeform'.
Definition: genworld_widget.h:59
genworld_widget.h
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:55
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GenerateLandscapeWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: genworld_gui.cpp:524
debug.h
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:33
_grfconfig_newgame
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
Definition: newgrf_config.cpp:172
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
WID_GL_DESERT_COVERAGE_TEXT
@ WID_GL_DESERT_COVERAGE_TEXT
Desert coverage.
Definition: genworld_widget.h:42
WID_CS_FLAT_LAND_HEIGHT_UP
@ WID_CS_FLAT_LAND_HEIGHT_UP
Increase flat land height.
Definition: genworld_widget.h:86
MAX_YEAR
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Definition: date_type.h:95
DEF_SNOW_COVERAGE
static const uint DEF_SNOW_COVERAGE
Default snow coverage.
Definition: tile_type.h:36
DropDownListStringItem::NatSortFunc
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Definition: dropdown.cpp:54
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:61