44 #include "table/strings.h"
61 if (_game_mode != GM_EDITOR)
return;
78 if (_game_mode != GM_EDITOR)
return;
165 this->last_user_action = INVALID_WID_TT;
179 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
186 this->last_user_action = widget;
191 this->last_user_action = widget;
196 this->last_user_action = widget;
201 this->last_user_action = widget;
206 this->last_user_action = widget;
210 ShowBuildTreesToolbar();
215 this->last_user_action = widget;
222 default: NOT_REACHED();
226 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
228 switch (this->last_user_action) {
253 default: NOT_REACHED();
262 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]]
int window_number)
override
272 switch (select_proc) {
273 default: NOT_REACHED();
312 static inline HotkeyList hotkeys{
"terraform", {
324 static constexpr
NWidgetPart _nested_terraform_widgets[] = {
332 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
334 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
336 SetFill(0, 1),
SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
343 SetFill(0, 1),
SetDataTip(SPR_IMG_BUY_LAND, STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND),
350 SetFill(0, 1),
SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
359 _nested_terraform_widgets,
360 &TerraformToolbarWindow::hotkeys
373 if (link ==
nullptr) {
374 w = AllocateWindowDescFront<TerraformToolbarWindow>(_terraform_desc, 0);
380 w = AllocateWindowDescFront<TerraformToolbarWindow>(_terraform_desc, 0);
392 static uint8_t _terraform_size = 1;
405 if (_terraform_size == 1) {
407 mode ? STR_ERROR_CAN_T_RAISE_LAND_HERE : STR_ERROR_CAN_T_LOWER_LAND_HERE;
411 assert(_terraform_size != 0);
412 TileArea ta(tile, _terraform_size, _terraform_size);
415 if (ta.
w == 0 || ta.
h == 0)
return;
442 static const int8_t _multi_terraform_coords[][2] = {
444 { 4, 0}, { -4, 0}, { 0, 2},
445 { -8, 2}, { -4, 4}, { 0, 6}, { 4, 4}, { 8, 2},
446 {-12, 0}, { -8, -2}, { -4, -4}, { 0, -6}, { 4, -4}, { 8, -2}, { 12, 0},
447 {-16, 2}, {-12, 4}, { -8, 6}, { -4, 8}, { 0, 10}, { 4, 8}, { 8, 6}, { 12, 4}, { 16, 2},
448 {-20, 0}, {-16, -2}, {-12, -4}, { -8, -6}, { -4, -8}, { 0,-10}, { 4, -8}, { 8, -6}, { 12, -4}, { 16, -2}, { 20, 0},
449 {-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},
450 {-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},
453 static constexpr
NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
466 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
468 SetFill(0, 1),
SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
470 SetFill(0, 1),
SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
472 SetFill(0, 1),
SetDataTip(SPR_IMG_ROCKS, STR_TERRAFORM_TOOLTIP_PLACE_ROCKY_AREAS_ON_LANDSCAPE),
475 SetFill(0, 1),
SetDataTip(SPR_IMG_DESERT, STR_TERRAFORM_TOOLTIP_DEFINE_DESERT_AREA),
478 SetFill(0, 1),
SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
519 old_generating_world.
Restore();
525 if (!st->IsInUse())
delete st;
545 this->last_user_action = INVALID_WID_ETT;
561 size.width = std::max<uint>(size.width,
ScaleGUITrad(59));
562 size.height = std::max<uint>(size.height,
ScaleGUITrad(31));
565 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
569 int center_x =
RoundDivSU(r.left + r.right, 2);
570 int center_y =
RoundDivSU(r.top + r.bottom, 2);
572 int n = _terraform_size * _terraform_size;
573 const int8_t *coords = &_multi_terraform_coords[0][0];
582 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
589 this->last_user_action = widget;
594 this->last_user_action = widget;
599 this->last_user_action = widget;
604 this->last_user_action = widget;
609 this->last_user_action = widget;
614 this->last_user_action = widget;
625 size += _terraform_size;
628 _terraform_size = size;
644 default: NOT_REACHED();
656 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
658 switch (this->last_user_action) {
683 default: NOT_REACHED();
695 switch (select_proc) {
696 default: NOT_REACHED();
728 static inline HotkeyList hotkeys{
"terraform_editor", {
740 WDP_AUTO,
"toolbar_landscape_scen", 0, 0,
743 _nested_scen_edit_land_gen_widgets,
744 &ScenarioEditorLandscapeGenerationWindow::hotkeys
753 return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(_scen_edit_land_gen_desc, 0);
Class for backupping variables and making sure they are restored later.
Base classes/functions for base stations.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
static uint GetUIClassCount()
Get the number of classes available to the user.
Map accessors for 'clear' tiles.
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Functions related to commands.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
@ DC_EXEC
execute the given command
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
Change the ownership of all the items of a company.
@ INVALID_OWNER
An invalid owner.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
void ShowCreateScenario()
Show the window to create a scenario.
bool _ctrl_pressed
Is Ctrl pressed?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
GUI functions that shouldn't be here.
Hotkey related functions.
definition of HouseSpec and accessors
Command definitions related to landscape (slopes etc.).
Types related to the landscape.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
@ LM_LEVEL
Level the land.
@ LM_LOWER
Lower the land.
@ LM_RAISE
Raise the land.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowQuery(StringID caption, StringID 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...
Functions related to NewGRF objects.
Functions related to objects.
Window * ShowBuildObjectPicker()
Show our object picker.
Command definitions related to objects.
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
Command definitions for rail.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
Functions related to signs.
@ SLOPE_N
the north corner of the tile is raised
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
static const CursorID ANIMCURSOR_LOWERLAND
699 - 701 - lower land tool
static const CursorID ANIMCURSOR_RAISELAND
696 - 698 - raise land tool
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
Definition of base types and functions in a cross-platform compatible way.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class to backup a specific variable and restore it later.
void Restore()
Restore the variable.
Base class for all station-ish types.
SoundSettings sound
sound effect settings
bool freeform_edges
allow terraforming the tiles at the map edges
Dimensions (a width and height) of a rectangle in 2D.
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
uint8_t landscape
the landscape we're currently in
ConstructionSettings construction
construction of things in-game
GameCreationSettings game_creation
settings used during the creation of a game (map)
List of hotkeys for a window.
All data for a single hotkey.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Represents the covered area of e.g.
void ClampToMap()
Clamp the tile area to map borders.
uint16_t w
The width of the area.
uint16_t h
The height of the area.
Coordinates of a point in 2D.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Specification of a rectangle with absolute coordinates of all edges.
Landscape generation window handler in the scenario editor.
int last_user_action
Last started user action.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnPaint() override
The window must be repainted.
void OnTimeout() override
Called when this window's timeout has been reached.
static EventState TerraformToolbarEditorGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScenarioEditorLandscapeGenerationWindow.
bool click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
High level window description.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
int left
x position of left edge of the window
int top
y position of top edge of the window
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
int height
Height of the window (number of pixels down in y direction)
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
@ TROPICZONE_DESERT
Tile is desert.
@ TROPICZONE_NORMAL
Normal tropiczone.
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
@ MP_TREES
Tile got trees.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Functions related to tile highlights.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_POINT
point (lower land, raise land, level land, ...)
@ HT_RECT
rectangle (stations, depots, ...)
Map accessors for tree tiles.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Functions related to (drawing on) viewports.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_CREATE_DESERT
Fill area with desert.
@ DDSP_LOWER_AND_LEVEL_AREA
Lower / level area.
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_CREATE_ROCKS
Fill area with rocks.
@ DDSP_RAISE_AND_LEVEL_AREA
Raise / level area.
@ DDSP_LEVEL_AREA
Level area.
@ DDSP_BUILD_OBJECT
Build an object.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
@ VPM_X_AND_Y
area of land in X and Y directions
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
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...
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
int32_t WindowNumber
Number to differentiate different windows of the same class.
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_TOWN_VIEW
Town view; Window numbers:
Functions related to zooming.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.