use of mage.view.PermanentView in project mage by magefree.
the class CardLayoutStrategyImpl method getVerticalCul.
// The root permanent is col 0. An attachment attached to the root is col 1. And an attachement attached to the first attachment is col 2. etc.
private int getVerticalCul(PermanentView permanentView, BattlefieldPanel battlefieldPanel) {
int cul = 0;
if (permanentView.isAttachedTo()) {
PermanentView attachedToPermanent = battlefieldPanel.getBattlefield().get(permanentView.getAttachedTo());
if (attachedToPermanent != null) {
cul = getVerticalCul(attachedToPermanent, battlefieldPanel);
}
cul++;
}
return cul;
}
use of mage.view.PermanentView in project mage by magefree.
the class CardLayoutStrategyImpl method doLayout.
@Override
public void doLayout(BattlefieldPanel battlefieldPanel, int battlefieldWidth) {
Map<UUID, MageCard> cards = battlefieldPanel.getPermanentPanels();
JLayeredPane mainPanel = battlefieldPanel.getMainPanel();
// does the basic layout of rows and colums
int height = Plugins.instance.sortPermanents(battlefieldPanel.getUiComponentsList(), cards, battlefieldPanel.isTopPanelBattlefield());
mainPanel.setPreferredSize(new Dimension(battlefieldWidth - 30, height));
for (PermanentView permanent : battlefieldPanel.getBattlefield().values()) {
if (permanent.getAttachments() != null && !permanent.isAttachedTo()) {
// Layout only permanents that are not attached to other permanents itself
groupAttachments(battlefieldPanel, mainPanel, cards, permanent);
}
}
}
use of mage.view.PermanentView in project mage by magefree.
the class GuiDisplayUtil method getTextLinesfromCardView.
public static TextLines getTextLinesfromCardView(CardView card) {
TextLines textLines = new TextLines();
// rules
textLines.setLines(new ArrayList<>(card.getRules()));
for (String rule : card.getRules()) {
textLines.setBasicTextLength(textLines.getBasicTextLength() + rule.length());
}
// counters
if (card.getMageObjectType().canHaveCounters()) {
java.util.List<CounterView> counters = new ArrayList<>();
if (card.getCounters() != null) {
counters.addAll(card.getCounters());
}
if (!counters.isEmpty()) {
StringBuilder sb = new StringBuilder();
int index = 0;
for (CounterView counter : counters) {
if (counter.getCount() > 0) {
if (index == 0) {
sb.append("<b>Counters:</b> ");
} else {
sb.append(", ");
}
sb.append(counter.getCount()).append(" x <i>").append(counter.getName()).append("</i>");
index++;
}
}
textLines.getLines().add(sb.toString());
textLines.setBasicTextLength(textLines.getBasicTextLength() + 50);
}
}
// damage
if (card.getMageObjectType().isPermanent() && card instanceof PermanentView) {
int damage = ((PermanentView) card).getDamage();
if (damage > 0) {
textLines.getLines().add("<span color='red'><b>Damage dealt:</b> " + damage + "</span>");
textLines.setBasicTextLength(textLines.getBasicTextLength() + 50);
}
}
return textLines;
}
use of mage.view.PermanentView in project mage by magefree.
the class CardLayoutStrategyImpl method layoutAttachements.
private void layoutAttachements(int startingCardX, int maxColumnLevels, int ZOrder, PermanentView permanentWithAttachmentsView, Map<UUID, MageCard> cards, BattlefieldPanel battlefieldPanel, JLayeredPane mainPanel, Rectangle lastAttachmentRect) {
// put attachments to the next level (take lastAttachmentRect and apply offsets)
MageCard cardWithAttachments = cards.get(permanentWithAttachmentsView.getId());
if (cardWithAttachments == null) {
return;
}
// from right to left [2][1][0]
int col = getVerticalCul(permanentWithAttachmentsView, battlefieldPanel);
int currentAttachmentCol = col + 1;
cardWithAttachments.getLinks().clear();
int verticalIndex = permanentWithAttachmentsView.getAttachments().size();
for (UUID attachmentId : permanentWithAttachmentsView.getAttachments()) {
// put child attachments of the attachment
PermanentView attachedPermanentView = battlefieldPanel.getBattlefield().get(attachmentId);
if (attachedPermanentView != null && attachedPermanentView.getAttachments() != null && !attachedPermanentView.getAttachments().isEmpty()) {
layoutAttachements(startingCardX, maxColumnLevels, ZOrder, attachedPermanentView, cards, battlefieldPanel, mainPanel, lastAttachmentRect);
}
// put attachment
MageCard attachedCard = cards.get(attachmentId);
if (attachedCard != null) {
// x position
Point point = new Point();
point.setLocation(startingCardX + (maxColumnLevels - currentAttachmentCol) * Math.max(cardWithAttachments.getCardLocation().getCardWidth() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_ALL_X), lastAttachmentRect.getY());
lastAttachmentRect.setLocation(point);
// set position first to the same as of the permanent it is attached to
attachedCard.setCardLocation(lastAttachmentRect.x, lastAttachmentRect.y);
// y position
cardWithAttachments.getLinks().add(attachedCard);
int dyOffset = Math.max(cardWithAttachments.getCardLocation().getCardHeight() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_SINGLE_Y);
if (verticalIndex == 1) {
lastAttachmentRect.translate(Math.max(cardWithAttachments.getCardLocation().getCardWidth() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_ALL_X), dyOffset);
} else {
lastAttachmentRect.translate(0, dyOffset);
}
cardWithAttachments.setCardLocation(lastAttachmentRect.x, lastAttachmentRect.y);
battlefieldPanel.moveToFront(attachedCard);
battlefieldPanel.moveToFront(cardWithAttachments);
mainPanel.setComponentZOrder(attachedCard, ZOrder--);
verticalIndex--;
}
}
}
use of mage.view.PermanentView in project mage by magefree.
the class CardPanel method update.
/**
* Inheriting classes should implement update(CardView card) by using this.
* However, they should ALSO call repaint() after the superclass call to
* this function, that can't be done here as the overriders may need to do
* things both before and after this call before repainting.
*
* @param card
*/
@Override
public void update(CardView card) {
if (card == null) {
return;
}
if (guiTransformed && card.equals(this.cardSideMain)) {
// update can be called from different places (after transform click, after selection change, etc)
// if card temporary transformed before (by icon click) then do not update full data (as example, after selection changed)
this.isChoosable = card.isChoosable();
this.isSelected = card.isSelected();
return;
} else {
this.setUpdateCard(card);
}
// Animation update
if (isPermanent && (card instanceof PermanentView)) {
boolean needsTapping = isTapped() != ((PermanentView) card).isTapped();
boolean needsFlipping = isFlipped() != ((PermanentView) card).isFlipped();
if (needsTapping || needsFlipping) {
Animation.tapCardToggle(this, needsTapping, needsFlipping);
}
if (needsTapping && ((PermanentView) card).isTapped()) {
AudioManager.playTapPermanent();
}
boolean needsTranforming = isTransformed() != card.isTransformed();
if (needsTranforming && !animationInProgress) {
Animation.transformCard(this);
}
}
// Update panel attributes
this.isChoosable = card.isChoosable();
this.isSelected = card.isSelected();
// Update art?
boolean mustUpdateArt = (!getGameCard().getName().equals(card.getName())) || (getGameCard().isFaceDown() != card.isFaceDown());
// Set the new card
this.setGameCard(card);
this.setGameCardSides(card);
// Update tooltip text
String cardType = getType(card);
tooltipText.setText(getText(cardType, card));
// Update the image
if (mustUpdateArt) {
updateArtImage();
}
// Update transform circle
if (card.canTransform() && dayNightButton != null) {
BufferedImage transformIcon;
if (this.isTransformed()) {
transformIcon = ImageManagerImpl.instance.getNightImage();
} else {
transformIcon = ImageManagerImpl.instance.getDayImage();
}
// show T button for any cards and permanents
dayNightButton.setVisible(true);
dayNightButton.setIcon(new ImageIcon(transformIcon));
}
}
Aggregations