ch.aplu.jgamegrid
Class ToolBarStack

java.lang.Object
  extended by ch.aplu.jgamegrid.Actor
      extended by ch.aplu.jgamegrid.ToolBarItem
          extended by ch.aplu.jgamegrid.ToolBarStack
All Implemented Interfaces:
GGActorCollisionListener, GGBorderListener, GGTileCollisionListener, java.util.EventListener

public class ToolBarStack
extends ToolBarItem

Class that represents a stack of items (e.g. card symbols with the same suit (in rank order). The stack is used to select a specific item by clicking through the stack.


Field Summary
 
Fields inherited from class ch.aplu.jgamegrid.Actor
gameGrid, nbCycles
 
Constructor Summary
ToolBarStack(java.lang.String filename, int nbItems)
          Creates a set of with given number of items taken from the given filename template.
 
Method Summary
 int getItemId()
          Returns the id of the item currently shown.
static int[] getSelectedItemIds()
          Returns an array with length equals to the number of stacks.
static ToolBarStack[] getSelectedStacks()
          Returns an array of all stacks that have the current item selected.
 boolean isSelected()
          Returns the state of the item currently shown.
 void setSelected(boolean b)
          Sets/deselects the item currently shown.
 void showNext()
          Shows the next item in the stack.
 
Methods inherited from class ch.aplu.jgamegrid.ToolBarItem
getFilename, getNumberOfSprites
 
Methods inherited from class ch.aplu.jgamegrid.Actor
act, addActorCollisionListener, addBorderListener, addCollisionActor, addCollisionActors, addCollisionActors, addCollisionTile, addCollisionTiles, addCollisionTiles, addMouseTouchListener, addMouseTouchListener, addTileCollisionListener, collide, collide, delay, displace, getBackground, getCollisionActors, getCollisionActorsInRange, getCollisionTiles, getCurrentImage, getDirection, getDirectionStart, getDisplacePosition, getHeight, getIdVisible, getImage, getImage, getIntDirection, getLocation, getLocationOffset, getLocationStart, getNbCycles, getNbHorzCells, getNbSprites, getNbVertCells, getNeighbours, getNeighbours, getNextMoveLocation, getPixelColor, getPixelLocation, getRotatedPosition, getRotationIndex, getScaledImage, getScaledImage, getScaledImage, getSlowDown, getWidth, getX, getXStart, getY, getYStart, hide, isActEnabled, isActorCollisionEnabled, isHorzMirror, isInGrid, isMoveValid, isNearBorder, isRemoved, isRotatable, isTileCollisionEnabled, isVertMirror, isVisible, move, move, nearBorder, removeSelf, reset, rotate, rotate, setActEnabled, setActorCollisionEnabled, setCollisionCircle, setCollisionCircle, setCollisionImage, setCollisionImage, setCollisionLine, setCollisionLine, setCollisionRectangle, setCollisionRectangle, setCollisionSpot, setCollisionSpot, setDirection, setDirection, setDisplacePosition, setHorzMirror, setLocation, setLocationOffset, setLocationOffset, setMouseTouchCircle, setMouseTouchCircle, setMouseTouchEnabled, setMouseTouchImage, setMouseTouchImage, setMouseTouchRectangle, setMouseTouchRectangle, setOnBottom, setOnTop, setPixelLocation, setSlowDown, setTileCollisionEnabled, setVertMirror, setX, setY, show, show, showNextSprite, showPreviousSprite, turn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolBarStack

public ToolBarStack(java.lang.String filename,
                    int nbItems)
Creates a set of with given number of items taken from the given filename template. A item stack is a single GameGrid actor with 2*nbItems sprite images.

E.g.if card symbols are used, the first series of images with id = 0..nbItems-1 corresponds to the cards in rank order, the second series of images with id = nbItems..2*nbItems-1 to the cards images representing the selected card (circumscribed rectangle, grayed, etc.).

The actual filename of the sprite images is the given filename template appended by _n with n from 0 to 2*nbItems-1. E.g. for nbItems = 3 and filename = "sprites/spades.gif" the image files are "sprites/spades_0.gif", "sprites/spades_1.gif", "sprites/spades_2.gif" for the normal images and "sprites/spades_3.gif", "sprites/spades_4.gif", "sprites/spades_5.gif" for the selected images.

Parameters:
filename - the filename template of the sprite images
nbItems - the number of ranks in this stack
Method Detail

isSelected

public boolean isSelected()
Returns the state of the item currently shown.

Returns:
true, if the item is in selected state; otherwise false

setSelected

public void setSelected(boolean b)
Sets/deselects the item currently shown.

Parameters:
b - if true, the item is selected; otherwise deselected

getItemId

public int getItemId()
Returns the id of the item currently shown.

Returns:
a number 0..nbItems-1 of the visible item (independent if selected or not)

showNext

public void showNext()
Shows the next item in the stack. The item state remains unchanged, if the current item is selected/deselected the next item is selected/deselected too.


getSelectedStacks

public static ToolBarStack[] getSelectedStacks()
Returns an array of all stacks that have the current item selected.

Returns:
an array of all stacks with the visible items in selected state; it no item is selected, the array has length zero (is not null)

getSelectedItemIds

public static int[] getSelectedItemIds()
Returns an array with length equals to the number of stacks. Each array element is the id of the selected item currently visible or -1, if the item currently visible is deselected.

Returns:
an array of integer holding the ids of the selected items; -1 if the visible item is not selected