Skip to content

Class ViewMenu

Definition

Namespace: StardewUI
Assembly: StardewUI.dll

Generic menu implementation based on a root IView.

public class ViewMenu : StardewValley.Menus.IClickableMenu, System.IDisposable

Inheritance
Object ⇦ IClickableMenu ⇦ ViewMenu

Implements
IDisposable

Members

Constructors

Name Description
ViewMenu(Edges, Boolean) Initializes a new instance of ViewMenu.

Fields

Name Description
_childMenu (Inherited from IClickableMenu)
_dependencies (Inherited from IClickableMenu)
_parentMenu (Inherited from IClickableMenu)
allClickableComponents (Inherited from IClickableMenu)
behaviorBeforeCleanup (Inherited from IClickableMenu)
closeSound (Inherited from IClickableMenu)
currentlySnappedComponent (Inherited from IClickableMenu)
destroy (Inherited from IClickableMenu)
exitFunction (Inherited from IClickableMenu)
height (Inherited from IClickableMenu)
upperRightCloseButton (Inherited from IClickableMenu)
width (Inherited from IClickableMenu)
xPositionOnScreen (Inherited from IClickableMenu)
yPositionOnScreen (Inherited from IClickableMenu)

Properties

Name Description
CloseButtonOffset Offset from the menu view's top-right edge to draw the close button, if a CloseButtonSprite is also specified.
CloseButtonSprite The sprite to draw for the close button shown on the upper right. If no value is specified, then no close button will be drawn. The default behavior is to not show any close button.
CloseOnOutsideClick Whether to automatically close the menu when a mouse click is detected outside the bounds of the menu and any floating elements.
CursorAttachment Additional cursor to draw below or adjacent to the normal mouse cursor.
DimmingAmount Amount of dimming between 0 and 1; i.e. opacity of the background underlay.
Gutter Gets or sets the menu's gutter edges, which constrain the portion of the viewport in which any part of the menu may be drawn.
Position (Inherited from IClickableMenu)
TooltipsEnabled Whether to display tooltips on mouse hover.
View The view to display with this menu.

Methods

