mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
fix leak with MouseListeners hooked up to mana pools.
This commit is contained in:
@@ -59,7 +59,6 @@ import forge.properties.NewConstants.Lang.GuiDisplay.HumanHand;
|
|||||||
import forge.properties.NewConstants.Lang.GuiDisplay.HumanLibrary;
|
import forge.properties.NewConstants.Lang.GuiDisplay.HumanLibrary;
|
||||||
import forge.view.GuiTopLevel;
|
import forge.view.GuiTopLevel;
|
||||||
import forge.view.match.ViewField;
|
import forge.view.match.ViewField;
|
||||||
import forge.view.match.ViewField.DetailLabel;
|
|
||||||
import forge.view.match.ViewTopLevel;
|
import forge.view.match.ViewTopLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,6 +74,8 @@ public class ControlField {
|
|||||||
private MouseMotionAdapter maCardOver;
|
private MouseMotionAdapter maCardOver;
|
||||||
private MouseAdapter maAvatar, maLibrary, maHand, maExiled, maGraveyard, maFlashback, maCardClick;
|
private MouseAdapter maAvatar, maLibrary, maHand, maExiled, maGraveyard, maFlashback, maCardClick;
|
||||||
|
|
||||||
|
private MouseAdapter maBlack, maBlue, maGreen, maRed, maWhite, maColorless;
|
||||||
|
|
||||||
private Observer observerZones, observerDetails, observerPlay;
|
private Observer observerZones, observerDetails, observerPlay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,31 +193,24 @@ public class ControlField {
|
|||||||
* Adds listeners to mana "pool" labels, for paying mana.
|
* Adds listeners to mana "pool" labels, for paying mana.
|
||||||
*/
|
*/
|
||||||
private void addPoolListeners() {
|
private void addPoolListeners() {
|
||||||
this.addPoolListener(this.view.getLblBlack(), Constant.Color.BLACK);
|
this.view.getLblBlack().enableHover();
|
||||||
this.addPoolListener(this.view.getLblBlue(), Constant.Color.BLUE);
|
this.view.getLblBlack().removeMouseListener(maBlack);
|
||||||
this.addPoolListener(this.view.getLblGreen(), Constant.Color.GREEN);
|
this.view.getLblBlack().addMouseListener(maBlack);
|
||||||
this.addPoolListener(this.view.getLblRed(), Constant.Color.RED);
|
this.view.getLblBlue().enableHover();
|
||||||
this.addPoolListener(this.view.getLblWhite(), Constant.Color.WHITE);
|
this.view.getLblBlue().removeMouseListener(maBlue);
|
||||||
this.addPoolListener(this.view.getLblColorless(), Constant.Color.COLORLESS);
|
this.view.getLblBlue().addMouseListener(maBlue);
|
||||||
}
|
this.view.getLblGreen().enableHover();
|
||||||
|
this.view.getLblGreen().removeMouseListener(maGreen);
|
||||||
private void addPoolListener(DetailLabel label, final String color) {
|
this.view.getLblGreen().addMouseListener(maGreen);
|
||||||
label.enableHover();
|
this.view.getLblRed().enableHover();
|
||||||
label.addMouseListener(new MouseAdapter() {
|
this.view.getLblRed().removeMouseListener(maRed);
|
||||||
@Override
|
this.view.getLblRed().addMouseListener(maRed);
|
||||||
public void mousePressed(final MouseEvent e) {
|
this.view.getLblWhite().enableHover();
|
||||||
if (ControlField.this.player.isComputer()) {
|
this.view.getLblWhite().removeMouseListener(maWhite);
|
||||||
System.out.print("Stop trying to spend the AI's mana");
|
this.view.getLblWhite().addMouseListener(maWhite);
|
||||||
// TODO: Mindslaver might need to add changes here
|
this.view.getLblColorless().enableHover();
|
||||||
} else {
|
this.view.getLblColorless().removeMouseListener(maColorless);
|
||||||
Input in = AllZone.getInputControl().getInput();
|
this.view.getLblColorless().addMouseListener(maColorless);
|
||||||
if (in instanceof InputMana) {
|
|
||||||
// Do something
|
|
||||||
((InputMana) in).selectManaPool(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -521,5 +515,102 @@ public class ControlField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
maBlack = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
System.out.println("Stop trying to spend the AI's mana");
|
||||||
|
// TODO: Mindslaver might need to add changes here
|
||||||
|
} else {
|
||||||
|
Input in = AllZone.getInputControl().getInput();
|
||||||
|
if (in instanceof InputMana) {
|
||||||
|
// Do something
|
||||||
|
((InputMana) in).selectManaPool(Constant.Color.BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maBlue = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
System.out.println("Stop trying to spend the AI's mana");
|
||||||
|
// TODO: Mindslaver might need to add changes here
|
||||||
|
} else {
|
||||||
|
Input in = AllZone.getInputControl().getInput();
|
||||||
|
if (in instanceof InputMana) {
|
||||||
|
// Do something
|
||||||
|
((InputMana) in).selectManaPool(Constant.Color.BLUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maGreen = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
System.out.println("Stop trying to spend the AI's mana");
|
||||||
|
// TODO: Mindslaver might need to add changes here
|
||||||
|
} else {
|
||||||
|
Input in = AllZone.getInputControl().getInput();
|
||||||
|
if (in instanceof InputMana) {
|
||||||
|
// Do something
|
||||||
|
((InputMana) in).selectManaPool(Constant.Color.GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maRed = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
System.out.println("Stop trying to spend the AI's mana");
|
||||||
|
// TODO: Mindslaver might need to add changes here
|
||||||
|
} else {
|
||||||
|
Input in = AllZone.getInputControl().getInput();
|
||||||
|
if (in instanceof InputMana) {
|
||||||
|
// Do something
|
||||||
|
((InputMana) in).selectManaPool(Constant.Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maWhite = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
System.out.println("Stop trying to spend the AI's mana");
|
||||||
|
// TODO: Mindslaver might need to add changes here
|
||||||
|
} else {
|
||||||
|
Input in = AllZone.getInputControl().getInput();
|
||||||
|
if (in instanceof InputMana) {
|
||||||
|
// Do something
|
||||||
|
((InputMana) in).selectManaPool(Constant.Color.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maColorless = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent e) {
|
||||||
|
if (ControlField.this.player.isComputer()) {
|
||||||
|
System.out.println("Stop trying to spend the AI's mana");
|
||||||
|
// TODO: Mindslaver might need to add changes here
|
||||||
|
} else {
|
||||||
|
Input in = AllZone.getInputControl().getInput();
|
||||||
|
if (in instanceof InputMana) {
|
||||||
|
// Do something
|
||||||
|
((InputMana) in).selectManaPool(Constant.Color.COLORLESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
} // End initMouseAdapters()
|
} // End initMouseAdapters()
|
||||||
|
|
||||||
} // End class ControlField
|
} // End class ControlField
|
||||||
|
|||||||
@@ -695,6 +695,7 @@ public class ViewField extends FRoundedPanel {
|
|||||||
|
|
||||||
/** Enable hover effects for this label. */
|
/** Enable hover effects for this label. */
|
||||||
public void enableHover() {
|
public void enableHover() {
|
||||||
|
this.disableHover();
|
||||||
this.addMouseListener(this.madHover);
|
this.addMouseListener(this.madHover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user