Fix transformable cards state desync.

This commit is contained in:
rkfg 2016-03-09 16:27:00 +03:00
parent 8be72c404e
commit 909a99ceec

View file

@ -861,6 +861,11 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
this.isSelected = card.isSelected(); this.isSelected = card.isSelected();
boolean updateImage = !gameCard.getName().equals(card.getName()) || gameCard.isFaceDown() != card.isFaceDown(); // update after e.g. turning a night/day card boolean updateImage = !gameCard.getName().equals(card.getName()) || gameCard.isFaceDown() != card.isFaceDown(); // update after e.g. turning a night/day card
if (updateImage && gameCard.canTransform() && card.canTransform() && transformed) {
if (card.getSecondCardFace() != null && card.getSecondCardFace().getName().equals(gameCard.getName())) {
transformed = false;
}
}
this.gameCard = card; this.gameCard = card;
String cardType = getType(card); String cardType = getType(card);
@ -875,7 +880,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
updateImage(); updateImage();
if (card.canTransform()) { if (card.canTransform()) {
BufferedImage transformIcon; BufferedImage transformIcon;
if (card.isTransformed()) { if (transformed) {
transformIcon = ImageManagerImpl.getInstance().getNightImage(); transformIcon = ImageManagerImpl.getInstance().getNightImage();
} else { } else {
transformIcon = ImageManagerImpl.getInstance().getDayImage(); transformIcon = ImageManagerImpl.getInstance().getDayImage();
@ -1181,8 +1186,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
public void toggleTransformed() { public void toggleTransformed() {
this.transformed = !this.transformed; this.transformed = !this.transformed;
if (transformed) { if (transformed) {
BufferedImage night = ImageManagerImpl.getInstance().getNightImage();
if (dayNightButton != null) { // if transformbable card is copied, button can be null if (dayNightButton != null) { // if transformbable card is copied, button can be null
BufferedImage night = ImageManagerImpl.getInstance().getNightImage();
dayNightButton.setIcon(new ImageIcon(night)); dayNightButton.setIcon(new ImageIcon(night));
} }
if (this.gameCard.getSecondCardFace() == null) { if (this.gameCard.getSecondCardFace() == null) {
@ -1194,14 +1199,13 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
update(this.gameCard.getSecondCardFace()); update(this.gameCard.getSecondCardFace());
} }
} else { } else {
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
if (dayNightButton != null) { // if transformbable card is copied, button can be null if (dayNightButton != null) { // if transformbable card is copied, button can be null
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
dayNightButton.setIcon(new ImageIcon(day)); dayNightButton.setIcon(new ImageIcon(day));
} }
if (!isPermanent) { // use only for custom transformation (when pressing day-night button) if (!isPermanent) { // use only for custom transformation (when pressing day-night button)
this.gameCard = this.temporary; update(this.temporary);
this.temporary = null; this.temporary = null;
update(this.gameCard);
} }
} }
String temp = this.gameCard.getAlternateName(); String temp = this.gameCard.getAlternateName();