mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Cleanup: use Lists rather than arrays whenever applicable (removes some methods)
This commit is contained in:
@@ -132,12 +132,12 @@ public class GuiDesktop implements IGuiBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showOptionDialog(final String message, final String title, final FSkinProp icon, final String[] options, final int defaultOption) {
|
||||
public int showOptionDialog(final String message, final String title, final FSkinProp icon, final List<String> options, final int defaultOption) {
|
||||
return FOptionPane.showOptionDialog(message, title, icon == null ? null : FSkin.getImage(icon), options, defaultOption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String showInputDialog(final String message, final String title, final FSkinProp icon, final String initialInput, final String[] inputOptions) {
|
||||
public String showInputDialog(final String message, final String title, final FSkinProp icon, final String initialInput, final List<String> inputOptions) {
|
||||
return FOptionPane.showInputDialog(message, title, icon == null ? null : FSkin.getImage(icon), initialInput, inputOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public enum FControl implements KeyEventDispatcher {
|
||||
public void windowClosing(final WindowEvent e) {
|
||||
switch (closeAction) {
|
||||
case NONE: //prompt user for close action if not previously specified
|
||||
final String[] options = {"Close Screen", "Exit Forge", "Cancel"};
|
||||
final List<String> options = ImmutableList.of("Close Screen", "Exit Forge", "Cancel");
|
||||
final int reply = FOptionPane.showOptionDialog(
|
||||
"Forge now supports navigation tabs which allow closing and switching between different screens with ease. "
|
||||
+ "As a result, you no longer need to use the X button in the upper right to close the current screen and go back."
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
package forge.deckchooser;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.UiCommand;
|
||||
import forge.deck.ColorDeckGenerator;
|
||||
@@ -24,16 +38,6 @@ import forge.quest.QuestUtil;
|
||||
import forge.screens.match.controllers.CDetailPicture;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FOptionPane;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
@@ -58,9 +62,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
final FDeckChooser chooser = new FDeckChooser(cDetailPicture, forAi);
|
||||
chooser.initialize(defaultDeckType);
|
||||
chooser.populate();
|
||||
Dimension parentSize = JOptionPane.getRootFrame().getSize();
|
||||
final Dimension parentSize = JOptionPane.getRootFrame().getSize();
|
||||
chooser.setMinimumSize(new Dimension((int)(parentSize.getWidth() / 2), (int)parentSize.getHeight() - 200));
|
||||
final FOptionPane optionPane = new FOptionPane(null, title, null, chooser, new String[] { "OK", "Cancel" }, 0);
|
||||
final FOptionPane optionPane = new FOptionPane(null, title, null, chooser, ImmutableList.of("OK", "Cancel"), 0);
|
||||
optionPane.setDefaultFocus(chooser);
|
||||
chooser.lstDecks.setItemActivateCommand(new UiCommand() {
|
||||
@Override
|
||||
@@ -69,7 +73,7 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
}
|
||||
});
|
||||
optionPane.setVisible(true);
|
||||
int dialogResult = optionPane.getResult();
|
||||
final int dialogResult = optionPane.getResult();
|
||||
optionPane.dispose();
|
||||
if (dialogResult == 0) {
|
||||
return chooser.getDeck();
|
||||
@@ -81,9 +85,8 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
lstDecks = new DeckManager(GameType.Constructed, cDetailPicture);
|
||||
setOpaque(false);
|
||||
isAi = forAi;
|
||||
UiCommand cmdViewDeck = new UiCommand() {
|
||||
@Override
|
||||
public void run() {
|
||||
final UiCommand cmdViewDeck = new UiCommand() {
|
||||
@Override public void run() {
|
||||
if (selectedDeckType != DeckType.COLOR_DECK && selectedDeckType != DeckType.THEME_DECK) {
|
||||
FDeckViewer.show(getDeck());
|
||||
}
|
||||
@@ -96,16 +99,16 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
public void initialize() {
|
||||
initialize(DeckType.COLOR_DECK);
|
||||
}
|
||||
public void initialize(DeckType defaultDeckType) {
|
||||
public void initialize(final DeckType defaultDeckType) {
|
||||
initialize(null, defaultDeckType);
|
||||
}
|
||||
public void initialize(FPref savedStateSetting, DeckType defaultDeckType) {
|
||||
public void initialize(final FPref savedStateSetting, final DeckType defaultDeckType) {
|
||||
stateSetting = savedStateSetting;
|
||||
selectedDeckType = defaultDeckType;
|
||||
}
|
||||
|
||||
public DeckType getSelectedDeckType() { return selectedDeckType; }
|
||||
public void setSelectedDeckType(DeckType selectedDeckType0) {
|
||||
public void setSelectedDeckType(final DeckType selectedDeckType0) {
|
||||
refreshDecksList(selectedDeckType0, false, null);
|
||||
}
|
||||
|
||||
@@ -247,8 +250,8 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
|
||||
// Special branch for quest events
|
||||
if (selectedDeckType == DeckType.QUEST_OPPONENT_DECK) {
|
||||
QuestEvent event = DeckgenUtil.getQuestEvent(lstDecks.getSelectedItem().getName());
|
||||
RegisteredPlayer result = new RegisteredPlayer(event.getEventDeck());
|
||||
final QuestEvent event = DeckgenUtil.getQuestEvent(lstDecks.getSelectedItem().getName());
|
||||
final RegisteredPlayer result = new RegisteredPlayer(event.getEventDeck());
|
||||
if (event instanceof QuestEventChallenge) {
|
||||
result.setStartingLife(((QuestEventChallenge) event).getAiLife());
|
||||
}
|
||||
@@ -283,7 +286,7 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
return isAi;
|
||||
}
|
||||
|
||||
public void setIsAi(boolean isAiDeck) {
|
||||
public void setIsAi(final boolean isAiDeck) {
|
||||
isAi = isAiDeck;
|
||||
}
|
||||
|
||||
@@ -317,7 +320,7 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
refreshDecksList(ev.getDeckType(), false, ev);
|
||||
}
|
||||
|
||||
private void refreshDecksList(DeckType deckType, boolean forceRefresh, DecksComboBoxEvent ev) {
|
||||
private void refreshDecksList(final DeckType deckType, final boolean forceRefresh, final DecksComboBoxEvent ev) {
|
||||
if (decksComboBox == null) { return; } // Not yet populated
|
||||
if (selectedDeckType == deckType && !forceRefresh) { return; }
|
||||
selectedDeckType = deckType;
|
||||
@@ -330,29 +333,29 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
lstDecks.setCaption(deckType.toString());
|
||||
|
||||
switch (deckType) {
|
||||
case CUSTOM_DECK:
|
||||
updateCustom();
|
||||
break;
|
||||
case COLOR_DECK:
|
||||
updateColors();
|
||||
break;
|
||||
case THEME_DECK:
|
||||
updateThemes();
|
||||
break;
|
||||
case QUEST_OPPONENT_DECK:
|
||||
updateQuestEvents();
|
||||
break;
|
||||
case PRECONSTRUCTED_DECK:
|
||||
updatePrecons();
|
||||
break;
|
||||
case RANDOM_DECK:
|
||||
updateRandom();
|
||||
break;
|
||||
case NET_DECK:
|
||||
updateNetDecks();
|
||||
break;
|
||||
default:
|
||||
break; //other deck types not currently supported here
|
||||
case CUSTOM_DECK:
|
||||
updateCustom();
|
||||
break;
|
||||
case COLOR_DECK:
|
||||
updateColors();
|
||||
break;
|
||||
case THEME_DECK:
|
||||
updateThemes();
|
||||
break;
|
||||
case QUEST_OPPONENT_DECK:
|
||||
updateQuestEvents();
|
||||
break;
|
||||
case PRECONSTRUCTED_DECK:
|
||||
updatePrecons();
|
||||
break;
|
||||
case RANDOM_DECK:
|
||||
updateRandom();
|
||||
break;
|
||||
case NET_DECK:
|
||||
updateNetDecks();
|
||||
break;
|
||||
default:
|
||||
break; //other deck types not currently supported here
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +370,7 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
}
|
||||
|
||||
private String getState() {
|
||||
StringBuilder state = new StringBuilder();
|
||||
final StringBuilder state = new StringBuilder();
|
||||
if (decksComboBox.getDeckType() == null || decksComboBox.getDeckType() == DeckType.NET_DECK) {
|
||||
//handle special case of net decks
|
||||
if (netDeckCategory == null) { return ""; }
|
||||
@@ -381,15 +384,14 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
return state.toString();
|
||||
}
|
||||
|
||||
private void joinSelectedDecks(StringBuilder state, String delimiter) {
|
||||
Iterable<DeckProxy> selectedDecks = lstDecks.getSelectedItems();
|
||||
private void joinSelectedDecks(final StringBuilder state, final String delimiter) {
|
||||
final Iterable<DeckProxy> selectedDecks = lstDecks.getSelectedItems();
|
||||
boolean isFirst = true;
|
||||
if (selectedDecks != null) {
|
||||
for (DeckProxy deck : selectedDecks) {
|
||||
for (final DeckProxy deck : selectedDecks) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
state.append(delimiter);
|
||||
}
|
||||
state.append(deck.toString());
|
||||
@@ -398,14 +400,14 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
}
|
||||
|
||||
public void restoreSavedState() {
|
||||
DeckType oldDeckType = selectedDeckType;
|
||||
final DeckType oldDeckType = selectedDeckType;
|
||||
if (stateSetting == null) {
|
||||
//if can't restore saved state, just refresh deck list
|
||||
refreshDecksList(oldDeckType, true, null);
|
||||
return;
|
||||
}
|
||||
|
||||
String savedState = prefs.getPref(stateSetting);
|
||||
final String savedState = prefs.getPref(stateSetting);
|
||||
refreshDecksList(getDeckTypeFromSavedState(savedState), true, null);
|
||||
if (!lstDecks.setSelectedStrings(getSelectedDecksFromSavedState(savedState))) {
|
||||
//if can't select old decks, just refresh deck list
|
||||
@@ -413,36 +415,32 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
}
|
||||
}
|
||||
|
||||
private DeckType getDeckTypeFromSavedState(String savedState) {
|
||||
private DeckType getDeckTypeFromSavedState(final String savedState) {
|
||||
try {
|
||||
if (StringUtils.isBlank(savedState)) {
|
||||
return selectedDeckType;
|
||||
}
|
||||
else {
|
||||
String deckType = savedState.split(";")[0];
|
||||
} else {
|
||||
final String deckType = savedState.split(";")[0];
|
||||
if (deckType.startsWith(NetDeckCategory.PREFIX)) {
|
||||
netDeckCategory = NetDeckCategory.selectAndLoad(lstDecks.getGameType(), deckType.substring(NetDeckCategory.PREFIX.length()));
|
||||
return DeckType.NET_DECK;
|
||||
}
|
||||
return DeckType.valueOf(deckType);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
System.err.println(ex.getMessage() + ". Using default : " + selectedDeckType);
|
||||
return selectedDeckType;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getSelectedDecksFromSavedState(String savedState) {
|
||||
private List<String> getSelectedDecksFromSavedState(final String savedState) {
|
||||
try {
|
||||
if (StringUtils.isBlank(savedState)) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Arrays.asList(savedState.split(";")[1].split(SELECTED_DECK_DELIMITER));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
System.err.println(ex + " [savedState=" + savedState + "]");
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package forge.gui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.game.card.CardView;
|
||||
import forge.screens.match.CMatchUI;
|
||||
@@ -16,9 +19,9 @@ import forge.toolbox.FOptionPane;
|
||||
*
|
||||
*/
|
||||
public class GuiDialog {
|
||||
private static final String[] defaultConfirmOptions = { "Yes", "No" };
|
||||
private static final ImmutableList<String> defaultConfirmOptions = ImmutableList.of("Yes", "No");
|
||||
|
||||
public static boolean confirm(final CardView c, final String question, final boolean defaultIsYes, final String[] options, final CMatchUI matchUI) {
|
||||
public static boolean confirm(final CardView c, final String question, final boolean defaultIsYes, final List<String> options, final CMatchUI matchUI) {
|
||||
final Callable<Boolean> confirmTask = new Callable<Boolean>() {
|
||||
@Override public final Boolean call() {
|
||||
if (matchUI != null && c != null) {
|
||||
@@ -27,7 +30,7 @@ public class GuiDialog {
|
||||
|
||||
final String title = c == null ? "Question" : c + " - Ability";
|
||||
final String questionToUse = StringUtils.isBlank(question) ? "Activate card's ability?" : question;
|
||||
final String[] opts = options == null ? defaultConfirmOptions : options;
|
||||
final List<String> opts = options == null ? defaultConfirmOptions : options;
|
||||
final int answer = FOptionPane.showOptionDialog(questionToUse, title, FOptionPane.QUESTION_ICON, opts, defaultIsYes ? 0 : 1);
|
||||
return Boolean.valueOf(answer == 0);
|
||||
}};
|
||||
|
||||
@@ -55,6 +55,8 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.UiCommand;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.error.BugReporter;
|
||||
@@ -91,6 +93,8 @@ public class ImportDialog {
|
||||
// volatile since it is checked from multiple threads
|
||||
private volatile boolean _cancel;
|
||||
|
||||
private static final ImmutableList<String> fixOrContinue = ImmutableList.of("Whoops, let me fix that!", "Continue with the import, I know what I'm doing.");
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public ImportDialog(final String forcedSrcDir, final Runnable onDialogClose) {
|
||||
this.forcedSrcDir = forcedSrcDir;
|
||||
@@ -636,8 +640,7 @@ public class ImportDialog {
|
||||
sb.append("will come up again the next time you start Forge in order to migrate the remaining files<br>");
|
||||
sb.append("unless you move or delete them manually.</html>");
|
||||
|
||||
final String[] options = { "Whoops, let me fix that!", "Continue with the import, I know what I'm doing." };
|
||||
final int chosen = FOptionPane.showOptionDialog(sb.toString(), "Migration warning", FOptionPane.WARNING_ICON, options);
|
||||
final int chosen = FOptionPane.showOptionDialog(sb.toString(), "Migration warning", FOptionPane.WARNING_ICON, fixOrContinue);
|
||||
|
||||
if (chosen != 1) {
|
||||
// i.e. option 0 was chosen or the dialog was otherwise closed
|
||||
|
||||
@@ -37,6 +37,7 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.FThreads;
|
||||
@@ -88,12 +89,11 @@ public class ListChooser<T> {
|
||||
this.list = list.getClass().isInstance(List.class) ? (List<T>)list : Lists.newArrayList(list);
|
||||
this.lstChoices = new FList<T>(new ChooserListModel());
|
||||
|
||||
String[] options;
|
||||
final ImmutableList<String> options;
|
||||
if (minChoices == 0) {
|
||||
options = new String[] {"OK","Cancel"};
|
||||
}
|
||||
else {
|
||||
options = new String[] {"OK"};
|
||||
options = ImmutableList.of("OK","Cancel");
|
||||
} else {
|
||||
options = ImmutableList.of("OK");
|
||||
}
|
||||
|
||||
if (maxChoices == 1 || minChoices == -1) {
|
||||
|
||||
@@ -12,6 +12,8 @@ import forge.toolbox.FOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Handles editor preferences saving and loading.
|
||||
*
|
||||
@@ -69,6 +71,7 @@ public class SEditorIO {
|
||||
return true;
|
||||
}
|
||||
|
||||
private final static ImmutableList<String> confirmSaveOptions = ImmutableList.of("Save", "Don't Save", "Cancel");
|
||||
/**
|
||||
* Prompts to save changes if necessary.
|
||||
*
|
||||
@@ -82,7 +85,7 @@ public class SEditorIO {
|
||||
}
|
||||
|
||||
final int choice = FOptionPane.showOptionDialog("Save changes to current deck?", "Save Changes?",
|
||||
FOptionPane.QUESTION_ICON, new String[] {"Save", "Don't Save", "Cancel"});
|
||||
FOptionPane.QUESTION_ICON, confirmSaveOptions);
|
||||
|
||||
if (choice == -1 || choice == 2) { return false; }
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ package forge.screens.deckeditor.controllers;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.Deck;
|
||||
@@ -71,6 +73,8 @@ public class CEditorQuestDraftingProcess extends ACEditorBase<PaperCard, DeckGro
|
||||
private DragCell deckGenParent = null;
|
||||
private boolean saved = false;
|
||||
|
||||
private static final ImmutableList<String> leaveOrCancel = ImmutableList.of("Leave", "Cancel");
|
||||
|
||||
//========== Constructor
|
||||
|
||||
/**
|
||||
@@ -290,7 +294,7 @@ public class CEditorQuestDraftingProcess extends ACEditorBase<PaperCard, DeckGro
|
||||
String userPrompt =
|
||||
"This will end the current draft and you will not be able to join this tournament again.\nYour credits will be refunded and the draft will be removed.\n\n" +
|
||||
"Leave anyway?";
|
||||
boolean leave = FOptionPane.showOptionDialog(userPrompt, "Leave Draft?", FSkin.getImage(FSkinProp.ICO_WARNING).scale(2.0), new String[] {"Leave", "Cancel"}, 1) == 0;
|
||||
boolean leave = FOptionPane.showOptionDialog(userPrompt, "Leave Draft?", FSkin.getImage(FSkinProp.ICO_WARNING).scale(2.0), leaveOrCancel, 1) == 0;
|
||||
if (leave) {
|
||||
QuestEventDraft draft = quest.getAchievements().getCurrentDraft();
|
||||
quest.getAssets().addCredits(draft.getEntryFee());
|
||||
|
||||
@@ -707,12 +707,13 @@ public class VLobby implements IUpdateable {
|
||||
return usedAvatars;
|
||||
}
|
||||
|
||||
|
||||
private static final ImmutableList<String> genderOptions = ImmutableList.of("Male", "Female", "Any"),
|
||||
typeOptions = ImmutableList.of("Fantasy", "Generic", "Any");
|
||||
final String getNewName() {
|
||||
final String title = "Get new random name";
|
||||
final String message = "What type of name do you want to generate?";
|
||||
final SkinImage icon = FOptionPane.QUESTION_ICON;
|
||||
final String[] genderOptions = new String[]{ "Male", "Female", "Any" };
|
||||
final String[] typeOptions = new String[]{ "Fantasy", "Generic", "Any" };
|
||||
|
||||
final int genderIndex = FOptionPane.showOptionDialog(message, title, icon, genderOptions, 2);
|
||||
if (genderIndex < 0) {
|
||||
@@ -723,8 +724,8 @@ public class VLobby implements IUpdateable {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String gender = genderOptions[genderIndex];
|
||||
final String type = typeOptions[typeIndex];
|
||||
final String gender = genderOptions.get(genderIndex);
|
||||
final String type = typeOptions.get(typeIndex);
|
||||
|
||||
String confirmMsg, newName;
|
||||
final List<String> usedNames = getPlayerNames();
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.List;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.Singletons;
|
||||
import forge.UiCommand;
|
||||
@@ -139,7 +141,7 @@ public enum CSubmenuQuestDraft implements ICDoc {
|
||||
|
||||
final boolean shouldQuit = FOptionPane.showOptionDialog("If you leave now, this tournament will be forever gone."
|
||||
+ "\nYou will keep the cards you drafted, but will receive no other prizes."
|
||||
+ "\n\nWould you still like to quit the tournament?", "Really Quit?", FSkin.getImage(FSkinProp.ICO_WARNING).scale(2.0), new String[] { "Yes", "No" }, 1) == 0;
|
||||
+ "\n\nWould you still like to quit the tournament?", "Really Quit?", FSkin.getImage(FSkinProp.ICO_WARNING).scale(2.0), ImmutableList.of("Yes", "No"), 1) == 0;
|
||||
if (!shouldQuit) {
|
||||
return;
|
||||
}
|
||||
@@ -149,7 +151,7 @@ public enum CSubmenuQuestDraft implements ICDoc {
|
||||
if (draft.playerHasMatchesLeft()) {
|
||||
final boolean shouldQuit = FOptionPane.showOptionDialog("You have matches left to play!\nLeaving the tournament early will forfeit your potential future winnings."
|
||||
+ "\nYou will still receive winnings as if you conceded your next match and you will keep the cards you drafted."
|
||||
+ "\n\nWould you still like to quit the tournament?", "Really Quit?", FSkin.getImage(FSkinProp.ICO_WARNING).scale(2.0), new String[] { "Yes", "No" }, 1) == 0;
|
||||
+ "\n\nWould you still like to quit the tournament?", "Really Quit?", FSkin.getImage(FSkinProp.ICO_WARNING).scale(2.0), ImmutableList.of("Yes", "No"), 1) == 0;
|
||||
if (!shouldQuit) {
|
||||
return;
|
||||
}
|
||||
@@ -242,7 +244,7 @@ public enum CSubmenuQuestDraft implements ICDoc {
|
||||
|
||||
}
|
||||
|
||||
final boolean saveDraft = FOptionPane.showOptionDialog("Would you like to save this draft to the regular draft mode?", "Save Draft?", FSkin.getImage(FSkinProp.ICO_QUESTION).scale(2.0), new String[] { "Yes", "No" }, 0) == 0;
|
||||
final boolean saveDraft = FOptionPane.showOptionDialog("Would you like to save this draft to the regular draft mode?", "Save Draft?", FSkin.getImage(FSkinProp.ICO_QUESTION).scale(2.0), ImmutableList.of("Yes", "No"), 0) == 0;
|
||||
|
||||
if (saveDraft) {
|
||||
draft.saveToRegularDraft();
|
||||
@@ -525,7 +527,7 @@ public enum CSubmenuQuestDraft implements ICDoc {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean okayToEnter = FOptionPane.showOptionDialog("This tournament costs " + draftEvent.getEntryFee() + " credits to enter.\nAre you sure you wish to enter?", "Enter Draft Tournament?", FSkin.getImage(FSkinProp.ICO_QUEST_GOLD), new String[] { "Yes", "No" }, 1) == 0;
|
||||
final boolean okayToEnter = FOptionPane.showOptionDialog("This tournament costs " + draftEvent.getEntryFee() + " credits to enter.\nAre you sure you wish to enter?", "Enter Draft Tournament?", FSkin.getImage(FSkinProp.ICO_QUEST_GOLD), ImmutableList.of("Yes", "No"), 1) == 0;
|
||||
|
||||
if (!okayToEnter) {
|
||||
return;
|
||||
|
||||
@@ -326,8 +326,11 @@ public final class CMatchUI
|
||||
}
|
||||
|
||||
public void setCard(final CardView c, final boolean isInAltState) {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
cDetailPicture.showCard(c, isInAltState);
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
||||
@Override public void run() {
|
||||
cDetailPicture.showCard(c, isInAltState);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setCard(final InventoryItem item) {
|
||||
@@ -819,17 +822,17 @@ public final class CMatchUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showOptionDialog(final String message, final String title, final FSkinProp icon, final String[] options, final int defaultOption) {
|
||||
public int showOptionDialog(final String message, final String title, final FSkinProp icon, final List<String> options, final int defaultOption) {
|
||||
return FOptionPane.showOptionDialog(message, title, icon == null ? null : FSkin.getImage(icon), options, defaultOption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String showInputDialog(final String message, final String title, final FSkinProp icon, final String initialInput, final String[] inputOptions) {
|
||||
public String showInputDialog(final String message, final String title, final FSkinProp icon, final String initialInput, final List<String> inputOptions) {
|
||||
return FOptionPane.showInputDialog(message, title, icon == null ? null : FSkin.getImage(icon), initialInput, inputOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> getChoices(final String message, final int min, final int max, final Collection<T> choices, final T selected, final Function<T, String> display) {
|
||||
public <T> List<T> getChoices(final String message, final int min, final int max, final List<T> choices, final T selected, final Function<T, String> display) {
|
||||
/*if ((choices != null && !choices.isEmpty() && choices.iterator().next() instanceof GameObject) || selected instanceof GameObject) {
|
||||
System.err.println("Warning: GameObject passed to GUI! Printing stack trace.");
|
||||
Thread.dumpStack();
|
||||
@@ -854,7 +857,7 @@ public final class CMatchUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameEntityView chooseSingleEntityForEffect(final String title, final Collection<? extends GameEntityView> optionList, final DelayedReveal delayedReveal, final boolean isOptional) {
|
||||
public GameEntityView chooseSingleEntityForEffect(final String title, final List<? extends GameEntityView> optionList, final DelayedReveal delayedReveal, final boolean isOptional) {
|
||||
if (delayedReveal != null) {
|
||||
reveal(delayedReveal.getMessagePrefix(), delayedReveal.getCards()); //TODO: Merge this into search dialog
|
||||
}
|
||||
@@ -984,13 +987,13 @@ public final class CMatchUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean confirm(final CardView c, final String question, final boolean defaultIsYes, final String[] options) {
|
||||
public boolean confirm(final CardView c, final String question, final boolean defaultIsYes, final List<String> options) {
|
||||
return GuiDialog.confirm(c, question, defaultIsYes, options, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConfirmDialog(final String message, final String title, final String yesButtonText, final String noButtonText, final boolean defaultYes) {
|
||||
final String[] options = {yesButtonText, noButtonText};
|
||||
final List<String> options = ImmutableList.of(yesButtonText, noButtonText);
|
||||
final int reply = SOptionPane.showOptionDialog(message, title, SOptionPane.QUESTION_ICON, options, defaultYes ? 0 : 1);
|
||||
return reply == 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package forge.screens.match;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.game.GameView;
|
||||
import forge.match.NextGameDecision;
|
||||
@@ -104,7 +106,7 @@ public class QuestDraftWinLose extends ControlWinLose {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
if (warningString == null ||
|
||||
FOptionPane.showOptionDialog(warningString, warningCaption, FSkin.getImage(FSkinProp.ICO_WARNING).scale(2), new String[] { "Yes", "No" }, 1) == 0) {
|
||||
FOptionPane.showOptionDialog(warningString, warningCaption, FSkin.getImage(FSkinProp.ICO_WARNING).scale(2), ImmutableList.of("Yes", "No"), 1) == 0) {
|
||||
matchUI.getGameController().nextGameDecision(NextGameDecision.QUIT);
|
||||
QuestDraftUtils.matchInProgress = false;
|
||||
QuestDraftUtils.continueMatches(matchUI);
|
||||
|
||||
@@ -11,6 +11,8 @@ import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardRules;
|
||||
@@ -117,6 +119,7 @@ public enum CCardScript implements ICDoc {
|
||||
return (currentScriptInfo != null && isTextDirty);
|
||||
}
|
||||
|
||||
private static final ImmutableList<String> switchAwayOptions = ImmutableList.of("Save", "Don't Save", "Cancel");
|
||||
public boolean canSwitchAway(final boolean isCardChanging) {
|
||||
if (switchInProgress) { return false; }
|
||||
if (!hasChanges()) { return true; }
|
||||
@@ -124,10 +127,10 @@ public enum CCardScript implements ICDoc {
|
||||
switchInProgress = true;
|
||||
Singletons.getControl().ensureScreenActive(FScreen.WORKSHOP_SCREEN); //ensure Workshop is active before showing dialog
|
||||
final int choice = FOptionPane.showOptionDialog(
|
||||
"Save changes to " + currentCard + "?",
|
||||
String.format("Save changes to %s?", currentCard),
|
||||
"Save Changes?",
|
||||
FOptionPane.QUESTION_ICON,
|
||||
new String[] {"Save", "Don't Save", "Cancel"});
|
||||
switchAwayOptions);
|
||||
switchInProgress = false;
|
||||
|
||||
if (choice == -1 || choice == 2) { return false; }
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.LayoutManager;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.ComboBoxModel;
|
||||
@@ -51,6 +52,9 @@ public class FComboBox<E> extends SkinnedComboBox<E> implements IComboBox<E> {
|
||||
super(items);
|
||||
initialize();
|
||||
}
|
||||
public FComboBox(final List<E> items) {
|
||||
this(new Vector<>(items));
|
||||
}
|
||||
public FComboBox(final Vector<E> items) {
|
||||
super(items);
|
||||
initialize();
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -14,6 +15,8 @@ import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.text.StyleConstants;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.toolbox.FSkin.SkinImage;
|
||||
import forge.view.FDialog;
|
||||
@@ -46,7 +49,7 @@ public class FOptionPane extends FDialog {
|
||||
}
|
||||
|
||||
public static void showMessageDialog(final String message, final String title, final SkinImage icon) {
|
||||
showOptionDialog(message, title, icon, new String[] {"OK"}, 0);
|
||||
showOptionDialog(message, title, icon, ImmutableList.of("OK"), 0);
|
||||
}
|
||||
|
||||
public static boolean showConfirmDialog(final String message) {
|
||||
@@ -66,16 +69,16 @@ public class FOptionPane extends FDialog {
|
||||
}
|
||||
|
||||
public static boolean showConfirmDialog(final String message, final String title, final String yesButtonText, final String noButtonText, final boolean defaultYes) {
|
||||
final String[] options = {yesButtonText, noButtonText};
|
||||
final List<String> options = ImmutableList.of(yesButtonText, noButtonText);
|
||||
final int reply = FOptionPane.showOptionDialog(message, title, QUESTION_ICON, options, defaultYes ? 0 : 1);
|
||||
return (reply == 0);
|
||||
}
|
||||
|
||||
public static int showOptionDialog(final String message, final String title, final SkinImage icon, final String[] options) {
|
||||
public static int showOptionDialog(final String message, final String title, final SkinImage icon, final List<String> options) {
|
||||
return showOptionDialog(message, title, icon, options, 0);
|
||||
}
|
||||
|
||||
public static int showOptionDialog(final String message, final String title, final SkinImage icon, final String[] options, final int defaultOption) {
|
||||
public static int showOptionDialog(final String message, final String title, final SkinImage icon, final List<String> options, final int defaultOption) {
|
||||
final FOptionPane optionPane = new FOptionPane(message, title, icon, null, options, defaultOption);
|
||||
optionPane.setVisible(true);
|
||||
final int dialogResult = optionPane.result;
|
||||
@@ -96,21 +99,20 @@ public class FOptionPane extends FDialog {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T showInputDialog(final String message, final String title, final SkinImage icon, final T initialInput, final T[] inputOptions) {
|
||||
public static <T> T showInputDialog(final String message, final String title, final SkinImage icon, final String initialInput, final List<T> inputOptions) {
|
||||
final JComponent inputField;
|
||||
FTextField txtInput = null;
|
||||
FComboBox<T> cbInput = null;
|
||||
if (inputOptions == null) {
|
||||
txtInput = new FTextField.Builder().text(initialInput.toString()).build();
|
||||
inputField = txtInput;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cbInput = new FComboBox<T>(inputOptions);
|
||||
cbInput.setSelectedItem(initialInput);
|
||||
inputField = cbInput;
|
||||
}
|
||||
|
||||
final FOptionPane optionPane = new FOptionPane(message, title, icon, inputField, new String[] {"OK", "Cancel"}, -1);
|
||||
final FOptionPane optionPane = new FOptionPane(message, title, icon, inputField, ImmutableList.of("OK", "Cancel"), -1);
|
||||
optionPane.setDefaultFocus(inputField);
|
||||
inputField.addKeyListener(new KeyAdapter() { //hook so pressing Enter on field accepts dialog
|
||||
@Override
|
||||
@@ -136,7 +138,7 @@ public class FOptionPane extends FDialog {
|
||||
private int result = -1; //default result to -1, indicating dialog closed without choosing option
|
||||
private final FButton[] buttons;
|
||||
|
||||
public FOptionPane(final String message, final String title, final SkinImage icon, final Component comp, final String[] options, final int defaultOption) {
|
||||
public FOptionPane(final String message, final String title, final SkinImage icon, final Component comp, final List<String> options, final int defaultOption) {
|
||||
this.setTitle(title);
|
||||
|
||||
final int padding = 10;
|
||||
@@ -184,18 +186,19 @@ public class FOptionPane extends FDialog {
|
||||
}
|
||||
|
||||
//determine size of buttons
|
||||
final int optionCount = options.length;
|
||||
final int optionCount = options.size();
|
||||
final FButton btnMeasure = new FButton(); //use blank button to aid in measurement
|
||||
final FontMetrics metrics = JOptionPane.getRootFrame().getGraphics().getFontMetrics(btnMeasure.getFont());
|
||||
|
||||
int maxTextWidth = 0;
|
||||
buttons = new FButton[optionCount];
|
||||
for (int i = 0; i < optionCount; i++) {
|
||||
final int textWidth = metrics.stringWidth(options[i]);
|
||||
final String option = options.get(i);
|
||||
final int textWidth = metrics.stringWidth(option);
|
||||
if (textWidth > maxTextWidth) {
|
||||
maxTextWidth = textWidth;
|
||||
}
|
||||
buttons[i] = new FButton(options[i]);
|
||||
buttons[i] = new FButton(option);
|
||||
}
|
||||
|
||||
this.pack(); //resize dialog to fit component and title to help determine button layout
|
||||
|
||||
@@ -238,7 +238,7 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reveal(Collection<CardView> cards, ZoneType zone, PlayerView owner, String messagePrefix) {
|
||||
public void reveal(List<CardView> cards, ZoneType zone, PlayerView owner, String messagePrefix) {
|
||||
//nothing needs to be done here
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CounterType chooseCounterType(Collection<CounterType> options, SpellAbility sa, String prompt) {
|
||||
public CounterType chooseCounterType(List<CounterType> options, SpellAbility sa, String prompt) {
|
||||
return Iterables.getFirst(options, CounterType.P1P1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user