mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Fix concurrent modification for desktop game (hopefully)
This commit is contained in:
@@ -384,7 +384,7 @@ public class GuiDesktop implements IGuiBase {
|
||||
|
||||
@Override
|
||||
public void refreshCardDetails(Collection<Card> cards) {
|
||||
//TODO: Consider caching card details like mobile game
|
||||
CMatchUI.SINGLETON_INSTANCE.refreshCardDetails(cards);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -380,9 +380,22 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
|
||||
|
||||
public void updateSingleCard(Card c) {
|
||||
Zone zone = c.getZone();
|
||||
if (null != zone && zone.getZoneType() == ZoneType.Battlefield) {
|
||||
if (zone != null && zone.getZoneType() == ZoneType.Battlefield) {
|
||||
PlayArea pa = getFieldViewFor(zone.getPlayer()).getTabletop();
|
||||
pa.updateSingleCard(c);
|
||||
pa.updateCard(c, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshCardDetails(Collection<Card> cards) {
|
||||
for (Card c : cards) {
|
||||
Zone zone = c.getZone();
|
||||
if (zone != null && zone.getZoneType() == ZoneType.Battlefield) {
|
||||
PlayArea pa = getFieldViewFor(zone.getPlayer()).getTabletop();
|
||||
CardPanel pnl = pa.getCardPanel(c.getUniqueNumber());
|
||||
if (pnl != null) {
|
||||
pnl.updatePTOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,13 +147,14 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
||||
}
|
||||
|
||||
private void createPTOverlay() {
|
||||
// Power
|
||||
// Power/Toughness
|
||||
this.ptText = new OutlinedLabel();
|
||||
this.ptText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
||||
this.ptText.setForeground(Color.white);
|
||||
this.ptText.setGlow(Color.black);
|
||||
this.add(this.ptText);
|
||||
// Toughness
|
||||
this.updatePTOverlay();
|
||||
// Damage
|
||||
this.damageText = new OutlinedLabel();
|
||||
this.damageText.setFont(this.getFont().deriveFont(Font.BOLD, 15f));
|
||||
this.damageText.setForeground(new Color(160,0,0));
|
||||
@@ -599,37 +600,19 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setText.
|
||||
* </p>
|
||||
*
|
||||
* @param card
|
||||
* a {@link forge.game.card.Card} object.
|
||||
*/
|
||||
public final void setText(final Card card) {
|
||||
if ((card == null)) {
|
||||
public final void updateText() {
|
||||
if (card == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Card name overlay
|
||||
if (card.isFaceDown()) {
|
||||
this.titleText.setText("");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.titleText.setText(card.getName());
|
||||
}
|
||||
|
||||
// P/T overlay
|
||||
String sPt = "";
|
||||
if (card.isCreature() && card.isPlaneswalker()) {
|
||||
sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCurrentLoyalty());
|
||||
} else if (card.isCreature()) {
|
||||
sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense());
|
||||
} else if (card.isPlaneswalker()) {
|
||||
sPt = String.valueOf(card.getCurrentLoyalty());
|
||||
}
|
||||
this.ptText.setText(sPt);
|
||||
|
||||
int damage = card.getDamage();
|
||||
this.damageText.setText(damage > 0 ? "\u00BB " + String.valueOf(damage) + " \u00AB" : "");
|
||||
|
||||
@@ -637,6 +620,21 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
||||
this.cardIdText.setText(Integer.toString(card.getUniqueNumber()));
|
||||
}
|
||||
|
||||
public final void updatePTOverlay() {
|
||||
// P/T overlay
|
||||
String sPt = "";
|
||||
if (card.isCreature() && card.isPlaneswalker()) {
|
||||
sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCurrentLoyalty());
|
||||
}
|
||||
else if (card.isCreature()) {
|
||||
sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense());
|
||||
}
|
||||
else if (card.isPlaneswalker()) {
|
||||
sPt = String.valueOf(card.getCurrentLoyalty());
|
||||
}
|
||||
this.ptText.setText(sPt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the card.
|
||||
*
|
||||
@@ -655,13 +653,17 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.card != card) {
|
||||
this.updatePTOverlay(); //update PT Overlay if card changes
|
||||
}
|
||||
|
||||
this.card = card;
|
||||
if (!this.isShowing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BufferedImage image = card == null ? null : ImageCache.getImage(card, imagePanel.getWidth(), imagePanel.getHeight());
|
||||
this.setText(this.getCard());
|
||||
this.updateText();
|
||||
|
||||
this.setImage(image);
|
||||
}
|
||||
|
||||
@@ -351,14 +351,6 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param c
|
||||
*/
|
||||
public void updateSingleCard(Card c) {
|
||||
updateCard(c);
|
||||
}
|
||||
|
||||
private List<CardStackRow> tryArrangePilesOfWidth(final CardStackRow lands, final CardStackRow tokens, final CardStackRow creatures, CardStackRow others) {
|
||||
List<CardStackRow> template = new ArrayList<PlayArea.CardStackRow>();
|
||||
|
||||
@@ -586,7 +578,6 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
recalculateCardPanels(model);
|
||||
}
|
||||
|
||||
|
||||
private void recalculateCardPanels(final List<Card> model) {
|
||||
List<Card> oldCards, toDelete;
|
||||
oldCards = new ArrayList<Card>();
|
||||
@@ -634,20 +625,16 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
|
||||
for (final Card card : model) {
|
||||
updateCard(card);
|
||||
updateCard(card, true);
|
||||
}
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param card
|
||||
*/
|
||||
private void updateCard(final Card card) {
|
||||
public void updateCard(final Card card, boolean fromRefresh) {
|
||||
final CardPanel toPanel = getCardPanel(card.getUniqueNumber());
|
||||
if (null == toPanel)
|
||||
return;
|
||||
if (null == toPanel) { return; }
|
||||
|
||||
if (card.isTapped()) {
|
||||
toPanel.setTapped(true);
|
||||
toPanel.setTappedAngle(forge.view.arcane.CardPanel.TAPPED_ANGLE);
|
||||
@@ -697,6 +684,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
|
||||
toPanel.setCard(toPanel.getCard());
|
||||
if (fromRefresh) {
|
||||
toPanel.updatePTOverlay(); //ensure PT Overlay updated on refresh
|
||||
}
|
||||
}
|
||||
|
||||
private static enum RowType {
|
||||
|
||||
Reference in New Issue
Block a user