com.threerings.puzzle.drop.client
Class DropBoardView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.threerings.media.MediaPanel
                  extended by com.threerings.media.VirtualMediaPanel
                      extended by com.threerings.puzzle.client.PuzzleBoardView
                          extended by com.threerings.puzzle.drop.client.DropBoardView
All Implemented Interfaces:
com.threerings.media.FrameParticipant, com.threerings.media.MediaConstants, com.threerings.media.MediaHost, DropPieceCodes, DirectionCodes, ImageObserver, MenuContainer, Serializable

public abstract class DropBoardView
extends PuzzleBoardView
implements DropPieceCodes

The drop board view displays a drop puzzle game in progress for a single player.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.media.MediaPanel
com.threerings.media.MediaPanel.ActionSpriteHandler, com.threerings.media.MediaPanel.Obscurer
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  int _bhei
          The board dimensions in pieces.
protected  int _bwid
          The board dimensions in pieces.
protected  DropBoard _dboard
          The drop board.
protected  boolean[] _moving
          Indicates whether a piece is en route to its destination.
protected  int _phei
          The piece dimensions in pixels.
protected  com.threerings.media.sprite.Sprite[] _pieces
          A sprite for every piece displayed in the drop board.
protected  int _pwid
          The piece dimensions in pixels.
protected  int _roff
          The board rising offset.
static Color CHAIN_COLOR
          The color used to render chain reward scoring text.
static Color SCORE_COLOR
          The color used to render normal scoring text.
 
Fields inherited from class com.threerings.puzzle.client.PuzzleBoardView
_actionAnimObs, _actionAnims, _actionSprites, _avoidArranger, _background, _board, _bounds, _ctx, _pauseLabel, _pctrl, _scoreDist, ACTION_CLEARED, ACTION_GOING, CLEAR_PENDING, DEBUG_ACTION, DEFAULT_SCORE_DISTANCE
 
Fields inherited from class com.threerings.media.VirtualMediaPanel
_abounds, _dx, _dy, _fmode, _fpath, _nx, _ny, _trackers, _vbounds, CENTER_ON_PATHABLE, ENCLOSE_PATHABLE, TRACK_PATHABLE
 
Fields inherited from class com.threerings.media.MediaPanel
_actionHandler, _actionSpriteCount, _animmgr, _metamgr, _obscurerList, _remgr, _spritemgr, _tickPaintPending
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.threerings.puzzle.drop.data.DropPieceCodes
DROP_BLOCK_PIECE_COUNT, PIECE_NONE
 
Fields inherited from interface com.threerings.util.DirectionCodes
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST
 
Fields inherited from interface com.threerings.media.MediaConstants
ALL, BACK, FRONT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DropBoardView(PuzzleContext ctx, int pwid, int phei)
          Constructs a drop board view.
 
Method Summary
protected  void centerRectInBoardRect(int bx, int by, int bwid, int bhei, int rwid, int rhei, Point pos)
          Populates pos with the most appropriate screen coordinates to center a rectangle of the given width and height (in pixels) within the specified rectangle (in board coordinates).
 void clearPiece(int xx, int yy)
          Clears out a piece from the board along with its piece sprite.
 void clearPieceSprite(int xx, int yy)
          Clears the specified piece from the board.
 void createPiece(int piece, int sx, int sy)
          Creates a new piece sprite and places it directly in its correct position.
 void createPiece(int piece, int sx, int sy, int tx, int ty, long duration)
          Creates a new piece sprite and moves it into position on the board.
 DropSprite createPieces(int col, int row, int[] pieces, int dist)
          Creates a new drop sprite used to animate the given pieces falling in the specified column.
protected  com.threerings.media.sprite.Sprite createPieceSprite(int piece, int px, int py)
          Creates the sprite that is used to display the specified piece.
 ScoreAnimation createScoreAnimation(String score, Color color, Font font)
          Creates and returns an animation showing the specified score floating up the view, with the label initially centered within the view.
 ScoreAnimation createScoreAnimation(String score, Color color, Font font, int x, int y, int width, int height)
          Creates and returns an animation showing the specified score floating up the view.
 void dirtySegment(int dir, int col, int row, int len)
          Dirties the rectangle encompassing the segment with the given direction and length whose bottom-leftmost corner is at (col, row).
 int getPieceHeight()
          Returns the height in pixels of a single board piece.
 com.threerings.media.image.Mirage getPieceImage(int piece)
          Returns the image used to display the given piece at coordinates (0, 0) with an orientation of DirectionCodes.NORTH.
