mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Fixed double listener bug in hand area.
This commit is contained in:
@@ -51,6 +51,9 @@ public class ControlHand {
|
|||||||
private final List<Card> cardsInPanel;
|
private final List<Card> cardsInPanel;
|
||||||
private final ViewHand view;
|
private final ViewHand view;
|
||||||
|
|
||||||
|
private MouseAdapter maCardClick;
|
||||||
|
private MouseMotionAdapter maCardMove;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child controller - handles operations related to cards in user's hand and
|
* Child controller - handles operations related to cards in user's hand and
|
||||||
* their Swing components, which are assembled in ViewHand.
|
* their Swing components, which are assembled in ViewHand.
|
||||||
@@ -61,11 +64,37 @@ public class ControlHand {
|
|||||||
public ControlHand(final ViewHand v) {
|
public ControlHand(final ViewHand v) {
|
||||||
this.view = v;
|
this.view = v;
|
||||||
this.cardsInPanel = new ArrayList<Card>();
|
this.cardsInPanel = new ArrayList<Card>();
|
||||||
|
|
||||||
|
maCardClick = new MouseAdapter() {
|
||||||
|
// Card click
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (e.getButton() != MouseEvent.BUTTON1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Card c = view.getHandArea().getCardFromMouseOverPanel();
|
||||||
|
if (c != null) {
|
||||||
|
view.getTopLevel().getInputController().getInputControl().selectCard(c, AllZone.getHumanPlayer().getZone(Zone.Hand));
|
||||||
|
view.getTopLevel().getInputController().getView().getBtnOK().requestFocusInWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maCardMove = new MouseMotionAdapter() {
|
||||||
|
// Card mouseover
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(final MouseEvent me) {
|
||||||
|
final Card c = view.getHandArea().getCardFromMouseOverPanel();
|
||||||
|
if (c != null) {
|
||||||
|
((GuiTopLevel) AllZone.getDisplay()).setCard(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds observers to hand panel. */
|
/** Adds observers to hand panel. */
|
||||||
public void addObservers() {
|
public void addObservers() {
|
||||||
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
final ViewTopLevel t = view.getTopLevel();
|
||||||
|
|
||||||
AllZone.getHumanPlayer().getZone(Zone.Hand).addObserver(new Observer() {
|
AllZone.getHumanPlayer().getZone(Zone.Hand).addObserver(new Observer() {
|
||||||
@Override
|
@Override
|
||||||
@@ -128,33 +157,11 @@ public class ControlHand {
|
|||||||
|
|
||||||
/** Adds listeners to hand panel: clicks, mouseover, etc. */
|
/** Adds listeners to hand panel: clicks, mouseover, etc. */
|
||||||
public void addListeners() {
|
public void addListeners() {
|
||||||
final ViewTopLevel t = ((GuiTopLevel) AllZone.getDisplay()).getController().getMatchController().getView();
|
view.getHandArea().removeMouseListener(maCardClick);
|
||||||
|
view.getHandArea().addMouseListener(maCardClick);
|
||||||
|
|
||||||
view.getHandArea().addMouseListener(new MouseAdapter() {
|
view.getHandArea().removeMouseMotionListener(maCardMove);
|
||||||
// Card click
|
view.getHandArea().addMouseMotionListener(maCardMove);
|
||||||
@Override
|
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
if (e.getButton() != MouseEvent.BUTTON1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Card c = view.getHandArea().getCardFromMouseOverPanel();
|
|
||||||
if (c != null) {
|
|
||||||
t.getInputController().getInputControl().selectCard(c, AllZone.getHumanPlayer().getZone(Zone.Hand));
|
|
||||||
t.getInputController().getView().getBtnOK().requestFocusInWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
view.getHandArea().addMouseMotionListener(new MouseMotionAdapter() {
|
|
||||||
// Card mouseover
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(final MouseEvent me) {
|
|
||||||
final Card c = view.getHandArea().getCardFromMouseOverPanel();
|
|
||||||
if (c != null) {
|
|
||||||
((GuiTopLevel) AllZone.getDisplay()).setCard(c);
|
|
||||||
}
|
|
||||||
} // mouseMoved
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,14 +33,18 @@ import forge.view.toolbox.FRoundedPanel;
|
|||||||
public class ViewHand extends FRoundedPanel {
|
public class ViewHand extends FRoundedPanel {
|
||||||
private ControlHand control;
|
private ControlHand control;
|
||||||
private HandArea hand;
|
private HandArea hand;
|
||||||
|
private ViewTopLevel topLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VIEW - Swing components for user hand.
|
* Swing components for user hand.
|
||||||
|
*
|
||||||
|
* @param v0   The ViewTopLevel parent.
|
||||||
*/
|
*/
|
||||||
public ViewHand() {
|
public ViewHand(ViewTopLevel v0) {
|
||||||
final JScrollPane scroller = new JScrollPane();
|
final JScrollPane scroller = new JScrollPane();
|
||||||
ViewHand.this.hand = new HandArea(scroller, null);
|
ViewHand.this.hand = new HandArea(scroller, null);
|
||||||
ViewHand.this.setBackground(AllZone.getSkin().getColor("theme"));
|
ViewHand.this.setBackground(AllZone.getSkin().getColor("theme"));
|
||||||
|
topLevel = v0;
|
||||||
|
|
||||||
scroller.setViewportView(ViewHand.this.hand);
|
scroller.setViewportView(ViewHand.this.hand);
|
||||||
scroller.setOpaque(false);
|
scroller.setOpaque(false);
|
||||||
@@ -72,4 +76,9 @@ public class ViewHand extends FRoundedPanel {
|
|||||||
public HandArea getHandArea() {
|
public HandArea getHandArea() {
|
||||||
return ViewHand.this.hand;
|
return ViewHand.this.hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return ViewTopLevel */
|
||||||
|
public ViewTopLevel getTopLevel() {
|
||||||
|
return this.topLevel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class ViewTopLevel extends FPanel {
|
|||||||
|
|
||||||
// Declare and add various view components
|
// Declare and add various view components
|
||||||
input = new ViewInput();
|
input = new ViewInput();
|
||||||
hand = new ViewHand();
|
hand = new ViewHand(this);
|
||||||
dock = new ViewDock();
|
dock = new ViewDock();
|
||||||
battlefield = new ViewBattlefield();
|
battlefield = new ViewBattlefield();
|
||||||
tabber = new ViewTabber();
|
tabber = new ViewTabber();
|
||||||
|
|||||||
Reference in New Issue
Block a user