Package VASSAL.counters
Class Stack
java.lang.Object
VASSAL.counters.Stack
- All Implemented Interfaces:
PropertySource
,GamePiece
,StateMergeable
- Direct Known Subclasses:
Deck
public class Stack extends Object implements GamePiece, StateMergeable
A collection of GamePieces which can be moved as a single unit
-
Field Summary
Fields Modifier and Type Field Description protected GamePiece[]
contents
static String
HAS_LAYER_MARKER
protected static int
INCR
protected int
layer
static int
LAYER_NOT_SET
protected Map
map
protected int
pieceCount
protected Point
pos
static String
TYPE
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
add(GamePiece c)
Adds a piece to the stack.List<GamePiece>
asList()
GamePiece
bottomPiece()
GamePiece
bottomPiece(String playerId)
Rectangle
boundingBox()
The area which this GamePiece occupies when drawn at the point (0,0)void
draw(Graphics g, int x, int y, Component obs, double zoom)
StackMetrics
getDefaultMetrics()
String
getId()
Each GamePiece must have a unique String identifierint
getLayer()
String
getLocalizedName()
And the translated name for this pieceObject
getLocalizedProperty(Object key)
Map
getMap()
int
getMaximumVisiblePieceCount()
Return the number of pieces that could possible be drawn in the stack, regardless of visibility to any particular playerString
getName()
The plain English name for this pieceString
getName(boolean localized)
Return a comma-separated list of the names of the pieces in this StackStack
getParent()
GamePiece
getPieceAbove(GamePiece p)
GamePiece
getPieceAt(int index)
GamePiece
getPieceBeneath(GamePiece p)
int
getPieceCount()
Enumeration<GamePiece>
getPieces()
Deprecated, for removal: This API element is subject to removal in a future version.Enumeration<GamePiece>
getPiecesInReverseOrder()
Deprecated, for removal: This API element is subject to removal in a future version.Enumeration<GamePiece>
getPiecesInVisibleOrder()
Deprecated, for removal: This API element is subject to removal in a future version.Iterator<GamePiece>
getPiecesInVisibleOrderIterator()
Iterator<GamePiece>
getPiecesIterator()
Iterator<GamePiece>
getPiecesReverseIterator()
Point
getPosition()
Object
getProperty(Object key)
Shape
getShape()
The shape of the piece from the user's viewpoint.StackMetrics
getStackMetrics()
StackMetrics
getStackMetrics(Map m)
String
getState()
The state information is information that can change during the course of a game.String
getType()
The type information is information that does not change during the course of a game.int
indexOf(GamePiece p)
void
insert(GamePiece p, int pos)
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)
boolean
isExpanded()
Command
keyEvent(KeyStroke stroke)
Keyboard events are forward to this method when a piece is selected The GamePiece can respond in any way it likesvoid
mergeState(String newState, String oldState)
Compute the difference betweennewState
andoldState
and appy that difference to the current stateprotected int
nVisible()
Command
pieceAdded(GamePiece p)
Perform some action on a GamePiece that has just been added to this StackCommand
pieceRemoved(GamePiece p)
Perform some action on a GamePiece that has just been removed this Stackvoid
remove(GamePiece p)
void
removeAll()
protected void
removePieceAt(int index)
void
selectNext(GamePiece c)
static void
setDefaultMetrics(StackMetrics s)
void
setExpanded(boolean b)
void
setId(String id)
void
setMap(Map map)
Each GamePiece belongs to a singleMap
void
setParent(Stack s)
void
setPosition(Point p)
void
setProperty(Object key, Object val)
Other properties, possibly game-specific, can be associated with a piece.void
setPropertyOnContents(Object key, Object val)
Calls setProperty() on each piece in this stackvoid
setState(String s)
GamePiece
topPiece()
GamePiece
topPiece(String playerId)
String
toString()
-
Field Details
-
TYPE
- See Also:
- Constant Field Values
-
HAS_LAYER_MARKER
- See Also:
- Constant Field Values
-
LAYER_NOT_SET
public static final int LAYER_NOT_SET- See Also:
- Constant Field Values
-
INCR
protected static final int INCR- See Also:
- Constant Field Values
-
contents
-
pieceCount
protected int pieceCount -
layer
protected int layer -
pos
-
map
-
-
Constructor Details
-
Stack
public Stack() -
Stack
-
-
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
-
getPiecesInReverseOrder
@Deprecated(since="2020-08-06", forRemoval=true) public Enumeration<GamePiece> getPiecesInReverseOrder()Deprecated, for removal: This API element is subject to removal in a future version.Return an enumeration of the pieces in the start, from the top down- Returns:
- Reverse order Enumerator
-
getPiecesInVisibleOrderIterator
-
getPiecesInVisibleOrder
@Deprecated(since="2020-08-06", forRemoval=true) public Enumeration<GamePiece> getPiecesInVisibleOrder()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. -
getLayer
public int getLayer()- Returns:
- the layer we're bound to, or LAYER_NOT_SET if it we haven't been bound yet
-
remove
-
removePieceAt
protected void removePieceAt(int index) -
pieceRemoved
Perform some action on a GamePiece that has just been removed this Stack- Parameters:
p
- GamePiece- Returns:
- a
Command
that performs the equivalent action when executed
-
insertPieceAt
-
removeAll
public void removeAll() -
indexOf
-
getPieceAt
-
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() -
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
Perform some action on a GamePiece that has just been added to this Stack- Parameters:
p
- Game Piece- Returns:
- a
Command
that performs the equivalent action when executed
-
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- Specified by:
draw
in interfaceGamePiece
x
- x-location of the center of the piecey
- y-location of the center of the pieceobs
- the Component on which this piece is being drawnzoom
- the scaling factor.- See Also:
StackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double)
,getDefaultMetrics()
-
getName
Return a comma-separated list of the names of the pieces in this Stack -
getName
Description copied from interface:GamePiece
The plain English name for this piece -
getLocalizedName
Description copied from interface:GamePiece
And the translated name for this piece- Specified by:
getLocalizedName
in interfaceGamePiece
-
boundingBox
Description copied from interface:GamePiece
The area which this GamePiece occupies when drawn at the point (0,0)- Specified by:
boundingBox
in interfaceGamePiece
-
getShape
Description copied from interface:GamePiece
The shape of the piece from the user's viewpoint. This defines the area in which the user must click to select or move the piece, for example. LikeGamePiece.boundingBox()
, it assumes the position is (0,0) and must be translated to the actual location where the piece is being drawn. -
selectNext
-
getPieceBeneath
-
getPieceAbove
-
topPiece
- Returns:
- the top visible piece in this stack
-
topPiece
- Parameters:
playerId
- Player Id to check- Returns:
- the top piece in this stack that is visible to the player with the given id
- See Also:
GameModule.getUserId()
-
bottomPiece
- Parameters:
playerId
- Player Id to Check- Returns:
- the bottom piece in this stack that is visible to the player with the given id
- See Also:
GameModule.getUserId()
-
bottomPiece
- Returns:
- the bottom visible piece in this stack
-
nVisible
protected int nVisible()- Returns:
- Number of GamePieces that are visible to me
-
keyEvent
Description copied from interface:GamePiece
Keyboard events are forward to this method when a piece is selected The GamePiece can respond in any way it likes- Specified by:
keyEvent
in interfaceGamePiece
- Returns:
- a
Command
that, when executed, will invoke the same response. Usually aChangePiece
command. - See Also:
ForwardToKeyBuffer
-
isExpanded
public boolean isExpanded() -
setExpanded
public void setExpanded(boolean b) -
getState
Description copied from interface:GamePiece
The state information is information that can change during the course of a game. State information is saved when the game is saved and is transferred between players on the server. For example, the relative order of pieces in a stack is state information, but whether the stack is expanded is not -
setState
-
mergeState
Compute the difference betweennewState
andoldState
and appy that difference to the current state- Specified by:
mergeState
in interfaceStateMergeable
- Parameters:
newState
- New StateoldState
- Old State
-
getType
Description copied from interface:GamePiece
The type information is information that does not change during the course of a game. Image file names, popup menu command names, etc., all should be reflected in the type.- Specified by:
getType
in interfaceGamePiece
- See Also:
BasicCommandEncoder
-
setProperty
Description copied from interface:GamePiece
Other properties, possibly game-specific, can be associated with a piece. The properties may or may not need to be encoded in the piece'sGamePiece.getState()
method.- Specified by:
setProperty
in interfaceGamePiece
-
toString
-
setPropertyOnContents
Calls setProperty() on each piece in this stack- Parameters:
key
- Property Keyval
- Property Value
-
getProperty
- Specified by:
getProperty
in interfaceGamePiece
- Specified by:
getProperty
in interfacePropertySource
-
getLocalizedProperty
- Specified by:
getLocalizedProperty
in interfacePropertySource
-
setMap
Description copied from interface:GamePiece
Each GamePiece belongs to a singleMap
-
getMap
-
getPosition
- Specified by:
getPosition
in interfaceGamePiece
- Returns:
- the location of this piece on its owning
Map
-
setPosition
- Specified by:
setPosition
in interfaceGamePiece
-
getParent
-
setParent
-
getId
Description copied from interface:GamePiece
Each GamePiece must have a unique String identifier- Specified by:
getId
in interfaceGamePiece
- See Also:
GameState.getNewPieceId()
-
setId
-
setDefaultMetrics
-
getStackMetrics
-
getStackMetrics
-
getDefaultMetrics
-
asList()