mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Code cleanup
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1082,6 +1082,7 @@ forge-gui-mobile/src/forge/error/BugReporter.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/CardManager.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/DeckManager.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/ItemManager.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/SpellShopManager.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/filters/CardCMCFilter.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/filters/CardCMCRangeFilter.java -text
|
||||
forge-gui-mobile/src/forge/itemmanager/filters/CardColorFilter.java -text
|
||||
|
||||
27
forge-gui-mobile/src/forge/itemmanager/SpellShopManager.java
Normal file
27
forge-gui-mobile/src/forge/itemmanager/SpellShopManager.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package forge.itemmanager;
|
||||
|
||||
import forge.item.InventoryItem;
|
||||
import forge.itemmanager.filters.ItemFilter;
|
||||
import forge.menu.FPopupMenu;
|
||||
|
||||
|
||||
public final class SpellShopManager extends ItemManager<InventoryItem> {
|
||||
public SpellShopManager(boolean wantUnique0) {
|
||||
super(InventoryItem.class, wantUnique0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addDefaultFilters() {
|
||||
CardManager.addDefaultFilters(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemFilter<? extends InventoryItem> createSearchFilter() {
|
||||
return CardManager.createSearchFilter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildAddFilterMenu(FPopupMenu menu) {
|
||||
CardManager.buildAddFilterMenu(menu, this);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import forge.item.InventoryItem;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.menu.FTooltip;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FTextField;
|
||||
import forge.util.LayoutHelper;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import forge.toolbox.FDisplayObject;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.toolbox.FList;
|
||||
import forge.util.Utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -46,19 +47,16 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
private static final FSkinColor SEL_ACTIVE_COLOR = FSkinColor.get(Colors.CLR_ACTIVE);
|
||||
private static final FSkinColor SEL_INACTIVE_COLOR = FSkinColor.get(Colors.CLR_INACTIVE);
|
||||
private static final FSkinColor HEADER_BACK_COLOR = BACK_COLOR.getContrastColor(-10);
|
||||
static final FSkinColor ALT_ROW_COLOR = BACK_COLOR.getContrastColor(-20);
|
||||
private static final FSkinColor GRID_COLOR = BACK_COLOR.getContrastColor(20);
|
||||
private static final FSkinFont ROW_FONT = FSkinFont.get(12);
|
||||
private static final int ROW_HEIGHT = 19;
|
||||
private static final float ROW_HEIGHT = Utils.AVG_FINGER_HEIGHT + 12;
|
||||
|
||||
private final ItemTable table = new ItemTable();
|
||||
private final ItemTableModel tableModel;
|
||||
private final ItemList list = new ItemList();
|
||||
private final ItemListModel listModel;
|
||||
private boolean allowMultipleSelections;
|
||||
private List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||
|
||||
public ItemTableModel getTableModel() {
|
||||
return tableModel;
|
||||
public ItemListModel getTableModel() {
|
||||
return listModel;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +67,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
*/
|
||||
public ItemListView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||
super(itemManager0, model0);
|
||||
tableModel = new ItemTableModel(model0);
|
||||
listModel = new ItemListModel(model0);
|
||||
setAllowMultipleSelections(false);
|
||||
getPnlOptions().setVisible(false); //hide options panel by default
|
||||
}
|
||||
@@ -78,26 +76,23 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
public void setup(ItemManagerConfig config, Map<ColumnDef, ItemColumn> colOverrides) {
|
||||
final Iterable<T> selectedItemsBefore = getSelectedItems();
|
||||
|
||||
//ensure columns ordered properly
|
||||
final List<ItemColumn> columns = new LinkedList<ItemColumn>();
|
||||
//ensure cells ordered properly
|
||||
final List<ItemColumn> cols = new LinkedList<ItemColumn>();
|
||||
for (ItemColumnConfig colConfig : config.getCols().values()) {
|
||||
if (colOverrides == null || !colOverrides.containsKey(colConfig.getDef())) {
|
||||
columns.add(new ItemColumn(colConfig));
|
||||
cols.add(new ItemColumn(colConfig));
|
||||
}
|
||||
else {
|
||||
columns.add(colOverrides.get(colConfig.getDef()));
|
||||
cols.add(colOverrides.get(colConfig.getDef()));
|
||||
}
|
||||
}
|
||||
Collections.sort(columns, new Comparator<ItemColumn>() {
|
||||
Collections.sort(cols, new Comparator<ItemColumn>() {
|
||||
@Override
|
||||
public int compare(ItemColumn arg0, ItemColumn arg1) {
|
||||
return Integer.compare(arg0.getConfig().getIndex(), arg1.getConfig().getIndex());
|
||||
}
|
||||
});
|
||||
|
||||
//hide table header if only showing single string column
|
||||
boolean hideHeader = (config.getCols().size() == 1 && config.getCols().containsKey(ColumnDef.STRING));
|
||||
|
||||
getPnlOptions().clear();
|
||||
|
||||
if (config.getShowUniqueCardsOption()) {
|
||||
@@ -112,7 +107,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
itemManager.refresh();
|
||||
|
||||
if (itemManager.getConfig() != null) {
|
||||
itemManager.getConfig().setUniqueCardsOnly(wantUnique);
|
||||
itemManager.setWantUnique(wantUnique);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -120,58 +115,53 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
}
|
||||
|
||||
int modelIndex = 0;
|
||||
for (final ItemColumn col : columns) {
|
||||
col.getConfig().setIndex(modelIndex++);
|
||||
if (col.getConfig().isVisible()) { table.columns.add(col); }
|
||||
for (final ItemColumn col : cols) {
|
||||
final ItemCell cell = new ItemCell(col);
|
||||
col.setIndex(modelIndex++);
|
||||
if (col.isVisible()) { list.cells.add(cell); }
|
||||
|
||||
if (!hideHeader) {
|
||||
final FCheckBox chkBox = new FCheckBox(StringUtils.isEmpty(col.getConfig().getShortName()) ?
|
||||
col.getConfig().getLongName() : col.getConfig().getShortName(), col.getConfig().isVisible());
|
||||
chkBox.setFontSize(ROW_FONT.getSize());
|
||||
chkBox.setCommand(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
boolean visible = chkBox.isSelected();
|
||||
if (col.getConfig().isVisible() == visible) { return; }
|
||||
col.getConfig().setVisible(visible);
|
||||
final FCheckBox chkBox = new FCheckBox(StringUtils.isEmpty(col.getShortName()) ?
|
||||
col.getLongName() : col.getShortName(), col.isVisible());
|
||||
chkBox.setFontSize(ROW_FONT.getSize());
|
||||
chkBox.setCommand(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
boolean visible = chkBox.isSelected();
|
||||
if (col.isVisible() == visible) { return; }
|
||||
col.setVisible(visible);
|
||||
|
||||
if (col.getConfig().isVisible()) {
|
||||
table.columns.add(col);
|
||||
if (col.isVisible()) {
|
||||
list.cells.add(cell);
|
||||
|
||||
//move column into proper position
|
||||
int oldIndex = table.getColumnCount() - 1;
|
||||
int newIndex = col.getConfig().getIndex();
|
||||
for (int i = 0; i < col.getConfig().getIndex(); i++) {
|
||||
if (!columns.get(i).getConfig().isVisible()) {
|
||||
newIndex--;
|
||||
}
|
||||
}
|
||||
if (newIndex < oldIndex) {
|
||||
table.columns.remove(oldIndex);
|
||||
table.columns.add(newIndex, col);
|
||||
//move cell into proper position
|
||||
int oldIndex = list.getCellCount() - 1;
|
||||
int newIndex = col.getIndex();
|
||||
for (int i = 0; i < col.getIndex(); i++) {
|
||||
if (!cols.get(i).isVisible()) {
|
||||
newIndex--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
table.columns.remove(col);
|
||||
if (newIndex < oldIndex) {
|
||||
list.cells.remove(oldIndex);
|
||||
list.cells.add(newIndex, cell);
|
||||
}
|
||||
ItemManagerConfig.save();
|
||||
}
|
||||
});
|
||||
getPnlOptions().add(chkBox);
|
||||
}
|
||||
else {
|
||||
list.cells.remove(cell);
|
||||
}
|
||||
ItemManagerConfig.save();
|
||||
}
|
||||
});
|
||||
getPnlOptions().add(chkBox);
|
||||
}
|
||||
|
||||
tableModel.setup();
|
||||
listModel.setup();
|
||||
refresh(selectedItemsBefore, 0, 0);
|
||||
}
|
||||
|
||||
public ItemTable getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FDisplayObject getComponent() {
|
||||
return table;
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,7 +208,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
public void scrollSelectionIntoView() {
|
||||
//table.scrollIntoView(table.getItemAt(getSelectedIndex()));
|
||||
//list.scrollIntoView(list.getItemAt(getSelectedIndex()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,18 +217,18 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
public int getIndexOfItem(T item) {
|
||||
return tableModel.itemToRow(item);
|
||||
return listModel.itemToRow(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getItemAtIndex(int index) {
|
||||
Entry<T, Integer> itemEntry = tableModel.rowToItem(index);
|
||||
Entry<T, Integer> itemEntry = listModel.rowToItem(index);
|
||||
return itemEntry != null ? itemEntry.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return table.getCount();
|
||||
return list.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,50 +249,49 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
protected void onRefresh() {
|
||||
}
|
||||
|
||||
public final class ItemTable extends FList<T> {
|
||||
private List<ItemColumn> columns = new ArrayList<ItemColumn>();
|
||||
public final class ItemList extends FList<T> {
|
||||
private List<ItemCell> cells = new ArrayList<ItemCell>();
|
||||
|
||||
private ItemTable() {
|
||||
private ItemList() {
|
||||
}
|
||||
|
||||
public Iterable<ItemColumn> getColumns() {
|
||||
return columns;
|
||||
public Iterable<ItemCell> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return columns.size();
|
||||
public int getCellCount() {
|
||||
return cells.size();
|
||||
}
|
||||
}
|
||||
|
||||
public final class ItemTableModel {
|
||||
public final class ItemListModel {
|
||||
private final ItemManagerModel<T> model;
|
||||
|
||||
/**
|
||||
* Instantiates a new table model.
|
||||
* Instantiates a new list model.
|
||||
*
|
||||
* @param table0   {@link forge.gui.ItemManager.ItemTable<T>}
|
||||
* @param model0   {@link forge.gui.ItemManager.ItemManagerModel<T>}
|
||||
*/
|
||||
public ItemTableModel(final ItemManagerModel<T> model0) {
|
||||
public ItemListModel(final ItemManagerModel<T> model0) {
|
||||
model = model0;
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
final ItemColumn[] sortcols = new ItemColumn[table.getColumnCount()];
|
||||
final ItemCell[] sortcells = new ItemCell[list.getCellCount()];
|
||||
|
||||
// Assemble priority sort.
|
||||
for (ItemColumn col : table.getColumns()) {
|
||||
if (col.getConfig().getSortPriority() > 0 && col.getConfig().getSortPriority() <= sortcols.length) {
|
||||
sortcols[col.getConfig().getSortPriority() - 1] = col;
|
||||
for (ItemCell cell : list.getCells()) {
|
||||
if (cell.getSortPriority() > 0 && cell.getSortPriority() <= sortcells.length) {
|
||||
sortcells[cell.getSortPriority() - 1] = cell;
|
||||
}
|
||||
}
|
||||
|
||||
model.getCascadeManager().reset();
|
||||
|
||||
for (int i = sortcols.length - 1; i >= 0; i--) {
|
||||
ItemColumn col = sortcols[i];
|
||||
if (col != null) {
|
||||
model.getCascadeManager().add(col, true);
|
||||
for (int i = sortcells.length - 1; i >= 0; i--) {
|
||||
ItemCell cell = sortcells[i];
|
||||
if (cell != null) {
|
||||
model.getCascadeManager().add(cell.getItemColumn(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ package forge.itemmanager;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.item.InventoryItem;
|
||||
import forge.itemmanager.ItemColumnConfig.SortState;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
@@ -50,6 +52,50 @@ public class ItemColumn {
|
||||
return config;
|
||||
}
|
||||
|
||||
public String getShortName() {
|
||||
return config.getShortName();
|
||||
}
|
||||
|
||||
public String getLongName() {
|
||||
return config.getLongName();
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return config.getIndex();
|
||||
}
|
||||
|
||||
public void setIndex(final int index0) {
|
||||
config.setIndex(index0);
|
||||
}
|
||||
|
||||
public int getSortPriority() {
|
||||
return config.getSortPriority();
|
||||
}
|
||||
|
||||
public void setSortPriority(final int sortPriority0) {
|
||||
config.setSortPriority(sortPriority0);
|
||||
}
|
||||
|
||||
public SortState getSortState() {
|
||||
return config.getSortState();
|
||||
}
|
||||
|
||||
public void setSortState(final SortState state0) {
|
||||
config.setSortState(state0);
|
||||
}
|
||||
|
||||
public SortState getDefaultSortState() {
|
||||
return config.getDefaultSortState();
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return config.isVisible();
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible0) {
|
||||
config.setVisible(visible0);
|
||||
}
|
||||
|
||||
public Function<Entry<InventoryItem, Integer>, Comparable<?>> getFnSort() {
|
||||
return fnSort;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user