QoL features, ui mostly, some pathing mechanics
parent
b5bfa08869
commit
cb04e9fe75
|
|
@ -27,7 +27,6 @@ public class GameObject implements IRenderable, ITickable {
|
|||
|
||||
protected final <T extends GameObject> T add(T obj) {
|
||||
if(obj.inScene()) {
|
||||
System.out.println(obj + " is already in the scene. not adding twice...");
|
||||
return obj;
|
||||
}
|
||||
scene.add(obj);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
package xyz.valnet.hadean;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.App;
|
||||
|
|
@ -13,13 +9,14 @@ import xyz.valnet.engine.graphics.Drawing;
|
|||
import xyz.valnet.engine.math.Matrix4f;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.scenes.GameScene;
|
||||
import xyz.valnet.hadean.scenes.MenuScene;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
|
||||
public class HadeanGame extends Game {
|
||||
public static final HadeanGame Hadean = new HadeanGame();
|
||||
|
||||
public static boolean debugView = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new App(Hadean).run();
|
||||
}
|
||||
|
|
@ -34,35 +31,36 @@ public class HadeanGame extends Game {
|
|||
public void render() {
|
||||
Drawing.setLayer(0);
|
||||
super.render();
|
||||
|
||||
if(!debugView) return;
|
||||
Drawing.setLayer(99);
|
||||
// renderDebugInfo();
|
||||
renderDebugInfo();
|
||||
}
|
||||
|
||||
private Runtime runtime = Runtime.getRuntime();
|
||||
private static Vector4f fontColor = new Vector4f(0, 1, 1, 1);
|
||||
private static Runtime runtime = Runtime.getRuntime();
|
||||
private static Vector4f fontColor = new Vector4f(1, 0, 0, 1);
|
||||
|
||||
private void renderDebugInfo() {
|
||||
|
||||
long allocated = runtime.totalMemory();
|
||||
long max = runtime.maxMemory();
|
||||
int left = 800;
|
||||
int top = 10;
|
||||
|
||||
Assets.flat.pushColor(Vector4f.black);
|
||||
Assets.font.drawString("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED", 1, 1);
|
||||
Assets.font.drawString("Mouse: <" + App.mouseX + ", " + App.mouseY + ">", 1, 17);
|
||||
Assets.font.drawString("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)", 1, 33);
|
||||
Assets.font.drawString("IPATHABLE", 1, 49);
|
||||
Assets.font.drawString("", 1, 65);
|
||||
Assets.font.drawString("", 1, 81);
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("DEBUG");
|
||||
strings.add("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED");
|
||||
strings.add("Mouse: <" + App.mouseX + ", " + App.mouseY + ">");
|
||||
strings.add("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)");
|
||||
|
||||
Assets.flat.swapColor(fontColor);
|
||||
Assets.font.drawString("FPS: " + Math.round(averageFPS) + "/" + measuredFPS + " | AVG/MEASURED", 0, 0);
|
||||
Assets.font.drawString("Mouse: <" + App.mouseX + ", " + App.mouseY + ">", 0, 16);
|
||||
Assets.font.drawString("MEMORY: " + (int)((allocated / (double)max) * 100) + "% (" + (allocated / (1024 * 1024)) + "/" + (max / (1024 * 1024)) + "MB)", 0, 32);
|
||||
Assets.font.drawString("IPATHABLE", 0, 48);
|
||||
Assets.font.drawString("", 0, 64);
|
||||
Assets.font.drawString("", 0, 80);
|
||||
|
||||
Assets.flat.popColor();
|
||||
for(String str : strings) {
|
||||
Assets.flat.pushColor(Vector4f.black);
|
||||
Assets.font.drawString(str, left + 1, top + 1);
|
||||
Assets.flat.swapColor(fontColor);
|
||||
Assets.font.drawString(str, left, top);
|
||||
Assets.flat.popColor();
|
||||
top += 16;
|
||||
}
|
||||
}
|
||||
|
||||
// receive the updated matrix every frame for the actual window.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package xyz.valnet.hadean.designation;
|
|||
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
|
||||
@BuildableMetadata(category = "Designations", name = "Chop Trees")
|
||||
@BuildableMetadata(category = "Jobs", name = "Chop Trees")
|
||||
public class CutTreesDesignation extends Designation<Tree> {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package xyz.valnet.hadean.designation;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
|
||||
@BuildableMetadata(category = "Jobs", name = "Haul Items")
|
||||
public class HaulItemDesignation extends Designation<Item> {
|
||||
@Override
|
||||
protected Class<Item> getType() {
|
||||
return Item.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void designate(Item thing) {
|
||||
thing.runAction(Item.ACTION_HAUL);
|
||||
}
|
||||
}
|
||||
|
|
@ -76,7 +76,6 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea {
|
|||
public void mouseDown(int button) {
|
||||
if(button == 1 && active && hovered) {
|
||||
listener.cancel();
|
||||
deactiveate();
|
||||
} else if(button == 0 && active && hovered) {
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
mouseDown = true;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import xyz.valnet.engine.math.Vector4f;
|
|||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
|
@ -26,9 +27,12 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea {
|
|||
private float animationAmplitude = 0.2f;
|
||||
private List<ISelectionChangeListener> listeners = new ArrayList<ISelectionChangeListener>();
|
||||
|
||||
private BuildTab buildTab;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
camera = get(Camera.class);
|
||||
buildTab = get(BuildTab.class);
|
||||
}
|
||||
|
||||
public void subscribe(ISelectionChangeListener listener) {
|
||||
|
|
@ -178,6 +182,13 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea {
|
|||
if(initialCoords == null) {
|
||||
initialCoords = new Vector2f(App.mouseX, App.mouseY);
|
||||
}
|
||||
} else if (button == 1) {
|
||||
if(selected.size() == 0) {
|
||||
buildTab.evoke();
|
||||
} else {
|
||||
selected.clear();
|
||||
broadcastSelectionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import xyz.valnet.engine.App;
|
|||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
public class HoverQuery extends GameObject {
|
||||
|
|
@ -38,7 +38,8 @@ public class HoverQuery extends GameObject {
|
|||
position.y < box.w
|
||||
) {
|
||||
thingStrings.add(obj.getName());
|
||||
|
||||
if (!HadeanGame.debugView) continue;
|
||||
|
||||
if(obj instanceof Tile) {
|
||||
thingStrings.add(((Tile)obj).toThingsString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
||||
|
|
@ -63,6 +65,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
private Map<String, List<Pair<String, Constructor<? extends IBuildable>>>> buildables = new HashMap<String, List<Pair<String, Constructor<? extends IBuildable>>>>();
|
||||
|
||||
private int height = 0;
|
||||
private String selectedBuildableName = "";
|
||||
|
||||
private void calculateBuildables() {
|
||||
try {
|
||||
|
|
@ -91,8 +94,6 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
buildables.put(category, new ArrayList<Pair<String, Constructor<? extends IBuildable>>>());
|
||||
buildables.get(category).add(new Pair<String, Constructor<? extends IBuildable>>(name, constructor));
|
||||
|
||||
selectedBuildable = constructor;
|
||||
|
||||
System.out.println("Added " + category + " / " + name);
|
||||
}
|
||||
|
||||
|
|
@ -109,8 +110,13 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
|
||||
if(opened.value()) {
|
||||
Assets.uiFrame.draw(padding, 576 - BottomBar.bottomBarHeight - padding - height, width, height);
|
||||
|
||||
if(selectedBuildable == null) return;
|
||||
// draw the currently selected build item
|
||||
Assets.flat.pushColor(new Vector4f(1f, 1f, 1f, 0.5f));
|
||||
Assets.flat.pushColor(new Vector4f(1f, 1f, 1f, 1.0f));
|
||||
Vector2i topLeft = camera.world2screen(x, y).asInt();
|
||||
Assets.font.drawString(selectedBuildableName, topLeft.x, topLeft.y - 20);
|
||||
Assets.flat.swapColor(new Vector4f(1f, 1f, 1f, 0.5f));
|
||||
for(int i = 0; i < w; i ++) for(int j = 0; j < h; j ++) {{
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.checkerBoard, x + i, y + j);
|
||||
}}
|
||||
|
|
@ -149,7 +155,17 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
|
||||
private List<Button> categoryButtons = new ArrayList<Button>();
|
||||
|
||||
private void activate() {
|
||||
private void selectBuildable(String name, Constructor<? extends IBuildable> constructor) {
|
||||
if(selectedBuildable != null && constructor == null) {
|
||||
buildLayer.deactiveate();
|
||||
} else if (selectedBuildable == null && constructor != null) {
|
||||
activateBuildLayer();
|
||||
}
|
||||
selectedBuildable = constructor;
|
||||
selectedBuildableName = name;
|
||||
}
|
||||
|
||||
private void activateBuildLayer() {
|
||||
buildLayer.activate(new IBuildLayerListener() {
|
||||
@Override
|
||||
public void update(int nx, int ny, int nw, int nh) {
|
||||
|
|
@ -161,10 +177,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
|
||||
@Override
|
||||
public void build(int x1, int y1, int x2, int y2) {
|
||||
int ix1 = x1;
|
||||
int iy1 = y1;
|
||||
int ix2 = x2;
|
||||
int iy2 = y2;
|
||||
if(selectedBuildable == null) return;
|
||||
try {
|
||||
IBuildable building = selectedBuildable.newInstance();
|
||||
if(building instanceof GameObject) {
|
||||
|
|
@ -173,17 +186,24 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
building.buildAt(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
|
||||
}
|
||||
|
||||
opened.set(false);
|
||||
// opened.set(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
opened.set(false);
|
||||
if(selectedBuildable == null) {
|
||||
opened.set(false);
|
||||
buildLayer.deactiveate();
|
||||
} else {
|
||||
selectBuildable("", null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void activate() {
|
||||
|
||||
int i = 0;
|
||||
categoryButtons.clear();
|
||||
|
|
@ -288,10 +308,11 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
|
|||
public void click(Button target) {
|
||||
if(categoryButtons.contains(target)) {
|
||||
selectedCategory = target.getText();
|
||||
selectBuildable("", null);
|
||||
constructItemButtons();
|
||||
} else if(buildableButtons.containsKey(target)) {
|
||||
Constructor<? extends IBuildable> newConstructor = buildableButtons.get(target);
|
||||
selectedBuildable = newConstructor;
|
||||
selectBuildable(target.getText(), newConstructor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,17 @@
|
|||
package xyz.valnet.hadean.gameobjects.ui.tabs;
|
||||
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
|
||||
public class MenuTab extends Tab {
|
||||
|
||||
@Override
|
||||
public void evoke() {
|
||||
|
||||
HadeanGame.debugView = !HadeanGame.debugView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabName() {
|
||||
return "Menu";
|
||||
return "Toggle Debug";
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void tick(float dTime) {
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public void render() {
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public void start() {
|
||||
// super.start();
|
||||
// add(new GOButton()
|
||||
// .setDimensions(200, 300, 100, 100, 50));
|
||||
// add(new GOButton()
|
||||
// .setDimensions(250, 350, 100, 100, 55));
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
|
@ -65,7 +66,6 @@ public class FarmPlot extends WorldObject implements ISelectable, ITileThing, IB
|
|||
|
||||
@Override
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
System.out.println("buildAt");
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
|
|
@ -83,4 +83,7 @@ public class FarmPlot extends WorldObject implements ISelectable, ITileThing, IB
|
|||
return "Farm Plot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(Tile tile) {}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ public class Stockpile extends WorldObject implements ISelectable, ITileThing, I
|
|||
|
||||
@Override
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
System.out.println("buildAt");
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import xyz.valnet.engine.math.Vector2f;
|
|||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.shaders.SimpleShader;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
|
|
@ -64,12 +65,21 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
|||
Vector2i nextPos = path.pop().getPosition();
|
||||
this.x = nextPos.x;
|
||||
this.y = nextPos.y;
|
||||
if(nextPath != null) {
|
||||
path = nextPath;
|
||||
nextPath = null;
|
||||
}
|
||||
if(path.isComplete()) path = null;
|
||||
frameCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void correctPath() {
|
||||
if(path != null && path.isComplete()) path = null;
|
||||
if(path == null) return;
|
||||
if(path.peek().getPosition().equals(this.getWorldPosition().asInt())) {
|
||||
path.pop();
|
||||
}
|
||||
if(path != null && path.isComplete()) path = null;
|
||||
if(path == null) return;
|
||||
Tile nextTile = terrain.getTile(path.peek().getPosition());
|
||||
|
|
@ -96,14 +106,26 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
|||
return false;
|
||||
}
|
||||
|
||||
private Path nextPath = null;
|
||||
|
||||
protected void goTo(int x, int y) {
|
||||
path = pathfinder.getPath((int)this.x, (int)this.y, x, y);
|
||||
frameCounter = 0;
|
||||
Path newPath = pathfinder.getPath((int)this.x, (int)this.y, x, y);
|
||||
if(path == null) {
|
||||
path = newPath;
|
||||
frameCounter = 0;
|
||||
} else {
|
||||
nextPath = newPath;
|
||||
}
|
||||
}
|
||||
|
||||
protected void goToClosest(Vector2i[] destinations) {
|
||||
path = pathfinder.getBestPath(this.getWorldPosition().asInt(), destinations);
|
||||
frameCounter = 0;
|
||||
Path newPath = pathfinder.getBestPath(this.getWorldPosition().asInt(), destinations);
|
||||
if(path == null) {
|
||||
path = newPath;
|
||||
frameCounter = 0;
|
||||
} else {
|
||||
nextPath = newPath;
|
||||
}
|
||||
}
|
||||
|
||||
protected void goTo(Vector2i location) {
|
||||
|
|
@ -118,6 +140,7 @@ public abstract class Agent extends WorldObject implements ISelectable {
|
|||
|
||||
@Override
|
||||
public void renderAlpha() {
|
||||
if(!HadeanGame.debugView) return;
|
||||
Drawing.setLayer(Layers.GENERAL_UI);
|
||||
Assets.flat.pushColor(Vector4f.opacity(0.4f));
|
||||
if(path != null) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin
|
|||
return new Vector4f(x, y, x + 1, y + 1);
|
||||
}
|
||||
|
||||
private static final Action ACTION_HAUL = new Action("Haul");
|
||||
public static final Action ACTION_HAUL = new Action("Haul");
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue