mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Modified format filter selection options to support large numbers of historic formats in the menu - uses a similar UI to the set selector
This commit is contained in:
@@ -319,6 +319,20 @@ public class GameFormat implements Comparable<GameFormat> {
|
||||
return coreList;
|
||||
}
|
||||
|
||||
public Map<String, List<GameFormat>> getHistoricMap() {
|
||||
Map<String, List<GameFormat>> coreList = new HashMap<>();
|
||||
for(GameFormat format: naturallyOrdered){
|
||||
if(format.getFormatType().equals(FormatType.Historic)){
|
||||
String alpha = format.getName().substring(0,1);
|
||||
if(!coreList.containsKey(alpha)){
|
||||
coreList.put(alpha,new ArrayList<>());
|
||||
}
|
||||
coreList.get(alpha).add(format);
|
||||
}
|
||||
}
|
||||
return coreList;
|
||||
}
|
||||
|
||||
public GameFormat getStandard() {
|
||||
return this.map.get("Standard");
|
||||
}
|
||||
|
||||
@@ -7,10 +7,13 @@ import forge.itemmanager.filters.*;
|
||||
import forge.model.FModel;
|
||||
import forge.quest.QuestWorld;
|
||||
import forge.quest.data.QuestPreferences;
|
||||
import forge.screens.home.quest.DialogChooseFormats;
|
||||
import forge.screens.home.quest.DialogChooseSets;
|
||||
import forge.screens.match.controllers.CDetailPicture;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
@@ -92,16 +95,26 @@ public class CardManager extends ItemManager<PaperCard> {
|
||||
}
|
||||
menu.add(fmt);
|
||||
|
||||
JMenu fmthist = GuiUtils.createMenu("Historic Format");
|
||||
for (final GameFormat f : FModel.getFormats().getHistoricList()) {
|
||||
GuiUtils.addMenuItem(fmthist, f.getName(), null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
itemManager.addFilter(new CardFormatFilter(itemManager, f));
|
||||
GuiUtils.addMenuItem(menu, "Formats...", null, new Runnable() {
|
||||
@Override public void run() {
|
||||
final CardSetFilter existingFilter = itemManager.getFilter(CardSetFilter.class);
|
||||
if (existingFilter != null) {
|
||||
existingFilter.edit();
|
||||
} else {
|
||||
final DialogChooseFormats dialog = new DialogChooseFormats();
|
||||
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));
|
||||
}
|
||||
}, FormatFilter.canAddFormat(f, itemManager.getFilter(CardFormatFilter.class)));
|
||||
}
|
||||
menu.add(fmthist);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GuiUtils.addMenuItem(menu, "Sets...", null, new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -4,18 +4,15 @@ import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import forge.screens.home.quest.DialogChooseFormats;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Singletons;
|
||||
@@ -186,16 +183,28 @@ public final class DeckManager extends ItemManager<DeckProxy> implements IHasGam
|
||||
}
|
||||
menu.add(fmt);
|
||||
|
||||
final JMenu fmtall = GuiUtils.createMenu("Historic Format");
|
||||
for (final GameFormat f : FModel.getFormats().getHistoricList()) {
|
||||
GuiUtils.addMenuItem(fmtall, f.getName(), null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addFilter(new DeckFormatFilter(DeckManager.this, f));
|
||||
|
||||
GuiUtils.addMenuItem(menu, "Formats...", null, new Runnable() {
|
||||
@Override public void run() {
|
||||
final DeckFormatFilter existingFilter = getFilter(DeckFormatFilter.class);
|
||||
if (existingFilter != null) {
|
||||
existingFilter.edit();
|
||||
} else {
|
||||
final DialogChooseFormats dialog = new DialogChooseFormats();
|
||||
dialog.setOkCallback(new Runnable() {
|
||||
@Override public void run() {
|
||||
final List<GameFormat> formats = dialog.getSelectedFormats();
|
||||
if (!formats.isEmpty()) {
|
||||
for(GameFormat format: formats) {
|
||||
addFilter(new DeckFormatFilter(DeckManager.this, format));
|
||||
}
|
||||
}, FormatFilter.canAddFormat(f, getFilter(DeckFormatFilter.class)));
|
||||
}
|
||||
menu.add(fmtall);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
GuiUtils.addMenuItem(menu, "Sets...", null, new Runnable() {
|
||||
@Override public void run() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import forge.game.GameFormat;
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.itemmanager.SFilterUtil;
|
||||
import forge.screens.home.quest.DialogChooseFormats;
|
||||
|
||||
|
||||
public class DeckFormatFilter extends FormatFilter<DeckProxy> {
|
||||
@@ -27,4 +28,16 @@ public class DeckFormatFilter extends FormatFilter<DeckProxy> {
|
||||
protected final Predicate<DeckProxy> buildPredicate() {
|
||||
return DeckProxy.createPredicate(SFilterUtil.buildFormatFilter(this.formats, this.allowReprints));
|
||||
}
|
||||
|
||||
public void edit() {
|
||||
final DialogChooseFormats dialog = new DialogChooseFormats(this.formats);
|
||||
dialog.setOkCallback(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
allowReprints = dialog.getWantReprints();
|
||||
formats.clear();
|
||||
formats.addAll(dialog.getSelectedFormats());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,9 @@ public abstract class FormatFilter<T extends InventoryItem> extends ListLabelFil
|
||||
}
|
||||
|
||||
CardEdition edition = editions.get(code);
|
||||
if(edition!=null) {
|
||||
tooltip.append(" ").append(edition.getName()).append(" (").append(code).append("),");
|
||||
}
|
||||
lineLen = tooltip.length() - lastLen;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package forge.screens.home.quest;
|
||||
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.card.CardEdition;
|
||||
import forge.game.GameFormat;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.*;
|
||||
import forge.util.TextUtil;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
|
||||
public class DialogChooseFormats {
|
||||
|
||||
private List<GameFormat> selectedFormats = new ArrayList<>() ;
|
||||
private boolean wantReprints = true;
|
||||
private Runnable okCallback;
|
||||
|
||||
private final List<FCheckBox> choices = new ArrayList<>();
|
||||
private final FCheckBox cbWantReprints = new FCheckBox("Allow compatible reprints from other sets");
|
||||
|
||||
public DialogChooseFormats(){
|
||||
this(null);
|
||||
}
|
||||
|
||||
public DialogChooseFormats(Set<GameFormat> preselectedFormats) {
|
||||
|
||||
List<FCheckBox> sanctioned = new ArrayList<>();
|
||||
List<FCheckBox> casual = new ArrayList<>();
|
||||
List<FCheckBox> historic = new ArrayList<>();
|
||||
|
||||
for (GameFormat format : FModel.getFormats().getOrderedList()){
|
||||
FCheckBox box = new FCheckBox(format.getName());
|
||||
box.setName(format.getName());
|
||||
switch (format.getFormatType()){
|
||||
case Sanctioned:
|
||||
sanctioned.add(box);
|
||||
break;
|
||||
case Historic:
|
||||
historic.add(box);
|
||||
break;
|
||||
case Custom:
|
||||
case Casual:
|
||||
default:
|
||||
casual.add(box);
|
||||
break;
|
||||
|
||||
}
|
||||
box.setSelected(null != preselectedFormats && preselectedFormats.contains(format));
|
||||
}
|
||||
|
||||
FPanel panel = new FPanel(new MigLayout("insets 0, gap 0, center, wrap 3"));
|
||||
panel.setOpaque(false);
|
||||
panel.setBackgroundTexture(FSkin.getIcon(FSkinProp.BG_TEXTURE));
|
||||
|
||||
panel.add(new FLabel.Builder().text("Choose formats").fontSize(18).build(), "center, span, wrap, gaptop 10");
|
||||
|
||||
String constraints = "aligny top";
|
||||
panel.add(makeCheckBoxList(sanctioned, "Sanctioned", true), constraints);
|
||||
panel.add(makeCheckBoxList(casual, "Casual", false), constraints);
|
||||
panel.add(makeCheckBoxList(historic, "Historic", false), constraints);
|
||||
|
||||
final JPanel overlay = FOverlay.SINGLETON_INSTANCE.getPanel();
|
||||
overlay.setLayout(new MigLayout("insets 0, gap 0, wrap, ax center, ay center"));
|
||||
|
||||
final Runnable cleanup = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SOverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
FButton btnOk = new FButton("OK");
|
||||
btnOk.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
cleanup.run();
|
||||
handleOk();
|
||||
}
|
||||
});
|
||||
|
||||
FButton btnCancel = new FButton("Cancel");
|
||||
btnCancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cleanup.run();
|
||||
}
|
||||
});
|
||||
|
||||
JPanel southPanel = new JPanel(new MigLayout("insets 10, gap 20, ax center"));
|
||||
southPanel.setOpaque(false);
|
||||
southPanel.add(cbWantReprints, "center, span, wrap");
|
||||
southPanel.add(btnOk, "center, w 40%, h 20!");
|
||||
southPanel.add(btnCancel, "center, w 40%, h 20!");
|
||||
|
||||
panel.add(southPanel, "dock south, gapBottom 10");
|
||||
|
||||
overlay.add(panel);
|
||||
panel.getRootPane().setDefaultButton(btnOk);
|
||||
SOverlayUtils.showOverlay();
|
||||
|
||||
}
|
||||
|
||||
public void setOkCallback(Runnable onOk) {
|
||||
okCallback = onOk;
|
||||
}
|
||||
|
||||
public List<GameFormat> getSelectedFormats() {
|
||||
return selectedFormats;
|
||||
}
|
||||
|
||||
public boolean getWantReprints() {
|
||||
return wantReprints;
|
||||
}
|
||||
|
||||
private JPanel makeCheckBoxList(List<FCheckBox> formats, String title, boolean focused) {
|
||||
|
||||
choices.addAll(formats);
|
||||
final FCheckBoxList<FCheckBox> cbl = new FCheckBoxList<>(false);
|
||||
cbl.setListData(formats.toArray(new FCheckBox[formats.size()]));
|
||||
cbl.setVisibleRowCount(Math.min(20, formats.size()));
|
||||
|
||||
if (focused) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cbl.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
JPanel pnl = new JPanel(new MigLayout("center, wrap"));
|
||||
pnl.setOpaque(false);
|
||||
pnl.add(new FLabel.Builder().text(title).build());
|
||||
pnl.add(new FScrollPane(cbl, true));
|
||||
return pnl;
|
||||
|
||||
}
|
||||
|
||||
private void handleOk() {
|
||||
|
||||
for (FCheckBox box : choices) {
|
||||
if (box.isSelected()) {
|
||||
selectedFormats.add(FModel.getFormats().getFormat(box.getName()));
|
||||
}
|
||||
wantReprints = cbWantReprints.isSelected();
|
||||
}
|
||||
|
||||
if (null != okCallback) {
|
||||
okCallback.run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user