Skip to content

Class SpriteMapBuilder<T>

Definition

Namespace: StardewUI.Graphics
Assembly: StardewUI.dll

Builder interface for a SpriteMap<T> using a single texture source.

public class SpriteMapBuilder<T>

Type Parameters

T
Type of key for which to obtain sprites.

Inheritance
Object ⇦ SpriteMapBuilder<T>

Remarks

Works by maintaining a virtual "cursor" which can be moved to capture the next sprite, and adding either one sprite at a time with a specific size, or several with the same size, wrapping around when necessary.

Members

Constructors

Name Description
SpriteMapBuilder<T>(Texture2D) Builder interface for a SpriteMap<T> using a single texture source.

Methods

Name Description
Add(T, Int32?, Int32?) Adds a single sprite.
Add(T, Rectangle) Adds a sprite using its specific position and size in the texture.
Add(IEnumerable<T>) Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element.
Add(T) Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element.
Build() Builds a new SpriteMap<T> from the registered sprites.
Default(T) Configures the default sprite for unknown keys to use an existing sprite that has already been registered.
Default(Sprite) Configures the default sprite for unknown keys to use a custom sprite.
MoveBy(Int32, Int32) Moves the current cursor position by a specified offset.
MoveBy(Point) Moves the current cursor position by a specified offset.
MoveTo(Int32, Int32) Moves the cursor to a specific coordinate.
MoveTo(Point) Moves the cursor to a specific coordinate.
Padding(Int32, Int32) Configures the padding between sprites.
Padding(Point) Configures the padding between sprites.
Size(Int32, Int32) Configures the pixel size per sprite.
Size(Point) Configures the pixel size per sprite.

Details

Constructors

SpriteMapBuilder<T>(Texture2D)

Builder interface for a SpriteMap<T> using a single texture source.

public SpriteMapBuilder<T>(Microsoft.Xna.Framework.Graphics.Texture2D texture);
Parameters

texture   Texture2D

Remarks

Works by maintaining a virtual "cursor" which can be moved to capture the next sprite, and adding either one sprite at a time with a specific size, or several with the same size, wrapping around when necessary.


Methods

Add(T, int?, int?)

Adds a single sprite.

public StardewUI.Graphics.SpriteMapBuilder<T> Add(T key, int? width, int? height);
Parameters

key   T
The key for the sprite.

width   Nullable<Int32>
Optional override width, otherwise the most recent Size(Int32, Int32) will be used. Custom widths only apply to this sprite and will not affect the size of any subsequent additions.

height   Nullable<Int32>
Optional override height, otherwise the most recent Size(Int32, Int32) will be used. Custom heights only apply to this sprite and will not affect the size of any subsequent additions.

Returns

SpriteMapBuilder<T>

The current builder instance.


Add(T, Rectangle)

Adds a sprite using its specific position and size in the texture.

public StardewUI.Graphics.SpriteMapBuilder<T> Add(T key, Microsoft.Xna.Framework.Rectangle sourceRect);
Parameters

key   T
The key for the sprite.

sourceRect   Rectangle
The exact position and size of the sprite.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

After adding, moves the cursor to the top-right of the sourceRect, unless it would be horizontally out of bounds, in which case it wraps to the beginning (X = 0) of the next row.


Add(IEnumerable<T>)

Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element.

public StardewUI.Graphics.SpriteMapBuilder<T> Add(System.Collections.Generic.IEnumerable<T> keys);
Parameters

keys   IEnumerable<T>
The keys for the sprites to add, in the same left-to-right order that they appear in the source texture.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Wraps to the beginning of the next row (X = 0) when the end of a row is reached.


Add(T)

Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element.

public StardewUI.Graphics.SpriteMapBuilder<T> Add(T keys);
Parameters

keys   T
The keys for the sprites to add, in the same left-to-right order that they appear in the source texture.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Wraps to the beginning of the next row (X = 0) when the end of a row is reached.


Build()

