Table of Contents

Class Tool

Namespace
TinyLife.Tools
Assembly
Tiny Life.dll

A tool is a type of game mode that is currently active. Tools are split up into the PlayModeTool and BuildTools, the latter of which holds all tools that can be found in the build menu.

public class Tool
Inheritance
Tool
Derived
Inherited Members
Extension Methods

Constructors

Tool(TextureRegion, bool)

Creates a new tool with the given settings

public Tool(TextureRegion texture, bool displayAsTab = false)

Parameters

texture TextureRegion

The texture of the tool icon

displayAsTab bool

Wheteher or not this tool should display as a tab. Defaults to false.

Fields

BuildTools

A set of Tool instances that can be activated using the build mode menu. All tools in this list are automatically added to the menu.

public static readonly List<Tool> BuildTools

Field Value

List<Tool>

DisplayAsTab

Whether or not this tool should be displayed as a tab (like the RemoveTool) or a button in the build menu

public readonly bool DisplayAsTab

Field Value

bool

MousePos

The position of the mouse in world coordinates. This position is set every Update(GameTime, bool) call.

protected Vector2 MousePos

Field Value

Vector2

MoveTool

The MoveTool singleton

public static readonly MoveTool MoveTool

Field Value

MoveTool

PlayModeTool

The PlayModeTool singleton, which is activated when build mode is inactive.

public static readonly PlayModeTool PlayModeTool

Field Value

PlayModeTool

RemoveTool

The RemoveTool singleton, which is activated using the Remove tab in the build menu or by holding the control key.

public static readonly RemoveTool RemoveTool

Field Value

RemoveTool

Texture

The texture region that should be used to display this tool in the build menu

public readonly TextureRegion Texture

Field Value

TextureRegion

Properties

CurrentFloor

The floor that the game's camera is currently focused on. For the active lot, all floors that are above the current floor are hidden, and all floors below the current floor are always displayed.

protected static int CurrentFloor { get; }

Property Value

int

Input

This game's input handler. This can easily be accessed through MLEM.Startup.MlemGame.Input.

protected static InputHandler Input { get; }

Property Value

InputHandler

IsCopyPressed

Returns whether a keybind or button combination is pressed that indicates that an object should be copied.

public static bool IsCopyPressed { get; }

Property Value

bool

IsRotateCcwPressed

Returns whether a keybind or button combination is pressed that indicates that an object should be rotated clockwise now. This should be queried before IsRotateCwPressed, since this checks for modifier keys being pressed.

public static bool IsRotateCcwPressed { get; }

Property Value

bool

IsRotateCwPressed

Returns whether a keybind or button combination is pressed that indicates that an object should be rotated clockwise now. This should be queried after IsRotateCcwPressed, since this doesn't check for any modifier keys.

public static bool IsRotateCwPressed { get; }

Property Value

bool

Map

The map that the game's Camera is currently on. If no maps are loaded (ie we're not in game), this property returns null.

protected static Map Map { get; }

Property Value

Map

Money

The money that this household has, rounded by two digits after the decimal point

protected static float Money { get; set; }

Property Value

float

SelectedObject

The MapObject that is currently below the mouse, or null if there is none. This object selection mechanic uses pixel-perfect collision based on the object's rendered texture.

public static MapObject SelectedObject { get; }

Property Value

MapObject

SelectedRoof

The Roof that is currently below the mouse, or null if there is none. This object selection mechanic uses pixel-perfect collision based on the roof's rendered texture.

public static Roof SelectedRoof { get; }

Property Value

Roof

SelectedStairs

The Stairs object that is currently below the mouse, or null is there is none. This object selection mechanic uses pixel-perfect collision based on the stairs' rendered texture.

public static Stairs SelectedStairs { get; }

Property Value

Stairs

SelectedWall

The WallLike that is currently below the mouse, or null if there is none. This object selection mechanic uses pixel-perfect collision based on the wall's rendered texture.

public static WallLike SelectedWall { get; }

Property Value

WallLike

Methods

BuildModeButton(string, GenericCallback, DrawCallback, float, TextureRegion, string, IEnumerable<string>, float?)

Creates a new MLEM.Ui.Elements.Button in the style of each build mode content button, like the ones that display the furniture that can be bought.

public static Button BuildModeButton(string name, Element.GenericCallback onPressed, Element.DrawCallback onDrawn, float price, TextureRegion icon, string seenId = null, IEnumerable<string> description = null, float? customPrice = null)

Parameters

name string

The name that should be displayed when hovering the button.

onPressed Element.GenericCallback

A fucntion that is called when the created button is pressed

onDrawn Element.DrawCallback

A function that is called when the created button is drawn

price float

The price that should be displayed for this object

icon TextureRegion

The build mode category icon of this object

seenId string

A name that can optionally be used for the seen system (SeenObjects), where a green dot will display next to any build mode buttons containing objects that the player has not seen yet. Usually, the seen id is the object's registry name.

description IEnumerable<string>

An optional set of text lines that will be inserted into the tooltip's description part

customPrice float?

The custom price that should be displayed (and used) instead of the price. If this value is set, the regular price will be displayed as strikethrough

Returns

Button

A new button with the passed settings

CanPlaceForTooltip()

Returns whether or not the tool should currently be considered to be able to place objects for a tooltip displayed to the player.

public virtual CanPlaceResult CanPlaceForTooltip()

Returns

CanPlaceResult

A CanPlaceResult that represents whether the tool should be considered to be able to place objects.

CanSwitchGameModes()

Whether or not the game CanSwitchGameModes() currently, while this tool is selected

public virtual bool CanSwitchGameModes()

Returns

