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[]contentsstatic StringHAS_LAYER_MARKERprotected static intINCRprotected intlayerstatic intLAYER_NOT_SETprotected Mapmapprotected intpieceCountprotected Pointposstatic StringTYPE -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidadd(GamePiece c)Adds a piece to the stack.List<GamePiece>asList()GamePiecebottomPiece()GamePiecebottomPiece(String playerId)RectangleboundingBox()The area which this GamePiece occupies when drawn at the point (0,0)voiddraw(Graphics g, int x, int y, Component obs, double zoom)StackMetricsgetDefaultMetrics()StringgetId()Each GamePiece must have a unique String identifierintgetLayer()StringgetLocalizedName()And the translated name for this pieceObjectgetLocalizedProperty(Object key)MapgetMap()intgetMaximumVisiblePieceCount()Return the number of pieces that could possible be drawn in the stack, regardless of visibility to any particular playerStringgetName()The plain English name for this pieceStringgetName(boolean localized)Return a comma-separated list of the names of the pieces in this StackStackgetParent()GamePiecegetPieceAbove(GamePiece p)GamePiecegetPieceAt(int index)GamePiecegetPieceBeneath(GamePiece p)intgetPieceCount()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()PointgetPosition()ObjectgetProperty(Object key)ShapegetShape()The shape of the piece from the user's viewpoint.StackMetricsgetStackMetrics()StackMetricsgetStackMetrics(Map m)StringgetState()The state information is information that can change during the course of a game.StringgetType()The type information is information that does not change during the course of a game.intindexOf(GamePiece p)voidinsert(GamePiece p, int pos)Inserts a child GamePiece at a given index.voidinsertChild(GamePiece child, int index)Adds a GamePiece to this Stack.protected voidinsertPieceAt(GamePiece p, int index)booleanisExpanded()CommandkeyEvent(KeyStroke stroke)Keyboard events are forward to this method when a piece is selected The GamePiece can respond in any way it likesvoidmergeState(String newState, String oldState)Compute the difference betweennewStateandoldStateand appy that difference to the current stateprotected intnVisible()CommandpieceAdded(GamePiece p)Perform some action on a GamePiece that has just been added to this StackCommandpieceRemoved(GamePiece p)Perform some action on a GamePiece that has just been removed this Stackvoidremove(GamePiece p)voidremoveAll()protected voidremovePieceAt(int index)voidselectNext(GamePiece c)static voidsetDefaultMetrics(StackMetrics s)voidsetExpanded(boolean b)voidsetId(String id)voidsetMap(Map map)Each GamePiece belongs to a singleMapvoidsetParent(Stack s)voidsetPosition(Point p)voidsetProperty(Object key, Object val)Other properties, possibly game-specific, can be associated with a piece.voidsetPropertyOnContents(Object key, Object val)Calls setProperty() on each piece in this stackvoidsetState(String s)GamePiecetopPiece()GamePiecetopPiece(String playerId)StringtoString()
-
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
Commandthat 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
Commandthat performs the equivalent action when executed
-
draw
If theobsparameter is aMap, delegate drawing of this Stack to theStackMetricsof that Map. Ifobsis not a Map, use the default StackMetrics- Specified by:
drawin interfaceGamePiecex- 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:GamePieceThe plain English name for this piece -
getLocalizedName
Description copied from interface:GamePieceAnd the translated name for this piece- Specified by:
getLocalizedNamein interfaceGamePiece
-
boundingBox
Description copied from interface:GamePieceThe area which this GamePiece occupies when drawn at the point (0,0)- Specified by:
boundingBoxin interfaceGamePiece
-
getShape
Description copied from interface:GamePieceThe 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:GamePieceKeyboard events are forward to this method when a piece is selected The GamePiece can respond in any way it likes- Specified by:
keyEventin interfaceGamePiece- Returns:
- a
Commandthat, when executed, will invoke the same response. Usually aChangePiececommand. - See Also:
ForwardToKeyBuffer
-
isExpanded
public boolean isExpanded() -
setExpanded
public void setExpanded(boolean b) -
getState
Description copied from interface:GamePieceThe 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 betweennewStateandoldStateand appy that difference to the current state- Specified by:
mergeStatein interfaceStateMergeable- Parameters:
newState- New StateoldState- Old State
-
getType
Description copied from interface:GamePieceThe 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:
getTypein interfaceGamePiece- See Also:
BasicCommandEncoder
-
setProperty
Description copied from interface:GamePieceOther 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:
setPropertyin interfaceGamePiece
-
toString
-
setPropertyOnContents
Calls setProperty() on each piece in this stack- Parameters:
key- Property Keyval- Property Value
-
getProperty
- Specified by:
getPropertyin interfaceGamePiece- Specified by:
getPropertyin interfacePropertySource
-
getLocalizedProperty
- Specified by:
getLocalizedPropertyin interfacePropertySource
-
setMap
Description copied from interface:GamePieceEach GamePiece belongs to a singleMap -
getMap
-
getPosition
- Specified by:
getPositionin interfaceGamePiece- Returns:
- the location of this piece on its owning
Map
-
setPosition
- Specified by:
setPositionin interfaceGamePiece
-
getParent
-
setParent
-
getId
Description copied from interface:GamePieceEach GamePiece must have a unique String identifier- Specified by:
getIdin interfaceGamePiece- See Also:
GameState.getNewPieceId()
-
setId
-
setDefaultMetrics
-
getStackMetrics
-
getStackMetrics
-
getDefaultMetrics
-
asList()