Prevent crash when resolving Ponder on mobile game

This commit is contained in:
drdev
2014-04-29 04:42:53 +00:00
parent 21a1c26cc7
commit 2394b8fb19
2 changed files with 16 additions and 32 deletions

View File

@@ -65,10 +65,12 @@ public class SGuiChoose {
} }
public static <T> T one(final String message, final Collection<T> choices) { public static <T> T one(final String message, final Collection<T> choices) {
if (choices == null || choices.isEmpty()) if (choices == null || choices.isEmpty()) {
return null; return null;
if( choices.size() == 1) }
if (choices.size() == 1) {
return Iterables.getFirst(choices, null); return Iterables.getFirst(choices, null);
}
final List<T> choice = SGuiChoose.getChoices(message, 1, 1, choices); final List<T> choice = SGuiChoose.getChoices(message, 1, 1, choices);
assert choice.size() == 1; assert choice.size() == 1;

View File

@@ -1,12 +1,8 @@
package forge; package forge;
import forge.FThreads;
import forge.game.card.Card; import forge.game.card.Card;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
/** /**
* Holds player interactions using standard windows * 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) { public static boolean confirm(final Card c, final String question, final boolean defaultIsYes, final String[] options) {
Callable<Boolean> confirmTask = new Callable<Boolean>() { if (c != null) {
@Override FThreads.invokeInEdtAndWait(new Runnable() {
public Boolean call() throws Exception { @Override
if (c != null) { public void run() {
GuiBase.getInterface().setCard(c); 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(); final String title = c == null ? "Question" : c.getName() + " - Ability";
} String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question;
return false; 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) { public static void message(final String message, final String title) {
FThreads.invokeInEdtAndWait(new Runnable() { SOptionPane.showMessageDialog(message, title, null);
@Override
public void run() {
SOptionPane.showMessageDialog(message, title, null);
}
});
} }
} }