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
|
@Override
|
||||||
public void refreshCardDetails(Collection<Card> cards) {
|
public void refreshCardDetails(Collection<Card> cards) {
|
||||||
//TODO: Consider caching card details like mobile game
|
CMatchUI.SINGLETON_INSTANCE.refreshCardDetails(cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -380,9 +380,22 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
|
|||||||
|
|
||||||
public void updateSingleCard(Card c) {
|
public void updateSingleCard(Card c) {
|
||||||
Zone zone = c.getZone();
|
Zone zone = c.getZone();
|
||||||
if (null != zone && zone.getZoneType() == ZoneType.Battlefield) {
|
if (zone != null && zone.getZoneType() == ZoneType.Battlefield) {
|
||||||
PlayArea pa = getFieldViewFor(zone.getPlayer()).getTabletop();
|
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() {
|
private void createPTOverlay() {
|
||||||
// Power
|
// Power/Toughness
|
||||||
this.ptText = new OutlinedLabel();
|
this.ptText = new OutlinedLabel();
|
||||||
this.ptText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
this.ptText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
||||||
this.ptText.setForeground(Color.white);
|
this.ptText.setForeground(Color.white);
|
||||||
this.ptText.setGlow(Color.black);
|
this.ptText.setGlow(Color.black);
|
||||||
this.add(this.ptText);
|
this.add(this.ptText);
|
||||||
// Toughness
|
this.updatePTOverlay();
|
||||||
|
// Damage
|
||||||
this.damageText = new OutlinedLabel();
|
this.damageText = new OutlinedLabel();
|
||||||
this.damageText.setFont(this.getFont().deriveFont(Font.BOLD, 15f));
|
this.damageText.setFont(this.getFont().deriveFont(Font.BOLD, 15f));
|
||||||
this.damageText.setForeground(new Color(160,0,0));
|
this.damageText.setForeground(new Color(160,0,0));
|
||||||
@@ -599,37 +600,19 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public final void updateText() {
|
||||||
* <p>
|
if (card == null) {
|
||||||
* setText.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param card
|
|
||||||
* a {@link forge.game.card.Card} object.
|
|
||||||
*/
|
|
||||||
public final void setText(final Card card) {
|
|
||||||
if ((card == null)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Card name overlay
|
// Card name overlay
|
||||||
if (card.isFaceDown()) {
|
if (card.isFaceDown()) {
|
||||||
this.titleText.setText("");
|
this.titleText.setText("");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.titleText.setText(card.getName());
|
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();
|
int damage = card.getDamage();
|
||||||
this.damageText.setText(damage > 0 ? "\u00BB " + String.valueOf(damage) + " \u00AB" : "");
|
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()));
|
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.
|
* Gets the card.
|
||||||
*
|
*
|
||||||
@@ -655,13 +653,17 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.card != card) {
|
||||||
|
this.updatePTOverlay(); //update PT Overlay if card changes
|
||||||
|
}
|
||||||
|
|
||||||
this.card = card;
|
this.card = card;
|
||||||
if (!this.isShowing()) {
|
if (!this.isShowing()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BufferedImage image = card == null ? null : ImageCache.getImage(card, imagePanel.getWidth(), imagePanel.getHeight());
|
final BufferedImage image = card == null ? null : ImageCache.getImage(card, imagePanel.getWidth(), imagePanel.getHeight());
|
||||||
this.setText(this.getCard());
|
this.updateText();
|
||||||
|
|
||||||
this.setImage(image);
|
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) {
|
private List<CardStackRow> tryArrangePilesOfWidth(final CardStackRow lands, final CardStackRow tokens, final CardStackRow creatures, CardStackRow others) {
|
||||||
List<CardStackRow> template = new ArrayList<PlayArea.CardStackRow>();
|
List<CardStackRow> template = new ArrayList<PlayArea.CardStackRow>();
|
||||||
|
|
||||||
@@ -586,7 +578,6 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
|||||||
recalculateCardPanels(model);
|
recalculateCardPanels(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void recalculateCardPanels(final List<Card> model) {
|
private void recalculateCardPanels(final List<Card> model) {
|
||||||
List<Card> oldCards, toDelete;
|
List<Card> oldCards, toDelete;
|
||||||
oldCards = new ArrayList<Card>();
|
oldCards = new ArrayList<Card>();
|
||||||
@@ -634,20 +625,16 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (final Card card : model) {
|
for (final Card card : model) {
|
||||||
updateCard(card);
|
updateCard(card, true);
|
||||||
}
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void updateCard(final Card card, boolean fromRefresh) {
|
||||||
* TODO: Write javadoc for this method.
|
|
||||||
* @param card
|
|
||||||
*/
|
|
||||||
private void updateCard(final Card card) {
|
|
||||||
final CardPanel toPanel = getCardPanel(card.getUniqueNumber());
|
final CardPanel toPanel = getCardPanel(card.getUniqueNumber());
|
||||||
if (null == toPanel)
|
if (null == toPanel) { return; }
|
||||||
return;
|
|
||||||
if (card.isTapped()) {
|
if (card.isTapped()) {
|
||||||
toPanel.setTapped(true);
|
toPanel.setTapped(true);
|
||||||
toPanel.setTappedAngle(forge.view.arcane.CardPanel.TAPPED_ANGLE);
|
toPanel.setTappedAngle(forge.view.arcane.CardPanel.TAPPED_ANGLE);
|
||||||
@@ -697,6 +684,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
toPanel.setCard(toPanel.getCard());
|
toPanel.setCard(toPanel.getCard());
|
||||||
|
if (fromRefresh) {
|
||||||
|
toPanel.updatePTOverlay(); //ensure PT Overlay updated on refresh
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum RowType {
|
private static enum RowType {
|
||||||
|
|||||||
Reference in New Issue
Block a user