Added updateBounds method to LabelSprite to allow changing the label, added methods to TrickCardGameUtil to get players left/right/opposite, changed the way CardPanel handles selections.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3481 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-04-13 21:09:32 +00:00
parent 4c3dd9b1af
commit 86959a5191
3 changed files with 64 additions and 38 deletions
@@ -30,8 +30,8 @@ import com.samskivert.swing.Label;
/**
* A sprite that uses a label to render itself. If the label has not been
* previously laid out (see {@link Label#layout}) it will be done when the
* sprite is added to a media panel. The label should not be altered
* after the sprite is created.
* sprite is added to a media panel. If the label is altered after the
* sprite is created, {@link #updateBounds} should be called.
*/
public class LabelSprite extends Sprite
{
@@ -60,6 +60,16 @@ public class LabelSprite extends Sprite
_antiAliased = antiAliased;
}
/**
* Updates the bounds of the sprite after a change to the label.
*/
public void updateBounds ()
{
Dimension size = _label.getSize();
_bounds.width = size.width;
_bounds.height = size.height;
}
// documentation inherited
protected void init ()
{
@@ -79,9 +89,7 @@ public class LabelSprite extends Sprite
}
// size the bounds to fit our label
Dimension size = _label.getSize();
_bounds.width = size.width;
_bounds.height = size.height;
updateBounds();
}
// documentation inherited
@@ -171,27 +171,13 @@ public abstract class CardPanel extends VirtualMediaPanel
/**
* Sets the selection mode for the hand (NONE, PLAY_SINGLE, SELECT_SINGLE,
* or SELECT_MULTIPLE). Changing the selection mode can change the
* current selection (clearing the selection, for example, if disabling
* selection mode).
* or SELECT_MULTIPLE). Changing the selection mode does not change the
* current selection.
*/
public void setHandSelectionMode (int mode)
{
if (_handSelectionMode == mode) {
return;
}
_handSelectionMode = mode;
// if entered non-selection or single-selection mode, deselect all
// or all but one card
if (mode != SELECT_MULTIPLE) {
CardSprite[] sprites = getSelectedHandSprites();
int begin = (mode == SELECT_SINGLE ? 1 : 0);
for (int i = begin; i < sprites.length; i++) {
deselectHandSprite(sprites[i]);
}
}
// update the offsets of all cards in the hand
updateHandOffsets();
}
@@ -426,7 +412,8 @@ public abstract class CardPanel extends VirtualMediaPanel
}
/**
* Flies a set of cards from the hand into the ether.
* Flies a set of cards from the hand into the ether. Clears any selected
* cards.
*
* @param cards the card sprites to remove from the hand
* @param dest the point to fly the cards to
@@ -440,10 +427,10 @@ public abstract class CardPanel extends VirtualMediaPanel
// fly each sprite over, removing it from the hand immediately and
// from the board when it finishes its path
for (int i = 0; i < cards.length; i++) {
removeFromHand(cards[i]);
LinePath flight = new LinePath(dest, flightDuration);
cards[i].addSpriteObserver(_pathEndRemover);
cards[i].moveAndFadeOut(flight, flightDuration, fadePortion);
removeFromHand(cards[i]);
}
// adjust the hand to cover the hole
@@ -451,7 +438,8 @@ public abstract class CardPanel extends VirtualMediaPanel
}
/**
* Flies a set of cards from the ether into the hand.
* Flies a set of cards from the ether into the hand. Clears any selected
* cards.
*
* @param cards the cards to add to the hand
* @param src the point to fly the cards from
@@ -546,7 +534,7 @@ public abstract class CardPanel extends VirtualMediaPanel
}
/**
* Flies a card from the hand onto the board.
* Flies a card from the hand onto the board. Clears any cards selected.
*
* @param card the sprite to remove from the hand
* @param dest the point to fly the card to
@@ -671,8 +659,8 @@ public abstract class CardPanel extends VirtualMediaPanel
/**
* Expands or collapses the hand to accommodate new cards or cover the
* space left by removed cards. Skips unmanaged sprites. Assumes that
* selection is disabled.
* space left by removed cards. Skips unmanaged sprites. Clears out
* any selected cards.
*
* @param adjustDuration the amount of time to spend settling the cards
* into their new locations
@@ -680,6 +668,9 @@ public abstract class CardPanel extends VirtualMediaPanel
*/
protected void adjustHand (long adjustDuration, boolean updateLayers)
{
// clear out selected cards
clearHandSelection();
// Sort the hand
QuickSort.sort(_handSprites);
@@ -887,7 +878,8 @@ public abstract class CardPanel extends VirtualMediaPanel
new CardSpriteObserver() {
public void cardSpriteClicked (CardSprite sprite, MouseEvent me) {
// select, deselect, or play card in hand
if (_selectedHandSprites.contains(sprite)) {
if (_selectedHandSprites.contains(sprite) &&
_handSelectionMode != NONE) {
deselectHandSprite(sprite);
} else if (_handSprites.contains(sprite) && isSelectable(sprite)) {
@@ -36,11 +36,11 @@ public class TrickCardGameUtil
* For four-player games with fixed partnerships, this returns the index
* of the player's team.
*
* @param plidx the player index
* @param pidx the player index
*/
public static int getTeamIndex (int plidx)
public static int getTeamIndex (int pidx)
{
return plidx / 2;
return pidx / 2;
}
/**
@@ -58,9 +58,9 @@ public class TrickCardGameUtil
* For four-player games with fixed partnerships, this returns the index
* of the player's partner.
*/
public static int getPartnerIndex (int plidx)
public static int getPartnerIndex (int pidx)
{
return plidx ^ 1;
return pidx ^ 1;
}
/**
@@ -76,16 +76,15 @@ public class TrickCardGameUtil
}
/**
* For four-player games with fixed partnerships, this returns the index
* of the player after the specified player going clockwise around the
* table.
* For four-player games, this returns the index of the player after the
* specified player going clockwise around the table.
*/
public static int getNextInClockwiseSequence (int plidx)
public static int getNextInClockwiseSequence (int pidx)
{
// 0
// 2 3
// 1
switch (plidx) {
switch (pidx) {
case 0: return 3;
case 1: return 2;
case 2: return 0;
@@ -107,6 +106,33 @@ public class TrickCardGameUtil
return RELATIVE_LOCATIONS[pidx1][pidx2];
}
/**
* For four-player games, returns the index of the player to the left of
* the specified player.
*/
public static int getLeftIndex (int pidx)
{
return getNextInClockwiseSequence(pidx);
}
/**
* For four-player games, returns the index of the player to the right of
* the specified player.
*/
public static int getRightIndex (int pidx)
{
return getNextInClockwiseSequence(pidx) ^ 1;
}
/**
* For four-player games, returns the index of the player across from the
* specified player.
*/
public static int getOppositeIndex (int pidx)
{
return pidx ^ 1;
}
/**
* Checks whether the player can follow the suit lead with the hand given.
*/