workshop ui start
parent
39710d33a7
commit
51d6c3db8b
|
|
@ -3,6 +3,7 @@ package xyz.valnet.engine.scenegraph;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import xyz.valnet.engine.scenegraph.SceneGraph.GameObjectCallback;
|
||||||
import xyz.valnet.hadean.util.Pair;
|
import xyz.valnet.hadean.util.Pair;
|
||||||
|
|
||||||
public class GameObject implements IRenderable, ITickable, Serializable {
|
public class GameObject implements IRenderable, ITickable, Serializable {
|
||||||
|
|
@ -91,4 +92,12 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
||||||
protected Pair<Float, Integer> getFPS() {
|
protected Pair<Float, Integer> getFPS() {
|
||||||
return scene.getFPS();
|
return scene.getFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onAddGameObject(GameObjectCallback listener) {
|
||||||
|
scene.registerAddListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onRemoveGameObject(GameObjectCallback listener) {
|
||||||
|
scene.registerRemoveListener(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -17,7 +18,6 @@ import java.util.stream.Collectors;
|
||||||
import xyz.valnet.engine.App;
|
import xyz.valnet.engine.App;
|
||||||
import xyz.valnet.engine.Game;
|
import xyz.valnet.engine.Game;
|
||||||
import xyz.valnet.engine.math.Box;
|
import xyz.valnet.engine.math.Box;
|
||||||
import xyz.valnet.hadean.HadeanGame;
|
|
||||||
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
||||||
import xyz.valnet.hadean.util.Pair;
|
import xyz.valnet.hadean.util.Pair;
|
||||||
|
|
||||||
|
|
@ -31,6 +31,22 @@ public abstract class SceneGraph implements IScene {
|
||||||
private boolean loadFlag = false;
|
private boolean loadFlag = false;
|
||||||
private boolean saveFlag = false;
|
private boolean saveFlag = false;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface GameObjectCallback extends Serializable {
|
||||||
|
public void apply(GameObject obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<GameObjectCallback> onAddListeners = new HashSet<>();
|
||||||
|
private Set<GameObjectCallback> onRemoveListeners = new HashSet<>();
|
||||||
|
|
||||||
|
public void registerAddListener(GameObjectCallback cb) {
|
||||||
|
onAddListeners.add(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerRemoveListener(GameObjectCallback cb) {
|
||||||
|
onRemoveListeners.add(cb);
|
||||||
|
}
|
||||||
|
|
||||||
public <T> T get(Class<T> clazz) {
|
public <T> T get(Class<T> clazz) {
|
||||||
for(GameObject obj : objects) {
|
for(GameObject obj : objects) {
|
||||||
if(clazz.isInstance(obj)) {
|
if(clazz.isInstance(obj)) {
|
||||||
|
|
@ -52,7 +68,7 @@ public abstract class SceneGraph implements IScene {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
dTime = 1;
|
dTime = Math.min(dTime, 6);
|
||||||
// ADD OBJECTS
|
// ADD OBJECTS
|
||||||
if(!newObjects.isEmpty()) {
|
if(!newObjects.isEmpty()) {
|
||||||
List<GameObject> added = new ArrayList<GameObject>();
|
List<GameObject> added = new ArrayList<GameObject>();
|
||||||
|
|
@ -155,6 +171,12 @@ public abstract class SceneGraph implements IScene {
|
||||||
for(GameObject obj : objects) {
|
for(GameObject obj : objects) {
|
||||||
obj.addedToScene();
|
obj.addedToScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(GameObject obj : objects) {
|
||||||
|
for(GameObjectCallback listener : onAddListeners) {
|
||||||
|
listener.apply(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -180,6 +202,9 @@ public abstract class SceneGraph implements IScene {
|
||||||
newObjects.add(obj);
|
newObjects.add(obj);
|
||||||
obj.link(this);
|
obj.link(this);
|
||||||
obj.addedToScene();
|
obj.addedToScene();
|
||||||
|
for(GameObjectCallback listener : onAddListeners) {
|
||||||
|
listener.apply(obj);
|
||||||
|
}
|
||||||
addObjectToCache(obj);
|
addObjectToCache(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,6 +216,9 @@ public abstract class SceneGraph implements IScene {
|
||||||
|
|
||||||
public void remove(GameObject obj) {
|
public void remove(GameObject obj) {
|
||||||
removeObjects.add(obj);
|
removeObjects.add(obj);
|
||||||
|
for(GameObjectCallback listener : onRemoveListeners) {
|
||||||
|
listener.apply(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inScene(GameObject gameObject) {
|
public boolean inScene(GameObject gameObject) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package xyz.valnet.engine.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ClassToInstanceSet<B> {
|
||||||
|
private Map<Class<? extends B>, Set<B>> map = new HashMap<>();
|
||||||
|
|
||||||
|
private final <T extends B> void ensure(Class<T> clazz) {
|
||||||
|
if(!map.containsKey(clazz)) {
|
||||||
|
map.put(clazz, new HashSet<>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends B> void add(Class<T> clazz, T obj) {
|
||||||
|
ensure(clazz);
|
||||||
|
var set = map.get(clazz);
|
||||||
|
set.add(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") // it IS checked, by way of the add method.
|
||||||
|
public final <T extends B> Set<T> get(Class<T> clazz) {
|
||||||
|
return (Set<T>) map.get(clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -60,8 +60,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
||||||
private void broadcastWorldCoords() {
|
private void broadcastWorldCoords() {
|
||||||
Vector2i worldcoords = camera.getWorldMouse().asInt();
|
Vector2i worldcoords = camera.getWorldMouse().asInt();
|
||||||
if(mouseDown) {
|
if(mouseDown) {
|
||||||
Vector2i[] ords = orderCoords(startingPoint, worldcoords);
|
listener.update(Box.fromPoints(startingPoint, camera.getWorldMouse()));
|
||||||
listener.update(new Box(ords[0].x, ords[0].y, ords[2].x + 1, ords[2].y + 1));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(type == BuildType.SINGLE && dimensions != null) {
|
if(type == BuildType.SINGLE && dimensions != null) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package xyz.valnet.hadean.gameobjects.ui;
|
||||||
|
|
||||||
|
import xyz.valnet.engine.graphics.ImmediateUI;
|
||||||
|
import xyz.valnet.engine.scenegraph.ITransient;
|
||||||
|
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||||
|
import xyz.valnet.hadean.interfaces.IWorkshop;
|
||||||
|
|
||||||
|
public class WorkshopOrdersUI extends ImmediateUI implements ITransient {
|
||||||
|
|
||||||
|
private IWorkshop shop;
|
||||||
|
private SelectionLayer selectionLayer;
|
||||||
|
|
||||||
|
public void open(IWorkshop shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
this.shop = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void gui() {
|
||||||
|
if(shop == null) return;
|
||||||
|
|
||||||
|
window(0, 0, 200, 300, () -> {
|
||||||
|
text("stuff");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void connect() {
|
||||||
|
super.connect();
|
||||||
|
this.selectionLayer = get(SelectionLayer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start() {
|
||||||
|
super.start();
|
||||||
|
this.selectionLayer.subscribe((selection) -> {
|
||||||
|
if(!selection.contains(shop)) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,11 +2,17 @@ package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
||||||
|
|
||||||
import xyz.valnet.engine.graphics.Sprite;
|
import xyz.valnet.engine.graphics.Sprite;
|
||||||
import xyz.valnet.engine.math.Vector2i;
|
import xyz.valnet.engine.math.Vector2i;
|
||||||
|
import xyz.valnet.hadean.gameobjects.ui.WorkshopOrdersUI;
|
||||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||||
|
import xyz.valnet.hadean.interfaces.IWorkshop;
|
||||||
|
import xyz.valnet.hadean.util.Action;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
|
|
||||||
public class MasonWorkshop extends Construction {
|
public class MasonWorkshop extends Construction implements IWorkshop {
|
||||||
|
|
||||||
|
private static Action OPEN_ORDERS = new Action("Orders");
|
||||||
|
private transient WorkshopOrdersUI ordersWindow;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IItemPredicate getBuildingMaterial() {
|
protected IItemPredicate getBuildingMaterial() {
|
||||||
|
|
@ -37,5 +43,23 @@ public class MasonWorkshop extends Construction {
|
||||||
public Vector2i getDimensions() {
|
public Vector2i getDimensions() {
|
||||||
return new Vector2i(3, 3);
|
return new Vector2i(3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action[] getActions() {
|
||||||
|
return new Action[] { OPEN_ORDERS };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runAction(Action action) {
|
||||||
|
if(action == OPEN_ORDERS) {
|
||||||
|
ordersWindow.open(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void connect() {
|
||||||
|
super.connect();
|
||||||
|
ordersWindow = get(WorkshopOrdersUI.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package xyz.valnet.hadean.interfaces;
|
||||||
|
|
||||||
|
public interface IWorkshop {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import xyz.valnet.hadean.gameobjects.Camera;
|
||||||
import xyz.valnet.hadean.gameobjects.Clock;
|
import xyz.valnet.hadean.gameobjects.Clock;
|
||||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||||
import xyz.valnet.hadean.gameobjects.ui.SelectionUI;
|
import xyz.valnet.hadean.gameobjects.ui.SelectionUI;
|
||||||
|
import xyz.valnet.hadean.gameobjects.ui.WorkshopOrdersUI;
|
||||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||||
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
||||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||||
|
|
@ -43,12 +44,12 @@ public class GameScene extends SceneGraph {
|
||||||
objects.add(new Pawn());
|
objects.add(new Pawn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
objects.add(new WorkshopOrdersUI());
|
||||||
objects.add(new SelectionLayer());
|
objects.add(new SelectionLayer());
|
||||||
objects.add(new SelectionUI());
|
objects.add(new SelectionUI());
|
||||||
|
|
||||||
objects.add(new BuildLayer());
|
objects.add(new BuildLayer());
|
||||||
|
|
||||||
|
|
||||||
objects.add(new HoverQuery());
|
objects.add(new HoverQuery());
|
||||||
|
|
||||||
objects.add(new BottomBar());
|
objects.add(new BottomBar());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue