OpenTTD Source: src/terraform_gui.cpp Source File

OpenTTD Source 15.0-RC2

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