Card render testing dialog improves:

* Added chooseable render testing (click by mouse on cards);
* Added column style render testing (many cards mode);
* Added tapped, face down and manifested render testing for permanents;
* CardView: fixed missing copy data (NPE for transformed cards);
* CardArea: added support to draw permanents;
* CardArea: added support of offsets between cards/columns;
This commit is contained in:
Oleg Agafonov 2020-01-22 00:44:25 +04:00
parent a072d8275f
commit eaaa37db11
27 changed files with 306 additions and 138 deletions

View file

@ -35,7 +35,6 @@ import static mage.client.constants.Constants.*;
@SuppressWarnings("serial")
public class Card extends MagePermanent implements MouseMotionListener, MouseListener, FocusListener, ComponentListener {
protected Point p;
protected final CardDimensions dimension;

View file

@ -24,15 +24,21 @@ public class CardArea extends JPanel implements MouseListener {
protected final CardEventSource cardEventSource = new CardEventSource();
private static int MAX_CARDS_PER_COLUMN = 20; // max cards amount in one column
private boolean reloaded = false;
private final javax.swing.JLayeredPane cardArea;
private final javax.swing.JScrollPane scrollPane;
private int yCardCaptionOffsetPercent = 0; // card caption offset (use for moving card caption view center, below mana icons -- for more good UI)
private int xOffsetBetweenCardsOrColumns = 0; // x offset between cards or columns (in many mode)
private Dimension cardDimension;
private int verticalCardOffset;
private int customRenderMode = -1; // custom render mode tests
private Dimension customCardSize = null; // custom size for tests
private Dimension customCardSize = null; // custom card size for tests
private boolean customNeedFullPermanentRender = false; // disable permanent render mode, see CardArea for more info
private int customXOffsetBetweenCardsOrColumns = 0;
private MouseListener customMouseListener = null;
/**
* Create the panel.
@ -71,6 +77,9 @@ public class CardArea extends JPanel implements MouseListener {
} else {
setCardDimension(GUISizeHelper.otherZonesCardDimension, GUISizeHelper.otherZonesCardVerticalOffset);
}
if (customXOffsetBetweenCardsOrColumns > 0) {
xOffsetBetweenCardsOrColumns = customXOffsetBetweenCardsOrColumns;
}
}
public void setCardDimension(Dimension dimension, int verticalCardOffset) {
@ -96,14 +105,18 @@ public class CardArea extends JPanel implements MouseListener {
yCardCaptionOffsetPercent = 0;
loadCardsMany(showCards, bigCard, gameId);
}
cardArea.revalidate();
this.revalidate();
this.repaint();
redraw();
fixDialogSize();
}
public void redraw() {
cardArea.revalidate();
this.revalidate();
this.repaint();
}
public void loadCardsNarrow(CardsView showCards, BigCard bigCard, UUID gameId) {
this.reloaded = true;
cardArea.removeAll();
@ -121,11 +134,18 @@ public class CardArea extends JPanel implements MouseListener {
private void loadCardsFew(CardsView showCards, BigCard bigCard, UUID gameId) {
Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height);
int cardsAdded = 0;
for (CardView card : showCards.values()) {
if (cardsAdded > 0) {
rectangle.translate(cardDimension.width + xOffsetBetweenCardsOrColumns, 0);
}
addCard(card, bigCard, gameId, rectangle);
rectangle.translate(cardDimension.width, 0);
cardsAdded++;
}
cardArea.setPreferredSize(new Dimension(cardDimension.width * showCards.size(), cardDimension.height + verticalCardOffset));
cardArea.setPreferredSize(new Dimension(
cardDimension.width * showCards.size() + (cardsAdded * xOffsetBetweenCardsOrColumns),
cardDimension.height + verticalCardOffset
));
}
private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) {
@ -138,31 +158,28 @@ public class CardArea extends JPanel implements MouseListener {
card = tmp;
}
MageCard cardPanel = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true,
customRenderMode != -1 ? customRenderMode : PreferencesDialog.getRenderMode());
customRenderMode != -1 ? customRenderMode : PreferencesDialog.getRenderMode(), customNeedFullPermanentRender);
cardPanel.setBounds(rectangle);
cardPanel.addMouseListener(this);
cardArea.add(cardPanel);
cardArea.moveToFront(cardPanel);
cardPanel.addMouseListener(customMouseListener != null ? customMouseListener : this);
cardPanel.update(card);
cardPanel.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height);
cardArea.add(cardPanel);
cardArea.moveToFront(cardPanel);
// new card have same settings as current view
cardPanel.setCardCaptionTopOffset(yCardCaptionOffsetPercent);
cardPanel.showCardTitle();
}
private void loadCardsMany(CardsView showCards, BigCard bigCard, UUID gameId) {
int rowsOfCards = 20;
int columns = 1;
if (showCards != null && !showCards.isEmpty()) {
Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height);
int count = 0;
for (CardView card : showCards.values()) {
addCard(card, bigCard, gameId, rectangle);
if (count >= rowsOfCards) {
rectangle.translate(cardDimension.width, -(rowsOfCards * verticalCardOffset));
if (count >= MAX_CARDS_PER_COLUMN) {
rectangle.translate(cardDimension.width + xOffsetBetweenCardsOrColumns, -(MAX_CARDS_PER_COLUMN * verticalCardOffset));
columns++;
count = 0;
} else {
@ -171,7 +188,7 @@ public class CardArea extends JPanel implements MouseListener {
}
}
}
cardArea.setPreferredSize(new Dimension(cardDimension.width * columns, cardDimension.height + (rowsOfCards * verticalCardOffset)));
cardArea.setPreferredSize(new Dimension(cardDimension.width * columns + xOffsetBetweenCardsOrColumns * (columns - 1), cardDimension.height + (MAX_CARDS_PER_COLUMN * verticalCardOffset)));
}
public boolean isReloaded() {
@ -278,10 +295,22 @@ public class CardArea extends JPanel implements MouseListener {
this.customRenderMode = customRenderMode;
}
public void setCustomNeedFullPermanentRender(boolean customNeedFullPermanentRender) {
this.customNeedFullPermanentRender = customNeedFullPermanentRender;
}
public void setCustomCardSize(Dimension customCardSize) {
this.customCardSize = customCardSize;
}
public void setCustomXOffsetBetweenCardsOrColumns(int customXOffsetBetweenCardsOrColumns) {
this.customXOffsetBetweenCardsOrColumns = customXOffsetBetweenCardsOrColumns;
}
public void setCustomMouseListener(MouseListener customMouseListener) {
this.customMouseListener = customMouseListener;
}
@Override
public void mouseEntered(MouseEvent e) {
}

View file

@ -73,7 +73,7 @@ public class CardDraggerGlassPane implements MouseListener, MouseMotionListener
currentCards = new ArrayList<>(source.dragCardList());
// Make a view for the first one and add it to us
dragView = Plugins.instance.getMageCard(currentCards.get(0), null, new Dimension(100, 140), null, true, false, PreferencesDialog.getRenderMode());
dragView = Plugins.instance.getMageCard(currentCards.get(0), null, new Dimension(100, 140), null, true, false, PreferencesDialog.getRenderMode(), true);
for (MouseListener l : dragView.getMouseListeners()) {
dragView.removeMouseListener(l);
}

View file

@ -101,7 +101,7 @@
}
private void addCard(CardView card, BigCard bigCard, UUID gameId, boolean drawImage) {
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, drawImage, true, PreferencesDialog.getRenderMode());
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, drawImage, true, PreferencesDialog.getRenderMode(), true);
cards.put(card.getId(), cardImg);
cardImg.addMouseListener(this);
add(cardImg);

View file

@ -228,7 +228,7 @@
}
private void addCard(CardView card, BigCard bigCard, UUID gameId) {
MageCard mageCard = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode());
MageCard mageCard = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
if (zone != null) {
mageCard.setZone(zone);
}

View file

@ -389,7 +389,7 @@
}
private MageCard addCard(CardView card, BigCard bigCard, UUID gameId) {
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true, PreferencesDialog.getRenderMode());
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true, PreferencesDialog.getRenderMode(), true);
cardArea.add(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);

View file

@ -103,7 +103,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
List<CardView> sortedCards = new ArrayList<>(booster.values());
sortedCards.sort(new CardViewRarityComparator());
for (CardView card : sortedCards) {
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, dimension, null, true, true, PreferencesDialog.getRenderMode());
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, dimension, null, true, true, PreferencesDialog.getRenderMode(), true);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);

View file

@ -1772,7 +1772,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
updateCounts();
// Create the card view
final MageCard cardPanel = Plugins.instance.getMageCard(card, lastBigCard, new Dimension(getCardWidth(), getCardHeight()), null, true, true, PreferencesDialog.getRenderMode());
final MageCard cardPanel = Plugins.instance.getMageCard(card, lastBigCard, new Dimension(getCardWidth(), getCardHeight()), null, true, true, PreferencesDialog.getRenderMode(), true);
cardPanel.update(card);
cardPanel.setCardCaptionTopOffset(0);

View file

@ -163,7 +163,7 @@ public class ChoiceDialog extends IDialogPanel {
}
CardView card = cardList.get(i);
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode());
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
cardImg.setLocation(dx, dy + j * (height + 30));
add(cardImg);

View file

@ -120,7 +120,7 @@ public class StackDialog extends IDialogPanel {
card = tmp;
}
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode());
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
//cardImg.setBorder(BorderFactory.createLineBorder(Color.red));
cardImg.setLocation(dx, dy);

View file

@ -407,7 +407,7 @@ public class MageBook extends JComponent {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
final MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true, PreferencesDialog.getRenderMode());
final MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true, PreferencesDialog.getRenderMode(), true);
cardImg.setBounds(rectangle);
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
cardImg.update(card);
@ -448,7 +448,7 @@ public class MageBook extends JComponent {
newToken.removeSummoningSickness();
PermanentView theToken = new PermanentView(newToken, null, null, null);
theToken.setInViewerOnly(true);
final MageCard cardImg = Plugins.instance.getMagePermanent(theToken, bigCard, cardDimension, gameId, true, PreferencesDialog.getRenderMode());
final MageCard cardImg = Plugins.instance.getMagePermanent(theToken, bigCard, cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
cardImg.setBounds(rectangle);
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
cardImg.update(theToken);

View file

@ -23,7 +23,7 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="578" max="32767" attributes="0"/>
<EmptySpace min="0" pref="748" max="32767" attributes="0"/>
<Component id="buttonCancel" min="-2" pref="100" max="-2" attributes="0"/>
</Group>
<Component id="cardsPanel" alignment="0" max="32767" attributes="0"/>
@ -37,6 +37,8 @@
<Component id="labelSize" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="sliderSize" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="checkBoxGenerateManyCards" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
@ -56,6 +58,7 @@
<Component id="labelSize" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="sliderSize" min="-2" max="-2" attributes="0"/>
<Component id="checkBoxGenerateManyCards" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="cardsPanel" pref="421" max="32767" attributes="0"/>
@ -116,5 +119,13 @@
<Property name="text" type="java.lang.String" value="Card size:"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="checkBoxGenerateManyCards">
<Properties>
<Property name="text" type="java.lang.String" value="Generate many cards"/>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="checkBoxGenerateManyCardsItemStateChanged"/>
</Events>
</Component>
</SubComponents>
</Form>

View file

@ -26,10 +26,14 @@ import mage.players.Player;
import mage.players.StubPlayer;
import mage.view.*;
import org.apache.log4j.Logger;
import org.mage.card.arcane.CardPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@ -70,7 +74,7 @@ public class TestCardRenderDialog extends MageDialog {
this.removeDialog();
}
private PermanentView createCard(Game game, UUID controllerId, String code, String cardNumber, int power, int toughness, int damage) {
private PermanentView createPermanentCard(Game game, UUID controllerId, String code, String cardNumber, int power, int toughness, int damage, boolean tapped) {
CardInfo cardInfo = CardRepository.instance.findCard(code, cardNumber);
ExpansionInfo setInfo = ExpansionRepository.instance.getSetByCode(code);
CardSetInfo testSet = new CardSetInfo(cardInfo.getName(), setInfo.getCode(), cardNumber, cardInfo.getRarity(),
@ -86,16 +90,42 @@ public class TestCardRenderDialog extends MageDialog {
if (power > 0) perm.getPower().setValue(power);
if (toughness > 0) perm.getToughness().setValue(toughness);
perm.removeSummoningSickness();
perm.setTapped(tapped);
if (perm.isTransformable()) {
perm.setTransformed(true);
}
PermanentView cardView = new PermanentView(perm, card, controllerId, game);
cardView.setInViewerOnly(true);
//cardView.setInViewerOnly(true);
return cardView;
}
private CardView createHandCard(Game game, UUID controllerId, String code, String cardNumber, int power, int toughness, int damage) {
private CardView createFaceDownCard(Game game, UUID controllerId, String code, String cardNumber, boolean isMorphed, boolean isManifested, boolean tapped) {
CardInfo cardInfo = CardRepository.instance.findCard(code, cardNumber);
ExpansionInfo setInfo = ExpansionRepository.instance.getSetByCode(code);
CardSetInfo testSet = new CardSetInfo(cardInfo.getName(), setInfo.getCode(), cardNumber, cardInfo.getRarity(),
new CardGraphicInfo(cardInfo.getFrameStyle(), cardInfo.usesVariousArt()));
Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
Set<Card> cardsList = new HashSet<>();
cardsList.add(card);
game.loadCards(cardsList, controllerId);
PermanentCard perm = new PermanentCard(card, controllerId, game);
perm.setFaceDown(true, game);
perm.setMorphed(isMorphed);
perm.setManifested(isManifested);
perm.removeSummoningSickness();
perm.setTapped(tapped);
if (perm.isTransformable()) {
perm.setTransformed(true);
}
PermanentView cardView = new PermanentView(perm, card, controllerId, game);
cardView.setInViewerOnly(false); // must false for face down
return cardView;
}
private CardView createHandCard(Game game, UUID controllerId, String code, String cardNumber) {
CardInfo cardInfo = CardRepository.instance.findCard(code, cardNumber);
ExpansionInfo setInfo = ExpansionRepository.instance.getSetByCode(code);
CardSetInfo testSet = new CardSetInfo(cardInfo.getName(), setInfo.getCode(), cardNumber, cardInfo.getRarity(),
@ -125,45 +155,89 @@ public class TestCardRenderDialog extends MageDialog {
private void reloadCards() {
cardsPanel.cleanUp();
cardsPanel.setCustomRenderMode(comboRenderMode.getSelectedIndex());
cardsPanel.setCustomNeedFullPermanentRender(false); // to fix cropped/position bugged with PermanentView (CardArean do not support it as normal, see CardArea for info)
cardsPanel.setCustomCardSize(new Dimension(getCardWidth(), getCardHeight()));
cardsPanel.setCustomXOffsetBetweenCardsOrColumns(10);
cardsPanel.changeGUISize(); // reload new settings
// create custom mouse listener
cardsPanel.setCustomMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
cardsPanel.mouseClicked(e); // default
// make cards chooseable or not
if (e.getSource() instanceof CardPanel) {
CardPanel panel = (CardPanel) e.getSource();
panel.setChoosable(!panel.isChoosable());
cardsPanel.redraw();
}
}
@Override
public void mousePressed(MouseEvent e) {
cardsPanel.mousePressed(e); // default
}
@Override
public void mouseReleased(MouseEvent e) {
cardsPanel.mouseReleased(e); // default
}
@Override
public void mouseEntered(MouseEvent e) {
cardsPanel.mouseEntered(e); // default
}
@Override
public void mouseExited(MouseEvent e) {
cardsPanel.mouseExited(e); // default
}
});
Game game = new TestGame(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, MulliganType.GAME_DEFAULT.getMulligan(0), 20);
Player player = new StubPlayer("player1", RangeOfInfluence.ALL);
Deck deck = new Deck();
game.addPlayer(player, deck);
Player playerYou = new StubPlayer("player1", RangeOfInfluence.ALL);
game.addPlayer(playerYou, deck);
Player playerOpponent = new StubPlayer("player2", RangeOfInfluence.ALL);
game.addPlayer(playerOpponent, deck);
ArrayList<CardView> cardViews = new ArrayList<>();
///*
cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "263", 0, 0, 0, false)); // mountain
cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "185", 0, 0, 0, true)); // Judith, the Scourge Diva
//*/
cardViews.add(createHandCard(game, playerYou.getId(), "DIS", "153")); // Odds // Ends (split card)
cardViews.add(createHandCard(game, playerYou.getId(), "ELD", "38")); // Animating Faerie (adventure card)
cardViews.add(createFaceDownCard(game, playerOpponent.getId(), "ELD", "38", false, false, false)); // face down
cardViews.add(createFaceDownCard(game, playerOpponent.getId(), "ELD", "38", true, false, true)); // morphed
cardViews.add(createFaceDownCard(game, playerOpponent.getId(), "ELD", "38", false, true, false)); // manifested
// duplicate cards
if (checkBoxGenerateManyCards.isSelected()) {
while (cardViews.size() < 30) {
int addingCount = cardViews.size();
for (int i = 0; i < addingCount; i++) {
CardView view = cardViews.get(i);
CardView newView = new CardView(view);
cardViews.add(newView);
}
}
}
/*
cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "78", 125, 89, 0, false)); // Noxious Groodion
cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "14", 3, 5, 2, false)); // Knight of Sorrows
cardViews.add(createPermanentCard(game, playerYou.getId(), "DKA", "140", 5, 2, 2, false)); // Huntmaster of the Fells, transforms
cardViews.add(createPermanentCard(game, playerYou.getId(), "RNA", "221", 0, 0, 0, false)); // Bedeck // Bedazzle
cardViews.add(createPermanentCard(game, playerYou.getId(), "XLN", "234", 0, 0, 0, false)); // Conqueror's Galleon
cardViews.add(createEmblem(new AjaniAdversaryOfTyrantsEmblem())); // Emblem Ajani
cardViews.add(createPlane(new AkoumPlane())); // Plane - Akoum
//*/
BigCard big = new BigCard();
CardsView view = new CardsView();
CardView card;
/*
card = createCard(game, player.getId(), "RNA", "263", 0, 0, 0); // mountain
view.put(card.getId(), card);
card = createCard(game, player.getId(), "RNA", "185", 0, 0, 0); // Judith, the Scourge Diva
view.put(card.getId(), card);
//*/
card = createHandCard(game, player.getId(), "DIS", "153", 0, 0, 0); // Odds // Ends (split card)
view.put(card.getId(), card);
card = createHandCard(game, player.getId(), "ELD", "38", 2, 2, 0); // Animating Faerie (adventure card)
view.put(card.getId(), card);
/*
card = createCard(game, player.getId(), "RNA", "78", 125, 89, 0); // Noxious Groodion
view.put(card.getId(), card);
card = createCard(game, player.getId(), "RNA", "14", 3, 5, 2); // Knight of Sorrows
view.put(card.getId(), card);
card = createCard(game, player.getId(), "DKA", "140", 5, 2, 2); // Huntmaster of the Fells, transforms
view.put(card.getId(), card);
card = createCard(game, player.getId(), "RNA", "221", 0, 0, 0); // Bedeck // Bedazzle
view.put(card.getId(), card);
card = createCard(game, player.getId(), "XLN", "234", 0, 0, 0); // Conqueror's Galleon
view.put(card.getId(), card);
card = createEmblem(new AjaniAdversaryOfTyrantsEmblem()); // Emblem Ajani
view.put(card.getId(), card);
card = createPlane(new AkoumPlane()); // Plane - Akoum
view.put(card.getId(), card);
//*/
cardsPanel.setCustomCardSize(new Dimension(getCardWidth(), getCardHeight()));
cardsPanel.changeGUISize();
CardsView view = new CardsView(cardViews);
cardsPanel.loadCards(view, big, game.getId());
}
@ -195,6 +269,7 @@ public class TestCardRenderDialog extends MageDialog {
comboRenderMode = new javax.swing.JComboBox<>();
sliderSize = new javax.swing.JSlider();
labelSize = new javax.swing.JLabel();
checkBoxGenerateManyCards = new javax.swing.JCheckBox();
buttonCancel.setText("Close");
buttonCancel.addActionListener(new java.awt.event.ActionListener() {
@ -227,6 +302,13 @@ public class TestCardRenderDialog extends MageDialog {
labelSize.setText("Card size:");
checkBoxGenerateManyCards.setText("Generate many cards");
checkBoxGenerateManyCards.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
checkBoxGenerateManyCardsItemStateChanged(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@ -235,7 +317,7 @@ public class TestCardRenderDialog extends MageDialog {
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 578, Short.MAX_VALUE)
.addGap(0, 748, Short.MAX_VALUE)
.addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(cardsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
@ -248,6 +330,8 @@ public class TestCardRenderDialog extends MageDialog {
.addComponent(labelSize)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sliderSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(checkBoxGenerateManyCards)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
@ -261,7 +345,8 @@ public class TestCardRenderDialog extends MageDialog {
.addComponent(labelRenderMode)
.addComponent(comboRenderMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelSize))
.addComponent(sliderSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(sliderSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(checkBoxGenerateManyCards))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cardsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@ -293,10 +378,15 @@ public class TestCardRenderDialog extends MageDialog {
reloadCards();
}//GEN-LAST:event_sliderSizeStateChanged
private void checkBoxGenerateManyCardsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_checkBoxGenerateManyCardsItemStateChanged
reloadCards();
}//GEN-LAST:event_checkBoxGenerateManyCardsItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonCancel;
private javax.swing.JButton buttonReloadCards;
private mage.client.cards.CardArea cardsPanel;
private javax.swing.JCheckBox checkBoxGenerateManyCards;
private javax.swing.JComboBox<String> comboRenderMode;
private javax.swing.JLabel labelRenderMode;
private javax.swing.JLabel labelSize;

View file

@ -228,7 +228,7 @@
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true, PreferencesDialog.getRenderMode());
final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
permanents.put(permanent.getId(), perm);

View file

@ -23,9 +23,9 @@ public interface MagePlugins {
JComponent updateTablePanel(Map<String, JComponent> ui);
MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, int renderMode);
MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, int renderMode, boolean needFullPermanentRender);
MageCard getMageCard(CardView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, boolean previewable, int renderMode);
MageCard getMageCard(CardView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, boolean previewable, int renderMode, boolean needFullPermanentRender);
boolean isThemePluginLoaded();

View file

@ -93,24 +93,24 @@ public enum Plugins implements MagePlugins {
}
@Override
public MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, int renderMode) {
public MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, int renderMode, boolean needFullPermanentRender) {
if (cardPlugin != null) {
mageActionCallback.refreshSession();
mageActionCallback.setCardPreviewComponent(bigCard);
return cardPlugin.getMagePermanent(card, dimension, gameId, mageActionCallback, false, !MageFrame.isLite() && loadImage, renderMode);
return cardPlugin.getMagePermanent(card, dimension, gameId, mageActionCallback, false, !MageFrame.isLite() && loadImage, renderMode, needFullPermanentRender);
} else {
return new Permanent(card, bigCard, Config.dimensions, gameId);
}
}
@Override
public MageCard getMageCard(CardView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, boolean previewable, int renderMode) {
public MageCard getMageCard(CardView card, BigCard bigCard, Dimension dimension, UUID gameId, boolean loadImage, boolean previewable, int renderMode, boolean needFullPermanentRender) {
if (cardPlugin != null) {
if (previewable) {
mageActionCallback.refreshSession();
mageActionCallback.setCardPreviewComponent(bigCard);
}
return cardPlugin.getMageCard(card, dimension, gameId, mageActionCallback, false, !MageFrame.isLite() && loadImage, renderMode);
return cardPlugin.getMageCard(card, dimension, gameId, mageActionCallback, false, !MageFrame.isLite() && loadImage, renderMode, needFullPermanentRender);
} else {
return new Card(card, bigCard, Config.dimensions, gameId);
}

View file

@ -84,6 +84,12 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
private boolean hasSickness;
private String zone;
// Permanent and card renders are different (another sizes and positions of panel, tapped, etc -- that's weird)
// Some card view components support only permanents (BattlefieldPanel), but another support only cards (CardArea)
// TODO: remove crop/size logic from CardPanel to viewers panels or make compatible for all panels
// But testing render needs both cards and permanents. That's settings allows to disable different render logic
private boolean needFullPermanentRender = true;
public double transformAngle = 1;
private boolean transformed;
@ -97,13 +103,27 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
// if this is set, it's opened if the user right clicks on the card panel
private JPopupMenu popupMenu;
public CardPanel(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil, Dimension dimension) {
public CardPanel(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil, Dimension dimension, boolean needFullPermanentRender) {
// Store away params
this.setGameCard(newGameCard);
this.callback = callback;
this.gameId = gameId;
this.needFullPermanentRender = needFullPermanentRender;
// Gather info about the card
/*
this.setFocusable(true);
this.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(FocusEvent e) {
//LOGGER.warn("focus gained " + getCard().getName());
}
public void focusLost(FocusEvent e) {
//LOGGER.warn("focus lost " + getCard().getName());
}
});
*/
// Gather info about the card (all card maniputations possible with permanents only, also render can be different)
this.isPermanent = this.getGameCard() instanceof PermanentView && !this.getGameCard().inViewerOnly();
if (isPermanent) {
this.hasSickness = ((PermanentView) this.getGameCard()).hasSummoningSickness();
@ -204,7 +224,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
updateArtImage();
}
}
public void setIsPermanent(boolean isPermanent) {
this.isPermanent = isPermanent;
}
@ -360,7 +380,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
this.cardWidth = cardWidth;
this.symbolWidth = cardWidth / 7;
this.cardHeight = cardHeight;
if (this.isPermanent) {
if (this.isPermanent && needFullPermanentRender) {
int rotCenterX = Math.round(cardWidth / 2f);
int rotCenterY = cardHeight - rotCenterX;
int rotCenterToTopCorner = Math.round(cardWidth * CardPanel.ROT_CENTER_TO_TOP_CORNER);
@ -382,7 +402,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
}
public int getXOffset(int cardWidth) {
if (this.isPermanent) {
if (this.isPermanent && needFullPermanentRender) {
int rotCenterX = Math.round(cardWidth / 2f);
int rotCenterToBottomCorner = Math.round(cardWidth * CardPanel.ROT_CENTER_TO_BOTTOM_CORNER);
int xOffset = rotCenterX - rotCenterToBottomCorner;
@ -393,7 +413,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
}
public final int getYOffset(int cardWidth, int cardHeight) {
if (this.isPermanent) {
if (this.isPermanent && needFullPermanentRender) {
int rotCenterX = Math.round(cardWidth / 2f);
int rotCenterY = cardHeight - rotCenterX;
int rotCenterToTopCorner = Math.round(cardWidth * CardPanel.ROT_CENTER_TO_TOP_CORNER);
@ -625,7 +645,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
if (getGameCard().hideInfo()) {
return;
}
if (tooltipShowing) {
synchronized (this) {
if (tooltipShowing) {

View file

@ -240,9 +240,9 @@ public class CardPanelComponentImpl extends CardPanel {
}
}
public CardPanelComponentImpl(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil, Dimension dimension) {
public CardPanelComponentImpl(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil, Dimension dimension, boolean needFullPermanentRender) {
// Call to super
super(newGameCard, gameId, loadImage, callback, foil, dimension);
super(newGameCard, gameId, loadImage, callback, foil, dimension, needFullPermanentRender);
// Counter panel
if (!newGameCard.isAbility()) {
@ -750,6 +750,7 @@ public class CardPanelComponentImpl extends CardPanel {
}
private BufferedImage getFaceDownImage() {
// TODO: add download default images
if (isPermanent()) {
if (((PermanentView) getGameCard()).isMorphed()) {
return ImageCache.getMorphImage();

View file

@ -231,9 +231,10 @@ public class CardPanelRenderImpl extends CardPanel {
private BufferedImage cardImage;
private CardRenderer cardRenderer;
public CardPanelRenderImpl(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback, final boolean foil, Dimension dimension) {
public CardPanelRenderImpl(CardView newGameCard, UUID gameId, final boolean loadImage, ActionCallback callback,
final boolean foil, Dimension dimension, boolean needFullPermanentRender) {
// Call to super
super(newGameCard, gameId, loadImage, callback, foil, dimension);
super(newGameCard, gameId, loadImage, callback, foil, dimension, needFullPermanentRender);
// Renderer
cardRenderer = cardRendererFactory.create(getGameCard(), isTransformed());

View file

@ -98,12 +98,12 @@ public class CardPluginImpl implements CardPlugin {
* Temporary card rendering shim. Split card rendering isn't implemented
* yet, so use old component based rendering for the split cards.
*/
private CardPanel makePanel(CardView view, UUID gameId, boolean loadImage, ActionCallback callback, boolean isFoil, Dimension dimension, int renderMode) {
private CardPanel makePanel(CardView view, UUID gameId, boolean loadImage, ActionCallback callback, boolean isFoil, Dimension dimension, int renderMode, boolean needFullPermanentRender) {
switch (renderMode) {
case 0:
return new CardPanelRenderImpl(view, gameId, loadImage, callback, isFoil, dimension);
return new CardPanelRenderImpl(view, gameId, loadImage, callback, isFoil, dimension, needFullPermanentRender);
case 1:
return new CardPanelComponentImpl(view, gameId, loadImage, callback, isFoil, dimension);
return new CardPanelComponentImpl(view, gameId, loadImage, callback, isFoil, dimension, needFullPermanentRender);
default:
throw new IllegalStateException("Unknown render mode " + renderMode);
@ -111,15 +111,15 @@ public class CardPluginImpl implements CardPlugin {
}
@Override
public MagePermanent getMagePermanent(PermanentView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage, int renderMode) {
CardPanel cardPanel = makePanel(permanent, gameId, loadImage, callback, false, dimension, renderMode);
public MagePermanent getMagePermanent(PermanentView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage, int renderMode, boolean needFullPermanentRender) {
CardPanel cardPanel = makePanel(permanent, gameId, loadImage, callback, false, dimension, renderMode, needFullPermanentRender);
cardPanel.setShowCastingCost(true);
return cardPanel;
}
@Override
public MagePermanent getMageCard(CardView cardView, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage, int renderMode) {
CardPanel cardPanel = makePanel(cardView, gameId, loadImage, callback, false, dimension, renderMode);
public MagePermanent getMageCard(CardView cardView, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage, int renderMode, boolean needFullPermanentRender) {
CardPanel cardPanel = makePanel(cardView, gameId, loadImage, callback, false, dimension, renderMode, needFullPermanentRender);
cardPanel.setShowCastingCost(true);
return cardPanel;
}

View file

@ -1,12 +1,12 @@
package mage.cards;
import java.awt.Image;
import java.util.UUID;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import mage.cards.action.ActionCallback;
import mage.view.CardView;
import javax.swing.*;
import java.awt.*;
import java.util.UUID;
public abstract class MageCard extends JPanel {
private static final long serialVersionUID = 6089945326434301879L;
@ -57,5 +57,4 @@ public abstract class MageCard extends JPanel {
public abstract void setPopupMenu(JPopupMenu popupMenu);
public abstract JPopupMenu getPopupMenu();
}

View file

@ -20,9 +20,11 @@ import java.util.UUID;
*/
public interface CardPlugin extends Plugin {
MagePermanent getMagePermanent(PermanentView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage, int renderMode);
MagePermanent getMagePermanent(PermanentView permanent, Dimension dimension, UUID gameId, ActionCallback callback,
boolean canBeFoil, boolean loadImage, int renderMode, boolean needFullPermanentRender);
MagePermanent getMageCard(CardView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage, int renderMode);
MagePermanent getMageCard(CardView permanent, Dimension dimension, UUID gameId, ActionCallback callback,
boolean canBeFoil, boolean loadImage, int renderMode, boolean needFullPermanentRender);
int sortPermanents(Map<String, JComponent> ui, Map<UUID, MagePermanent> cards, boolean nonPermanentsOwnRow, boolean topPanel);

View file

@ -137,83 +137,76 @@ public class CardView extends SimpleCardView {
public CardView(CardView cardView) {
super(cardView);
this.originalCard = cardView.originalCard;
// generetate new ID
// generetate new ID (TODO: why new ID?)
this.id = UUID.randomUUID();
this.parentId = cardView.parentId;
this.name = cardView.name;
this.displayName = cardView.displayName;
this.displayFullName = cardView.displayFullName;
this.rules = cardView.rules;
this.rules = new ArrayList<>(cardView.rules);
this.power = cardView.power;
this.toughness = cardView.toughness;
this.loyalty = cardView.loyalty;
this.startingLoyalty = cardView.startingLoyalty;
this.cardTypes = cardView.cardTypes;
this.subTypes = cardView.subTypes;
this.cardTypes = new HashSet<>(cardView.cardTypes);
this.subTypes = new SubTypeList(cardView.subTypes);
this.superTypes = cardView.superTypes;
this.color = cardView.color;
this.frameColor = cardView.frameColor;
this.frameStyle = cardView.frameStyle;
this.manaCostLeft = cardView.manaCostLeft;
this.manaCostRight = cardView.manaCostRight;
this.manaCostLeft = new ArrayList<>(cardView.manaCostLeft);
this.manaCostRight = new ArrayList<>(cardView.manaCostRight);
this.convertedManaCost = cardView.convertedManaCost;
this.rarity = cardView.rarity;
this.mageObjectType = cardView.mageObjectType;
this.isAbility = cardView.isAbility;
this.abilityType = cardView.abilityType;
this.isToken = cardView.isToken;
this.ability = null;
this.ability = cardView.ability; // reference, not copy
this.type = cardView.type;
this.transformable = cardView.transformable;
if (cardView.secondCardFace != null) {
this.secondCardFace = new CardView(cardView.secondCardFace);
} else {
this.secondCardFace = null;
}
this.secondCardFace = cardView.secondCardFace == null ? null : new CardView(cardView.secondCardFace);
this.transformed = cardView.transformed;
this.flipCard = cardView.flipCard;
this.faceDown = cardView.faceDown;
this.alternateName = cardView.alternateName;
this.originalName = cardView.originalName;
this.artRect = cardView.artRect;
this.isSplitCard = cardView.isSplitCard;
this.leftSplitName = cardView.leftSplitName;
this.leftSplitCosts = cardView.leftSplitCosts;
this.leftSplitRules = null;
this.leftSplitCosts = cardView.leftSplitCosts == null ? null : cardView.leftSplitCosts.copy();
this.leftSplitRules = cardView.leftSplitRules == null ? null : new ArrayList<>(cardView.leftSplitRules);
this.leftSplitTypeLine = cardView.leftSplitTypeLine;
this.rightSplitName = cardView.rightSplitName;
this.rightSplitCosts = cardView.rightSplitCosts;
this.rightSplitRules = null;
this.rightSplitCosts = cardView.rightSplitCosts == null ? null : cardView.rightSplitCosts.copy();
this.rightSplitRules = cardView.rightSplitRules == null ? null : new ArrayList<>(cardView.rightSplitRules);
this.rightSplitTypeLine = cardView.rightSplitTypeLine;
this.targets = null;
this.artRect = cardView.artRect;
this.targets = cardView.targets == null ? null : new ArrayList<>(cardView.targets);
this.pairedCard = cardView.pairedCard;
this.bandedCards = null;
this.bandedCards = cardView.bandedCards == null ? null : new ArrayList<>(cardView.bandedCards);
this.paid = cardView.paid;
this.counters = null;
if (cardView.counters != null) {
this.counters = new ArrayList<>();
cardView.counters.forEach(c -> this.counters.add(new CounterView(c)));
}
this.controlledByOwner = cardView.controlledByOwner;
this.zone = cardView.zone;
this.rotate = cardView.rotate;
this.hideInfo = cardView.hideInfo;
this.canAttack = cardView.canAttack;
this.canBlock = cardView.canBlock;
this.inViewerOnly = cardView.inViewerOnly;
this.originalCard = cardView.originalCard.copy();
this.originalCard = cardView.originalCard == null ? null : cardView.originalCard.copy();
}
/**

View file

@ -1,6 +1,5 @@
package mage.view;
import java.util.*;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.Effect;
@ -15,6 +14,8 @@ import mage.game.permanent.PermanentToken;
import mage.target.targetpointer.TargetPointer;
import mage.util.GameLog;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -23,6 +24,17 @@ public class CardsView extends LinkedHashMap<UUID, CardView> {
public CardsView() {
}
/**
* Uses for card render tests
*
* @param cardViews
*/
public CardsView(List<CardView> cardViews) {
for (CardView view : cardViews) {
this.put(view.getId(), view);
}
}
public CardsView(Collection<? extends Card> cards) {
for (Card card : cards) {
this.put(card.getId(), new CardView(card));

View file

@ -1,12 +1,10 @@
package mage.view;
import java.io.Serializable;
import mage.counters.Counter;
import java.io.Serializable;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CounterView implements Serializable {
@ -20,6 +18,11 @@ public class CounterView implements Serializable {
this.count = counter.getCount();
}
public CounterView(final CounterView view) {
this.name = view.name;
this.count = view.count;
}
public String getName() {
return name;
}
@ -27,7 +30,7 @@ public class CounterView implements Serializable {
public int getCount() {
return count;
}
@Override
public boolean equals(Object other) {
if (other == this) {
@ -39,9 +42,9 @@ public class CounterView implements Serializable {
if (!(other instanceof CounterView)) {
return false;
}
CounterView oth = (CounterView)other;
CounterView oth = (CounterView) other;
return
(count == oth.count) &&
(name.equals(oth.name));
(name.equals(oth.name));
}
}

View file

@ -1,5 +1,6 @@
package mage.util;
import java.awt.*;
import java.util.Random;
/**
@ -32,6 +33,10 @@ public final class RandomUtil {
return random.nextDouble();
}
public static Color nextColor() {
return new Color(RandomUtil.nextInt(256), RandomUtil.nextInt(256), RandomUtil.nextInt(256));
}
public static void setSeed(long newSeed) {
random.setSeed(newSeed);
}

View file

@ -5,7 +5,6 @@ import mage.constants.SubType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class SubTypeList extends ArrayList<SubType> {
@ -20,6 +19,10 @@ public class SubTypeList extends ArrayList<SubType> {
Collections.addAll(this, subTypesList);
}
public SubTypeList(final SubTypeList list) {
this.addAll(list);
}
public boolean add(SubType... subTypes) {
return Collections.addAll(this, subTypes);
}