ensure card that last registered the cursor hover isn't tapped when the application loses focus via alt-tab and then is clicked on again

This commit is contained in:
myk
2013-02-19 09:34:45 +00:00
parent 567eee7cb6
commit 18985676b9
4 changed files with 15 additions and 24 deletions

View File

@@ -45,7 +45,7 @@ public class CCommand implements ICDoc {
private MouseMotionListener mmlCardOver = new MouseMotionAdapter() { @Override
public void mouseMoved(final MouseEvent e) {
cardoverAction(); } };
cardoverAction(e); } };
private final MouseListener madCardClick = new MouseAdapter() { @Override
public void mousePressed(final MouseEvent e) {
@@ -102,8 +102,8 @@ public class CCommand implements ICDoc {
}
/** */
private void cardoverAction() {
final Card c = CCommand.this.view.getTabletop().getCardFromMouseOverPanel();
private void cardoverAction(MouseEvent e) {
final Card c = CCommand.this.view.getTabletop().getHoveredCard(e);
if (c != null) {
CMatchUI.SINGLETON_INSTANCE.setCard(c);
}
@@ -114,7 +114,7 @@ public class CCommand implements ICDoc {
// original version:
// final Card c = t.getDetailController().getCurrentCard();
// Roujin's bug fix version dated 2-12-2012
final Card c = CCommand.this.view.getTabletop().getCardFromMouseOverPanel();
final Card c = CCommand.this.view.getTabletop().getHoveredCard(e);
if (c != null && c.isInZone(ZoneType.Command)) {
//TODO: Cast commander/activate avatar/roll planar dice here.

View File

@@ -29,7 +29,6 @@ import java.util.Observable;
import java.util.Observer;
import forge.Card;
import forge.Command;
import forge.Constant;
import forge.Constant.Preferences;
@@ -40,8 +39,8 @@ import forge.control.input.Input;
import forge.control.input.InputAttack;
import forge.control.input.InputBlock;
import forge.control.input.InputPayManaBase;
import forge.control.input.InputPayManaSimple;
import forge.control.input.InputPayManaExecuteCommands;
import forge.control.input.InputPayManaSimple;
import forge.control.input.InputPaySacCost;
import forge.game.GameState;
import forge.game.phase.CombatUtil;
@@ -73,7 +72,7 @@ public class CField implements ICDoc {
private MouseMotionListener mmlCardOver = new MouseMotionAdapter() { @Override
public void mouseMoved(final MouseEvent e) {
cardoverAction(); } };
cardoverAction(e); } };
private final MouseListener madHand = new MouseAdapter() { @Override
public void mousePressed(final MouseEvent e) {
@@ -382,8 +381,8 @@ public class CField implements ICDoc {
}
/** */
private void cardoverAction() {
final Card c = CField.this.view.getTabletop().getCardFromMouseOverPanel();
private void cardoverAction(MouseEvent e) {
final Card c = CField.this.view.getTabletop().getHoveredCard(e);
if (c != null) {
CMatchUI.SINGLETON_INSTANCE.setCard(c);
}
@@ -394,7 +393,7 @@ public class CField implements ICDoc {
// original version:
// final Card c = t.getDetailController().getCurrentCard();
// Roujin's bug fix version dated 2-12-2012
final Card c = CField.this.view.getTabletop().getCardFromMouseOverPanel();
final Card c = CField.this.view.getTabletop().getHoveredCard(e);
final Input input = CMessage.SINGLETON_INSTANCE.getInputControl().getInput();

View File

@@ -182,7 +182,7 @@ public class CHand implements ICDoc {
if (e.getButton() != MouseEvent.BUTTON1) {
return;
}
final Card c = view.getHandArea().getCardFromMouseOverPanel();
final Card c = view.getHandArea().getHoveredCard(e);
if (c != null) {
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c, Singletons.getControl().getPlayer().getZone(ZoneType.Hand));
}

View File

@@ -559,13 +559,6 @@ public abstract class CardPanelContainer extends JPanel {
}
}
/**
* @return {@link forge.view.arcane.CardPanel}
*/
public final CardPanel getMouseOverPanel() {
return this.hoveredPanel;
}
/**
* <p>
* getCardFromMouseOverPanel.
@@ -573,12 +566,11 @@ public abstract class CardPanelContainer extends JPanel {
*
* @return a {@link forge.Card} object.
*/
public final Card getCardFromMouseOverPanel() {
if (this.hoveredPanel != null) {
return this.hoveredPanel.getGameCard();
} else {
return null;
}
public final Card getHoveredCard(MouseEvent e) {
// re-evaluate cursor position so if we hovered over a card, alt-tabbed out of the application, then
// clicked back on the application somewhere else, the last hovered card won't register the click
CardPanel p = getCardPanel(e.getX(), e.getY());
return (p == null && p == hoveredPanel) ? null : p.getGameCard();
}
/**