Go to the documentation of this file.
37 #include "table/strings.h"
55 if (_game_mode != GM_EDITOR)
return;
72 if (_game_mode != GM_EDITOR)
return;
180 this->last_user_action = widget;
185 this->last_user_action = widget;
190 this->last_user_action = widget;
195 this->last_user_action = widget;
200 this->last_user_action = widget;
204 ShowBuildTreesToolbar();
209 this->last_user_action = widget;
216 default: NOT_REACHED();
222 switch (this->last_user_action) {
247 default: NOT_REACHED();
266 switch (select_proc) {
267 default: NOT_REACHED();
299 static Hotkey terraform_hotkeys[] = {
312 static const NWidgetPart _nested_terraform_widgets[] = {
320 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
322 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
324 SetFill(0, 1),
SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
331 SetFill(0, 1),
SetDataTip(SPR_IMG_BUY_LAND, STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND),
338 SetFill(0, 1),
SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
347 _nested_terraform_widgets,
lengthof(_nested_terraform_widgets),
348 &TerraformToolbarWindow::hotkeys
361 if (link ==
nullptr) {
362 w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
368 w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
380 static byte _terraform_size = 1;
393 if (_terraform_size == 1) {
395 mode ? STR_ERROR_CAN_T_RAISE_LAND_HERE : STR_ERROR_CAN_T_LOWER_LAND_HERE;
399 assert(_terraform_size != 0);
400 TileArea ta(tile, _terraform_size, _terraform_size);
403 if (ta.
w == 0 || ta.
h == 0)
return;
430 static const int8 _multi_terraform_coords[][2] = {
432 { 4, 0}, { -4, 0}, { 0, 2},
433 { -8, 2}, { -4, 4}, { 0, 6}, { 4, 4}, { 8, 2},
434 {-12, 0}, { -8, -2}, { -4, -4}, { 0, -6}, { 4, -4}, { 8, -2}, { 12, 0},
435 {-16, 2}, {-12, 4}, { -8, 6}, { -4, 8}, { 0, 10}, { 4, 8}, { 8, 6}, { 12, 4}, { 16, 2},
436 {-20, 0}, {-16, -2}, {-12, -4}, { -8, -6}, { -4, -8}, { 0,-10}, { 4, -8}, { 8, -6}, { 12, -4}, { 16, -2}, { 20, 0},
437 {-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},
438 {-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 static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
454 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
456 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
458 SetFill(0, 1),
SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
460 SetFill(0, 1),
SetDataTip(SPR_IMG_ROCKS, STR_TERRAFORM_TOOLTIP_PLACE_ROCKY_AREAS_ON_LANDSCAPE),
463 SetFill(0, 1),
SetDataTip(SPR_IMG_DESERT, STR_TERRAFORM_TOOLTIP_DEFINE_DESERT_AREA),
466 SetFill(0, 1),
SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
514 if (!st->IsInUse())
delete st;
550 size->width = std::max<uint>(size->width,
ScaleGUITrad(59));
551 size->height = std::max<uint>(size->height,
ScaleGUITrad(31));
558 int center_x =
RoundDivSU(r.left + r.right, 2);
559 int center_y =
RoundDivSU(r.top + r.bottom, 2);
561 int n = _terraform_size * _terraform_size;
562 const int8 *coords = &_multi_terraform_coords[0][0];
578 this->last_user_action = widget;
583 this->last_user_action = widget;
588 this->last_user_action = widget;
593 this->last_user_action = widget;
598 this->last_user_action = widget;
603 this->last_user_action = widget;
614 size += _terraform_size;
617 _terraform_size = size;
633 default: NOT_REACHED();
650 switch (this->last_user_action) {
675 default: NOT_REACHED();
687 switch (select_proc) {
688 default: NOT_REACHED();
723 static Hotkey terraform_editor_hotkeys[] = {
737 WDP_AUTO,
"toolbar_landscape_scen", 0, 0,
740 _nested_scen_edit_land_gen_widgets,
lengthof(_nested_scen_edit_land_gen_widgets),
741 &ScenarioEditorLandscapeGenerationWindow::hotkeys
750 return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
@ DDSP_DEMOLISH_AREA
Clear area.
#define CMD_MSG(x)
Used to combine a StringID with the command.
uint32 TileIndex
The index/ID of a Tile.
@ TROPICZONE_DESERT
Tile is desert.
@ CMD_CLEAR_AREA
clear an area
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
int last_user_action
Last started user action.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
List of hotkeys for a window.
Dimensions (a width and height) of a rectangle in 2D.
@ DDSP_CREATE_ROCKS
Fill area with rocks.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
byte landscape
the landscape we're currently in
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
static const CursorID ANIMCURSOR_RAISELAND
696 - 698 - raise land tool
@ DDSP_LEVEL_AREA
Level area.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
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.
bool _ctrl_pressed
Is Ctrl pressed?
@ SND_15_BEEP
19 == 0x13 GUI button click
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
ClientSettings _settings_client
The current settings for this game.
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
static uint TileY(TileIndex tile)
Get the Y component of a tile.
int32 WindowNumber
Number to differentiate different windows of the same class.
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
@ DC_EXEC
execute the given command
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void OnPaint() override
The window must be repainted.
@ LM_LEVEL
Level the land.
bool Succeeded() const
Did this command succeed?
static uint TileX(TileIndex tile)
Get the X component of a tile.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
High level window description.
@ WDP_AUTO
Find a place automatically.
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
ResizeInfo resize
Resize information.
Common return value for all commands.
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
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.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
SoundSettings sound
sound effect settings
@ CMD_TERRAFORM_LAND
terraform a tile
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
int height
Height of the window (number of pixels down in y direction)
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
void ShowCreateScenario()
Show the window to create a scenario.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ INVALID_OWNER
An invalid owner.
uint16 w
The width of the area.
@ ES_NOT_HANDLED
The passed event is not handled.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Represents the covered area of e.g.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
int left
x position of left edge of the window
bool freeform_edges
allow terraforming the tiles at the map edges
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
@ DDSP_LOWER_AND_LEVEL_AREA
Lower / level area.
Coordinates of a point in 2D.
WindowNumber window_number
Window number within the window class.
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
@ LM_RAISE
Raise the land.
@ CMD_LEVEL_LAND
level land
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
uint16 h
The height of the area.
@ MP_TREES
Tile got trees.
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
bool _generating_world
Whether we are generating the map or not.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
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...
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
bool confirm
Play sound effect on successful constructions or other actions.
@ SLOPE_N
the north corner of the tile is raised
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
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...
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
@ DDSP_RAISE_AND_LEVEL_AREA
Raise / level area.
EventState
State of handling an event.
@ HT_RECT
rectangle (stations, depots, ...)
@ VPM_X_AND_Y
area of land in X and Y directions
@ CMD_BUILD_OBJECT
build an object
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Base class for all station-ish types.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
int top
y position of top edge of the window
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
void OnTimeout() override
Called when this window's timeout has been reached.
bool click_beep
Beep on a random selection of buttons.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
Landscape generation window handler in the scenario editor.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
@ WC_TOWN_VIEW
Town view; Window numbers:
ConstructionSettings construction
construction of things in-game
Data structure for an opened window.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
void DrawWidgets() const
Paint all widgets of a window.
@ TROPICZONE_NORMAL
Normal tropiczone.
Window * ShowBuildObjectPicker()
Show our object picker.
@ HT_POINT
point (lower land, raise land, level land, ...)
uint nested_array_size
Size of the nested array.
void ClampToMap()
Clamp the tile area to map borders.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Specification of a rectangle with absolute coordinates of all edges.
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
Change the ownership of all the items of a company.
@ LM_LOWER
Lower the land.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ CMD_LANDSCAPE_CLEAR
demolish a tile
All data for a single hotkey.
static const CursorID ANIMCURSOR_LOWERLAND
699 - 701 - lower land tool
@ DDSP_CREATE_DESERT
Fill area with desert.