mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
Displaying top revealed card in client. PlayWithTheTopCardRevealedEffect.
This commit is contained in:
parent
8b415e2296
commit
31d849ef46
9 changed files with 160 additions and 20 deletions
|
@ -78,6 +78,7 @@ import mage.Constants.CardType;
|
||||||
import mage.cards.CardDimensions;
|
import mage.cards.CardDimensions;
|
||||||
import mage.cards.MagePermanent;
|
import mage.cards.MagePermanent;
|
||||||
import mage.cards.TextPopup;
|
import mage.cards.TextPopup;
|
||||||
|
import mage.cards.action.ActionCallback;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.game.PlayAreaPanel;
|
import mage.client.game.PlayAreaPanel;
|
||||||
import mage.remote.Session;
|
import mage.remote.Session;
|
||||||
|
@ -205,6 +206,10 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
||||||
gSmall.dispose();
|
gSmall.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateImage() {
|
||||||
|
}
|
||||||
|
|
||||||
protected String getText(String cardType) {
|
protected String getText(String cardType) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (card instanceof StackAbilityView || card instanceof AbilityView) {
|
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.
|
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() {
|
public PermanentView getOriginalPermanent() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,16 @@
|
||||||
|
|
||||||
package mage.client.game;
|
package mage.client.game;
|
||||||
|
|
||||||
|
import mage.cards.MageCard;
|
||||||
|
import mage.cards.action.ActionCallback;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.cards.BigCard;
|
import mage.client.cards.BigCard;
|
||||||
import mage.client.components.HoverButton;
|
import mage.client.components.HoverButton;
|
||||||
import mage.client.components.MageRoundPane;
|
import mage.client.components.MageRoundPane;
|
||||||
import mage.client.components.arcane.ManaSymbols;
|
import mage.client.components.arcane.ManaSymbols;
|
||||||
import mage.client.dialog.ShowCardsDialog;
|
import mage.client.dialog.ShowCardsDialog;
|
||||||
|
import mage.client.plugins.adapters.MageActionCallback;
|
||||||
|
import mage.client.plugins.impl.Plugins;
|
||||||
import mage.remote.Session;
|
import mage.remote.Session;
|
||||||
import mage.client.util.Command;
|
import mage.client.util.Command;
|
||||||
import mage.client.util.Config;
|
import mage.client.util.Config;
|
||||||
|
@ -47,8 +51,10 @@ import mage.client.util.ImageHelper;
|
||||||
import mage.client.util.gui.BufferedImageBuilder;
|
import mage.client.util.gui.BufferedImageBuilder;
|
||||||
import mage.components.ImagePanel;
|
import mage.components.ImagePanel;
|
||||||
import mage.sets.Sets;
|
import mage.sets.Sets;
|
||||||
|
import mage.view.CardView;
|
||||||
import mage.view.ManaPoolView;
|
import mage.view.ManaPoolView;
|
||||||
import mage.view.PlayerView;
|
import mage.view.PlayerView;
|
||||||
|
import org.mage.card.arcane.CardPanel;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.Border;
|
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 redBorder = new LineBorder(Color.red, 2);
|
||||||
private static final Border emptyBorder = BorderFactory.createEmptyBorder(0,0,0,0);
|
private static final Border emptyBorder = BorderFactory.createEmptyBorder(0,0,0,0);
|
||||||
|
|
||||||
|
private static final Dimension topCardDimension = new Dimension(40, 56);
|
||||||
|
|
||||||
/** Creates new form PlayerPanel */
|
/** Creates new form PlayerPanel */
|
||||||
public PlayerPanelExt(boolean me) {
|
public PlayerPanelExt(boolean me) {
|
||||||
initComponents(me);
|
initComponents(me);
|
||||||
|
@ -117,6 +125,25 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
this.avatar.setBorder(emptyBorder);
|
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());
|
update(player.getManaPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +167,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
|
|
||||||
MageRoundPane panelBackground = new MageRoundPane();
|
panelBackground = new MageRoundPane();
|
||||||
panelBackground.setXOffset(3);
|
panelBackground.setXOffset(3);
|
||||||
panelBackground.setYOffset(3);
|
panelBackground.setYOffset(3);
|
||||||
panelBackground.setLayout(null);
|
panelBackground.setLayout(null);
|
||||||
|
@ -156,6 +183,10 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
Image image = ImageHelper.getImageFromResources("/avatars/face" + index + ".jpg");
|
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
|
// Avatar
|
||||||
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
|
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
|
||||||
avatar = new HoverButton("player", resized, resized, resized, r);
|
avatar = new HoverButton("player", resized, resized, resized, r);
|
||||||
|
@ -305,7 +336,10 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
private ImagePanel hand;
|
private ImagePanel hand;
|
||||||
private HoverButton grave;
|
private HoverButton grave;
|
||||||
private ImagePanel library;
|
private ImagePanel library;
|
||||||
|
private CardView topCard;
|
||||||
|
private MageCard topCardPanel;
|
||||||
private JButton cheat;
|
private JButton cheat;
|
||||||
|
private MageRoundPane panelBackground;
|
||||||
|
|
||||||
private JLabel lifeLabel;
|
private JLabel lifeLabel;
|
||||||
private JLabel handLabel;
|
private JLabel handLabel;
|
||||||
|
|
|
@ -96,6 +96,8 @@ public class Plugins implements MagePlugins {
|
||||||
return new Card(card, bigCard, Config.dimensions, gameId);
|
return new Card(card, bigCard, Config.dimensions, gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCardPluginLoaded() {
|
public boolean isCardPluginLoaded() {
|
||||||
|
|
|
@ -155,8 +155,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
setText(gameCard);
|
setText(gameCard);
|
||||||
setImage(srcImage);
|
setImage(srcImage);
|
||||||
setFoil(foil);
|
setFoil(foil);
|
||||||
} else {
|
|
||||||
//log.warn("image wasn't found, card=" + gameCard.getName() + ", set=" + gameCard.getExpansionSetCode() + ", cid=" + gameCard.getCardNumber());
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -487,22 +485,25 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateImage() {
|
public void updateImage() {
|
||||||
if (!hasImage) {
|
Util.threadPool.submit(new Runnable() {
|
||||||
throw new IllegalStateException("Not implemented");
|
public void run() {
|
||||||
//TODO:
|
try {
|
||||||
/*Util.threadPool.submit(new Runnable() {
|
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
||||||
public void run () {
|
flippedAngle = isFlipped() ? CardPanel.FLIPPED_ANGLE : 0;
|
||||||
//BufferedImage srcImage = ImageCache.getImageOriginal(gameCard);
|
if (gameCard.isFaceDown()) return;
|
||||||
//BufferedImage srcImage = null;
|
BufferedImage srcImage = ImageCache.getThumbnail(gameCard);
|
||||||
//tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
if (srcImage != null) {
|
||||||
if (srcImage != null) {
|
hasImage = true;
|
||||||
hasImage = true;
|
setText(gameCard);
|
||||||
setText(gameCard);
|
setImage(srcImage);
|
||||||
setImage(srcImage, srcImage);
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
});*/
|
} catch (Error err) {
|
||||||
}
|
err.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -759,4 +760,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
public PermanentView getOriginalPermanent() {
|
public PermanentView getOriginalPermanent() {
|
||||||
throw new IllegalStateException("Is not permanent.");
|
throw new IllegalStateException("Is not permanent.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCallback(ActionCallback callback, UUID gameId) {
|
||||||
|
this.callback = callback;
|
||||||
|
this.gameId = gameId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package mage.cards;
|
package mage.cards;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import mage.cards.action.ActionCallback;
|
||||||
import mage.view.CardView;
|
import mage.view.CardView;
|
||||||
|
|
||||||
public abstract class MageCard extends JPanel {
|
public abstract class MageCard extends JPanel {
|
||||||
|
@ -18,9 +20,11 @@ public abstract class MageCard extends JPanel {
|
||||||
abstract public CardView getOriginal();
|
abstract public CardView getOriginal();
|
||||||
abstract public void setCardBounds(int x, int y, int width, int height);
|
abstract public void setCardBounds(int x, int y, int width, int height);
|
||||||
abstract public void update(CardView card);
|
abstract public void update(CardView card);
|
||||||
|
abstract public void updateImage();
|
||||||
abstract public Image getImage();
|
abstract public Image getImage();
|
||||||
abstract public void setFoil(boolean foil);
|
abstract public void setFoil(boolean foil);
|
||||||
abstract public boolean isFoil();
|
abstract public boolean isFoil();
|
||||||
abstract public void setZone(String zone);
|
abstract public void setZone(String zone);
|
||||||
abstract public String getZone();
|
abstract public String getZone();
|
||||||
|
abstract public void updateCallback(ActionCallback callback, UUID gameId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,6 +145,14 @@ public class CardView extends SimpleCardView {
|
||||||
super(null, "", 0, false);
|
super(null, "", 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CardView(boolean empty) {
|
||||||
|
super(null, "", 0, false);
|
||||||
|
if (!empty) {
|
||||||
|
throw new IllegalArgumentException("Not supported.");
|
||||||
|
}
|
||||||
|
fillEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private void fillEmpty() {
|
private void fillEmpty() {
|
||||||
this.name = "Face Down";
|
this.name = "Face Down";
|
||||||
this.rules = new ArrayList<String>();
|
this.rules = new ArrayList<String>();
|
||||||
|
|
|
@ -57,6 +57,7 @@ public class PlayerView implements Serializable {
|
||||||
private ManaPoolView manaPool;
|
private ManaPoolView manaPool;
|
||||||
private SimpleCardsView graveyard = new SimpleCardsView();
|
private SimpleCardsView graveyard = new SimpleCardsView();
|
||||||
private Map<UUID, PermanentView> battlefield = new HashMap<UUID, PermanentView>();
|
private Map<UUID, PermanentView> battlefield = new HashMap<UUID, PermanentView>();
|
||||||
|
private CardView topCard;
|
||||||
|
|
||||||
public PlayerView(Player player, GameState state, Game game) {
|
public PlayerView(Player player, GameState state, Game game) {
|
||||||
this.playerId = player.getId();
|
this.playerId = player.getId();
|
||||||
|
@ -77,6 +78,8 @@ public class PlayerView implements Serializable {
|
||||||
battlefield.put(view.getId(), view);
|
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) {
|
private boolean showInBattlefield(Permanent permanent, GameState state) {
|
||||||
|
@ -136,4 +139,8 @@ public class PlayerView implements Serializable {
|
||||||
public boolean hasLeft() {
|
public boolean hasLeft() {
|
||||||
return this.hasLeft;
|
return this.hasLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CardView getTopCard() {
|
||||||
|
return this.topCard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -101,6 +101,8 @@ public interface Player extends MageItem, Copyable<Player> {
|
||||||
public boolean hasLeft();
|
public boolean hasLeft();
|
||||||
public ManaPool getManaPool();
|
public ManaPool getManaPool();
|
||||||
public Set<UUID> getInRange();
|
public Set<UUID> getInRange();
|
||||||
|
public boolean isTopCardRevealed();
|
||||||
|
public void setTopCardRevealed(boolean topCardRevealed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a set of players which turns under you control.
|
* Returns a set of players which turns under you control.
|
||||||
|
|
Loading…
Reference in a new issue