don't enable world filter unless there is an active quest

This commit is contained in:
myk
2013-02-21 01:08:05 +00:00
parent 2af6395649
commit c0b12e6266

View File

@@ -200,12 +200,18 @@ public enum CCardCatalog implements ICDoc {
popup.add(range); popup.add(range);
JMenu world = new JMenu("Quest world"); JMenu world = new JMenu("Quest world");
for (final QuestWorld w : Singletons.getModel().getWorlds()) { for (final QuestWorld w : Singletons.getModel().getWorlds()) {
GameFormatQuest format = w.getFormat();
if (null == format) {
// assumes that no world other than the main world will have a null format
format = Singletons.getModel().getQuest().getMainFormat();
}
final GameFormatQuest f = format;
GuiUtils.addMenuItem(world, w.getName(), null, new Runnable() { GuiUtils.addMenuItem(world, w.getName(), null, new Runnable() {
@Override @Override
public void run() { public void run() {
addRestriction(buildWorldRestriction(w), activeWorlds, w); addRestriction(buildFormatRestriction(w.getName(), f, true), activeWorlds, w);
} }
}, !isActive(activeWorlds, w)); }, !isActive(activeWorlds, w) && null != f);
} }
popup.add(world); popup.add(world);
popup.show(VCardCatalog.SINGLETON_INSTANCE.getBtnAddRestriction(), 0, popup.show(VCardCatalog.SINGLETON_INSTANCE.getBtnAddRestriction(), 0,
@@ -366,12 +372,6 @@ public enum CCardCatalog implements ICDoc {
return activeSet.contains(key); return activeSet.contains(key);
} }
// private interface _RestrictionBuilder<T> {
// Predicate<CardPrinted> getPredicate();
// JComponent buildRestrictionWidget();
// boolean buildMenu(JPopupMenu root, Set<T> activeSet, T key);
// }
@SuppressWarnings("serial") @SuppressWarnings("serial")
private <T> void addRestriction(Pair<? extends JComponent, Predicate<CardPrinted>> restriction, final Set<T> activeSet, final T key) { private <T> void addRestriction(Pair<? extends JComponent, Predicate<CardPrinted>> restriction, final Set<T> activeSet, final T key) {
final Predicate<CardPrinted> predicate = restriction.getRight(); final Predicate<CardPrinted> predicate = restriction.getRight();
@@ -462,7 +462,7 @@ public enum CCardCatalog implements ICDoc {
int lineLen = 0; int lineLen = 0;
// use HTML tooltips so we can insert line breaks // use HTML tooltips so we can insert line breaks
List<String> sets = null == format ? null : format.getAllowedSetCodes(); List<String> sets = format.getAllowedSetCodes();
if (null == sets || sets.isEmpty()) { if (null == sets || sets.isEmpty()) {
tooltip.append(" All"); tooltip.append(" All");
} else { } else {
@@ -487,7 +487,7 @@ public enum CCardCatalog implements ICDoc {
} }
} }
List<String> bannedCards = null == format ? null : format.getBannedCardNames(); List<String> bannedCards = format.getBannedCardNames();
if (null != bannedCards && !bannedCards.isEmpty()) { if (null != bannedCards && !bannedCards.isEmpty()) {
tooltip.append("<br><br>Banned:"); tooltip.append("<br><br>Banned:");
lastLen += lineLen; lastLen += lineLen;
@@ -518,13 +518,4 @@ public enum CCardCatalog implements ICDoc {
private Pair<FLabel, Predicate<CardPrinted>> buildSetRestriction(String displayName, List<String> setCodes, boolean allowReprints) { private Pair<FLabel, Predicate<CardPrinted>> buildSetRestriction(String displayName, List<String> setCodes, boolean allowReprints) {
return buildFormatRestriction(displayName, new GameFormat(null, setCodes, null), allowReprints); return buildFormatRestriction(displayName, new GameFormat(null, setCodes, null), allowReprints);
} }
private Pair<FLabel, Predicate<CardPrinted>> buildWorldRestriction(QuestWorld world) {
GameFormatQuest format = world.getFormat();
if (null == format) {
// assumes that no world other than the main world will have a null format
format = Singletons.getModel().getQuest().getMainFormat();
}
return buildFormatRestriction(world.getName(), format, true);
}
} }