From 31d849ef46452a7d387597a4c45f1fe4714b154a Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sat, 27 Aug 2011 16:30:06 +0400 Subject: [PATCH] Displaying top revealed card in client. PlayWithTheTopCardRevealedEffect. --- .../src/main/java/mage/client/cards/Card.java | 12 +++- .../java/mage/client/game/PlayerPanelExt.java | 36 +++++++++- .../mage/client/plugins/impl/Plugins.java | 2 + .../java/org/mage/card/arcane/CardPanel.java | 43 +++++++----- Mage.Common/src/mage/cards/MageCard.java | 4 ++ Mage.Common/src/mage/view/CardView.java | 8 +++ Mage.Common/src/mage/view/PlayerView.java | 7 ++ .../PlayWithTheTopCardRevealedEffect.java | 66 +++++++++++++++++++ Mage/src/mage/players/Player.java | 2 + 9 files changed, 160 insertions(+), 20 deletions(-) create mode 100644 Mage/src/mage/abilities/effects/common/continious/PlayWithTheTopCardRevealedEffect.java 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 0574905108..836062a9d8 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.java +++ b/Mage.Client/src/main/java/mage/client/cards/Card.java @@ -78,6 +78,7 @@ import mage.Constants.CardType; import mage.cards.CardDimensions; import mage.cards.MagePermanent; import mage.cards.TextPopup; +import mage.cards.action.ActionCallback; import mage.client.MageFrame; import mage.client.game.PlayAreaPanel; import mage.remote.Session; @@ -205,6 +206,10 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis gSmall.dispose(); } + @Override + public void updateImage() { + } + protected String getText(String cardType) { StringBuilder sb = new StringBuilder(); if (card instanceof StackAbilityView || card instanceof AbilityView) { @@ -500,7 +505,12 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis return null; //To change body of implemented methods use File | Settings | File Templates. } - @Override + @Override + public void updateCallback(ActionCallback callback, UUID gameId) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override public PermanentView getOriginalPermanent() { return null; } diff --git a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java index 1f04aa0310..8cfcb8824c 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java @@ -34,12 +34,16 @@ package mage.client.game; +import mage.cards.MageCard; +import mage.cards.action.ActionCallback; import mage.client.MageFrame; import mage.client.cards.BigCard; import mage.client.components.HoverButton; import mage.client.components.MageRoundPane; import mage.client.components.arcane.ManaSymbols; import mage.client.dialog.ShowCardsDialog; +import mage.client.plugins.adapters.MageActionCallback; +import mage.client.plugins.impl.Plugins; import mage.remote.Session; import mage.client.util.Command; import mage.client.util.Config; @@ -47,8 +51,10 @@ import mage.client.util.ImageHelper; import mage.client.util.gui.BufferedImageBuilder; import mage.components.ImagePanel; import mage.sets.Sets; +import mage.view.CardView; import mage.view.ManaPoolView; import mage.view.PlayerView; +import org.mage.card.arcane.CardPanel; import javax.swing.*; import javax.swing.border.Border; @@ -87,6 +93,8 @@ public class PlayerPanelExt extends javax.swing.JPanel { private static final Border redBorder = new LineBorder(Color.red, 2); private static final Border emptyBorder = BorderFactory.createEmptyBorder(0,0,0,0); + private static final Dimension topCardDimension = new Dimension(40, 56); + /** Creates new form PlayerPanel */ public PlayerPanelExt(boolean me) { initComponents(me); @@ -117,6 +125,25 @@ public class PlayerPanelExt extends javax.swing.JPanel { this.avatar.setBorder(emptyBorder); } + synchronized (this) { + if (player.getTopCard() != null) { + if (topCard == null || !topCard.getId().equals(player.getTopCard().getId())) { + if (topCard == null) { + topCardPanel.setVisible(true); + } + topCard = player.getTopCard(); + topCardPanel.update(topCard); + topCardPanel.updateImage(); + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback)callback).refreshSession(); + topCardPanel.updateCallback(callback, gameId); + } + } else if (topCard != null) { + topCard = null; + topCardPanel.setVisible(false); + } + } + update(player.getManaPool()); } @@ -140,7 +167,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { setLayout(null); setOpaque(false); - MageRoundPane panelBackground = new MageRoundPane(); + panelBackground = new MageRoundPane(); panelBackground.setXOffset(3); panelBackground.setYOffset(3); panelBackground.setLayout(null); @@ -156,6 +183,10 @@ public class PlayerPanelExt extends javax.swing.JPanel { } Image image = ImageHelper.getImageFromResources("/avatars/face" + index + ".jpg"); + topCardPanel = Plugins.getInstance().getMageCard(new CardView(Sets.findCard("Forest")), bigCard, topCardDimension, gameId, true); + topCardPanel.setVisible(false); + panelBackground.add(topCardPanel); + // Avatar BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r); avatar = new HoverButton("player", resized, resized, resized, r); @@ -305,7 +336,10 @@ public class PlayerPanelExt extends javax.swing.JPanel { private ImagePanel hand; private HoverButton grave; private ImagePanel library; + private CardView topCard; + private MageCard topCardPanel; private JButton cheat; + private MageRoundPane panelBackground; private JLabel lifeLabel; private JLabel handLabel; diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index c1dbd014f1..085887e5fe 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -96,6 +96,8 @@ public class Plugins implements MagePlugins { return new Card(card, bigCard, Config.dimensions, gameId); } } + + @Override public boolean isCardPluginLoaded() { 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 db0e793f00..b9e1a243a3 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 @@ -155,8 +155,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti setText(gameCard); setImage(srcImage); setFoil(foil); - } else { - //log.warn("image wasn't found, card=" + gameCard.getName() + ", set=" + gameCard.getExpansionSetCode() + ", cid=" + gameCard.getCardNumber()); } } catch (Exception e) { e.printStackTrace(); @@ -487,22 +485,25 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti } public void updateImage() { - if (!hasImage) { - throw new IllegalStateException("Not implemented"); - //TODO: - /*Util.threadPool.submit(new Runnable() { - public void run () { - //BufferedImage srcImage = ImageCache.getImageOriginal(gameCard); - //BufferedImage srcImage = null; - //tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0; - if (srcImage != null) { - hasImage = true; - setText(gameCard); - setImage(srcImage, srcImage); - } - } - });*/ - } + Util.threadPool.submit(new Runnable() { + public void run() { + try { + tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0; + flippedAngle = isFlipped() ? CardPanel.FLIPPED_ANGLE : 0; + if (gameCard.isFaceDown()) return; + BufferedImage srcImage = ImageCache.getThumbnail(gameCard); + if (srcImage != null) { + hasImage = true; + setText(gameCard); + setImage(srcImage); + } + } catch (Exception e) { + e.printStackTrace(); + } catch (Error err) { + err.printStackTrace(); + } + } + }); } @Override @@ -759,4 +760,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti public PermanentView getOriginalPermanent() { throw new IllegalStateException("Is not permanent."); } + + @Override + public void updateCallback(ActionCallback callback, UUID gameId) { + this.callback = callback; + this.gameId = gameId; + } } diff --git a/Mage.Common/src/mage/cards/MageCard.java b/Mage.Common/src/mage/cards/MageCard.java index 3ae538e4ed..79af5519b8 100644 --- a/Mage.Common/src/mage/cards/MageCard.java +++ b/Mage.Common/src/mage/cards/MageCard.java @@ -1,9 +1,11 @@ package mage.cards; 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 { @@ -18,9 +20,11 @@ public abstract class MageCard extends JPanel { abstract public CardView getOriginal(); abstract public void setCardBounds(int x, int y, int width, int height); abstract public void update(CardView card); + abstract public void updateImage(); abstract public Image getImage(); abstract public void setFoil(boolean foil); abstract public boolean isFoil(); abstract public void setZone(String zone); abstract public String getZone(); + abstract public void updateCallback(ActionCallback callback, UUID gameId); } diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 041b798c96..03ec07bce9 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -145,6 +145,14 @@ public class CardView extends SimpleCardView { super(null, "", 0, false); } + public CardView(boolean empty) { + super(null, "", 0, false); + if (!empty) { + throw new IllegalArgumentException("Not supported."); + } + fillEmpty(); + } + private void fillEmpty() { this.name = "Face Down"; this.rules = new ArrayList(); diff --git a/Mage.Common/src/mage/view/PlayerView.java b/Mage.Common/src/mage/view/PlayerView.java index 99bd372915..799fbe37ca 100644 --- a/Mage.Common/src/mage/view/PlayerView.java +++ b/Mage.Common/src/mage/view/PlayerView.java @@ -57,6 +57,7 @@ public class PlayerView implements Serializable { private ManaPoolView manaPool; private SimpleCardsView graveyard = new SimpleCardsView(); private Map battlefield = new HashMap(); + private CardView topCard; public PlayerView(Player player, GameState state, Game game) { this.playerId = player.getId(); @@ -77,6 +78,8 @@ public class PlayerView implements Serializable { battlefield.put(view.getId(), view); } } + this.topCard = player.isTopCardRevealed() && player.getLibrary().size() > 0 ? + new CardView(player.getLibrary().getFromTop(game)) : null; } private boolean showInBattlefield(Permanent permanent, GameState state) { @@ -136,4 +139,8 @@ public class PlayerView implements Serializable { public boolean hasLeft() { return this.hasLeft; } + + public CardView getTopCard() { + return this.topCard; + } } diff --git a/Mage/src/mage/abilities/effects/common/continious/PlayWithTheTopCardRevealedEffect.java b/Mage/src/mage/abilities/effects/common/continious/PlayWithTheTopCardRevealedEffect.java new file mode 100644 index 0000000000..78bf5fff36 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/continious/PlayWithTheTopCardRevealedEffect.java @@ -0,0 +1,66 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.effects.common.continious; + +import static mage.Constants.*; + +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.players.Player; + +/** + * @author nantuko + */ +public class PlayWithTheTopCardRevealedEffect extends ContinuousEffectImpl { + + public PlayWithTheTopCardRevealedEffect() { + super(Duration.WhileOnBattlefield, Layer.PlayerEffects, SubLayer.NA, Outcome.Detriment); + staticText = "Play with the top card of your library revealed"; + } + + public PlayWithTheTopCardRevealedEffect(final PlayWithTheTopCardRevealedEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player != null) { + player.setTopCardRevealed(true); + return true; + } + return false; + } + + @Override + public PlayWithTheTopCardRevealedEffect copy() { + return new PlayWithTheTopCardRevealedEffect(this); + } + +} \ No newline at end of file diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 9cd884e1b0..63219bc780 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -101,6 +101,8 @@ public interface Player extends MageItem, Copyable { public boolean hasLeft(); public ManaPool getManaPool(); public Set getInRange(); + public boolean isTopCardRevealed(); + public void setTopCardRevealed(boolean topCardRevealed); /** * Returns a set of players which turns under you control.