Improve deck manager list view some more

This commit is contained in:
drdev
2014-04-26 23:57:54 +00:00
parent 39a204c5ba
commit 76f03c61b6
5 changed files with 95 additions and 16 deletions

View File

@@ -177,17 +177,21 @@ public class CardRenderer {
String set = card.getCurSetCode(); String set = card.getCurSetCode();
if (!StringUtils.isEmpty(set)) { if (!StringUtils.isEmpty(set)) {
float setWidth = SET_FONT.getFont().getBounds(set).width + SET_FONT.getFont().getCapHeight(); float setWidth = getSetWidth(SET_FONT, set);
drawSetLabel(g, card, set, padding, x + w + padding - setWidth - SET_BOX_MARGIN, y + SET_BOX_MARGIN, setWidth, h - SET_BOX_MARGIN); drawSetLabel(g, SET_FONT, set, card.getRarity(), x + w + padding - setWidth - SET_BOX_MARGIN, y + SET_BOX_MARGIN, setWidth, h - SET_BOX_MARGIN);
w -= setWidth; //reduce available width for type w -= setWidth; //reduce available width for type
} }
g.drawText(CardDetailUtil.formatCardType(card), TYPE_FONT, Color.BLACK, x, y, w, h, false, HAlignment.LEFT, true); g.drawText(CardDetailUtil.formatCardType(card), TYPE_FONT, Color.BLACK, x, y, w, h, false, HAlignment.LEFT, true);
} }
private static void drawSetLabel(Graphics g, Card card, String set, float padding, float x, float y, float w, float h) { public static float getSetWidth(FSkinFont font, String set) {
return font.getFont().getBounds(set).width + font.getFont().getCapHeight();
}
public static void drawSetLabel(Graphics g, FSkinFont font, String set, CardRarity rarity, float x, float y, float w, float h) {
Color backColor; Color backColor;
switch(card.getRarity()) { switch(rarity) {
case Uncommon: case Uncommon:
backColor = fromDetailColor(DetailColors.UNCOMMON); backColor = fromDetailColor(DetailColors.UNCOMMON);
break; break;

View File

@@ -5,6 +5,7 @@ import forge.assets.FSkinColor;
import forge.assets.FSkinFont; import forge.assets.FSkinFont;
import forge.assets.FSkinImage; import forge.assets.FSkinImage;
import forge.card.CardFaceSymbols; import forge.card.CardFaceSymbols;
import forge.card.CardRenderer;
import forge.card.ColorSet; import forge.card.ColorSet;
import forge.deck.DeckProxy; import forge.deck.DeckProxy;
import forge.deck.io.DeckPreferences; import forge.deck.io.DeckPreferences;
@@ -32,7 +33,6 @@ import forge.util.Utils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment; import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
@@ -248,19 +248,20 @@ public final class DeckManager extends ItemManager<DeckProxy> {
} }
private static final float IMAGE_SIZE = FSkinImage.MANA_W.getNearestHQHeight(Utils.AVG_FINGER_HEIGHT / 2); private static final float IMAGE_SIZE = FSkinImage.MANA_W.getNearestHQHeight(Utils.AVG_FINGER_HEIGHT / 2);
private static final float ITEM_HEIGHT = 2 * IMAGE_SIZE + 3 * FList.PADDING;
@Override @Override
public ItemRenderer<DeckProxy> getListItemRenderer() { public ItemRenderer<DeckProxy> getListItemRenderer() {
return new ItemRenderer<DeckProxy>() { return new ItemRenderer<DeckProxy>() {
@Override @Override
public float getItemHeight() { public float getItemHeight() {
return ITEM_HEIGHT; return IMAGE_SIZE + 2 * FSkinFont.get(12).getFont().getLineHeight() + 4 * FList.PADDING;
} }
@Override @Override
public void drawValue(Graphics g, Entry<DeckProxy, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { public void drawValue(Graphics g, Entry<DeckProxy, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
DeckProxy deck = value.getKey(); DeckProxy deck = value.getKey();
//draw favorite, name, and color on first line
g.drawImage(DeckPreferences.getPrefs(deck).getStarCount() > 0 ? FSkinImage.STAR_FILLED : FSkinImage.STAR_OUTINE, x, y, IMAGE_SIZE, IMAGE_SIZE); g.drawImage(DeckPreferences.getPrefs(deck).getStarCount() > 0 ? FSkinImage.STAR_FILLED : FSkinImage.STAR_OUTINE, x, y, IMAGE_SIZE, IMAGE_SIZE);
x += IMAGE_SIZE + FList.PADDING; x += IMAGE_SIZE + FList.PADDING;
ColorSet deckColor = deck.getColor(); ColorSet deckColor = deck.getColor();
@@ -268,6 +269,37 @@ public final class DeckManager extends ItemManager<DeckProxy> {
g.drawText(deck.getName(), font, foreColor, x, y, availableNameWidth, IMAGE_SIZE, false, HAlignment.LEFT, true); g.drawText(deck.getName(), font, foreColor, x, y, availableNameWidth, IMAGE_SIZE, false, HAlignment.LEFT, true);
x += availableNameWidth + FList.PADDING; x += availableNameWidth + FList.PADDING;
CardFaceSymbols.drawColorSet(g, deckColor, x, y, IMAGE_SIZE); CardFaceSymbols.drawColorSet(g, deckColor, x, y, IMAGE_SIZE);
//draw path and main/side on second line
x = FList.PADDING;
y += IMAGE_SIZE + FList.PADDING;
font = FSkinFont.get(font.getSize() - 2);
float lineHeight = font.getFont().getLineHeight();
int mainSize = deck.getMainSize();
if (mainSize < 0) {
mainSize = 0; //show main as 0 if empty
}
int sideSize = deck.getSideSize();
if (sideSize < 0) {
sideSize = 0; //show sideboard as 0 if empty
}
String countStr = mainSize + " / " + sideSize;
float countWidth = font.getFont().getBounds(countStr).width;
if (!deck.getPath().isEmpty()) {
g.drawText(deck.getPath().substring(1) + "/", font, foreColor, x, y, w - countWidth - FList.PADDING, lineHeight, false, HAlignment.LEFT, true);
}
g.drawText(countStr, font, foreColor, x, y, w, lineHeight, false, HAlignment.RIGHT, true);
//draw formats and set/highest rarity on third line
x = FList.PADDING;
y += lineHeight + FList.PADDING;
String set = deck.getEdition().getCode();
float setWidth = CardRenderer.getSetWidth(font, set);
float availableFormatWidth = w - setWidth - FList.PADDING;
g.drawText(deck.getFormatsString(), font, foreColor, x, y, availableFormatWidth, lineHeight, false, HAlignment.LEFT, true);
x += availableFormatWidth + FList.PADDING;
CardRenderer.drawSetLabel(g, font, set, deck.getHighestRarity(), x, y, setWidth, lineHeight);
} }
}; };
} }

View File

@@ -42,8 +42,8 @@ import java.util.Map.Entry;
public final class ItemListView<T extends InventoryItem> extends ItemView<T> { public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
private static final FSkinColor BACK_COLOR = FSkinColor.get(Colors.CLR_ZEBRA); private static final FSkinColor ROW_COLOR = FSkinColor.get(Colors.CLR_ZEBRA);
private static final FSkinColor ALT_ROW_COLOR = BACK_COLOR.getContrastColor(-20); private static final FSkinColor ALT_ROW_COLOR = ROW_COLOR.getContrastColor(-20);
private static final FSkinColor SEL_COLOR = FSkinColor.get(Colors.CLR_ACTIVE); private static final FSkinColor SEL_COLOR = FSkinColor.get(Colors.CLR_ACTIVE);
private final ItemList list = new ItemList(); private final ItemList list = new ItemList();
@@ -308,7 +308,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
@Override @Override
protected void drawBackground(Graphics g) { protected void drawBackground(Graphics g) {
g.fillRect(BACK_COLOR, 0, 0, getWidth(), getHeight()); //draw no background by default
} }
@Override @Override
@@ -319,7 +319,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
if (index % 2 == 1) { if (index % 2 == 1) {
return ALT_ROW_COLOR; return ALT_ROW_COLOR;
} }
return null; return ROW_COLOR;
} }
@Override @Override

View File

@@ -2,9 +2,11 @@ package forge.deck;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import forge.StaticData; import forge.StaticData;
import forge.card.CardEdition; import forge.card.CardEdition;
import forge.card.CardRarity;
import forge.card.ColorSet; import forge.card.ColorSet;
import forge.card.MagicColor; import forge.card.MagicColor;
import forge.deck.CardPool; import forge.deck.CardPool;
@@ -54,6 +56,7 @@ public class DeckProxy implements InventoryItem {
private final String path; private final String path;
private final Function<IHasName, Deck> fnGetDeck; private final Function<IHasName, Deck> fnGetDeck;
private CardEdition edition; private CardEdition edition;
private CardRarity highestRarity;
protected DeckProxy() { protected DeckProxy() {
this(null, "", null, "", null, null); this(null, "", null, "", null, null);
@@ -128,6 +131,7 @@ public class DeckProxy implements InventoryItem {
public void invalidateCache() { public void invalidateCache() {
color = null; color = null;
colorIdentity = null; colorIdentity = null;
highestRarity = null;
formats = null; formats = null;
edition = null; edition = null;
mainSize = Integer.MIN_VALUE; mainSize = Integer.MIN_VALUE;
@@ -176,6 +180,45 @@ public class DeckProxy implements InventoryItem {
return colorIdentity; return colorIdentity;
} }
public CardRarity getHighestRarity() {
if (highestRarity == null) {
highestRarity = CardRarity.Common;
for (Entry<DeckSection, CardPool> deckEntry : getDeck()) {
switch (deckEntry.getKey()) {
case Main:
case Sideboard:
case Commander:
for (Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
switch (poolEntry.getKey().getRarity()) {
case MythicRare:
highestRarity = CardRarity.MythicRare;
return highestRarity; //can return right away since nothing is higher
case Special:
highestRarity = CardRarity.Special; //can always set this since only mythic should be treated higher
break;
case Rare:
if (highestRarity != CardRarity.Special) {
highestRarity = CardRarity.Rare; //can set to rare unless deck contains Special rarity
}
break;
case Uncommon:
if (highestRarity != CardRarity.Rare && highestRarity != CardRarity.Special) {
highestRarity = CardRarity.Uncommon; //can set to uncommon unless deck contains rare or uncommon
}
break;
default:
break; //treat other rarities as equivalent to common
}
}
break;
default:
break; //ignore other sections
}
}
}
return highestRarity;
}
public Iterable<GameFormat> getFormats() { public Iterable<GameFormat> getFormats() {
if (formats == null) { if (formats == null) {
formats = FModel.getFormats().getAllFormatsOfDeck(getDeck()); formats = FModel.getFormats().getAllFormatsOfDeck(getDeck());
@@ -183,6 +226,10 @@ public class DeckProxy implements InventoryItem {
return formats; return formats;
} }
public String getFormatsString() {
return StringUtils.join(Iterables.transform(getFormats(), GameFormat.FN_GET_NAME), ", ");
}
public int getMainSize() { public int getMainSize() {
if (mainSize == Integer.MIN_VALUE) { if (mainSize == Integer.MIN_VALUE) {
if (deck == null) { if (deck == null) {

View File

@@ -18,8 +18,6 @@
package forge.itemmanager; package forge.itemmanager;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import forge.card.*; import forge.card.*;
import forge.deck.DeckProxy; import forge.deck.DeckProxy;
import forge.deck.io.DeckPreferences; import forge.deck.io.DeckPreferences;
@@ -33,8 +31,6 @@ import forge.itemmanager.ItemColumnConfig.SortState;
import forge.limited.DraftRankCache; import forge.limited.DraftRankCache;
import forge.model.FModel; import forge.model.FModel;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -341,7 +337,7 @@ public enum ColumnDef {
if (deck == null) { if (deck == null) {
return null; return null;
} }
return StringUtils.join(Iterables.transform(deck.getFormats(), GameFormat.FN_GET_NAME) , ", "); return deck.getFormatsString();
} }
}), }),
DECK_EDITION("Set", "Set of oldest card in deck", 38, true, SortState.DESC, DECK_EDITION("Set", "Set of oldest card in deck", 38, true, SortState.DESC,