Displaying top revealed card in client. PlayWithTheTopCardRevealedEffect.

This commit is contained in:
magenoxx 2011-08-27 16:30:06 +04:00
parent 8b415e2296
commit 31d849ef46
9 changed files with 160 additions and 20 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -96,6 +96,8 @@ public class Plugins implements MagePlugins {
return new Card(card, bigCard, Config.dimensions, gameId);
}
}
@Override
public boolean isCardPluginLoaded() {

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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<String>();

View file

@ -57,6 +57,7 @@ public class PlayerView implements Serializable {
private ManaPoolView manaPool;
private SimpleCardsView graveyard = new SimpleCardsView();
private Map<UUID, PermanentView> battlefield = new HashMap<UUID, PermanentView>();
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;
}
}

View file

@ -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<PlayWithTheTopCardRevealedEffect> {
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);
}
}

View file

@ -101,6 +101,8 @@ public interface Player extends MageItem, Copyable<Player> {
public boolean hasLeft();
public ManaPool getManaPool();
public Set<UUID> getInRange();
public boolean isTopCardRevealed();
public void setTopCardRevealed(boolean topCardRevealed);
/**
* Returns a set of players which turns under you control.