Name Description
_ShouldAutoSnapPrioritizeAlignedElements() (Inherited from IClickableMenu)
actionOnRegionChange(Int32, Int32) (Inherited from IClickableMenu)
AddDependency() (Inherited from IClickableMenu)
applyMovementKey(Int32) Initiates a focus search in the specified direction.
(Overrides IClickableMenu.applyMovementKey(Int32))
applyMovementKey(Keys) (Inherited from IClickableMenu)
areGamePadControlsImplemented() Returns whether or not the menu wants exclusive gamepad controls.
(Overrides IClickableMenu.areGamePadControlsImplemented())
automaticSnapBehavior(Int32, Int32, Int32) (Inherited from IClickableMenu)
BuildTooltip(IEnumerable<ViewChild>) Builds/formats a tooltip given the sequence of views from root to the lowest-level hovered child.
cleanupBeforeExit() (Inherited from IClickableMenu)
clickAway() (Inherited from IClickableMenu)
Close() Closes this menu, either by removing it from the parent if it is a child menu, or removing it as the game's active menu if it is standalone.
CreateView() Creates the view.
CustomClose() When overridden in a derived class, provides an alternative method to close the menu instead of the default logic in exitThisMenu(Boolean).
customSnapBehavior(Int32, Int32, Int32) (Inherited from IClickableMenu)
Dispose()
draw(SpriteBatch) Draws the current menu content.
(Overrides IClickableMenu.draw(SpriteBatch))
draw(SpriteBatch, Int32, Int32, Int32) (Inherited from IClickableMenu)
drawBackground(SpriteBatch) (Inherited from IClickableMenu)
drawBorderLabel(SpriteBatch, string, SpriteFont, Int32, Int32) (Inherited from IClickableMenu)
drawHorizontalPartition(SpriteBatch, Int32, Boolean, Int32, Int32, Int32) (Inherited from IClickableMenu)
drawMouse(SpriteBatch, Boolean, Int32) (Inherited from IClickableMenu)
drawVerticalIntersectingPartition(SpriteBatch, Int32, Int32, Int32, Int32, Int32) (Inherited from IClickableMenu)
drawVerticalPartition(SpriteBatch, Int32, Boolean, Int32, Int32, Int32, Int32) (Inherited from IClickableMenu)
drawVerticalUpperIntersectingPartition(SpriteBatch, Int32, Int32, Int32, Int32, Int32) (Inherited from IClickableMenu)
emergencyShutDown() (Inherited from IClickableMenu)
exitThisMenu(Boolean) (Inherited from IClickableMenu)
exitThisMenuNoSound() (Inherited from IClickableMenu)
gamePadButtonHeld(Buttons) Invoked on every frame during which a controller button is down, once for each held button.
(Overrides IClickableMenu.gamePadButtonHeld(Buttons))
gameWindowSizeChanged(Rectangle, Rectangle) (Inherited from IClickableMenu)
GetChildMenu() (Inherited from IClickableMenu)
GetCloseBehavior() Gets the current close behavior for the menu.
getComponentWithID(Int32) (Inherited from IClickableMenu)
getCurrentlySnappedComponent() (Inherited from IClickableMenu)
GetOriginPosition(Point, Point) Computes the origin (top left) position of the menu for a given viewport and offset.
GetParentMenu() (Inherited from IClickableMenu)
HasDependencies() (Inherited from IClickableMenu)
initialize(Int32, Int32, Int32, Int32, Boolean) (Inherited from IClickableMenu)
initializeUpperRightCloseButton() (Inherited from IClickableMenu)
IsActive() (Inherited from IClickableMenu)
IsAutomaticSnapValid(Int32, ClickableComponent, ClickableComponent) (Inherited from IClickableMenu)
isWithinBounds(Int32, Int32) (Inherited from IClickableMenu)
leftClickHeld(Int32, Int32) Invoked on every frame in which a mouse button is down, regardless of the state in the previous frame.
(Overrides IClickableMenu.leftClickHeld(Int32, Int32))
moveCursorInDirection(Int32) (Inherited from IClickableMenu)
noSnappedComponentFound(Int32, Int32, Int32) (Inherited from IClickableMenu)
OnClosed(EventArgs) Invokes the Closed event handler.
Open(MenuActivationMode) Opens this menu, i.e. makes it active if it is not already active.
overrideSnappyMenuCursorMovementBan() (Inherited from IClickableMenu)
performHoverAction(Int32, Int32) Invoked on every frame with the mouse's current coordinates.
(Overrides IClickableMenu.performHoverAction(Int32, Int32))
populateClickableComponentList() (Overrides IClickableMenu.populateClickableComponentList())
readyToClose() Checks if the menu is allowed to be closed by the game's default input handling.
(Overrides IClickableMenu.readyToClose())
receiveGamePadButton(Buttons) Invoked whenever a controller button is newly pressed.
(Overrides IClickableMenu.receiveGamePadButton(Buttons))
receiveKeyPress(Keys) Invoked whenever a keyboard key is newly pressed.
(Overrides IClickableMenu.receiveKeyPress(Keys))
receiveLeftClick(Int32, Int32, Boolean) Invoked whenever the left mouse button is newly pressed.
(Overrides IClickableMenu.receiveLeftClick(Int32, Int32, Boolean))
receiveRightClick(Int32, Int32, Boolean) Invoked whenever the right mouse button is newly pressed.
(Overrides IClickableMenu.receiveRightClick(Int32, Int32, Boolean))
receiveScrollWheelAction(Int32) Invoked whenever the mouse wheel is used. Only works with vertical scrolls.
(Overrides IClickableMenu.receiveScrollWheelAction(Int32))
releaseLeftClick(Int32, Int32) Invoked whenever the left mouse button is just released, after being pressed/held on the last frame.
(Overrides IClickableMenu.releaseLeftClick(Int32, Int32))
RemoveDependency() (Inherited from IClickableMenu)
SetChildMenu(IClickableMenu) (Inherited from IClickableMenu)
setCurrentlySnappedComponentTo(Int32) (Inherited from IClickableMenu)
setUpForGamePadMode() (Inherited from IClickableMenu)
shouldClampGamePadCursor() (Inherited from IClickableMenu)
shouldDrawCloseButton() Returns whether or not to draw a button on the upper right that closes the menu when clicked.
(Overrides IClickableMenu.shouldDrawCloseButton())
showWithoutTransparencyIfOptionIsSet() (Inherited from IClickableMenu)
snapCursorToCurrentSnappedComponent() (Inherited from IClickableMenu)
snapToDefaultClickableComponent() (Inherited from IClickableMenu)
update(GameTime) Runs on every update tick.
(Overrides IClickableMenu.update(GameTime))

Events

Name Description
Closed Event raised when the menu is closed.

Details

Constructors

ViewMenu(Edges, bool)

Initializes a new instance of ViewMenu.

public ViewMenu(StardewUI.Layout.Edges gutter, bool forceDefaultFocus);
Parameters

