From 59d907c981006d814f524fe5eaacf64cda8d681c Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 6 Mar 2014 21:51:51 +0100 Subject: [PATCH] * Improved handling of enlarged images. Added mode to show other side of flip and transform cards. Added icon for copied cards and possibility to show enlarged original or copied card. --- .../main/java/mage/client/cards/BigCard.java | 13 +- .../src/main/java/mage/client/cards/Card.form | 2 +- .../src/main/java/mage/client/cards/Card.java | 108 ++++++++---- .../client/deckeditor/table/TableModel.java | 3 +- .../main/java/mage/client/game/GamePanel.java | 22 ++- .../plugins/adapters/MageActionCallback.java | 166 +++++++++++------- .../client/remote/CallbackClientImpl.java | 3 +- .../java/org/mage/card/arcane/CardPanel.java | 84 +++++++-- .../org/mage/plugins/card/CardPluginImpl.java | 4 +- .../mage/plugins/card/images/ImageCache.java | 50 ++++-- .../mage/plugins/card/utils/ImageManager.java | 1 + .../card/utils/impl/ImageManagerImpl.java | 10 ++ Mage.Client/src/main/resources/card/copy.png | Bin 0 -> 545 bytes Mage.Common/src/mage/cards/MageCard.java | 5 +- Mage.Common/src/mage/view/CardView.java | 60 ++++++- Mage.Common/src/mage/view/PermanentView.java | 32 +++- Mage/src/mage/MageObjectImpl.java | 19 +- .../abilities/effects/common/CopyEffect.java | 10 +- .../effects/common/CopyTokenEffect.java | 6 +- Mage/src/mage/cards/Card.java | 2 + Mage/src/mage/cards/CardImpl.java | 43 +++-- Mage/src/mage/constants/EnlargeMode.java | 11 ++ .../mage/game/permanent/PermanentCard.java | 58 +----- Mage/src/mage/game/stack/Spell.java | 11 ++ 24 files changed, 490 insertions(+), 233 deletions(-) create mode 100644 Mage.Client/src/main/resources/card/copy.png create mode 100644 Mage/src/mage/constants/EnlargeMode.java diff --git a/Mage.Client/src/main/java/mage/client/cards/BigCard.java b/Mage.Client/src/main/java/mage/client/cards/BigCard.java index 766eb5a208..f4f60a4cf1 100644 --- a/Mage.Client/src/main/java/mage/client/cards/BigCard.java +++ b/Mage.Client/src/main/java/mage/client/cards/BigCard.java @@ -47,6 +47,7 @@ import java.util.List; import java.util.UUID; import static mage.constants.Constants.*; +import mage.constants.EnlargeMode; /** * Class for displaying big image of the card @@ -65,6 +66,7 @@ public class BigCard extends JComponent { protected Thread foilThread; protected float hue = 0.005f; protected float dh = 0.005f; + protected EnlargeMode enlargeMode; public BigCard() { initComponents(); @@ -87,19 +89,20 @@ public class BigCard extends JComponent { } - public void setCard(UUID cardId, Image image, List strings, boolean foil) { - if (this.cardId == null || !this.cardId.equals(cardId)) { + public void setCard(UUID cardId, EnlargeMode enlargeMode, Image image, List strings) { + if (this.cardId == null || !enlargeMode.equals(this.enlargeMode) || !this.cardId.equals(cardId)) { if (this.panel != null) { remove(this.panel); } this.cardId = cardId; + this.enlargeMode = enlargeMode; bigImage = image; synchronized (this) { source = null; hue = 0.000f; } drawText(strings); - setFoil(foil); + repaint(); } } @@ -143,10 +146,6 @@ public class BigCard extends JComponent { this.scrollPane.setVisible(true); } - public void setFoil(boolean foil) { - repaint(); - } - public void addJXPanel(UUID cardId, JXPanel jxPanel) { bigImage = null; synchronized (this) { diff --git a/Mage.Client/src/main/java/mage/client/cards/Card.form b/Mage.Client/src/main/java/mage/client/cards/Card.form index 3f9a08b3b9..9bfc695442 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.form +++ b/Mage.Client/src/main/java/mage/client/cards/Card.form @@ -1,4 +1,4 @@ - +
diff --git a/Mage.Client/src/main/java/mage/client/cards/Card.java b/Mage.Client/src/main/java/mage/client/cards/Card.java index 06c1cdc398..24bade0d9d 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.java +++ b/Mage.Client/src/main/java/mage/client/cards/Card.java @@ -34,36 +34,64 @@ package mage.client.cards; -import mage.constants.CardType; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import javax.swing.JScrollPane; +import javax.swing.Popup; +import javax.swing.PopupFactory; +import javax.swing.text.BadLocationException; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyleContext; +import javax.swing.text.StyledDocument; import mage.cards.CardDimensions; import mage.cards.MagePermanent; +import mage.cards.Sets; import mage.cards.TextPopup; import mage.cards.action.ActionCallback; import mage.client.MageFrame; +import static mage.client.constants.Constants.CONTENT_MAX_XOFFSET; +import static mage.client.constants.Constants.FRAME_MAX_HEIGHT; +import static mage.client.constants.Constants.FRAME_MAX_WIDTH; +import static mage.client.constants.Constants.NAME_FONT_MAX_SIZE; +import static mage.client.constants.Constants.NAME_MAX_YOFFSET; +import static mage.client.constants.Constants.POWBOX_TEXT_MAX_LEFT; +import static mage.client.constants.Constants.POWBOX_TEXT_MAX_TOP; +import static mage.client.constants.Constants.SYMBOL_MAX_XOFFSET; +import static mage.client.constants.Constants.SYMBOL_MAX_YOFFSET; +import static mage.client.constants.Constants.TYPE_MAX_YOFFSET; import mage.client.game.PlayAreaPanel; import mage.client.util.Config; import mage.client.util.DefaultActionCallback; import mage.client.util.ImageHelper; import mage.client.util.gui.ArrowBuilder; +import mage.constants.CardType; +import mage.constants.EnlargeMode; import mage.remote.Session; -import mage.cards.Sets; import mage.view.AbilityView; import mage.view.CardView; +import mage.view.CounterView; import mage.view.PermanentView; import mage.view.StackAbilityView; -import javax.swing.*; -import javax.swing.text.*; -import java.awt.*; -import java.awt.event.*; -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import static mage.constants.Constants.*; -import mage.view.CounterView; - /** * * @author BetaSteward_at_googlemail.com @@ -89,7 +117,14 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis protected BufferedImage small; protected String backgroundName; - /** Creates new form Card */ + /** + * Creates new form Card + * + * @param card + * @param bigCard + * @param dimension + * @param gameId + */ public Card(CardView card, BigCard bigCard, CardDimensions dimension, UUID gameId) { this.dimension = dimension; initComponents(); @@ -120,10 +155,12 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis return card.getId(); } + @Override public void update(PermanentView permanent) { this.update((CardView)permanent); } + @Override public void update(CardView card) { this.card = card; Graphics2D gImage = image.createGraphics(); @@ -141,8 +178,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis gImage.setColor(Color.BLACK); gImage.drawImage(background, 0, 0, this); - if (card.getManaCost().size() > 0) + if (card.getManaCost().size() > 0) { ImageHelper.drawCosts(card.getManaCost(), gImage, FRAME_MAX_WIDTH - SYMBOL_MAX_XOFFSET, SYMBOL_MAX_YOFFSET, this); + } gSmall.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gSmall.setColor(Color.BLACK); @@ -157,8 +195,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis gImage.drawString(card.getLoyalty(), POWBOX_TEXT_MAX_LEFT, POWBOX_TEXT_MAX_TOP); } - if (card.getCardTypes().size() > 0) + if (card.getCardTypes().size() > 0) { gImage.drawString(cardType, CONTENT_MAX_XOFFSET, TYPE_MAX_YOFFSET); + } gImage.dispose(); @@ -171,8 +210,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis gSmall.drawString(card.getLoyalty(), Config.dimensions.powBoxTextLeft, Config.dimensions.powBoxTextTop); } - if (card.getCardTypes().size() > 0) + if (card.getCardTypes().size() > 0) { gSmall.drawString(cardType, Config.dimensions.contentXOffset, Config.dimensions.typeYOffset); + } drawText(); gSmall.dispose(); @@ -217,7 +257,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis return sb.toString(); } - protected String getBackgroundName() { + private String getBackgroundName() { if (card instanceof StackAbilityView || card instanceof AbilityView) { return "effect"; } @@ -237,8 +277,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis StyledDocument doc = text.getStyledDocument(); try { - for (String rule: getRules()) + for (String rule: getRules()) { doc.insertString(doc.getLength(), rule + "\n", doc.getStyle("small")); + } } catch (BadLocationException e) {} text.setCaretPosition(0); @@ -246,7 +287,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis protected List getRules() { if (card.getCounters() != null) { - List rules = new ArrayList(card.getRules()); + List rules = new ArrayList<>(card.getRules()); for (CounterView counter: card.getCounters()) { rules.add(counter.getCount() + " x " + counter.getName()); } @@ -333,7 +374,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void mouseMoved(MouseEvent arg0) { this.bigCard.showTextComponent(); - this.bigCard.setCard(card.getId(), image, getRules(), false); + this.bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, getRules()); } @Override @@ -353,8 +394,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void mouseEntered(MouseEvent arg0) { if (!popupShowing) { - if (popup != null) + if (popup != null) { popup.hide(); + } PopupFactory factory = PopupFactory.getSharedInstance(); popup = factory.getPopup(this, popupText, (int) this.getLocationOnScreen().getX() + Config.dimensions.frameWidth, (int) this.getLocationOnScreen().getY() + 40); popup.show(); @@ -368,9 +410,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis List targets = card.getTargets(); if (targets != null) { for (UUID uuid : targets) { - PlayAreaPanel p = MageFrame.getGame(gameId).getPlayers().get(uuid); - if (p != null) { - Point target = p.getLocationOnScreen(); + PlayAreaPanel playAreaPanel = MageFrame.getGame(gameId).getPlayers().get(uuid); + if (playAreaPanel != null) { + Point target = playAreaPanel.getLocationOnScreen(); Point me = this.getLocationOnScreen(); ArrowBuilder.getBuilder().addArrow(gameId, (int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET); } else { @@ -390,7 +432,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void mouseExited(MouseEvent arg0) { - if(getMousePosition(true) != null) return; + if(getMousePosition(true) != null) { + return; + } if (popup != null) { popup.hide(); popupShowing = false; @@ -408,8 +452,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void focusLost(FocusEvent arg0) { - if (popup != null) + if (popup != null) { popup.hide(); + } this.repaint(); } @@ -433,8 +478,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void componentHidden(ComponentEvent e) { - if (popup != null) + if (popup != null) { popup.hide(); + } } @Override @@ -491,7 +537,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis } @Override - public float getAlpha() {return 0;} + public float getAlpha() { + return 0; + } @Override public void toggleTransformed() { diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java index fd4250c906..bab7b7da2c 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java @@ -59,6 +59,7 @@ import mage.client.util.ImageHelper; import mage.client.util.Listener; import mage.client.util.gui.GuiDisplayUtil; import mage.constants.CardType; +import mage.constants.EnlargeMode; import mage.view.CardView; import mage.view.CardsView; import org.apache.log4j.Logger; @@ -380,7 +381,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { if (image != null && image instanceof BufferedImage) { // XXX: scaled to fit width image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth()); - bigCard.setCard(card.getId(), image, new ArrayList(), false); + bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, new ArrayList()); } else { drawCardText(card); } diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index d865bb30b5..fa6bde0c08 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -92,6 +92,7 @@ import mage.client.util.Config; import mage.client.util.GameManager; import mage.client.util.PhaseManager; import mage.client.util.gui.ArrowBuilder; +import mage.constants.EnlargeMode; import mage.constants.PhaseStep; import static mage.constants.PhaseStep.BEGIN_COMBAT; import static mage.constants.PhaseStep.COMBAT_DAMAGE; @@ -952,7 +953,17 @@ public final class GamePanel extends javax.swing.JPanel { @Override public void actionPerformed(ActionEvent actionEvent) { ActionCallback callback = Plugins.getInstance().getActionCallback(); - ((MageActionCallback)callback).enlargeCard(); + ((MageActionCallback)callback).enlargeCard(EnlargeMode.NORMAL); + } + }); + + KeyStroke ksAltS = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK); + this.getInputMap(c).put(ksAltS, "ENLARGE_SOURCE"); + this.getActionMap().put("ENLARGE_SOURCE", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback)callback).enlargeCard(EnlargeMode.ALTERNATE); } }); @@ -989,16 +1000,19 @@ public final class GamePanel extends javax.swing.JPanel { } }); - KeyStroke ksAltShiftReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true); - this.getInputMap(c).put(ksAltShiftReleased, "ENLARGE_RELEASE"); + KeyStroke ksAltEReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true); + this.getInputMap(c).put(ksAltEReleased, "ENLARGE_RELEASE"); + KeyStroke ksAltSReleased = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK, true); + this.getInputMap(c).put(ksAltSReleased, "ENLARGE_RELEASE"); this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { ActionCallback callback = Plugins.getInstance().getActionCallback(); - ((MageActionCallback)callback).hideCard(); + ((MageActionCallback)callback).hideEnlargedCard(); } }); + btnSwitchHands.setText("Switch Hands"); btnSwitchHands.addMouseListener(new MouseAdapter() { @Override diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index ae58bca459..5a8512126f 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -34,13 +34,16 @@ import mage.client.util.ImageHelper; import mage.client.util.gui.ArrowBuilder; import mage.client.util.gui.GuiDisplayUtil; import mage.components.CardInfoPane; +import mage.constants.EnlargeMode; import mage.remote.Session; import mage.utils.ThreadUtils; import mage.view.CardView; +import mage.view.PermanentView; import mage.view.PlayerView; import mage.view.SimpleCardsView; import org.apache.log4j.Logger; import org.jdesktop.swingx.JXPanel; +import org.mage.plugins.card.images.ImageCache; public class MageActionCallback implements ActionCallback { @@ -54,13 +57,16 @@ public class MageActionCallback implements ActionCallback { private CardView popupCard; private TransferData popupData; private JComponent cardInfoPane; - private volatile boolean state = false; - private boolean enlarged = false; + private volatile boolean popupTextWindowOpen = false; + private volatile boolean enlargedImageWindowOpen = false; + // shows the alternative card the normal card or the alternative card (copy source, other flip side, other transformed side) + private volatile EnlargeMode enlargeMode; private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(1); private ScheduledFuture hideTimeout; public MageActionCallback() { + enlargeMode = EnlargeMode.NORMAL; } public void setCardPreviewComponent(BigCard bigCard) { @@ -227,7 +233,7 @@ public class MageActionCallback implements ActionCallback { public void run() { ThreadUtils.sleep(300); - if (popupCard == null || !popupCard.equals(data.card) || session == null || !state || enlarged) { + if (popupCard == null || !popupCard.equals(data.card) || session == null || !popupTextWindowOpen || enlargedImageWindowOpen) { return; } @@ -248,7 +254,7 @@ public class MageActionCallback implements ActionCallback { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - if (!state || enlarged) { + if (!popupTextWindowOpen || enlargedImageWindowOpen) { return; } popupContainer.setVisible(true); @@ -265,7 +271,7 @@ public class MageActionCallback implements ActionCallback { } @Override - public void mouseMoved(MouseEvent e, TransferData data) { + public void mouseMoved(MouseEvent e, TransferData transferData) { if (!Plugins.getInstance().isCardPluginLoaded()) { return; } @@ -273,26 +279,32 @@ public class MageActionCallback implements ActionCallback { return; } - MageCard card = (MageCard) data.component; - if (!state || card.getOriginal().getId() != bigCard.getCardId()) { + MageCard mageCard = (MageCard) transferData.component; + if (!popupTextWindowOpen || mageCard.getOriginal().getId() != bigCard.getCardId()) { if (bigCard.getWidth() > 0) { synchronized (MageActionCallback.class) { - if (!state || card.getOriginal().getId() != bigCard.getCardId()) { - if (!state) { + if (!popupTextWindowOpen || mageCard.getOriginal().getId() != bigCard.getCardId()) { + if (!popupTextWindowOpen) { bigCard.resetCardId(); } - state = true; - Image image = card.getImage(); - displayCardInfo(card, image, bigCard); + popupTextWindowOpen = true; + Image image = mageCard.getImage(); + displayCardInfo(mageCard, image, bigCard); } } } else { - state = true; + popupTextWindowOpen = true; + } + if (enlargedImageWindowOpen) { + displayEnlargedCard(mageCard.getOriginal(), transferData); } - displayCard(card.getOriginal(), data); } } + /** + * Hides the text popup window + * + */ @Override public void hidePopup() { this.popupCard = null; @@ -306,6 +318,7 @@ public class MageActionCallback implements ActionCallback { if (session == null) { return; } + // set enlarged card display to visible = false Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); popupContainer.setVisible(false); } catch (Exception e2) { @@ -325,7 +338,7 @@ public class MageActionCallback implements ActionCallback { public void hideAll(UUID gameId) { hidePopup(); startHideTimeout(); - this.state = false; + this.popupTextWindowOpen = false; if (gameId != null) { ArrowBuilder.getBuilder().removeArrowsByType(gameId, ArrowBuilder.Type.TARGET); ArrowBuilder.getBuilder().removeArrowsByType(gameId, ArrowBuilder.Type.PAIRED); @@ -334,26 +347,49 @@ public class MageActionCallback implements ActionCallback { } } - public void enlargeCard() { - if (!enlarged) { - enlarged = true; - CardView card = null; - if (popupData != null) { - card = popupData.card; + @Override + public void mouseWheelMoved(MouseWheelEvent e, TransferData transferData) { + if (enlargedImageWindowOpen) { + hideEnlargedCard(); + return; + } + int notches = e.getWheelRotation(); + if (notches < 0) { + // move up - show normal image + enlargeCard(EnlargeMode.NORMAL); + + } else { + // move down - show alternate image + enlargeCard(EnlargeMode.ALTERNATE); + } + } + + /** + * Show the big card image on mouse position while hoovering over a card + * + * @param showAlternative defines if the original image (if it's a copied card) or the opposite side of a transformable card will be shown + */ + public void enlargeCard(EnlargeMode showAlternative) { + if (!enlargedImageWindowOpen) { + this.enlargeMode = showAlternative; + CardView cardView = null; + if (popupData != null) { + cardView = popupData.card; } - if (this.state) { + if (this.popupTextWindowOpen) { hidePopup(); } - if (card != null) { - displayCard(card, popupData); + if (cardView != null) { + enlargedImageWindowOpen = true; + displayEnlargedCard(cardView, popupData); } } } - public void hideCard() { - if (enlarged) { - enlarged = false; + public void hideEnlargedCard() { + if (enlargedImageWindowOpen) { + enlargedImageWindowOpen = false; try { Component cardPreviewContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER); cardPreviewContainer.setVisible(false); @@ -363,52 +399,59 @@ public class MageActionCallback implements ActionCallback { } } - @Override - public void mouseWheelMoved(MouseWheelEvent e, TransferData data) { - int notches = e.getWheelRotation(); - if (notches < 0) { - enlargeCard(); - } else { - hideCard(); - } - } - private void displayCard(final CardView card, final TransferData data) { - if (!enlarged) { - return; - - } + private void displayEnlargedCard(final CardView cardView, final TransferData transferData) { ThreadUtils.threadPool2.submit(new Runnable() { @Override public void run() { - if (card == null) { + if (cardView == null) { return; } - try { - if (!enlarged) { + if (!enlargedImageWindowOpen) { return; } - - Component parentComponent = SwingUtilities.getRoot(data.component); + Component parentComponent = SwingUtilities.getRoot(transferData.component); Point parentPoint = parentComponent.getLocationOnScreen(); final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER); - Component cardPreview = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_PANE); - if (cardPreview != null) { - Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40); - location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreview, parentComponent); + Component cardPreviewPane = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_PANE); + if (cardPreviewPane != null) { + Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40); + location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent); location.translate(-parentPoint.x, -parentPoint.y); popupContainer.setLocation(location); popupContainer.setVisible(true); + + MageCard mageCard = (MageCard) transferData.component; + Image image = null; + switch (enlargeMode) { + case COPY: + if (cardView instanceof PermanentView) { + image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal()); + } + break; + case ALTERNATE: + if (cardView.getAlternateName() != null) { + if (cardView instanceof PermanentView && !cardView.isFlipCard() && !cardView.canTransform() && ((PermanentView) cardView).isCopy()) { + image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal()); + } else { + image = ImageCache.getImageOriginalAlternateName(cardView); + } + } + break; + } + if (image == null) { + image = mageCard.getImage(); + } + // shows the card in the popup Container + BigCard bigCard = (BigCard)cardPreviewPane; + displayCardInfo(mageCard, image, bigCard); + - MageCard card = (MageCard) data.component; - Image image = card.getImage(); - BigCard bigCard = (BigCard)cardPreview; - displayCardInfo(card, image, bigCard); } else { - Logger.getLogger(MageActionCallback.class).warn("No Card preview Pane in Mage Frame defined. Card: " + card.getName()); + logger.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName()); } } catch (Exception e) { @@ -418,21 +461,22 @@ public class MageActionCallback implements ActionCallback { }); } - private void displayCardInfo(MageCard card, Image image, BigCard bigCard) { + private void displayCardInfo(MageCard mageCard, Image image, BigCard bigCard) { if (image != null && image instanceof BufferedImage) { // XXX: scaled to fit width image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth()); - bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules(), false); - if (card.getOriginal().isAbility()) { + bigCard.setCard(mageCard.getOriginal().getId(), enlargeMode, image, mageCard.getOriginal().getRules()); + // if it's an ability, show only the ability text as overlay + if (mageCard.getOriginal().isAbility()) { bigCard.showTextComponent(); } else { bigCard.hideTextComponent(); } } else { - JXPanel panel = GuiDisplayUtil.getDescription(card.getOriginal(), bigCard.getWidth(), bigCard.getHeight()); + JXPanel panel = GuiDisplayUtil.getDescription(mageCard.getOriginal(), bigCard.getWidth(), bigCard.getHeight()); panel.setVisible(true); bigCard.hideTextComponent(); - bigCard.addJXPanel(card.getOriginal().getId(), panel); + bigCard.addJXPanel(mageCard.getOriginal().getId(), panel); } } @@ -441,7 +485,7 @@ public class MageActionCallback implements ActionCallback { hideTimeout = timeoutExecutor.schedule(new Runnable() { @Override public void run() { - hideCard(); + hideEnlargedCard(); } }, 700, TimeUnit.MILLISECONDS); } diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index 62d3b03782..8c019ffb82 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -379,7 +379,8 @@ public class CallbackClientImpl implements CallbackClient { switch (usedPanel.getChatType()) { case GAME: usedPanel.receiveMessage("", new StringBuilder("You may use hot keys to play faster:") - .append("\nTurn Mousewheel - Show big image of card your mousepointer hovers over") + .append("\nTurn mousewheel up (ALT-e) - enlarge image of card the mousepointer hovers over") + .append("\nTurn mousewheel down (ALT-s) - enlarge original/alternate image of card the mousepointer hovers over") .append("\nF2 - Confirm \"Ok\", \"Yes\" or \"Done\" button") .append("\nF4 - Skip current turn but stop on declare attackers/blockers and something on the stack") .append("\nF9 - Skip everything until your next turn") diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index 0b60e3197f..76297fbdc4 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -24,15 +24,17 @@ import java.util.UUID; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JOptionPane; import javax.swing.JPanel; import mage.cards.MagePermanent; import mage.cards.TextPopup; import mage.cards.action.ActionCallback; import mage.cards.action.TransferData; +import mage.client.plugins.adapters.MageActionCallback; +import mage.client.plugins.impl.Plugins; import mage.client.util.audio.AudioManager; import mage.components.ImagePanel; import mage.constants.CardType; +import mage.constants.EnlargeMode; import mage.utils.CardUtil; import mage.view.AbilityView; import mage.view.CardView; @@ -76,7 +78,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti // for two faced cards public CardView temporary; - private List links = new ArrayList(); + private List links = new ArrayList<>(); public double tappedAngle = 0; public double flippedAngle = 0; @@ -84,6 +86,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti public ImagePanel overlayPanel; public JPanel buttonPanel; public JPanel iconPanel; + public JPanel copyIconPanel; private GlowText titleText; private GlowText ptText; @@ -111,8 +114,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti private boolean transformed; private boolean animationInProgress = false; + private JButton dayNightButton; private JButton tokenButton; + private JButton showCopySourceButton; private boolean displayTitleAnyway; @@ -140,7 +145,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti dayNightButton.setLocation(2, 2); dayNightButton.setSize(25, 25); - buttonPanel.setVisible(this.gameCard.canTransform()); + buttonPanel.setVisible(true); BufferedImage day = ImageManagerImpl.getInstance().getDayImage(); dayNightButton.setIcon(new ImageIcon(day)); @@ -154,9 +159,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti // if card is tapped, no visual transforming is possible (implementation limitation) // if card is permanent, it will be rotated by Mage, so manual rotate should be possible if (animationInProgress || isTapped() || isPermanent) { - if (isPermanent) { - JOptionPane.showMessageDialog(null, "You can't transform cards on battlefield."); - } return; } Animation.transformCard(CardPanel.this, CardPanel.this, true); @@ -183,6 +185,32 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti iconPanel.add(tokenButton); } + // icon to inform about permanent is copying something + if (this.gameCard instanceof PermanentView) { + copyIconPanel = new JPanel(); + copyIconPanel.setLayout(null); + copyIconPanel.setOpaque(false); + add(copyIconPanel); + + showCopySourceButton = new JButton(""); + showCopySourceButton.setLocation(2, 2); + showCopySourceButton.setSize(25, 25); + showCopySourceButton.setToolTipText("This permanent is copying a target. To see original image, push this button or turn mouse wheel down while hoovering with the mouse pointer over the permanent."); + copyIconPanel.setVisible(((PermanentView) this.gameCard).isCopy()); + + showCopySourceButton.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCopyInformIconImage())); + + copyIconPanel.add(showCopySourceButton); + + showCopySourceButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback) callback).enlargeCard(EnlargeMode.COPY); + } + }); + } + setBackground(Color.black); setOpaque(false); @@ -462,6 +490,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti iconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); iconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); } + if (copyIconPanel != null) { + copyIconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); + copyIconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); + } int fontHeight = Math.round(cardHeight * (27f / 680)); boolean showText = (!isAnimationPanel && fontHeight < 12); titleText.setVisible(showText); @@ -634,7 +666,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti @Override public void update(CardView card) { - if (isPermanent) { + if (isPermanent && (card instanceof PermanentView)) { boolean needsTapping = isTapped() != ((PermanentView) card).isTapped(); boolean needsFlipping = isFlipped() != ((PermanentView) card).isFlipped(); if (needsTapping || needsFlipping) { @@ -648,6 +680,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti Animation.transformCard(this, this, card.isTransformed()); } } + if (card.canTransform()) { + dayNightButton.setVisible(!isPermanent); + } + if (CardUtil.isCreature(card) && CardUtil.isPlaneswalker(card)) { ptText.setText(card.getPower() + "/" + card.getToughness() + " (" + card.getLoyalty() + ")"); } else if (CardUtil.isCreature(card)) { @@ -658,6 +694,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti ptText.setText(""); } setText(card); + + boolean updateImage = !gameCard.getName().equals(card.getName()); // update after e.g. turning a night/day card this.gameCard = card; String cardType = getType(card); @@ -668,7 +706,18 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti } else { overlayPanel.setVisible(false); } - + if (updateImage) { + updateImage(); + if (card.canTransform()) { + BufferedImage transformIcon; + if (card.isTransformed()) { + transformIcon = ImageManagerImpl.getInstance().getNightImage(); + } else { + transformIcon = ImageManagerImpl.getInstance().getDayImage(); + } + dayNightButton.setIcon(new ImageIcon(transformIcon)); + } + } repaint(); } @@ -859,8 +908,9 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti @Override public void update(PermanentView card) { - update((CardView) card); this.hasSickness = card.hasSummoningSickness(); + this.copyIconPanel.setVisible(card.isCopy()); + update((CardView) card); } @Override @@ -883,7 +933,9 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti this.transformed = !this.transformed; if (transformed) { BufferedImage night = ImageManagerImpl.getInstance().getNightImage(); - dayNightButton.setIcon(new ImageIcon(night)); + if (dayNightButton != null) { // if transformbable card is copied, button can be null + dayNightButton.setIcon(new ImageIcon(night)); + } if (this.gameCard.getSecondCardFace() == null) { log.error("no second side for card to transform!"); return; @@ -892,17 +944,21 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti this.temporary = this.gameCard; update(this.gameCard.getSecondCardFace()); } - updateImage(); } else { BufferedImage day = ImageManagerImpl.getInstance().getDayImage(); - dayNightButton.setIcon(new ImageIcon(day)); + if (dayNightButton != null) { // if transformbable card is copied, button can be null + dayNightButton.setIcon(new ImageIcon(day)); + } if (!isPermanent) { // use only for custom transformation (when pressing day-night button) this.gameCard = this.temporary; this.temporary = null; update(this.gameCard); - } - updateImage(); + } } + String temp = this.gameCard.getAlternateName(); + this.gameCard.setAlternateName(this.gameCard.getOriginalName()); + this.gameCard.setOriginalName(temp); + updateImage(); } @Override diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java index a76e2120c2..ed76ae4f3a 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java @@ -62,7 +62,7 @@ public class CardPluginImpl implements CardPlugin { private int cardWidth, cardHeight; private int extraCardSpacingX, cardSpacingX, cardSpacingY; private int stackSpacingX, stackSpacingY; - private List rows = new ArrayList(); + private List rows = new ArrayList<>(); @Init public void init() { @@ -183,7 +183,7 @@ public class CardPluginImpl implements CardPlugin { int afterCreaturesIndex = rows.size(); wrap(lands, rows, afterCreaturesIndex); // Store the current rows and others. - List storedRows = new ArrayList(rows.size()); + List storedRows = new ArrayList<>(rows.size()); for (Row row : rows) { storedRows.add((Row) row.clone()); } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java index 27843d7fb6..9a1a1d219b 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java @@ -7,21 +7,21 @@ import com.mortennobel.imagescaling.ResampleOp; import de.schlichtherle.truezip.file.TFile; import de.schlichtherle.truezip.file.TFileInputStream; import de.schlichtherle.truezip.file.TFileOutputStream; -import mage.client.dialog.PreferencesDialog; -import mage.view.CardView; -import org.apache.log4j.Logger; -import org.mage.plugins.card.constants.Constants; -import org.mage.plugins.card.dl.sources.DirectLinksForDownload; -import org.mage.plugins.card.utils.CardImageUtils; - -import javax.imageio.ImageIO; -import java.awt.*; +import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.imageio.ImageIO; +import mage.client.dialog.PreferencesDialog; +import mage.view.CardView; +import org.apache.log4j.Logger; +import org.mage.plugins.card.constants.Constants; +import org.mage.plugins.card.dl.sources.DirectLinksForDownload; +import org.mage.plugins.card.utils.CardImageUtils; /** * This class stores ALL card images in a cache with soft values. this means @@ -167,10 +167,20 @@ public class ImageCache { if (card.getUsesVariousArt()) { key += "#usesVariousArt"; } - // log.debug("#key: " + key); + // log.warn("#key: " + key); return getImage(key); } + public static BufferedImage getImageOriginalAlternateName(CardView card) { + String key = getKeyAlternateName(card, card.getAlternateName()); + if (card.getUsesVariousArt()) { + key += "#usesVariousArt"; + } + // log.warn("#key: " + key); + return getImage(key); + } + + /** * Returns the Image corresponding to the key */ @@ -205,6 +215,18 @@ public class ImageCache { return sb.toString(); } + /** + * Returns the map key for the flip image of a card, without any suffixes for the image size. + */ + private static String getKeyAlternateName(CardView card, String alternateName) { + StringBuilder sb = new StringBuilder(alternateName).append("#"); + sb.append(card.getExpansionSetCode()).append("#"); + sb.append(card.getType()).append("#"); + sb.append(card.getCardNumber()).append("#"); + sb.append(card.getTokenSetCode() == null ? "":card.getTokenSetCode()); + return sb.toString(); + } + /** * Load image from file * @@ -251,6 +273,7 @@ public class ImageCache { /** * Returns an image scaled to the size given + * @param original * @return */ public static BufferedImage getNormalSizeImage(BufferedImage original) { @@ -289,6 +312,9 @@ public class ImageCache { /** * Returns an image scaled to the size appropriate for the card picture * panel + * @param original + * @param sizeNeed + * @return */ public static BufferedImage getResizedImage(BufferedImage original, Rectangle sizeNeed) { ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height); @@ -298,6 +324,10 @@ public class ImageCache { /** * Returns the image appropriate to display the card in the picture panel + * @param card + * @param width + * @param height + * @return */ public static BufferedImage getImage(CardView card, int width, int height) { if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) { diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java index fd8a65891e..30ad68bb0e 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java @@ -13,6 +13,7 @@ public interface ImageManager { Image getNightImage(); Image getTokenIconImage(); + Image getCopyInformIconImage(); Image getDlgAcceptButtonImage(); Image getDlgActiveAcceptButtonImage(); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java index a161c643c4..7192d912f7 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java @@ -106,6 +106,15 @@ public class ImageManagerImpl implements ImageManager { return imageTokenIcon; } + @Override + public BufferedImage getCopyInformIconImage() { + if (imageCopyIcon == null) { + Image image = getImageFromResourceTransparent("/card/copy.png", Color.WHITE, new Rectangle(20, 20)); + imageCopyIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return imageCopyIcon; + } + @Override public Image getDlgCancelButtonImage() { if (imageDlgCancelButton == null) { @@ -226,6 +235,7 @@ public class ImageManagerImpl implements ImageManager { private static BufferedImage imageNight; private static BufferedImage imageTokenIcon; + private static BufferedImage imageCopyIcon; private static BufferedImage imageDlgAcceptButton; private static BufferedImage imageDlgActiveAcceptButton; diff --git a/Mage.Client/src/main/resources/card/copy.png b/Mage.Client/src/main/resources/card/copy.png new file mode 100644 index 0000000000000000000000000000000000000000..8070be19aeaa89057808bfdba38dc19a14c5472c GIT binary patch literal 545 zcmV++0^a?JP)K@fac_JDa7x&pS4*h_ccZia5RdtcMEA-EM5nifUz ztKDvII?9ld9Rm#(sv;&kx-zc2j^&P#by&E;WowNPM2lDyfU-N{$hsB`20sjcXpjKF zHryTH6*!Y5=`9+Kj=~=%gu`K9p-{N|Ib(=oqTVSm1v~&Zz+)^H6H=*EGY|;W@jS`i zqkR?l>>)H!ZvO&ptF!kFF$UG8s=i9z$M)#hG~hJA)fN z5+TB?SF6?h$z;--%jM{$31E)x-vcX7W|=;+TrQWF5{ZPasw(xLAMkQY_sp`@pMykY z&StYSilR`hHEvqQ0U10SPX0EtsNpJWW*6693*gxuIC>^_E6eg2Be6frW|q(Aula81 jJIglgS2ysp{4Kx$)djYr`j?Xt00000NkvXXu0mjf>bCAq literal 0 HcmV?d00001 diff --git a/Mage.Common/src/mage/cards/MageCard.java b/Mage.Common/src/mage/cards/MageCard.java index 92089bc922..9712a30f53 100644 --- a/Mage.Common/src/mage/cards/MageCard.java +++ b/Mage.Common/src/mage/cards/MageCard.java @@ -1,11 +1,10 @@ package mage.cards; -import mage.cards.action.ActionCallback; -import mage.view.CardView; - import java.awt.Image; import java.util.UUID; import javax.swing.JPanel; +import mage.cards.action.ActionCallback; +import mage.view.CardView; public abstract class MageCard extends JPanel { private static final long serialVersionUID = 6089945326434301879L; diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 19d12d6550..9563425468 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -87,6 +87,11 @@ public class CardView extends SimpleCardView { protected CardView secondCardFace; protected boolean transformed; + protected boolean flipCard; + + protected String alternateName; + protected String originalName; + protected boolean isSplitCard; protected String leftSplitName; protected ManaCosts leftSplitCosts; @@ -167,7 +172,7 @@ public class CardView extends SimpleCardView { this.superTypes = card.getSupertype(); this.color = card.getColor(); this.canTransform = card.canTransform(); - + this.flipCard = card.isFlipCard(); if (card instanceof PermanentToken) { this.isToken = true; @@ -190,13 +195,20 @@ public class CardView extends SimpleCardView { this.isToken = false; } if (card.getCounters() != null && !card.getCounters().isEmpty()) { - counters = new ArrayList(); + counters = new ArrayList<>(); for (Counter counter: card.getCounters().values()) { counters.add(new CounterView(counter)); } } if (card.getSecondCardFace() != null) { this.secondCardFace = new CardView(card.getSecondCardFace()); + this.alternateName = secondCardFace.getName(); + this.originalName = card.getName(); + } + this.flipCard = card.isFlipCard(); + if (card.isFlipCard() && card.getFlipCardName() != null) { + this.alternateName = card.getFlipCardName(); + this.originalName = card.getName(); } if (card instanceof Spell) { @@ -258,7 +270,7 @@ public class CardView extends SimpleCardView { if (this.rarity == null && object instanceof StackAbility) { StackAbility stackAbility = (StackAbility)object; this.rarity = Rarity.NA; - this.rules = new ArrayList(); + this.rules = new ArrayList<>(); this.rules.add(stackAbility.getRule()); if (stackAbility.getZone().equals(Zone.COMMAND)) { this.expansionSetCode = stackAbility.getExpansionSetCode(); @@ -298,15 +310,15 @@ public class CardView extends SimpleCardView { private void fillEmpty() { this.name = "Face Down"; - this.rules = new ArrayList(); + this.rules = new ArrayList<>(); this.power = ""; this.toughness = ""; this.loyalty = ""; - this.cardTypes = new ArrayList(); - this.subTypes = new ArrayList(); - this.superTypes = new ArrayList(); + this.cardTypes = new ArrayList<>(); + this.subTypes = new ArrayList<>(); + this.superTypes = new ArrayList<>(); this.color = new ObjectColor(); - this.manaCost = new ArrayList(); + this.manaCost = new ArrayList<>(); this.convertedManaCost = 0; this.rarity = Rarity.COMMON; this.expansionSetCode = ""; @@ -338,7 +350,7 @@ public class CardView extends SimpleCardView { if (target.isChosen()) { for (UUID targetUUID : target.getTargets()) { if (this.targets == null) { - this.targets = new ArrayList(); + this.targets = new ArrayList<>(); } this.targets.add(targetUUID); } @@ -483,6 +495,32 @@ public class CardView extends SimpleCardView { return this.isSplitCard; } + /** + * Name of the other side (transform), flipped, or copying card name. + * + * @return name + */ + public String getAlternateName() { + return alternateName; + } + + /** + * Stores the name of the original name, to provide it for a flipped or transformed or copying card + * + * @return + */ + public String getOriginalName() { + return originalName; + } + + public void setAlternateName(String alternateName) { + this.alternateName = alternateName; + } + + public void setOriginalName(String originalName) { + this.originalName = originalName; + } + public String getLeftSplitName() { return leftSplitName; } @@ -554,5 +592,9 @@ public class CardView extends SimpleCardView { public boolean isControlledByOwner() { return controlledByOwner; } + + public boolean isFlipCard() { + return flipCard; + } } diff --git a/Mage.Common/src/mage/view/PermanentView.java b/Mage.Common/src/mage/view/PermanentView.java index 0715d8efc3..6d80c34314 100644 --- a/Mage.Common/src/mage/view/PermanentView.java +++ b/Mage.Common/src/mage/view/PermanentView.java @@ -43,13 +43,14 @@ public class PermanentView extends CardView { private static final long serialVersionUID = 1L; private boolean tapped; - private boolean flipped; - private boolean phasedIn; - private boolean faceUp; - private boolean summoningSickness; - private int damage; + private final boolean flipped; + private final boolean phasedIn; + private final boolean faceUp; + private final boolean summoningSickness; + private final int damage; private List attachments; - private CardView original; + private final CardView original; + private final boolean copy; public PermanentView(Permanent permanent, Card card) { super(permanent); @@ -61,7 +62,7 @@ public class PermanentView extends CardView { this.summoningSickness = permanent.hasSummoningSickness(); this.damage = permanent.getDamage(); if (permanent.getAttachments().size() > 0) { - attachments = new ArrayList(); + attachments = new ArrayList<>(); attachments.addAll(permanent.getAttachments()); } if (isToken()) { @@ -77,6 +78,19 @@ public class PermanentView extends CardView { } } this.transformed = permanent.isTransformed(); + this.copy = permanent.isCopy(); + + // for fipped, transformed or copied cards, switch the names + if (!original.getName().equals(this.getName())) { + if (permanent.isCopy() && permanent.isFlipCard()) { + this.alternateName = permanent.getFlipCardName(); + this.originalName = this.getName(); + } else { + this.alternateName = original.getName(); + this.originalName = this.getName(); + } + } + } public boolean isTapped() { @@ -91,6 +105,10 @@ public class PermanentView extends CardView { return flipped; } + public boolean isCopy() { + return copy; + } + public boolean isPhasedIn() { return phasedIn; } diff --git a/Mage/src/mage/MageObjectImpl.java b/Mage/src/mage/MageObjectImpl.java index ca7e091a7c..94bc3ac2c4 100644 --- a/Mage/src/mage/MageObjectImpl.java +++ b/Mage/src/mage/MageObjectImpl.java @@ -28,7 +28,9 @@ package mage; -import mage.constants.CardType; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import mage.abilities.Abilities; import mage.abilities.AbilitiesImpl; import mage.abilities.Ability; @@ -36,12 +38,9 @@ import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.keyword.ChangelingAbility; +import mage.constants.CardType; import mage.game.Game; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - public abstract class MageObjectImpl> implements MageObject { protected UUID objectId; @@ -49,9 +48,9 @@ public abstract class MageObjectImpl> implements Mag protected String name; protected ManaCosts manaCost; protected ObjectColor color; - protected List cardType = new ArrayList(); - protected List subtype = new ArrayList(); - protected List supertype = new ArrayList(); + protected List cardType = new ArrayList<>(); + protected List subtype = new ArrayList<>(); + protected List supertype = new ArrayList<>(); protected Abilities abilities; protected String text; protected MageInt power; @@ -70,8 +69,8 @@ public abstract class MageObjectImpl> implements Mag power = new MageInt(0); toughness = new MageInt(0); color = new ObjectColor(); - manaCost = new ManaCostsImpl(""); - abilities = new AbilitiesImpl(); + manaCost = new ManaCostsImpl<>(""); + abilities = new AbilitiesImpl<>(); } public MageObjectImpl(final MageObjectImpl object) { diff --git a/Mage/src/mage/abilities/effects/common/CopyEffect.java b/Mage/src/mage/abilities/effects/common/CopyEffect.java index 6cdee302f9..31dea81726 100644 --- a/Mage/src/mage/abilities/effects/common/CopyEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyEffect.java @@ -36,7 +36,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import java.util.UUID; -import mage.cards.Card; import mage.game.permanent.PermanentCard; /** @@ -73,7 +72,6 @@ public class CopyEffect extends ContinuousEffectImpl { if (permanent == null) { return false; } - permanent.setName(target.getName()); permanent.getColor().setColor(target.getColor()); permanent.getManaCost().clear(); @@ -97,9 +95,13 @@ public class CopyEffect extends ContinuousEffectImpl { permanent.getPower().setValue(target.getPower().getValue()); permanent.getToughness().setValue(target.getToughness().getValue()); if (target instanceof Permanent) { - permanent.setTransformed(((Permanent)target).isTransformed()); - permanent.setSecondCardFace(((Permanent) target).getSecondCardFace()); + Permanent targetPermanent = (Permanent) target; + permanent.setTransformed(targetPermanent.isTransformed()); + permanent.setSecondCardFace(targetPermanent.getSecondCardFace()); + permanent.setFlipCard(targetPermanent.isFlipCard()); + permanent.setFlipCardName(targetPermanent.getFlipCardName()); } + // to get the image of the copied permanent copy number und expansionCode if (target instanceof PermanentCard) { permanent.setCardNumber(((PermanentCard) target).getCard().getCardNumber()); diff --git a/Mage/src/mage/abilities/effects/common/CopyTokenEffect.java b/Mage/src/mage/abilities/effects/common/CopyTokenEffect.java index a8adf33985..d24348fa6e 100644 --- a/Mage/src/mage/abilities/effects/common/CopyTokenEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyTokenEffect.java @@ -2,7 +2,11 @@ package mage.abilities.effects.common; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.SubLayer; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.permanent.token.Token; diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java index c18dd290da..7904a7ac7c 100644 --- a/Mage/src/mage/cards/Card.java +++ b/Mage/src/mage/cards/Card.java @@ -64,6 +64,8 @@ public interface Card extends MageObject { boolean isFaceDown(); boolean isFlipCard(); String getFlipCardName(); + void setFlipCard(boolean flipCard); + void setFlipCardName(String flipCardName); boolean isSplitCard(); boolean canTransform(); diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index 4fb0e7328b..3c9f89aaad 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -55,7 +55,10 @@ import mage.constants.TimingRule; import static mage.constants.Zone.EXILED; import mage.game.command.Commander; - +/** + * + * @param + */ public abstract class CardImpl> extends MageObjectImpl implements Card { private static final long serialVersionUID = 1L; @@ -63,7 +66,7 @@ public abstract class CardImpl> extends MageObjectImpl protected UUID ownerId; protected int cardNumber; - protected List watchers = new ArrayList(); + protected List watchers = new ArrayList<>(); protected String expansionSetCode; protected String tokenSetCode; protected Rarity rarity; @@ -127,7 +130,7 @@ public abstract class CardImpl> extends MageObjectImpl expansionSetCode = card.expansionSetCode; rarity = card.rarity; for (Watcher watcher: (List)card.watchers) { - this.watchers.add(watcher.copy()); + watchers.add(watcher.copy()); } faceDown = card.faceDown; @@ -138,14 +141,14 @@ public abstract class CardImpl> extends MageObjectImpl } zoneChangeCounter = card.zoneChangeCounter; if (card.info != null) { - info = new HashMap(); + info = new HashMap<>(); info.putAll(card.info); } - this.flipCard = card.flipCard; - this.flipCardName = card.flipCardName; - this.splitCard = card.splitCard; - this.usesVariousArt = card.usesVariousArt; - this.counters = card.counters.copy(); + flipCard = card.flipCard; + flipCardName = card.flipCardName; + splitCard = card.splitCard; + usesVariousArt = card.usesVariousArt; + counters = card.counters.copy(); } @Override @@ -210,7 +213,7 @@ public abstract class CardImpl> extends MageObjectImpl System.out.println("Exception in rules generation for card: " + this.getName()); e.printStackTrace(); } - ArrayList rules = new ArrayList(); + ArrayList rules = new ArrayList<>(); rules.add("Exception occured in rules generation"); return rules; } @@ -562,15 +565,27 @@ public abstract class CardImpl> extends MageObjectImpl return flipCard; } + @Override + public String getFlipCardName() { + return flipCardName; + } + + @Override + public void setFlipCard(boolean flipCard) { + this.flipCard = flipCard; + } + + @Override + public void setFlipCardName(String flipCardName) { + this.flipCardName = flipCardName; + } + + @Override public boolean isSplitCard() { return splitCard; } - @Override - public String getFlipCardName() { - return flipCardName; - } @Override public int getZoneChangeCounter() { diff --git a/Mage/src/mage/constants/EnlargeMode.java b/Mage/src/mage/constants/EnlargeMode.java new file mode 100644 index 0000000000..0c83f215a9 --- /dev/null +++ b/Mage/src/mage/constants/EnlargeMode.java @@ -0,0 +1,11 @@ +package mage.constants; + +/** + * Controlls the display handling of the enlarged image of the card / permanent + * + * @author LevelX2 + */ +public enum EnlargeMode { + + NORMAL, ALTERNATE, COPY +} diff --git a/Mage/src/mage/game/permanent/PermanentCard.java b/Mage/src/mage/game/permanent/PermanentCard.java index 02b4d1ef96..bad546062d 100644 --- a/Mage/src/mage/game/permanent/PermanentCard.java +++ b/Mage/src/mage/game/permanent/PermanentCard.java @@ -78,11 +78,9 @@ public class PermanentCard extends PermanentImpl { @Override public void reset(Game game) { - // when the permanent is reset copy all original values from the card + // when the permanent is reset, copy all original values from the card // must copy card each reset so that the original values don't get modified - // game.getState().getContinuousEffects().removeGainedEffectsForSource(objectId); - // game.getState().resetTriggersForSourceId(this.getId()); - copyFromCard(card, game); + copyFromCard(card); super.reset(game); } @@ -98,16 +96,6 @@ public class PermanentCard extends PermanentImpl { this.manaCost = card.getManaCost().copy(); this.power = card.getPower().copy(); this.toughness = card.getToughness().copy(); - /*if (card instanceof LevelerCard) { - LevelAbility level = ((LevelerCard) card).getLevel(this.getCounters().getCount(CounterType.LEVEL)); - if (level != null) { - this.power.setValue(level.getPower()); - this.toughness.setValue(level.getToughness()); - for (Ability ability : level.getAbilities()) { - this.addAbility(ability); - } - } - }*/ if (card instanceof PermanentCard) { this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters; } @@ -125,46 +113,8 @@ public class PermanentCard extends PermanentImpl { secondSideCard = card.getSecondCardFace(); nightCard = card.isNightCard(); } - } - - protected void copyFromCard(Card card, Game game) { - this.name = card.getName(); - // this.removeAllAbilities(objectId, game); - this.abilities.clear(); - this.abilities.addAll(card.getAbilities()); - this.abilities.setControllerId(this.controllerId); - this.cardType.clear(); - this.cardType.addAll(card.getCardType()); - this.color = card.getColor().copy(); - this.manaCost = card.getManaCost().copy(); - this.power = card.getPower().copy(); - this.toughness = card.getToughness().copy(); - /*if (card instanceof LevelerCard) { - LevelAbility level = ((LevelerCard) card).getLevel(this.getCounters().getCount(CounterType.LEVEL)); - if (level != null) { - this.power.setValue(level.getPower()); - this.toughness.setValue(level.getToughness()); - for (Ability ability : level.getAbilities()) { - this.addAbility(ability, game); - } - } - }*/ - if (card instanceof PermanentCard) { - this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters; - } - this.subtype.clear(); - this.subtype.addAll(card.getSubtype()); - this.supertype.clear(); - this.supertype.addAll(card.getSupertype()); - this.expansionSetCode = card.getExpansionSetCode(); - this.rarity = card.getRarity(); - this.cardNumber = card.getCardNumber(); - - canTransform = card.canTransform(); - if (canTransform) { - secondSideCard = card.getSecondCardFace(); - nightCard = card.isNightCard(); - } + this.flipCard = card.isFlipCard(); + this.flipCardName = card.getFlipCardName(); } public Card getCard() { diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index ab5b16e25d..6d90954cf6 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -626,6 +626,17 @@ public class Spell> implements StackObject, Card { return false; } + @Override + public void setFlipCard(boolean flipCard) { + throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setFlipCardName(String flipCardName) { + throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates. + } + + @Override public Spell copy() { return new Spell(this);