Moving cards are not selectable; update card offsets when they reach the ends of their paths.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3500 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-04-18 21:02:20 +00:00
parent 967f99b60c
commit 8bb219bfed
@@ -778,21 +778,28 @@ public abstract class CardPanel extends VirtualMediaPanel
*/ */
protected boolean isSelectable (CardSprite sprite) protected boolean isSelectable (CardSprite sprite)
{ {
return _handSelectionMode != NONE && return _handSelectionMode != NONE && sprite.getPath() == null &&
(_handSelectionPredicate == null || (_handSelectionPredicate == null ||
_handSelectionPredicate.evaluate(sprite)); _handSelectionPredicate.evaluate(sprite));
} }
/** /**
* Determines whether the specified sprite is the only selectable sprite * Determines whether the specified sprite is the only selectable sprite
* in the hand. * in the hand according to the selection predicate.
*/ */
protected boolean isOnlySelectable (CardSprite sprite) protected boolean isOnlySelectable (CardSprite sprite)
{ {
// if there's no predicate, last remaining card is only selectable
if (_handSelectionPredicate == null) {
return _handSprites.size() == 1 && _handSprites.contains(sprite);
}
// otherwise, look for a sprite that fits the predicate and isn't the
// parameter
int size = _handSprites.size(); int size = _handSprites.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
CardSprite cs = (CardSprite)_handSprites.get(i); CardSprite cs = (CardSprite)_handSprites.get(i);
if (cs != sprite && isSelectable(cs)) { if (cs != sprite && _handSelectionPredicate.evaluate(cs)) {
return false; return false;
} }
} }
@@ -885,6 +892,10 @@ public abstract class CardPanel extends VirtualMediaPanel
/** The sprites for cards on the board. */ /** The sprites for cards on the board. */
protected ArrayList _boardSprites = new ArrayList(); protected ArrayList _boardSprites = new ArrayList();
/** The hand sprite observer instance. */
protected HandSpriteObserver _handSpriteObserver =
new HandSpriteObserver();
/** A path observer that removes the sprite at the end of its path. */ /** A path observer that removes the sprite at the end of its path. */
protected PathAdapter _pathEndRemover = new PathAdapter() { protected PathAdapter _pathEndRemover = new PathAdapter() {
public void pathCompleted (Sprite sprite, Path path, long when) { public void pathCompleted (Sprite sprite, Path path, long when) {
@@ -893,9 +904,17 @@ public abstract class CardPanel extends VirtualMediaPanel
}; };
/** Listens for interactions with cards in hand. */ /** Listens for interactions with cards in hand. */
protected CardSpriteObserver _handSpriteObserver = protected class HandSpriteObserver extends PathAdapter
new CardSpriteObserver() { implements CardSpriteObserver
public void cardSpriteClicked (CardSprite sprite, MouseEvent me) { {
public void pathCompleted (Sprite sprite, Path path, long when)
{
// update the offset
updateOffset((CardSprite)sprite);
}
public void cardSpriteClicked (CardSprite sprite, MouseEvent me)
{
// select, deselect, or play card in hand // select, deselect, or play card in hand
if (_selectedHandSprites.contains(sprite) && if (_selectedHandSprites.contains(sprite) &&
_handSelectionMode != NONE) { _handSelectionMode != NONE) {
@@ -911,22 +930,27 @@ public abstract class CardPanel extends VirtualMediaPanel
} }
} }
public void cardSpriteEntered (CardSprite sprite, MouseEvent me) { public void cardSpriteEntered (CardSprite sprite, MouseEvent me)
{
// update the offset // update the offset
updateOffset(sprite);
}
public void cardSpriteExited (CardSprite sprite, MouseEvent me)
{
// update the offset
updateOffset(sprite);
}
public void cardSpriteDragged (CardSprite sprite, MouseEvent me)
{}
protected void updateOffset (CardSprite sprite)
{
if (_handSprites.contains(sprite)) { if (_handSprites.contains(sprite)) {
sprite.setLocation(sprite.getX(), getHandY(sprite)); sprite.setLocation(sprite.getX(), getHandY(sprite));
} }
} }
public void cardSpriteExited (CardSprite sprite, MouseEvent me) {
// update the offset
if (_handSprites.contains(sprite)) {
sprite.setLocation(sprite.getX(), getHandY(sprite));
}
}
public void cardSpriteDragged (CardSprite sprite, MouseEvent me) {
}
}; };
/** Listens for mouse interactions with cards. */ /** Listens for mouse interactions with cards. */