diff --git a/core/src/gdx/diablo/entity/Entity.java b/core/src/gdx/diablo/entity/Entity.java index a39a0072..28cc9c12 100644 --- a/core/src/gdx/diablo/entity/Entity.java +++ b/core/src/gdx/diablo/entity/Entity.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Array; @@ -514,6 +515,15 @@ public class Entity { label.draw(batch, 1); } + public boolean contains(Vector2 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; + } + public boolean contains(Vector3 coords) { if (animation == null) return false; BBox box = animation.getBox(); diff --git a/core/src/gdx/diablo/entity/StaticEntity.java b/core/src/gdx/diablo/entity/StaticEntity.java index 673b1e2f..3456b9b7 100644 --- a/core/src/gdx/diablo/entity/StaticEntity.java +++ b/core/src/gdx/diablo/entity/StaticEntity.java @@ -1,6 +1,7 @@ package gdx.diablo.entity; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Align; @@ -10,12 +11,13 @@ import gdx.diablo.graphics.PaletteIndexedBatch; import gdx.diablo.map.DS1; import gdx.diablo.map.DT1.Tile; import gdx.diablo.map.Map; +import gdx.diablo.screen.GameScreen; public class StaticEntity extends Entity { private static final String TAG = "StaticEntity"; - DS1.Object object; - Objects.Entry base; + public final DS1.Object object; + public final Objects.Entry base; public StaticEntity(DS1.Object object, Objects.Entry base) { super(base.Token, EntType.OBJECT); @@ -53,6 +55,13 @@ public class StaticEntity extends Entity { label.draw(batch, 1); } + @Override + public boolean contains(Vector2 coords) { + int mode = Diablo.files.ObjMode.index(this.mode); + if (!base.Selectable[mode]) return false; + return super.contains(coords); + } + @Override public boolean contains(Vector3 coords) { int mode = Diablo.files.ObjMode.index(this.mode); @@ -93,14 +102,19 @@ public class StaticEntity extends Entity { } } - private void operate() { + public void operate(GameScreen gameScreen) { switch (base.OperateFn) { case 0: break; case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: - case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: + case 30: case 31: + break; + case 32: // stash + gameScreen.stashPanel.setVisible(true); + break; + case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: case 58: case 59: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 67: case 68: case 69: diff --git a/core/src/gdx/diablo/map/MapListener.java b/core/src/gdx/diablo/map/MapListener.java new file mode 100644 index 00000000..b38fd230 --- /dev/null +++ b/core/src/gdx/diablo/map/MapListener.java @@ -0,0 +1,51 @@ +package gdx.diablo.map; + +import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.math.Vector2; + +import gdx.diablo.entity.Entity; +import gdx.diablo.entity.StaticEntity; +import gdx.diablo.screen.GameScreen; + +public class MapListener extends InputAdapter { + private final Vector2 tmpVec2 = new Vector2(); + + GameScreen gameScreen; + Map map; + MapRenderer mapRenderer; + + public MapListener(GameScreen gameScreen, Map map, MapRenderer mapRenderer) { + this.gameScreen = gameScreen; + this.map = map; + this.mapRenderer = mapRenderer; + } + + @Override + public boolean mouseMoved(int x, int y) { + mapRenderer.unproject(x, y, tmpVec2); + for (Map.Zone zone : map.zones) { + for (Entity entity : zone.entities) { + entity.over = entity.contains(tmpVec2); + } + } + + return false; + } + + @Override + public boolean touchDown(int x, int y, int pointer, int button) { + mapRenderer.unproject(x, y, tmpVec2); + for (Map.Zone zone : map.zones) { + for (Entity entity : zone.entities) { + if (entity.over && entity instanceof StaticEntity) { + StaticEntity object = (StaticEntity) entity; + if (object.position().dst(gameScreen.player.position()) <= object.base.OperateRange) { + object.operate(gameScreen); + } + } + } + } + + return false; + } +} diff --git a/core/src/gdx/diablo/map/MapRenderer.java b/core/src/gdx/diablo/map/MapRenderer.java index 88bec9df..9a6b9b5e 100644 --- a/core/src/gdx/diablo/map/MapRenderer.java +++ b/core/src/gdx/diablo/map/MapRenderer.java @@ -258,7 +258,7 @@ public class MapRenderer { } public void update(boolean force) { - hitAll(); + //hitAll(); if (src == null) return; Vector3 pos = src.position(); if (pos.epsilonEquals(currentPos) && !force) return; diff --git a/core/src/gdx/diablo/screen/GameScreen.java b/core/src/gdx/diablo/screen/GameScreen.java index 71860f2a..9a3a11e6 100644 --- a/core/src/gdx/diablo/screen/GameScreen.java +++ b/core/src/gdx/diablo/screen/GameScreen.java @@ -44,6 +44,7 @@ import gdx.diablo.key.MappedKey; import gdx.diablo.key.MappedKeyStateAdapter; import gdx.diablo.map.DT1; import gdx.diablo.map.Map; +import gdx.diablo.map.MapListener; import gdx.diablo.map.MapLoader; import gdx.diablo.map.MapRenderer; import gdx.diablo.panel.CharacterPanel; @@ -89,6 +90,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable final AssetDescriptor mapDescriptor = new AssetDescriptor<>("Act 1", Map.class, MapLoader.MapParameters.of(0, 0, 0)); Map map; MapRenderer mapRenderer; + MapListener mapListener; InputProcessor inputProcessorTest; public TextArea input; @@ -463,6 +465,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable mapRenderer.zoom(0.80f); } mapRenderer.resize(); + mapListener = new MapListener(this, map, mapRenderer); GridPoint2 origin = map.find(Map.ID.TOWN_ENTRY_1); player.position().set(origin.x, origin.y, 0); @@ -475,6 +478,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable Keys.Enter.addStateListener(mappedKeyStateListener); Diablo.input.addProcessor(stage); Diablo.input.addProcessor(inputProcessorTest); + Diablo.input.addProcessor(mapListener); if (socket != null && socket.isConnected()) { Gdx.app.log(TAG, "connecting to " + socket.getRemoteAddress() + "..."); @@ -519,6 +523,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable Keys.Enter.removeStateListener(mappedKeyStateListener); Diablo.input.removeProcessor(stage); Diablo.input.removeProcessor(inputProcessorTest); + Diablo.input.removeProcessor(mapListener); //updateTask.cancel(); }