Class Tool
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(string, TextureRegion, bool, Func<Options, Keybind>)
Creates a new tool with the given settings
public Tool(string name, TextureRegion texture, bool displayAsTab = false, Func<Options, Keybind> keybind = null)
Parameters
namestringThe name of this tool, which is used for localization, and should start with the mod's id.
textureTextureRegionThe texture of the tool icon
displayAsTabboolWheteher or not this tool should display as a tab. Defaults to false.
keybindFunc<Options, Keybind>
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
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
FurnitureTool
The FurnitureTool singleton.
public static readonly FurnitureTool FurnitureTool
Field Value
Keybind
public readonly Func<Options, Keybind> Keybind
Field Value
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
Name
The name of this tool, which is used for localization.
public readonly string Name
Field Value
PlayModeTool
The PlayModeTool singleton, which is activated when build mode is inactive.
public static readonly PlayModeTool PlayModeTool
Field Value
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
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
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
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
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
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
Money
The money that this household has, rounded by two digits after the decimal point
protected static float Money { get; set; }
Property Value
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
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
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
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
Methods
BuildModeButton(string, 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, string displayName, Element.GenericCallback onPressed, Element.DrawCallback onDrawn, float price, TextureRegion icon, string seenId = null, IEnumerable<string> description = null, float? customPrice = null)
Parameters
namestringThe internal name of the object displayed on this build mode button.
displayNamestringThe display name that should be displayed when hovering the button.
onPressedElement.GenericCallbackA fucntion that is called when the created button is pressed
onDrawnElement.DrawCallbackA function that is called when the created button is drawn
pricefloatThe price that should be displayed for this object
iconTextureRegionThe build mode category icon of this object
seenIdstringA 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.
descriptionIEnumerable<string>An optional set of text lines that will be inserted into the tooltip's description part
customPricefloat?The custom price that should be displayed (and used) instead of the
price. If this value is set, the regularpricewill be displayed as strikethrough
Returns
- Button
A new button with the passed settings
BuildModeButton(string, string, GenericCallback, DrawCallback, float, IEnumerable<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, string displayName, Element.GenericCallback onPressed, Element.DrawCallback onDrawn, float price, IEnumerable<TextureRegion> icons, string seenId = null, IEnumerable<string> description = null, float? customPrice = null)
Parameters
namestringThe internal name of the object displayed on this build mode button.
displayNamestringThe display name that should be displayed when hovering the button.
onPressedElement.GenericCallbackA fucntion that is called when the created button is pressed
onDrawnElement.DrawCallbackA function that is called when the created button is drawn
pricefloatThe price that should be displayed for this object
iconsIEnumerable<TextureRegion>The build mode category icons of this object
seenIdstringA 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.
descriptionIEnumerable<string>An optional set of text lines that will be inserted into the tooltip's description part
customPricefloat?The custom price that should be displayed (and used) instead of the
price. If this value is set, the regularpricewill 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(bool) currently, while this tool is selected
public virtual bool CanSwitchGameModes()
Returns
- bool
Whether the game can be mode switched right now
CanUndoRedo(bool)
Returns whether or not the UndoRedoStack can currently operate and thus, whether the Undo() or Redo() actions can be called.
public virtual bool CanUndoRedo(bool cursorOnUi)
Parameters
cursorOnUibool
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()
ClosedByOverride()
Called when this build tool is opened after being closed temporarily by the RemoveTool becoming active when a player holds CTRL. By default, this method does nothing.
public virtual void ClosedByOverride()
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
colorsColorSchemeThe color scheme to create buttons for
modifierColorA 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.
onPressedAction<int>A function that returns the index of the color that has been pressed
isSelectedFunc<int, bool>A function that determines whether the color with the given index is selected, which causes a rectangle to be drawn around it.
namestringThe 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>, LnCategory)
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>, LnCategory) 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, LnCategory previewLnCategory = LnCategory.BuildMode)
Parameters
settingsColorSettingsThe color settings to create buttons for.
onPressedAction<int, int>A function that returns the index of the color scheme, as well as the index of the color, that has been pressed.
isSelectedFunc<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.
previewLnCategoryLnCategoryThe localization category used for the preview names, if PreviewName is set.
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
timeGameTimeThe game's time
batchSpriteBatchThe sprite batch used for drawing
cursorOnUiboolWhether 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
contentPanelThe main content panel. Add custom BuildModeButton(string, string, GenericCallback, DrawCallback, float, IEnumerable<TextureRegion>, string, IEnumerable<string>, float?) instances here.
zoomPanelThe zoom panel that contains ColorSelection(ColorSettings, Action<int, int>, Func<int, int, bool>, LnCategory) 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
posPointThe 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
buttonButtonThe 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()
OpenedAfterOverride()
Called when this build tool is closed temporarily by the RemoveTool becoming active when a player holds CTRL. By default, this method does nothing.
public virtual void OpenedAfterOverride()
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 selected object 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
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
timeGameTimeThe game's time
cursorOnUiboolWhether the cursor is currently covering the ui.
Events
OnClosed
public static event Action<Tool> OnClosed
Event Type
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
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
OnOpened
public static event Action<Tool> OnOpened
Event Type
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