Add support for deleted functions
[openttd/fttd.git] / src / genworld_gui.cpp
blobf1b561ef1809527bdd47f15a440913e256f8b0ed
1 /* $Id$ */
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 */
10 /** @file genworld_gui.cpp GUI to configure and show progress during map generation. */
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 "settings_func.h"
28 #include "core/geometry_func.hpp"
29 #include "core/random_func.hpp"
30 #include "progress.h"
31 #include "error.h"
33 #include "widgets/genworld_widget.h"
36 extern void MakeNewgameSettingsLive();
38 /** Enum for the modes we can generate in. */
39 enum GenenerateLandscapeWindowMode {
40 GLWM_GENERATE, ///< Generate new game.
41 GLWM_HEIGHTMAP, ///< Load from heightmap.
42 GLWM_SCENARIO, ///< Generate flat land.
45 /**
46 * Changes landscape type and sets genworld window dirty
47 * @param landscape new landscape type
49 void SetNewLandscapeType(byte landscape)
51 _settings_newgame.game_creation.landscape = landscape;
52 InvalidateWindowClassesData(WC_SELECT_GAME);
53 InvalidateWindowClassesData(WC_GENERATE_LANDSCAPE);
56 /** Widgets of GenerateLandscapeWindow when generating world */
57 static const NWidgetPart _nested_generate_landscape_widgets[] = {
58 NWidget(NWID_HORIZONTAL),
59 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
60 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
61 EndContainer(),
62 NWidget(WWT_PANEL, COLOUR_BROWN),
63 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
64 /* Landscape selection. */
65 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
66 NWidget(NWID_SPACER), SetFill(1, 0),
67 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
68 NWidget(NWID_SPACER), SetFill(1, 0),
69 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
70 NWidget(NWID_SPACER), SetFill(1, 0),
71 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
72 NWidget(NWID_SPACER), SetFill(1, 0),
73 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
74 NWidget(NWID_SPACER), SetFill(1, 0),
75 EndContainer(),
76 NWidget(NWID_SPACER), SetMinimalSize(0, 11),
77 NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
78 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
79 /* Left column with labels. */
80 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
81 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
82 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_LAND_GENERATOR, STR_NULL), SetFill(1, 1),
83 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
84 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
85 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
86 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_SEA_LAKES, STR_NULL), SetFill(1, 1),
87 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
88 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_VARIETY, 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_EDITBOX, COLOUR_ORANGE, WID_GL_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
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_DROPDOWN, COLOUR_ORANGE, WID_GL_VARIETY_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_DATE, 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_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
115 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
116 EndContainer(),
117 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
118 /* Starting date. */
119 NWidget(NWID_HORIZONTAL),
120 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),
121 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
122 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),
123 EndContainer(),
124 /* Snow line. */
125 NWidget(NWID_HORIZONTAL),
126 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
127 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
128 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
129 EndContainer(),
130 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
131 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
132 EndContainer(),
133 EndContainer(),
134 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
135 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
136 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
137 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
138 EndContainer(),
139 NWidget(NWID_SPACER), SetFill(1, 1),
140 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 30), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 0),
141 EndContainer(),
142 EndContainer(),
143 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
144 /* Map borders buttons for each edge. */
145 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
146 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
147 NWidget(NWID_SPACER), SetFill(1, 1),
148 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
149 EndContainer(),
150 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
151 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
152 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
153 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
154 NWidget(NWID_SPACER), SetFill(1, 1),
155 EndContainer(),
156 EndContainer(),
157 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
158 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
159 NWidget(NWID_SPACER), SetFill(1, 1),
160 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
161 EndContainer(),
162 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
163 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
164 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
165 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
166 NWidget(NWID_SPACER), SetFill(1, 1),
167 EndContainer(),
168 EndContainer(),
169 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
170 EndContainer(),
173 /** Widgets of GenerateLandscapeWindow when loading heightmap */
174 static const NWidgetPart _nested_heightmap_load_widgets[] = {
175 /* Window header. */
176 NWidget(NWID_HORIZONTAL),
177 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
178 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
179 EndContainer(),
180 NWidget(WWT_PANEL, COLOUR_BROWN),
181 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
182 /* Landscape selection. */
183 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
184 NWidget(NWID_SPACER), SetFill(1, 0),
185 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
186 NWidget(NWID_SPACER), SetFill(1, 0),
187 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
188 NWidget(NWID_SPACER), SetFill(1, 0),
189 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
190 NWidget(NWID_SPACER), SetFill(1, 0),
191 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
192 NWidget(NWID_SPACER), SetFill(1, 0),
193 EndContainer(),
194 NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
195 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
196 /* Labels at the left side. */
197 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
198 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
199 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
200 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
201 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
202 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
203 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
204 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
205 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
206 EndContainer(),
207 /* Widgets at the right of the labels. */
208 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
209 NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
210 NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
211 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
212 /* Mapsize X * Y. */
213 NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
214 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
215 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
216 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
217 EndContainer(),
218 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
219 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
220 NWidget(WWT_EDITBOX, COLOUR_ORANGE, WID_GL_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
221 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
222 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
223 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_ROTATION_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_DATE, STR_NULL), SetFill(1, 1),
230 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
231 EndContainer(),
232 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
233 NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
234 NWidget(NWID_HORIZONTAL),
235 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),
236 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
237 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),
238 EndContainer(),
239 NWidget(NWID_HORIZONTAL),
240 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
241 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
242 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
243 EndContainer(),
244 EndContainer(),
245 EndContainer(),
246 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
247 NWidget(NWID_SPACER), SetFill(1, 1),
248 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 30), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 0),
249 EndContainer(),
250 EndContainer(),
251 EndContainer(),
252 EndContainer(),
253 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
254 EndContainer(),
257 static void StartGeneratingLandscape(GenenerateLandscapeWindowMode mode)
259 DeleteAllNonVitalWindows();
260 ClearErrorMessages();
262 /* Copy all XXX_newgame to XXX when coming from outside the editor */
263 MakeNewgameSettingsLive();
264 ResetGRFConfig(true);
266 if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
267 switch (mode) {
268 case GLWM_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break;
269 case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
270 case GLWM_SCENARIO: _switch_mode = SM_EDITOR; break;
271 default: NOT_REACHED();
275 static void LandscapeGenerationCallback(Window *w, bool confirmed)
277 if (confirmed) StartGeneratingLandscape((GenenerateLandscapeWindowMode)w->window_number);
280 static DropDownList *BuildMapsizeDropDown()
282 DropDownList *list = new DropDownList();
284 for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
285 DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
286 item->SetParam(0, 1 << i);
287 *list->Append() = item;
290 return list;
293 static const StringID _elevations[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, INVALID_STRING_ID};
294 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};
295 static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
296 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};
297 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};
298 static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
299 static const StringID _landscape[] = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
300 static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
301 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};
302 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};
304 assert_compile(lengthof(_num_inds) == ID_END + 1);
306 struct GenerateLandscapeWindow : public Window {
307 uint widget_id;
308 uint x;
309 uint y;
310 char name[64];
311 GenenerateLandscapeWindowMode mode;
312 QueryString seed_editbox;
314 GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc), seed_editbox(11)
316 this->InitNested(number);
318 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_GL_TEMPERATE);
320 this->querystrings[WID_GL_RANDOM_EDITBOX] = &this->seed_editbox;
321 this->seed_editbox.text.Print("%u", _settings_newgame.game_creation.generation_seed);
322 this->seed_editbox.caption = STR_NULL;
323 this->seed_editbox.text.afilter = CS_NUMERAL;
325 this->mode = (GenenerateLandscapeWindowMode)this->window_number;
327 /* Disable town, industry and trees in SE */
328 this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
329 this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
330 this->SetWidgetDisabledState(WID_GL_TREE_PULLDOWN, _game_mode == GM_EDITOR);
332 this->OnInvalidateData();
336 virtual void SetStringParameters(int widget) const
338 switch (widget) {
339 case WID_GL_START_DATE_TEXT: SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
340 case WID_GL_MAPSIZE_X_PULLDOWN: SetDParam(0, 1 << _settings_newgame.game_creation.map_x); break;
341 case WID_GL_MAPSIZE_Y_PULLDOWN: SetDParam(0, 1 << _settings_newgame.game_creation.map_y); break;
342 case WID_GL_SNOW_LEVEL_TEXT: SetDParam(0, _settings_newgame.game_creation.snow_line_height); break;
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]);
353 break;
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;
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]);
367 break;
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;
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);
387 break;
392 * Some data on this window has become invalid.
393 * @param data Information about the changed data.
394 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
396 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
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);
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 == 0);
408 this->SetWidgetDisabledState(WID_GL_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
409 this->SetWidgetDisabledState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges);
410 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 || !_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);
413 this->SetWidgetLoweredState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
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));
420 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 && (_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);
424 /* Disable snowline if not arctic */
425 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
427 /* Update availability of decreasing / increasing start date and snow level */
428 this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
429 this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
430 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_DOWN, _settings_newgame.game_creation.snow_line_height <= MIN_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
431 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 /* Do not allow a custom sea level with the original land generator. */
434 if (_settings_newgame.game_creation.land_generator == 0 &&
435 _settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
436 _settings_newgame.difficulty.quantity_sea_lakes = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE;
441 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
443 const StringID *strs = NULL;
444 switch (widget) {
445 case WID_GL_START_DATE_TEXT:
446 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
447 *size = GetStringBoundingBox(STR_BLACK_DATE_LONG);
448 break;
450 case WID_GL_MAPSIZE_X_PULLDOWN:
451 case WID_GL_MAPSIZE_Y_PULLDOWN:
452 SetDParamMaxValue(0, MAX_MAP_SIZE);
453 *size = GetStringBoundingBox(STR_JUST_INT);
454 break;
456 case WID_GL_SNOW_LEVEL_TEXT:
457 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
458 *size = GetStringBoundingBox(STR_JUST_INT);
459 break;
461 case WID_GL_HEIGHTMAP_SIZE_TEXT:
462 SetDParam(0, this->x);
463 SetDParam(1, this->y);
464 *size = GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE);
465 break;
467 case WID_GL_TOWN_PULLDOWN:
468 strs = _num_towns;
469 SetDParamMaxValue(0, CUSTOM_TOWN_MAX_NUMBER);
470 *size = GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER);
471 break;
473 case WID_GL_INDUSTRY_PULLDOWN: strs = _num_inds; break;
474 case WID_GL_LANDSCAPE_PULLDOWN: strs = _landscape; break;
475 case WID_GL_TREE_PULLDOWN: strs = _tree_placer; break;
476 case WID_GL_TERRAIN_PULLDOWN: strs = _elevations; break;
477 case WID_GL_WATER_PULLDOWN:
478 strs = _sea_lakes;
479 SetDParamMaxValue(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
480 *size = GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
481 break;
483 case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
484 case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
485 case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
486 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
487 case WID_GL_BORDERS_RANDOM:
488 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
489 break;
491 case WID_GL_WATER_NE:
492 case WID_GL_WATER_NW:
493 case WID_GL_WATER_SE:
494 case WID_GL_WATER_SW:
495 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
496 break;
498 case WID_GL_HEIGHTMAP_NAME_TEXT:
499 size->width = 0;
500 break;
502 default:
503 return;
505 if (strs != NULL) {
506 while (*strs != INVALID_STRING_ID) {
507 *size = maxdim(*size, GetStringBoundingBox(*strs++));
510 size->width += padding.width;
511 size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
514 virtual void DrawWidget(const Rect &r, int widget) const
516 switch (widget) {
517 case WID_GL_HEIGHTMAP_NAME_TEXT: {
518 DrawString(r.left, r.right, r.top, this->name, TC_ORANGE);
519 break;
524 virtual void OnClick(Point pt, int widget, int click_count)
526 switch (widget) {
527 case WID_GL_TEMPERATE:
528 case WID_GL_ARCTIC:
529 case WID_GL_TROPICAL:
530 case WID_GL_TOYLAND:
531 SetNewLandscapeType(widget - WID_GL_TEMPERATE);
532 break;
534 case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
535 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
536 break;
538 case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
539 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
540 break;
542 case WID_GL_TOWN_PULLDOWN: // Number of towns
543 ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
544 break;
546 case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
547 ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
548 break;
550 case WID_GL_RANDOM_BUTTON: // Random seed
551 _settings_newgame.game_creation.generation_seed = InteractiveRandom();
552 this->seed_editbox.text.Print("%u", _settings_newgame.game_creation.generation_seed);
553 this->SetDirty();
554 break;
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;
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);
580 break;
583 case WID_GL_START_DATE_DOWN:
584 case WID_GL_START_DATE_UP: // Year buttons
585 /* Don't allow too fast scrolling */
586 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
587 this->HandleButtonClick(widget);
589 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
590 this->InvalidateData();
592 _left_button_clicked = false;
593 break;
595 case WID_GL_START_DATE_TEXT: // Year text
596 this->widget_id = WID_GL_START_DATE_TEXT;
597 SetDParam(0, _settings_newgame.game_creation.starting_year);
598 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
599 break;
601 case WID_GL_SNOW_LEVEL_DOWN:
602 case WID_GL_SNOW_LEVEL_UP: // Snow line buttons
603 /* Don't allow too fast scrolling */
604 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
605 this->HandleButtonClick(widget);
607 _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);
608 this->InvalidateData();
610 _left_button_clicked = false;
611 break;
613 case WID_GL_SNOW_LEVEL_TEXT: // Snow line text
614 this->widget_id = WID_GL_SNOW_LEVEL_TEXT;
615 SetDParam(0, _settings_newgame.game_creation.snow_line_height);
616 ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 3, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
617 break;
619 case WID_GL_TREE_PULLDOWN: // Tree placer
620 ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, WID_GL_TREE_PULLDOWN, 0, 0);
621 break;
623 case WID_GL_LANDSCAPE_PULLDOWN: // Landscape generator
624 ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, WID_GL_LANDSCAPE_PULLDOWN, 0, 0);
625 break;
627 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
628 ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
629 break;
631 case WID_GL_TERRAIN_PULLDOWN: // Terrain type
632 ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, WID_GL_TERRAIN_PULLDOWN, 0, 0);
633 break;
635 case WID_GL_WATER_PULLDOWN: { // Water quantity
636 uint32 hidden_mask = 0;
637 /* Disable custom water level when the original map generator is active. */
638 if (_settings_newgame.game_creation.land_generator == 0) {
639 SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
641 ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
642 break;
645 case WID_GL_RIVER_PULLDOWN: // Amount of rivers
646 ShowDropDownMenu(this, _rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
647 break;
649 case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
650 ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
651 break;
653 case WID_GL_VARIETY_PULLDOWN: // Map variety
654 ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
655 break;
657 /* Freetype map borders */
658 case WID_GL_WATER_NW:
659 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
660 this->InvalidateData();
661 break;
663 case WID_GL_WATER_NE:
664 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
665 this->InvalidateData();
666 break;
668 case WID_GL_WATER_SE:
669 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
670 this->InvalidateData();
671 break;
673 case WID_GL_WATER_SW:
674 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
675 this->InvalidateData();
676 break;
678 case WID_GL_BORDERS_RANDOM:
679 _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
680 this->InvalidateData();
681 break;
685 virtual void OnTimeout()
687 static const int raise_widgets[] = {WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_LEVEL_UP, WID_GL_SNOW_LEVEL_DOWN, WIDGET_LIST_END};
688 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
689 if (this->IsWidgetLowered(*widget)) {
690 this->RaiseWidget(*widget);
691 this->SetWidgetDirty(*widget);
696 virtual void OnEditboxChanged(int wid)
698 if (wid == WID_GL_RANDOM_EDITBOX) {
699 /* the seed is unsigned, therefore atoi cannot be used.
700 * As UINT32_MAX is a 'magic' value (use random seed) it
701 * should not be possible to be entered into the input
702 * field; the generate seed button can be used instead. */
703 _settings_newgame.game_creation.generation_seed = minu(strtoul(this->seed_editbox.text.buf, NULL, 10), UINT32_MAX - 1);
707 virtual void OnDropdownSelect(int widget, int index)
709 switch (widget) {
710 case WID_GL_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
711 case WID_GL_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
712 case WID_GL_TREE_PULLDOWN: _settings_newgame.game_creation.tree_placer = index; break;
713 case WID_GL_RIVER_PULLDOWN: _settings_newgame.game_creation.amount_of_rivers = index; break;
714 case WID_GL_SMOOTHNESS_PULLDOWN: _settings_newgame.game_creation.tgen_smoothness = index; break;
715 case WID_GL_VARIETY_PULLDOWN: _settings_newgame.game_creation.variety = index; break;
716 case WID_GL_LANDSCAPE_PULLDOWN: _settings_newgame.game_creation.land_generator = index; break;
717 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
719 case WID_GL_TOWN_PULLDOWN:
720 if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
721 this->widget_id = widget;
722 SetDParam(0, _settings_newgame.game_creation.custom_town_number);
723 ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE);
725 IConsoleSetSetting("difficulty.number_towns", index);
726 break;
728 case WID_GL_INDUSTRY_PULLDOWN:
729 IConsoleSetSetting("difficulty.industry_density", index);
730 break;
732 case WID_GL_TERRAIN_PULLDOWN: {
733 GameMode old_gm = _game_mode;
734 _game_mode = GM_MENU;
735 IConsoleSetSetting("difficulty.terrain_type", index);
736 _game_mode = old_gm;
737 break;
740 case WID_GL_WATER_PULLDOWN: {
741 if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
742 this->widget_id = widget;
743 SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
744 ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, this, CS_NUMERAL, QSF_NONE);
746 GameMode old_gm = _game_mode;
747 _game_mode = GM_MENU;
748 IConsoleSetSetting("difficulty.quantity_sea_lakes", index);
749 _game_mode = old_gm;
750 break;
753 this->InvalidateData();
756 virtual void OnQueryTextFinished(char *str)
758 /* Was 'cancel' pressed? */
759 if (str == NULL) return;
761 int32 value;
762 if (!StrEmpty(str)) {
763 value = atoi(str);
764 } else {
765 /* An empty string means revert to the default */
766 switch (this->widget_id) {
767 case WID_GL_START_DATE_TEXT: value = DEF_START_YEAR; break;
768 case WID_GL_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
769 case WID_GL_TOWN_PULLDOWN: value = 1; break;
770 case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
771 default: NOT_REACHED();
775 switch (this->widget_id) {
776 case WID_GL_START_DATE_TEXT:
777 this->SetWidgetDirty(WID_GL_START_DATE_TEXT);
778 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
779 break;
781 case WID_GL_SNOW_LEVEL_TEXT:
782 this->SetWidgetDirty(WID_GL_SNOW_LEVEL_TEXT);
783 _settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
784 break;
786 case WID_GL_TOWN_PULLDOWN:
787 _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
788 break;
790 case WID_GL_WATER_PULLDOWN:
791 _settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
792 break;
795 this->InvalidateData();
799 static WindowDesc _generate_landscape_desc(
800 WDP_CENTER, NULL, 0, 0,
801 WC_GENERATE_LANDSCAPE, WC_NONE,
803 _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
806 static WindowDesc _heightmap_load_desc(
807 WDP_CENTER, NULL, 0, 0,
808 WC_GENERATE_LANDSCAPE, WC_NONE,
810 _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
813 static void _ShowGenerateLandscape(GenenerateLandscapeWindowMode mode)
815 uint x = 0;
816 uint y = 0;
818 DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
820 /* Always give a new seed if not editor */
821 if (_game_mode != GM_EDITOR) _settings_newgame.game_creation.generation_seed = InteractiveRandom();
823 if (mode == GLWM_HEIGHTMAP) {
824 /* If the function returns negative, it means there was a problem loading the heightmap */
825 if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
828 GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
830 if (mode == GLWM_HEIGHTMAP) {
831 w->x = x;
832 w->y = y;
833 strecpy(w->name, _file_to_saveload.title, lastof(w->name));
836 SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
839 /** Start with a normal game. */
840 void ShowGenerateLandscape()
842 _ShowGenerateLandscape(GLWM_GENERATE);
845 /** Start with loading a heightmap. */
846 void ShowHeightmapLoad()
848 _ShowGenerateLandscape(GLWM_HEIGHTMAP);
851 /** Start with a scenario editor. */
852 void StartScenarioEditor()
854 StartGeneratingLandscape(GLWM_SCENARIO);
858 * Start a normal game without the GUI.
859 * @param seed The seed of the new game.
861 void StartNewGameWithoutGUI(uint seed)
863 /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
864 _settings_newgame.game_creation.generation_seed = seed;
866 StartGeneratingLandscape(GLWM_GENERATE);
869 struct CreateScenarioWindow : public Window
871 uint widget_id;
873 CreateScenarioWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
875 this->InitNested(window_number);
876 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
879 virtual void SetStringParameters(int widget) const
881 switch (widget) {
882 case WID_CS_START_DATE_TEXT:
883 SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
884 break;
886 case WID_CS_MAPSIZE_X_PULLDOWN:
887 SetDParam(0, 1 << _settings_newgame.game_creation.map_x);
888 break;
890 case WID_CS_MAPSIZE_Y_PULLDOWN:
891 SetDParam(0, 1 << _settings_newgame.game_creation.map_y);
892 break;
894 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
895 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
896 break;
900 virtual void OnPaint()
902 this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
903 this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
904 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
905 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP, _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
907 this->SetWidgetLoweredState(WID_CS_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
908 this->SetWidgetLoweredState(WID_CS_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
909 this->SetWidgetLoweredState(WID_CS_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
910 this->SetWidgetLoweredState(WID_CS_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
912 this->DrawWidgets();
915 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
917 StringID str = STR_JUST_INT;
918 switch (widget) {
919 case WID_CS_START_DATE_TEXT:
920 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
921 str = STR_BLACK_DATE_LONG;
922 break;
924 case WID_CS_MAPSIZE_X_PULLDOWN:
925 case WID_CS_MAPSIZE_Y_PULLDOWN:
926 SetDParamMaxValue(0, MAX_MAP_SIZE);
927 break;
929 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
930 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
931 break;
933 default:
934 return;
936 *size = GetStringBoundingBox(str);
937 size->width += padding.width;
938 size->height += padding.height;
941 virtual void OnClick(Point pt, int widget, int click_count)
943 switch (widget) {
944 case WID_CS_TEMPERATE:
945 case WID_CS_ARCTIC:
946 case WID_CS_TROPICAL:
947 case WID_CS_TOYLAND:
948 this->RaiseWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
949 SetNewLandscapeType(widget - WID_CS_TEMPERATE);
950 break;
952 case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
953 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
954 break;
956 case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
957 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
958 break;
960 case WID_CS_EMPTY_WORLD: // Empty world / flat world
961 StartGeneratingLandscape(GLWM_SCENARIO);
962 break;
964 case WID_CS_RANDOM_WORLD: // Generate
965 ShowGenerateLandscape();
966 break;
968 case WID_CS_START_DATE_DOWN:
969 case WID_CS_START_DATE_UP: // Year buttons
970 /* Don't allow too fast scrolling */
971 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
972 this->HandleButtonClick(widget);
973 this->SetDirty();
975 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
977 _left_button_clicked = false;
978 break;
980 case WID_CS_START_DATE_TEXT: // Year text
981 this->widget_id = WID_CS_START_DATE_TEXT;
982 SetDParam(0, _settings_newgame.game_creation.starting_year);
983 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE);
984 break;
986 case WID_CS_FLAT_LAND_HEIGHT_DOWN:
987 case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
988 /* Don't allow too fast scrolling */
989 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
990 this->HandleButtonClick(widget);
991 this->SetDirty();
993 _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, MAX_TILE_HEIGHT);
995 _left_button_clicked = false;
996 break;
998 case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
999 this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1000 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
1001 ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, this, CS_NUMERAL, QSF_NONE);
1002 break;
1006 virtual void OnTimeout()
1008 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};
1009 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
1010 if (this->IsWidgetLowered(*widget)) {
1011 this->RaiseWidget(*widget);
1012 this->SetWidgetDirty(*widget);
1017 virtual void OnDropdownSelect(int widget, int index)
1019 switch (widget) {
1020 case WID_CS_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
1021 case WID_CS_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
1023 this->SetDirty();
1026 virtual void OnQueryTextFinished(char *str)
1028 if (!StrEmpty(str)) {
1029 int32 value = atoi(str);
1031 switch (this->widget_id) {
1032 case WID_CS_START_DATE_TEXT:
1033 this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
1034 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
1035 break;
1037 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
1038 this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
1039 _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
1040 break;
1043 this->SetDirty();
1048 static const NWidgetPart _nested_create_scenario_widgets[] = {
1049 NWidget(NWID_HORIZONTAL),
1050 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1051 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
1052 EndContainer(),
1053 NWidget(WWT_PANEL, COLOUR_BROWN),
1054 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
1055 /* Landscape style selection. */
1056 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
1057 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
1058 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1059 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1060 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1061 EndContainer(),
1062 NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
1063 /* Green generation type buttons: 'Flat land' and 'Random land'. */
1064 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1065 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1066 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1067 EndContainer(),
1068 /* Labels + setting drop-downs */
1069 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1070 /* Map size. */
1071 NWidget(NWID_HORIZONTAL),
1072 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
1073 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1074 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
1075 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
1076 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
1077 EndContainer(),
1078 /* Date. */
1079 NWidget(NWID_HORIZONTAL),
1080 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
1081 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1082 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),
1083 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
1084 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),
1085 EndContainer(),
1086 /* Flat map height. */
1087 NWidget(NWID_HORIZONTAL),
1088 NWidget(WWT_TEXT, COLOUR_ORANGE),
1089 SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
1090 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1091 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),
1092 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
1093 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),
1094 EndContainer(),
1095 EndContainer(),
1096 EndContainer(),
1097 EndContainer(),
1100 static WindowDesc _create_scenario_desc(
1101 WDP_CENTER, NULL, 0, 0,
1102 WC_GENERATE_LANDSCAPE, WC_NONE,
1104 _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
1107 /** Show the window to create a scenario. */
1108 void ShowCreateScenario()
1110 DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
1111 new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
1114 static const NWidgetPart _nested_generate_progress_widgets[] = {
1115 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1116 NWidget(WWT_PANEL, COLOUR_GREY),
1117 NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
1118 NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
1119 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
1120 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
1121 NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
1122 EndContainer(),
1123 EndContainer(),
1124 EndContainer(),
1128 static WindowDesc _generate_progress_desc(
1129 WDP_CENTER, NULL, 0, 0,
1130 WC_MODAL_PROGRESS, WC_NONE,
1132 _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
1135 struct GenWorldStatus {
1136 uint percent;
1137 StringID cls;
1138 uint current;
1139 uint total;
1140 int timer;
1143 static GenWorldStatus _gws;
1145 static const StringID _generation_class_table[] = {
1146 STR_GENERATION_WORLD_GENERATION,
1147 STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
1148 STR_GENERATION_RIVER_GENERATION,
1149 STR_GENERATION_CLEARING_TILES,
1150 STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
1151 STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
1152 STR_GENERATION_OBJECT_GENERATION,
1153 STR_GENERATION_TREE_GENERATION,
1154 STR_GENERATION_SETTINGUP_GAME,
1155 STR_GENERATION_PREPARING_TILELOOP,
1156 STR_GENERATION_PREPARING_SCRIPT,
1157 STR_GENERATION_PREPARING_GAME
1159 assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
1162 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
1164 if (confirmed) {
1165 AbortGeneratingWorld();
1166 } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1167 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1171 struct GenerateProgressWindow : public Window {
1173 GenerateProgressWindow() : Window(&_generate_progress_desc)
1175 this->InitNested();
1178 virtual void OnClick(Point pt, int widget, int click_count)
1180 switch (widget) {
1181 case WID_GP_ABORT:
1182 if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
1183 ShowQuery(
1184 STR_GENERATION_ABORT_CAPTION,
1185 STR_GENERATION_ABORT_MESSAGE,
1186 this,
1187 AbortGeneratingWorldCallback
1189 break;
1193 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1195 switch (widget) {
1196 case WID_GP_PROGRESS_BAR: {
1197 SetDParamMaxValue(0, 100);
1198 *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
1199 /* We need some spacing for the 'border' */
1200 size->height += 8;
1201 size->width += 8;
1202 break;
1205 case WID_GP_PROGRESS_TEXT:
1206 for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
1207 size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
1209 size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
1210 break;
1214 virtual void DrawWidget(const Rect &r, int widget) const
1216 switch (widget) {
1217 case WID_GP_PROGRESS_BAR:
1218 /* Draw the % complete with a bar and a text */
1219 DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
1220 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);
1221 SetDParam(0, _gws.percent);
1222 DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
1223 break;
1225 case WID_GP_PROGRESS_TEXT:
1226 /* Tell which class we are generating */
1227 DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
1229 /* And say where we are in that class */
1230 SetDParam(0, _gws.current);
1231 SetDParam(1, _gws.total);
1232 DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
1238 * Initializes the progress counters to the starting point.
1240 void PrepareGenerateWorldProgress()
1242 _gws.cls = STR_GENERATION_WORLD_GENERATION;
1243 _gws.current = 0;
1244 _gws.total = 0;
1245 _gws.percent = 0;
1246 _gws.timer = 0; // Forces to paint the progress window immediately
1250 * Show the window where a user can follow the process of the map generation.
1252 void ShowGenerateWorldProgress()
1254 if (BringWindowToFrontById(WC_MODAL_PROGRESS, 0)) return;
1255 new GenerateProgressWindow();
1258 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1260 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
1261 assert_compile(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1262 assert(cls < GWP_CLASS_COUNT);
1264 /* Do not run this function if we aren't in a thread */
1265 if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
1267 if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
1269 if (total == 0) {
1270 assert(_gws.cls == _generation_class_table[cls]);
1271 _gws.current += progress;
1272 assert(_gws.current <= _gws.total);
1273 } else {
1274 _gws.cls = _generation_class_table[cls];
1275 _gws.current = progress;
1276 _gws.total = total;
1277 _gws.percent = percent_table[cls];
1280 /* Don't update the screen too often. So update it once in every once in a while... */
1281 if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < MODAL_PROGRESS_REDRAW_TIMEOUT) return;
1283 /* Percentage is about the number of completed tasks, so 'current - 1' */
1284 _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
1286 if (_network_dedicated) {
1287 static uint last_percent = 0;
1289 /* Never display 0% */
1290 if (_gws.percent == 0) return;
1291 /* Reset if percent is lower than the last recorded */
1292 if (_gws.percent < last_percent) last_percent = 0;
1293 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1294 if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
1295 /* Never show steps smaller than 2%, even if it is a mod 5% */
1296 if (_gws.percent <= last_percent + 2) return;
1298 DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
1299 last_percent = _gws.percent;
1301 /* Don't continue as dedicated never has a thread running */
1302 return;
1305 SetWindowDirty(WC_MODAL_PROGRESS, 0);
1306 MarkWholeScreenDirty();
1308 /* Release the rights to the map generator, and acquire the rights to the
1309 * paint thread. The 'other' thread already has the paint thread rights so
1310 * this ensures us that we are waiting until the paint thread is done
1311 * before we reacquire the mapgen rights */
1312 _modal_progress_work_mutex->EndCritical();
1313 _modal_progress_paint_mutex->BeginCritical();
1314 _modal_progress_work_mutex->BeginCritical();
1315 _modal_progress_paint_mutex->EndCritical();
1317 _gws.timer = _realtime_tick;
1321 * Set the total of a stage of the world generation.
1322 * @param cls the current class we are in.
1323 * @param total Set the total expected items for this class.
1325 * Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
1326 * Also, progress works if total is zero, total works if progress is zero.
1328 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
1330 if (total == 0) return;
1332 _SetGeneratingWorldProgress(cls, 0, total);
1336 * Increases the current stage of the world generation with one.
1337 * @param cls the current class we are in.
1339 * Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
1340 * Also, progress works if total is zero, total works if progress is zero.
1342 void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
1344 /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1345 _SetGeneratingWorldProgress(cls, 1, 0);