abstract  com.threerings.media.image.Mirage getPieceImage(int piece, int col, int row, int orient)
          Returns the image used to display the given piece at the specified column and row with the given orientation.
 void getPiecePosition(int col, int row, Point pos)
          Called by the DropSprite to populate pos with the screen coordinates in pixels at which a piece at (col, row) in the board should be drawn.
 Dimension getPieceSegmentSize(int col, int row, int orient, int len)
          Called by the DropSprite to get the dimensions of the area that will be occupied by rendering a piece segment of the given orientation and length whose bottom-leftmost corner is at (col, row).
 com.threerings.media.sprite.Sprite getPieceSprite(int xx, int yy)
          Returns the piece sprite at the specified location.
 int getPieceWidth()
          Returns the width in pixels of a single board piece.
 Dimension getPreferredSize()
           
 boolean inBounds(int col, int row)
          Returns true if the specified coordinate is within the bounds of the board, false if it is not.
 void init(GameConfig config)
          Initializes the board with the board dimensions.
protected  boolean isMoving(int px, int py)
          Returns true if the piece that is supposed to be at the specified coordinates is not yet there but is actually en route to that location (due to a call to movePiece(Sprite,int,int,int,int,long)).
 com.threerings.media.sprite.Sprite movePiece(int sx, int sy, int tx, int ty, long duration)
          Instructs the view to move the piece at the specified starting position to the specified destination position.
protected  void movePiece(com.threerings.media.sprite.Sprite piece, int sx, int sy, int tx, int ty, long duration)
          A helper function for moving pieces into place.
 void paintBetween(Graphics2D gfx, Rectangle dirtyRect)
           
protected  void pieceArrived(long tickStamp, com.threerings.media.sprite.Sprite sprite, int px, int py)
          Called when a piece is finished moving into its requested position.
protected  void renderRisingPieces(Graphics2D gfx, Rectangle dirtyRect)
          Renders the row of rising pieces to the given graphics context.
 void rotateDropBlock(DropBlockSprite sprite, int orient)
          Rotates the given drop block sprite to the specified orientation, updating the image as necessary.
 void setBoard(Board board)
          Sets the board to be displayed.
protected  void setRiseOffset(int y)
          Sets the board rising offset to the given y-position.
 void updatePiece(int sx, int sy)
          Refreshes the piece sprite at the specified location, if no sprite exists at the location, one will be created.
 void updatePiece(int piece, int sx, int sy)
          Updates the piece sprite at the specified location, if no sprite exists at the location, one will be created.
 
Methods inherited from class com.threerings.puzzle.client.PuzzleBoardView
abortAnimation, addActionAnimation, addActionSprite, animationFinished, clearAnimations, clearSprites, createScoreAnimation, createScoreAnimation, dumpActors, getActionAnimationCount, getActionCount, getActionSpriteCount, maybeFireCleared, paintBehind, paintInFront, removeSprite, renderBackground, renderBoard, setBackgroundImage, setController, setPaused, trackAvoidAnimation
 
Methods inherited from class com.threerings.media.VirtualMediaPanel
addObscurerDirtyRegion, addViewTracker, adjustBoundsCenter, clearPathable, constrainToBounds, didTick, dirtyScreenRect, doLayout, findRootBounds, getViewBounds, paint, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeViewTracker, setBackground, setBounds, setFollowsPathable, setViewLocation, trackPathable, viewLocationDidChange
 
Methods inherited from class com.threerings.media.MediaPanel
addAnimation, addObscurer, addObscurerDirtyRegions, addSprite, clipToDirtyRegion, createActionSpriteHandler, createGraphics, getAnimationManager, getComponent, getRegionManager, getSpriteManager, getTimeStamp, isManaged, isManaged, needsPaint, paint, paintBits, paintDirtyRect, removeObscurer, repaint, setOpaque, tick, willTick
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCORE_COLOR