gutter   Edges
Gutter edges, in which no content should be drawn. Used for overscan, or general aesthetics.

forceDefaultFocus   Boolean
Whether to always focus (snap the cursor to) the default element, even if the menu was triggered by keyboard/mouse.


Properties

CloseButtonOffset

Offset from the menu view's top-right edge to draw the close button, if a CloseButtonSprite is also specified.

public Microsoft.Xna.Framework.Vector2 CloseButtonOffset { get; set; }
Property Value

Vector2


CloseButtonSprite

The sprite to draw for the close button shown on the upper right. If no value is specified, then no close button will be drawn. The default behavior is to not show any close button.

public StardewUI.Graphics.Sprite CloseButtonSprite { get; set; }
Property Value

Sprite


CloseOnOutsideClick

Whether to automatically close the menu when a mouse click is detected outside the bounds of the menu and any floating elements.

public bool CloseOnOutsideClick { get; set; }
Property Value

Boolean

Remarks

This setting is primarily intended for submenus and makes them behave more like overlays.


CursorAttachment

Additional cursor to draw below or adjacent to the normal mouse cursor.

public StardewUI.Graphics.Cursor CursorAttachment { get; set; }
Property Value

Cursor


DimmingAmount

Amount of dimming between 0 and 1; i.e. opacity of the background underlay.

public float DimmingAmount { get; set; }
Property Value

Single

Remarks

Underlay is only drawn when game options do not force clear backgrounds.


Gutter

Gets or sets the menu's gutter edges, which constrain the portion of the viewport in which any part of the menu may be drawn.

protected StardewUI.Layout.Edges Gutter { get; set; }
Property Value

Edges

Remarks

Gutters effectively shrink the viewport for both measurement (size calculation) and layout (centering) by clipping the screen edges.


TooltipsEnabled

Whether to display tooltips on mouse hover.

public bool TooltipsEnabled { get; set; }
Property Value

Boolean

Remarks

Tooltips should normally always be left enabled; one reason to disable them would be if a CursorAttachment is set that would overlap.


View

The view to display with this menu.

public StardewUI.IView View { get; }
Property Value

IView


Methods

applyMovementKey(int)

Initiates a focus search in the specified direction.

public override void applyMovementKey(int directionValue);
Parameters

directionValue   Int32
An integer value corresponding to the direction; one of 0 (up), 1 (right), 2 (down) or 3 (left).


areGamePadControlsImplemented()

Returns whether or not the menu wants exclusive gamepad controls.

public override bool areGamePadControlsImplemented();
Returns

Boolean

Always false.

Remarks

This implementation always returns false. Contrary to what the name in Stardew's code implies, this setting is not required for receiveGamePadButton(Buttons) to work; instead, when enabled, it suppresses the game's default mapping of button presses to clicks, and would therefore require reimplementing key-repeat and other basic behaviors. There is no reason to enable it here.


BuildTooltip(IEnumerable<ViewChild>)

Builds/formats a tooltip given the sequence of views from root to the lowest-level hovered child.

protected virtual StardewUI.Data.TooltipData BuildTooltip(System.Collections.Generic.IEnumerable<StardewUI.ViewChild> path);
Parameters

path   IEnumerable<ViewChild>
Sequence of all elements, and their relative positions, that the mouse coordinates are currently within.

Returns

TooltipData

The tooltip string to display, or null to not show any tooltip.

Remarks

The default implementation reads the value of the last (lowest-level) view with a non-null Tooltip, and breaks Text and Title lines longer than 640px, which is the default vanilla tooltip width.


Close()

Closes this menu, either by removing it from the parent if it is a child menu, or removing it as the game's active menu if it is standalone.

public void Close();

CreateView()

Creates the view.

protected virtual StardewUI.IView CreateView();
Returns

IView

The created view.

Remarks

Subclasses will generally create an entire tree in this method and store references to any views that might require content updates.


CustomClose()

When overridden in a derived class, provides an alternative method to close the menu instead of the default logic in exitThisMenu(Boolean).

protected virtual void CustomClose();
Remarks

The method will only be called when the menu is closed (either programmatically or via the UI) while GetCloseBehavior() is returning Custom.


Dispose()

public void Dispose();

draw(SpriteBatch)

Draws the current menu content.

public override void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch b);
Parameters

b   SpriteBatch
The target batch.


gamePadButtonHeld(Buttons)

Invoked on every frame during which a controller button is down, once for each held button.

public override void gamePadButtonHeld(Microsoft.Xna.Framework.Input.Buttons b);
Parameters

