use of mage.view.CounterView 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.CounterView 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.CounterView in project mage by magefree.
the class CardPanelRenderModeImage method updateCounters.
private void updateCounters(CardView card) {
if (card.getCounters() != null && !card.getCounters().isEmpty()) {
String name = "";
if (lastCardWidth != getCardWidth()) {
lastCardWidth = getCardWidth();
plusCounter = 0;
minusCounter = 0;
otherCounter = 0;
loyaltyCounter = 0;
}
plusCounterLabel.setVisible(false);
minusCounterLabel.setVisible(false);
loyaltyCounterLabel.setVisible(false);
otherCounterLabel.setVisible(false);
for (CounterView counterView : card.getCounters()) {
if (counterView.getCount() == 0) {
continue;
}
switch(counterView.getName()) {
case "+1/+1":
if (counterView.getCount() != plusCounter) {
plusCounter = counterView.getCount();
plusCounterLabel.setIcon(getCounterImageWithAmount(plusCounter, ImageManagerImpl.instance.getCounterImageGreen(), getCardWidth()));
}
plusCounterLabel.setVisible(true);
break;
case "-1/-1":
if (counterView.getCount() != minusCounter) {
minusCounter = counterView.getCount();
minusCounterLabel.setIcon(getCounterImageWithAmount(minusCounter, ImageManagerImpl.instance.getCounterImageRed(), getCardWidth()));
}
minusCounterLabel.setVisible(true);
break;
case "loyalty":
if (counterView.getCount() != loyaltyCounter) {
loyaltyCounter = counterView.getCount();
loyaltyCounterLabel.setIcon(getCounterImageWithAmount(loyaltyCounter, ImageManagerImpl.instance.getCounterImageViolet(), getCardWidth()));
}
loyaltyCounterLabel.setVisible(true);
break;
default:
if (name.isEmpty()) {
// only first other counter is shown
name = counterView.getName();
otherCounter = counterView.getCount();
otherCounterLabel.setToolTipText(name);
otherCounterLabel.setIcon(getCounterImageWithAmount(otherCounter, ImageManagerImpl.instance.getCounterImageGrey(), getCardWidth()));
otherCounterLabel.setVisible(true);
}
}
}
getCounterPanel().setVisible(true);
} else {
plusCounterLabel.setVisible(false);
minusCounterLabel.setVisible(false);
loyaltyCounterLabel.setVisible(false);
otherCounterLabel.setVisible(false);
getCounterPanel().setVisible(false);
}
}
use of mage.view.CounterView in project mage by magefree.
the class CardRenderer method drawCounters.
// Draw +1/+1 and other counters
protected void drawCounters(Graphics2D g) {
int xPos = (int) (0.65 * cardWidth);
int yPos = (int) (0.15 * cardHeight);
if (cardView.getCounters() != null) {
for (CounterView v : cardView.getCounters()) {
// Don't render loyalty, we do that in the bottom corner
if (!v.getName().equals("loyalty")) {
Polygon p;
switch(v.getName()) {
case "+1/+1":
p = PLUS_COUNTER_POLY;
break;
case "-1/-1":
p = MINUS_COUNTER_POLY;
break;
case "time":
p = TIME_COUNTER_POLY;
break;
default:
p = OTHER_COUNTER_POLY;
break;
}
double scale = (0.1 * 0.25 * cardWidth);
Graphics2D g2 = (Graphics2D) g.create();
g2.translate(xPos, yPos);
g2.scale(scale, scale);
g2.setColor(Color.white);
g2.fillPolygon(p);
g2.setColor(Color.black);
g2.drawPolygon(p);
g2.setFont(new Font("Arial", Font.BOLD, 7));
String cstr = String.valueOf(v.getCount());
int strW = g2.getFontMetrics().stringWidth(cstr);
g2.drawString(cstr, 5 - strW / 2, 8);
g2.dispose();
yPos += ((int) (0.30 * cardWidth));
}
}
}
}
Aggregations