public static final Color SCORE_COLOR
The color used to render normal scoring text.


CHAIN_COLOR

public static final Color CHAIN_COLOR
The color used to render chain reward scoring text.


_dboard

protected DropBoard _dboard
The drop board.


_pieces

protected com.threerings.media.sprite.Sprite[] _pieces
A sprite for every piece displayed in the drop board.


_moving

protected boolean[] _moving
Indicates whether a piece is en route to its destination.


_pwid

protected int _pwid
The piece dimensions in pixels.


_phei

protected int _phei
The piece dimensions in pixels.


_roff

protected int _roff
The board rising offset.


_bwid

protected int _bwid
The board dimensions in pieces.


_bhei

protected int _bhei
The board dimensions in pieces.

Constructor Detail

DropBoardView

public DropBoardView(PuzzleContext ctx,
                     int pwid,
                     int phei)
Constructs a drop board view.

Method Detail

init

public void init(GameConfig config)
Initializes the board with the board dimensions.

Overrides:
init in class PuzzleBoardView

getPieceWidth

public int getPieceWidth()
Returns the width in pixels of a single board piece.


getPieceHeight

public int getPieceHeight()
Returns the height in pixels of a single board piece.


getPiecePosition

public void getPiecePosition(int col,
                             int row,
                             Point pos)
Called by the DropSprite to populate pos with the screen coordinates in pixels at which a piece at (col, row) in the board should be drawn. Derived classes may wish to override this method to allow specialized positioning of sprites.


getPieceSegmentSize

public Dimension getPieceSegmentSize(int col,
                                     int row,
                                     int orient,
                                     int len)
Called by the DropSprite to get the dimensions of the area that will be occupied by rendering a piece segment of the given orientation and length whose bottom-leftmost corner is at (col, row).


createPiece

public void createPiece(int piece,
                        int sx,
                        int sy)
Creates a new piece sprite and places it directly in its correct position.


updatePiece

public void updatePiece(int sx,
                        int sy)
Refreshes the piece sprite at the specified location, if no sprite exists at the location, one will be created. Note: this method assumes the default ImageSprite is being used to display pieces. If createPieceSprite(int, int, int) is overridden to return a non-ImageSprite, this method must also be customized.


updatePiece

public void updatePiece(int piece,
                        int sx,
                        int sy)
Updates the piece sprite at the specified location, if no sprite exists at the location, one will be created. Note: this method assumes the default ImageSprite is being used to display pieces. If createPieceSprite(int, int, int) is overridden to return a non-ImageSprite, this method must also be customized.


createPiece

public void createPiece(int piece,
                        int sx,
                        int sy,
                        int tx,
                        int ty,
                        long duration)
Creates a new piece sprite and moves it into position on the board.


movePiece

public com.threerings.media.sprite.Sprite movePiece(int sx,
                                                    int sy,
                                                    int tx,
                                                    int ty,
                                                    long duration)
Instructs the view to move the piece at the specified starting position to the specified destination position. There must be a sprite at the starting position, if there is a sprite at the destination position, it must also be moved immediately following this call (as in the case of a swap) to avoid badness.

Returns:
the piece sprite that is being moved.

movePiece

protected void movePiece(com.threerings.media.sprite.Sprite piece,
                         int sx,
                         int sy,
                         int tx,
                         int ty,
                         long duration)
A helper function for moving pieces into place.


pieceArrived

protected void pieceArrived(long tickStamp,
                            com.threerings.media.sprite.Sprite sprite,
                            int px,
                            int py)
Called when a piece is finished moving into its requested position. Derived classes may wish to take this opportunity to play a sound or whatnot.


isMoving

protected boolean isMoving(int px,
                           int py)
Returns true if the piece that is supposed to be at the specified coordinates is not yet there but is actually en route to that location (due to a call to movePiece(Sprite,int,int,int,int,long)).


getPieceImage

