Go to the documentation of this file.
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) {
107 this->tree_to_plant = current_tree;
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;
151 if (_game_mode != GM_EDITOR) {
162 size->width = d.width + padding.width;
191 this->mode = PM_NORMAL;
196 assert(_game_mode == GM_EDITOR);
197 this->mode = PM_FOREST_SM;
202 assert(_game_mode == GM_EDITOR);
203 this->mode = PM_FOREST_LG;
210 this->tree_to_plant = this->tree_to_plant == index ? -1 : index;
219 if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL) {
228 if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL) {
233 if (this->mode == PM_NORMAL) {
236 this->DoPlantForest(tile);
243 if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL && pt.x != -1 && select_proc ==
DDSP_PLANT_TREES) {
250 this->tree_to_plant = -1;
267 const int num_columns = type_count == 9 ? 3 : 4;
268 const int num_rows =
CeilDiv(type_count, num_columns);
269 byte cur_type = type_base;
274 for (
int row = 0; row < num_rows; row++) {
278 for (
int col = 0; col < num_columns; col++) {
279 if (cur_type > type_base + type_count)
break;
281 button->
SetDataTip(0x0, STR_PLANT_TREE_TOOLTIP);
291 static const NWidgetPart _nested_build_trees_widgets[] = {
323 _nested_build_trees_widgets,
lengthof(_nested_build_trees_widgets)
326 void ShowBuildTreesToolbar()
329 AllocateWindowDescFront<BuildTreesWindow>(&_build_trees_desc, 0);
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Dimensions (a width and height) of a rectangle in 2D.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
byte landscape
the landscape we're currently in
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
static const int BUTTON_BOTTOM_OFFSET
Visual Y offset of tree root from the bottom of the tree type buttons.
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
Place some trees in a radius around a tile.
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.
@ WC_BUILD_TREES
Build trees toolbar; Window numbers:
ClientSettings _settings_client
The current settings for this game.
int32 WindowNumber
Number to differentiate different windows of the same class.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
GameCreationSettings game_creation
settings used during the creation of a game (map)
PlantingMode mode
Current mode for planting.
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.
High level window description.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
void PlaceTreesRandomly()
Place some trees randomly.
SoundSettings sound
sound effect settings
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
@ TREE_INVALID
An invalid tree.
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 VpStartDragging(ViewportDragDropSelectionProcess process)
Drag over the map while holding the left mouse down.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Coordinates of a point in 2D.
WindowNumber window_number
Window number within the window class.
const PalSpriteID tree_sprites[]
Tree Sprites with their palettes.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool confirm
Play sound effect on successful constructions or other actions.
static Dimension GetMaxTreeSpriteSize()
Calculate the maximum size of all tree sprites.
@ HT_RECT
rectangle (stations, depots, ...)
@ VPM_X_AND_Y
area of land in X and Y directions
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.
WindowClass window_class
Window class.
Combination of a palette sprite and a 'real' sprite.
void UpdateMode()
Update the GUI and enable/disable planting to reflect selected options.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
#define lengthof(x)
Return the length of an fixed size array.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Data structure for an opened window.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ DDSP_PLANT_TREES
Plant trees.
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...
int tree_to_plant
Tree number to plant, TREE_INVALID for a random tree.
Specification of a rectangle with absolute coordinates of all edges.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
static NWidgetBase * MakeTreeTypeButtons(int *biggest_index)
Make widgets for the current available tree types.
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.
TreeType
List of tree types along all landscape types.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.