Translations update
[openttd/fttd.git] / src / genworld_gui.cpp
bloba7b5a9ed4595b4643674df4cf6eff38ecce45c8a
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.h"
23 #include "widgets/dropdown_type.h"
24 #include "widgets/dropdown_func.h"
25 #include "querystring_gui.h"
26 #include "town.h"
27 #include "core/geometry_func.hpp"
28 #include "core/random_func.hpp"
29 #include "saveload/saveload.h"
30 #include "progress.h"
31 #include "error.h"
33 #include "widgets/genworld_widget.h"
36 extern void MakeNewgameSettingsLive();
38 /** Enum for the modes we can generate in. */
39 enum GenerateLandscapeWindowMode {
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), SetMinimalSize(76, 54), 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), SetMinimalSize(76, 54), 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), SetMinimalSize(76, 54), 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), SetMinimalSize(76, 54), 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_VARIETY, STR_NULL), SetFill(1, 1),
86 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, 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_EDITBOX, COLOUR_ORANGE, WID_GL_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
104 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_WATER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
105 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
106 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_BORDERS_RANDOM), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
107 EndContainer(),
108 EndContainer(),
109 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
110 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
111 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
112 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
113 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
114 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
115 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
116 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
117 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 EndContainer(),
140 EndContainer(),
141 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
142 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
143 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
144 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
145 EndContainer(),
146 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
147 EndContainer(),
148 EndContainer(),
149 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
150 /* Map borders buttons for each edge. */
151 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
152 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
153 NWidget(NWID_SPACER), SetFill(1, 1),
154 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
155 EndContainer(),
156 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
157 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
158 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
159 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
160 NWidget(NWID_SPACER), SetFill(1, 1),
161 EndContainer(),
162 EndContainer(),
163 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
164 NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
165 NWidget(NWID_SPACER), SetFill(1, 1),
166 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
167 EndContainer(),
168 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
169 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
170 NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
171 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
172 NWidget(NWID_SPACER), SetFill(1, 1),
173 EndContainer(),
174 EndContainer(),
175 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
176 EndContainer(),
179 /** Widgets of GenerateLandscapeWindow when loading heightmap */
180 static const NWidgetPart _nested_heightmap_load_widgets[] = {
181 /* Window header. */
182 NWidget(NWID_HORIZONTAL),
183 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
184 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
185 EndContainer(),
186 NWidget(WWT_PANEL, COLOUR_BROWN),
187 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
188 /* Landscape selection. */
189 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
190 NWidget(NWID_SPACER), SetFill(1, 0),
191 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
192 NWidget(NWID_SPACER), SetFill(1, 0),
193 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
194 NWidget(NWID_SPACER), SetFill(1, 0),
195 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
196 NWidget(NWID_SPACER), SetFill(1, 0),
197 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
198 NWidget(NWID_SPACER), SetFill(1, 0),
199 EndContainer(),
200 NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
201 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
202 /* Labels at the left side. */
203 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
204 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
205 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
206 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
207 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
208 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
209 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
210 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
211 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
212 EndContainer(),
213 /* Widgets at the right of the labels. */
214 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
215 NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
216 NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
217 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
218 /* Mapsize X * Y. */
219 NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
220 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
221 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
222 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
223 EndContainer(),
224 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
225 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
226 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
227 NWidget(WWT_EDITBOX, COLOUR_ORANGE, WID_GL_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
228 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
229 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
230 EndContainer(),
231 NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
232 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
233 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
234 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_NULL), SetFill(1, 1),
235 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
236 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
237 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
238 EndContainer(),
239 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
240 NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
241 NWidget(NWID_HORIZONTAL),
242 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
243 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
244 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
245 EndContainer(),
246 NWidget(NWID_HORIZONTAL),
247 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_MAX_HEIGHTLEVEL_DOWN), SetFill(0, 1),
248 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
249 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_MAX_HEIGHTLEVEL_UP), SetFill(0, 1),
250 EndContainer(),
251 NWidget(NWID_HORIZONTAL),
252 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),
253 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
254 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),
255 EndContainer(),
256 EndContainer(),
257 EndContainer(),
258 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
259 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
260 EndContainer(),
261 EndContainer(),
262 EndContainer(),
263 EndContainer(),
264 NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
265 EndContainer(),
268 static void StartGeneratingLandscape(GenerateLandscapeWindowMode mode)
270 DeleteAllNonVitalWindows();
271 ClearErrorMessages();
273 /* Copy all XXX_newgame to XXX when coming from outside the editor */
274 MakeNewgameSettingsLive();
275 ResetGRFConfig(true);
277 if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
278 switch (mode) {
279 case GLWM_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break;
280 case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
281 case GLWM_SCENARIO: _switch_mode = SM_EDITOR; break;
282 default: NOT_REACHED();
286 static void LandscapeGenerationCallback(Window *w, bool confirmed)
288 if (confirmed) StartGeneratingLandscape((GenerateLandscapeWindowMode)w->window_number);
291 static DropDownList *BuildMapsizeDropDown()
293 DropDownList *list = new DropDownList();
295 for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
296 DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
297 item->SetParam(0, 1 << i);
298 *list->Append() = item;
301 return list;
304 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};
305 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};
306 static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
307 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};
308 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};
309 static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
310 static const StringID _landscape[] = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
311 static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
312 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};
313 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};
315 assert_compile(lengthof(_num_inds) == ID_END + 1);
317 struct GenerateLandscapeWindow : public Window {
318 uint widget_id;
319 uint x;
320 uint y;
321 char name[64];
322 GenerateLandscapeWindowMode mode;
323 QueryStringN<11> seed_editbox;
325 GenerateLandscapeWindow (const WindowDesc *desc, WindowNumber number = 0)
326 : Window (desc), widget_id (0), x (0), y (0), seed_editbox ()
328 this->name[0] = '\0';
330 this->InitNested(number);
332 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_GL_TEMPERATE);
334 this->querystrings[WID_GL_RANDOM_EDITBOX] = &this->seed_editbox;
335 this->seed_editbox.Print("%u", _settings_newgame.game_creation.generation_seed);
336 this->seed_editbox.caption = STR_NULL;
337 this->seed_editbox.afilter = CS_NUMERAL;
339 this->mode = (GenerateLandscapeWindowMode)this->window_number;
341 /* Disable town, industry and trees in SE */
342 this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
343 this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
344 this->SetWidgetDisabledState(WID_GL_TREE_PULLDOWN, _game_mode == GM_EDITOR);
346 this->OnInvalidateData();
350 virtual void SetStringParameters(int widget) const
352 switch (widget) {
353 case WID_GL_START_DATE_TEXT: SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
354 case WID_GL_MAPSIZE_X_PULLDOWN: SetDParam(0, 1 << _settings_newgame.game_creation.map_x); break;
355 case WID_GL_MAPSIZE_Y_PULLDOWN: SetDParam(0, 1 << _settings_newgame.game_creation.map_y); break;
356 case WID_GL_MAX_HEIGHTLEVEL_TEXT: SetDParam(0, _settings_newgame.construction.max_heightlevel); break;
357 case WID_GL_SNOW_LEVEL_TEXT: SetDParam(0, _settings_newgame.game_creation.snow_line_height); break;
359 case WID_GL_TOWN_PULLDOWN:
360 if (_game_mode == GM_EDITOR) {
361 SetDParam(0, STR_CONFIG_SETTING_OFF);
362 } else if (_settings_newgame.difficulty.number_towns == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
363 SetDParam(0, STR_NUM_CUSTOM_NUMBER);
364 SetDParam(1, _settings_newgame.game_creation.custom_town_number);
365 } else {
366 SetDParam(0, _num_towns[_settings_newgame.difficulty.number_towns]);
368 break;
370 case WID_GL_INDUSTRY_PULLDOWN: SetDParam(0, _game_mode == GM_EDITOR ? STR_CONFIG_SETTING_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
371 case WID_GL_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
372 case WID_GL_TREE_PULLDOWN: SetDParam(0, _tree_placer[_settings_newgame.game_creation.tree_placer]); break;
373 case WID_GL_TERRAIN_PULLDOWN: SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
375 case WID_GL_WATER_PULLDOWN:
376 if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
377 SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
378 SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
379 } else {
380 SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
382 break;
384 case WID_GL_RIVER_PULLDOWN: SetDParam(0, _rivers[_settings_newgame.game_creation.amount_of_rivers]); break;
385 case WID_GL_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
386 case WID_GL_VARIETY_PULLDOWN: SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
387 case WID_GL_BORDERS_RANDOM: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
388 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;
389 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;
390 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;
391 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;
392 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: SetDParam(0, _rotation[_settings_newgame.game_creation.heightmap_rotation]); break;
394 case WID_GL_HEIGHTMAP_SIZE_TEXT:
395 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
396 SetDParam(0, this->y);
397 SetDParam(1, this->x);
398 } else {
399 SetDParam(0, this->x);
400 SetDParam(1, this->y);
402 break;
407 * Some data on this window has become invalid.
408 * @param data Information about the changed data.
409 * @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.
411 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
413 if (!gui_scope) return;
414 /* Update the climate buttons */
415 this->SetWidgetLoweredState(WID_GL_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
416 this->SetWidgetLoweredState(WID_GL_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
417 this->SetWidgetLoweredState(WID_GL_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
418 this->SetWidgetLoweredState(WID_GL_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
420 /* You can't select smoothness / non-water borders if not terragenesis */
421 if (mode == GLWM_GENERATE) {
422 this->SetWidgetDisabledState(WID_GL_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == LG_ORIGINAL);
423 this->SetWidgetDisabledState(WID_GL_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == LG_ORIGINAL);
424 this->SetWidgetDisabledState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges);
425 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
426 WID_GL_WATER_NW, WID_GL_WATER_NE, WID_GL_WATER_SE, WID_GL_WATER_SW, WIDGET_LIST_END);
428 this->SetWidgetLoweredState(WID_GL_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
430 this->SetWidgetLoweredState(WID_GL_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
431 this->SetWidgetLoweredState(WID_GL_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
432 this->SetWidgetLoweredState(WID_GL_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
433 this->SetWidgetLoweredState(WID_GL_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
435 this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == LG_ORIGINAL && (_settings_newgame.game_creation.landscape == LT_ARCTIC || _settings_newgame.game_creation.landscape == LT_TROPIC),
436 WID_GL_TERRAIN_PULLDOWN, WID_GL_WATER_PULLDOWN, WIDGET_LIST_END);
439 /* Disable snowline if not arctic */
440 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
442 /* Update availability of decreasing / increasing start date and snow level */
443 this->SetWidgetDisabledState(WID_GL_MAX_HEIGHTLEVEL_DOWN, _settings_newgame.construction.max_heightlevel <= MIN_MAX_HEIGHTLEVEL);
444 this->SetWidgetDisabledState(WID_GL_MAX_HEIGHTLEVEL_UP, _settings_newgame.construction.max_heightlevel >= MAX_MAX_HEIGHTLEVEL);
445 this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
446 this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
447 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_DOWN, _settings_newgame.game_creation.snow_line_height <= MIN_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
448 this->SetWidgetDisabledState(WID_GL_SNOW_LEVEL_UP, _settings_newgame.game_creation.snow_line_height >= MAX_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
450 /* Do not allow a custom sea level with the original land generator. */
451 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL &&
452 _settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
453 _settings_newgame.difficulty.quantity_sea_lakes = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE;
458 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
460 const StringID *strs = NULL;
461 switch (widget) {
462 case WID_GL_MAX_HEIGHTLEVEL_TEXT:
463 SetDParam(0, MAX_TILE_HEIGHT);
464 *size = GetStringBoundingBox(STR_JUST_INT);
465 break;
467 case WID_GL_START_DATE_TEXT:
468 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
469 *size = maxdim(*size, GetStringBoundingBox(STR_BLACK_DATE_LONG));
470 break;
472 case WID_GL_MAPSIZE_X_PULLDOWN:
473 case WID_GL_MAPSIZE_Y_PULLDOWN:
474 SetDParamMaxValue(0, MAX_MAP_SIZE);
475 *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
476 break;
478 case WID_GL_SNOW_LEVEL_TEXT:
479 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
480 *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
481 break;
483 case WID_GL_HEIGHTMAP_SIZE_TEXT:
484 SetDParam(0, this->x);
485 SetDParam(1, this->y);
486 *size = maxdim(*size, GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE));
487 break;
489 case WID_GL_TOWN_PULLDOWN:
490 strs = _num_towns;
491 SetDParamMaxValue(0, CUSTOM_TOWN_MAX_NUMBER);
492 *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
493 break;
495 case WID_GL_INDUSTRY_PULLDOWN: strs = _num_inds; break;
496 case WID_GL_LANDSCAPE_PULLDOWN: strs = _landscape; break;
497 case WID_GL_TREE_PULLDOWN: strs = _tree_placer; break;
498 case WID_GL_TERRAIN_PULLDOWN: strs = _elevations; break;
499 case WID_GL_WATER_PULLDOWN:
500 strs = _sea_lakes;
501 SetDParamMaxValue(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
502 *size = maxdim(*size, GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE));
503 break;
505 case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
506 case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
507 case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
508 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
509 case WID_GL_BORDERS_RANDOM:
510 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
511 break;
513 case WID_GL_WATER_NE:
514 case WID_GL_WATER_NW:
515 case WID_GL_WATER_SE:
516 case WID_GL_WATER_SW:
517 *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
518 break;
520 case WID_GL_HEIGHTMAP_NAME_TEXT:
521 size->width = 0;
522 break;
524 default:
525 return;
527 if (strs != NULL) {
528 while (*strs != INVALID_STRING_ID) {
529 *size = maxdim(*size, GetStringBoundingBox(*strs++));
532 size->width += padding.width;
533 size->height = max(size->height, (uint)(FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM));
536 void DrawWidget (BlitArea *dpi, const Rect &r, int widget) const OVERRIDE
538 switch (widget) {
539 case WID_GL_HEIGHTMAP_NAME_TEXT: {
540 DrawString (dpi, r.left, r.right, r.top, this->name, TC_ORANGE);
541 break;
546 virtual void OnClick(Point pt, int widget, int click_count)
548 switch (widget) {
549 case WID_GL_TEMPERATE:
550 case WID_GL_ARCTIC:
551 case WID_GL_TROPICAL:
552 case WID_GL_TOYLAND:
553 SetNewLandscapeType(widget - WID_GL_TEMPERATE);
554 break;
556 case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
557 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_GL_MAPSIZE_X_PULLDOWN);
558 break;
560 case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
561 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_GL_MAPSIZE_Y_PULLDOWN);
562 break;
564 case WID_GL_TOWN_PULLDOWN: // Number of towns
565 ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
566 break;
568 case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
569 ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
570 break;
572 case WID_GL_RANDOM_BUTTON: // Random seed
573 _settings_newgame.game_creation.generation_seed = InteractiveRandom();
574 this->seed_editbox.Print("%u", _settings_newgame.game_creation.generation_seed);
575 this->SetDirty();
576 break;
578 case WID_GL_GENERATE_BUTTON: { // Generate
579 /* Get rotated map size. */
580 uint map_x;
581 uint map_y;
582 if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
583 map_x = this->y;
584 map_y = this->x;
585 } else {
586 map_x = this->x;
587 map_y = this->y;
589 if (mode == GLWM_HEIGHTMAP &&
590 (map_x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
591 map_x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
592 map_y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
593 map_y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
594 ShowQuery(
595 STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
596 STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
597 this,
598 LandscapeGenerationCallback);
599 } else {
600 StartGeneratingLandscape(mode);
602 break;
605 case WID_GL_MAX_HEIGHTLEVEL_DOWN:
606 case WID_GL_MAX_HEIGHTLEVEL_UP: // Height level buttons
607 /* Don't allow too fast scrolling */
608 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
609 this->HandleButtonClick(widget);
611 _settings_newgame.construction.max_heightlevel = Clamp(_settings_newgame.construction.max_heightlevel + widget - WID_GL_MAX_HEIGHTLEVEL_TEXT, MIN_MAX_HEIGHTLEVEL, MAX_MAX_HEIGHTLEVEL);
612 this->InvalidateData();
614 _left_button_clicked = false;
615 break;
617 case WID_GL_MAX_HEIGHTLEVEL_TEXT: // Height level text
618 this->widget_id = WID_GL_MAX_HEIGHTLEVEL_TEXT;
619 SetDParam(0, _settings_newgame.construction.max_heightlevel);
620 ShowQueryString(STR_JUST_INT, STR_MAPGEN_MAX_HEIGHTLEVEL_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
621 break;
624 case WID_GL_START_DATE_DOWN:
625 case WID_GL_START_DATE_UP: // Year buttons
626 /* Don't allow too fast scrolling */
627 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
628 this->HandleButtonClick(widget);
630 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
631 this->InvalidateData();
633 _left_button_clicked = false;
634 break;
636 case WID_GL_START_DATE_TEXT: // Year text
637 this->widget_id = WID_GL_START_DATE_TEXT;
638 SetDParam(0, _settings_newgame.game_creation.starting_year);
639 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
640 break;
642 case WID_GL_SNOW_LEVEL_DOWN:
643 case WID_GL_SNOW_LEVEL_UP: // Snow line buttons
644 /* Don't allow too fast scrolling */
645 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
646 this->HandleButtonClick(widget);
648 _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);
649 this->InvalidateData();
651 _left_button_clicked = false;
652 break;
654 case WID_GL_SNOW_LEVEL_TEXT: // Snow line text
655 this->widget_id = WID_GL_SNOW_LEVEL_TEXT;
656 SetDParam(0, _settings_newgame.game_creation.snow_line_height);
657 ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
658 break;
660 case WID_GL_TREE_PULLDOWN: // Tree placer
661 ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, WID_GL_TREE_PULLDOWN, 0, 0);
662 break;
664 case WID_GL_LANDSCAPE_PULLDOWN: // Landscape generator
665 ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, WID_GL_LANDSCAPE_PULLDOWN, 0, 0);
666 break;
668 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
669 ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
670 break;
672 case WID_GL_TERRAIN_PULLDOWN: // Terrain type
673 /* For the original map generation only the first four are valid. */
674 ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, WID_GL_TERRAIN_PULLDOWN, 0, _settings_newgame.game_creation.land_generator == LG_ORIGINAL ? ~0xF : 0);
675 break;
677 case WID_GL_WATER_PULLDOWN: { // Water quantity
678 uint32 hidden_mask = 0;
679 /* Disable custom water level when the original map generator is active. */
680 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
681 SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
683 ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, WID_GL_WATER_PULLDOWN, 0, hidden_mask);
684 break;
687 case WID_GL_RIVER_PULLDOWN: // Amount of rivers
688 ShowDropDownMenu(this, _rivers, _settings_newgame.game_creation.amount_of_rivers, WID_GL_RIVER_PULLDOWN, 0, 0);
689 break;
691 case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
692 ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, WID_GL_SMOOTHNESS_PULLDOWN, 0, 0);
693 break;
695 case WID_GL_VARIETY_PULLDOWN: // Map variety
696 ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, WID_GL_VARIETY_PULLDOWN, 0, 0);
697 break;
699 /* Freetype map borders */
700 case WID_GL_WATER_NW:
701 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
702 this->InvalidateData();
703 break;
705 case WID_GL_WATER_NE:
706 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
707 this->InvalidateData();
708 break;
710 case WID_GL_WATER_SE:
711 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
712 this->InvalidateData();
713 break;
715 case WID_GL_WATER_SW:
716 _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
717 this->InvalidateData();
718 break;
720 case WID_GL_BORDERS_RANDOM:
721 _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
722 this->InvalidateData();
723 break;
727 virtual void OnTimeout()
729 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};
730 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
731 if (this->IsWidgetLowered(*widget)) {
732 this->RaiseWidget(*widget);
733 this->SetWidgetDirty(*widget);
738 virtual void OnEditboxChanged(int wid)
740 if (wid == WID_GL_RANDOM_EDITBOX) {
741 /* the seed is unsigned, therefore atoi cannot be used.
742 * As UINT32_MAX is a 'magic' value (use random seed) it
743 * should not be possible to be entered into the input
744 * field; the generate seed button can be used instead. */
745 _settings_newgame.game_creation.generation_seed = minu(strtoul(this->seed_editbox.GetText(), NULL, 10), UINT32_MAX - 1);
749 virtual void OnDropdownSelect(int widget, int index)
751 switch (widget) {
752 case WID_GL_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
753 case WID_GL_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
754 case WID_GL_TREE_PULLDOWN: _settings_newgame.game_creation.tree_placer = index; break;
755 case WID_GL_RIVER_PULLDOWN: _settings_newgame.game_creation.amount_of_rivers = index; break;
756 case WID_GL_SMOOTHNESS_PULLDOWN: _settings_newgame.game_creation.tgen_smoothness = index; break;
757 case WID_GL_VARIETY_PULLDOWN: _settings_newgame.game_creation.variety = index; break;
759 case WID_GL_LANDSCAPE_PULLDOWN: _settings_newgame.game_creation.land_generator = index;
760 /* If original landgenerator is selected and alpinist terrain_type was selected, revert to mountainous. */
761 if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
762 _settings_newgame.difficulty.terrain_type = Clamp(_settings_newgame.difficulty.terrain_type, 0, 3);
764 break;
766 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
768 case WID_GL_TOWN_PULLDOWN:
769 if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
770 this->widget_id = widget;
771 SetDParam(0, _settings_newgame.game_creation.custom_town_number);
772 ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE);
774 _settings_newgame.difficulty.number_towns = index;
775 break;
777 case WID_GL_INDUSTRY_PULLDOWN: _settings_newgame.difficulty.industry_density = index; break;
778 case WID_GL_TERRAIN_PULLDOWN: _settings_newgame.difficulty.terrain_type = index; break;
780 case WID_GL_WATER_PULLDOWN: {
781 if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
782 this->widget_id = widget;
783 SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
784 ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, this, CS_NUMERAL, QSF_NONE);
786 _settings_newgame.difficulty.quantity_sea_lakes = index;
787 break;
790 this->InvalidateData();
793 virtual void OnQueryTextFinished(char *str)
795 /* Was 'cancel' pressed? */
796 if (str == NULL) return;
798 int32 value;
799 if (!StrEmpty(str)) {
800 value = atoi(str);
801 } else {
802 /* An empty string means revert to the default */
803 switch (this->widget_id) {
804 case WID_GL_MAX_HEIGHTLEVEL_TEXT: value = DEF_MAX_HEIGHTLEVEL; break;
805 case WID_GL_START_DATE_TEXT: value = DEF_START_YEAR; break;
806 case WID_GL_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
807 case WID_GL_TOWN_PULLDOWN: value = 1; break;
808 case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
809 default: NOT_REACHED();
813 switch (this->widget_id) {
814 case WID_GL_MAX_HEIGHTLEVEL_TEXT:
815 this->SetWidgetDirty(WID_GL_MAX_HEIGHTLEVEL_TEXT);
816 _settings_newgame.construction.max_heightlevel = Clamp(value, MIN_MAX_HEIGHTLEVEL, MAX_MAX_HEIGHTLEVEL);
817 break;
819 case WID_GL_START_DATE_TEXT:
820 this->SetWidgetDirty(WID_GL_START_DATE_TEXT);
821 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
822 break;
824 case WID_GL_SNOW_LEVEL_TEXT:
825 this->SetWidgetDirty(WID_GL_SNOW_LEVEL_TEXT);
826 _settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
827 break;
829 case WID_GL_TOWN_PULLDOWN:
830 _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
831 break;
833 case WID_GL_WATER_PULLDOWN:
834 _settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
835 break;
838 this->InvalidateData();
842 static const WindowDesc _generate_landscape_desc(
843 WDP_CENTER, 0, 0,
844 WC_GENERATE_LANDSCAPE, WC_NONE,
846 _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
849 static const WindowDesc _heightmap_load_desc(
850 WDP_CENTER, 0, 0,
851 WC_GENERATE_LANDSCAPE, WC_NONE,
853 _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
856 static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
858 uint x = 0;
859 uint y = 0;
861 DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
863 /* Always give a new seed if not editor */
864 if (_game_mode != GM_EDITOR) _settings_newgame.game_creation.generation_seed = InteractiveRandom();
866 if (mode == GLWM_HEIGHTMAP) {
867 /* If the function returns negative, it means there was a problem loading the heightmap */
868 if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name, &x, &y)) return;
871 const WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;
872 GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
874 if (mode == GLWM_HEIGHTMAP) {
875 w->x = x;
876 w->y = y;
877 bstrcpy (w->name, _file_to_saveload.title);
880 SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
883 /** Start with a normal game. */
884 void ShowGenerateLandscape()
886 _ShowGenerateLandscape(GLWM_GENERATE);
889 /** Start with loading a heightmap. */
890 void ShowHeightmapLoad()
892 _ShowGenerateLandscape(GLWM_HEIGHTMAP);
895 /** Start with a scenario editor. */
896 void StartScenarioEditor()
898 StartGeneratingLandscape(GLWM_SCENARIO);
902 * Start a normal game without the GUI.
903 * @param seed The seed of the new game.
905 void StartNewGameWithoutGUI(uint seed)
907 /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
908 _settings_newgame.game_creation.generation_seed = seed;
910 StartGeneratingLandscape(GLWM_GENERATE);
913 struct CreateScenarioWindow : public Window
915 uint widget_id;
917 CreateScenarioWindow (const WindowDesc *desc, WindowNumber window_number)
918 : Window (desc), widget_id (0)
920 this->InitNested(window_number);
921 this->LowerWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
924 virtual void SetStringParameters(int widget) const
926 switch (widget) {
927 case WID_CS_START_DATE_TEXT:
928 SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
929 break;
931 case WID_CS_MAPSIZE_X_PULLDOWN:
932 SetDParam(0, 1 << _settings_newgame.game_creation.map_x);
933 break;
935 case WID_CS_MAPSIZE_Y_PULLDOWN:
936 SetDParam(0, 1 << _settings_newgame.game_creation.map_y);
937 break;
939 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
940 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
941 break;
945 void OnPaint (BlitArea *dpi) OVERRIDE
947 this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
948 this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
949 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
950 this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP, _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
952 this->SetWidgetLoweredState(WID_CS_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
953 this->SetWidgetLoweredState(WID_CS_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);
954 this->SetWidgetLoweredState(WID_CS_TROPICAL, _settings_newgame.game_creation.landscape == LT_TROPIC);
955 this->SetWidgetLoweredState(WID_CS_TOYLAND, _settings_newgame.game_creation.landscape == LT_TOYLAND);
957 this->DrawWidgets (dpi);
960 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
962 StringID str = STR_JUST_INT;
963 switch (widget) {
964 case WID_CS_START_DATE_TEXT:
965 SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
966 str = STR_BLACK_DATE_LONG;
967 break;
969 case WID_CS_MAPSIZE_X_PULLDOWN:
970 case WID_CS_MAPSIZE_Y_PULLDOWN:
971 SetDParamMaxValue(0, MAX_MAP_SIZE);
972 break;
974 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
975 SetDParamMaxValue(0, MAX_TILE_HEIGHT);
976 break;
978 default:
979 return;
981 *size = maxdim(*size, GetStringBoundingBox(str));
982 size->width += padding.width;
983 size->height += padding.height;
986 virtual void OnClick(Point pt, int widget, int click_count)
988 switch (widget) {
989 case WID_CS_TEMPERATE:
990 case WID_CS_ARCTIC:
991 case WID_CS_TROPICAL:
992 case WID_CS_TOYLAND:
993 this->RaiseWidget(_settings_newgame.game_creation.landscape + WID_CS_TEMPERATE);
994 SetNewLandscapeType(widget - WID_CS_TEMPERATE);
995 break;
997 case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
998 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, WID_CS_MAPSIZE_X_PULLDOWN);
999 break;
1001 case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
1002 ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, WID_CS_MAPSIZE_Y_PULLDOWN);
1003 break;
1005 case WID_CS_EMPTY_WORLD: // Empty world / flat world
1006 StartGeneratingLandscape(GLWM_SCENARIO);
1007 break;
1009 case WID_CS_RANDOM_WORLD: // Generate
1010 ShowGenerateLandscape();
1011 break;
1013 case WID_CS_START_DATE_DOWN:
1014 case WID_CS_START_DATE_UP: // Year buttons
1015 /* Don't allow too fast scrolling */
1016 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1017 this->HandleButtonClick(widget);
1018 this->SetDirty();
1020 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
1022 _left_button_clicked = false;
1023 break;
1025 case WID_CS_START_DATE_TEXT: // Year text
1026 this->widget_id = WID_CS_START_DATE_TEXT;
1027 SetDParam(0, _settings_newgame.game_creation.starting_year);
1028 ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE);
1029 break;
1031 case WID_CS_FLAT_LAND_HEIGHT_DOWN:
1032 case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
1033 /* Don't allow too fast scrolling */
1034 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1035 this->HandleButtonClick(widget);
1036 this->SetDirty();
1038 _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);
1040 _left_button_clicked = false;
1041 break;
1043 case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
1044 this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1045 SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
1046 ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
1047 break;
1051 virtual void OnTimeout()
1053 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};
1054 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
1055 if (this->IsWidgetLowered(*widget)) {
1056 this->RaiseWidget(*widget);
1057 this->SetWidgetDirty(*widget);
1062 virtual void OnDropdownSelect(int widget, int index)
1064 switch (widget) {
1065 case WID_CS_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
1066 case WID_CS_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
1068 this->SetDirty();
1071 virtual void OnQueryTextFinished(char *str)
1073 if (!StrEmpty(str)) {
1074 int32 value = atoi(str);
1076 switch (this->widget_id) {
1077 case WID_CS_START_DATE_TEXT:
1078 this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
1079 _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
1080 break;
1082 case WID_CS_FLAT_LAND_HEIGHT_TEXT:
1083 this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
1084 _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, _settings_game.construction.max_heightlevel);
1085 break;
1088 this->SetDirty();
1093 static const NWidgetPart _nested_create_scenario_widgets[] = {
1094 NWidget(NWID_HORIZONTAL),
1095 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1096 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
1097 EndContainer(),
1098 NWidget(WWT_PANEL, COLOUR_BROWN),
1099 NWidget(NWID_SPACER), SetMinimalSize(0, 10),
1100 /* Landscape style selection. */
1101 NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
1102 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TEMPERATE), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
1103 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_ARCTIC), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1104 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TROPICAL), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1105 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TOYLAND), SetMinimalSize(76, 54), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1106 EndContainer(),
1107 NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
1108 /* Green generation type buttons: 'Flat land' and 'Random land'. */
1109 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1110 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1111 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1112 EndContainer(),
1113 /* Labels + setting drop-downs */
1114 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1115 /* Map size. */
1116 NWidget(NWID_HORIZONTAL),
1117 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
1118 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1119 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
1120 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
1121 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
1122 EndContainer(),
1123 /* Date. */
1124 NWidget(NWID_HORIZONTAL),
1125 NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
1126 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1127 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),
1128 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
1129 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),
1130 EndContainer(),
1131 /* Flat map height. */
1132 NWidget(NWID_HORIZONTAL),
1133 NWidget(WWT_TEXT, COLOUR_ORANGE),
1134 SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
1135 NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1136 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),
1137 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
1138 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),
1139 EndContainer(),
1140 EndContainer(),
1141 EndContainer(),
1142 EndContainer(),
1145 static const WindowDesc _create_scenario_desc(
1146 WDP_CENTER, 0, 0,
1147 WC_GENERATE_LANDSCAPE, WC_NONE,
1149 _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
1152 /** Show the window to create a scenario. */
1153 void ShowCreateScenario()
1155 DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
1156 new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
1159 static const NWidgetPart _nested_generate_progress_widgets[] = {
1160 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1161 NWidget(WWT_PANEL, COLOUR_GREY),
1162 NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
1163 NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
1164 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
1165 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
1166 NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
1167 EndContainer(),
1168 EndContainer(),
1169 EndContainer(),
1173 static const WindowDesc _generate_progress_desc(
1174 WDP_CENTER, 0, 0,
1175 WC_MODAL_PROGRESS, WC_NONE,
1177 _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
1180 struct GenWorldStatus {
1181 uint percent;
1182 StringID cls;
1183 uint current;
1184 uint total;
1185 int timer;
1188 static GenWorldStatus _gws;
1190 static const StringID _generation_class_table[] = {
1191 STR_GENERATION_WORLD_GENERATION,
1192 STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
1193 STR_GENERATION_RIVER_GENERATION,
1194 STR_GENERATION_CLEARING_TILES,
1195 STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
1196 STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
1197 STR_GENERATION_OBJECT_GENERATION,
1198 STR_GENERATION_TREE_GENERATION,
1199 STR_GENERATION_SETTINGUP_GAME,
1200 STR_GENERATION_PREPARING_TILELOOP,
1201 STR_GENERATION_PREPARING_SCRIPT,
1202 STR_GENERATION_PREPARING_GAME
1204 assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
1207 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
1209 if (confirmed) {
1210 AbortGeneratingWorld();
1211 } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1212 SetMouseCursor (SPR_CURSOR_ZZZ);
1216 struct GenerateProgressWindow : public Window {
1218 GenerateProgressWindow() : Window(&_generate_progress_desc)
1220 this->InitNested();
1223 virtual void OnClick(Point pt, int widget, int click_count)
1225 switch (widget) {
1226 case WID_GP_ABORT:
1227 SetMouseCursorBusy(false);
1228 ShowQuery(
1229 STR_GENERATION_ABORT_CAPTION,
1230 STR_GENERATION_ABORT_MESSAGE,
1231 this,
1232 AbortGeneratingWorldCallback
1234 break;
1238 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1240 switch (widget) {
1241 case WID_GP_PROGRESS_BAR: {
1242 SetDParamMaxValue(0, 100);
1243 *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
1244 /* We need some spacing for the 'border' */
1245 size->height += 8;
1246 size->width += 8;
1247 break;
1250 case WID_GP_PROGRESS_TEXT:
1251 for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
1252 size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
1254 size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
1255 break;
1259 void DrawWidget (BlitArea *dpi, const Rect &r, int widget) const OVERRIDE
1261 switch (widget) {
1262 case WID_GP_PROGRESS_BAR:
1263 /* Draw the % complete with a bar and a text */
1264 DrawFrameRect (dpi, r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
1265 DrawFrameRect (dpi, 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);
1266 SetDParam(0, _gws.percent);
1267 DrawString (dpi, r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
1268 break;
1270 case WID_GP_PROGRESS_TEXT:
1271 /* Tell which class we are generating */
1272 DrawString (dpi, r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
1274 /* And say where we are in that class */
1275 SetDParam(0, _gws.current);
1276 SetDParam(1, _gws.total);
1277 DrawString (dpi, r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
1283 * Initializes the progress counters to the starting point.
1285 void PrepareGenerateWorldProgress()
1287 _gws.cls = STR_GENERATION_WORLD_GENERATION;
1288 _gws.current = 0;
1289 _gws.total = 0;
1290 _gws.percent = 0;
1291 _gws.timer = 0; // Forces to paint the progress window immediately
1295 * Show the window where a user can follow the process of the map generation.
1297 void ShowGenerateWorldProgress()
1299 if (BringWindowToFrontById(WC_MODAL_PROGRESS, 0)) return;
1300 new GenerateProgressWindow();
1303 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1305 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
1306 assert_compile(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1307 assert(cls < GWP_CLASS_COUNT);
1309 /* Do not run this function if we aren't in a thread */
1310 if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
1312 if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
1314 if (total == 0) {
1315 assert(_gws.cls == _generation_class_table[cls]);
1316 _gws.current += progress;
1317 assert(_gws.current <= _gws.total);
1318 } else {
1319 _gws.cls = _generation_class_table[cls];
1320 _gws.current = progress;
1321 _gws.total = total;
1322 _gws.percent = percent_table[cls];
1325 /* Don't update the screen too often. So update it once in every once in a while... */
1326 if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < MODAL_PROGRESS_REDRAW_TIMEOUT) return;
1328 /* Percentage is about the number of completed tasks, so 'current - 1' */
1329 _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
1331 if (_network_dedicated) {
1332 static uint last_percent = 0;
1334 /* Never display 0% */
1335 if (_gws.percent == 0) return;
1336 /* Reset if percent is lower than the last recorded */
1337 if (_gws.percent < last_percent) last_percent = 0;
1338 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1339 if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
1340 /* Never show steps smaller than 2%, even if it is a mod 5% */
1341 if (_gws.percent <= last_percent + 2) return;
1343 DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
1344 last_percent = _gws.percent;
1346 /* Don't continue as dedicated never has a thread running */
1347 return;
1350 SetWindowDirty(WC_MODAL_PROGRESS, 0);
1351 MarkWholeScreenDirty();
1353 /* Release the rights to the map generator, and acquire the rights to the
1354 * paint thread. The 'other' thread already has the paint thread rights so
1355 * this ensures us that we are waiting until the paint thread is done
1356 * before we reacquire the mapgen rights */
1357 _modal_progress_work_mutex->EndCritical();
1358 _modal_progress_paint_mutex->BeginCritical();
1359 _modal_progress_work_mutex->BeginCritical();
1360 _modal_progress_paint_mutex->EndCritical();
1362 _gws.timer = _realtime_tick;
1366 * Set the total of a stage of the world generation.
1367 * @param cls the current class we are in.
1368 * @param total Set the total expected items for this class.
1370 * Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
1371 * Also, progress works if total is zero, total works if progress is zero.
1373 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
1375 if (total == 0) return;
1377 _SetGeneratingWorldProgress(cls, 0, total);
1381 * Increases the current stage of the world generation with one.
1382 * @param cls the current class we are in.
1384 * Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
1385 * Also, progress works if total is zero, total works if progress is zero.
1387 void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
1389 /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1390 _SetGeneratingWorldProgress(cls, 1, 0);