mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
prevent NPE when overriding CardView for HumanCostDecision
This commit is contained in:
@@ -1170,6 +1170,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
|
|||||||
private boolean confirmAction(CostPart costPart, String message) {
|
private boolean confirmAction(CostPart costPart, String message) {
|
||||||
CardView cardView = ability.getCardView();
|
CardView cardView = ability.getCardView();
|
||||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||||
|
try {
|
||||||
//for cards like Sword-Point Diplomacy and others that uses imprinted as container for their ability
|
//for cards like Sword-Point Diplomacy and others that uses imprinted as container for their ability
|
||||||
if (cardView != null && cardView.getImprintedCards() != null && cardView.getImprintedCards().size() == 1)
|
if (cardView != null && cardView.getImprintedCards() != null && cardView.getImprintedCards().size() == 1)
|
||||||
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getImprintedCards().get(0).getCurrentState().getImageKey()));
|
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getImprintedCards().get(0).getCurrentState().getImageKey()));
|
||||||
@@ -1179,6 +1180,10 @@ public class HumanCostDecision extends CostDecisionMakerBase {
|
|||||||
if (!cardView.hasAlternateState()) //don't override if it has alternatestate since it maybe showing alternate view
|
if (!cardView.hasAlternateState()) //don't override if it has alternatestate since it maybe showing alternate view
|
||||||
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getCurrentState().getImageKey()));
|
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getCurrentState().getImageKey()));
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
//prevent NPE when overriding the cardView, the getPaperCardFromImageKey can return null making the GUI freeze, reset the view if error happens
|
||||||
|
cardView = ability.getCardView();
|
||||||
|
}
|
||||||
return controller.getGui().confirm(cardView, message.replaceAll("\n", " "));
|
return controller.getGui().confirm(cardView, message.replaceAll("\n", " "));
|
||||||
} else {
|
} else {
|
||||||
return controller.confirmPayment(costPart, message, ability);
|
return controller.confirmPayment(costPart, message, ability);
|
||||||
|
|||||||
@@ -1786,9 +1786,14 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
public boolean confirmPayment(final CostPart costPart, final String question, SpellAbility sa) {
|
public boolean confirmPayment(final CostPart costPart, final String question, SpellAbility sa) {
|
||||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||||
CardView cardView = sa.getView().getHostCard();
|
CardView cardView = sa.getView().getHostCard();
|
||||||
|
try {
|
||||||
if (cardView.getZone() == null || cardView.getZone().isHidden())
|
if (cardView.getZone() == null || cardView.getZone().isHidden())
|
||||||
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getCurrentState().getImageKey()));
|
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getCurrentState().getImageKey()));
|
||||||
return this.getGui().confirm(sa.getView().getHostCard(), question.replaceAll("\n", " "));
|
} catch (Exception e) {
|
||||||
|
//prevent NPE
|
||||||
|
cardView = sa.getView().getHostCard();
|
||||||
|
}
|
||||||
|
return this.getGui().confirm(cardView, question.replaceAll("\n", " "));
|
||||||
} else {
|
} else {
|
||||||
final InputConfirm inp = new InputConfirm(this, question, sa);
|
final InputConfirm inp = new InputConfirm(this, question, sa);
|
||||||
inp.showAndWait();
|
inp.showAndWait();
|
||||||
|
|||||||
Reference in New Issue
Block a user