OpenTTD Source: src/terraform_gui.cpp Source File

OpenTTD Source 13.2.1

terraform_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "core/backup_type.hpp"
12 #include "clear_map.h"
13 #include "company_func.h"
14 #include "company_base.h"
15 #include "gui.h"
16 #include "window_gui.h"
17 #include "window_func.h"
18 #include "viewport_func.h"
19 #include "command_func.h"
20 #include "signs_func.h"
21 #include "sound_func.h"
22 #include "base_station_base.h"
23 #include "textbuf_gui.h"
24 #include "genworld.h"
25 #include "tree_map.h"
26 #include "landscape_type.h"
27 #include "tilehighlight_func.h"
28 #include "strings_func.h"
29 #include "newgrf_object.h"
30 #include "object.h"
31 #include "hotkeys.h"
32 #include "engine_base.h"
33 #include "terraform_gui.h"
34 #include "terraform_cmd.h"
35 #include "zoom_func.h"
36 #include "rail_cmd.h"
37 #include "landscape_cmd.h"
38 #include "terraform_cmd.h"
39 #include "object_cmd.h"
40
41 #include "widgets/terraform_widget.h"
42
43 #include "table/strings.h"
44
45 #include "safeguards.h"
46
47 void CcTerraform(Commands cmd, const CommandCost &result, Money, TileIndex tile)
48 {
49 if (result.Succeeded()) {
50 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
51 } else {
52 SetRedErrorSquare(tile);
53 }
54 }
55
56
58 static void GenerateDesertArea(TileIndex end, TileIndex start)
59 {
60 if (_game_mode != GM_EDITOR) return;
61
62 Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
63
64 TileArea ta(start, end);
65 for (TileIndex tile : ta) {
66 SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
67 Command<CMD_LANDSCAPE_CLEAR>::Post(tile);
68 MarkTileDirtyByTile(tile);
69 }
70 old_generating_world.Restore();
71 InvalidateWindowClassesData(WC_TOWN_VIEW, 0);
72 }
73
75 static void GenerateRockyArea(TileIndex end, TileIndex start)
76 {
77 if (_game_mode != GM_EDITOR) return;
78
79 bool success = false;
80 TileArea ta(start, end);
81
82 for (TileIndex tile : ta) {
83 switch (GetTileType(tile)) {
84 case MP_TREES:
85 if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue;
86 FALLTHROUGH;
87
88 case MP_CLEAR:
89 MakeClear(tile, CLEAR_ROCKS, 3);
90 break;
91
92 default:
93 continue;
94 }
95 MarkTileDirtyByTile(tile);
96 success = true;
97 }
98
99 if (success && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, end);
100 }
101
111 bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
112 {
113 if (!_settings_game.construction.freeform_edges) {
114 /* When end_tile is MP_VOID, the error tile will not be visible to the
115 * user. This happens when terraforming at the southern border. */
116 if (TileX(end_tile) == MapMaxX()) end_tile += TileDiffXY(-1, 0);
117 if (TileY(end_tile) == MapMaxY()) end_tile += TileDiffXY(0, -1);
118 }
119
120 switch (proc) {
121 case DDSP_DEMOLISH_AREA:
122 Command<CMD_CLEAR_AREA>::Post(STR_ERROR_CAN_T_CLEAR_THIS_AREA, CcPlaySound_EXPLOSION, end_tile, start_tile, _ctrl_pressed);
123 break;
124 case DDSP_RAISE_AND_LEVEL_AREA:
125 Command<CMD_LEVEL_LAND>::Post(STR_ERROR_CAN_T_RAISE_LAND_HERE, CcTerraform, end_tile, start_tile, _ctrl_pressed, LM_RAISE);
126 break;
127 case DDSP_LOWER_AND_LEVEL_AREA:
128 Command<CMD_LEVEL_LAND>::Post(STR_ERROR_CAN_T_LOWER_LAND_HERE, CcTerraform, end_tile, start_tile, _ctrl_pressed, LM_LOWER);
129 break;
130 case DDSP_LEVEL_AREA:
131 Command<CMD_LEVEL_LAND>::Post(STR_ERROR_CAN_T_LEVEL_LAND_HERE, CcTerraform, end_tile, start_tile, _ctrl_pressed, LM_LEVEL);
132 break;
133 case DDSP_CREATE_ROCKS:
134 GenerateRockyArea(end_tile, start_tile);
135 break;
136 case DDSP_CREATE_DESERT:
137 GenerateDesertArea(end_tile, start_tile);
138 break;
139 default:
140 return false;
141 }
142
143 return true;
144 }
145
150 void PlaceProc_DemolishArea(TileIndex tile)
151 {
152 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
153 }
154
156 struct TerraformToolbarWindow : Window {
157 int last_user_action;
158
159 TerraformToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
160 {
161 /* This is needed as we like to have the tree available on OnInit. */
162 this->CreateNestedTree();
163 this->FinishInitNested(window_number);
164 this->last_user_action = WIDGET_LIST_END;
165 }
166
167 ~TerraformToolbarWindow()
168 {
169 }
170
171 void OnInit() override
172 {
173 /* Don't show the place object button when there are no objects to place. */
174 NWidgetStacked *show_object = this->GetWidget<NWidgetStacked>(WID_TT_SHOW_PLACE_OBJECT);
175 show_object->SetDisplayedPlane(ObjectClass::GetUIClassCount() != 0 ? 0 : SZSP_NONE);
176 }
177
178 void OnClick(Point pt, int widget, int click_count) override
179 {
180 if (widget < WID_TT_BUTTONS_START) return;
181
182 switch (widget) {
183 case WID_TT_LOWER_LAND: // Lower land button
184 HandlePlacePushButton(this, WID_TT_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT | HT_DIAGONAL);
185 this->last_user_action = widget;
186 break;
187
188 case WID_TT_RAISE_LAND: // Raise land button
189 HandlePlacePushButton(this, WID_TT_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT | HT_DIAGONAL);
190 this->last_user_action = widget;
191 break;
192
193 case WID_TT_LEVEL_LAND: // Level land button
194 HandlePlacePushButton(this, WID_TT_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
195 this->last_user_action = widget;
196 break;
197
198 case WID_TT_DEMOLISH: // Demolish aka dynamite button
199 HandlePlacePushButton(this, WID_TT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
200 this->last_user_action = widget;
201 break;
202
203 case WID_TT_BUY_LAND: // Buy land button
204 HandlePlacePushButton(this, WID_TT_BUY_LAND, SPR_CURSOR_BUY_LAND, HT_RECT | HT_DIAGONAL);
205 this->last_user_action = widget;
206 break;
207
208 case WID_TT_PLANT_TREES: // Plant trees button
209 ShowBuildTreesToolbar();
210 break;
211
212 case WID_TT_PLACE_SIGN: // Place sign button
213 HandlePlacePushButton(this, WID_TT_PLACE_SIGN, SPR_CURSOR_SIGN, HT_RECT);
214 this->last_user_action = widget;
215 break;
216
217 case WID_TT_PLACE_OBJECT: // Place object button
218 ShowBuildObjectPicker();
219 break;
220
221 default: NOT_REACHED();
222 }
223 }
224
225 void OnPlaceObject(Point pt, TileIndex tile) override
226 {
227 switch (this->last_user_action) {
228 case WID_TT_LOWER_LAND: // Lower land button
229 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LOWER_AND_LEVEL_AREA);
230 break;
231
232 case WID_TT_RAISE_LAND: // Raise land button
233 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_RAISE_AND_LEVEL_AREA);
234 break;
235
236 case WID_TT_LEVEL_LAND: // Level land button
237 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
238 break;
239
240 case WID_TT_DEMOLISH: // Demolish aka dynamite button
241 PlaceProc_DemolishArea(tile);
242 break;
243
244 case WID_TT_BUY_LAND: // Buy land button
245 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_BUILD_OBJECT);
246 break;
247
248 case WID_TT_PLACE_SIGN: // Place sign button
249 PlaceProc_Sign(tile);
250 break;
251
252 default: NOT_REACHED();
253 }
254 }
255
256 void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
257 {
258 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
259 }
260
261 Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
262 {
263 Point pt = GetToolbarAlignedWindowPosition(sm_width);
264 pt.y += sm_height;
265 return pt;
266 }
267
268 void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
269 {
270 if (pt.x != -1) {
271 switch (select_proc) {
272 default: NOT_REACHED();
273 case DDSP_DEMOLISH_AREA:
274 case DDSP_RAISE_AND_LEVEL_AREA:
275 case DDSP_LOWER_AND_LEVEL_AREA:
276 case DDSP_LEVEL_AREA:
277 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
278 break;
279 case DDSP_BUILD_OBJECT:
280 if (!_settings_game.construction.freeform_edges) {
281 /* When end_tile is MP_VOID, the error tile will not be visible to the
282 * user. This happens when terraforming at the southern border. */
283 if (TileX(end_tile) == MapMaxX()) end_tile += TileDiffXY(-1, 0);
284 if (TileY(end_tile) == MapMaxY()) end_tile += TileDiffXY(0, -1);
285 }
286 Command<CMD_BUILD_OBJECT_AREA>::Post(STR_ERROR_CAN_T_PURCHASE_THIS_LAND, CcPlaySound_CONSTRUCTION_RAIL,
287 end_tile, start_tile, OBJECT_OWNED_LAND, 0, (_ctrl_pressed ? true : false));
288 break;
289 }
290 }
291 }
292
293 void OnPlaceObjectAbort() override
294 {
295 this->RaiseButtons();
296 }
297
298 static HotkeyList hotkeys;
299 };
300
306 static EventState TerraformToolbarGlobalHotkeys(int hotkey)
307 {
308 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
309 Window *w = ShowTerraformToolbar(nullptr);
310 if (w == nullptr) return ES_NOT_HANDLED;
311 return w->OnHotkey(hotkey);
312 }
313
314 static Hotkey terraform_hotkeys[] = {
315 Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_TT_LOWER_LAND),
316 Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_TT_RAISE_LAND),
317 Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_LEVEL_LAND),
318 Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_TT_DEMOLISH),
319 Hotkey('U', "buyland", WID_TT_BUY_LAND),
320 Hotkey('I', "trees", WID_TT_PLANT_TREES),
321 Hotkey('O', "placesign", WID_TT_PLACE_SIGN),
322 Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT),
323 HOTKEY_LIST_END
324 };
325 HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys, TerraformToolbarGlobalHotkeys);
326
327 static const NWidgetPart _nested_terraform_widgets[] = {
328 NWidget(NWID_HORIZONTAL),
329 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
330 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_LANDSCAPING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
331 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
332 EndContainer(),
333 NWidget(NWID_HORIZONTAL),
334 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LOWER_LAND), SetMinimalSize(22, 22),
335 SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
336 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_RAISE_LAND), SetMinimalSize(22, 22),
337 SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
338 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LEVEL_LAND), SetMinimalSize(22, 22),
339 SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
340
341 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), EndContainer(),
342
343 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_DEMOLISH), SetMinimalSize(22, 22),
344 SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
345 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BUY_LAND), SetMinimalSize(22, 22),
346 SetFill(0, 1), SetDataTip(SPR_IMG_BUY_LAND, STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND),
347 NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLANT_TREES), SetMinimalSize(22, 22),
348 SetFill(0, 1), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
349 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_SIGN), SetMinimalSize(22, 22),
350 SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
351 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TT_SHOW_PLACE_OBJECT),
352 NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_OBJECT), SetMinimalSize(22, 22),
353 SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
354 EndContainer(),
355 EndContainer(),
356 };
357
358 static WindowDesc _terraform_desc(
359 WDP_MANUAL, "toolbar_landscape", 0, 0,
360 WC_SCEN_LAND_GEN, WC_NONE,
361 WDF_CONSTRUCTION,
362 _nested_terraform_widgets, lengthof(_nested_terraform_widgets),
363 &TerraformToolbarWindow::hotkeys
364 );
365
371 Window *ShowTerraformToolbar(Window *link)
372 {
373 if (!Company::IsValidID(_local_company)) return nullptr;
374
375 Window *w;
376 if (link == nullptr) {
377 w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
378 return w;
379 }
380
381 /* Delete the terraform toolbar to place it again. */
382 CloseWindowById(WC_SCEN_LAND_GEN, 0, true);
383 w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
384 /* Align the terraform toolbar under the main toolbar. */
385 w->top -= w->height;
386 w->SetDirty();
387 /* Put the linked toolbar to the left / right of it. */
388 link->left = w->left + (_current_text_dir == TD_RTL ? w->width : -link->width);
389 link->top = w->top;
390 link->SetDirty();
391
392 return w;
393 }
394
395 static byte _terraform_size = 1;
396
406 static void CommonRaiseLowerBigLand(TileIndex tile, bool mode)
407 {
408 if (_terraform_size == 1) {
409 StringID msg =
410 mode ? STR_ERROR_CAN_T_RAISE_LAND_HERE : STR_ERROR_CAN_T_LOWER_LAND_HERE;
411
412 Command<CMD_TERRAFORM_LAND>::Post(msg, CcTerraform, tile, SLOPE_N, mode);
413 } else {
414 assert(_terraform_size != 0);
415 TileArea ta(tile, _terraform_size, _terraform_size);
416 ta.ClampToMap();
417
418 if (ta.w == 0 || ta.h == 0) return;
419
420 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
421
422 uint h;
423 if (mode != 0) {
424 /* Raise land */
425 h = MAX_TILE_HEIGHT;
426 for (TileIndex tile2 : ta) {
427 h = std::min(h, TileHeight(tile2));
428 }
429 } else {
430 /* Lower land */
431 h = 0;
432 for (TileIndex tile2 : ta) {
433 h = std::max(h, TileHeight(tile2));
434 }
435 }
436
437 for (TileIndex tile2 : ta) {
438 if (TileHeight(tile2) == h) {
439 Command<CMD_TERRAFORM_LAND>::Post(tile2, SLOPE_N, mode);
440 }
441 }
442 }
443 }
444
445 static const int8 _multi_terraform_coords[][2] = {
446 { 0, -2},
447 { 4, 0}, { -4, 0}, { 0, 2},
448 { -8, 2}, { -4, 4}, { 0, 6}, { 4, 4}, { 8, 2},
449 {-12, 0}, { -8, -2}, { -4, -4}, { 0, -6}, { 4, -4}, { 8, -2}, { 12, 0},
450 {-16, 2}, {-12, 4}, { -8, 6}, { -4, 8}, { 0, 10}, { 4, 8}, { 8, 6}, { 12, 4}, { 16, 2},
451 {-20, 0}, {-16, -2}, {-12, -4}, { -8, -6}, { -4, -8}, { 0,-10}, { 4, -8}, { 8, -6}, { 12, -4}, { 16, -2}, { 20, 0},
452 {-24, 2}, {-20, 4}, {-16, 6}, {-12, 8}, { -8, 10}, { -4, 12}, { 0, 14}, { 4, 12}, { 8, 10}, { 12, 8}, { 16, 6}, { 20, 4}, { 24, 2},
453 {-28, 0}, {-24, -2}, {-20, -4}, {-16, -6}, {-12, -8}, { -8,-10}, { -4,-12}, { 0,-14}, { 4,-12}, { 8,-10}, { 12, -8}, { 16, -6}, { 20, -4}, { 24, -2}, { 28, 0},
454 };
455
456 static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
457 NWidget(NWID_HORIZONTAL),
458 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
459 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TERRAFORM_TOOLBAR_LAND_GENERATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
460 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
461 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
462 EndContainer(),
463 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
464 NWidget(NWID_HORIZONTAL), SetPadding(2, 2, 7, 2),
465 NWidget(NWID_SPACER), SetFill(1, 0),
466 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_DEMOLISH), SetMinimalSize(22, 22),
467 SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
468 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_LOWER_LAND), SetMinimalSize(22, 22),
469 SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
470 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_RAISE_LAND), SetMinimalSize(22, 22),
471 SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
472 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_LEVEL_LAND), SetMinimalSize(22, 22),
473 SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
474 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_ROCKS), SetMinimalSize(22, 22),
475 SetFill(0, 1), SetDataTip(SPR_IMG_ROCKS, STR_TERRAFORM_TOOLTIP_PLACE_ROCKY_AREAS_ON_LANDSCAPE),
476 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_ETT_SHOW_PLACE_DESERT),
477 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_DESERT), SetMinimalSize(22, 22),
478 SetFill(0, 1), SetDataTip(SPR_IMG_DESERT, STR_TERRAFORM_TOOLTIP_DEFINE_DESERT_AREA),
479 EndContainer(),
480 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_ETT_PLACE_OBJECT), SetMinimalSize(23, 22),
481 SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
482 NWidget(NWID_SPACER), SetFill(1, 0),
483 EndContainer(),
484 NWidget(NWID_HORIZONTAL),
485 NWidget(NWID_SPACER), SetFill(1, 0),
486 NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_ETT_DOTS), SetMinimalSize(59, 31), SetDataTip(STR_EMPTY, STR_NULL),
487 NWidget(NWID_SPACER), SetFill(1, 0),
488 NWidget(NWID_VERTICAL),
489 NWidget(NWID_SPACER), SetFill(0, 1),
490 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_INCREASE_SIZE), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_UP, STR_TERRAFORM_TOOLTIP_INCREASE_SIZE_OF_LAND_AREA),
491 NWidget(NWID_SPACER), SetMinimalSize(0, 1),
492 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_DECREASE_SIZE), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_DOWN, STR_TERRAFORM_TOOLTIP_DECREASE_SIZE_OF_LAND_AREA),
493 NWidget(NWID_SPACER), SetFill(0, 1),
494 EndContainer(),
495 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
496 EndContainer(),
497 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
498 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_NEW_SCENARIO), SetMinimalSize(160, 12),
499 SetFill(1, 0), SetDataTip(STR_TERRAFORM_SE_NEW_WORLD, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetPadding(0, 2, 0, 2),
500 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_RESET_LANDSCAPE), SetMinimalSize(160, 12),
501 SetFill(1, 0), SetDataTip(STR_TERRAFORM_RESET_LANDSCAPE, STR_TERRAFORM_RESET_LANDSCAPE_TOOLTIP), SetPadding(1, 2, 2, 2),
502 EndContainer(),
503 };
504
510 static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
511 {
512 if (confirmed) {
513 /* Set generating_world to true to get instant-green grass after removing
514 * company property. */
515 Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
516
517 /* Delete all companies */
518 for (Company *c : Company::Iterate()) {
519 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
520 delete c;
521 }
522
523 old_generating_world.Restore();
524
525 /* Delete all station signs */
526 for (BaseStation *st : BaseStation::Iterate()) {
527 /* There can be buoys, remove them */
528 if (IsBuoyTile(st->xy)) Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, st->xy);
529 if (!st->IsInUse()) delete st;
530 }
531
532 /* Now that all vehicles are gone, we can reset the engine pool. Maybe it reduces some NewGRF changing-mess */
533 EngineOverrideManager::ResetToCurrentNewGRFConfig();
534
535 MarkWholeScreenDirty();
536 }
537 }
538
540 struct ScenarioEditorLandscapeGenerationWindow : Window {
541 int last_user_action;
542
543 ScenarioEditorLandscapeGenerationWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
544 {
545 this->CreateNestedTree();
546 NWidgetStacked *show_desert = this->GetWidget<NWidgetStacked>(WID_ETT_SHOW_PLACE_DESERT);
547 show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE);
548 this->FinishInitNested(window_number);
549 this->last_user_action = WIDGET_LIST_END;
550 }
551
552 void OnPaint() override
553 {
554 this->DrawWidgets();
555
556 if (this->IsWidgetLowered(WID_ETT_LOWER_LAND) || this->IsWidgetLowered(WID_ETT_RAISE_LAND)) { // change area-size if raise/lower corner is selected
557 SetTileSelectSize(_terraform_size, _terraform_size);
558 }
559 }
560
561 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
562 {
563 if (widget != WID_ETT_DOTS) return;
564
565 size->width = std::max<uint>(size->width, ScaleGUITrad(59));
566 size->height = std::max<uint>(size->height, ScaleGUITrad(31));
567 }
568
569 void DrawWidget(const Rect &r, int widget) const override
570 {
571 if (widget != WID_ETT_DOTS) return;
572
573 int center_x = RoundDivSU(r.left + r.right, 2);
574 int center_y = RoundDivSU(r.top + r.bottom, 2);
575
576 int n = _terraform_size * _terraform_size;
577 const int8 *coords = &_multi_terraform_coords[0][0];
578
579 assert(n != 0);
580 do {
581 DrawSprite(SPR_WHITE_POINT, PAL_NONE, center_x + ScaleGUITrad(coords[0]), center_y + ScaleGUITrad(coords[1]));
582 coords += 2;
583 } while (--n);
584 }
585
586 void OnClick(Point pt, int widget, int click_count) override
587 {
588 if (widget < WID_ETT_BUTTONS_START) return;
589
590 switch (widget) {
591 case WID_ETT_DEMOLISH: // Demolish aka dynamite button
592 HandlePlacePushButton(this, WID_ETT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
593 this->last_user_action = widget;
594 break;
595
596 case WID_ETT_LOWER_LAND: // Lower land button
597 HandlePlacePushButton(this, WID_ETT_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT);
598 this->last_user_action = widget;
599 break;
600
601 case WID_ETT_RAISE_LAND: // Raise land button
602 HandlePlacePushButton(this, WID_ETT_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT);
603 this->last_user_action = widget;
604 break;
605
606 case WID_ETT_LEVEL_LAND: // Level land button
607 HandlePlacePushButton(this, WID_ETT_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
608 this->last_user_action = widget;
609 break;
610
611 case WID_ETT_PLACE_ROCKS: // Place rocks button
612 HandlePlacePushButton(this, WID_ETT_PLACE_ROCKS, SPR_CURSOR_ROCKY_AREA, HT_RECT);
613 this->last_user_action = widget;
614 break;
615
616 case WID_ETT_PLACE_DESERT: // Place desert button (in tropical climate)
617 HandlePlacePushButton(this, WID_ETT_PLACE_DESERT, SPR_CURSOR_DESERT, HT_RECT);
618 this->last_user_action = widget;
619 break;
620
621 case WID_ETT_PLACE_OBJECT: // Place transmitter button
622 ShowBuildObjectPicker();
623 break;
624
625 case WID_ETT_INCREASE_SIZE:
626 case WID_ETT_DECREASE_SIZE: { // Increase/Decrease terraform size
627 int size = (widget == WID_ETT_INCREASE_SIZE) ? 1 : -1;
628 this->HandleButtonClick(widget);
629 size += _terraform_size;
630
631 if (!IsInsideMM(size, 1, 8 + 1)) return;
632 _terraform_size = size;
633
634 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
635 this->SetDirty();
636 break;
637 }
638
639 case WID_ETT_NEW_SCENARIO: // gen random land
640 this->HandleButtonClick(widget);
641 ShowCreateScenario();
642 break;
643
644 case WID_ETT_RESET_LANDSCAPE: // Reset landscape
645 ShowQuery(STR_QUERY_RESET_LANDSCAPE_CAPTION, STR_RESET_LANDSCAPE_CONFIRMATION_TEXT, nullptr, ResetLandscapeConfirmationCallback);
646 break;
647
648 default: NOT_REACHED();
649 }
650 }
651
652 void OnTimeout() override
653 {
654 for (uint i = WID_ETT_START; i < this->nested_array_size; i++) {
655 if (i == WID_ETT_BUTTONS_START) i = WID_ETT_BUTTONS_END; // skip the buttons
656 if (this->IsWidgetLowered(i)) {
657 this->RaiseWidget(i);
658 this->SetWidgetDirty(i);
659 }
660 }
661 }
662
663 void OnPlaceObject(Point pt, TileIndex tile) override
664 {
665 switch (this->last_user_action) {
666 case WID_ETT_DEMOLISH: // Demolish aka dynamite button
667 PlaceProc_DemolishArea(tile);
668 break;
669
670 case WID_ETT_LOWER_LAND: // Lower land button
671 CommonRaiseLowerBigLand(tile, false);
672 break;
673
674 case WID_ETT_RAISE_LAND: // Raise land button
675 CommonRaiseLowerBigLand(tile, true);
676 break;
677
678 case WID_ETT_LEVEL_LAND: // Level land button
679 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
680 break;
681
682 case WID_ETT_PLACE_ROCKS: // Place rocks button
683 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_ROCKS);
684 break;
685
686 case WID_ETT_PLACE_DESERT: // Place desert button (in tropical climate)
687 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_DESERT);
688 break;
689
690 default: NOT_REACHED();
691 }
692 }
693
694 void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
695 {
696 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
697 }
698
699 void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
700 {
701 if (pt.x != -1) {
702 switch (select_proc) {
703 default: NOT_REACHED();
704 case DDSP_CREATE_ROCKS:
705 case DDSP_CREATE_DESERT:
706 case DDSP_RAISE_AND_LEVEL_AREA:
707 case DDSP_LOWER_AND_LEVEL_AREA:
708 case DDSP_LEVEL_AREA:
709 case DDSP_DEMOLISH_AREA:
710 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
711 break;
712 }
713 }
714 }
715
716 void OnPlaceObjectAbort() override
717 {
718 this->RaiseButtons();
719 this->SetDirty();
720 }
721
722 static HotkeyList hotkeys;
723 };
724
730 static EventState TerraformToolbarEditorGlobalHotkeys(int hotkey)
731 {
732 if (_game_mode != GM_EDITOR) return ES_NOT_HANDLED;
733 Window *w = ShowEditorTerraformToolbar();
734 if (w == nullptr) return ES_NOT_HANDLED;
735 return w->OnHotkey(hotkey);
736 }
737
738 static Hotkey terraform_editor_hotkeys[] = {
739 Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_ETT_DEMOLISH),
740 Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_ETT_LOWER_LAND),
741 Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_ETT_RAISE_LAND),
742 Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_ETT_LEVEL_LAND),
743 Hotkey('R', "rocky", WID_ETT_PLACE_ROCKS),
744 Hotkey('T', "desert", WID_ETT_PLACE_DESERT),
745 Hotkey('O', "object", WID_ETT_PLACE_OBJECT),
746 HOTKEY_LIST_END
747 };
748
749 HotkeyList ScenarioEditorLandscapeGenerationWindow::hotkeys("terraform_editor", terraform_editor_hotkeys, TerraformToolbarEditorGlobalHotkeys);
750
751 static WindowDesc _scen_edit_land_gen_desc(
752 WDP_AUTO, "toolbar_landscape_scen", 0, 0,
753 WC_SCEN_LAND_GEN, WC_NONE,
754 WDF_CONSTRUCTION,
755 _nested_scen_edit_land_gen_widgets, lengthof(_nested_scen_edit_land_gen_widgets),
756 &ScenarioEditorLandscapeGenerationWindow::hotkeys
757 );
758
763 Window *ShowEditorTerraformToolbar()
764 {
765 return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
766 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:428
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2483
DDSP_DEMOLISH_AREA
@ DDSP_DEMOLISH_AREA
Clear area.
Definition: viewport_type.h:108
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
TerraformToolbarWindow::OnInitialPosition
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Definition: terraform_gui.cpp:261
IsInsideMM
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:230
sound_func.h
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:519
ScenarioEditorLandscapeGenerationWindow::last_user_action
int last_user_action
Last started user action.
Definition: terraform_gui.cpp:541
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:40
landscape_type.h
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1143
DDSP_CREATE_ROCKS
@ DDSP_CREATE_ROCKS
Fill area with rocks.
Definition: viewport_type.h:113
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
Commands
Commands
List of commands.
Definition: command_type.h:176
WID_ETT_LOWER_LAND
@ WID_ETT_LOWER_LAND
Lower land button.
Definition: terraform_widget.h:34
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
LM_LOWER
@ LM_LOWER
Lower the land.
Definition: map_type.h:83
terraform_cmd.h
company_base.h
ViewportDragDropSelectionProcess
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
Definition: viewport_type.h:107
ANIMCURSOR_RAISELAND
static const CursorID ANIMCURSOR_RAISELAND
696 - 698 - raise land tool
Definition: sprites.h:1498
CLEAR_ROCKS
@ CLEAR_ROCKS
3
Definition: clear_map.h:22
DDSP_LEVEL_AREA
@ DDSP_LEVEL_AREA
Level area.
Definition: viewport_type.h:111
signs_func.h
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:50
ScenarioEditorLandscapeGenerationWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: terraform_gui.cpp:569
WID_ETT_RESET_LANDSCAPE
@ WID_ETT_RESET_LANDSCAPE
Button for removing all company-owned property.
Definition: terraform_widget.h:44
SetRedErrorSquare
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2465
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
MakeClear
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition: tree_map.h:56
ScenarioEditorLandscapeGenerationWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: terraform_gui.cpp:716
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
CommonRaiseLowerBigLand
static void CommonRaiseLowerBigLand(TileIndex tile, bool mode)
Raise/Lower a bigger chunk of land at the same time in the editor.
Definition: terraform_gui.cpp:406
ScenarioEditorLandscapeGenerationWindow::OnPlaceDrag
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
Definition: terraform_gui.cpp:694
PlaceProc_DemolishArea
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Definition: terraform_gui.cpp:150
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
zoom_func.h
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:597
WID_ETT_BUTTONS_START
@ WID_ETT_BUTTONS_START
Start of pushable buttons.
Definition: terraform_widget.h:32
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
WID_ETT_PLACE_ROCKS
@ WID_ETT_PLACE_ROCKS
Place rocks button.
Definition: terraform_widget.h:37
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
ANIMCURSOR_DEMOLISH
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition: sprites.h:1496
TerraformToolbarWindow::last_user_action
int last_user_action
Last started user action.
Definition: terraform_gui.cpp:157
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
MAX_TILE_HEIGHT
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition: tile_type.h:24
clear_map.h
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:88
Window::HandleButtonClick
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:659
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:357
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:634
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
TerraformToolbarWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: terraform_gui.cpp:171
genworld.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
ScenarioEditorLandscapeGenerationWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: terraform_gui.cpp:552
WID_ETT_BUTTONS_END
@ WID_ETT_BUTTONS_END
End of pushable buttons.
Definition: terraform_widget.h:40
WID_ETT_NEW_SCENARIO
@ WID_ETT_NEW_SCENARIO
Button for generating a new scenario.
Definition: terraform_widget.h:43
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
textbuf_gui.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
TerraformToolbarWindow::OnPlaceMouseUp
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
Definition: terraform_gui.cpp:268
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
TerraformToolbarEditorGlobalHotkeys
static EventState TerraformToolbarEditorGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScenarioEditorLandscapeGenerationWindow.
Definition: terraform_gui.cpp:730
WindowDesc
High level window description.
Definition: window_gui.h:102
window_gui.h
TerraformToolbarWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: terraform_gui.cpp:225
landscape_cmd.h
WID_ETT_RAISE_LAND
@ WID_ETT_RAISE_LAND
Raise land button.
Definition: terraform_widget.h:35
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
GenerateDesertArea
static void GenerateDesertArea(TileIndex end, TileIndex start)
Scenario editor command that generates desert areas.
Definition: terraform_gui.cpp:58
WKC_GLOBAL_HOTKEY
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
Definition: gfx_type.h:33
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
CommandCost
Common return value for all commands.
Definition: command_type.h:24
SetTropicZone
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
ScenarioEditorLandscapeGenerationWindow::OnPlaceMouseUp
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
Definition: terraform_gui.cpp:699
tilehighlight_func.h
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:249
VpStartPlaceSizing
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Definition: viewport.cpp:2665
ShowCreateScenario
void ShowCreateScenario()
Show the window to create a scenario.
Definition: genworld_gui.cpp:1346
GenerateRockyArea
static void GenerateRockyArea(TileIndex end, TileIndex start)
Scenario editor command that generates rocky areas.
Definition: terraform_gui.cpp:75
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
ScenarioEditorLandscapeGenerationWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: terraform_gui.cpp:561
rail_cmd.h
HT_DIAGONAL
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
Definition: tilehighlight_type.h:28
WID_TT_LOWER_LAND
@ WID_TT_LOWER_LAND
Lower land button.
Definition: terraform_widget.h:17
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
DDSP_BUILD_OBJECT
@ DDSP_BUILD_OBJECT
Build an object.
Definition: viewport_type.h:118
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
WID_TT_RAISE_LAND
@ WID_TT_RAISE_LAND
Raise land button.
Definition: terraform_widget.h:18
VpSelectTilesWithMethod
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition: viewport.cpp:3150
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
WID_TT_PLACE_OBJECT
@ WID_TT_PLACE_OBJECT
Place object button.
Definition: terraform_widget.h:24
WID_TT_PLANT_TREES
@ WID_TT_PLANT_TREES
Plant trees button (note: opens separate window, no place-push-button).
Definition: terraform_widget.h:22
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
ScenarioEditorLandscapeGenerationWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: terraform_gui.cpp:586
GetToolbarAlignedWindowPosition
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
Definition: window.cpp:1679
HandlePlacePushButton
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:62
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:246
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:354
WID_ETT_PLACE_OBJECT
@ WID_ETT_PLACE_OBJECT
Place transmitter button.
Definition: terraform_widget.h:39
WID_ETT_DOTS
@ WID_ETT_DOTS
Invisible widget for rendering the terraform size on.
Definition: terraform_widget.h:31
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1058
DDSP_LOWER_AND_LEVEL_AREA
@ DDSP_LOWER_AND_LEVEL_AREA
Lower / level area.
Definition: viewport_type.h:110
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WID_ETT_SHOW_PLACE_DESERT
@ WID_ETT_SHOW_PLACE_DESERT
Should the place desert button be shown?
Definition: terraform_widget.h:29
LM_LEVEL
@ LM_LEVEL
Level the land.
Definition: map_type.h:82
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
TerraformToolbarWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: terraform_gui.cpp:178
RoundDivSU
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:302
WID_TT_SHOW_PLACE_OBJECT
@ WID_TT_SHOW_PLACE_OBJECT
Should the place object button be shown?
Definition: terraform_widget.h:15
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:363
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1409
viewport_func.h
terraform_widget.h
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:443
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
ResetLandscapeConfirmationCallback
static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
Callback function for the scenario editor 'reset landscape' confirmation window.
Definition: terraform_gui.cpp:510
object_cmd.h
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
newgrf_object.h
OrthogonalTileArea::h
uint16 h
The height of the area.
Definition: tilearea_type.h:21
WID_TT_BUTTONS_START
@ WID_TT_BUTTONS_START
Start of pushable buttons.
Definition: terraform_widget.h:16
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
OBJECT_OWNED_LAND
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
Definition: object_type.h:19
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1266
IsBuoyTile
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:316
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:216
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
strings_func.h
TerraformToolbarWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: terraform_gui.cpp:293
terraform_gui.h
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
WID_ETT_LEVEL_LAND
@ WID_ETT_LEVEL_LAND
Level land button.
Definition: terraform_widget.h:36
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
WID_ETT_START
@ WID_ETT_START
Used for iterations.
Definition: terraform_widget.h:30
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
SLOPE_N
@ SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:53
WC_SCEN_LAND_GEN
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:442
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
TerraformToolbarWindow::OnPlaceDrag
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
Definition: terraform_gui.cpp:256
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3271
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
tree_map.h
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1998
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
WID_TT_BUY_LAND
@ WID_TT_BUY_LAND
Buy land button.
Definition: terraform_widget.h:21
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:422
DDSP_RAISE_AND_LEVEL_AREA
@ DDSP_RAISE_AND_LEVEL_AREA
Raise / level area.
Definition: viewport_type.h:109
EventState
EventState
State of handling an event.
Definition: window_type.h:719
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
VPM_X_AND_Y
@ VPM_X_AND_Y
area of land in X and Y directions
Definition: viewport_type.h:92
base_station_base.h
PlaceProc_Sign
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
Definition: signs_cmd.cpp:123
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
company_func.h
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:247
TerraformToolbarGlobalHotkeys
static EventState TerraformToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the TerraformToolbarWindow.
Definition: terraform_gui.cpp:306
GetTreeGround
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
ScenarioEditorLandscapeGenerationWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: terraform_gui.cpp:652
CommandHelper
Definition: command_func.h:94
window_func.h
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:217
WID_TT_DEMOLISH
@ WID_TT_DEMOLISH
Demolish aka dynamite button.
Definition: terraform_widget.h:20
TerraformToolbarWindow
Terra form toolbar managing class.
Definition: terraform_gui.cpp:156
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
ScenarioEditorLandscapeGenerationWindow
Landscape generation window handler in the scenario editor.
Definition: terraform_gui.cpp:540
ShowTerraformToolbar
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
Definition: terraform_gui.cpp:371
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:89
SND_1F_CONSTRUCTION_OTHER
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition: sound_type.h:68
OverflowSafeInt< int64 >
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
engine_base.h
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition: window_type.h:326
gui.h
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
Window
Data structure for an opened window.
Definition: window_gui.h:213
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:412
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:77
ShowBuildObjectPicker
Window * ShowBuildObjectPicker()
Show our object picker.
Definition: object_gui.cpp:753
HT_POINT
@ HT_POINT
point (lower land, raise land, level land, ...)
Definition: tilehighlight_type.h:22
WID_ETT_DECREASE_SIZE
@ WID_ETT_DECREASE_SIZE
Downwards arrow button to decrease terraforming size.
Definition: terraform_widget.h:42
LM_RAISE
@ LM_RAISE
Raise the land.
Definition: map_type.h:84
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
Window::nested_array_size
uint nested_array_size
Size of the nested array.
Definition: window_gui.h:260
OrthogonalTileArea::ClampToMap
void ClampToMap()
Clamp the tile area to map borders.
Definition: tilearea.cpp:142
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:621
WID_ETT_PLACE_DESERT
@ WID_ETT_PLACE_DESERT
Place desert button (in tropical climate).
Definition: terraform_widget.h:38
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
Company
Definition: company_base.h:117
ChangeOwnershipOfCompanyItems
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
Change the ownership of all the items of a company.
Definition: economy.cpp:299
WID_TT_LEVEL_LAND
@ WID_TT_LEVEL_LAND
Level land button.
Definition: terraform_widget.h:19
WID_ETT_DEMOLISH
@ WID_ETT_DEMOLISH
Demolish aka dynamite button.
Definition: terraform_widget.h:33
ScenarioEditorLandscapeGenerationWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: terraform_gui.cpp:663
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
WID_TT_PLACE_SIGN
@ WID_TT_PLACE_SIGN
Place sign button.
Definition: terraform_widget.h:23
WID_ETT_INCREASE_SIZE
@ WID_ETT_INCREASE_SIZE
Upwards arrow button to increase terraforming size.
Definition: terraform_widget.h:41
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
object.h
ShowEditorTerraformToolbar
Window * ShowEditorTerraformToolbar()
Show the toolbar for terraforming in the scenario editor.
Definition: terraform_gui.cpp:763
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:22
hotkeys.h
ANIMCURSOR_LOWERLAND
static const CursorID ANIMCURSOR_LOWERLAND
699 - 701 - lower land tool
Definition: sprites.h:1497
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
backup_type.hpp
DDSP_CREATE_DESERT
@ DDSP_CREATE_DESERT
Fill area with desert.
Definition: viewport_type.h:112
GUIPlaceProcDragXY
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
Definition: terraform_gui.cpp:111