mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Fixed double listener bug in field.
This commit is contained in:
@@ -100,9 +100,6 @@ public class ControlMatchUI {
|
|||||||
AllZone.getInputControl().updateObservers();
|
AllZone.getInputControl().updateObservers();
|
||||||
this.view.getTabberController().updateObservers();
|
this.view.getTabberController().updateObservers();
|
||||||
this.mapKeyboardShortcuts();
|
this.mapKeyboardShortcuts();
|
||||||
|
|
||||||
// This line is probably not necessary. Doublestrike 8-12-11
|
|
||||||
//((GuiTopLevel) AllZone.getDisplay()).getController().changeState(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ public class ControlField {
|
|||||||
private final Player player;
|
private final Player player;
|
||||||
private final ViewField view;
|
private final ViewField view;
|
||||||
|
|
||||||
|
private MouseMotionAdapter maCardOver;
|
||||||
|
private MouseAdapter maAvatar, maLibrary, maHand, maExiled, maGraveyard, maFlashback, maCardClick;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child controller, applied to single field in battlefield. Manages player
|
* Child controller, applied to single field in battlefield. Manages player
|
||||||
* view functions such as card observers, life total changes, graveyard
|
* view functions such as card observers, life total changes, graveyard
|
||||||
@@ -83,6 +86,8 @@ public class ControlField {
|
|||||||
public ControlField(final Player p, final ViewField v) {
|
public ControlField(final Player p, final ViewField v) {
|
||||||
this.player = p;
|
this.player = p;
|
||||||
this.view = v;
|
this.view = v;
|
||||||
|
|
||||||
|
initMouseAdapters();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,81 +169,16 @@ public class ControlField {
|
|||||||
this.addZoneListeners();
|
this.addZoneListeners();
|
||||||
|
|
||||||
// Battlefield card clicks
|
// Battlefield card clicks
|
||||||
this.view.getTabletop().addMouseListener(new MouseAdapter() {
|
this.view.getTabletop().removeMouseListener(maCardClick);
|
||||||
@Override
|
this.view.getTabletop().addMouseListener(maCardClick);
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
|
||||||
final Card c = t.getDetailController().getCurrentCard();
|
|
||||||
final Input input = t.getInputController().getInputControl().getInput();
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
if (c.isTapped()
|
|
||||||
&& ((input instanceof InputPayManaCost) || (input instanceof InputPayManaCostAbility))) {
|
|
||||||
final arcane.ui.CardPanel cardPanel = ControlField.this.view.getTabletop().getCardPanel(
|
|
||||||
c.getUniqueNumber());
|
|
||||||
for (final arcane.ui.CardPanel cp : cardPanel.getAttachedPanels()) {
|
|
||||||
if (cp.getCard().isUntapped()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final CardList att = new CardList(AllZone.getCombat().getAttackers());
|
|
||||||
if ((c.isTapped() || c.hasSickness() || ((c.hasKeyword("Vigilance")) && att.contains(c)))
|
|
||||||
&& (input instanceof InputAttack)) {
|
|
||||||
final arcane.ui.CardPanel cardPanel = ControlField.this.view.getTabletop().getCardPanel(
|
|
||||||
c.getUniqueNumber());
|
|
||||||
for (final arcane.ui.CardPanel cp : cardPanel.getAttachedPanels()) {
|
|
||||||
if (cp.getCard().isUntapped() && !cp.getCard().hasSickness()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.isMetaDown()) {
|
|
||||||
if (att.contains(c) && (input instanceof InputAttack)
|
|
||||||
&& !c.hasKeyword("CARDNAME attacks each turn if able.")) {
|
|
||||||
c.untap();
|
|
||||||
AllZone.getCombat().removeFromCombat(c);
|
|
||||||
} else if (input instanceof InputBlock) {
|
|
||||||
if (c.getController().isHuman()) {
|
|
||||||
AllZone.getCombat().removeFromCombat(c);
|
|
||||||
}
|
|
||||||
((InputBlock) input).removeFromAllBlocking(c);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.getInputController().getInputControl()
|
|
||||||
.selectCard(c, AllZone.getHumanPlayer().getZone(Zone.Battlefield));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Battlefield card mouseover
|
// Battlefield card mouseover
|
||||||
this.view.getTabletop().addMouseMotionListener(new MouseMotionAdapter() {
|
this.view.getTabletop().removeMouseMotionListener(maCardOver);
|
||||||
@Override
|
this.view.getTabletop().addMouseMotionListener(maCardOver);
|
||||||
public void mouseMoved(final MouseEvent me) {
|
|
||||||
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
|
||||||
final Card c = ControlField.this.view.getTabletop().getCardFromMouseOverPanel();
|
|
||||||
if (c != null) {
|
|
||||||
t.getDetailController().showCard(c);
|
|
||||||
t.getPictureController().showCard(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Player select
|
// Player select
|
||||||
this.view.getAvatarArea().addMouseListener(new MouseAdapter() {
|
this.view.getAvatarArea().removeMouseListener(maAvatar);
|
||||||
@Override
|
this.view.getAvatarArea().addMouseListener(maAvatar);
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
|
||||||
if (ControlField.this.player.isComputer()) {
|
|
||||||
t.getInputController().getInputControl().selectPlayer(AllZone.getComputerPlayer());
|
|
||||||
} else {
|
|
||||||
t.getInputController().getInputControl().selectPlayer(AllZone.getHumanPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} // End addListeners()
|
} // End addListeners()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -248,107 +188,30 @@ public class ControlField {
|
|||||||
private void addZoneListeners() {
|
private void addZoneListeners() {
|
||||||
// Graveyard card list button
|
// Graveyard card list button
|
||||||
this.view.getLblGraveyard().enableHover();
|
this.view.getLblGraveyard().enableHover();
|
||||||
this.view.getLblGraveyard().addMouseListener(new MouseAdapter() {
|
this.view.getLblGraveyard().removeMouseListener(maGraveyard);
|
||||||
@Override
|
this.view.getLblGraveyard().addMouseListener(maGraveyard);
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
if (ControlField.this.player.isComputer()) {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Graveyard),
|
|
||||||
NewConstants.Lang.GuiDisplay.COMPUTER_GRAVEYARD).actionPerformed(null);
|
|
||||||
} else {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Graveyard),
|
|
||||||
NewConstants.Lang.GuiDisplay.HUMAN_GRAVEYARD).actionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Exile card list button
|
// Exile card list button
|
||||||
this.view.getLblExile().enableHover();
|
this.view.getLblExile().enableHover();
|
||||||
this.view.getLblExile().addMouseListener(new MouseAdapter() {
|
this.view.getLblExile().removeMouseListener(maExiled);
|
||||||
@Override
|
this.view.getLblExile().addMouseListener(maExiled);
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
if (ControlField.this.player.isComputer()) {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Exile),
|
|
||||||
NewConstants.Lang.GuiDisplay.COMPUTER_REMOVED).actionPerformed(null);
|
|
||||||
} else {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Exile),
|
|
||||||
NewConstants.Lang.GuiDisplay.HUMAN_REMOVED).actionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Library card list button
|
// Library card list button
|
||||||
if (Constant.Runtime.DEV_MODE[0]) {
|
if (Constant.Runtime.DEV_MODE[0]) {
|
||||||
this.view.getLblLibrary().enableHover();
|
this.view.getLblLibrary().enableHover();
|
||||||
this.view.getLblLibrary().addMouseListener(new MouseAdapter() {
|
this.view.getLblLibrary().removeMouseListener(maLibrary);
|
||||||
@Override
|
this.view.getLblLibrary().addMouseListener(maLibrary);
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
if (!ControlField.this.player.isComputer()) {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Library), HumanLibrary.BASE)
|
|
||||||
.actionPerformed(null);
|
|
||||||
} else {
|
|
||||||
// TODO DeckListAction has been rewritten to accept either
|
|
||||||
// human or computer
|
|
||||||
// decklists. However, NewConstants.Lang.GuiDisplay does not
|
|
||||||
// have a computer
|
|
||||||
// decklist available. That needs to be added for the below
|
|
||||||
// line to work
|
|
||||||
// properly. The current solution will work in the meantime.
|
|
||||||
// Doublestrike 15-11-11.
|
|
||||||
|
|
||||||
// new
|
|
||||||
// DeckListAction(NewConstants.Lang.GuiDisplay).actionPerformed(null);
|
|
||||||
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Library), ComputerLibrary.BASE)
|
|
||||||
.actionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flashback card list button
|
// Flashback card list button
|
||||||
this.view.getLblFlashback().enableHover();
|
this.view.getLblFlashback().enableHover();
|
||||||
this.view.getLblFlashback().addMouseListener(new MouseAdapter() {
|
this.view.getLblFlashback().removeMouseListener(maFlashback);
|
||||||
@Override
|
this.view.getLblFlashback().addMouseListener(maFlashback);
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
if (!ControlField.this.player.isComputer()) {
|
|
||||||
new ZoneAction(AllZone.getHumanPlayer().getZone(Zone.Graveyard),
|
|
||||||
NewConstants.Lang.GuiDisplay.HUMAN_FLASHBACK) {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 8120331222693706164L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Iterable<Card> getCardsAsIterable() {
|
|
||||||
return new ImmutableIterableFrom<Card>(CardFactoryUtil.getExternalZoneActivationCards(AllZone
|
|
||||||
.getHumanPlayer()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doAction(final Card c) {
|
|
||||||
AllZone.getGameAction().playCard(c);
|
|
||||||
}
|
|
||||||
} .actionPerformed(null);
|
|
||||||
} else {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Graveyard),
|
|
||||||
NewConstants.Lang.GuiDisplay.COMPUTER_FLASHBACK).actionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Hand button
|
// Hand button
|
||||||
if (Constant.Runtime.DEV_MODE[0]) {
|
if (Constant.Runtime.DEV_MODE[0]) {
|
||||||
this.view.getLblHand().enableHover();
|
this.view.getLblHand().enableHover();
|
||||||
|
this.view.getLblHand().removeMouseListener(maHand);
|
||||||
this.view.getLblHand().addMouseListener(new MouseAdapter() {
|
this.view.getLblHand().addMouseListener(maHand);
|
||||||
@Override
|
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
if (!ControlField.this.player.isComputer()) {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Hand), HumanHand.BASE)
|
|
||||||
.actionPerformed(null);
|
|
||||||
} else {
|
|
||||||
new ZoneAction(ControlField.this.player.getZone(Zone.Hand), ComputerHand.BASE)
|
|
||||||
.actionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,4 +314,169 @@ public class ControlField {
|
|||||||
}
|
}
|
||||||
} // End ZoneAction
|
} // End ZoneAction
|
||||||
|
|
||||||
} //end class ControlField
|
/** Simple method that inits the mouse adapters for listeners,
|
||||||
|
* here to simplify life in the constructor.
|
||||||
|
*/
|
||||||
|
private void initMouseAdapters() {
|
||||||
|
// Hand listener
|
||||||
|
maHand = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (!ControlField.this.player.isComputer()) {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Hand), HumanHand.BASE)
|
||||||
|
.actionPerformed(null);
|
||||||
|
} else {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Hand), ComputerHand.BASE)
|
||||||
|
.actionPerformed(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Flashback listener
|
||||||
|
maFlashback = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (!ControlField.this.player.isComputer()) {
|
||||||
|
new ZoneAction(AllZone.getHumanPlayer().getZone(Zone.Graveyard),
|
||||||
|
NewConstants.Lang.GuiDisplay.HUMAN_FLASHBACK) {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 8120331222693706164L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Iterable<Card> getCardsAsIterable() {
|
||||||
|
return new ImmutableIterableFrom<Card>(CardFactoryUtil.getExternalZoneActivationCards(AllZone
|
||||||
|
.getHumanPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doAction(final Card c) {
|
||||||
|
AllZone.getGameAction().playCard(c);
|
||||||
|
}
|
||||||
|
} .actionPerformed(null);
|
||||||
|
} else {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Graveyard),
|
||||||
|
NewConstants.Lang.GuiDisplay.COMPUTER_FLASHBACK).actionPerformed(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Library listener
|
||||||
|
new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (!ControlField.this.player.isComputer()) {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Library), HumanLibrary.BASE)
|
||||||
|
.actionPerformed(null);
|
||||||
|
} else {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Library), ComputerLibrary.BASE)
|
||||||
|
.actionPerformed(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Exiled adapter
|
||||||
|
maExiled = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Exile),
|
||||||
|
NewConstants.Lang.GuiDisplay.COMPUTER_REMOVED).actionPerformed(null);
|
||||||
|
} else {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Exile),
|
||||||
|
NewConstants.Lang.GuiDisplay.HUMAN_REMOVED).actionPerformed(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Graveyard adapter
|
||||||
|
maGraveyard = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Graveyard),
|
||||||
|
NewConstants.Lang.GuiDisplay.COMPUTER_GRAVEYARD).actionPerformed(null);
|
||||||
|
} else {
|
||||||
|
new ZoneAction(ControlField.this.player.getZone(Zone.Graveyard),
|
||||||
|
NewConstants.Lang.GuiDisplay.HUMAN_GRAVEYARD).actionPerformed(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Avatar
|
||||||
|
maAvatar = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
t.getInputController().getInputControl().selectPlayer(AllZone.getComputerPlayer());
|
||||||
|
} else {
|
||||||
|
t.getInputController().getInputControl().selectPlayer(AllZone.getHumanPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Battlefield card mouse over
|
||||||
|
maCardOver = new MouseMotionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(final MouseEvent me) {
|
||||||
|
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
||||||
|
final Card c = ControlField.this.view.getTabletop().getCardFromMouseOverPanel();
|
||||||
|
if (c != null) {
|
||||||
|
t.getDetailController().showCard(c);
|
||||||
|
t.getPictureController().showCard(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Battlefield card
|
||||||
|
maCardClick = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
||||||
|
final Card c = t.getDetailController().getCurrentCard();
|
||||||
|
final Input input = t.getInputController().getInputControl().getInput();
|
||||||
|
|
||||||
|
if (c != null) {
|
||||||
|
if (c.isTapped()
|
||||||
|
&& ((input instanceof InputPayManaCost) || (input instanceof InputPayManaCostAbility))) {
|
||||||
|
final arcane.ui.CardPanel cardPanel = ControlField.this.view.getTabletop().getCardPanel(
|
||||||
|
c.getUniqueNumber());
|
||||||
|
for (final arcane.ui.CardPanel cp : cardPanel.getAttachedPanels()) {
|
||||||
|
if (cp.getCard().isUntapped()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final CardList att = new CardList(AllZone.getCombat().getAttackers());
|
||||||
|
if ((c.isTapped() || c.hasSickness() || ((c.hasKeyword("Vigilance")) && att.contains(c)))
|
||||||
|
&& (input instanceof InputAttack)) {
|
||||||
|
final arcane.ui.CardPanel cardPanel = ControlField.this.view.getTabletop().getCardPanel(
|
||||||
|
c.getUniqueNumber());
|
||||||
|
for (final arcane.ui.CardPanel cp : cardPanel.getAttachedPanels()) {
|
||||||
|
if (cp.getCard().isUntapped() && !cp.getCard().hasSickness()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.isMetaDown()) {
|
||||||
|
if (att.contains(c) && (input instanceof InputAttack)
|
||||||
|
&& !c.hasKeyword("CARDNAME attacks each turn if able.")) {
|
||||||
|
c.untap();
|
||||||
|
AllZone.getCombat().removeFromCombat(c);
|
||||||
|
} else if (input instanceof InputBlock) {
|
||||||
|
if (c.getController().isHuman()) {
|
||||||
|
AllZone.getCombat().removeFromCombat(c);
|
||||||
|
}
|
||||||
|
((InputBlock) input).removeFromAllBlocking(c);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.getInputController().getInputControl()
|
||||||
|
.selectCard(c, AllZone.getHumanPlayer().getZone(Zone.Battlefield));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // End initMouseAdapters()
|
||||||
|
} // End class ControlField
|
||||||
|
|||||||
Reference in New Issue
Block a user