mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Prevent crash when resolving Ponder on mobile game
This commit is contained in:
@@ -65,10 +65,12 @@ public class SGuiChoose {
|
||||
}
|
||||
|
||||
public static <T> T one(final String message, final Collection<T> choices) {
|
||||
if (choices == null || choices.isEmpty())
|
||||
if (choices == null || choices.isEmpty()) {
|
||||
return null;
|
||||
if( choices.size() == 1)
|
||||
}
|
||||
if (choices.size() == 1) {
|
||||
return Iterables.getFirst(choices, null);
|
||||
}
|
||||
|
||||
final List<T> choice = SGuiChoose.getChoices(message, 1, 1, choices);
|
||||
assert choice.size() == 1;
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package forge;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.game.card.Card;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* Holds player interactions using standard windows
|
||||
*
|
||||
@@ -25,29 +21,20 @@ public class SGuiDialog {
|
||||
}
|
||||
|
||||
public static boolean confirm(final Card c, final String question, final boolean defaultIsYes, final String[] options) {
|
||||
Callable<Boolean> confirmTask = new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
if (c != null) {
|
||||
if (c != null) {
|
||||
FThreads.invokeInEdtAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GuiBase.getInterface().setCard(c);
|
||||
}
|
||||
|
||||
final String title = c == null ? "Question" : c.getName() + " - Ability";
|
||||
String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question;
|
||||
String[] opts = options == null ? defaultConfirmOptions : options;
|
||||
int answer = SOptionPane.showOptionDialog(questionToUse, title, SOptionPane.QUESTION_ICON, opts, defaultIsYes ? 0 : 1);
|
||||
return answer == 0;
|
||||
}};
|
||||
|
||||
FutureTask<Boolean> future = new FutureTask<Boolean>(confirmTask);
|
||||
FThreads.invokeInEdtAndWait(future);
|
||||
try {
|
||||
return future.get().booleanValue();
|
||||
});
|
||||
}
|
||||
catch (Exception e) { // should be no exception here
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
||||
final String title = c == null ? "Question" : c.getName() + " - Ability";
|
||||
String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question;
|
||||
String[] opts = options == null ? defaultConfirmOptions : options;
|
||||
int answer = SOptionPane.showOptionDialog(questionToUse, title, SOptionPane.QUESTION_ICON, opts, defaultIsYes ? 0 : 1);
|
||||
return answer == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,11 +50,6 @@ public class SGuiDialog {
|
||||
}
|
||||
|
||||
public static void message(final String message, final String title) {
|
||||
FThreads.invokeInEdtAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SOptionPane.showMessageDialog(message, title, null);
|
||||
}
|
||||
});
|
||||
SOptionPane.showMessageDialog(message, title, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user