mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Avoid muddying collection with unowned cards
This commit is contained in:
@@ -105,8 +105,6 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
||||
|
||||
private final Class<T> myClass; //class does not keep this in runtime by itself
|
||||
|
||||
private boolean allowZero; //whether to allow items with 0 count to remain in pool
|
||||
|
||||
@Override
|
||||
public final Iterator<Entry<T, Integer>> iterator() {
|
||||
return items.entrySet().iterator();
|
||||
@@ -184,13 +182,6 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
||||
return myClass;
|
||||
}
|
||||
|
||||
public boolean allowZero() {
|
||||
return allowZero;
|
||||
}
|
||||
public void setAllowZero(boolean allowZero0) {
|
||||
allowZero = allowZero0;
|
||||
}
|
||||
|
||||
public ItemPool<T> getView() {
|
||||
return new ItemPool<T>(Collections.unmodifiableMap(items), getMyClass());
|
||||
}
|
||||
@@ -200,16 +191,8 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
||||
}
|
||||
|
||||
public void add(final T item, final int amount) {
|
||||
if (item == null) { return; }
|
||||
if (item == null || amount <= 0) { return; }
|
||||
|
||||
if (amount <= 0) {
|
||||
if (allowZero) {
|
||||
if (!items.containsKey(item)) {
|
||||
items.put(item, 0);
|
||||
}
|
||||
}
|
||||
else { return; }
|
||||
}
|
||||
items.put(item, count(item) + amount);
|
||||
}
|
||||
|
||||
@@ -253,13 +236,8 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
||||
return false;
|
||||
}
|
||||
if (count <= amount) {
|
||||
if (allowZero) {
|
||||
items.put(item, 0);
|
||||
}
|
||||
else {
|
||||
items.remove(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
items.put(item, count - amount);
|
||||
}
|
||||
|
||||
@@ -408,7 +408,6 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
public void setPool(final ItemPool<T> pool0, boolean infinite) {
|
||||
pool = pool0;
|
||||
model.clear();
|
||||
model.setAllowZero(pool.allowZero());
|
||||
model.addItems(pool);
|
||||
model.setInfinite(infinite);
|
||||
updateView(true, null);
|
||||
@@ -763,17 +762,7 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
//update ratio of # in filtered pool / # in total pool
|
||||
ItemPool<T> filteredItems = getFilteredItems();
|
||||
int filteredCount = filteredItems.countAll();
|
||||
|
||||
int totalCount;
|
||||
if (pool.allowZero() && isInfinite()) { //use count distinct if pool is infinite to account for zeros and save performance
|
||||
totalCount = filteredItems.countDistinct();
|
||||
}
|
||||
else if (useFilter) {
|
||||
totalCount = pool.countAll();
|
||||
}
|
||||
else {
|
||||
totalCount = filteredCount;
|
||||
}
|
||||
int totalCount = useFilter ? pool.countAll() : filteredCount;
|
||||
|
||||
searchFilter.setRatio("(" + filteredCount + " / " + totalCount + ")");
|
||||
}
|
||||
|
||||
@@ -366,13 +366,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
group = otherItems;
|
||||
}
|
||||
|
||||
if (qty > 0) {
|
||||
for (int i = 0; i < qty; i++) {
|
||||
group.add(new ItemInfo(item, group, false));
|
||||
}
|
||||
}
|
||||
else { //add single item for unowned item
|
||||
group.add(new ItemInfo(item, group, true));
|
||||
group.add(new ItemInfo(item, group));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,7 +766,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private final String name;
|
||||
private boolean isCollapsed;
|
||||
private float scrollWidth;
|
||||
private int owned;
|
||||
|
||||
public Group(String name0) {
|
||||
name = name0;
|
||||
@@ -779,9 +773,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
public void add(ItemInfo item) {
|
||||
items.add(item);
|
||||
if (!item.unowned) {
|
||||
owned++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -797,13 +788,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
//draw group name and horizontal line
|
||||
float x = GROUP_HEADER_GLYPH_WIDTH + PADDING + 1;
|
||||
float y = 0;
|
||||
String caption;
|
||||
if (itemManager.getPool().allowZero() && itemManager.isInfinite()) {
|
||||
caption = name + " (" + owned + " / " + items.size() + ")"; //show ratio of owned / total when zero allowed
|
||||
}
|
||||
else {
|
||||
caption = name + " (" + owned + ")";
|
||||
}
|
||||
String caption = name + " (" + items.size() + ")";
|
||||
g.drawText(caption, GROUP_HEADER_FONT, GROUP_HEADER_FORE_COLOR, x, y, getWidth(), GROUP_HEADER_HEIGHT, false, HAlignment.LEFT, true);
|
||||
x += GROUP_HEADER_FONT.getBounds(caption).width + PADDING;
|
||||
y += GROUP_HEADER_HEIGHT / 2;
|
||||
@@ -922,15 +907,13 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private class ItemInfo extends FDisplayObject implements Entry<InventoryItem, Integer> {
|
||||
private final T item;
|
||||
private final Group group;
|
||||
private final boolean unowned;
|
||||
private int index;
|
||||
private CardStackPosition pos;
|
||||
private boolean selected;
|
||||
|
||||
private ItemInfo(T item0, Group group0, boolean unowned0) {
|
||||
private ItemInfo(T item0, Group group0) {
|
||||
item = item0;
|
||||
group = group0;
|
||||
unowned = unowned0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -961,19 +944,9 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
final float h = getHeight();
|
||||
|
||||
if (selected) {
|
||||
if (unowned) { //use drawRect for unowned to prevent green showing through card
|
||||
g.drawRect(SEL_BORDER_SIZE, Color.GREEN, x - SEL_BORDER_SIZE, y - SEL_BORDER_SIZE,
|
||||
w + 2 * SEL_BORDER_SIZE, h + 2 * SEL_BORDER_SIZE);
|
||||
}
|
||||
else {
|
||||
g.fillRect(Color.GREEN, x - SEL_BORDER_SIZE, y - SEL_BORDER_SIZE,
|
||||
w + 2 * SEL_BORDER_SIZE, h + 2 * SEL_BORDER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
if (unowned) {
|
||||
g.setAlphaComposite(UNOWNED_ALPHA_COMPOSITE);
|
||||
}
|
||||
|
||||
if (item instanceof PaperCard) {
|
||||
CardRenderer.drawCard(g, (PaperCard)item, x, y, w, h, pos);
|
||||
@@ -988,10 +961,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
g.drawText(item.getName(), GROUP_HEADER_FONT, Color.WHITE, x + PADDING, y + PADDING, w - 2 * PADDING, h - 2 * PADDING, true, HAlignment.CENTER, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (unowned) {
|
||||
g.resetAlphaComposite();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,10 +239,6 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Integer index, Entry<T, Integer> value, FSkinFont font, FSkinColor foreColor, FSkinColor backColor, boolean pressed, float x, float y, float w, float h) {
|
||||
boolean unowned = (value.getValue() == 0); //fade out item if item isn't owned
|
||||
if (unowned) {
|
||||
g.setAlphaComposite(UNOWNED_ALPHA_COMPOSITE);
|
||||
}
|
||||
if (maxSelections > 1) {
|
||||
if (pressed) { //if multi-select mode, draw SEL_COLOR when pressed
|
||||
g.fillRect(SEL_COLOR, x - FList.PADDING, y - FList.PADDING, w + 2 * FList.PADDING, h + 2 * FList.PADDING);
|
||||
@@ -255,9 +251,6 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
w -= padding;
|
||||
}
|
||||
renderer.drawValue(g, value, font, foreColor, backColor, pressed, x + 1, y, w - 2, h); //x + 1 and w - 2 to account for left and right borders
|
||||
if (unowned) {
|
||||
g.resetAlphaComposite();
|
||||
}
|
||||
}
|
||||
});
|
||||
setFont(FSkinFont.get(14));
|
||||
|
||||
@@ -2,6 +2,7 @@ package forge.screens.planarconquest;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.deck.CardPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.itemmanager.CardManager;
|
||||
import forge.itemmanager.ItemManager;
|
||||
@@ -33,7 +34,9 @@ public class ConquestCollectionScreen extends FScreen {
|
||||
}
|
||||
|
||||
public void refreshCards() {
|
||||
FModel.getConquest().getModel().populateCollectionManager(lstCollection);
|
||||
CardPool pool = new CardPool();
|
||||
pool.add(FModel.getConquest().getModel().getUnlockedCards());
|
||||
lstCollection.setPool(pool, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -117,13 +117,6 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
||||
return infiniteSupply;
|
||||
}
|
||||
|
||||
public boolean allowZero() {
|
||||
return data.allowZero();
|
||||
}
|
||||
public void setAllowZero(boolean allowZero0) {
|
||||
data.setAllowZero(allowZero0);
|
||||
}
|
||||
|
||||
public CascadeManager getCascadeManager() {
|
||||
return cascadeManager;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import forge.card.CardDb;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.itemmanager.ColumnDef;
|
||||
import forge.itemmanager.IItemManager;
|
||||
import forge.itemmanager.ItemColumn;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.model.FModel;
|
||||
@@ -31,7 +30,6 @@ import forge.planarconquest.ConquestPlane.Region;
|
||||
import forge.planarconquest.ConquestPreferences.CQPref;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.XmlReader;
|
||||
import forge.util.XmlWriter;
|
||||
|
||||
@@ -55,7 +53,6 @@ public final class ConquestData {
|
||||
private ISkinImage planeswalkerToken;
|
||||
private ConquestLocation currentLocation;
|
||||
private int aetherShards;
|
||||
private ConquestCollection collection;
|
||||
|
||||
private final File directory;
|
||||
private final String xmlFilename;
|
||||
@@ -145,13 +142,6 @@ public final class ConquestData {
|
||||
return getOrCreatePlaneData(getCurrentPlane());
|
||||
}
|
||||
|
||||
public void populateCollectionManager(IItemManager<PaperCard> manager) {
|
||||
if (collection == null) {
|
||||
collection = new ConquestCollection();
|
||||
}
|
||||
manager.setPool(collection, true);
|
||||
}
|
||||
|
||||
public Iterable<PaperCard> getUnlockedCards() {
|
||||
return unlockedCards;
|
||||
}
|
||||
@@ -163,9 +153,6 @@ public final class ConquestData {
|
||||
public void unlockCard(PaperCard card) {
|
||||
if (unlockedCards.add(card)) {
|
||||
newCards.add(card);
|
||||
if (collection != null) {
|
||||
collection.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void unlockCards(Iterable<PaperCard> cards) {
|
||||
@@ -404,20 +391,4 @@ public final class ConquestData {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class ConquestCollection extends ItemPool<PaperCard> {
|
||||
private ConquestCollection() {
|
||||
super(PaperCard.class);
|
||||
setAllowZero(true);
|
||||
|
||||
//initialize to contain all available cards, with unlocked
|
||||
//having a count of 1 and the rest having a count of 0
|
||||
for (ConquestPlane plane : ConquestPlane.values()) {
|
||||
for (PaperCard card : plane.getCardPool().getAllCards()) {
|
||||
items.put(card, hasUnlockedCard(card) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user