OpenTTD: src/genworld_gui.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

genworld_gui.cpp
Go to the documentation of this file.
1 /* $Id: genworld_gui.cpp 27650 2016-09-04 12:57:43Z alberth $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #include "stdafx.h"
13 #include "heightmap.h"
14 #include "debug.h"
15 #include "genworld.h"
16 #include "network/network.h"
17 #include "strings_func.h"
18 #include "window_func.h"
19 #include "date_func.h"
20 #include "sound_func.h"
21 #include "fios.h"
22 #include "string_func.h"
23 #include "widgets/dropdown_type.h"
24 #include "widgets/dropdown_func.h"
25 #include "querystring_gui.h"
26 #include "town.h"
27 #include "core/geometry_func.hpp"
28 #include "core/random_func.hpp"
29 #include "saveload/saveload.h"
30 #include "progress.h"
31 #include "error.h"
32
33 #include "widgets/genworld_widget.h"
34
35 #include "safeguards.h"
36
37
38 extern void MakeNewgameSettingsLive();
39
41 enum GenerateLandscapeWindowMode {
42 GLWM_GENERATE,
43 GLWM_HEIGHTMAP,
44 GLWM_SCENARIO,
45 };
46
51 void SetNewLandscapeType(byte landscape)
52 {
53 _settings_newgame.game_creation.landscape = landscape;
54 InvalidateWindowClassesData(WC_SELECT_GAME);
55 InvalidateWindowClassesData(WC_GENERATE_LANDSCAPE);
56 }
57
59 static const NWidgetPart _nested_generate_landscape_widgets[] = {
60 NWidget(NWID_HORIZONTAL),
61 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
62 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
63 EndContainer(),
64 NWidget(WWT_PANEL, COLOUR_BROWN),
65 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
66 /* Landscape selection. */
67 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
68 NWidget(NWID_SPACER), SetFill(1, 0),
69 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
70 NWidget(NWID_SPACER), SetFill(1, 0),
71 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
72 NWidget(NWID_SPACER), SetFill(1, 0),
73 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
74 NWidget(NWID_SPACER), SetFill(1, 0),
75 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
76 NWidget(NWID_SPACER), SetFill(1, 0),
77 EndContainer(),
78 NWidget(NWID_SPACER), SetMinimalSize(0, 11),
79 NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
80 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
81 /* Left column with labels. */
82 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
83 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
84 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_LAND_GENERATOR, STR_NULL), SetFill(1, 1),
85 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
86 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
87 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_VARIETY, STR_NULL), SetFill(1, 1),
88 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_SEA_LAKES, STR_NULL), SetFill(1, 1),
89 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
90 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BORDER_TYPE, STR_NULL), SetFill(1, 1),
91 EndContainer(),
92 /* Widgets at the right of the labels. */
93 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
94 /* Mapsize X * Y. */
95 NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
96 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 0),
97 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
98 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 0),
99 EndContainer(),
100 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_LANDSCAPE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
101 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
102 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TERRAIN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
103 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_VARIETY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
104 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_WATER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
105 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
106 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_BORDERS_RANDOM), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
107 EndContainer(),
108 EndContainer(),
109 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
110 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
111 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
112 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
113 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
114 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
115 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
116 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
117 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
118 EndContainer(),
119 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
120 /* Max. heightlevel. */
121 NWidget(NWID_HORIZONTAL),
122 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_MAX_HEIGHTLEVEL_DOWN), SetFill(0, 1),
123 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
124 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_MAX_HEIGHTLEVEL_UP), SetFill(0, 1),
125 EndContainer(),
126 /* Snow line. */
127 NWidget(NWID_HORIZONTAL),
128 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
129 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
130 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
131 EndContainer(),
132 /* Starting date. */
133 NWidget(NWID_HORIZONTAL),
134 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),
135 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
136 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),
137 EndContainer(),
138 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
139 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
140 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
141 EndContainer(),
142 EndContainer(),
143 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
144 EndContainer(),
145 EndContainer(),
146 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
147 /* Map borders buttons for each edge. */
148 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
149 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
150 NWidget(NWID_SPACER), SetFill(1, 1),
151 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
152 EndContainer(),
153 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
154 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
155 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
156 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
157 NWidget(NWID_SPACER), SetFill(1, 1),
158 EndContainer(),
159 EndContainer(),
160 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
161 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
162 NWidget(NWID_SPACER), SetFill(1, 1),
163 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
164 EndContainer(),
165 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
166 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
167 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
168 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
169 NWidget(NWID_SPACER), SetFill(1, 1),
170 EndContainer(),
171 EndContainer(),
172 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
173 EndContainer(),
174 };
175
177 static const NWidgetPart _nested_heightmap_load_widgets[] = {
178 /* Window header. */
179 NWidget(NWID_HORIZONTAL),
180 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
181 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
182 EndContainer(),
183 NWidget(WWT_PANEL, COLOUR_BROWN),
184 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
185 /* Landscape selection. */
186 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
187 NWidget(NWID_SPACER), SetFill(1, 0),
188 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
189 NWidget(NWID_SPACER), SetFill(1, 0),
190 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
191 NWidget(NWID_SPACER), SetFill(1, 0),
192 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
193 NWidget(NWID_SPACER), SetFill(1, 0),
194 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
195 NWidget(NWID_SPACER), SetFill(1, 0),
196 EndContainer(),
197 NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
198 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
199 /* Labels at the left side. */
200 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
201 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
202 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
203 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
204 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
205 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
206 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
207 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
208 EndContainer(),
209 /* Widgets at the right of the labels. */
210 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
211 NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
212 NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
213 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
214 /* Mapsize X * Y. */
215 NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
216 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
217 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
218 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
219 EndContainer(),
220 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
221 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
222 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
223 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
224 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
225 EndContainer(),
226 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
227 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
228 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
229 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_NULL), SetFill(1, 1),
230 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
231 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
232 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
233 EndContainer(),
234 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
235 NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
236 NWidget(NWID_HORIZONTAL),
237 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
238 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
239 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
240 EndContainer(),
241 NWidget(NWID_HORIZONTAL),
242 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_MAX_HEIGHTLEVEL_DOWN), SetFill(0, 1),
243 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
244 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_MAX_HEIGHTLEVEL_UP), SetFill(0, 1),
245 EndContainer(),
246 NWidget(NWID_HORIZONTAL),
247 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),
248 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
249 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),
250 EndContainer(),
251 EndContainer(),
252 EndContainer(),
253 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
254 EndContainer(),
255 EndContainer(),
256 EndContainer(),
257 EndContainer(),
258 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
259 EndContainer(),
260 };
261
262 static void StartGeneratingLandscape(GenerateLandscapeWindowMode mode)
263 {
264 DeleteAllNonVitalWindows();
265 ClearErrorMessages();
266
267 /* Copy all XXX_newgame to XXX when coming from outside the editor */
268 MakeNewgameSettingsLive();
269 ResetGRFConfig(true);
270
271 if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
272 switch (mode) {
273 case GLWM_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break;
274 case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
275 case GLWM_SCENARIO: _switch_mode = SM_EDITOR; break;
276 default: NOT_REACHED();
277 }
278 }
279
280 static void LandscapeGenerationCallback(Window *w, bool confirmed)
281 {
282 if (confirmed) StartGeneratingLandscape((GenerateLandscapeWindowMode)w->window_number);
283 }
284
285 static DropDownList *BuildMapsizeDropDown()
286 {
287 DropDownList *list = new DropDownList();
288
289 for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
290 DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
291 item->SetParam(0, 1 << i);
292 *list->Append() = item;
293 }
294
295 return list;
296 }
297
298 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, INVALID_STRING_ID};
299 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};
300 static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
301 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};
302 static const StringID _tree_placer[] = {STR_CONFIG_SETTING_TREE_PLACER_NONE, STR_CONFIG_SETTING_TREE_PLACER_ORIGINAL, STR_CONFIG_SETTING_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
303 static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
304 static const StringID _landscape[] = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
305 static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
306 static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, INVALID_STRING_ID};
307 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};
308
309 assert_compile(lengthof(_num_inds) == ID_END + 1);
310
311 struct GenerateLandscapeWindow : public Window {
312 uint widget_id;
313 uint x;
314 uint y;
315 char name[64];
316 GenerateLandscapeWindowMode mode;
317
318 GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc)
319 {
320 this->InitNested(number);
321
322 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_GL_TEMPERATE);
323
324 this->mode = (GenerateLandscapeWindowMode)this->window_number;
325
326 /* Disable town, industry and trees in SE */
327 this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
328 this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
329 this->SetWidgetDisabledState(WID_GL_TREE_PULLDOWN, _game_mode == GM_EDITOR);
330
331 this->OnInvalidateData();
332 }
333
334
335 virtual void SetStringParameters(int widget) const
336 {
337 switch (widget) {
338 case WID_GL_START_DATE_TEXT: SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
339 case WID_GL_MAPSIZE_X_PULLDOWN: SetDParam(0, 1 << _settings_newgame.game_creation.map_x); break;
340 case WID_GL_MAPSIZE_Y_PULLDOWN: SetDParam(0, 1 << _settings_newgame.game_creation.map_y); break;
341 case WID_GL_MAX_HEIGHTLEVEL_TEXT: SetDParam(0, _settings_newgame.construction.max_heightlevel); break;
342 case WID_GL_SNOW_LEVEL_TEXT: SetDParam(0, _settings_newgame.game_creation.snow_line_height); break;
343
344 case WID_GL_TOWN_PULLDOWN:
345 if (_game_mode == GM_EDITOR) {
346 SetDParam(0, STR_CONFIG_SETTING_OFF);
347 } else if (_settings_newgame.difficulty.number_towns == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
348 SetDParam(0, STR_NUM_CUSTOM_NUMBER);
349 SetDParam(1, _settings_newgame.game_creation.custom_town_number);
350 } else {
351 SetDParam(0, _num_towns[_settings_newgame.difficulty.number_towns]);
352 }
353 break;
354
355 case WID_GL_INDUSTRY_PULLDOWN: SetDParam(0, _game_mode == GM_EDITOR ? STR_CONFIG_SETTING_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
356 case WID_GL_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
357 case WID_GL_TREE_PULLDOWN: SetDParam(0, _tree_placer[_settings_newgame.game_creation.tree_placer]); break;
358 case WID_GL_TERRAIN_PULLDOWN: SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
359
360 case WID_GL_WATER_PULLDOWN:
361 if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
362 SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
363 SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
364 } else {
365 SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
366 }
367 break;
368
369 case WID_GL_RIVER_PULLDOWN: SetDParam(0, _rivers[_settings_newgame.game_creation.amount_of_rivers]); break;
370 case WID_GL_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
371 case WID_GL_VARIETY_PULLDOWN: SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
372 case WID_GL_BORDERS_RANDOM: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
373 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;
374 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;
375 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;
376 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;
377 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: SetDParam(0, _rotation[_settings_newgame.game_creation.heightmap_rotation]); break;
378
379 case WID_GL_HEIGHTMAP_SIZE_TEXT:
380 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
381 SetDParam(0, this->y);
382 SetDParam(1, this->x);
383 } else {
384 SetDParam(0, this->x);
385 SetDParam(1, this->y);
386 }
387 break;
388 }
389 }
390
396 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
397 {
398 if (!gui_scope) return;
399 /* Update the climate buttons */
400 this->SetWidgetLoweredState(WID_GL_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
401 this->SetWidgetLoweredState(WID_GL_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
402 this->SetWidgetLoweredState(WID_GL_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
403 this->SetWidgetLoweredState(WID_GL_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
404
405 /* You can't select smoothness / non-water borders if not terragenesis */
406 if (mode == GLWM_GENERATE) {
407 this->SetWidgetDisabledState(WID_GL_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == LG_ORIGINAL);
408 this->SetWidgetDisabledState(WID_GL_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == LG_ORIGINAL);
409 this->SetWidgetDisabledState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges);
410 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
411 WID_GL_WATER_NW, WID_GL_WATER_NE, WID_GL_WATER_SE, WID_GL_WATER_SW, WIDGET_LIST_END);
412
413 this->SetWidgetLoweredState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
414
415 this->SetWidgetLoweredState(WID_GL_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
416 this->SetWidgetLoweredState(WID_GL_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
417 this->SetWidgetLoweredState(WID_GL_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
418 this->SetWidgetLoweredState(WID_GL_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
419
420 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL && (_settings_newgame.game_creation.landscape == LT_ARCTIC || _settings_newgame.game_creation.landscape == LT_TROPIC),
421 WID_GL_TERRAIN_PULLDOWN, WID_GL_WATER_PULLDOWN, WIDGET_LIST_END);
422 }
423
424 /* Disable snowline if not arctic */
425 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
426
427 /* Update availability of decreasing / increasing start date and snow level */
428 this->SetWidgetDisabledState(WID_GL_MAX_HEIGHTLEVEL_DOWN, _settings_newgame.construction.max_heightlevel <= MIN_MAX_HEIGHTLEVEL);
429 this->SetWidgetDisabledState(WID_GL_MAX_HEIGHTLEVEL_UP, _settings_newgame.construction.max_heightlevel >= MAX_MAX_HEIGHTLEVEL);
430 this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
431 this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
432 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_DOWN, _settings_newgame.game_creation.snow_line_height <= MIN_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
433 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_UP, _settings_newgame.game_creation.snow_line_height >= MAX_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
434
435 /* Do not allow a custom sea level with the original land generator. */
436 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL &&
437 _settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
438 _settings_newgame.difficulty.quantity_sea_lakes = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE;
439 }
440
441 }
442
443 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
444 {
445 const StringID *strs = NULL;
446 switch (widget) {
447 case WID_GL_MAX_HEIGHTLEVEL_TEXT:
448 SetDParam(0, MAX_TILE_HEIGHT);
449 *size = GetStringBoundingBox(STR_JUST_INT);
450 break;
451
452 case WID_GL_START_DATE_TEXT:
453 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
454 *size = maxdim(*size, GetStringBoundingBox(STR_BLACK_DATE_LONG));
455 break;
456
457 case WID_GL_MAPSIZE_X_PULLDOWN:
458 case WID_GL_MAPSIZE_Y_PULLDOWN:
459 SetDParamMaxValue(0, MAX_MAP_SIZE);
460 *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
461 break;
462
463 case WID_GL_SNOW_LEVEL_TEXT:
464 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
465 *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
466 break;
467
468 case WID_GL_HEIGHTMAP_SIZE_TEXT:
469 SetDParam(0, this->x);
470 SetDParam(1, this->y);
471 *size = maxdim(*size, GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE));
472 break;
473
474 case WID_GL_TOWN_PULLDOWN:
475 strs = _num_towns;
476 SetDParamMaxValue(0, CUSTOM_TOWN_MAX_NUMBER);
477 *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
478 break;
479
480 case WID_GL_INDUSTRY_PULLDOWN: strs = _num_inds; break;
481 case WID_GL_LANDSCAPE_PULLDOWN: strs = _landscape; break;
482 case WID_GL_TREE_PULLDOWN: strs = _tree_placer; break;
483 case WID_GL_TERRAIN_PULLDOWN: strs = _elevations; break;
484 case WID_GL_WATER_PULLDOWN:
485 strs = _sea_lakes;
486 SetDParamMaxValue(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
487 *size = maxdim(*size, GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE));
488 break;
489
490 case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
491 case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
492 case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
493 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
494 case WID_GL_BORDERS_RANDOM:
495 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
496 break;
497
498 case WID_GL_WATER_NE:
499 case WID_GL_WATER_NW:
500 case WID_GL_WATER_SE:
501 case WID_GL_WATER_SW:
502 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
503 break;
504
505 case WID_GL_HEIGHTMAP_NAME_TEXT:
506 size->width = 0;
507 break;
508
509 default:
510 return;
511 }
512 if (strs != NULL) {
513 while (*strs != INVALID_STRING_ID) {
514 *size = maxdim(*size, GetStringBoundingBox(*strs++));
515 }
516 }
517 size->width += padding.width;
518 size->height = max(size->height, (uint)(FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM));
519 }
520
521 virtual void DrawWidget(const Rect &r, int widget) const
522 {
523 switch (widget) {
524 case WID_GL_HEIGHTMAP_NAME_TEXT: {
525 DrawString(r.left, r.right, r.top, this->name, TC_ORANGE);
526 break;
527 }
528 }
529 }
530
531 virtual void OnClick(Point pt, int widget, int click_count)
532 {
533 switch (widget) {
534 case WID_GL_TEMPERATE:
535 case WID_GL_ARCTIC:
536 case WID_GL_TROPICAL:
537 case WID_GL_TOYLAND:
538 SetNewLandscapeType(widget - WID_GL_TEMPERATE);
539 break;
540
541 case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
542 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
543 break;
544
545 case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
546 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
547 break;
548
549 case WID_GL_TOWN_PULLDOWN: // Number of towns
550 ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
551 break;
552
553 case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
554 ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
555 break;
556
557 case WID_GL_GENERATE_BUTTON: { // Generate
558 /* Get rotated map size. */
559 uint map_x;
560 uint map_y;
561 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
562 map_x = this->y;
563 map_y = this->x;
564 } else {
565 map_x = this->x;
566 map_y = this->y;
567 }
568 if (mode == GLWM_HEIGHTMAP &&
569 (map_x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
570 map_x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
571 map_y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
572 map_y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
573 ShowQuery(
574 STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
575 STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
576 this,
577 LandscapeGenerationCallback);
578 } else {
579 StartGeneratingLandscape(mode);
580 }
581 break;
582 }
583
584 case WID_GL_MAX_HEIGHTLEVEL_DOWN:
585 case WID_GL_MAX_HEIGHTLEVEL_UP: // Height level buttons
586 /* Don't allow too fast scrolling */
587 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
588 this->HandleButtonClick(widget);
589
590 _settings_newgame.construction.max_heightlevel = Clamp(_settings_newgame.construction.max_heightlevel + widget - WID_GL_MAX_HEIGHTLEVEL_TEXT, MIN_MAX_HEIGHTLEVEL, MAX_MAX_HEIGHTLEVEL);
591 this->InvalidateData();
592 }
593 _left_button_clicked = false;
594 break;
595
596 case WID_GL_MAX_HEIGHTLEVEL_TEXT: // Height level text
597 this->widget_id = WID_GL_MAX_HEIGHTLEVEL_TEXT;
598 SetDParam(0, _settings_newgame.construction.max_heightlevel);
599 ShowQueryString(STR_JUST_INT, STR_MAPGEN_MAX_HEIGHTLEVEL_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
600 break;
601
602
603 case WID_GL_START_DATE_DOWN:
604 case WID_GL_START_DATE_UP: // Year buttons
605 /* Don't allow too fast scrolling */
606 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
607 this->HandleButtonClick(widget);
608
609 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
610 this->InvalidateData();
611 }
612 _left_button_clicked = false;
613 break;
614
615 case WID_GL_START_DATE_TEXT: // Year text
616 this->widget_id = WID_GL_START_DATE_TEXT;
617 SetDParam(0, _settings_newgame.game_creation.starting_year);
618 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
619 break;
620
621 case WID_GL_SNOW_LEVEL_DOWN:
622 case WID_GL_SNOW_LEVEL_UP: // Snow line buttons
623 /* Don't allow too fast scrolling */
624 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
625 this->HandleButtonClick(widget);
626
627 _settings_newgame.game_creation.snow_line_height = Clamp(_settings_newgame.game_creation.snow_line_height + widget - WID_GL_SNOW_LEVEL_TEXT, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
628 this->InvalidateData();
629 }
630 _left_button_clicked = false;
631 break;
632
633 case WID_GL_SNOW_LEVEL_TEXT: // Snow line text
634 this->widget_id = WID_GL_SNOW_LEVEL_TEXT;
635 SetDParam(0, _settings_newgame.game_creation.snow_line_height);
636 ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
637 break;
638
639 case WID_GL_TREE_PULLDOWN: // Tree placer
640 ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, WID_GL_TREE_PULLDOWN, 0, 0);
641 break;
642
643 case WID_GL_LANDSCAPE_PULLDOWN: // Landscape generator
644 ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, WID_GL_LANDSCAPE_PULLDOWN, 0, 0);
645 break;
646
647 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
648 ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
649 break;
650
651 case WID_GL_TERRAIN_PULLDOWN: // Terrain type
652 /* For the original map generation only the first four are valid. */
653 ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, WID_GL_TERRAIN_PULLDOWN, 0, _settings_newgame.game_creation.land_generator == LG_ORIGINAL ? ~0xF : 0);
654 break;
655
656 case WID_GL_WATER_PULLDOWN: { // Water quantity
657 uint32 hidden_mask = 0;
658 /* Disable custom water level when the original map generator is active. */
659 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
660 SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
661 }
662 ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
663 break;
664 }
665
666 case WID_GL_RIVER_PULLDOWN: // Amount of rivers
667 ShowDropDownMenu(this, _rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
668 break;
669
670 case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
671 ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
672 break;
673
674 case WID_GL_VARIETY_PULLDOWN: // Map variety
675 ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
676 break;
677
678 /* Freetype map borders */
679 case WID_GL_WATER_NW:
680 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
681 this->InvalidateData();
682 break;
683
684 case WID_GL_WATER_NE:
685 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
686 this->InvalidateData();
687 break;
688
689 case WID_GL_WATER_SE:
690 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
691 this->InvalidateData();
692 break;
693
694 case WID_GL_WATER_SW:
695 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
696 this->InvalidateData();
697 break;
698
699 case WID_GL_BORDERS_RANDOM:
700 _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
701 this->InvalidateData();
702 break;
703 }
704 }
705
706 virtual void OnTimeout()
707 {
708 static const int raise_widgets[] = {WID_GL_MAX_HEIGHTLEVEL_DOWN, WID_GL_MAX_HEIGHTLEVEL_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_LEVEL_UP, WID_GL_SNOW_LEVEL_DOWN, WIDGET_LIST_END};
709 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
710 if (this->IsWidgetLowered(*widget)) {
711 this->RaiseWidget(*widget);
712 this->SetWidgetDirty(*widget);
713 }
714 }
715 }
716
717 virtual void OnDropdownSelect(int widget, int index)
718 {
719 switch (widget) {
720 case WID_GL_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
721 case WID_GL_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
722 case WID_GL_TREE_PULLDOWN: _settings_newgame.game_creation.tree_placer = index; break;
723 case WID_GL_RIVER_PULLDOWN: _settings_newgame.game_creation.amount_of_rivers = index; break;
724 case WID_GL_SMOOTHNESS_PULLDOWN: _settings_newgame.game_creation.tgen_smoothness = index; break;
725 case WID_GL_VARIETY_PULLDOWN: _settings_newgame.game_creation.variety = index; break;
726
727 case WID_GL_LANDSCAPE_PULLDOWN: _settings_newgame.game_creation.land_generator = index;
728 /* If original landgenerator is selected and alpinist terrain_type was selected, revert to mountainous. */
729 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
730 _settings_newgame.difficulty.terrain_type = Clamp(_settings_newgame.difficulty.terrain_type, 0, 3);
731 }
732 break;
733
734 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
735
736 case WID_GL_TOWN_PULLDOWN:
737 if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
738 this->widget_id = widget;
739 SetDParam(0, _settings_newgame.game_creation.custom_town_number);
740 ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE);
741 }
742 _settings_newgame.difficulty.number_towns = index;
743 break;
744
745 case WID_GL_INDUSTRY_PULLDOWN: _settings_newgame.difficulty.industry_density = index; break;
746 case WID_GL_TERRAIN_PULLDOWN: _settings_newgame.difficulty.terrain_type = index; break;
747
748 case WID_GL_WATER_PULLDOWN: {
749 if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
750 this->widget_id = widget;
751 SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
752 ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, this, CS_NUMERAL, QSF_NONE);
753 }
754 _settings_newgame.difficulty.quantity_sea_lakes = index;
755 break;
756 }
757 }
758 this->InvalidateData();
759 }
760
761 virtual void OnQueryTextFinished(char *str)
762 {
763 /* Was 'cancel' pressed? */
764 if (str == NULL) return;
765
766 int32 value;
767 if (!StrEmpty(str)) {
768 value = atoi(str);
769 } else {
770 /* An empty string means revert to the default */
771 switch (this->widget_id) {
772 case WID_GL_MAX_HEIGHTLEVEL_TEXT: value = DEF_MAX_HEIGHTLEVEL; break;
773 case WID_GL_START_DATE_TEXT: value = DEF_START_YEAR; break;
774 case WID_GL_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
775 case WID_GL_TOWN_PULLDOWN: value = 1; break;
776 case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
777 default: NOT_REACHED();
778 }
779 }
780
781 switch (this->widget_id) {
782 case WID_GL_MAX_HEIGHTLEVEL_TEXT:
783 this->SetWidgetDirty(WID_GL_MAX_HEIGHTLEVEL_TEXT);
784 _settings_newgame.construction.max_heightlevel = Clamp(value, MIN_MAX_HEIGHTLEVEL, MAX_MAX_HEIGHTLEVEL);
785 break;
786
787 case WID_GL_START_DATE_TEXT:
788 this->SetWidgetDirty(WID_GL_START_DATE_TEXT);
789 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
790 break;
791
792 case WID_GL_SNOW_LEVEL_TEXT:
793 this->SetWidgetDirty(WID_GL_SNOW_LEVEL_TEXT);
794 _settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
795 break;
796
797 case WID_GL_TOWN_PULLDOWN:
798 _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
799 break;
800
801 case WID_GL_WATER_PULLDOWN:
802 _settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
803 break;
804 }
805
806 this->InvalidateData();
807 }
808 };
809
810 static WindowDesc _generate_landscape_desc(
811 WDP_CENTER, NULL, 0, 0,
812 WC_GENERATE_LANDSCAPE, WC_NONE,
813 0,
814 _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
815 );
816
817 static WindowDesc _heightmap_load_desc(
818 WDP_CENTER, NULL, 0, 0,
819 WC_GENERATE_LANDSCAPE, WC_NONE,
820 0,
821 _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
822 );
823
824 static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
825 {
826 uint x = 0;
827 uint y = 0;
828
829 DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
830
831 /* Generate a new seed when opening the window */
832 _settings_newgame.game_creation.generation_seed = InteractiveRandom();
833
834 if (mode == GLWM_HEIGHTMAP) {
835 /* If the function returns negative, it means there was a problem loading the heightmap */
836 if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name, &x, &y)) return;
837 }
838
839 WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;
840 GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
841
842 if (mode == GLWM_HEIGHTMAP) {
843 w->x = x;
844 w->y = y;
845 strecpy(w->name, _file_to_saveload.title, lastof(w->name));
846 }
847
848 SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
849 }
850
852 void ShowGenerateLandscape()
853 {
854 _ShowGenerateLandscape(GLWM_GENERATE);
855 }
856
858 void ShowHeightmapLoad()
859 {
860 _ShowGenerateLandscape(GLWM_HEIGHTMAP);
861 }
862
864 void StartScenarioEditor()
865 {
866 StartGeneratingLandscape(GLWM_SCENARIO);
867 }
868
873 void StartNewGameWithoutGUI(uint seed)
874 {
875 /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
876 _settings_newgame.game_creation.generation_seed = seed;
877
878 StartGeneratingLandscape(GLWM_GENERATE);
879 }
880
881 struct CreateScenarioWindow : public Window
882 {
883 uint widget_id;
884
885 CreateScenarioWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
886 {
887 this->InitNested(window_number);
888 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
889 }
890
891 virtual void SetStringParameters(int widget) const
892 {
893 switch (widget) {
894 case WID_CS_START_DATE_TEXT:
895 SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
896 break;
897
898 case WID_CS_MAPSIZE_X_PULLDOWN:
899 SetDParam(0, 1 << _settings_newgame.game_creation.map_x);
900 break;
901
902 case WID_CS_MAPSIZE_Y_PULLDOWN:
903 SetDParam(0, 1 << _settings_newgame.game_creation.map_y);
904 break;
905
906 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
907 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
908 break;
909 }
910 }
911
912 virtual void OnPaint()
913 {
914 this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
915 this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
916 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
917 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP, _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
918
919 this->SetWidgetLoweredState(WID_CS_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
920 this->SetWidgetLoweredState(WID_CS_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
921 this->SetWidgetLoweredState(WID_CS_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
922 this->SetWidgetLoweredState(WID_CS_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
923
924 this->DrawWidgets();
925 }
926
927 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
928 {
929 StringID str = STR_JUST_INT;
930 switch (widget) {
931 case WID_CS_START_DATE_TEXT:
932 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
933 str = STR_BLACK_DATE_LONG;
934 break;
935
936 case WID_CS_MAPSIZE_X_PULLDOWN:
937 case WID_CS_MAPSIZE_Y_PULLDOWN:
938 SetDParamMaxValue(0, MAX_MAP_SIZE);
939 break;
940
941 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
942 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
943 break;
944
945 default:
946 return;
947 }
948 *size = maxdim(*size, GetStringBoundingBox(str));
949 size->width += padding.width;
950 size->height += padding.height;
951 }
952
953 virtual void OnClick(Point pt, int widget, int click_count)
954 {
955 switch (widget) {
956 case WID_CS_TEMPERATE:
957 case WID_CS_ARCTIC:
958 case WID_CS_TROPICAL:
959 case WID_CS_TOYLAND:
960 this->RaiseWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
961 SetNewLandscapeType(widget - WID_CS_TEMPERATE);
962 break;
963
964 case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
965 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
966 break;
967
968 case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
969 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
970 break;
971
972 case WID_CS_EMPTY_WORLD: // Empty world / flat world
973 StartGeneratingLandscape(GLWM_SCENARIO);
974 break;
975
976 case WID_CS_RANDOM_WORLD: // Generate
977 ShowGenerateLandscape();
978 break;
979
980 case WID_CS_START_DATE_DOWN:
981 case WID_CS_START_DATE_UP: // Year buttons
982 /* Don't allow too fast scrolling */
983 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
984 this->HandleButtonClick(widget);
985 this->SetDirty();
986
987 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
988 }
989 _left_button_clicked = false;
990 break;
991
992 case WID_CS_START_DATE_TEXT: // Year text
993 this->widget_id = WID_CS_START_DATE_TEXT;
994 SetDParam(0, _settings_newgame.game_creation.starting_year);
995 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE);
996 break;
997
998 case WID_CS_FLAT_LAND_HEIGHT_DOWN:
999 case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
1000 /* Don't allow too fast scrolling */
1001 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1002 this->HandleButtonClick(widget);
1003 this->SetDirty();
1004
1005 _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, _settings_game.construction.max_heightlevel);
1006 }
1007 _left_button_clicked = false;
1008 break;
1009
1010 case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
1011 this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1012 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
1013 ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
1014 break;
1015 }
1016 }
1017
1018 virtual void OnTimeout()
1019 {
1020 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};
1021 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
1022 if (this->IsWidgetLowered(*widget)) {
1023 this->RaiseWidget(*widget);
1024 this->SetWidgetDirty(*widget);
1025 }
1026 }
1027 }
1028
1029 virtual void OnDropdownSelect(int widget, int index)
1030 {
1031 switch (widget) {
1032 case WID_CS_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
1033 case WID_CS_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
1034 }
1035 this->SetDirty();
1036 }
1037
1038 virtual void OnQueryTextFinished(char *str)
1039 {
1040 if (!StrEmpty(str)) {
1041 int32 value = atoi(str);
1042
1043 switch (this->widget_id) {
1044 case WID_CS_START_DATE_TEXT:
1045 this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
1046 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
1047 break;
1048
1049 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
1050 this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
1051 _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, _settings_game.construction.max_heightlevel);
1052 break;
1053 }
1054
1055 this->SetDirty();
1056 }
1057 }
1058 };
1059
1060 static const NWidgetPart _nested_create_scenario_widgets[] = {
1061 NWidget(NWID_HORIZONTAL),
1062 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1063 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
1064 EndContainer(),
1065 NWidget(WWT_PANEL, COLOUR_BROWN),
1066 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
1067 /* Landscape style selection. */
1068 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
1069 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
1070 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1071 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1072 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1073 EndContainer(),
1074 NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
1075 /* Green generation type buttons: 'Flat land' and 'Random land'. */
1076 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1077 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1078 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1079 EndContainer(),
1080 /* Labels + setting drop-downs */
1081 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1082 /* Map size. */
1083 NWidget(NWID_HORIZONTAL),
1084 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
1085 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1086 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
1087 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
1088 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
1089 EndContainer(),
1090 /* Date. */
1091 NWidget(NWID_HORIZONTAL),
1092 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
1093 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1094 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),
1095 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
1096 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),
1097 EndContainer(),
1098 /* Flat map height. */
1099 NWidget(NWID_HORIZONTAL),
1100 NWidget(WWT_TEXT, COLOUR_ORANGE),
1101 SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
1102 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1103 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),
1104 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
1105 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),
1106 EndContainer(),
1107 EndContainer(),
1108 EndContainer(),
1109 EndContainer(),
1110 };
1111
1112 static WindowDesc _create_scenario_desc(
1113 WDP_CENTER, NULL, 0, 0,
1114 WC_GENERATE_LANDSCAPE, WC_NONE,
1115 0,
1116 _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
1117 );
1118
1120 void ShowCreateScenario()
1121 {
1122 DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
1123 new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
1124 }
1125
1126 static const NWidgetPart _nested_generate_progress_widgets[] = {
1127 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1128 NWidget(WWT_PANEL, COLOUR_GREY),
1129 NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
1130 NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
1131 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
1132 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
1133 NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
1134 EndContainer(),
1135 EndContainer(),
1136 EndContainer(),
1137 };
1138
1139
1140 static WindowDesc _generate_progress_desc(
1141 WDP_CENTER, NULL, 0, 0,
1142 WC_MODAL_PROGRESS, WC_NONE,
1143 0,
1144 _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
1145 );
1146
1147 struct GenWorldStatus {
1148 uint percent;
1149 StringID cls;
1150 uint current;
1151 uint total;
1152 int timer;
1153 };
1154
1155 static GenWorldStatus _gws;
1156
1157 static const StringID _generation_class_table[] = {
1158 STR_GENERATION_WORLD_GENERATION,
1159 STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
1160 STR_GENERATION_RIVER_GENERATION,
1161 STR_GENERATION_CLEARING_TILES,
1162 STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
1163 STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
1164 STR_GENERATION_OBJECT_GENERATION,
1165 STR_GENERATION_TREE_GENERATION,
1166 STR_GENERATION_SETTINGUP_GAME,
1167 STR_GENERATION_PREPARING_TILELOOP,
1168 STR_GENERATION_PREPARING_SCRIPT,
1169 STR_GENERATION_PREPARING_GAME
1170 };
1171 assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
1172
1173
1174 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
1175 {
1176 if (confirmed) {
1177 AbortGeneratingWorld();
1178 } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1179 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1180 }
1181 }
1182
1183 struct GenerateProgressWindow : public Window {
1184
1185 GenerateProgressWindow() : Window(&_generate_progress_desc)
1186 {
1187 this->InitNested();
1188 }
1189
1190 virtual void OnClick(Point pt, int widget, int click_count)
1191 {
1192 switch (widget) {
1193 case WID_GP_ABORT:
1194 SetMouseCursorBusy(false);
1195 ShowQuery(
1196 STR_GENERATION_ABORT_CAPTION,
1197 STR_GENERATION_ABORT_MESSAGE,
1198 this,
1199 AbortGeneratingWorldCallback
1200 );
1201 break;
1202 }
1203 }
1204
1205 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1206 {
1207 switch (widget) {
1208 case WID_GP_PROGRESS_BAR: {
1209 SetDParamMaxValue(0, 100);
1210 *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
1211 /* We need some spacing for the 'border' */
1212 size->height += 8;
1213 size->width += 8;
1214 break;
1215 }
1216
1217 case WID_GP_PROGRESS_TEXT:
1218 for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
1219 size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
1220 }
1221 size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
1222 break;
1223 }
1224 }
1225
1226 virtual void DrawWidget(const Rect &r, int widget) const
1227 {
1228 switch (widget) {
1229 case WID_GP_PROGRESS_BAR:
1230 /* Draw the % complete with a bar and a text */
1231 DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
1232 DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * _gws.percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
1233 SetDParam(0, _gws.percent);
1234 DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
1235 break;
1236
1237 case WID_GP_PROGRESS_TEXT:
1238 /* Tell which class we are generating */
1239 DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
1240
1241 /* And say where we are in that class */
1242 SetDParam(0, _gws.current);
1243 SetDParam(1, _gws.total);
1244 DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
1245 }
1246 }
1247 };
1248
1252 void PrepareGenerateWorldProgress()
1253 {
1254 _gws.cls = STR_GENERATION_WORLD_GENERATION;
1255 _gws.current = 0;
1256 _gws.total = 0;
1257 _gws.percent = 0;
1258 _gws.timer = 0; // Forces to paint the progress window immediately
1259 }
1260
1264 void ShowGenerateWorldProgress()
1265 {
1266 if (BringWindowToFrontById(WC_MODAL_PROGRESS, 0)) return;
1267 new GenerateProgressWindow();
1268 }
1269
1270 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1271 {
1272 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
1273 assert_compile(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1274 assert(cls < GWP_CLASS_COUNT);
1275
1276 /* Do not run this function if we aren't in a thread */
1277 if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
1278
1279 if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
1280
1281 if (total == 0) {
1282 assert(_gws.cls == _generation_class_table[cls]);
1283 _gws.current += progress;
1284 assert(_gws.current <= _gws.total);
1285 } else {
1286 _gws.cls = _generation_class_table[cls];
1287 _gws.current = progress;
1288 _gws.total = total;
1289 _gws.percent = percent_table[cls];
1290 }
1291
1292 /* Don't update the screen too often. So update it once in every once in a while... */
1293 if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < MODAL_PROGRESS_REDRAW_TIMEOUT) return;
1294
1295 /* Percentage is about the number of completed tasks, so 'current - 1' */
1296 _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
1297
1298 if (_network_dedicated) {
1299 static uint last_percent = 0;
1300
1301 /* Never display 0% */
1302 if (_gws.percent == 0) return;
1303 /* Reset if percent is lower than the last recorded */
1304 if (_gws.percent < last_percent) last_percent = 0;
1305 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1306 if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
1307 /* Never show steps smaller than 2%, even if it is a mod 5% */
1308 if (_gws.percent <= last_percent + 2) return;
1309
1310 DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
1311 last_percent = _gws.percent;
1312
1313 /* Don't continue as dedicated never has a thread running */
1314 return;
1315 }
1316
1317 SetWindowDirty(WC_MODAL_PROGRESS, 0);
1318 MarkWholeScreenDirty();
1319
1320 /* Release the rights to the map generator, and acquire the rights to the
1321 * paint thread. The 'other' thread already has the paint thread rights so
1322 * this ensures us that we are waiting until the paint thread is done
1323 * before we reacquire the mapgen rights */
1324 _modal_progress_work_mutex->EndCritical();
1325 _modal_progress_paint_mutex->BeginCritical();
1326 _modal_progress_work_mutex->BeginCritical();
1327 _modal_progress_paint_mutex->EndCritical();
1328
1329 _gws.timer = _realtime_tick;
1330 }
1331
1340 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
1341 {
1342 if (total == 0) return;
1343
1344 _SetGeneratingWorldProgress(cls, 0, total);
1345 }
1346
1354 void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
1355 {
1356 /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1357 _SetGeneratingWorldProgress(cls, 1, 0);
1358 }