Builds a new SpriteMap<T> from the registered sprites.

public StardewUI.Graphics.SpriteMap<T> Build();
Returns

SpriteMap<T>


Default(T)

Configures the default sprite for unknown keys to use an existing sprite that has already been registered.

public StardewUI.Graphics.SpriteMapBuilder<T> Default(T key);
Parameters

key   T
Key of the previously-added sprite to use as default.

Returns

SpriteMapBuilder<T>

The current builder instance.


Default(Sprite)

Configures the default sprite for unknown keys to use a custom sprite.

public StardewUI.Graphics.SpriteMapBuilder<T> Default(StardewUI.Graphics.Sprite sprite);
Parameters

sprite   Sprite
The sprite to use as default.

Returns

SpriteMapBuilder<T>

The current builder instance.


MoveBy(int, int)

Moves the current cursor position by a specified offset.

public StardewUI.Graphics.SpriteMapBuilder<T> MoveBy(int x, int y);
Parameters

x   Int32
Horizontal offset from current position.

y   Int32
Vertical offset from current position.

Returns

SpriteMapBuilder<T>

The current builder instance.


MoveBy(Point)

Moves the current cursor position by a specified offset.

public StardewUI.Graphics.SpriteMapBuilder<T> MoveBy(Microsoft.Xna.Framework.Point p);
Parameters

p   Point
The horizontal (X) and vertical (Y) offsets from the current position.

Returns

SpriteMapBuilder<T>

The current builder instance.


MoveTo(int, int)

Moves the cursor to a specific coordinate.

public StardewUI.Graphics.SpriteMapBuilder<T> MoveTo(int x, int y);
Parameters

x   Int32
The new X coordinate of the cursor.

y   Int32
The new Y coordinate of the cursor.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Generally used when dealing with semi-regular spritesheets having distinct areas that are individually uniform but different from each other, e.g. a row of 10x10 placed in an empty area of a 32x32 sheet.


MoveTo(Point)

Moves the cursor to a specific coordinate.

public StardewUI.Graphics.SpriteMapBuilder<T> MoveTo(Microsoft.Xna.Framework.Point p);
Parameters

p   Point
The horizontal (X) and vertical (Y) coordinates for the cursor.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Generally used when dealing with semi-regular spritesheets having distinct areas that are individually uniform but different from each other, e.g. a row of 10x10 placed in an empty area of a 32x32 sheet.


Padding(int, int)

Configures the padding between sprites.

public StardewUI.Graphics.SpriteMapBuilder<T> Padding(int x, int y);
Parameters

x   Int32
Horizontal padding from the right edge of one sprite to the left edge of the next. Added whenever advancing from left to right.

y   Int32
Vertical padding from the bottom edge of one sprite to the top edge of the next. Added whenever wrapping from the end of a row to the beginning of the next row.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Applies only to new sprites added afterward; will not affect sprites previously added.


Padding(Point)

Configures the padding between sprites.

public StardewUI.Graphics.SpriteMapBuilder<T> Padding(Microsoft.Xna.Framework.Point p);
Parameters

p   Point
A point containing the horizontal (X) and vertical (Y) padding values. See Padding(Int32, Int32).

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Applies only to new sprites added afterward; will not affect sprites previously added.


Size(int, int)

Configures the pixel size per sprite.

public StardewUI.Graphics.SpriteMapBuilder<T> Size(int width, int height);
Parameters

width   Int32
The pixel width for newly-added sprites.

height   Int32
The pixel height for newly-added sprites.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Applies only to new sprites added afterward; will not affect sprites previously added.


Size(Point)

Configures the pixel size per sprite.

public StardewUI.Graphics.SpriteMapBuilder<T> Size(Microsoft.Xna.Framework.Point p);
Parameters

p   Point
A point containing the width (X) and height (Y) for newly-added sprites.

Returns

SpriteMapBuilder<T>

The current builder instance.

Remarks

Applies only to new sprites added afterward; will not affect sprites previously added.