mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Code cleanup
This commit is contained in:
@@ -45,7 +45,6 @@ public enum CDetail implements ICDoc {
|
|||||||
* @param c   Card object
|
* @param c   Card object
|
||||||
*/
|
*/
|
||||||
public void showCard(final Card c) {
|
public void showCard(final Card c) {
|
||||||
|
|
||||||
view.getLblFlipcard().setVisible(c != null && (c.isDoubleFaced() || c.isFlipCard() || c.isFaceDown() && Singletons.getControl().mayShowCard(c)));
|
view.getLblFlipcard().setVisible(c != null && (c.isDoubleFaced() || c.isFlipCard() || c.isFaceDown() && Singletons.getControl().mayShowCard(c)));
|
||||||
view.getPnlDetail().setCard(c);
|
view.getPnlDetail().setCard(c);
|
||||||
if( view.getParentCell() != null)
|
if( view.getParentCell() != null)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package forge.gui.match.controllers;
|
package forge.gui.match.controllers;
|
||||||
|
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
@@ -37,7 +38,7 @@ import forge.item.InventoryItem;
|
|||||||
/**
|
/**
|
||||||
* Singleton controller for VPicture.
|
* Singleton controller for VPicture.
|
||||||
* <p>
|
* <p>
|
||||||
* Can be used to display images associated with a {@code Card} or
|
* Can be used to display images associated with a {@code Card} or
|
||||||
* {@code InventoryItem} in {@code CardPicturePanel}.<br>
|
* {@code InventoryItem} in {@code CardPicturePanel}.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* Can also be used to display details associated with a {@code Card}.
|
* Can also be used to display details associated with a {@code Card}.
|
||||||
@@ -47,7 +48,7 @@ import forge.item.InventoryItem;
|
|||||||
*/
|
*/
|
||||||
public enum CPicture implements ICDoc {
|
public enum CPicture implements ICDoc {
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
// For brevity, local shortcuts to singletons & child controls...
|
// For brevity, local shortcuts to singletons & child controls...
|
||||||
private final VPicture view = VPicture.SINGLETON_INSTANCE;
|
private final VPicture view = VPicture.SINGLETON_INSTANCE;
|
||||||
private final CardPicturePanel picturePanel = this.view.getPnlPicture();
|
private final CardPicturePanel picturePanel = this.view.getPnlPicture();
|
||||||
@@ -61,25 +62,25 @@ public enum CPicture implements ICDoc {
|
|||||||
* Shows card details and/or picture in sidebar cardview tabber.
|
* Shows card details and/or picture in sidebar cardview tabber.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void showCard(final Card c, boolean showFlipped) {
|
public void showCard(final Card c, boolean showFlipped) {
|
||||||
if (null == c) {
|
if (null == c) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCard = c;
|
currentCard = c;
|
||||||
displayedState = c.getCurState();
|
displayedState = c.getCurState();
|
||||||
flipIndicator.setVisible(isCurrentCardFlippable());
|
flipIndicator.setVisible(isCurrentCardFlippable());
|
||||||
picturePanel.setCard(c);
|
picturePanel.setCard(c);
|
||||||
if (showFlipped && isCurrentCardFlippable()) {
|
if (showFlipped && isCurrentCardFlippable()) {
|
||||||
flipCard();
|
flipCard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays image associated with either a {@code Card}
|
* Displays image associated with either a {@code Card}
|
||||||
* or {@code InventoryItem} instance.
|
* or {@code InventoryItem} instance.
|
||||||
*/
|
*/
|
||||||
public void showImage(final InventoryItem item) {
|
public void showImage(final InventoryItem item) {
|
||||||
if (item instanceof IPaperCard) {
|
if (item instanceof IPaperCard) {
|
||||||
IPaperCard paperCard = ((IPaperCard)item);
|
IPaperCard paperCard = ((IPaperCard)item);
|
||||||
Card c = Card.getCardForUi(paperCard);
|
Card c = Card.getCardForUi(paperCard);
|
||||||
@@ -108,7 +109,7 @@ public enum CPicture implements ICDoc {
|
|||||||
setMouseWheelListener();
|
setMouseWheelListener();
|
||||||
setMouseButtonListener();
|
setMouseButtonListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a mouse button listener to CardPicturePanel.
|
* Adds a mouse button listener to CardPicturePanel.
|
||||||
* <p><ul>
|
* <p><ul>
|
||||||
@@ -117,12 +118,11 @@ public enum CPicture implements ICDoc {
|
|||||||
* <li>Displays the alternate image for applicable cards on mouse click.
|
* <li>Displays the alternate image for applicable cards on mouse click.
|
||||||
*/
|
*/
|
||||||
private void setMouseButtonListener() {
|
private void setMouseButtonListener() {
|
||||||
|
|
||||||
this.picturePanel.addMouseListener(new MouseAdapter() {
|
this.picturePanel.addMouseListener(new MouseAdapter() {
|
||||||
private final boolean[] buttonsDown = new boolean[4];
|
private final boolean[] buttonsDown = new boolean[4];
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(final MouseEvent e) {
|
public void mousePressed(final MouseEvent e) {
|
||||||
if (isCardDisplayed()) {
|
if (isCardDisplayed()) {
|
||||||
final int button = e.getButton();
|
final int button = e.getButton();
|
||||||
if (button < 1 || button > 3) {
|
if (button < 1 || button > 3) {
|
||||||
@@ -130,13 +130,13 @@ public enum CPicture implements ICDoc {
|
|||||||
}
|
}
|
||||||
this.buttonsDown[button] = true;
|
this.buttonsDown[button] = true;
|
||||||
if (this.buttonsDown[2] || (this.buttonsDown[1] && this.buttonsDown[3])) {
|
if (this.buttonsDown[2] || (this.buttonsDown[1] && this.buttonsDown[3])) {
|
||||||
zoomer.doMouseButtonZoom(currentCard, displayedState);
|
zoomer.doMouseButtonZoom(currentCard, displayedState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(final MouseEvent e) {
|
public void mouseReleased(final MouseEvent e) {
|
||||||
if (isCardDisplayed()) {
|
if (isCardDisplayed()) {
|
||||||
final int button = e.getButton();
|
final int button = e.getButton();
|
||||||
if (button < 1 || button > 3) {
|
if (button < 1 || button > 3) {
|
||||||
@@ -157,8 +157,8 @@ public enum CPicture implements ICDoc {
|
|||||||
|
|
||||||
if (button == 1) {
|
if (button == 1) {
|
||||||
flipCard();
|
flipCard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -170,11 +170,11 @@ public enum CPicture implements ICDoc {
|
|||||||
* while the mouse pointer is hovering over the image.
|
* while the mouse pointer is hovering over the image.
|
||||||
*/
|
*/
|
||||||
private void setMouseWheelListener() {
|
private void setMouseWheelListener() {
|
||||||
picturePanel.addMouseWheelListener(new MouseWheelListener() {
|
picturePanel.addMouseWheelListener(new MouseWheelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(MouseWheelEvent arg0) {
|
public void mouseWheelMoved(MouseWheelEvent arg0) {
|
||||||
if (isCardDisplayed()) {
|
if (isCardDisplayed()) {
|
||||||
if (arg0.getWheelRotation() < 0) {
|
if (arg0.getWheelRotation() < 0) {
|
||||||
zoomer.doMouseWheelZoom(currentCard, displayedState);
|
zoomer.doMouseWheelZoom(currentCard, displayedState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,15 +189,15 @@ public enum CPicture implements ICDoc {
|
|||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flipCard() {
|
public void flipCard() {
|
||||||
if (isCurrentCardFlippable()) {
|
if (isCurrentCardFlippable()) {
|
||||||
displayedState = getAlternateState(currentCard, displayedState);
|
displayedState = getAlternateState(currentCard, displayedState);
|
||||||
picturePanel.setCardImage(displayedState);
|
picturePanel.setCardImage(displayedState);
|
||||||
setCardDetailPanel();
|
setCardDetailPanel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays details about the current card state in appropriate GUI panel.
|
* Displays details about the current card state in appropriate GUI panel.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -209,7 +209,7 @@ public enum CPicture implements ICDoc {
|
|||||||
* trigger any significant functionality but potentially this could cause
|
* trigger any significant functionality but potentially this could cause
|
||||||
* unforeseen consequences. Recommend that a read-only mechanism is implemented
|
* unforeseen consequences. Recommend that a read-only mechanism is implemented
|
||||||
* to get card details for a given {@code CardCharacteristicName} state that does
|
* to get card details for a given {@code CardCharacteristicName} state that does
|
||||||
* not require temporarily setting state of {@code Card} instance.
|
* not require temporarily setting state of {@code Card} instance.
|
||||||
*/
|
*/
|
||||||
private void setCardDetailPanel() {
|
private void setCardDetailPanel() {
|
||||||
CardCharacteristicName temp = currentCard.getCurState();
|
CardCharacteristicName temp = currentCard.getCurState();
|
||||||
@@ -217,21 +217,19 @@ public enum CPicture implements ICDoc {
|
|||||||
CDetail.SINGLETON_INSTANCE.showCard(currentCard);
|
CDetail.SINGLETON_INSTANCE.showCard(currentCard);
|
||||||
currentCard.setState(temp);
|
currentCard.setState(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCurrentCardFlippable() {
|
private boolean isCurrentCardFlippable() {
|
||||||
boolean isFlippableMorph =
|
boolean isFlippableMorph =
|
||||||
currentCard.isFaceDown() && isAuthorizedToViewFaceDownCard(currentCard);
|
currentCard.isFaceDown() && isAuthorizedToViewFaceDownCard(currentCard);
|
||||||
return (currentCard != null) &
|
return (currentCard != null) &
|
||||||
(currentCard.isDoubleFaced() || currentCard.isFlipCard() || isFlippableMorph);
|
(currentCard.isDoubleFaced() || currentCard.isFlipCard() || isFlippableMorph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Card characteristic state machine.
|
* Card characteristic state machine.
|
||||||
* <p>
|
* <p>
|
||||||
* Given a card and a state in terms of {@code CardCharacteristicName} this
|
* Given a card and a state in terms of {@code CardCharacteristicName} this
|
||||||
* will determine whether there is a valid alternate {@code CardCharacteristicName}
|
* will determine whether there is a valid alternate {@code CardCharacteristicName}
|
||||||
* state for that card.
|
* state for that card.
|
||||||
*
|
*
|
||||||
* @param card the {@code Card}
|
* @param card the {@code Card}
|
||||||
@@ -239,10 +237,9 @@ public enum CPicture implements ICDoc {
|
|||||||
* @return the alternate {@code CardCharacteristicName} state or default if not applicable
|
* @return the alternate {@code CardCharacteristicName} state or default if not applicable
|
||||||
*/
|
*/
|
||||||
public static CardCharacteristicName getAlternateState(final Card card, CardCharacteristicName currentState) {
|
public static CardCharacteristicName getAlternateState(final Card card, CardCharacteristicName currentState) {
|
||||||
|
|
||||||
// Default. Most cards will only ever have an "Original" state represented by a single image.
|
// Default. Most cards will only ever have an "Original" state represented by a single image.
|
||||||
CardCharacteristicName alternateState = CardCharacteristicName.Original;
|
CardCharacteristicName alternateState = CardCharacteristicName.Original;
|
||||||
|
|
||||||
if (card.isDoubleFaced()) {
|
if (card.isDoubleFaced()) {
|
||||||
if (currentState == CardCharacteristicName.Original) {
|
if (currentState == CardCharacteristicName.Original) {
|
||||||
alternateState = CardCharacteristicName.Transformed;
|
alternateState = CardCharacteristicName.Transformed;
|
||||||
@@ -265,11 +262,11 @@ public enum CPicture implements ICDoc {
|
|||||||
|
|
||||||
return alternateState;
|
return alternateState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents player from identifying opponent's face-down card.
|
* Prevents player from identifying opponent's face-down card.
|
||||||
*/
|
*/
|
||||||
public static boolean isAuthorizedToViewFaceDownCard(Card card) {
|
public static boolean isAuthorizedToViewFaceDownCard(Card card) {
|
||||||
return Singletons.getControl().mayShowCard(card);
|
return Singletons.getControl().mayShowCard(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user