mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Display of split costs in deck editor
This commit is contained in:
@@ -24,6 +24,8 @@ import java.util.List;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.gui.toolbox.CardFaceSymbols;
|
||||
@@ -34,7 +36,13 @@ import forge.gui.toolbox.CardFaceSymbols;
|
||||
public class ManaCostRenderer extends DefaultTableCellRenderer {
|
||||
private static final long serialVersionUID = 1770527102334163549L;
|
||||
|
||||
private ManaCost value;
|
||||
static final int elemtWidth = 13;
|
||||
static final int elemtGap = 0;
|
||||
static final int padding0 = 1;
|
||||
static final int spaceBetweenSplitCosts = 3;
|
||||
|
||||
private ManaCost v1;
|
||||
private ManaCost v2;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -46,8 +54,10 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
|
||||
@Override
|
||||
public final Component getTableCellRendererComponent(final JTable table, final Object value,
|
||||
final boolean isSelected, final boolean hasFocus, final int row, final int column) {
|
||||
this.value = (ManaCost) value;
|
||||
this.setToolTipText(this.value.toString());
|
||||
CardRules v = value instanceof CardRules ? (CardRules) value : null;
|
||||
this.v1 = v == null ? ManaCost.NO_COST : v.getMainPart().getManaCost();
|
||||
this.v2 = v == null || v.getSplitType() != CardSplitType.Split ? null : v.getOtherPart().getManaCost();
|
||||
this.setToolTipText(v2 == null ? v1.toString() : v1.toString() + " / " + v2.toString());
|
||||
return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column);
|
||||
}
|
||||
|
||||
@@ -60,18 +70,38 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
|
||||
public final void paint(final Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
final int elemtWidth = 13;
|
||||
final int elemtGap = 0;
|
||||
final int padding = 1;
|
||||
|
||||
float xpos = padding;
|
||||
|
||||
final int genericManaCost = this.value.getGenericCost();
|
||||
final int xManaCosts = this.value.countX();
|
||||
final boolean hasGeneric = (genericManaCost > 0) || this.value.isPureGeneric();
|
||||
final List<ManaCostShard> shards = this.value.getShards();
|
||||
|
||||
final int cellWidth = this.getWidth();
|
||||
|
||||
if ( null == v2 )
|
||||
drawCost(g, v1, padding0, cellWidth);
|
||||
else
|
||||
{
|
||||
int shards1 = v1.isPureGeneric() || v1.getGenericCost() > 0 ? 1 : 0;
|
||||
int shards2 = v2.isPureGeneric() || v2.getGenericCost() > 0 ? 1 : 0;
|
||||
shards1 += v1.getShards().size();
|
||||
shards2 += v2.getShards().size();
|
||||
|
||||
int perGlyph = (cellWidth - padding0 - spaceBetweenSplitCosts) / (shards1 + shards2);
|
||||
perGlyph = Math.min(perGlyph, elemtWidth + elemtGap);
|
||||
drawCost(g, v1, padding0, padding0 + perGlyph * shards1);
|
||||
drawCost(g, v2, cellWidth - perGlyph * shards2, cellWidth );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param g
|
||||
* @param padding
|
||||
* @param cellWidth
|
||||
*/
|
||||
private void drawCost(final Graphics g, ManaCost value, final int padding, final int cellWidth) {
|
||||
float xpos = padding;
|
||||
final int genericManaCost = value.getGenericCost();
|
||||
final int xManaCosts = value.countX();
|
||||
final boolean hasGeneric = (genericManaCost > 0) || this.v1.isPureGeneric();
|
||||
final List<ManaCostShard> shards = value.getShards();
|
||||
|
||||
|
||||
final int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size();
|
||||
final float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f)
|
||||
: elemtWidth + elemtGap;
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.google.common.base.Function;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.card.CardAiHints;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
@@ -318,11 +319,14 @@ public final class SColumnUtil {
|
||||
private static final Pattern AE_FINDER = Pattern.compile("AE", Pattern.LITERAL);
|
||||
|
||||
private static ManaCost toManaCost(final InventoryItem i) {
|
||||
return i instanceof CardPrinted ? ((IPaperCard) i).getRules().getManaCost() : ManaCost.NO_COST;
|
||||
return i instanceof IPaperCard ? ((IPaperCard) i).getRules().getManaCost() : ManaCost.NO_COST;
|
||||
}
|
||||
|
||||
private static CardRules toCardRules(final InventoryItem i) {
|
||||
return i instanceof IPaperCard ? ((IPaperCard) i).getRules() : null;
|
||||
}
|
||||
|
||||
private static ColorSet toColor(final InventoryItem i) {
|
||||
return i instanceof CardPrinted ? ((IPaperCard) i).getRules().getColor() : ColorSet.getNullColor();
|
||||
return i instanceof IPaperCard ? ((IPaperCard) i).getRules().getColor() : ColorSet.getNullColor();
|
||||
}
|
||||
|
||||
private static int toPower(final InventoryItem i) {
|
||||
@@ -430,7 +434,7 @@ public final class SColumnUtil {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_COST_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toManaCost(from.getKey());
|
||||
return SColumnUtil.toCardRules(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user