use of mage.view.PermanentView in project mage by magefree.
the class MageActionCallback method displayEnlargedCard.
private void displayEnlargedCard(final CardView cardView, final TransferData data) {
MageCard cardPanel = data.getComponent().getTopPanelRef();
ThreadUtils.threadPool3.submit(() -> {
if (cardView == null) {
return;
}
try {
if (enlargedWindowState == EnlargedWindowState.CLOSED) {
return;
}
MageComponents mageComponentCardPreviewContainer;
MageComponents mageComponentCardPreviewPane;
if (cardView.isToRotate()) {
if (enlargedWindowState == EnlargedWindowState.NORMAL) {
hideEnlargedCard();
enlargedWindowState = EnlargedWindowState.ROTATED;
}
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER_ROTATED;
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE_ROTATED;
} else {
if (enlargedWindowState == EnlargedWindowState.ROTATED) {
hideEnlargedCard();
enlargedWindowState = EnlargedWindowState.NORMAL;
}
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER;
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE;
}
final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer);
Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane);
Component parentComponent = SwingUtilities.getRoot(cardPanel);
if (cardPreviewPane != null && parentComponent != null) {
Point parentPoint = parentComponent.getLocationOnScreen();
data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
Point location = new Point((int) data.getLocationOnScreen().getX() + data.getPopupOffsetX() - 40, (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
popupContainer.setVisible(true);
// popup hint mode
Image image = null;
CardView displayCard = cardPanel.getOriginal();
switch(enlargeMode) {
case COPY:
if (cardView instanceof PermanentView) {
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
}
break;
case ALTERNATE:
if (cardView.getAlternateName() != null) {
if (cardView instanceof PermanentView && !cardView.isFlipCard() && !cardView.canTransform() && ((PermanentView) cardView).isCopy()) {
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
} else {
image = ImageCache.getImageOriginalAlternateName(cardView);
displayCard = displayCard.getSecondCardFace();
}
}
break;
default:
break;
}
if (image == null) {
image = cardPanel.getImage();
}
// shows the card in the popup Container
displayCardInfo(displayCard, image, (BigCard) cardPreviewPane);
} else {
logger.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName());
}
} catch (Exception e) {
logger.warn("Problem dring display of enlarged card", e);
}
});
}
use of mage.view.PermanentView in project mage by magefree.
the class BattlefieldPanel method update.
public void update(Map<UUID, PermanentView> battlefield) {
gameUpdateTimer.stop();
boolean changed = false;
List<PermanentView> permanentsToAdd = new ArrayList<>();
for (PermanentView permanent : battlefield.values()) {
if (!permanent.isPhasedIn()) {
continue;
}
MageCard oldFound = permanents.get(permanent.getId());
MagePermanent oldMagePermanent = oldFound == null ? null : (MagePermanent) oldFound.getMainPanel();
if (oldMagePermanent == null) {
permanentsToAdd.add(permanent);
changed = true;
} else {
if (!changed) {
changed = oldMagePermanent.getOriginalPermanent().isCreature() != permanent.isCreature();
// Check if there was a change in the permanets that are the permanent attached to
if (!changed) {
int attachments = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size();
int attachmentsBefore = oldMagePermanent.getLinks().size();
if (attachments != attachmentsBefore) {
changed = true;
} else if (attachments > 0) {
Set<UUID> attachmentIds = new HashSet<>(permanent.getAttachments());
for (MageCard mageCard : oldMagePermanent.getLinks()) {
MagePermanent magePermanent = (MagePermanent) mageCard.getMainPanel();
if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) {
// that means that the amount of attachments is the same
// but they are different:
// we've just found an attachment on previous view
// that doesn't exist anymore on current view
changed = true;
break;
}
}
}
}
// Check if permanents it now attached to another or no permanent
if (!changed) {
UUID attachedToIdBefore = oldMagePermanent.getOriginalPermanent().getAttachedTo();
UUID attachedToId = permanent.getAttachedTo();
if (attachedToIdBefore == null && attachedToId != null || attachedToId == null && attachedToIdBefore != null || (attachedToIdBefore != null && !attachedToIdBefore.equals(attachedToId))) {
changed = true;
}
}
// Check for changes in the counters of the permanent
if (!changed) {
List<CounterView> counters1 = oldMagePermanent.getOriginalPermanent().getCounters();
List<CounterView> counters2 = permanent.getCounters();
if (counters1 == null && counters2 != null || counters1 != null && counters2 == null) {
changed = true;
} else if (counters1 != null && counters2 != null && counters1.size() != counters2.size()) {
changed = true;
}
}
}
oldMagePermanent.update(permanent);
}
}
addedArtifact = addedCreature = addedPermanent = false;
int count = permanentsToAdd.size();
for (PermanentView permanent : permanentsToAdd) {
addPermanent(permanent, count);
}
if (addedArtifact) {
AudioManager.playAddArtifact();
} else if (addedCreature) {
AudioManager.playSummon();
} else if (addedPermanent) {
AudioManager.playAddPermanent();
}
removedCreature = false;
for (Iterator<Entry<UUID, MageCard>> iterator = permanents.entrySet().iterator(); iterator.hasNext(); ) {
Entry<UUID, MageCard> entry = iterator.next();
if (!battlefield.containsKey(entry.getKey()) || !battlefield.get(entry.getKey()).isPhasedIn()) {
removePermanent(entry.getKey(), 1);
iterator.remove();
changed = true;
}
}
if (removedCreature) {
AudioManager.playDiedCreature();
}
if (changed) {
this.battlefield = battlefield;
sortLayout();
}
}
use of mage.view.PermanentView in project mage by magefree.
the class ModernCardRenderer method drawNameLine.
// Draw the name line
protected void drawNameLine(Graphics2D g, CardPanelAttributes attribs, String baseName, String manaCost, int x, int y, int w, int h) {
// Width of the mana symbols
int manaCostWidth;
if (cardView.isAbility()) {
manaCostWidth = 0;
} else {
manaCostWidth = CardRendererUtils.getManaCostWidth(manaCost, boxTextHeight);
}
// Available width for name. Add a little bit of slop so that one character
// can partially go underneath the mana cost
int availableWidth = w - manaCostWidth + 2;
// Draw the name
String nameStr;
if (cardView.isFaceDown()) {
if (cardView instanceof PermanentView && ((PermanentView) cardView).isManifested()) {
nameStr = "Manifest: " + cardView.getName();
} else {
nameStr = "Morph: " + cardView.getName();
}
} else {
nameStr = baseName;
}
if (!nameStr.isEmpty()) {
AttributedString str = new AttributedString(nameStr);
str.addAttribute(TextAttribute.FONT, boxTextFont);
TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext());
int breakIndex = measure.getLineBreakIndex(0, availableWidth);
if (breakIndex < nameStr.length()) {
str = new AttributedString(nameStr);
str.addAttribute(TextAttribute.FONT, boxTextFontNarrow);
measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext());
breakIndex = measure.getLineBreakIndex(0, availableWidth);
}
if (breakIndex > 0) {
TextLayout layout = measure.getLayout(0, breakIndex);
g.setColor(getBoxTextColor(attribs));
layout.draw(g, x, y + boxTextOffset + boxTextHeight - 1);
}
}
// Draw the mana symbols
if (!cardView.isAbility() && !cardView.isFaceDown()) {
ManaSymbols.draw(g, manaCost, x + w - manaCostWidth, y + boxTextOffset, boxTextHeight, ModernCardRenderer.MANA_ICONS_TEXT_COLOR, 2);
}
}
use of mage.view.PermanentView in project mage by magefree.
the class ModernCardRenderer method drawBottomRight.
// Draw the P/T and/or Loyalty boxes
protected void drawBottomRight(Graphics2D g, CardPanelAttributes attribs, Paint borderPaint, Color fill) {
// No bottom right for abilities
if (cardView.isAbility()) {
return;
}
// Where to start drawing the things
int curY = cardHeight - (int) (0.03f * cardHeight);
// Width of the boxes
int partBoxWidth = (int) Math.max(30, 0.20f * cardWidth);
// Is it a creature?
boolean isVehicle = cardView.getSubTypes().contains(SubType.VEHICLE);
if (cardView.isCreature() || isVehicle) {
// draws p/t by parts
// Arial font is too narrow for devider (2/2) and needs extra space
int ptDeviderSpace = 1;
String ptText1 = cardView.getPower();
String ptText2 = "/";
String ptText3 = CardRendererUtils.getCardLifeWithDamage(cardView);
int ptTextWidth1 = g.getFontMetrics(ptTextFont).stringWidth(ptText1);
int ptTextWidth2 = g.getFontMetrics(ptTextFont).stringWidth(ptText2) + 2 * ptDeviderSpace;
int ptTextWidth3 = g.getFontMetrics(ptTextFont).stringWidth(ptText3);
// PT max size
int ptContentWidth = contentInset + ptTextWidth1 + ptDeviderSpace + ptTextWidth2 + ptDeviderSpace + ptTextWidth3 + contentInset;
partBoxWidth = Math.max(ptContentWidth, partBoxWidth);
int x = cardWidth - borderWidth - partBoxWidth;
// Draw PT box
CardRendererUtils.drawRoundedBox(g, x, curY - boxHeight, partBoxWidth, boxHeight, contentInset, borderPaint, isVehicle ? BOX_VEHICLE : fill);
// Draw shadow line top
g.setColor(new Color(0, 0, 0, 150));
g.fillRect(x + contentInset, curY - boxHeight - 1, partBoxWidth - 2 * contentInset, 1);
// Draw text
Color defaultTextColor;
boolean defaultTextLight;
if (isVehicle) {
boolean isAnimated = !(cardView instanceof PermanentView) || cardView.isCreature();
if (isAnimated) {
defaultTextColor = Color.white;
} else {
defaultTextColor = new Color(180, 180, 180);
}
defaultTextLight = true;
} else {
defaultTextColor = getBoxTextColor(attribs);
defaultTextLight = !defaultTextColor.equals(Color.black);
}
g.setColor(defaultTextColor);
g.setFont(ptTextFont);
// draws
int ptEmptySpace = (partBoxWidth - ptContentWidth) / 2;
int ptPosStart1 = x + contentInset + ptEmptySpace;
int ptPosStart2 = ptPosStart1 + ptTextWidth1 + ptDeviderSpace;
int ptPosStart3 = ptPosStart2 + ptTextWidth2 + ptDeviderSpace;
// p
g.setColor(CardRendererUtils.getCardTextColor(cardView.getOriginalCard().getPower(), false, defaultTextColor, defaultTextLight));
// left
g.drawString(ptText1, ptPosStart1, curY - ptTextOffset - 1);
// /
g.setColor(defaultTextColor);
// center
g.drawString(ptText2, ptPosStart2, curY - ptTextOffset - 1);
// t
g.setColor(CardRendererUtils.getCardTextColor(cardView.getOriginalCard().getToughness(), CardRendererUtils.isCardWithDamage(cardView), defaultTextColor, defaultTextLight));
// right
g.drawString(ptText3, ptPosStart3, curY - ptTextOffset - 1);
//
g.setColor(defaultTextColor);
// Advance
curY -= boxHeight;
}
// of a walker without a starting loyalty (EG: Arlin Kord's flipped side).
if (cardView.isPlanesWalker() && (cardView instanceof PermanentView || !cardView.getStartingLoyalty().equals("0"))) {
// Draw the PW loyalty box
int w = partBoxWidth;
int h = partBoxWidth / 2;
int x = cardWidth - partBoxWidth - borderWidth;
int y = curY - h;
Polygon symbol = new Polygon(new int[] { x + w / 2, (int) (x + w * 0.9), x + w, (int) (x + w * 0.6), x + w / 2, (int) (x + w * 0.4), x, (int) (x + w * 0.1) }, new int[] { y + h, (int) (y + 0.8 * h), y, (int) (y - 0.2 * h), y, (int) (y - 0.2 * h), y, (int) (y + 0.8 * h) }, 8);
// Draw + stroke
g.setColor(Color.black);
g.fillPolygon(symbol);
g.setColor(new Color(200, 200, 200));
g.setStroke(new BasicStroke(2));
g.drawPolygon(symbol);
g.setStroke(new BasicStroke(1));
// Loyalty number
String loyalty;
if (cardView instanceof PermanentView) {
loyalty = cardView.getLoyalty();
} else {
loyalty = cardView.getStartingLoyalty();
}
g.setFont(ptTextFont);
g.setColor(Color.white);
int loyaltyWidth = g.getFontMetrics().stringWidth(loyalty);
g.drawString(loyalty, x + (w - loyaltyWidth) / 2, y + ptTextHeight + (h - ptTextHeight) / 2);
// Advance
curY -= (int) (1.2 * y);
}
// does it have damage on it?
if ((cardView instanceof PermanentView) && ((PermanentView) cardView).getDamage() > 0) {
int x = cardWidth - partBoxWidth - borderWidth;
int y = curY - boxHeight;
String damage = String.valueOf(((PermanentView) cardView).getDamage());
g.setFont(ptTextFont);
int txWidth = g.getFontMetrics().stringWidth(damage);
g.setColor(Color.red);
g.fillRect(x, y, partBoxWidth, boxHeight);
g.setColor(Color.white);
g.drawRect(x, y, partBoxWidth, boxHeight);
g.drawString(damage, x + (partBoxWidth - txWidth) / 2, curY - 1);
}
}
use of mage.view.PermanentView in project mage by magefree.
the class CardLayoutStrategyImpl method calculateNeededNumberOfVerticalColumns.
private AttachmentLayoutInfos calculateNeededNumberOfVerticalColumns(int currentCol, BattlefieldPanel battlefieldPanel, Map<UUID, MageCard> cards, PermanentView permanentWithAttachmentsView) {
int maxCol = ++currentCol;
int attachments = 0;
for (UUID attachmentId : permanentWithAttachmentsView.getAttachments()) {
PermanentView attachedPermanent = battlefieldPanel.getBattlefield().get(attachmentId);
if (attachedPermanent != null) {
attachments++;
if (attachedPermanent.getAttachments() != null && !attachedPermanent.getAttachments().isEmpty()) {
AttachmentLayoutInfos attachmentLayoutInfos = calculateNeededNumberOfVerticalColumns(currentCol, battlefieldPanel, cards, attachedPermanent);
if (attachmentLayoutInfos.getColumns() > maxCol) {
maxCol = attachmentLayoutInfos.getColumns();
attachments += attachmentLayoutInfos.getAttachments();
}
}
}
}
return new AttachmentLayoutInfos(maxCol, attachments);
}
Aggregations