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
This commit is contained in:
Collin Smith 2019-03-05 01:55:39 -08:00
parent 6e341253c7
commit f4f1924343
5 changed files with 71 additions and 24 deletions

View File

@ -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() {

View File

@ -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);
}

View File

@ -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

View File

@ -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;

View File

@ -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();