Added option to disable selection mode without updating offsets (to avoid playing a card more than once) and switched to checking the mouse location every frame in order to activate cards that moved themselves under the mouse cursor.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3522 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -174,15 +174,30 @@ 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 does not change the
|
||||
* current selection.
|
||||
* or SELECT_MULTIPLE) and updates the hand sprite offsets. Changing the
|
||||
* selection mode does not change the current selection.
|
||||
*/
|
||||
public void setHandSelectionMode (int mode)
|
||||
{
|
||||
setHandSelectionMode(mode, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selection mode for the hand (NONE, PLAY_SINGLE, SELECT_SINGLE,
|
||||
* or SELECT_MULTIPLE). Changing the selection mode does not change the
|
||||
* current selection.
|
||||
*
|
||||
* @param updateOffsets if true, immediately update the offsets of the
|
||||
* cards in the hand
|
||||
*/
|
||||
public void setHandSelectionMode (int mode, boolean updateOffsets)
|
||||
{
|
||||
_handSelectionMode = mode;
|
||||
|
||||
// update the offsets of all cards in the hand
|
||||
updateHandOffsets();
|
||||
if (updateOffsets) {
|
||||
updateHandOffsets();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -856,9 +871,57 @@ public abstract class CardPanel extends VirtualMediaPanel
|
||||
}
|
||||
}
|
||||
|
||||
// Documentation inherited.
|
||||
protected void didTick (long tickStamp)
|
||||
{
|
||||
super.didTick(tickStamp);
|
||||
|
||||
// update active card sprite
|
||||
updateActiveCardSprite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the active card sprite based on the location of the mouse
|
||||
* pointer.
|
||||
*/
|
||||
protected void updateActiveCardSprite ()
|
||||
{
|
||||
// can't do anything if we don't know where the mouse pointer is
|
||||
if (_mouseMotionEvent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite newHighestHit = _spritemgr.getHighestHitSprite(
|
||||
_mouseMotionEvent.getX(), _mouseMotionEvent.getY());
|
||||
|
||||
CardSprite newActiveCardSprite =
|
||||
(newHighestHit instanceof CardSprite ?
|
||||
(CardSprite)newHighestHit : null);
|
||||
|
||||
if (_activeCardSprite != newActiveCardSprite) {
|
||||
if (_activeCardSprite != null &&
|
||||
isManaged(_activeCardSprite)) {
|
||||
_activeCardSprite.queueNotification(
|
||||
new CardSpriteExitedOp(_activeCardSprite,
|
||||
_mouseMotionEvent)
|
||||
);
|
||||
}
|
||||
_activeCardSprite = newActiveCardSprite;
|
||||
if (_activeCardSprite != null) {
|
||||
_activeCardSprite.queueNotification(
|
||||
new CardSpriteEnteredOp(_activeCardSprite,
|
||||
_mouseMotionEvent)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The width of the playing cards. */
|
||||
protected int _cardWidth;
|
||||
|
||||
/** The last motion event received from the mouse. */
|
||||
protected MouseEvent _mouseMotionEvent;
|
||||
|
||||
/** The currently active card sprite (the one that the mouse is over). */
|
||||
protected CardSprite _activeCardSprite;
|
||||
|
||||
@@ -989,31 +1052,15 @@ public abstract class CardPanel extends VirtualMediaPanel
|
||||
|
||||
public void mouseMoved (MouseEvent me)
|
||||
{
|
||||
Sprite newHighestHit = _spritemgr.getHighestHitSprite(
|
||||
me.getX(), me.getY());
|
||||
|
||||
CardSprite newActiveCardSprite =
|
||||
(newHighestHit instanceof CardSprite ?
|
||||
(CardSprite)newHighestHit : null);
|
||||
_mouseMotionEvent = me;
|
||||
|
||||
if (_activeCardSprite != newActiveCardSprite) {
|
||||
if (_activeCardSprite != null &&
|
||||
isManaged(_activeCardSprite)) {
|
||||
_activeCardSprite.queueNotification(
|
||||
new CardSpriteExitedOp(_activeCardSprite, me)
|
||||
);
|
||||
}
|
||||
_activeCardSprite = newActiveCardSprite;
|
||||
if (_activeCardSprite != null) {
|
||||
_activeCardSprite.queueNotification(
|
||||
new CardSpriteEnteredOp(_activeCardSprite, me)
|
||||
);
|
||||
}
|
||||
}
|
||||
updateActiveCardSprite();
|
||||
}
|
||||
|
||||
public void mouseDragged (MouseEvent me)
|
||||
{
|
||||
_mouseMotionEvent = me;
|
||||
|
||||
if (_activeCardSprite != null &&
|
||||
isManaged(_activeCardSprite) &&
|
||||
_activeCardSprite.isDraggable()) {
|
||||
@@ -1024,7 +1071,7 @@ public abstract class CardPanel extends VirtualMediaPanel
|
||||
_hasBeenDragged = true;
|
||||
|
||||
} else {
|
||||
mouseMoved(me);
|
||||
updateActiveCardSprite();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user