mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Refactor so mobile game can determine whether card can be flipped
This commit is contained in:
@@ -19,6 +19,7 @@ package forge.screens.match.controllers;
|
|||||||
|
|
||||||
import forge.UiCommand;
|
import forge.UiCommand;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
|
import forge.card.CardDetailUtil;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
@@ -45,7 +46,7 @@ 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 && CardDetailUtil.isCardFlippable(c) && Singletons.getControl().mayShowCard(c));
|
||||||
view.getPnlDetail().setCard(c);
|
view.getPnlDetail().setCard(c);
|
||||||
if (view.getParentCell() != null) {
|
if (view.getParentCell() != null) {
|
||||||
view.getParentCell().repaintSelf();
|
view.getParentCell().repaintSelf();
|
||||||
@@ -55,11 +56,13 @@ public enum CDetail implements ICDoc {
|
|||||||
public void showCard(InventoryItem item) {
|
public void showCard(InventoryItem item) {
|
||||||
if (item instanceof IPaperCard) {
|
if (item instanceof IPaperCard) {
|
||||||
showCard(Card.getCardForUi((IPaperCard)item));
|
showCard(Card.getCardForUi((IPaperCard)item));
|
||||||
} else if (item instanceof InventoryItemFromSet) {
|
}
|
||||||
|
else if (item instanceof InventoryItemFromSet) {
|
||||||
view.getLblFlipcard().setVisible(false);
|
view.getLblFlipcard().setVisible(false);
|
||||||
view.getPnlDetail().setItem((InventoryItemFromSet)item);
|
view.getPnlDetail().setItem((InventoryItemFromSet)item);
|
||||||
view.getParentCell().repaintSelf();
|
view.getParentCell().repaintSelf();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
showCard((Card)null);
|
showCard((Card)null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package forge.screens.match.controllers;
|
|||||||
import forge.UiCommand;
|
import forge.UiCommand;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.CardCharacteristicName;
|
import forge.card.CardCharacteristicName;
|
||||||
|
import forge.card.CardDetailUtil;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.gui.CardPicturePanel;
|
import forge.gui.CardPicturePanel;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
@@ -177,7 +178,7 @@ public enum CPicture implements ICDoc {
|
|||||||
|
|
||||||
public void flipCard() {
|
public void flipCard() {
|
||||||
if (isCurrentCardFlippable()) {
|
if (isCurrentCardFlippable()) {
|
||||||
displayedState = getAlternateState(currentCard, displayedState);
|
displayedState = CardDetailUtil.getAlternateState(currentCard, displayedState);
|
||||||
picturePanel.setCardImage(displayedState);
|
picturePanel.setCardImage(displayedState);
|
||||||
setCardDetailPanel();
|
setCardDetailPanel();
|
||||||
}
|
}
|
||||||
@@ -206,51 +207,6 @@ public enum CPicture implements ICDoc {
|
|||||||
private boolean isCurrentCardFlippable() {
|
private boolean isCurrentCardFlippable() {
|
||||||
if (!mayShowCurrentCard()) { return false; }
|
if (!mayShowCurrentCard()) { return false; }
|
||||||
|
|
||||||
return currentCard.isDoubleFaced() || currentCard.isFlipCard() || currentCard.isFaceDown();
|
return CardDetailUtil.isCardFlippable(currentCard);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Card characteristic state machine.
|
|
||||||
* <p>
|
|
||||||
* Given a card and a state in terms of {@code CardCharacteristicName} this
|
|
||||||
* will determine whether there is a valid alternate {@code CardCharacteristicName}
|
|
||||||
* state for that card.
|
|
||||||
*
|
|
||||||
* @param card the {@code Card}
|
|
||||||
* @param currentState not necessarily {@code card.getCurState()}
|
|
||||||
* @return the alternate {@code CardCharacteristicName} state or default if not applicable
|
|
||||||
*/
|
|
||||||
public static CardCharacteristicName getAlternateState(final Card card, CardCharacteristicName currentState) {
|
|
||||||
// Default. Most cards will only ever have an "Original" state represented by a single image.
|
|
||||||
CardCharacteristicName alternateState = CardCharacteristicName.Original;
|
|
||||||
|
|
||||||
if (card.isDoubleFaced()) {
|
|
||||||
if (currentState == CardCharacteristicName.Original) {
|
|
||||||
alternateState = CardCharacteristicName.Transformed;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (card.isFlipCard()) {
|
|
||||||
if (currentState == CardCharacteristicName.Original) {
|
|
||||||
alternateState = CardCharacteristicName.Flipped;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (card.isFaceDown()) {
|
|
||||||
if (currentState == CardCharacteristicName.Original) {
|
|
||||||
alternateState = CardCharacteristicName.FaceDown;
|
|
||||||
} else if (isAuthorizedToViewFaceDownCard(card)) {
|
|
||||||
alternateState = CardCharacteristicName.Original;
|
|
||||||
} else {
|
|
||||||
alternateState = currentState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return alternateState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevents player from identifying opponent's face-down card.
|
|
||||||
*/
|
|
||||||
public static boolean isAuthorizedToViewFaceDownCard(Card card) {
|
|
||||||
return Singletons.getControl().mayShowCard(card);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,12 @@
|
|||||||
|
|
||||||
package forge.toolbox.special;
|
package forge.toolbox.special;
|
||||||
|
|
||||||
|
import forge.Singletons;
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
import forge.card.CardCharacteristicName;
|
import forge.card.CardCharacteristicName;
|
||||||
|
import forge.card.CardDetailUtil;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
import forge.screens.match.controllers.CPicture;
|
|
||||||
import forge.toolbox.FOverlay;
|
import forge.toolbox.FOverlay;
|
||||||
import forge.toolbox.FSkin;
|
import forge.toolbox.FSkin;
|
||||||
import forge.toolbox.FSkin.SkinnedLabel;
|
import forge.toolbox.FSkin.SkinnedLabel;
|
||||||
@@ -217,7 +218,7 @@ public enum CardZoomer {
|
|||||||
* Displays a graphical indicator that shows whether the current card can be flipped or transformed.
|
* Displays a graphical indicator that shows whether the current card can be flipped or transformed.
|
||||||
*/
|
*/
|
||||||
private void setFlipIndicator() {
|
private void setFlipIndicator() {
|
||||||
boolean isFaceDownFlippable = (isFaceDownCard && CPicture.isAuthorizedToViewFaceDownCard(thisCard));
|
boolean isFaceDownFlippable = (isFaceDownCard && Singletons.getControl().mayShowCard(thisCard));
|
||||||
if (thisCard.isFlipCard() || thisCard.isDoubleFaced() || isFaceDownFlippable ) {
|
if (thisCard.isFlipCard() || thisCard.isDoubleFaced() || isFaceDownFlippable ) {
|
||||||
imagePanel.setLayout(new MigLayout("insets 0, w 100%!, h 100%!"));
|
imagePanel.setLayout(new MigLayout("insets 0, w 100%!, h 100%!"));
|
||||||
imagePanel.add(lblFlipcard, "pos (100% - 100px) 0");
|
imagePanel.add(lblFlipcard, "pos (100% - 100px) 0");
|
||||||
@@ -320,7 +321,7 @@ public enum CardZoomer {
|
|||||||
* Uses constraint that prevents a player from identifying opponent's face-down cards.
|
* Uses constraint that prevents a player from identifying opponent's face-down cards.
|
||||||
*/
|
*/
|
||||||
private void toggleFaceDownCard() {
|
private void toggleFaceDownCard() {
|
||||||
cardState = CPicture.getAlternateState(thisCard, cardState);
|
cardState = CardDetailUtil.getAlternateState(thisCard, cardState);
|
||||||
setImage();
|
setImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,8 +329,7 @@ public enum CardZoomer {
|
|||||||
* Toggles between the front and back image of a double-sided card.
|
* Toggles between the front and back image of a double-sided card.
|
||||||
*/
|
*/
|
||||||
private void toggleDoubleFacedCard() {
|
private void toggleDoubleFacedCard() {
|
||||||
cardState = CPicture.getAlternateState(thisCard, cardState);
|
cardState = CardDetailUtil.getAlternateState(thisCard, cardState);
|
||||||
setImage();
|
setImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -499,4 +499,48 @@ public class CardDetailUtil {
|
|||||||
}
|
}
|
||||||
return area.toString();
|
return area.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCardFlippable(Card card) {
|
||||||
|
return card.isDoubleFaced() || card.isFlipCard() || card.isFaceDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card characteristic state machine.
|
||||||
|
* <p>
|
||||||
|
* Given a card and a state in terms of {@code CardCharacteristicName} this
|
||||||
|
* will determine whether there is a valid alternate {@code CardCharacteristicName}
|
||||||
|
* state for that card.
|
||||||
|
*
|
||||||
|
* @param card the {@code Card}
|
||||||
|
* @param currentState not necessarily {@code card.getCurState()}
|
||||||
|
* @return the alternate {@code CardCharacteristicName} state or default if not applicable
|
||||||
|
*/
|
||||||
|
public static CardCharacteristicName getAlternateState(final Card card, CardCharacteristicName currentState) {
|
||||||
|
// Default. Most cards will only ever have an "Original" state represented by a single image.
|
||||||
|
CardCharacteristicName alternateState = CardCharacteristicName.Original;
|
||||||
|
|
||||||
|
if (card.isDoubleFaced()) {
|
||||||
|
if (currentState == CardCharacteristicName.Original) {
|
||||||
|
alternateState = CardCharacteristicName.Transformed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (card.isFlipCard()) {
|
||||||
|
if (currentState == CardCharacteristicName.Original) {
|
||||||
|
alternateState = CardCharacteristicName.Flipped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (card.isFaceDown()) {
|
||||||
|
if (currentState == CardCharacteristicName.Original) {
|
||||||
|
alternateState = CardCharacteristicName.FaceDown;
|
||||||
|
}
|
||||||
|
else if (GuiBase.getInterface().mayShowCard(card)) {
|
||||||
|
alternateState = CardCharacteristicName.Original;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alternateState = currentState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return alternateState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user