b   Buttons
The button that is down.


GetCloseBehavior()

Gets the current close behavior for the menu.

protected virtual StardewUI.MenuCloseBehavior GetCloseBehavior();
Returns

MenuCloseBehavior

Remarks

The default implementation always returns Default. Subclasses may override this in order to use CustomClose(), or disable closure entirely.


GetOriginPosition(Point, Point)

Computes the origin (top left) position of the menu for a given viewport and offset.

protected virtual Microsoft.Xna.Framework.Point GetOriginPosition(Microsoft.Xna.Framework.Point viewportSize, Microsoft.Xna.Framework.Point gutterOffset);
Parameters

viewportSize   Point
The available size of the viewport in which the menu is to be displayed.

gutterOffset   Point
The offset implied by any asymmetrical Gutter setting; for example, a gutter whose Left edge is 100 px and whose Right edge is only 50 px would have an X offset of 25 px (half the difference, because centered).

Returns

Point

The origin (top left) position for the menu's root view.


leftClickHeld(int, int)

Invoked on every frame in which a mouse button is down, regardless of the state in the previous frame.

public override void leftClickHeld(int x, int y);
Parameters

x   Int32
The mouse's current X position on screen.

y   Int32
The mouse's current Y position on screen.


OnClosed(EventArgs)

Invokes the Closed event handler.

protected virtual void OnClosed(System.EventArgs e);
Parameters

e   EventArgs
The event arguments.


Open(MenuActivationMode)

Opens this menu, i.e. makes it active if it is not already active.

public void Open(StardewUI.MenuActivationMode activationMode);
Parameters

activationMode   MenuActivationMode
The activation behavior which determines which (if any) other active menu this one can replace. Ignored when the game's title menu is open.


performHoverAction(int, int)

Invoked on every frame with the mouse's current coordinates.

public override void performHoverAction(int x, int y);
Parameters

x   Int32
The mouse's current X position on screen.

y   Int32
The mouse's current Y position on screen.

Remarks

Essentially the same as update(GameTime) but slightly more convenient for mouse hover/movement effects because of the arguments provided.


populateClickableComponentList()

public override void populateClickableComponentList();
Remarks

Always a no-op for menus in StardewUI.


readyToClose()

Checks if the menu is allowed to be closed by the game's default input handling.

public override bool readyToClose();
Returns

Boolean


receiveGamePadButton(Buttons)

Invoked whenever a controller button is newly pressed.

public override void receiveGamePadButton(Microsoft.Xna.Framework.Input.Buttons b);
Parameters

b   Buttons
The button that was pressed.


receiveKeyPress(Keys)

Invoked whenever a keyboard key is newly pressed.

public override void receiveKeyPress(Microsoft.Xna.Framework.Input.Keys key);
Parameters

key   Keys
The key that was pressed.


receiveLeftClick(int, int, bool)

Invoked whenever the left mouse button is newly pressed.

public override void receiveLeftClick(int x, int y, bool playSound);
Parameters

x   Int32
The mouse's current X position on screen.

y   Int32
The mouse's current Y position on screen.

playSound   Boolean
Currently not used.


receiveRightClick(int, int, bool)

Invoked whenever the right mouse button is newly pressed.

public override void receiveRightClick(int x, int y, bool playSound);
Parameters

x   Int32
The mouse's current X position on screen.

y   Int32
The mouse's current Y position on screen.

playSound   Boolean
Currently not used.


receiveScrollWheelAction(int)

Invoked whenever the mouse wheel is used. Only works with vertical scrolls.

public override void receiveScrollWheelAction(int value);
Parameters

value   Int32
A value indicating the desired vertical scroll direction; negative values indicate "down" and positive values indicate "up".


releaseLeftClick(int, int)

Invoked whenever the left mouse button is just released, after being pressed/held on the last frame.

public override void releaseLeftClick(int x, int y);
Parameters

x   Int32
The mouse's current X position on screen.

y   Int32
The mouse's current Y position on screen.


shouldDrawCloseButton()

Returns whether or not to draw a button on the upper right that closes the menu when clicked.

public override bool shouldDrawCloseButton();
Returns

Boolean

Remarks

Regardless of this value, a close button will never be drawn unless CloseButtonSprite is set.


update(GameTime)

Runs on every update tick.

public override void update(Microsoft.Xna.Framework.GameTime time);
Parameters

time   GameTime
The current GameTime including the time elapsed since last update tick.


Events

Closed

Event raised when the menu is closed.

public event EventHandler<System.EventArgs>? Closed;
Event Type

EventHandler<EventArgs>