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