Support showing certain card overlays

This commit is contained in:
drdev
2014-05-24 22:08:35 +00:00
parent abc441fb01
commit 20f72d324f
4 changed files with 140 additions and 11 deletions

View File

@@ -114,25 +114,25 @@ public class CardFaceSymbols {
if (hasGeneric) {
for (final ManaCostShard s : manaCost) { //render X shards before generic
if (s == ManaCostShard.X) {
drawSymbol(s.getImageKey(), g, x, y, imageSize);
drawSymbol(s.getImageKey(), g, x, y, imageSize, imageSize);
x += dx;
}
}
final String sGeneric = Integer.toString(genericManaCost);
drawSymbol(sGeneric, g, x, y, imageSize);
drawSymbol(sGeneric, g, x, y, imageSize, imageSize);
x += dx;
for (final ManaCostShard s : manaCost) { //render non-X shards after generic
if (s != ManaCostShard.X) {
drawSymbol(s.getImageKey(), g, x, y, imageSize);
drawSymbol(s.getImageKey(), g, x, y, imageSize, imageSize);
x += dx;
}
}
}
else { //if no generic, just render shards in order
for (final ManaCostShard s : manaCost) {
drawSymbol(s.getImageKey(), g, x, y, imageSize);
drawSymbol(s.getImageKey(), g, x, y, imageSize, imageSize);
x += dx;
}
}
@@ -140,7 +140,7 @@ public class CardFaceSymbols {
public static void drawColorSet(Graphics g, ColorSet colorSet, float x, float y, final float imageSize) {
if (colorSet.isColorless()) {
CardFaceSymbols.drawSymbol(ManaCostShard.X.getImageKey(), g, x, y, imageSize);
CardFaceSymbols.drawSymbol(ManaCostShard.X.getImageKey(), g, x, y, imageSize, imageSize);
return;
}
@@ -166,12 +166,12 @@ public class CardFaceSymbols {
}
}
public static void drawOther(final Graphics g, String s, float x, final float y, final float imageSize) {
public static void drawOther(final Graphics g, String s, float x, final float y, final float w, final float h) {
if (s.length() == 0) {
return;
}
final float dx = imageSize;
final float dx = w;
StringTokenizer tok = new StringTokenizer(s, " ");
while (tok.hasMoreTokens()) {
@@ -181,13 +181,13 @@ public class CardFaceSymbols {
BugReporter.reportBug("Symbol not recognized \"" + symbol + "\" in string: " + s);
continue;
}
g.drawImage(image, x, y, imageSize, imageSize);
g.drawImage(image, x, y, w, h);
x += dx;
}
}
public static void drawSymbol(final String imageName, final Graphics g, final float x, final float y, final float imageSize) {
g.drawImage(MANA_IMAGES.get(imageName), x, y, imageSize, imageSize);
public static void drawSymbol(final String imageName, final Graphics g, final float x, final float y, final float w, final float h) {
g.drawImage(MANA_IMAGES.get(imageName), x, y, w, h);
}
public static float getWidth(final ManaCost manaCost, float imageSize) {

View File

@@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map;
import forge.FThreads;
import forge.Forge;
import forge.Forge.Graphics;
import forge.card.CardZoom;
import forge.game.card.Card;
import forge.screens.match.FControl;
@@ -129,6 +131,13 @@ public abstract class VCardDisplayArea extends VDisplayArea {
return new ScrollBounds(x, visibleHeight);
}
@Override
protected void startClip(Graphics g) {
//prevent clipping horizontally
float dy = Forge.getCurrentScreen().getHeight();
g.startClip(0, -dy, getWidth(), 2 * dy);
}
public static class CardAreaPanel extends FCardPanel {
private static final Map<Integer, CardAreaPanel> allCardPanels = new HashMap<Integer, CardAreaPanel>();

View File

@@ -4,7 +4,14 @@ import com.badlogic.gdx.graphics.Texture;
import forge.Forge.Graphics;
import forge.assets.ImageCache;
import forge.card.CardCharacteristicName;
import forge.card.CardFaceSymbols;
import forge.card.mana.ManaCost;
import forge.game.card.Card;
import forge.game.combat.Combat;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.screens.match.FControl;
import forge.util.Utils;
public class FCardPanel extends FDisplayObject {
@@ -90,9 +97,118 @@ public class FCardPanel extends FDisplayObject {
}
g.drawImage(image, x, y, w, h);
drawOverlays(g, x, y, w, h);
if (tapped) {
g.clearTransform();
}
}
private void drawOverlays(Graphics g, float x, float y, float w, float h) {
if (showCardManaCostOverlay() && w < 200) {
float manaSymbolSize = w / 4;
if (card.isSplitCard() && card.getCurState() == CardCharacteristicName.Original) {
float dy = manaSymbolSize / 2 + Utils.scaleY(5);
drawManaCost(g, card.getRules().getMainPart().getManaCost(), x, y + dy, w, h, manaSymbolSize);
drawManaCost(g, card.getRules().getOtherPart().getManaCost(), x, y - dy, w, h, manaSymbolSize);
}
else {
drawManaCost(g, card.getManaCost(), x, y, w, h, manaSymbolSize);
}
}
int number = 0;
for (final Integer i : card.getCounters().values()) {
number += i.intValue();
}
final int counters = number;
float countersSize = w / 2;
final float xCounters = x - countersSize / 2;
final float yCounters = y + h * 2 / 3 - countersSize;
if (counters == 1) {
CardFaceSymbols.drawSymbol("counters1", g, xCounters, yCounters, countersSize, countersSize);
}
else if (counters == 2) {
CardFaceSymbols.drawSymbol("counters2", g, xCounters, yCounters, countersSize, countersSize);
}
else if (counters == 3) {
CardFaceSymbols.drawSymbol("counters3", g, xCounters, yCounters, countersSize, countersSize);
}
else if (counters > 3) {
CardFaceSymbols.drawSymbol("countersMulti", g, xCounters, yCounters, countersSize, countersSize);
}
float otherSymbolsSize = w / 2;
final float combatXSymbols = (x + (w / 4)) - otherSymbolsSize / 2;
final float stateXSymbols = (x + (w / 2)) - otherSymbolsSize / 2;
final float ySymbols = (y + h) - (h / 8) - otherSymbolsSize / 2;
Combat combat = card.getGame().getCombat();
if (combat != null) {
if (combat.isAttacking(card)) {
CardFaceSymbols.drawSymbol("attack", g, combatXSymbols, ySymbols, otherSymbolsSize, otherSymbolsSize);
}
if (combat.isBlocking(card)) {
CardFaceSymbols.drawSymbol("defend", g, combatXSymbols, ySymbols, otherSymbolsSize, otherSymbolsSize);
}
}
if (card.isSick() && card.isInPlay()) {
CardFaceSymbols.drawSymbol("summonsick", g, stateXSymbols, ySymbols, otherSymbolsSize, otherSymbolsSize);
}
if (card.isPhasedOut()) {
CardFaceSymbols.drawSymbol("phasing", g, stateXSymbols, ySymbols, otherSymbolsSize, otherSymbolsSize);
}
if (FControl.isUsedToPay(card)) {
float sacSymbolSize = otherSymbolsSize * 1.2f;
CardFaceSymbols.drawSymbol("sacrifice", g, (x + (w / 2)) - sacSymbolSize / 2, (y + (h / 2)) - sacSymbolSize / 2, otherSymbolsSize, otherSymbolsSize);
}
drawFoilEffect(g, card, x, y, w, h);
}
private void drawManaCost(final Graphics g, ManaCost cost, float x, float y, float w, float h, float manaSymbolSize) {
float manaCostWidth = CardFaceSymbols.getWidth(cost, manaSymbolSize);
CardFaceSymbols.drawManaCost(g, cost, x + (w - manaCostWidth) / 2, y + (h - manaSymbolSize) / 2, manaSymbolSize);
}
public static void drawFoilEffect(Graphics g, Card card, float x, float y, float w, float h) {
if (isPreferenceEnabled(FPref.UI_OVERLAY_FOIL_EFFECT)) {
int foil = card.getFoil();
if (foil > 0) {
CardFaceSymbols.drawOther(g, String.format("foil%02d", foil), x, y, w, h);
}
}
}
private static boolean isPreferenceEnabled(FPref preferenceName) {
return FModel.getPreferences().getPrefBoolean(preferenceName);
}
private boolean isShowingOverlays() {
return isPreferenceEnabled(FPref.UI_SHOW_CARD_OVERLAYS) && card != null && FControl.mayShowCard(card);
}
private boolean showCardNameOverlay() {
return isShowingOverlays() && isPreferenceEnabled(FPref.UI_OVERLAY_CARD_NAME);
}
private boolean showCardPowerOverlay() {
return isShowingOverlays() && isPreferenceEnabled(FPref.UI_OVERLAY_CARD_POWER);
}
private boolean showCardManaCostOverlay() {
return isShowingOverlays() &&
isPreferenceEnabled(FPref.UI_OVERLAY_CARD_MANA_COST) &&
!getCard().isFaceDown();
}
private boolean showCardIdOverlay() {
return isShowingOverlays() && isPreferenceEnabled(FPref.UI_OVERLAY_CARD_ID);
}
}

View File

@@ -264,9 +264,13 @@ public abstract class FScrollPane extends FContainer {
return true;
}
protected void startClip(Graphics g) {
g.startClip(0, 0, getWidth(), getHeight());
}
@Override
public void draw(Graphics g) {
g.startClip(0, 0, getWidth(), getHeight());
startClip(g);
super.draw(g);
g.endClip();
}