[Mobile] update bg animation and overlays

This commit is contained in:
Anthony Calosa
2021-09-21 15:35:03 +08:00
parent b09a7e7d65
commit aed59750f9
13 changed files with 95 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Set;
import forge.game.spellability.SpellAbility;
import forge.util.*;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Predicate;
@@ -36,10 +37,6 @@ import forge.trackable.TrackableCollection;
import forge.trackable.TrackableObject;
import forge.trackable.TrackableProperty;
import forge.trackable.Tracker;
import forge.util.CardTranslation;
import forge.util.Lang;
import forge.util.Localizer;
import forge.util.TextUtil;
import forge.util.collect.FCollectionView;
public class CardView extends GameEntityView {
@@ -311,12 +308,19 @@ public class CardView extends GameEntityView {
state.updateLoyalty(c);
}
public int getCrackOverlayInt() {
if (get(TrackableProperty.CrackOverlay) == null)
return 0;
return get(TrackableProperty.CrackOverlay);
}
public int getDamage() {
return get(TrackableProperty.Damage);
}
void updateDamage(Card c) {
set(TrackableProperty.Damage, c.getDamage());
updateLethalDamage(c);
//update CrackOverlay (currently 16 overlays)
set(TrackableProperty.CrackOverlay, c.getDamage() > 0 ? MyRandom.getRandom().nextInt(16) : 0);
}
public int getAssignedDamage() {

View File

@@ -79,6 +79,7 @@ public enum TrackableProperty {
CloneOrigin(TrackableTypes.CardViewType),
ExiledWith(TrackableTypes.CardViewType),
WasDestroyed(TrackableTypes.BooleanType),
CrackOverlay(TrackableTypes.IntegerType),
ImprintedCards(TrackableTypes.CardViewCollectionType),
HauntedBy(TrackableTypes.CardViewCollectionType),

View File

@@ -719,9 +719,11 @@ public class Graphics {
batch.begin();
}
}
public void drawCardImage(FImage image, float x, float y, float w, float h, boolean drawGrayscale) {
public void drawCardImage(FImage image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (!drawGrayscale) {
image.draw(this, x, y, w, h);
if (damage_overlay != null && damaged)
batch.draw(damage_overlay, adjustX(x), adjustY(y, h), w, h);
} else {
batch.end();
shaderGrayscale.bind();
@@ -736,9 +738,11 @@ public class Graphics {
batch.begin();
}
}
public void drawCardImage(Texture image, float x, float y, float w, float h, boolean drawGrayscale) {
public void drawCardImage(Texture image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (!drawGrayscale) {
batch.draw(image, adjustX(x), adjustY(y, h), w, h);
if (damage_overlay != null && damaged)
batch.draw(damage_overlay, adjustX(x), adjustY(y, h), w, h);
} else {
batch.end();
shaderGrayscale.bind();
@@ -753,10 +757,12 @@ public class Graphics {
batch.begin();
}
}
public void drawCardImage(TextureRegion image, float x, float y, float w, float h, boolean drawGrayscale) {
public void drawCardImage(TextureRegion image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (image != null) {
if (!drawGrayscale) {
batch.draw(image, adjustX(x), adjustY(y, h), w, h);
if (damage_overlay != null && damaged)
batch.draw(damage_overlay, adjustX(x), adjustY(y, h), w, h);
} else {
batch.end();
shaderGrayscale.bind();
@@ -772,6 +778,25 @@ public class Graphics {
}
}
}
public void drawGrayTransitionImage(FImage image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", percentage);
batch.setShader(shaderGrayscale);
batch.begin();
//draw gray
image.draw(this, x, y, w, h);
//reset
batch.end();
batch.setShader(null);
batch.begin();
if(withDarkOverlay){
float oldalpha = alphaComposite;
setAlphaComposite(0.4f);
fillRect(Color.BLACK, x, y, w, h);
setAlphaComposite(oldalpha);
}
}
public void drawImage(FImage image, float x, float y, float w, float h) {
drawImage(image, x, y, w, h, false);
}

View File

@@ -30,6 +30,7 @@ public class FSkin {
private static final Map<FSkinProp, FSkinImage> images = new HashMap<>(512);
private static final Map<Integer, TextureRegion> avatars = new HashMap<>(150);
private static final Map<Integer, TextureRegion> sleeves = new HashMap<>(64);
private static final Map<Integer, TextureRegion> cracks = new HashMap<>(16);
private static final Map<Integer, TextureRegion> borders = new HashMap<>();
private static final Map<Integer, TextureRegion> deckbox = new HashMap<>();
@@ -39,7 +40,7 @@ public class FSkin {
private static boolean loaded = false;
public static Texture hdLogo = null;
public static Texture overlay_alpha = null;
public static Texture scratch = null;
public static Texture splatter = null;
public static void changeSkin(final String skinName) {
final ForgePreferences prefs = FModel.getPreferences();
@@ -143,13 +144,13 @@ public class FSkin {
} else {
overlay_alpha = null;
}
final FileHandle scratch_overlay = getDefaultSkinFile("scratch.png");
if (scratch_overlay.exists()) {
Texture txScratch = new Texture(scratch_overlay, true);
txScratch.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
scratch = txScratch;
final FileHandle splatter_overlay = getDefaultSkinFile("splatter.png");
if (splatter_overlay.exists()) {
Texture txSplatter = new Texture(splatter_overlay, true);
txSplatter.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
splatter = txSplatter;
} else {
scratch = null;
splatter = null;
}
if (splashScreen != null) {
@@ -236,6 +237,7 @@ public class FSkin {
final FileHandle f11 = getSkinFile(ForgeConstants.SPRITE_BUTTONS_FILE);
final FileHandle f12 = getSkinFile(ForgeConstants.SPRITE_START_FILE);
final FileHandle f13 = getDefaultSkinFile(ForgeConstants.SPRITE_DECKBOX_FILE);
final FileHandle f17 = getDefaultSkinFile(ForgeConstants.SPRITE_CRACKS_FILE);
/*TODO Themeable
final FileHandle f14 = getDefaultSkinFile(ForgeConstants.SPRITE_SETLOGO_FILE);
@@ -313,8 +315,8 @@ public class FSkin {
int counter = 0;
int scount = 0;
Color pxTest;
Pixmap pxDefaultAvatars, pxPreferredAvatars, pxDefaultSleeves;
Texture txDefaultAvatars, txPreferredAvatars, txDefaultSleeves;
Pixmap pxDefaultAvatars, pxPreferredAvatars, pxDefaultSleeves, pxCracks;
Texture txDefaultAvatars, txPreferredAvatars, txDefaultSleeves, txCracks;
pxDefaultAvatars = new Pixmap(f4);
pxDefaultSleeves = new Pixmap(f8);
@@ -399,6 +401,21 @@ public class FSkin {
FSkin.sleeves.put(scount++, new TextureRegion(txDefaultSleeves, i, j, 360, 500));
}
}
//cracks
pxCracks = new Pixmap(f17);
txCracks = new Texture(f17, textureFilter);
int crackCount = 0;
if (textureFilter)
txCracks.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
for (int j = 0; j < 4; j++) {
int x = j * 200;
for(int i = 0; i < 4; i++) {
int y = i * 279;
FSkin.cracks.put(crackCount++, new TextureRegion(txCracks, x, y, 200, 279));
}
}
//borders
Texture bordersBW = new Texture(f10);
FSkin.borders.put(0, new TextureRegion(bordersBW, 2, 2, 672, 936));
@@ -417,6 +434,7 @@ public class FSkin {
preferredIcons.dispose();
pxDefaultAvatars.dispose();
pxDefaultSleeves.dispose();
pxCracks.dispose();
}
catch (final Exception e) {
System.err.println("FSkin$loadFull: Missing a sprite (default icons, "
@@ -513,6 +531,10 @@ public class FSkin {
return sleeves;
}
public static Map<Integer, TextureRegion> getCracks() {
return cracks;
}
public static Map<Integer, TextureRegion> getBorders() {
return borders;
}

View File

@@ -486,6 +486,7 @@ public enum FSkinImage implements FImage {
MANAICONS(ForgeConstants.SPRITE_MANAICONS_FILE),
SETLOGOS(ForgeConstants.SPRITE_SETLOGO_FILE),
WATERMARKS(ForgeConstants.SPRITE_WATERMARK_FILE),
CRACKS(ForgeConstants.SPRITE_CRACKS_FILE),
CARDBG(ForgeConstants.SPRITE_CARDBG_FILE),
PLANAR_CONQUEST(ForgeConstants.SPRITE_PLANAR_CONQUEST_FILE);

View File

@@ -9,7 +9,7 @@ import java.util.Map;
import forge.ImageKeys;
import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.*;
import org.apache.commons.lang3.StringUtils;
import com.badlogic.gdx.Gdx;
@@ -57,9 +57,6 @@ import forge.localinstance.properties.ForgePreferences.FPref;
import forge.model.FModel;
import forge.screens.match.MatchController;
import forge.toolbox.FList;
import forge.util.CardTranslation;
import forge.util.TextBounds;
import forge.util.Utils;
public class CardRenderer {
public enum CardStackPosition {
@@ -573,6 +570,7 @@ public class CardRenderer {
boolean canshow = MatchController.instance.mayView(card);
boolean showsleeves = card.isFaceDown() && card.isInZone(EnumSet.of(ZoneType.Exile)); //fix facedown card image ie gonti lord of luxury
Texture image = new RendererCachedCardImage(card, false).getImage( showAltState ? card.getAlternateState().getImageKey() : card.getCurrentState().getImageKey());
TextureRegion crack_overlay = FSkin.getCracks().get(card.getCrackOverlayInt());
FImage sleeves = MatchController.getPlayerSleeve(card.getOwner());
float radius = (h - w)/8;
float croppedArea = isModernFrame(card) ? CROP_MULTIPLIER : 0.97f;
@@ -590,9 +588,9 @@ public class CardRenderer {
g.setAlphaComposite(oldAlpha);
} else if (showsleeves) {
if (!card.isForeTold())
g.drawCardImage(sleeves, x, y, w, h, card.wasDestroyed());
g.drawCardImage(sleeves, crack_overlay, x, y, w, h, card.wasDestroyed(), card.getDamage() > 0);
else
g.drawCardImage(image, x, y, w, h, card.wasDestroyed());
g.drawCardImage(image, crack_overlay, x, y, w, h, card.wasDestroyed(), card.getDamage() > 0);
} else {
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_ROTATE_PLANE_OR_PHENOMENON)
&& (card.getCurrentState().isPhenomenon() || card.getCurrentState().isPlane()) && rotate){
@@ -610,19 +608,19 @@ public class CardRenderer {
} else {
if (Forge.enableUIMask.equals("Full") && canshow) {
if (ImageCache.isBorderlessCardArt(image))
g.drawCardImage(image, x, y, w, h, card.wasDestroyed());
g.drawCardImage(image, crack_overlay, x, y, w, h, card.wasDestroyed(), card.getDamage() > 0);
else {
boolean t = (card.getCurrentState().getOriginalColors() != card.getCurrentState().getColors()) || card.getCurrentState().hasChangeColors();
g.drawBorderImage(ImageCache.getBorderImage(image.toString(), canshow), ImageCache.borderColor(image), ImageCache.getTint(card, image), x, y, w, h, t); //tint check for changed colors
g.drawCardImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea, card.wasDestroyed());
g.drawCardImage(ImageCache.croppedBorderImage(image), crack_overlay, x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea, card.wasDestroyed(), card.getDamage() > 0);
}
} else if (Forge.enableUIMask.equals("Crop") && canshow) {
g.drawCardImage(ImageCache.croppedBorderImage(image), x, y, w, h, card.wasDestroyed());
g.drawCardImage(ImageCache.croppedBorderImage(image), crack_overlay, x, y, w, h, card.wasDestroyed(), card.getDamage() > 0);
} else {
if (canshow)
g.drawCardImage(image, x, y, w, h, card.wasDestroyed());
g.drawCardImage(image, crack_overlay, x, y, w, h, card.wasDestroyed(), card.getDamage() > 0);
else // draw card back sleeves
g.drawCardImage(sleeves, x, y, w, h, card.wasDestroyed());
g.drawCardImage(sleeves, crack_overlay, x, y, w, h, card.wasDestroyed(), card.getDamage() > 0);
}
}
}

View File

@@ -580,7 +580,7 @@ public class MatchScreen extends FScreen {
}
private class BGAnimation extends ForgeAnimation {
private static final float DURATION = 0.2f;
private static final float DURATION = 1.5f;
private float progress = 0;
private boolean finished;
@@ -593,7 +593,7 @@ public class MatchScreen extends FScreen {
percentage = 1;
}
g.setAlphaComposite(percentage);
g.drawImage(image, x, y, w, h, darkoverlay);
g.drawGrayTransitionImage(image, x, y, w, h, darkoverlay, 1-(percentage*1));
g.setAlphaComposite(oldAlpha);
}
@@ -643,7 +643,7 @@ public class MatchScreen extends FScreen {
bgFullWidth = w;
bgHeight = scaledbgHeight;
}
if (bgAnimation != null && !isGameFast) {
if (bgAnimation != null && !isGameFast && !MatchController.instance.getGameView().isMatchOver()) {
bgAnimation.drawBackground(g, FSkinTexture.valueOf(imageName), x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, true);
} else {
g.drawImage(FSkinTexture.valueOf(imageName), x + (w - bgFullWidth) / 2, y, bgFullWidth, bgHeight, true);

View File

@@ -43,7 +43,7 @@ public class VAvatar extends FDisplayObject {
private static final float DURATION = 0.6f;
private float progress = 0;
private boolean finished;
Texture scratch = FSkin.scratch;
Texture splatter = FSkin.splatter;
private void drawAvatar(Graphics g, FImage image, float x, float y, float w, float h) {
float percentage = progress / DURATION;
@@ -55,14 +55,14 @@ public class VAvatar extends FDisplayObject {
player.setAvatarWasDamaged(false);
}
float mod = w/2f;
if (scratch == null) {
if (splatter == null) {
g.setColorRGBA(1, percentage, percentage, g.getfloatAlphaComposite());
g.drawAvatarImage(image, x, y, w, h, player.getHasLost());
g.resetColorRGBA(g.getfloatAlphaComposite());
} else {
g.drawAvatarImage(image, x, y, w, h, player.getHasLost());
g.setAlphaComposite(1-(percentage*1));
g.drawImage(scratch, x-mod/2, y-mod/2, w+mod, h+mod);
g.drawImage(splatter, x-mod/2, y-mod/2, w+mod, h+mod);
g.resetAlphaComposite();
}

View File

@@ -371,7 +371,7 @@ public class VPlayerPanel extends FContainer {
if (!Forge.altZoneTabs)
field.setFieldModifier(0);
else
field.setFieldModifier(avatarWidth);
field.setFieldModifier(avatarWidth/16);
}
@Override
@@ -546,6 +546,12 @@ public class VPlayerPanel extends FContainer {
public void draw(Graphics g) {
float x, y, w, h;
if (Forge.altZoneTabs) {
//draw extra
if (isAltZoneDisplay(this) && selectedTab == this) {
g.fillRect(DISPLAY_AREA_BACK_COLOR, 0, isFlipped() ? INFO_TAB_PADDING_Y : 0, getWidth(), getHeight() - INFO_TAB_PADDING_Y);
}
}
if (selectedTab == this) {
y = 0;
w = getWidth();

View File

@@ -92,7 +92,7 @@ public class FCardPanel extends FDisplayObject {
private static final float DURATION = 0.6f;
private float progress = 0;
private boolean finished;
private Texture scratch = FSkin.scratch;
private Texture splatter = FSkin.splatter;
private void drawCard(Graphics g, CardView card, float x, float y, float w, float h, float edgeOffset) {
float percentage = progress / DURATION;
@@ -107,9 +107,9 @@ public class FCardPanel extends FDisplayObject {
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
}
CardRenderer.drawCardWithOverlays(g, card, x-mod/2, y-mod/2, w+mod, h+mod, getStackPosition());
if (scratch != null) {
if (splatter != null) {
g.setAlphaComposite(0.6f);
g.drawCardImage(scratch, x-mod/2, y-mod/2, w+mod, h+mod, true);
g.drawCardImage(splatter, null,x-mod/2, y-mod/2, w+mod, h+mod, true, false);
g.setAlphaComposite(oldAlpha);
}
if (tapped) {
@@ -230,7 +230,6 @@ public class FCardPanel extends FDisplayObject {
if (tapped) {
g.endTransform();
}
} else {
if (tapped) {
//reset untapAnimation

View File

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 KiB

View File

@@ -117,6 +117,7 @@ public final class ForgeConstants {
public static final String SPRITE_START_FILE = "sprite_start.png";
public static final String SPRITE_MANAICONS_FILE = "sprite_manaicons.png";
public static final String SPRITE_AVATARS_FILE = "sprite_avatars.png";
public static final String SPRITE_CRACKS_FILE = "sprite_cracks.png";
public static final String SPRITE_SLEEVES_FILE = "sprite_sleeves.png";
public static final String SPRITE_SLEEVES2_FILE = "sprite_sleeves2.png";
public static final String SPRITE_FAVICONS_FILE = "sprite_favicons.png";