From f4f192434365c2d751780e243255fcc79ad94ddd Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Tue, 5 Mar 2019 01:55:39 -0800 Subject: [PATCH] Added support for COF layer transforms Added support for COF layer transforms (transparency, luminance blending, etc) Added tint to Animation.Layer Refactored Animation API a bit to make common use-case easier Refactored colors order, added transparency colors --- core/src/gdx/diablo/Colors.java | 36 +++++++------ core/src/gdx/diablo/codec/Animation.java | 50 +++++++++++++++++-- core/src/gdx/diablo/entity/Entity.java | 4 +- core/src/gdx/diablo/screen/GameScreen.java | 2 +- .../gdx/diablo/widget/CharacterPreview.java | 3 +- 5 files changed, 71 insertions(+), 24 deletions(-) diff --git a/core/src/gdx/diablo/Colors.java b/core/src/gdx/diablo/Colors.java index 25da630d..74954069 100644 --- a/core/src/gdx/diablo/Colors.java +++ b/core/src/gdx/diablo/Colors.java @@ -18,27 +18,33 @@ public class Colors { public static final Color PURPLE = new Color(0xAE00FFFF); // 11 #AE00FF public static final Color C12 = new Color(0x00C800FF); // 12 #00C800 - public Color white = WHITE.cpy(); - public Color red = RED.cpy(); - public Color green = GREEN.cpy(); - public Color blue = BLUE.cpy(); - public Color gold = GOLD.cpy(); - public Color grey = GREY.cpy(); - public Color black = BLACK.cpy(); - public Color c7 = C7.cpy(); - public Color orange = ORANGE.cpy(); - public Color yellow = YELLOW.cpy(); - public Color c10 = C10.cpy(); - public Color purple = PURPLE.cpy(); - public Color c12 = C12.cpy(); - public Color modal50 = new Color(0, 0, 0, 0.50f); - public Color modal75 = new Color(0, 0, 0, 0.75f); + public Color white = WHITE.cpy(); + public Color red = RED.cpy(); + public Color green = GREEN.cpy(); + public Color blue = BLUE.cpy(); + public Color gold = GOLD.cpy(); + public Color grey = GREY.cpy(); + public Color black = BLACK.cpy(); + public Color c7 = C7.cpy(); + public Color orange = ORANGE.cpy(); + public Color yellow = YELLOW.cpy(); + public Color c10 = C10.cpy(); + public Color purple = PURPLE.cpy(); + public Color c12 = C12.cpy(); public Color invBlue = new Color(0.1f, 0.1f, 0.5f, 0.3f); public Color invGreen = new Color(0.1f, 0.5f, 0.1f, 0.3f); public Color invRed = new Color(0.5f, 0.1f, 0.1f, 0.3f); public Color invWhite = new Color(0.5f, 0.5f, 0.5f, 0.3f); + public Color modal25 = new Color(0, 0, 0, 0.25f); + public Color modal50 = new Color(0, 0, 0, 0.50f); + public Color modal75 = new Color(0, 0, 0, 0.75f); + + public Color trans25 = new Color(1, 1, 1, 0.25f); + public Color trans50 = new Color(1, 1, 1, 0.50f); + public Color trans75 = new Color(1, 1, 1, 0.75f); + public Colors() {} public void load() { diff --git a/core/src/gdx/diablo/codec/Animation.java b/core/src/gdx/diablo/codec/Animation.java index 37dc7c43..d9a43780 100644 --- a/core/src/gdx/diablo/codec/Animation.java +++ b/core/src/gdx/diablo/codec/Animation.java @@ -117,6 +117,41 @@ public class Animation extends BaseDrawable { return this; } + public Layer setLayer(COF.Layer cofLayer, DC dc, boolean updateBox) { + setLayer(cofLayer.component, dc, updateBox); + Layer layer = layers[cofLayer.component]; + if (layer != null && cofLayer.overrideTransLvl != 0) { + applyTransform(layer, cofLayer.newTransLvl & 0xFF); + } + + return layer; + } + + private void applyTransform(Layer layer, int transform) { + switch (transform) { + case 0x00: + layer.setBlendMode(layer.blendMode, Diablo.colors.trans75); + break; + case 0x01: + layer.setBlendMode(layer.blendMode, Diablo.colors.trans50); + break; + case 0x02: + layer.setBlendMode(layer.blendMode, Diablo.colors.trans25); + break; + case 0x03: + layer.setBlendMode(BlendMode.LUMINOSITY); + break; + case 0x04: + layer.setBlendMode(BlendMode.LUMINOSITY); // not sure + break; + case 0x06: + layer.setBlendMode(BlendMode.LUMINOSITY); // not sure + break; + default: + Gdx.app.error(TAG, "Unknown transform: " + transform); + } + } + public Layer getLayer(int component) { return layers[component]; } @@ -246,11 +281,11 @@ public class Animation extends BaseDrawable { int f = frame; // TODO: Layer blend modes should correspond with the cof trans levels for (int l = 0; l < cof.getNumLayers(); l++) { - //COF.Layer cofLayer = cof.getLayer(l); - //if (cofLayer.overrideTransLvl != 0) cofLayer.newTransLvl; int component = cof.getLayerOrder(d, f, l); Layer layer = layers[component]; - if (layer != null) drawLayer(batch, layer, x, y); + if (layer != null) { + drawLayer(batch, layer, x, y); + } } batch.resetBlendMode(); batch.resetColormap(); @@ -379,6 +414,7 @@ public class Animation extends BaseDrawable { final int numFrames; int blendMode; + Color tint; Index transform; int transformColor; @@ -389,6 +425,7 @@ public class Animation extends BaseDrawable { Layer(DC dc, int blendMode) { this.dc = dc; this.blendMode = blendMode; + tint = Color.WHITE; numDirections = dc.getNumDirections(); numFrames = dc.getNumFramesPerDir(); regions = new TextureRegion[numDirections][]; @@ -416,7 +453,12 @@ public class Animation extends BaseDrawable { } public void setBlendMode(int blendMode) { + setBlendMode(blendMode, Color.WHITE); + } + + public void setBlendMode(int blendMode, Color tint) { this.blendMode = blendMode; + this.tint = tint; } public void setTransform(Index colormap, int id) { @@ -439,7 +481,7 @@ public class Animation extends BaseDrawable { y -= box.yMax; if (regions[d] == null) load(d); PaletteIndexedBatch b = (PaletteIndexedBatch) batch; - b.setBlendMode(blendMode); + b.setBlendMode(blendMode, tint); b.setColormap(transform, transformColor); b.draw(regions[d][f], x, y); } diff --git a/core/src/gdx/diablo/entity/Entity.java b/core/src/gdx/diablo/entity/Entity.java index 50042a67..c7809d22 100644 --- a/core/src/gdx/diablo/entity/Entity.java +++ b/core/src/gdx/diablo/entity/Entity.java @@ -400,7 +400,7 @@ public class Entity { String weaponClass = layer.weaponClass; path = entType.PATH + type + "\\" + component + "\\" + type + component + armType + mode + weaponClass + ".dcc"; if (armType.isEmpty()) { - animation.setLayer(c, null, false); + animation.setLayer(layer, null, false); continue; } if (DEBUG_DIRTY) Gdx.app.log(TAG, path); @@ -409,7 +409,7 @@ public class Entity { Diablo.assets.load(descriptor); Diablo.assets.finishLoadingAsset(descriptor); DCC dcc = Diablo.assets.get(descriptor); - animation.setLayer(c, dcc, false); + animation.setLayer(layer, dcc, false); /*Runnable loader = new Runnable() { @Override diff --git a/core/src/gdx/diablo/screen/GameScreen.java b/core/src/gdx/diablo/screen/GameScreen.java index 461b4aa8..fd4fc139 100644 --- a/core/src/gdx/diablo/screen/GameScreen.java +++ b/core/src/gdx/diablo/screen/GameScreen.java @@ -70,7 +70,7 @@ import gdx.diablo.widget.TextArea; public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable { private static final String TAG = "GameScreen"; private static final boolean DEBUG = true; - private static final boolean DEBUG_TOUCHPAD = true; + private static final boolean DEBUG_TOUCHPAD = !true; private static final boolean DEBUG_MOBILE = true; private static final boolean DEBUG_HIT = DEBUG && !true; diff --git a/core/src/gdx/diablo/widget/CharacterPreview.java b/core/src/gdx/diablo/widget/CharacterPreview.java index 09c75042..60ee5749 100644 --- a/core/src/gdx/diablo/widget/CharacterPreview.java +++ b/core/src/gdx/diablo/widget/CharacterPreview.java @@ -73,8 +73,7 @@ public class CharacterPreview extends Widget implements Disposable { Diablo.assets.load(assets[i]); Diablo.assets.finishLoadingAsset(assets[i]); DCC dcc = Diablo.assets.get(assets[i].fileName, DCC.class); - anim.setLayer(layer.component, dcc, false); - anim.getLayer(layer.component).setTransform(d2s.colors[layer.component]); + anim.setLayer(layer, dcc, false).setTransform(d2s.colors[layer.component]); } anim.updateBox();