bool

Whether the game can be mode switched right now

CanUndoRedo()

Returns whether or not the UndoRedoStack can currently operate and thus, whether the Undo() or Redo() actions can be called.

public virtual bool CanUndoRedo()

Returns

bool

Whether the undo or redo commands can be used right now.

Closed()

Called when this build tool is closed. By default, this method removes its elements from the ui.

public virtual void Closed()

ColorSelection(ColorScheme, Color, Action<int>, Func<int, bool>, string)

Creates a new MLEM.Ui.Elements.Group that resembles a set of color selection buttons. This is used by CharacterCreator, as well as tools like the FurnitureTool.

public static Group ColorSelection(ColorScheme colors, Color modifier, Action<int> onPressed, Func<int, bool> isSelected, string name = null)

Parameters

colors ColorScheme

The color scheme to create buttons for

modifier Color

A color that all colors in the color scheme will be multiplied, which is useful if the object the colors are being applied on is not grayscale.

onPressed Action<int>

A function that returns the index of the color that has been pressed

isSelected Func<int, bool>

A function that determines whether the color with the given index is selected, which causes a rectangle to be drawn around it.

name string

The name to display above this color selection.

Returns

Group

A group of buttons with the given settings

ColorSelection(ColorSettings, Action<int, int>, Func<int, int, bool>)

Creates a new MLEM.Ui.Elements.Group that resembles a set of color selection buttons. This method uses ColorSelection(ColorSettings, Action<int, int>, Func<int, int, bool>) to create multiple color selection areas for all the passed settings' Schemes.

public static Group ColorSelection(ColorSettings settings, Action<int, int> onPressed, Func<int, int, bool> isSelected)

Parameters

settings ColorSettings

The color settings to create buttons for.

onPressed Action<int, int>

A function that returns the index of the color scheme, as well as the index of the color, that has been pressed.

isSelected Func<int, int, bool>

A function that determines whether the color scheme with the given index and the color with the given index are selected, which causes a rectangle to be drawn around it.

Returns

Group

A group of color selection areas with the given settings.

Draw(GameTime, SpriteBatch, bool)

This method is called every draw frame for the CurrentTool. By default, this method invokes OnDraw.

public virtual void Draw(GameTime time, SpriteBatch batch, bool cursorOnUi)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch used for drawing

cursorOnUi bool

Whether the cursor is currently covering the ui.

GetMouseCursor()

Returns the CursorType that this tool should currently display. By default, Default is returned.

public virtual CursorType GetMouseCursor()

Returns

CursorType

The cursor type

InitBuildModeUi(Panel, Panel)

Override this method to add custom content to the passed ui elements. By default, this method does nothing.

protected virtual void InitBuildModeUi(Panel content, Panel zoom)

Parameters

content Panel

The main content panel. Add custom BuildModeButton(string, GenericCallback, DrawCallback, float, TextureRegion, string, IEnumerable<string>, float?) instances here.

zoom Panel

The zoom panel that contains ColorSelection(ColorSettings, Action<int, int>, Func<int, int, bool>) and object previews

IsOnLot(Point)

Returns whether or not the passed position is on the currently edited lot (CurrentLot)

public static bool IsOnLot(Point pos)

Parameters

pos Point

The position to check

Returns

bool

Whether or not the position is on the current lot

OnButtonCreated(Button)

A method that is called when this tool's build mode button is created.

public virtual void OnButtonCreated(Button button)

Parameters

button Button

The button that was created.

Opened()

Called when this build tool is opened. By default, this method initializes several settings and calls InitBuildModeUi(Panel, Panel).

public virtual void Opened()

SelectFirstContentItem()

Causes the first content item in the BuildContent menu to be selected. If none is available, the world cursor will be selected instead if using a gamepad.

protected static void SelectFirstContentItem()

ShouldHighlightSelectedObject(object)

Whether or not the SelectedObject should currently have a white highlight around it. This method defaults to return true if IsCursorOnUi() is false.

public virtual bool ShouldHighlightSelectedObject(object obj)

Parameters

obj object

The selected object, which can be a MapObject or a WallLike.

Returns

bool

Whether or not the selected object should be highlighted

Update(GameTime, bool)

This method is called every update frame for the CurrentTool. By default, this method updates the MousePos and invokes OnUpdate, and also manages the UndoRedoStack.

public virtual void Update(GameTime time, bool cursorOnUi)

Parameters

time GameTime

The game's time

cursorOnUi bool

Whether the cursor is currently covering the ui.

Events

OnClosed

An event that is invoked when a Tool is Closed().

public static event Action<Tool> OnClosed

Event Type

Action<Tool>

OnDraw

An event that is invoked when a Tool is drawn in Draw(GameTime, SpriteBatch, bool). The bool passed contains whether the cursor is currently on the game's ui, using IsCursorOnUi().

public static event Action<Tool, GameTime, SpriteBatch, bool> OnDraw

Event Type

Action<Tool, GameTime, SpriteBatch, bool>

OnInitBuildModeUi

An event that is invoked when a Tool's InitBuildModeUi(Panel, Panel) method is called.

public static event Action<Tool, Panel, Panel> OnInitBuildModeUi

Event Type

Action<Tool, Panel, Panel>

OnOpened

An event that is invoked when a Tool is Opened().

public static event Action<Tool> OnOpened

Event Type

Action<Tool>

OnUpdate

An event that is invoked when a Tool is updated in Update(GameTime, bool). The bool passed contains whether the cursor is currently on the game's ui, using IsCursorOnUi().

public static event Action<Tool, GameTime, bool> OnUpdate

Event Type

Action<Tool, GameTime, bool>