mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-13 01:07:43 +07:00
Added support for StaticEntity labels
Added support for StaticEntity labels Refactored entity labels/names into Entity class -- needs optimization Fixed issue where changing Label text wouldn't resize Label itself Fixed issue where left padding on Label background Drawable was ignored
This commit is contained in:
@ -9,8 +9,10 @@ import com.badlogic.gdx.graphics.g2d.Batch;
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.utils.Align;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -21,8 +23,10 @@ import gdx.diablo.codec.COFD2;
|
|||||||
import gdx.diablo.codec.DCC;
|
import gdx.diablo.codec.DCC;
|
||||||
import gdx.diablo.codec.util.BBox;
|
import gdx.diablo.codec.util.BBox;
|
||||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||||
|
import gdx.diablo.graphics.PaletteIndexedColorDrawable;
|
||||||
import gdx.diablo.map.DS1;
|
import gdx.diablo.map.DS1;
|
||||||
import gdx.diablo.map.DT1.Tile;
|
import gdx.diablo.map.DT1.Tile;
|
||||||
|
import gdx.diablo.widget.Label;
|
||||||
|
|
||||||
public class Entity {
|
public class Entity {
|
||||||
private static final String TAG = "Entity";
|
private static final String TAG = "Entity";
|
||||||
@ -119,6 +123,8 @@ public class Entity {
|
|||||||
|
|
||||||
Animation animation;
|
Animation animation;
|
||||||
public boolean over = true;
|
public boolean over = true;
|
||||||
|
Label label;
|
||||||
|
String name;
|
||||||
|
|
||||||
public static Entity create(DS1 ds1, DS1.Object obj) {
|
public static Entity create(DS1 ds1, DS1.Object obj) {
|
||||||
final int type = obj.type;
|
final int type = obj.type;
|
||||||
@ -143,6 +149,16 @@ public class Entity {
|
|||||||
weaponClass = "HTH";
|
weaponClass = "HTH";
|
||||||
layers = DEFAULT_LAYERS;
|
layers = DEFAULT_LAYERS;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
|
// TODO: LabelStyle should be made static
|
||||||
|
label = new Label(Diablo.fonts.font16);
|
||||||
|
label.getStyle().background = new PaletteIndexedColorDrawable(Diablo.colors.modal75) {{
|
||||||
|
final float padding = 2;
|
||||||
|
setLeftWidth(padding);
|
||||||
|
setTopHeight(padding);
|
||||||
|
setRightWidth(padding);
|
||||||
|
setBottomHeight(padding);
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMode(String mode) {
|
public void setMode(String mode) {
|
||||||
@ -347,7 +363,13 @@ public class Entity {
|
|||||||
if (over) drawLabel(batch);
|
if (over) drawLabel(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawLabel(PaletteIndexedBatch batch) {}
|
public void drawLabel(PaletteIndexedBatch batch) {
|
||||||
|
if (label.getText().length == 0) return;
|
||||||
|
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50);
|
||||||
|
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50);
|
||||||
|
label.setPosition(x, y + animation.getMinHeight() + label.getHeight(), Align.center);
|
||||||
|
label.draw(batch, 1);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean move() {
|
public boolean move() {
|
||||||
int x = Direction.getOffX(angle);
|
int x = Direction.getOffX(angle);
|
||||||
@ -364,4 +386,14 @@ public class Entity {
|
|||||||
return x <= coords.x && coords.x <= x + box.width
|
return x <= coords.x && coords.x <= x + box.width
|
||||||
&& y <= coords.y && coords.y <= y + box.height;
|
&& y <= coords.y && coords.y <= y + box.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
if (!StringUtils.equalsIgnoreCase(this.name, name)) {
|
||||||
|
label.setText(this.name = name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,8 @@ import gdx.diablo.Diablo;
|
|||||||
import gdx.diablo.codec.excel.MonStats;
|
import gdx.diablo.codec.excel.MonStats;
|
||||||
import gdx.diablo.codec.excel.MonStats2;
|
import gdx.diablo.codec.excel.MonStats2;
|
||||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||||
import gdx.diablo.graphics.PaletteIndexedColorDrawable;
|
|
||||||
import gdx.diablo.map.DS1;
|
import gdx.diablo.map.DS1;
|
||||||
import gdx.diablo.map.DT1.Tile;
|
import gdx.diablo.map.DT1.Tile;
|
||||||
import gdx.diablo.widget.Label;
|
|
||||||
|
|
||||||
public class Monster extends Entity {
|
public class Monster extends Entity {
|
||||||
private static final String TAG = "Monster";
|
private static final String TAG = "Monster";
|
||||||
@ -25,13 +23,12 @@ public class Monster extends Entity {
|
|||||||
MonStats.Entry monstats;
|
MonStats.Entry monstats;
|
||||||
MonStats2.Entry monstats2;
|
MonStats2.Entry monstats2;
|
||||||
|
|
||||||
Label label;
|
|
||||||
|
|
||||||
public Monster(DS1.Object object, MonStats.Entry monstats) {
|
public Monster(DS1.Object object, MonStats.Entry monstats) {
|
||||||
super(monstats.Code, EntType.MONSTER);
|
super(monstats.Code, EntType.MONSTER);
|
||||||
this.object = object;
|
this.object = object;
|
||||||
this.monstats = monstats;
|
this.monstats = monstats;
|
||||||
this.monstats2 = Diablo.files.monstats2.get(monstats.MonStatsEx);
|
this.monstats2 = Diablo.files.monstats2.get(monstats.MonStatsEx);
|
||||||
|
setName(monstats.NameStr);
|
||||||
setWeaponClass(monstats2.BaseW);
|
setWeaponClass(monstats2.BaseW);
|
||||||
setMode(monstats.spawnmode.isEmpty() ? "NU" : monstats.spawnmode);
|
setMode(monstats.spawnmode.isEmpty() ? "NU" : monstats.spawnmode);
|
||||||
for (int i = 0; i < monstats2.ComponentV.length; i++) {
|
for (int i = 0; i < monstats2.ComponentV.length; i++) {
|
||||||
@ -42,15 +39,6 @@ public class Monster extends Entity {
|
|||||||
setArmType(Component.valueOf(i), v[random]);
|
setArmType(Component.valueOf(i), v[random]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
label = new Label(monstats.NameStr, Diablo.fonts.font16);
|
|
||||||
label.getStyle().background = new PaletteIndexedColorDrawable(Diablo.colors.modal75) {{
|
|
||||||
final float padding = 3;
|
|
||||||
setLeftWidth(padding);
|
|
||||||
setTopHeight(padding);
|
|
||||||
setRightWidth(padding);
|
|
||||||
setBottomHeight(padding);
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Monster create(DS1 ds1, DS1.Object obj) {
|
public static Monster create(DS1 ds1, DS1.Object obj) {
|
||||||
@ -109,16 +97,8 @@ public class Monster extends Entity {
|
|||||||
public void drawLabel(PaletteIndexedBatch batch) {
|
public void drawLabel(PaletteIndexedBatch batch) {
|
||||||
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50);
|
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50);
|
||||||
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50);
|
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50);
|
||||||
label.setPosition(x, y + monstats2.pixHeight/*animation.getMinHeight() + label.getHeight()*/, Align.center);
|
label.setPosition(x, y + monstats2.pixHeight + label.getHeight(), Align.center);
|
||||||
label.draw(batch, 1);
|
label.draw(batch, 1);
|
||||||
//BitmapFont font = Diablo.fonts.font16;
|
|
||||||
//GlyphLayout glyphs = new GlyphLayout(font, "Test", font.getColor(), 0, Align.center, false);
|
|
||||||
|
|
||||||
//batch.setBlendMode(BlendMode.SOLID, Diablo.colors.modal50);
|
|
||||||
//batch.draw(Diablo.textures.white, x - glyphs.width / 2, y + animation.getMinHeight(), glyphs.width, glyphs.height);
|
|
||||||
//batch.resetBlendMode();
|
|
||||||
|
|
||||||
//font.draw(batch, glyphs, x, y + animation.getMinHeight() + font.getLineHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package gdx.diablo.entity;
|
package gdx.diablo.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.utils.Align;
|
||||||
|
|
||||||
import gdx.diablo.Diablo;
|
import gdx.diablo.Diablo;
|
||||||
import gdx.diablo.codec.excel.Objects;
|
import gdx.diablo.codec.excel.Objects;
|
||||||
|
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||||
import gdx.diablo.map.DS1;
|
import gdx.diablo.map.DS1;
|
||||||
|
import gdx.diablo.map.DT1.Tile;
|
||||||
|
|
||||||
public class StaticEntity extends Entity {
|
public class StaticEntity extends Entity {
|
||||||
private static final String TAG = "StaticEntity";
|
private static final String TAG = "StaticEntity";
|
||||||
@ -16,6 +20,7 @@ public class StaticEntity extends Entity {
|
|||||||
super(base.Token, EntType.OBJECT);
|
super(base.Token, EntType.OBJECT);
|
||||||
this.object = object;
|
this.object = object;
|
||||||
this.base = base;
|
this.base = base;
|
||||||
|
setName(base.Name);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +44,19 @@ public class StaticEntity extends Entity {
|
|||||||
animation.setFrameDelta(base.FrameDelta[mode]); // FIXME: anim framedelta looks too quick
|
animation.setFrameDelta(base.FrameDelta[mode]); // FIXME: anim framedelta looks too quick
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
@Override
|
||||||
return base == null ? toString() : base.Name + "(" + base.Id + ")";
|
public void drawLabel(PaletteIndexedBatch batch) {
|
||||||
|
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50);
|
||||||
|
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50);
|
||||||
|
label.setPosition(x, y - base.NameOffset + label.getHeight(), Align.center);
|
||||||
|
label.draw(batch, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Vector3 coords) {
|
||||||
|
int mode = Diablo.files.ObjMode.index(this.mode);
|
||||||
|
if (!base.Selectable[mode]) return false;
|
||||||
|
return super.contains(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
@ -45,9 +45,8 @@ public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label {
|
|||||||
if (style != null) {
|
if (style != null) {
|
||||||
Drawable background = style.background;
|
Drawable background = style.background;
|
||||||
if (background != null) {
|
if (background != null) {
|
||||||
// TODO: background.getLeftWidth() looks like it shifts background.getMinWidth() -- bug?
|
|
||||||
background.draw(batch,
|
background.draw(batch,
|
||||||
getX() /*- background.getLeftWidth()*/, getY() - background.getBottomHeight(),
|
getX() - background.getLeftWidth(), getY() - background.getBottomHeight(),
|
||||||
getWidth() + background.getMinWidth(), getHeight() + background.getMinHeight());
|
getWidth() + background.getMinWidth(), getHeight() + background.getMinHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,4 +64,10 @@ public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label {
|
|||||||
setText(id == -1 ? "" : Diablo.string.lookup(id));
|
setText(id == -1 ? "" : Diablo.string.lookup(id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setText(CharSequence newText) {
|
||||||
|
super.setText(newText);
|
||||||
|
setSize(getPrefWidth(), getPrefHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user