27#include "table/strings.h"
37 { 1621, PAL_NONE }, { 1635, PAL_NONE }, { 1656, PAL_NONE }, { 1579, PAL_NONE },
38 { 1607, PAL_NONE }, { 1593, PAL_NONE }, { 1614, PAL_NONE }, { 1586, PAL_NONE },
39 { 1663, PAL_NONE }, { 1677, PAL_NONE }, { 1691, PAL_NONE }, { 1705, PAL_NONE },
40 { 1711, PAL_NONE }, { 1746, PAL_NONE }, { 1753, PAL_NONE }, { 1732, PAL_NONE },
41 { 1739, PAL_NONE }, { 1718, PAL_NONE }, { 1725, PAL_NONE }, { 1760, PAL_NONE },
42 { 1838, PAL_NONE }, { 1844, PAL_NONE }, { 1866, PAL_NONE }, { 1871, PAL_NONE },
43 { 1899, PAL_NONE }, { 1935, PAL_NONE }, { 1928, PAL_NONE }, { 1915, PAL_NONE },
44 { 1887, PAL_NONE }, { 1908, PAL_NONE }, { 1824, PAL_NONE }, { 1943, PAL_NONE },
45 { 1950, PAL_NONE }, { 1957, PALETTE_TO_GREEN }, { 1964, PALETTE_TO_RED }, { 1971, PAL_NONE },
46 { 1978, PAL_NONE }, { 1985, PALETTE_TO_RED, }, { 1992, PALETTE_TO_PALE_GREEN }, { 1999, PALETTE_TO_YELLOW }, { 2006, PALETTE_TO_RED }
66 for (
int i = base; i < base + count; i++) {
69 size.width = std::max<int>(size.width, 2 * std::max<int>(this_size.width, -offset.x));
70 size.height = std::max<int>(size.height, std::max<int>(this_size.height, -offset.y));
103 if (this->tree_to_plant >= 0) {
115 }
else if (this->tree_to_plant >= 0) {
119 switch (this->mode) {
123 default: NOT_REACHED();
135 const uint
radius = this->mode == PM_FOREST_LG ? 12 : 5;
136 const uint count = this->mode == PM_FOREST_LG ? 12 : 5;
149 if (_game_mode != GM_EDITOR) {
160 size.width =
d.width + padding.width;
189 this->mode = PM_NORMAL;
194 assert(_game_mode == GM_EDITOR);
195 this->mode = PM_FOREST_SM;
200 assert(_game_mode == GM_EDITOR);
201 this->mode = PM_FOREST_LG;
208 this->tree_to_plant = this->tree_to_plant == index ? -1 : index;
217 if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL) {
226 if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL) {
231 if (this->mode == PM_NORMAL) {
234 this->DoPlantForest(tile);
241 if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL &&
pt.x != -1 && select_proc ==
DDSP_PLANT_TREES) {
248 this->tree_to_plant = -1;
265 const int num_columns = type_count == 9 ? 3 : 4;
266 const int num_rows =
CeilDiv(type_count, num_columns);
267 uint8_t cur_type = type_base;
269 auto vstack = std::make_unique<NWidgetVertical>(
NC_EQUALSIZE);
270 vstack->SetPIP(0, 1, 0);
272 for (
int row = 0; row < num_rows; row++) {
273 auto hstack = std::make_unique<NWidgetHorizontal>(
NC_EQUALSIZE);
274 hstack->SetPIP(0, 1, 0);
275 for (
int col = 0; col < num_columns; col++) {
276 if (cur_type > type_base + type_count)
break;
278 button->SetDataTip(0x0, STR_PLANT_TREE_TOOLTIP);
279 hstack->Add(std::move(button));
282 vstack->Add(std::move(hstack));
288static constexpr NWidgetPart _nested_build_trees_widgets[] = {
317 _nested_build_trees_widgets
320void ShowBuildTreesToolbar()
323 AllocateWindowDescFront<BuildTreesWindow>(_build_trees_desc, 0);
PlantingMode mode
Current mode for planting.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
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.
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.
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.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
int tree_to_plant
Tree number to plant, TREE_INVALID for a random tree.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
static const int BUTTON_BOTTOM_OFFSET
Visual Y offset of tree root from the bottom of the tree type buttons.
void UpdateMode()
Update the GUI and enable/disable planting to reflect selected options.
Functions related to 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.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
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.
Functions related to the gfx engine.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Pseudo random number generator.
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.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Functions related to OTTD's strings.
SoundSettings sound
sound effect settings
Dimensions (a width and height) of a rectangle in 2D.
uint8_t landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
Combination of a palette sprite and a 'real' sprite.
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.
Specification of a rectangle with absolute coordinates of all edges.
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.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
WindowClass window_class
Window class.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
WindowNumber window_number
Window number within the window class.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
void VpStartDragging(ViewportDragDropSelectionProcess process)
Drag over the map while holding the left mouse down.
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_RECT
rectangle (stations, depots, ...)
Command definitions related to tree tiles.
static Dimension GetMaxTreeSpriteSize()
Calculate the maximum size of all tree sprites.
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
Place some trees in a radius around a tile.
void PlaceTreesRandomly()
Place some trees randomly.
const PalSpriteID tree_sprites[]
Tree Sprites with their palettes.
static std::unique_ptr< NWidgetBase > MakeTreeTypeButtons()
Make widgets for the current available tree types.
Sprites to use and how to display them for tree tiles.
Map accessors for tree tiles.
TreeType
List of tree types along all landscape types.
@ TREE_INVALID
An invalid tree.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_PLANT_TREES
Plant trees.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
@ VPM_X_AND_Y
area of land in X and Y directions
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.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_BUILD_TREES
Build trees toolbar; Window numbers:
Functions related to zooming.