Fix deck editor Set/Format edit problems.

Add code to respect the "allow reprints" option on the Formats dialog.  Default it to 'true'.  Also add code to be able to initialize the sate of  that same checkbox.

Change format and set edits to refresh the item manager list so edits are realized.

Change wording of set "allow reprints" checkbox to remove confusion / conflict with the format "allow reprints" checkbox.

Add constructor so a whole format list can simply be added at once rather than iterating and creating multiple filter objects for each format.  (Net result is the same in either case.)

Change text of filter drop down to indicate things are being added or edited vs just added.
This commit is contained in:
Tim Scott
2019-02-24 11:52:05 -06:00
parent f5f164af93
commit b090cdfa41
6 changed files with 45 additions and 12 deletions

View File

@@ -95,18 +95,17 @@ public class CardManager extends ItemManager<PaperCard> {
GuiUtils.addMenuItem(menu, "Formats...", null, new Runnable() {
@Override public void run() {
final CardSetFilter existingFilter = itemManager.getFilter(CardSetFilter.class);
final CardFormatFilter existingFilter = itemManager.getFilter(CardFormatFilter.class);
if (existingFilter != null) {
existingFilter.edit();
existingFilter.edit(itemManager);
} else {
final DialogChooseFormats dialog = new DialogChooseFormats();
dialog.setWantReprintsCB(true); // assume user wants things permissive...
dialog.setOkCallback(new Runnable() {
@Override public void run() {
final List<GameFormat> formats = dialog.getSelectedFormats();
if (!formats.isEmpty()) {
for(GameFormat format: formats) {
itemManager.addFilter(new CardFormatFilter(itemManager, format));
}
itemManager.addFilter(new CardFormatFilter(itemManager,formats,dialog.getWantReprints()));
}
}
});
@@ -119,7 +118,7 @@ public class CardManager extends ItemManager<PaperCard> {
public void run() {
CardSetFilter existingFilter = itemManager.getFilter(CardSetFilter.class);
if (existingFilter != null) {
existingFilter.edit();
existingFilter.edit(itemManager);
}
else {
final DialogChooseSets dialog = new DialogChooseSets(null, null, true);

View File

@@ -250,7 +250,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel implem
if (hideFilters) {
GuiUtils.addMenuItem(menu, "Show Filters", null, cmdHideFilters);
} else {
final JMenu addMenu = GuiUtils.createMenu("Add Filter");
final JMenu addMenu = GuiUtils.createMenu("Add/Edit Filter");
GuiUtils.addMenuItem(addMenu, "Current text search",
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
cmdAddCurrentSearch, !mainSearchFilter.isEmpty());

View File

@@ -1,21 +1,29 @@
package forge.itemmanager.filters;
import java.util.List;
import com.google.common.base.Predicate;
import forge.game.GameFormat;
import forge.item.PaperCard;
import forge.itemmanager.ItemManager;
import forge.itemmanager.SFilterUtil;
import forge.screens.home.quest.DialogChooseFormats;
public class CardFormatFilter extends FormatFilter<PaperCard> {
public CardFormatFilter(ItemManager<? super PaperCard> itemManager0) {
super(itemManager0);
}
public CardFormatFilter(ItemManager<? super PaperCard> itemManager0, GameFormat format0) {
super(itemManager0, format0);
}
public CardFormatFilter(ItemManager<? super PaperCard> itemManager0, List<GameFormat> formats0,boolean allowReprints0) {
super(itemManager0);
this.formats.addAll(formats0);
this.allowReprints = allowReprints0;
}
@Override
public ItemFilter<PaperCard> createCopy() {
CardFormatFilter copy = new CardFormatFilter(itemManager);
@@ -27,4 +35,20 @@ public class CardFormatFilter extends FormatFilter<PaperCard> {
protected final Predicate<PaperCard> buildPredicate() {
return SFilterUtil.buildFormatFilter(this.formats, this.allowReprints);
}
public void edit(final ItemManager<? super PaperCard> itemManager) {
final DialogChooseFormats dialog = new DialogChooseFormats(this.formats);
final CardFormatFilter itemFilter = this;
dialog.setWantReprintsCB(allowReprints);
dialog.setOkCallback(new Runnable() {
@Override
public void run() {
formats.clear();
formats.addAll(dialog.getSelectedFormats());
allowReprints = dialog.getWantReprints();
itemManager.addFilter(itemFilter); // this adds/updates the current filter...
}
});
}
}

View File

@@ -49,16 +49,18 @@ public class CardSetFilter extends CardFormatFilter {
return true;
}
public void edit() {
public void edit(final ItemManager<? super PaperCard> itemManager) {
final DialogChooseSets dialog = new DialogChooseSets(this.sets, null, true);
final CardSetFilter itemFilter = this;
dialog.setWantReprintsCB(allowReprints);
dialog.setOkCallback(new Runnable() {
@Override
public void run() {
sets.clear();
sets.addAll(dialog.getSelectedSets());
allowReprints = dialog.getWantReprints();
formats.clear();
formats.add(new GameFormat(null, sets, null));
itemManager.addFilter(itemFilter); // this adds/updates the current filter
}
});
}

View File

@@ -116,6 +116,10 @@ public class DialogChooseFormats {
return wantReprints;
}
public void setWantReprintsCB(boolean isSet) {
cbWantReprints.setSelected(isSet);
}
private JPanel makeCheckBoxList(List<FCheckBox> formats, String title, boolean focused) {
choices.addAll(formats);

View File

@@ -24,7 +24,7 @@ public class DialogChooseSets {
private Runnable okCallback;
private final List<FCheckBox> choices = new ArrayList<>();
private final FCheckBox cbWantReprints = new FCheckBox("Allow compatible reprints from other sets");
private final FCheckBox cbWantReprints = new FCheckBox("Display compatible reprints from more recent sets");
// lists are of set codes (e.g. "2ED")
public DialogChooseSets(Collection<String> preselectedSets, Collection<String> unselectableSets, boolean showWantReprintsCheckbox) {
@@ -129,6 +129,10 @@ public class DialogChooseSets {
public boolean getWantReprints() {
return wantReprints;
}
public void setWantReprintsCB(boolean isSet) {
cbWantReprints.setSelected(isSet);
}
private JPanel makeCheckBoxList(List<FCheckBox> sets, String title, boolean focused) {