public com.threerings.media.image.Mirage getPieceImage(int piece)
Returns the image used to display the given piece at coordinates (0, 0) with an orientation of DirectionCodes.NORTH. This serves as a convenience routine for those puzzles that don't bother rendering their pieces differently when placed at different board coordinates or in different orientations.


getPieceImage

public abstract com.threerings.media.image.Mirage getPieceImage(int piece,
                                                                int col,
                                                                int row,
                                                                int orient)
Returns the image used to display the given piece at the specified column and row with the given orientation.


setBoard

public void setBoard(Board board)
Description copied from class: PuzzleBoardView
Sets the board to be displayed.

Overrides:
setBoard in class PuzzleBoardView

getPieceSprite

public com.threerings.media.sprite.Sprite getPieceSprite(int xx,
                                                         int yy)
Returns the piece sprite at the specified location.


clearPieceSprite

public void clearPieceSprite(int xx,
                             int yy)
Clears the specified piece from the board.


clearPiece

public void clearPiece(int xx,
                       int yy)
Clears out a piece from the board along with its piece sprite.


createPieces

public DropSprite createPieces(int col,
                               int row,
                               int[] pieces,
                               int dist)
Creates a new drop sprite used to animate the given pieces falling in the specified column.


dirtySegment

public void dirtySegment(int dir,
                         int col,
                         int row,
                         int len)
Dirties the rectangle encompassing the segment with the given direction and length whose bottom-leftmost corner is at (col, row).


createScoreAnimation

public ScoreAnimation createScoreAnimation(String score,
                                           Color color,
                                           Font font)
Creates and returns an animation showing the specified score floating up the view, with the label initially centered within the view.

Parameters:
score - the score text to display.
color - the color of the text.
font - the font.

createScoreAnimation

public ScoreAnimation createScoreAnimation(String score,
                                           Color color,
                                           Font font,
                                           int x,
                                           int y,
                                           int width,
                                           int height)
Creates and returns an animation showing the specified score floating up the view.

Parameters:
score - the score text to display.
color - the color of the text.
font - the font to use.
x - the left coordinate in board coordinates of the rectangle within which the score is to be centered.
y - the bottom coordinate in board coordinates of the rectangle within which the score is to be centered.
width - the width in board coordinates of the rectangle within which the score is to be centered.
height - the height in board coordinates of the rectangle within which the score is to be centered.

createPieceSprite

protected com.threerings.media.sprite.Sprite createPieceSprite(int piece,
                                                               int px,
                                                               int py)
Creates the sprite that is used to display the specified piece. If the piece represents no piece, this method should return null.


centerRectInBoardRect

protected void centerRectInBoardRect(int bx,
                                     int by,
                                     int bwid,
                                     int bhei,
                                     int rwid,
                                     int rhei,
                                     Point pos)
Populates pos with the most appropriate screen coordinates to center a rectangle of the given width and height (in pixels) within the specified rectangle (in board coordinates).

Parameters:
bx - the bounding rectangle's left board coordinate.
by - the bounding rectangle's bottom board coordinate.
bwid - the bounding rectangle's width in board coordinates.
bhei - the bounding rectangle's height in board coordinates.
rwid - the width of the rectangle to position in pixels.
rhei - the height of the rectangle to position in pixels.
pos - the point to populate with the rectangle's final position.

rotateDropBlock

public void rotateDropBlock(DropBlockSprite sprite,
                            int orient)
Rotates the given drop block sprite to the specified orientation, updating the image as necessary. Derived classes that make use of block dropping functionality should override this method to do the right thing.


paintBetween

public void paintBetween(Graphics2D gfx,
                         Rectangle dirtyRect)
Overrides:
paintBetween in class PuzzleBoardView

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

inBounds

public boolean inBounds(int col,
                        int row)
Returns true if the specified coordinate is within the bounds of the board, false if it is not.


renderRisingPieces

protected void renderRisingPieces(Graphics2D gfx,
                                  Rectangle dirtyRect)
Renders the row of rising pieces to the given graphics context. Sub-classes that make use of board rising functionality should override this method to draw the rising piece row.


setRiseOffset

protected void setRiseOffset(int y)
Sets the board rising offset to the given y-position.