Fixed arrows displayed under dialogs. Since now card.plugin is used in ShowCardsDialog. Added sourceCard to AbilityView (required for source arrows).

This commit is contained in:
magenoxx 2010-11-28 21:10:31 +00:00
parent be707b3b52
commit 0211787433
7 changed files with 56 additions and 22 deletions

View file

@ -164,12 +164,16 @@ public class MageFrame extends javax.swing.JFrame {
e.printStackTrace();
}
desktopPane.add(ArrowBuilder.getArrowsPanel(), JLayeredPane.DRAG_LAYER);
desktopPane.addComponentListener(new ComponentAdapter(){
@Override
public void componentResized(ComponentEvent e) {
int width = ((JComponent)e.getSource()).getWidth();
int height = ((JComponent)e.getSource()).getHeight();
backgroundPane.setSize(width, height);
JPanel arrowsPanel = ArrowBuilder.getArrowsPanelRef();
if (arrowsPanel != null) arrowsPanel.setSize(width, height);
}
});

View file

@ -43,10 +43,12 @@ import java.util.UUID;
import javax.swing.JLayeredPane;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.cards.Card;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.view.AbilityView;
import mage.view.CardView;
import mage.view.CardsView;
@ -82,16 +84,29 @@ public class ShowCardsDialog extends MageDialog implements MouseListener {
private void loadCardsFew(CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
for (CardView card: showCards.values()) {
Card cardImg = new Card(card, bigCard, dimension, gameId);
cardImg.setBounds(rectangle);
cardArea.add(cardImg);
cardArea.moveToFront(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);
addCard(card, bigCard, gameId, rectangle, dimension);
rectangle.translate(Config.dimensions.frameWidth, 0);
}
cardArea.setPreferredSize(new Dimension(Config.dimensions.frameWidth * showCards.size(), Config.dimensions.frameHeight));
}
private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle, CardDimensions dimension) {
if (card instanceof AbilityView) {
CardView tmp = ((AbilityView)card).getSourceCard();
tmp.overrideRules(card.getRules());
tmp.setIsAbility(true);
tmp.overrideTargets(card.getTargets());
tmp.setAbility(card); // cross-reference, required for ability picker
card = tmp;
}
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, dimension, gameId);
cardImg.setBounds(rectangle);
cardArea.add(cardImg);
cardArea.moveToFront(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
}
private void loadCardsMany(CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId) {
int columns = 1;
@ -99,12 +114,7 @@ public class ShowCardsDialog extends MageDialog implements MouseListener {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
int count = 0;
for (CardView card: showCards.values()) {
Card cardImg = new Card(card, bigCard, dimension, gameId);
cardImg.setBounds(rectangle);
cardArea.add(cardImg);
cardArea.moveToFront(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);
addCard(card, bigCard, gameId, rectangle, dimension);
if (count >= 20) {
rectangle.translate(Config.dimensions.frameWidth, -400);
columns++;

View file

@ -41,6 +41,7 @@ import java.awt.event.ComponentEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
@ -87,7 +88,6 @@ public class GamePanel extends javax.swing.JPanel {
// Override layout (I can't edit generated code)
this.setLayout(new BorderLayout());
final JLayeredPane j = new JLayeredPane();
j.add(ArrowBuilder.getArrowsPanel(), JLayeredPane.MODAL_LAYER);
j.setSize(1024,768);
this.add(j);
j.add(jSplitPane1, JLayeredPane.DEFAULT_LAYER);
@ -102,8 +102,6 @@ public class GamePanel extends javax.swing.JPanel {
int width = ((JComponent)e.getSource()).getWidth();
int height = ((JComponent)e.getSource()).getHeight();
j.setSize(width, height);
JPanel arrowsPanel = ArrowBuilder.getArrowsPanelRef();
if (arrowsPanel != null) arrowsPanel.setSize(width, height);
jSplitPane1.setSize(width, height);
}
});
@ -188,15 +186,18 @@ public class GamePanel extends javax.swing.JPanel {
public void hideGame() {
this.chatPanel.disconnect();
this.players.clear();
logger.log(Level.FINE, "players clear.");
this.pnlBattlefield.removeAll();
MageFrame.getCombatDialog().hideDialog();
this.setVisible(false);
}
public synchronized void init(GameView game) {
logger.log(Level.FINE, "init.");
MageFrame.getCombatDialog().init(gameId, bigCard);
MageFrame.getCombatDialog().setLocation(500, 300);
addPlayers(game);
logger.log(Level.FINE, "added players.");
updateGame(game);
}

View file

@ -18,7 +18,12 @@ public class DefaultActionCallback {
}
public void mouseClicked(MouseEvent e, UUID gameId, Session session, CardView card) {
if (gameId != null)
session.sendPlayerUUID(gameId, card.getId());
if (gameId != null) {
if (card.isAbility() && card.getAbility() != null) {
session.sendPlayerUUID(gameId, card.getAbility().getId());
} else {
session.sendPlayerUUID(gameId, card.getId());
}
}
}
}

View file

@ -40,11 +40,13 @@ import mage.abilities.Ability;
public class AbilityView extends CardView {
private String sourceName;
private CardView sourceCard;
public AbilityView(Ability ability, String sourceName) {
public AbilityView(Ability ability, String sourceName, CardView sourceCard) {
this.id = ability.getId();
this.name = "Ability";
this.sourceName = sourceName;
this.sourceCard = sourceCard;
this.rules = new ArrayList<String>();
rules.add(formatRule(ability.getRule()));
this.power = "";
@ -65,5 +67,7 @@ public class AbilityView extends CardView {
return newRule;
}
public CardView getSourceCard() {
return this.sourceCard;
}
}

View file

@ -68,6 +68,7 @@ public class CardView implements Serializable {
protected String expansionSetCode;
protected int cardNumber;
protected boolean isAbility;
protected CardView ability;
public List<UUID> targets;
@ -240,6 +241,14 @@ public class CardView implements Serializable {
this.targets = newTargets;
}
public void setAbility(CardView ability) {
this.ability = ability;
}
public CardView getAbility() {
return this.ability;
}
@Override
public String toString() {
return getName() + " [" + getId() + "]";

View file

@ -59,8 +59,9 @@ public class CardsView extends HashMap<UUID, CardView> {
public CardsView(Collection<? extends Ability> abilities, GameState state) {
for (Ability ability: abilities) {
String sourceName = state.getPermanent(ability.getSourceId()).getName();
this.put(ability.getId(), new AbilityView(ability, sourceName));
Card sourceCard = state.getPermanent(ability.getSourceId());
String sourceName = sourceCard.getName();
this.put(ability.getId(), new AbilityView(ability, sourceName, new CardView(sourceCard)));
}
}