mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-19 16:57:20 +07:00
Added basic entity cursor focusing
Added basic entity cursor focusing using backing animation bounds and MapRenderer Added background drawable support to Label widget Improved ColorDrawable padding calculations such that min width/height is a sum of respective padding Disabled some mouse debugging features in MapRenderer
This commit is contained in:
parent
247e62ff2b
commit
3829c34c24
@ -32,6 +32,7 @@ public class Colors {
|
||||
public Color purple = PURPLE.cpy();
|
||||
public Color c12 = C12.cpy();
|
||||
public Color modal = black.cpy().sub(0, 0, 0, 0.5f);
|
||||
public Color modal2 = black.cpy().sub(0, 0, 0, 0.25f);
|
||||
|
||||
public Colors() {}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import gdx.diablo.codec.Animation;
|
||||
import gdx.diablo.codec.COF;
|
||||
import gdx.diablo.codec.COFD2;
|
||||
import gdx.diablo.codec.DCC;
|
||||
import gdx.diablo.codec.util.BBox;
|
||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||
import gdx.diablo.map.DS1;
|
||||
import gdx.diablo.map.DT1.Tile;
|
||||
@ -117,6 +118,7 @@ public class Entity {
|
||||
float angle = MathUtils.PI * 3 / 2;
|
||||
|
||||
Animation animation;
|
||||
public boolean over = true;
|
||||
|
||||
public static Entity create(DS1 ds1, DS1.Object obj) {
|
||||
final int type = obj.type;
|
||||
@ -342,12 +344,24 @@ public class Entity {
|
||||
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50);
|
||||
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50);
|
||||
animation.draw(batch, x, y);
|
||||
if (over) drawLabel(batch);
|
||||
}
|
||||
|
||||
public void drawLabel(PaletteIndexedBatch batch) {}
|
||||
|
||||
public boolean move() {
|
||||
int x = Direction.getOffX(angle);
|
||||
int y = Direction.getOffY(angle);
|
||||
position.add(x, y, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean contains(Vector3 coords) {
|
||||
if (animation == null) return false;
|
||||
BBox box = animation.getBox();
|
||||
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50) - (box.width / 2);
|
||||
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50) - box.yMax;
|
||||
return x <= coords.x && coords.x <= x + box.width
|
||||
&& y <= coords.y && coords.y <= y + box.height;
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,18 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import gdx.diablo.Diablo;
|
||||
import gdx.diablo.codec.excel.MonStats;
|
||||
import gdx.diablo.codec.excel.MonStats2;
|
||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||
import gdx.diablo.graphics.PaletteIndexedColorDrawable;
|
||||
import gdx.diablo.map.DS1;
|
||||
import gdx.diablo.map.DT1.Tile;
|
||||
import gdx.diablo.widget.Label;
|
||||
|
||||
public class Monster extends Entity {
|
||||
private static final String TAG = "Monster";
|
||||
@ -20,6 +24,8 @@ public class Monster extends Entity {
|
||||
MonStats.Entry monstats;
|
||||
MonStats2.Entry monstats2;
|
||||
|
||||
Label label;
|
||||
|
||||
public Monster(DS1.Object object, MonStats.Entry monstats) {
|
||||
super(monstats.Code, EntType.MONSTER);
|
||||
this.object = object;
|
||||
@ -35,6 +41,15 @@ public class Monster extends Entity {
|
||||
setArmType(Component.valueOf(i), v[random]);
|
||||
}
|
||||
}
|
||||
|
||||
label = new Label(monstats.NameStr, Diablo.fonts.font16);
|
||||
label.getStyle().background = new PaletteIndexedColorDrawable(Diablo.colors.modal2) {{
|
||||
final float padding = 3;
|
||||
setLeftWidth(padding);
|
||||
setTopHeight(padding);
|
||||
setRightWidth(padding);
|
||||
setBottomHeight(padding);
|
||||
}};
|
||||
}
|
||||
|
||||
public static Monster create(DS1 ds1, DS1.Object obj) {
|
||||
@ -88,4 +103,20 @@ public class Monster extends Entity {
|
||||
shapes.rect(p1x - HALF_BOX, p1y - HALF_BOX, BOX_SIZE, BOX_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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 + monstats2.pixHeight/*animation.getMinHeight() + label.getHeight()*/, Align.center);
|
||||
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.modal);
|
||||
//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());
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,6 @@ public class PaletteIndexedBatch extends SpriteBatch {
|
||||
setColor(Color.WHITE);
|
||||
}
|
||||
|
||||
|
||||
public float getGamma() {
|
||||
return gamma;
|
||||
}
|
||||
|
@ -16,6 +16,30 @@ public class PaletteIndexedColorDrawable extends TextureRegionDrawable {
|
||||
this.tint = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeftWidth(float leftWidth) {
|
||||
super.setLeftWidth(leftWidth);
|
||||
setMinWidth(getLeftWidth() + getRightWidth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRightWidth(float rightWidth) {
|
||||
super.setRightWidth(rightWidth);
|
||||
setMinWidth(getLeftWidth() + getRightWidth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopHeight(float topHeight) {
|
||||
super.setTopHeight(topHeight);
|
||||
setMinHeight(getTopHeight() + getBottomHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottomHeight(float bottomHeight) {
|
||||
super.setBottomHeight(bottomHeight);
|
||||
setMinHeight(getTopHeight() + getBottomHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float x, float y, float width, float height) {
|
||||
if (!(batch instanceof PaletteIndexedBatch)) {
|
||||
|
@ -102,6 +102,41 @@ public class MapRenderer {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public Entity hit() {
|
||||
Vector3 coords = new Vector3();
|
||||
coords.set(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
camera.unproject(coords);
|
||||
float adjustX = (int) coords.x;
|
||||
float adjustY = (int) coords.y - Tile.SUBTILE_HEIGHT50;
|
||||
|
||||
float selectX = ( adjustX / Tile.SUBTILE_WIDTH50 - adjustY / Tile.SUBTILE_HEIGHT50) / 2;
|
||||
float selectY = (-adjustX / Tile.SUBTILE_WIDTH50 - adjustY / Tile.SUBTILE_HEIGHT50) / 2;
|
||||
if (selectX < 0) selectX--;
|
||||
if (selectY < 0) selectY--;
|
||||
|
||||
int mx = -Tile.SUBTILE_WIDTH50 + ((int)selectX * Tile.SUBTILE_WIDTH50) - ((int)selectY * Tile.SUBTILE_WIDTH50);
|
||||
int my = -Tile.SUBTILE_HEIGHT50 - ((int)selectX * Tile.SUBTILE_HEIGHT50) - ((int)selectY * Tile.SUBTILE_HEIGHT50);
|
||||
|
||||
Map.Zone zone = map.getZone((int) selectX, (int) selectY);
|
||||
if (zone != null) {
|
||||
for (Entity entity : zone.entities) {
|
||||
entity.over = entity.contains(coords);
|
||||
/*Vector3 position = entity.position();
|
||||
float x = +(position.x * Tile.SUBTILE_WIDTH50) - (position.y * Tile.SUBTILE_WIDTH50);
|
||||
float y = -(position.x * Tile.SUBTILE_HEIGHT50) - (position.y * Tile.SUBTILE_HEIGHT50);
|
||||
if (x < coords.x && coords.x < x + 50
|
||||
&& y < coords.y && coords.y < y + 50) {
|
||||
entity.over = true;
|
||||
return entity;
|
||||
} else {
|
||||
entity.over = false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setMap(Map map) {
|
||||
if (this.map != map) {
|
||||
this.map = map;
|
||||
@ -251,12 +286,12 @@ public class MapRenderer {
|
||||
case Map.FLOOR_OFFSET: case Map.FLOOR_OFFSET + 1:
|
||||
//drawWalls(batch, tile, px, py, false);
|
||||
drawFloor(batch, tile, px, py);
|
||||
break;
|
||||
case Map.SHADOW_OFFSET:
|
||||
//batch.setBlendMode(BlendMode.SHADOW, SHADOW_TINT);
|
||||
//drawShadows(batch, tx, ty, px, py);
|
||||
//batch.resetBlendMode();
|
||||
break;
|
||||
case Map.SHADOW_OFFSET:
|
||||
break;
|
||||
case Map.WALL_OFFSET:
|
||||
drawEntities(batch, stx, sty);
|
||||
drawObjects(batch, zone, stx, sty);
|
||||
@ -411,17 +446,17 @@ public class MapRenderer {
|
||||
int mx = -Tile.SUBTILE_WIDTH50 + ((int)selectX * Tile.SUBTILE_WIDTH50) - ((int)selectY * Tile.SUBTILE_WIDTH50);
|
||||
int my = -Tile.SUBTILE_HEIGHT50 - ((int)selectX * Tile.SUBTILE_HEIGHT50) - ((int)selectY * Tile.SUBTILE_HEIGHT50);
|
||||
|
||||
shapes.end();
|
||||
batch.begin();
|
||||
batch.setShader(null);
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
Diablo.fonts.consolas16.draw(batch,
|
||||
String.format("%3.0f,%3.0f%n%3.0f,%3.0f%n%3.0f,%3.0f%n%3d,%3d",
|
||||
coords.x, coords.y, adjustX, adjustY, selectX, selectY, mx + Tile.SUBTILE_WIDTH50, my + Tile.SUBTILE_HEIGHT50),
|
||||
coords.x + 10, coords.y - 10);
|
||||
batch.end();
|
||||
batch.getProjectionMatrix().idt();
|
||||
shapes.begin();
|
||||
//shapes.end();
|
||||
//batch.begin();
|
||||
//batch.setShader(null);
|
||||
//batch.setProjectionMatrix(camera.combined);
|
||||
//Diablo.fonts.consolas16.draw(batch,
|
||||
// String.format("%3.0f,%3.0f%n%3.0f,%3.0f%n%3.0f,%3.0f%n%3d,%3d",
|
||||
// coords.x, coords.y, adjustX, adjustY, selectX, selectY, mx + Tile.SUBTILE_WIDTH50, my + Tile.SUBTILE_HEIGHT50),
|
||||
// coords.x + 10, coords.y - 10);
|
||||
//batch.end();
|
||||
//batch.getProjectionMatrix().idt();
|
||||
//shapes.begin();
|
||||
shapes.setColor(Color.VIOLET);
|
||||
drawDiamond(shapes, mx, my, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
|
||||
import gdx.diablo.Diablo;
|
||||
@ -40,6 +41,17 @@ public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label {
|
||||
public void draw(PaletteIndexedBatch batch, float a) {
|
||||
validate();
|
||||
|
||||
LabelStyle style = getStyle();
|
||||
if (style != null) {
|
||||
Drawable background = style.background;
|
||||
if (background != null) {
|
||||
// TODO: background.getLeftWidth() looks like it shifts background.getMinWidth() -- bug?
|
||||
background.draw(batch,
|
||||
getX() /*- background.getLeftWidth()*/, getY() - background.getBottomHeight(),
|
||||
getWidth() + background.getMinWidth(), getHeight() + background.getMinHeight());
|
||||
}
|
||||
}
|
||||
|
||||
batch.setBlendMode(((FontTBL.BitmapFont) getStyle().font).getBlendMode());
|
||||
BitmapFontCache cache = getBitmapFontCache();
|
||||
cache.setPosition(getX(), getY());
|
||||
|
@ -20,10 +20,12 @@ import com.badlogic.gdx.scenes.scene2d.utils.UIUtils;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
|
||||
import gdx.diablo.COFs;
|
||||
import gdx.diablo.Colors;
|
||||
import gdx.diablo.Diablo;
|
||||
import gdx.diablo.Files;
|
||||
import gdx.diablo.Fonts;
|
||||
import gdx.diablo.Palettes;
|
||||
import gdx.diablo.Textures;
|
||||
import gdx.diablo.codec.COF;
|
||||
import gdx.diablo.codec.DC6;
|
||||
import gdx.diablo.codec.DCC;
|
||||
@ -98,6 +100,8 @@ public class MapViewer extends ApplicationAdapter {
|
||||
|
||||
Diablo.files = new Files(assets);
|
||||
Diablo.fonts = new Fonts(assets);
|
||||
Diablo.colors = new Colors();
|
||||
Diablo.textures = new Textures();
|
||||
Diablo.cofs = new COFs(assets);//COFD2.loadFromFile(resolver.resolve("data\\global\\cmncof_a1.d2"));
|
||||
|
||||
TXT txt = TXT.loadFromFile(Gdx.files.local("data/ds1types.txt"));
|
||||
@ -298,12 +302,15 @@ public class MapViewer extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
Gdx.app.debug(TAG, "JAVA: " + Gdx.app.getJavaHeap() + " Bytes; NATIVE: " + Gdx.app.getNativeHeap() + " Bytes");
|
||||
Diablo.batch.setGamma(1.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
mapRenderer.hit();
|
||||
|
||||
PaletteIndexedBatch batch = Diablo.batch;
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
batch.begin(palette);
|
||||
@ -351,6 +358,7 @@ public class MapViewer extends ApplicationAdapter {
|
||||
font.dispose();
|
||||
shapes.dispose();
|
||||
palette.dispose();
|
||||
Diablo.textures.dispose();
|
||||
Diablo.assets.dispose();
|
||||
Diablo.batch.dispose();
|
||||
Diablo.shader.dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user