From 174c1cbb53712be65faa4d56f584c212d236cda2 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sat, 23 Mar 2019 02:35:29 -0700 Subject: [PATCH] Added per-component alpha support Added per-component alpha support Added support for drawing equipped ethereal items as partly transparent Cleaned up Animation.Layer API a bit --- core/src/com/riiablo/codec/Animation.java | 22 +++++++++++++++------- core/src/com/riiablo/entity/Entity.java | 16 ++++++++++++++++ core/src/com/riiablo/entity/Player.java | 4 ++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/core/src/com/riiablo/codec/Animation.java b/core/src/com/riiablo/codec/Animation.java index 75bc36a4..67f8cd16 100644 --- a/core/src/com/riiablo/codec/Animation.java +++ b/core/src/com/riiablo/codec/Animation.java @@ -545,26 +545,34 @@ public class Animation extends BaseDrawable { return this; } - public void setBlendMode(int blendMode) { - setBlendMode(blendMode, Color.WHITE); + public Layer setBlendMode(int blendMode) { + return setBlendMode(blendMode, Color.WHITE); } - public void setBlendMode(int blendMode, Color tint) { + public Layer setBlendMode(int blendMode, Color tint) { this.blendMode = blendMode; this.tint = tint; + return this; } - public void setTransform(Index colormap, int id) { + public Layer setAlpha(float a) { + if (tint == Color.WHITE) tint = tint.cpy(); + tint.a = a; + return this; + } + + public Layer setTransform(Index colormap, int id) { transform = colormap; transformColor = colormap == null ? 0 : id; + return this; } - public void setTransform(byte packedTransform) { + public Layer setTransform(byte packedTransform) { int transform = packedTransform & 0xFF; if (transform == 0xFF) { - setTransform(null, 0); + return setTransform(null, 0); } else { - setTransform(Riiablo.colormaps.get(transform >>> 5), transform & 0x1F); + return setTransform(Riiablo.colormaps.get(transform >>> 5), transform & 0x1F); } } diff --git a/core/src/com/riiablo/entity/Entity.java b/core/src/com/riiablo/entity/Entity.java index 5ea7ba57..b0a9c71d 100644 --- a/core/src/com/riiablo/entity/Entity.java +++ b/core/src/com/riiablo/entity/Entity.java @@ -211,6 +211,11 @@ public abstract class Entity implements Animation.AnimationListener { DEFAULT_TRANS = new byte[COF.Component.NUM_COMPONENTS]; Arrays.fill(DEFAULT_TRANS, (byte) 0xFF); } + private static final float[] DEFAULT_ALPHA; + static { + DEFAULT_ALPHA = new float[COF.Component.NUM_COMPONENTS]; + Arrays.fill(DEFAULT_ALPHA, 1.0f); + } String classname; Type type; @@ -223,6 +228,7 @@ public abstract class Entity implements Animation.AnimationListener { String cof; byte comp[]; byte trans[]; // TODO: Could also assign DEFAULT_TRANS and lazy change + float alpha[]; float angle = DEFAULT_ANGLE; Vector2 position = new Vector2(); @@ -272,6 +278,7 @@ public abstract class Entity implements Animation.AnimationListener { wclass = WEAPON_HTH; comp = components; trans = transforms; + alpha = DEFAULT_ALPHA.clone(); invalidate(); // TODO: lazy init @@ -329,6 +336,14 @@ public abstract class Entity implements Animation.AnimationListener { } } + public void setAlpha(byte component, float a) { + if (alpha[component] != a) { + if (DEBUG_STATE) Gdx.app.debug(TAG, classname + " alpha: " + alpha[component] + " -> " + a); + alpha[component] = a; + if (animation != null) animation.getLayer(component).setAlpha(a); + } + } + public final void invalidate() { dirty = Dirty.ALL; } @@ -383,6 +398,7 @@ public abstract class Entity implements Animation.AnimationListener { DCC dcc = Riiablo.assets.get(descriptor); animation.setLayer(layer, dcc, false) .setTransform(trans[layer.component]) + .setAlpha(alpha[layer.component]) ; // FIXME: colors don't look right for sorc Tirant circlet changing hair color // putting a ruby in a white circlet not change color on item or character diff --git a/core/src/com/riiablo/entity/Player.java b/core/src/com/riiablo/entity/Player.java index ab7eda03..7ca300cb 100644 --- a/core/src/com/riiablo/entity/Player.java +++ b/core/src/com/riiablo/entity/Player.java @@ -322,6 +322,10 @@ public class Player extends Entity { setComponent(COF.Component.RH, RH != null ? (byte) Type.PLR.getComponent(RH.base.alternateGfx) : 0); setComponent(COF.Component.LH, LH != null ? (byte) Type.PLR.getComponent(LH.base.alternateGfx) : 0); setComponent(COF.Component.SH, SH != null ? (byte) Type.PLR.getComponent(SH.base.alternateGfx) : 0); + + setAlpha(COF.Component.RH, RH != null && RH.isEthereal() ? Item.ETHEREAL_ALPHA : 1.0f); + setAlpha(COF.Component.LH, LH != null && LH.isEthereal() ? Item.ETHEREAL_ALPHA : 1.0f); + setAlpha(COF.Component.SH, SH != null && SH.isEthereal() ? Item.ETHEREAL_ALPHA : 1.0f); } public Item getSlot(Slot slot) {