Package VASSAL.counters
Class Stack
java.lang.Object
VASSAL.search.AbstractImageFinder
VASSAL.counters.Stack
- All Implemented Interfaces:
PropertySource
,GamePiece
,StateMergeable
,Auditable
,ImageSearchTarget
- Direct Known Subclasses:
Deck
A Stack is a collection of pieces in the same location that can often be moved with a single drag-and-drop.
Because it implements the
A standard Stack will only contain pieces that are "stackable" (i.e. doesn't have a "Does Not Stack"
GamePiece
interface, a Stack is formally a kind of GamePiece itself, which
can lead to confusion when the terms pieces, GamePieces, etc are used loosely/interchangeably. The kind of "pieces"
a Stack contains are the "regular" kind of pieces that have a BasicPiece
plus an optional group of
Decorator
traits.
A standard Stack will only contain pieces that are "stackable" (i.e. doesn't have a "Does Not Stack"
Immobilized
trait with stacking disabled, so that Properties.NO_STACK
is false) and share the same X/Y position on the same Map
, and all
stackable pieces on a Map
will always be part of some Stack -- even single stackable pieces will have
a Stack created to contain them. Stacks should contain only pieces from the same visual layer (see
LayeredPieceCollection
), but presently bad behaviors can still develop (e.g. a piece
uses a Dynamic Property to control its Game Piece Layer, and ends up changing layers without the Stack noticing) --
ideally we should straighten that out in future versions.
Deck
is a further extension of Stack which utilizes the piece-grouping code but overrides other aspects
(e.g. can allow pieces regardless of their "stackability", has different drag-and-drop behavior, etc) to create
a different kind of grouping.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a piece to the stack.void
SeeAbstractImageFinder
Tells each of the pieces in the stack to add its images to the collectionasList()
A list of the pieces in the stack.bottomPiece
(String playerId) void
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks.getId()
Each GamePiece must have a unique String identifierint
getLayer()
And the translated name for this pieceStacks themselves do not have any properties, so always return null.getMap()
int
Return the number of pieces that could possible be drawn in the stack, regardless of visibility to any particular playergetName()
The plain English name for this piecegetName
(boolean localized) Stacks cannot contain other stacks/decks, nor be contained in them, so parent is always null.Finds the piece "above" the one providedgetPieceAt
(int index) Finds the piece "underneath" the one providedint
Deprecated, for removal: This API element is subject to removal in a future version.Returns pieces in the order in which they are visible to the player -- topmost first In other words, selected pieces first, then unselected pieces from the top to the bottom.getProperty
(Object key) Stacks themselves do not have any properties, so always return null.getShape()
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks.StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks.getState()
Encodes the game state information of the stack into a stringgetType()
int
Finds the index of a piece in the stackvoid
Inserts a child GamePiece at a given index.void
insertChild
(GamePiece child, int index) Adds a GamePiece to this Stack.protected void
insertPieceAt
(GamePiece p, int index) Insert a piece at a particular point in the stackprotected void
insertPieceAt
(GamePiece p, int index, boolean suppressDeckCounts) Insert a piece at a particular point in the stackboolean
isEmpty()
boolean
Processes a key command for this stack, by sending it to the top visible piece in the stack.void
mergeState
(String newState, String oldState) Compute the difference betweennewState
andoldState
and apply that difference to the current stateint
nVisible()
Perform some action on a GamePiece that has just been added to this StackPerform some action on a GamePiece that has just been removed this Stackvoid
void
Marks the stack as emptyprotected void
removePieceAt
(int index) protected void
removePieceAt
(int index, boolean suppressDeckCounts) void
Finds and selects (in the UI) the next piece in the stack after this onestatic void
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks.void
setExpanded
(boolean b) Sets the expansion state of the stack.void
Each GamePiece must have a unique String identifiervoid
void
Required for interface but won't be needed for stacksvoid
setPosition
(Point p) void
setProperty
(Object key, Object val) Stacks themselves ignore property sets -- usesetPropertyOnContents(java.lang.Object,java.lang.Object)
to apply a property to the members of a stack.void
setPropertyOnContents
(Object key, Object val) Calls setProperty() on each piece in this stackvoid
Decodes the game state information of the stack from a stringtopPiece()
CAUTION: returns the top VISIBLE piece in the stack, or null if none is visible.toString()
Methods inherited from class VASSAL.search.AbstractImageFinder
addLocalImageNames, getAllImageNames, getLocalImageNames
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface VASSAL.script.expression.Auditable
getComponentName, getComponentTypeName
Methods inherited from interface VASSAL.counters.GamePiece
checkTrueMoved, finishMove, finishMove, prepareMove
-
Field Details
-
TYPE
- See Also:
-
HAS_LAYER_MARKER
- See Also:
-
LAYER_NOT_SET
public static final int LAYER_NOT_SET- See Also:
-
INCR
protected static final int INCR- See Also:
-
contents
-
pieceCount
protected int pieceCount -
map
-
pos
-
layer
protected int layer
-
-
Constructor Details
-
Stack
public Stack() -
Stack
Creates a Stack to contain a specific stackable piece.- Parameters:
p
- piece to make a stack for
-
-
Method Details
-
getPiecesIterator
-
getPieces
Deprecated, for removal: This API element is subject to removal in a future version.useasList()
- Returns:
- an Enumeration of the pieces in the stack, from the bottom up This is a clone of the contents so add/remove operations during read won't affect it.
-
asList
-
getPiecesReverseIterator
-
getPiecesInVisibleOrderIterator
-
getLayer
public int getLayer()- Returns:
- the visual layer we're bound to, or LAYER_NOT_SET if it we haven't been bound yet. Keeps the stack oriented to its correct Game Piece Layer - see
LayeredPieceCollection
-
remove
- Parameters:
p
- Piece to remove from the stack
-
isEmpty
public boolean isEmpty() -
removePieceAt
protected void removePieceAt(int index) - Parameters:
index
- Index of piece to remove from the stack
-
removePieceAt
protected void removePieceAt(int index, boolean suppressDeckCounts) - Parameters:
index
- Index of piece to remove from the stacksuppressDeckCounts
- true if this is should not update deck counts nor fire last-card-in-deck (ignored in a mere Stack)
-
pieceRemoved
-
insertPieceAt
Insert a piece at a particular point in the stack- Parameters:
p
- piece to insertindex
- place to insert it
-
insertPieceAt
Insert a piece at a particular point in the stack- Parameters:
p
- piece to insertindex
- place to insert itsuppressDeckCounts
- true if ONLY the Stack part of the operation should be performed (we're just rearranging deck order and so don't want extra property updates). Ignored at Stack level.
-
removeAll
public void removeAll()Marks the stack as empty -
indexOf
Finds the index of a piece in the stack- Parameters:
p
- Piece to locate- Returns:
- The index of the piece, or -1 if it is not present in the stack
-
getPieceAt
- Parameters:
index
- Index in the stack- Returns:
- the piece at the specified index
-
add
Adds a piece to the stack. If the piece already exists in the stack, moves it to the top- Parameters:
c
- Stack to add piece to
-
insertChild
Adds a GamePiece to this Stack. Slightly more efficient thaninsert(VASSAL.counters.GamePiece, int)
because it assumes the piece does not already belong to this Stack.- Parameters:
child
- GamePiece to insertindex
- Insert Index
-
getPieceCount
public int getPieceCount()- Returns:
- the number of pieces in the stack
-
getMaximumVisiblePieceCount
public int getMaximumVisiblePieceCount()Return the number of pieces that could possible be drawn in the stack, regardless of visibility to any particular player- Returns:
- Piece Count
-
insert
Inserts a child GamePiece at a given index. If the child piece already belongs to this Stack, it will be repositioned to the given index.- Parameters:
p
- GamePiece to insertpos
- Insert position
-
pieceAdded
-
draw
If theobs
parameter is aMap
, delegate drawing of this Stack to theStackMetrics
of that Map. Ifobs
is not a Map, use the default StackMetrics -
getName
- Parameters:
localized
- if true, use the localized names- Returns:
- a comma-separated list of the names of the pieces in this Stack
-
getName
-
getLocalizedName
Description copied from interface:GamePiece
And the translated name for this piece- Specified by:
getLocalizedName
in interfaceGamePiece
- Returns:
- a comma-separated list of the (localized) names of the pieces in this Stack
-
boundingBox
- Specified by:
boundingBox
in interfaceGamePiece
- Returns:
- bounding box for the stack (minimum rectangle to contain the bounding boxes of all the pieces inside)
-
getShape
-
selectNext
Finds and selects (in the UI) the next piece in the stack after this one- Parameters:
c
- Starting piece
-
getPieceBeneath
-
getPieceAbove
-
topPiece
CAUTION: returns the top VISIBLE piece in the stack, or null if none is visible.- Returns:
- the top visible piece in this stack
-
topPiece
-
bottomPiece
-
bottomPiece
- Returns:
- the bottom visible piece in this stack
-
nVisible
public int nVisible()- Returns:
- Number of GamePieces that are visible to me
-
keyEvent
-
isExpanded
public boolean isExpanded()- Returns:
- true if stack has been visually expanded by the player
-
setExpanded
public void setExpanded(boolean b) Sets the expansion state of the stack. Players can expand (and un-expand) stacks by e.g. double-clicking on them. Expanded stacks are generally shown with the pieces drawn further apart, the better to see the individual pieces. When a stack is expanded, drag-and-drop operations can affect an individual piece rather than only the whole group.- Parameters:
b
- true if stack should be expanded, false if not
-
getState
-
setState
-
mergeState
Compute the difference betweennewState
andoldState
and apply that difference to the current state- Specified by:
mergeState
in interfaceStateMergeable
- Parameters:
newState
- New StateoldState
- Old State
-
getType
-
setProperty
Stacks themselves ignore property sets -- usesetPropertyOnContents(java.lang.Object,java.lang.Object)
to apply a property to the members of a stack.- Specified by:
setProperty
in interfaceGamePiece
- Parameters:
key
- String key of property to be changedval
- Object containing new value of the property
-
toString
-
setPropertyOnContents
-
getProperty
Stacks themselves do not have any properties, so always return null.- Specified by:
getProperty
in interfaceGamePiece
- Specified by:
getProperty
in interfacePropertySource
- Parameters:
key
- String key of property to be returned- Returns:
- always null
-
getLocalizedProperty
Stacks themselves do not have any properties, so always return null.- Specified by:
getLocalizedProperty
in interfacePropertySource
- Parameters:
key
- String key of property to be returned- Returns:
- always null
-
setMap
-
getMap
-
getPosition
- Specified by:
getPosition
in interfaceGamePiece
- Returns:
- current X/Y position of stack
-
setPosition
- Specified by:
setPosition
in interfaceGamePiece
- Parameters:
p
- Sets the location of this stack on itsMap
-
getParent
-
setParent
-
getId
-
setId
-
setDefaultMetrics
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks. This method sets the default metrics for the module, but each map can have its own configuration, which can be found in the [Stacking options] subcomponent of the Map in the Editor.- Parameters:
s
- default stack metrics for the module
-
getStackMetrics
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks. This method retrieves the appropriate stack metrics to use for a given map- Parameters:
m
- a map- Returns:
- stack metrics for the map, if provided, or the default one for the module.
-
getStackMetrics
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks. This method retrieves the appropriate stack metrics to use the stack, based on its map- Returns:
- stack metrics for the map, if provided, or the default one for the module.
-
getDefaultMetrics
StackMetrics
encapsulate information on how to draw expanded/unexpanded views of stacks. This method retrieves the default stack metrics for the module.- Returns:
- default stack metrics for the module
-
addImageNamesRecursively
SeeAbstractImageFinder
Tells each of the pieces in the stack to add its images to the collection- Specified by:
addImageNamesRecursively
in interfaceImageSearchTarget
- Overrides:
addImageNamesRecursively
in classAbstractImageFinder
- Parameters:
s
- Collection to add image names to
-
asList()