the best build menu in existence

pull/1/head
valyrie97 2022-12-25 11:34:53 -05:00
parent f576907ec1
commit e4007a76ab
25 changed files with 451 additions and 165 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -10,7 +10,11 @@ public class GameObject implements IRenderable, ITickable {
}
public boolean inScene() {
return scene.inScene(this);
return scene != null && scene.inScene(this);
}
protected void dumpScene() {
scene.dump();
}
protected <T> T get(Class<T> clazz) {
@ -22,11 +26,18 @@ public class GameObject implements IRenderable, ITickable {
}
protected final void add(GameObject obj) {
if(obj.inScene()) {
System.out.println(obj + " is already in the scene. not adding twice...");
return;
}
scene.add(obj);
}
@Override
public void render() {}
@Override
public void renderAlpha() {}
@Override
public void update(float dTime) {}

View File

@ -2,4 +2,5 @@ package xyz.valnet.engine.scenegraph;
public interface IRenderable {
public void render();
public void renderAlpha();
}

View File

@ -43,10 +43,6 @@ public abstract class SceneGraph implements IScene {
added.add(obj);
}
newObjects.clear();
for(GameObject obj : added) {
obj.start();
}
}
// REMOVE OBJECTS
@ -110,6 +106,9 @@ public abstract class SceneGraph implements IScene {
for(GameObject obj : objects) {
obj.render();
}
for(GameObject obj : objects) {
obj.renderAlpha();
}
}
protected abstract void construct();
@ -123,6 +122,7 @@ public abstract class SceneGraph implements IScene {
public void add(GameObject obj) {
newObjects.add(obj);
obj.link(this);
obj.start();
}
public void remove(GameObject obj) {
@ -130,7 +130,12 @@ public abstract class SceneGraph implements IScene {
}
public boolean inScene(GameObject gameObject) {
return objects.contains(gameObject);
return objects.contains(gameObject) || newObjects.contains(gameObject);
}
public void dump() {
for(GameObject go : objects)
System.out.println(go);
}
@Override

View File

@ -27,6 +27,10 @@ public class SimpleShader extends Shader {
popColor();
pushColor(color);
}
public void clearColorStack() {
colorStack.clear();
}
public void popColor() {
colorStack.pop();

View File

@ -1,5 +1,12 @@
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;
import xyz.valnet.engine.Game;
import xyz.valnet.engine.graphics.Drawing;

View File

@ -83,7 +83,7 @@ public class JobBoard extends GameObject {
if(workables.size() > 0) {
for(IJob job : workables) {
if(!job.hasWork()) continue;
Vector2i[] workablePositions = job.getWorablePositions();
Vector2i[] workablePositions = job.getWorkablePositions();
Path bestPathToJob = pathfinder.getBestPath(
new Vector2i((int)Math.floor(workerLocation.x), (int)Math.floor(workerLocation.y)),
workablePositions

View File

@ -173,12 +173,10 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener,
@Override
public void mouseEnter() {
}
@Override
public void mouseLeave() {
}
@Override

View File

@ -12,11 +12,6 @@ public class Stockpile extends WorldObject implements ITileThing, ISelectable {
private WorldObject thing;
public Stockpile(int x, int y) {
this.x = x;
this.y = y;
}
public boolean isFree() {
return thing == null;
}
@ -59,11 +54,5 @@ public class Stockpile extends WorldObject implements ITileThing, ISelectable {
public String details() {
return "";
}
@Override
public void updatePosition(int x, int y) {
this.x = x;
this.y = y;
}
}

View File

@ -35,7 +35,7 @@ public class Tile extends GameObject {
public void start() {
camera = get(Camera.class);
if(Math.random() > 0.9) {
if(Math.random() > 0.97) {
Tree tree = new Tree(x, y);
stuff.add(tree);
add(tree);
@ -49,7 +49,6 @@ public class Tile extends GameObject {
}
public void placeThing(ITileThing thing) {
thing.updatePosition(x, y);
stuff.add(thing);
if(thing instanceof GameObject) {
add((GameObject)thing);

View File

@ -35,7 +35,6 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea {
@Override
public void render() {
if(mouseDown && active) {
Assets.selectionFrame.draw(screenX, screenY, App.mouseX - screenX, App.mouseY - screenY);
camera.screen2world(App.mouseX, App.mouseY);
}
}

View File

@ -2,11 +2,20 @@ package xyz.valnet.hadean.gameobjects.tabs;
import static xyz.valnet.engine.util.Math.lerp;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.GameObject;
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
import xyz.valnet.hadean.gameobjects.BottomBar;
import xyz.valnet.hadean.gameobjects.Camera;
@ -14,15 +23,21 @@ import xyz.valnet.hadean.gameobjects.Terrain;
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
import xyz.valnet.hadean.gameobjects.inputlayer.Selection;
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
import xyz.valnet.hadean.input.Button;
import xyz.valnet.hadean.input.IButtonListener;
import xyz.valnet.hadean.input.SimpleButton;
import xyz.valnet.hadean.interfaces.BuildableMetadata;
import xyz.valnet.hadean.interfaces.IBuildLayerListener;
import xyz.valnet.hadean.interfaces.IBuildable;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
import xyz.valnet.hadean.interfaces.ITileThing;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
import xyz.valnet.hadean.util.Pair;
import xyz.valnet.hadean.util.SmartBoolean;
public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCaptureArea {
public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCaptureArea, IButtonListener {
private Selection selection;
private BuildLayer buildLayer;
@ -30,23 +45,70 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
private Terrain terrain;
private SmartBoolean opened;
private float progress = 0f;
private float width = 200;
private int width = 200;
private int padding = 10;
private int x, y;
private int w, h;
// private List<String> categories = new ArrayList<String>();
private String selectedCategory = "Zones";
private List<Class<ITileThing>> things = new ArrayList<Class<ITileThing>>();
private Constructor<? extends IBuildable> selectedBuildable = null;
private Map<String, List<Pair<String, Constructor<? extends IBuildable>>>> buildables = new HashMap<String, List<Pair<String, Constructor<? extends IBuildable>>>>();
private int height = 0;
private void calculateBuildables() {
try {
Class<? extends IBuildable>[] maybeBuildables = getClasses("xyz.valnet.hadean");
for(Class<? extends IBuildable> clazz : maybeBuildables) {
if(clazz.isAnonymousClass()) continue;
if(!IBuildable.class.isAssignableFrom(clazz)) continue;
if(clazz.isInterface()) continue;
Constructor<? extends IBuildable> constructor = clazz.getConstructor();
if(constructor.getParameterCount() != 0) {
System.out.println(clazz + " has no default constructor (no params)");
continue;
}
BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
if(annotation == null) {
System.out.println(clazz + " has no buildable data annotation");
continue;
}
String category = annotation.category();
String name = annotation.name();
if(!buildables.containsKey(category))
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);
}
} catch (Exception e) {
System.out.println(e);
}
height = Math.max((int)Math.ceil(buildables.size() / 2f) * 24, 24*3);
}
@Override
public void render() {
public void renderAlpha () {
Drawing.setLayer(Layers.GENERAL_UI);
float left = lerp(-width - padding, padding, progress);
Assets.uiFrame.draw((int) left, padding, (int) width, 576 - padding * 2 - BottomBar.bottomBarHeight);
if(opened.value()) {
Assets.uiFrame.draw(padding, 576 - BottomBar.bottomBarHeight - padding - height, width, height);
// draw the currently selected build item
Assets.flat.pushColor(new Vector4f(1f, 1f, 1f, 0.8f));
Assets.flat.pushColor(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.stockpile, x + i, y + j);
}}
@ -61,8 +123,32 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
selection = get(Selection.class);
camera = get(Camera.class);
terrain = get(Terrain.class);
IBuildLayerListener buildListener = new IBuildLayerListener() {
opened = new SmartBoolean(false, new SmartBoolean.IListener() {
@Override
public void rise() {
activate();
}
@Override
public void fall() {
deactiveate();
}
});
if(selection != null) {
selection.subscribe(this);
}
calculateBuildables();
}
private List<Button> categoryButtons = new ArrayList<Button>();
private void activate() {
buildLayer.activate(new IBuildLayerListener() {
@Override
public void update(int nx, int ny, int nw, int nh) {
x = nx;
@ -77,12 +163,16 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
int iy1 = y1;
int ix2 = x2;
int iy2 = y2;
for(int x = ix1; x <= ix2; x ++) {
for(int y = iy1; y <= iy2; y ++) {
ITileThing thing = new FarmPlot(x, y);
terrain.getTile(x, y).placeThing(thing);
}
try {
IBuildable building = selectedBuildable.newInstance();
GameObject go = (GameObject) building;
add(go);
building.buildAt(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
} catch (Exception e) {
System.out.println(e);
}
opened.set(false);
}
@ -90,30 +180,33 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
public void cancel() {
opened.set(false);
}
};
opened = new SmartBoolean(false, new SmartBoolean.IListener() {
@Override
public void rise() {
buildLayer.activate(buildListener);
}
@Override
public void fall() {
buildLayer.deactiveate();
}
});
if(selection != null) {
selection.subscribe(this);
int i = 0;
categoryButtons.clear();
for(String c : buildables.keySet()) {
int left = i % 2 == 0 ? padding : padding + width / 2;
int y = 576 - BottomBar.bottomBarHeight - padding - height + ((int)Math.floor(i / 2)) * 24;
Button b = new SimpleButton(c, left, y, width / 2, 24, Layers.GENERAL_UI_INTERACTABLE);
b.registerClickListener(this);
categoryButtons.add(b);
add(b);
i ++;
}
constructItemButtons();
}
private void deactiveate() {
buildLayer.deactiveate();
if(categoryButtons != null) for(Button btn : categoryButtons) remove(btn);
categoryButtons.clear();
constructItemButtons();
}
@Override
public void update(float dTime) {
progress = lerp(progress, opened.value() ? 1 : 0, 0.05f);
}
@Override
@ -150,12 +243,86 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
@Override
public Vector4f getBox() {
float left = lerp(-width - padding, padding, progress);
return new Vector4f((int) left, padding, (int) width, 576 - padding * 2 - BottomBar.bottomBarHeight);
return new Vector4f(padding, 576 - BottomBar.bottomBarHeight - padding - height, width, height);
}
@Override
public float getLayer() {
return Layers.GENERAL_UI;
}
private Map<Button, Constructor<? extends IBuildable>> buildableButtons = new HashMap<Button, Constructor<? extends IBuildable>>();
private void constructItemButtons() {
for(Button btn : buildableButtons.keySet()) {
remove(btn);
}
buildableButtons.clear();
if(!opened.value()) return;
List<Pair<String, Constructor<? extends IBuildable>>> categoryBuildables = buildables.get(selectedCategory);
int left = width + padding * 2;
int buttonHeight = 24;
int buttonWidth = 100;
int top = 576 - BottomBar.bottomBarHeight - padding - buttonHeight;
int i = 0;
for(Pair<String, Constructor<? extends IBuildable>> nameConstructorPair : categoryBuildables) {
int x = left + (buttonWidth + padding) * i;
int y = top;
int w = buttonWidth;
int h = buttonHeight;
i ++;
Button btn = new SimpleButton(nameConstructorPair.first(), x, y, w, h, Layers.GENERAL_UI_INTERACTABLE);
btn.registerClickListener(this);
add(btn);
buildableButtons.put(btn, nameConstructorPair.second());
}
}
@Override
public void click(Button target) {
if(categoryButtons.contains(target)) {
selectedCategory = target.getText();
constructItemButtons();
} else if(buildableButtons.containsKey(target)) {
Constructor<? extends IBuildable> newConstructor = buildableButtons.get(target);
selectedBuildable = newConstructor;
}
}
private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
assert classLoader != null;
String path = packageName.replace('.', '/');
Enumeration<URL> resources = classLoader.getResources(path);
List<File> dirs = new ArrayList<File>();
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
dirs.add(new File(resource.getFile()));
}
ArrayList<Class> classes = new ArrayList<Class>();
for (File directory : dirs) {
classes.addAll(findClasses(directory, packageName));
}
return classes.toArray(new Class[classes.size()]);
}
private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException {
List<Class> classes = new ArrayList<Class>();
if (!directory.exists()) {
return classes;
}
File[] files = directory.listFiles();
for (File file : files) {
if (file.isDirectory()) {
assert !file.getName().contains(".");
classes.addAll(findClasses(file, packageName + "." + file.getName()));
} else if (file.getName().endsWith(".class")) {
classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
}
}
return classes;
}
}

View File

@ -3,6 +3,8 @@ package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.JobBoard;
import xyz.valnet.hadean.interfaces.BuildableMetadata;
import xyz.valnet.hadean.interfaces.IBuildable;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ITileThing;
import xyz.valnet.hadean.interfaces.IWorkable;
@ -10,7 +12,8 @@ import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITileThing {
@BuildableMetadata(category = "Zones", name = "Farm Plot")
public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITileThing, IBuildable {
private float progress = 0f;
private int stage = 0;
@ -22,14 +25,11 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
private JobBoard board;
public FarmPlot(int x, int y) {
this.x = x;
this.y = y;
}
private int w, h;
@Override
public void render() {
camera.draw(Layers.GROUND, Assets.farmPlot, x, y);
camera.draw(Layers.TILES, Assets.farmPlot, x, y);
if(planted) {
if(stage > 1) {
@ -40,6 +40,14 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
}
}
@Override
public void renderAlpha() {
if(!visible) return;
Assets.flat.pushColor(new Vector4f(0.4f, 1f, 0.3f, 0.2f));
camera.draw(Layers.GROUND, Assets.whiteBox, x, y, w, h);
Assets.flat.popColor();
}
@Override
public void update(float dTime) {
super.update(dTime);
@ -79,7 +87,7 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
}
@Override
public Vector2i[] getWorablePositions() {
public Vector2i[] getWorkablePositions() {
return new Vector2i[] {
new Vector2i((int) x, (int) y + 1),
new Vector2i((int) x, (int) y - 1),
@ -100,16 +108,24 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
@Override
public Vector4f getWorldBox() {
return new Vector4f(x, y, x + 1, y + 1);
return new Vector4f(x, y, x + w, y + h);
}
private static Action TOGGLE_VISIBILITY = new Action("Hide / Show");
@Override
public Action[] getActions() {
return new Action[] {};
return new Action[] { TOGGLE_VISIBILITY };
}
private boolean visible = true;
@Override
public void runAction(Action action) {}
public void runAction(Action action) {
if(action == TOGGLE_VISIBILITY) {
visible = !visible;
}
}
@Override
public String details() {
@ -148,7 +164,20 @@ public class FarmPlot extends WorldObject implements IWorkable, ISelectable, ITi
}
@Override
public void updatePosition(int x, int y) {}
public void buildAt(int x, int y, int w, int h) {
System.out.println("buildAt");
this.x = x;
this.y = y;
this.w = w;
this.h = h;
System.out.println("<" + x + ", " + y + ", " + w + ", " + h + ">");
System.out.println(inScene());
terrain.getTile(x, y).placeThing(this);
for(int i = x; i < x + w; i ++) {
for(int j = y; j < y + h; j ++) {
terrain.getTile(i, j).placeThing(this);
}
}
}
}

View File

@ -97,7 +97,7 @@ public class Log extends WorldObject implements ITileThing, ISelectable, IHaulab
}
@Override
public Vector2i[] getWorablePositions() {
public Vector2i[] getWorkablePositions() {
return new Vector2i[] {
new Vector2i((int)x + 1, (int)y),
new Vector2i((int)x - 1, (int)y),
@ -124,12 +124,6 @@ public class Log extends WorldObject implements ITileThing, ISelectable, IHaulab
return get(Stockpile.class).getTile();
}
@Override
public void updatePosition(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String getJobName() {
return "Haul Log";

View File

@ -147,7 +147,7 @@ public class Pawn extends WorldObject implements ISelectable, IWorker {
// try to do your work!
if(currentJob != null && currentJob.hasWork()) {
if(getCurrentPos().isOneOf(currentJob.getWorablePositions())) {
if(getCurrentPos().isOneOf(currentJob.getWorkablePositions())) {
if(currentJob instanceof IWorkable) {
((IWorkable)currentJob).doWork();
} else if (currentJob instanceof IHaulable) {

View File

@ -113,13 +113,7 @@ public class Rice extends WorldObject implements ITileThing, ISelectable {
// public Tile getDestination() {
// return get(Stockpile.class).getTile();
// }
@Override
public void updatePosition(int x, int y) {
this.x = x;
this.y = y;
}
// @Override
// public String getJobName() {
// return "Haul Log";

View File

@ -0,0 +1,136 @@
package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.JobBoard;
import xyz.valnet.hadean.interfaces.BuildableMetadata;
import xyz.valnet.hadean.interfaces.IBuildable;
import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ITileThing;
import xyz.valnet.hadean.interfaces.IWorkable;
import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
@BuildableMetadata(category = "Zones", name = "Stockpile")
public class Stockpile extends WorldObject implements IWorkable, ISelectable, ITileThing, IBuildable {
private JobBoard board;
private int w, h;
@Override
public void render() {
}
@Override
public void renderAlpha() {
if(!visible) return;
Assets.flat.pushColor(new Vector4f(1f, 0.2f, 0.1f, 0.3f));
camera.draw(Layers.GROUND, Assets.whiteBox, x, y, w, h);
Assets.flat.popColor();
}
@Override
public void update(float dTime) {
super.update(dTime);
}
@Override
public void start() {
super.start();
board = get(JobBoard.class);
board.postJob(this);
}
@Override
public boolean hasWork() {
return false;
}
@Override
public Vector2i[] getWorkablePositions() {
return new Vector2i[] {
new Vector2i((int) x, (int) y + 1),
new Vector2i((int) x, (int) y - 1),
new Vector2i((int) x + 1, (int) y),
new Vector2i((int) x - 1, (int) y)
};
}
@Override
public Vector2i getLocation() {
return new Vector2i((int) x, (int) y);
}
@Override
public String getJobName() {
return "No jobs here!";
}
@Override
public Vector4f getWorldBox() {
return new Vector4f(x, y, x + w, y + h);
}
private static Action TOGGLE_VISIBILITY = new Action("Hide / Show");
@Override
public Action[] getActions() {
return new Action[] { TOGGLE_VISIBILITY };
}
private boolean visible = true;
@Override
public void runAction(Action action) {
if(action == TOGGLE_VISIBILITY) {
visible = !visible;
}
}
@Override
public String details() {
return "";
}
@Override
public void doWork() {
}
@Override
public boolean isWalkable() {
return true;
}
@Override
public boolean shouldRemove() {
return false;
}
@Override
public void onRemove() {
}
@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;
this.h = h;
System.out.println("<" + x + ", " + y + ", " + w + ", " + h + ">");
System.out.println(inScene());
terrain.getTile(x, y).placeThing(this);
for(int i = x; i < x + w; i ++) {
for(int j = y; j < y + h; j ++) {
terrain.getTile(i, j).placeThing(this);
}
}
}
}

View File

@ -71,7 +71,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
}
@Override
public Vector2i[] getWorablePositions() {
public Vector2i[] getWorkablePositions() {
return new Vector2i[] {
new Vector2i(x, y - 1),
new Vector2i(x, y + 1),
@ -127,12 +127,6 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
return new Vector2i(x, y);
}
@Override
public void updatePosition(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String getJobName() {
return "Chop " + name;

View File

@ -41,6 +41,10 @@ public class Button extends GameObject implements IMouseCaptureArea {
layer = l;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
Vector4i measuredText = Assets.font.measure(text);

View File

@ -1,64 +0,0 @@
package xyz.valnet.hadean.input;
import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.GameObject;
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
import xyz.valnet.hadean.util.Assets;
public class GOButton extends GameObject implements IMouseCaptureArea {
private boolean hovered = false;
public int layer = 1;
public int x, y, w, h;
public GOButton setDimensions(int x, int y, int w, int h, int l) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.layer = l;
return this;
}
@Override
public void render() {
Drawing.setLayer(layer);
if(hovered) {
Assets.uiFrameLight.draw(x, y, w, h);
} else {
Assets.uiFrame.draw(x, y, w, h);
}
}
@Override
public void mouseEnter() {
hovered = true;
}
@Override
public void mouseLeave() {
hovered = false;
}
@Override
public void mouseDown(int button) {
}
@Override
public void mouseUp(int button) {
}
@Override
public Vector4f getBox() {
return new Vector4f(x, y, w, h);
}
@Override
public float getLayer() {
return layer;
}
}

View File

@ -0,0 +1,10 @@
package xyz.valnet.hadean.interfaces;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface BuildableMetadata {
public String name();
public String category();
}

View File

@ -0,0 +1,7 @@
package xyz.valnet.hadean.interfaces;
public interface IBuildable {
public void buildAt(int x, int y, int w, int h);
}

View File

@ -4,7 +4,7 @@ import xyz.valnet.engine.math.Vector2i;
public interface IJob {
public boolean hasWork();
public Vector2i[] getWorablePositions();
public Vector2i[] getWorkablePositions();
public Vector2i getLocation();
public String getJobName();
}

View File

@ -4,5 +4,4 @@ public interface ITileThing {
public boolean isWalkable();
public boolean shouldRemove();
public void onRemove();
public void updatePosition(int x, int y);
}

View File

@ -35,6 +35,7 @@ public class Assets {
public static final Sprite stockpile;
public static final Sprite riceBag;
public static final Sprite farmPlot;
public static final Sprite whiteBox;
public static final SimpleShader flat;
@ -43,6 +44,8 @@ public class Assets {
atlas = new Texture("res/textures.png");
whiteBox = new Sprite(atlas, 0, 88, 8, 8);
defaultTerrain = new Sprite[] {
new Sprite(atlas, new Vector4i(24, 72, 8, 8)),
new Sprite(atlas, new Vector4i(24, 64, 8, 8)),
@ -228,15 +231,15 @@ public class Assets {
);
selectedFrame = new Tile9(
new Sprite(atlas, new Vector4i( 8, 88, 5, 5)),
new Sprite(atlas, new Vector4i(13, 88, 6, 5)),
new Sprite(atlas, new Vector4i(19, 88, 5, 5)),
new Sprite(atlas, new Vector4i( 8, 93, 5, 6)),
new Sprite(atlas, new Vector4i(13, 93, 6, 6)),
new Sprite(atlas, new Vector4i(19, 93, 5, 6)),
new Sprite(atlas, new Vector4i( 8, 99, 5, 5)),
new Sprite(atlas, new Vector4i(13, 99, 6, 5)),
new Sprite(atlas, new Vector4i(19, 99, 5, 5))
new Sprite(atlas, new Vector4i( 8, 88, 7, 7)),
new Sprite(atlas, new Vector4i(15, 88, 2, 7)),
new Sprite(atlas, new Vector4i(17, 88, 7, 7)),
new Sprite(atlas, new Vector4i( 8, 95, 7, 2)),
new Sprite(atlas, new Vector4i(15, 95, 2, 2)),
new Sprite(atlas, new Vector4i(17, 95, 7, 2)),
new Sprite(atlas, new Vector4i( 8, 97, 7, 7)),
new Sprite(atlas, new Vector4i(15, 97, 2, 7)),
new Sprite(atlas, new Vector4i(17, 97, 7, 7))
);
uiFrame = new Tile9(