lots of conversion to color & box

bottom-bar
Ivory 2023-01-27 09:56:56 -05:00
parent 072774e2bf
commit 118f5299df
29 changed files with 282 additions and 246 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ out
output output
SAVE_DATA.TXT SAVE_DATA.TXT
.DS_Store .DS_Store
.vscode/graalvm

41
.vscode/launch.json vendored
View File

@ -1,20 +1,25 @@
{ {
// Use IntelliSense to learn about possible attributes. // Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes. // Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "java", "type": "java",
"name": "Launch App", "name": "Launch App",
"request": "launch", "request": "launch",
"mainClass": "xyz.valnet.hadean.HadeanGame", "mainClass": "xyz.valnet.hadean.HadeanGame",
"projectName": "hadean", "projectName": "hadean",
"console": "internalConsole", "console": "internalConsole",
"internalConsoleOptions": "neverOpen", "internalConsoleOptions": "neverOpen",
"osx": {
"vmArgs": "-XstartOnFirstThread" "osx": {
} "type": "java",
} "name": "Launch App",
] "request": "launch",
"mainClass": "xyz.valnet.hadean.HadeanGame",
"vmArgs": "-XstartOnFirstThread"
}
}
]
} }

View File

@ -0,0 +1,60 @@
package xyz.valnet.engine.graphics;
public class Color {
public final float r, g, b, a;
public static Color black = new Color(0, 0, 0);
public static Color white = new Color(1, 1, 1);
public static Color red = new Color(1, 0, 0);
public static Color green = new Color(0, 1, 0);
public static Color blue = new Color(0, 0, 1);
public static Color yellow = new Color(1, 1, 0);
public static Color cyan = new Color(0, 1, 1);
public static Color magenta = new Color(1, 0, 1);
public static Color orange = new Color(1, 0.5f, 0);
public static Color lime = new Color(0.5f, 1, 0);
public static Color aqua = new Color(0, 1, 0.5f);
public static Color indigo = new Color(0, 0.5f, 1);
public static Color purple = new Color(0.5f, 0, 1);
public static Color hotpink = new Color(1, 0, 0.5f);
public Color(float r, float g, float b) {
this(r, g, b, 1.0f);
}
public Color(float r, float g, float b, float a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public Color withAlpha(float a) {
return new Color(r, g, b, a);
}
public Color brighter() {
return new Color(
(float) Math.sqrt(r),
(float) Math.sqrt(g),
(float) Math.sqrt(b),
a
);
}
public Color darker() {
return new Color(
(float) Math.pow(r, 2),
(float) Math.pow(g, 2),
(float) Math.pow(b, 2),
a
);
}
public static Color grey(float f) {
return new Color(f, f, f);
}
}

View File

@ -2,7 +2,6 @@ package xyz.valnet.engine.graphics;
import java.util.Map; import java.util.Map;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Assets;
@ -21,7 +20,7 @@ public class Font {
} }
public void drawStringOutlined(String str, int x, int y) { public void drawStringOutlined(String str, int x, int y) {
Assets.flat.pushColor(Vector4f.black); Assets.flat.pushColor(Color.black);
drawString(str, x - scale, y - scale); drawString(str, x - scale, y - scale);
drawString(str, x, y - scale); drawString(str, x, y - scale);
drawString(str, x + scale, y - scale); drawString(str, x + scale, y - scale);

View File

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.engine.scenegraph.GameObject;
@ -29,16 +30,6 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
end(); end();
} }
public void renderAlpha() {
// float f = 99;
// Assets.flat.pushColor(new Vector4f(1, 0, 0, 0.3f));
// for(Vector4f box : guiAreas) {
// Drawing.setLayer(f += 0.001f);
// Assets.fillColor.draw(box);
// }
// Assets.flat.popColor();
}
@Override @Override
public void mouseEnter() { public void mouseEnter() {
active = true; active = true;
@ -68,8 +59,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
private record StackingContext( private record StackingContext(
boolean fixedSize, boolean fixedSize,
Vector4f box, Box box,
Vector4f occlusionBox, Box occlusionBox,
boolean hasRegisteredGuiArea, boolean hasRegisteredGuiArea,
boolean horizontal boolean horizontal
// layout manager? // layout manager?
@ -120,31 +111,40 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
return false; return false;
} }
private void modifyBox(float x, float y, float w, float h) {
context = new StackingContext(
context.fixedSize,
new Box(context.box.x + x, context.box.y + y, context.box.w + w, context.box.h + h),
context.occlusionBox,
context.hasRegisteredGuiArea,
context.horizontal
);
}
private void adjustBox(float w, float h) { private void adjustBox(float w, float h) {
if(context.vertical()) { if(context.vertical()) {
if(context.fixedSize) { if(context.fixedSize) {
context.box.y += h; modifyBox(0, h, 0, -h);
context.box.w -= h;
} else { } else {
context.box.w += h; modifyBox(0, 0, 0, h);
} }
} else { } else {
if(context.fixedSize) { if(context.fixedSize) {
context.box.x += w; modifyBox(w, 0, -w, 0);
context.box.z -= w;
} else { } else {
context.box.z += w; modifyBox(0, 0, w, 0);
context.box.w = Math.max(context.box.w, h); if (h - context.box.h > 0)
modifyBox(0, 0, 0, h - context.box.h);
} }
} }
} }
@Override @Override
public final List<Vector4f> getGuiBoxes() { public final List<Box> getGuiBoxes() {
return guiAreas; return guiAreas;
} }
private transient List<Vector4f> guiAreas = new ArrayList<Vector4f>(); private transient List<Box> guiAreas = new ArrayList<Box>();
@FunctionalInterface @FunctionalInterface
public interface RenderCallback { public interface RenderCallback {
@ -187,7 +187,7 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
protected void root(int x, int y, int w, int h) { protected void root(int x, int y, int w, int h) {
assert context == null : "root can only be a root element"; assert context == null : "root can only be a root element";
Vector4f box = new Vector4f(x, y, w, h); Box box = new Box(x, y, w, h);
context = new StackingContext(true, box, box, false, false); context = new StackingContext(true, box, box, false, false);
} }
@ -200,7 +200,7 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
contextStack.push(context); contextStack.push(context);
context = new StackingContext( context = new StackingContext(
true, true,
new Vector4f(context.box.x, context.box.y, w, h), new Box(context.box.x, context.box.y, w, h),
context.occlusionBox.copy(), context.occlusionBox.copy(),
true, true,
context.horizontal context.horizontal
@ -211,7 +211,7 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
contextStack.push(context); contextStack.push(context);
context = new StackingContext( context = new StackingContext(
false, false,
new Vector4f(context.box.x, context.box.y, context.box.z, 0), new Box(context.box.x, context.box.y, context.box.w, 0),
context.occlusionBox.copy(), context.occlusionBox.copy(),
true, true,
context.horizontal context.horizontal
@ -245,11 +245,11 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
} }
protected boolean button(String id, String text, boolean expand) { protected boolean button(String id, String text, boolean expand) {
float h = 32; int h = 32;
if(expand && context.fixedSize) { if(expand && context.fixedSize) {
h = context.box.w; h = (int) context.box.h;
} }
float w = context.box.z; int w = (int) context.box.w;
if(context.horizontal && !context.fixedSize) { if(context.horizontal && !context.fixedSize) {
w = 100; w = 100;
} }
@ -259,13 +259,13 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
if(!context.fixedSize) { if(!context.fixedSize) {
if(context.vertical()) { if(context.vertical()) {
y += (int) context.box.w; y += (int) context.box.h;
} else { } else {
x += (int) context.box.z; x += (int) context.box.w;
} }
} }
Vector4f buttonBox = new Vector4f(x, y, w, h); Box buttonBox = new Box(x, y, w, h);
Button btn = getButton(id); Button btn = getButton(id);
if(!context.hasRegisteredGuiArea) { if(!context.hasRegisteredGuiArea) {
@ -274,10 +274,10 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
btn.setText(text); btn.setText(text);
btn.setPosition(x, y); btn.setPosition(x, y);
btn.setSize((int) buttonBox.z, (int) buttonBox.w); btn.setSize(w, h);
btn.setLayer(getCurrentLayer()); btn.setLayer(getCurrentLayer());
adjustBox(buttonBox.z, buttonBox.w); adjustBox(buttonBox.w, buttonBox.h);
return getClick(btn); return getClick(btn);
} }
@ -291,8 +291,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
protected void group() { protected void group() {
contextStack.push(context); contextStack.push(context);
context = new StackingContext(false, context = new StackingContext(false,
new Vector4f( new Box(
context.box.x, context.box.y, context.box.z, 0 context.box.x, context.box.y, context.box.w, 0
), ),
context.occlusionBox.copy(), context.occlusionBox.copy(),
context.hasRegisteredGuiArea, context.hasRegisteredGuiArea,
@ -304,18 +304,18 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
protected void groupEnd() { protected void groupEnd() {
padEnd(); padEnd();
Drawing.setLayer(getPreviousLayer()); Drawing.setLayer(getPreviousLayer());
float h = context.box.w; float h = context.box.h;
Assets.uiFrame.draw(context.box); Assets.uiFrame.draw(context.box);
context = contextStack.pop(); context = contextStack.pop();
adjustBox(context.box.z, h); adjustBox(context.box.w, h);
} }
protected void pad() { protected void pad() {
contextStack.push(context); contextStack.push(context);
if(context.fixedSize) { if(context.fixedSize) {
context = new StackingContext(true, context = new StackingContext(true,
new Vector4f( new Box(
context.box.x + 8, context.box.y + 8, context.box.z - 16, context.box.w - 16 context.box.x + 8, context.box.y + 8, context.box.w - 16, context.box.h - 16
), ),
context.occlusionBox.copy(), context.occlusionBox.copy(),
context.hasRegisteredGuiArea, context.hasRegisteredGuiArea,
@ -323,8 +323,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
); );
} else { } else {
context = new StackingContext(false, context = new StackingContext(false,
new Vector4f( new Box(
context.box.x + 8, context.box.y + 8, context.box.z - 16, 0 context.box.x + 8, context.box.y + 8, context.box.w - 16, 0
), ),
context.occlusionBox.copy(), context.occlusionBox.copy(),
context.hasRegisteredGuiArea, context.hasRegisteredGuiArea,
@ -334,23 +334,23 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
} }
protected void padEnd() { protected void padEnd() {
float h = context.box.w + 16; float h = context.box.h + 16;
context = contextStack.pop(); context = contextStack.pop();
adjustBox(context.box.z + 16, h); adjustBox(context.box.w + 16, h);
} }
protected void horizontal(RenderCallback cb) { protected void horizontal(RenderCallback cb) {
contextStack.push(context); contextStack.push(context);
context = new StackingContext( context = new StackingContext(
false, false,
new Vector4f(context.box.x, context.box.y, 0, 0), new Box(context.box.x, context.box.y, 0, 0),
context.occlusionBox, context.occlusionBox,
context.hasRegisteredGuiArea, context.hasRegisteredGuiArea,
true true
); );
cb.apply(); cb.apply();
float w = context.box.z; float w = context.box.w;
float h = context.box.w; float h = context.box.h;
context = contextStack.pop(); context = contextStack.pop();
adjustBox(w, h); adjustBox(w, h);
} }
@ -398,9 +398,9 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
if(!context.fixedSize) { if(!context.fixedSize) {
if(context.vertical()) { if(context.vertical()) {
y += (int) context.box.w; y += (int) context.box.h;
} else { } else {
x += (int) context.box.z; x += (int) context.box.w;
} }
} }

View File

@ -1,7 +1,6 @@
package xyz.valnet.engine.graphics; package xyz.valnet.engine.graphics;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector4i;
public class Tile9 { public class Tile9 {
@ -37,12 +36,8 @@ public class Tile9 {
this.bottomRight = bottomRight; this.bottomRight = bottomRight;
} }
public void draw(Vector4f box) { public void draw(Box box) {
draw(box.asInt()); draw((int) box.x, (int) box.y, (int) box.w, (int) box.h);
}
public void draw(Vector4i box) {
draw(box.x, box.y, box.z, box.w);
} }
public void draw(int x, int y, int w, int h) { public void draw(int x, int y, int w, int h) {

View File

@ -0,0 +1,54 @@
package xyz.valnet.engine.math;
public class Box {
public final float x, y, w, h, x2, y2;
public final Vector2f a, b;
public static final Box none = new Box(0, 0, 0, 0);
public Box(float x, float y, float w, float h) {
if(w < 0) {
this.w = Math.abs(w);
this.x = x + w;
} else {
this.x = x;
this.w = w;
}
if(h < 0) {
this.h = Math.abs(h);
this.y = y + h;
} else {
this.y = y;
this.h = h;
}
this.x2 = this.x + this.w;
this.y2 = this.y + this.h;
this.a = new Vector2f(this.x, this.y);
this.b = new Vector2f(this.x2, this.y2);
}
public static Box fromPoints(Vector2f a, Vector2f b) {
return new Box(a.x, a.y, b.x - a.x, b.y - a.y);
}
public static Box fromPoints(Vector2f a, float x2, float y2) {
return new Box(a.x, a.y, x2 - a.x, y2 - a.y);
}
public static Box fromPoints(float x, float y, Vector2f b) {
return new Box(x, y, b.x - x, b.y - y);
}
public static Box fromPoints(float x, float y, float x2, float y2) {
return new Box(x, y, x2 - x, y2 - y);
}
public Box copy() {
return new Box(x, y, w, h);
}
public boolean contains(float x, float y) {
return x >= this.x && x < this.x2 && y >= this.y && y < this.y2;
}
}

View File

@ -55,4 +55,8 @@ public class Vector2i implements Serializable {
return new Vector2i(x - 1, y); return new Vector2i(x - 1, y);
} }
public Box getTileBox() {
return new Box(x, y, 1, 1);
}
} }

View File

@ -2,16 +2,18 @@ package xyz.valnet.engine.scenegraph;
import java.util.List; import java.util.List;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Box;
public interface IMouseCaptureArea { public interface IMouseCaptureArea {
public void mouseEnter();
public void mouseLeave(); public default void mouseEnter() {}
public default void mouseLeave() {}
public List<Box> getGuiBoxes();
public float getLayer();
public void mouseDown(int button); public void mouseDown(int button);
public void mouseUp(int button); public void mouseUp(int button);
public default void scrollUp() {} public default void scrollUp() {}
public default void scrollDown() {} public default void scrollDown() {}
public List<Vector4f> getGuiBoxes();
public float getLayer();
} }

View File

@ -15,6 +15,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import xyz.valnet.engine.App; import xyz.valnet.engine.App;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
public abstract class SceneGraph implements IScene { public abstract class SceneGraph implements IScene {
@ -91,7 +92,7 @@ public abstract class SceneGraph implements IScene {
}); });
for(IMouseCaptureArea listener : mouseListeners) { for(IMouseCaptureArea listener : mouseListeners) {
for(Vector4f guiBox : listener.getGuiBoxes()) { for(Box guiBox : listener.getGuiBoxes()) {
boolean currentlyEntered = guiBox.contains(App.mouseX, App.mouseY); boolean currentlyEntered = guiBox.contains(App.mouseX, App.mouseY);
if(currentlyEntered) { if(currentlyEntered) {
if(listener != hoveredMouseListener) { if(listener != hoveredMouseListener) {

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Matrix4f; import xyz.valnet.engine.math.Matrix4f;
import xyz.valnet.engine.math.Vector3f; import xyz.valnet.engine.math.Vector3f;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -123,6 +124,11 @@ public class Shader {
glUniform4f(getUniform(name), vector.x, vector.y, vector.z, vector.w); glUniform4f(getUniform(name), vector.x, vector.y, vector.z, vector.w);
} }
public void setUniform4f(String name, Color c) {
if (!enabled) enable();
glUniform4f(getUniform(name), c.r, c.g, c.b, c.a);
}
public void setUniformMat4f(String name, Matrix4f matrix) { public void setUniformMat4f(String name, Matrix4f matrix) {
if (!enabled) enable(); if (!enabled) enable();
glUniformMatrix4fv(getUniform(name), false, matrix.toFloatBuffer()); glUniformMatrix4fv(getUniform(name), false, matrix.toFloatBuffer());

View File

@ -1,14 +1,14 @@
package xyz.valnet.engine.shaders; package xyz.valnet.engine.shaders;
import java.util.Stack;
import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL20.*;
import xyz.valnet.engine.math.Vector4f; import java.util.Stack;
import xyz.valnet.engine.graphics.Color;
public class SimpleShader extends Shader { public class SimpleShader extends Shader {
private Stack<Vector4f> colorStack = new Stack<Vector4f>(); private Stack<Color> colorStack = new Stack<Color>();
public final static int COLOR = 1; public final static int COLOR = 1;
public final static int TEX_COORD = 2; public final static int TEX_COORD = 2;
@ -17,12 +17,12 @@ public class SimpleShader extends Shader {
super(vertPath, fragPath); super(vertPath, fragPath);
} }
public void pushColor(Vector4f color) { public void pushColor(Color color) {
colorStack.push(color); colorStack.push(color);
setUniform4f("uColor", color); setUniform4f("uColor", color);
} }
public void swapColor(Vector4f color) { public void swapColor(Color color) {
popColor(); popColor();
pushColor(color); pushColor(color);
} }
@ -33,10 +33,10 @@ public class SimpleShader extends Shader {
public void popColor() { public void popColor() {
colorStack.pop(); colorStack.pop();
Vector4f newColor = colorStack.peek(); Color newColor = colorStack.peek();
if(newColor == null) { if(newColor == null) {
setUniform4f("uColor", Vector4f.one); setUniform4f("uColor", Color.white);
return; return;
} }
setUniform4f("uColor", newColor); setUniform4f("uColor", newColor);

View File

@ -5,6 +5,7 @@ import java.util.List;
import xyz.valnet.engine.App; import xyz.valnet.engine.App;
import xyz.valnet.engine.Game; import xyz.valnet.engine.Game;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.graphics.Drawing; import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Matrix4f; import xyz.valnet.engine.math.Matrix4f;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -22,7 +23,7 @@ public class HadeanGame extends Game {
@Override @Override
public void start() { public void start() {
Assets.flat.pushColor(Vector4f.one); Assets.flat.pushColor(Color.white);
changeScene(new GameScene()); changeScene(new GameScene());
} }
@ -37,7 +38,7 @@ public class HadeanGame extends Game {
} }
private static Runtime runtime = Runtime.getRuntime(); private static Runtime runtime = Runtime.getRuntime();
private static Vector4f fontColor = new Vector4f(1, 0, 0, 1); private static Color fontColor = Color.red;
private void renderDebugInfo() { private void renderDebugInfo() {
@ -54,7 +55,7 @@ public class HadeanGame extends Game {
strings.add("dTime: " + dTime); strings.add("dTime: " + dTime);
for(String str : strings) { for(String str : strings) {
Assets.flat.pushColor(Vector4f.black); Assets.flat.pushColor(Color.black);
Assets.font.drawString(str, left + 1, top + 1); Assets.font.drawString(str, left + 1, top + 1);
Assets.flat.swapColor(fontColor); Assets.flat.swapColor(fontColor);
Assets.font.drawString(str, left, top); Assets.font.drawString(str, left, top);

View File

@ -5,9 +5,11 @@ import static xyz.valnet.engine.util.Math.*;
import java.util.List; import java.util.List;
import xyz.valnet.engine.App; import xyz.valnet.engine.App;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.graphics.Drawing; import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.graphics.Sprite; import xyz.valnet.engine.graphics.Sprite;
import xyz.valnet.engine.graphics.Tile9; import xyz.valnet.engine.graphics.Tile9;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector2f; import xyz.valnet.engine.math.Vector2f;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -37,6 +39,10 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
maxY = bounds.w; maxY = bounds.w;
} }
public Vector2f getWorldMouse() {
return screen2world(App.mouseX, App.mouseY);
}
public void update(float dTime) { public void update(float dTime) {
Vector2f direction = Vector2f.zero; Vector2f direction = Vector2f.zero;
if(dragOrigin == null) { if(dragOrigin == null) {
@ -124,6 +130,10 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
Drawing.drawSprite(sprite, (int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h)); Drawing.drawSprite(sprite, (int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
} }
public void draw(float layer, Tile9 sprite, Box box) {
draw(layer, sprite, box.x, box.y, box.w, box.h);
}
public void draw(float layer, Tile9 sprite, float x, float y, float w, float h) { public void draw(float layer, Tile9 sprite, float x, float y, float w, float h) {
Vector2i screenPos = world2screen(x, y); Vector2i screenPos = world2screen(x, y);
Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY))); Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY)));
@ -134,9 +144,9 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
int h = 6; int h = 6;
Vector4i box = world2screen(worldBox).toXYWH().asInt(); Vector4i box = world2screen(worldBox).toXYWH().asInt();
Drawing.setLayer(Layers.GENERAL_UI); Drawing.setLayer(Layers.GENERAL_UI);
Assets.flat.pushColor(new Vector4f(0, 0, 0, 1)); Assets.flat.pushColor(Color.black);
Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h); Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h);
Assets.flat.swapColor(new Vector4f(1, 1, 0, 1)); Assets.flat.swapColor(Color.yellow);
Assets.fillColor.draw(box.x + 1 - h, box.y + 1 + box.w / 2 - h / 2, (int)Math.round(lerp(0, box.z - 3 + h * 2, progress)) + 1, h - 2); Assets.fillColor.draw(box.x + 1 - h, box.y + 1 + box.w / 2 - h / 2, (int)Math.round(lerp(0, box.z - 3 + h * 2, progress)) + 1, h - 2);
Assets.flat.popColor(); Assets.flat.popColor();
} }
@ -164,8 +174,8 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
} }
@Override @Override
public List<Vector4f> getGuiBoxes() { public List<Box> getGuiBoxes() {
return List.of(Vector4f.zero); return List.of(Box.none);
} }
@Override @Override

View File

@ -9,6 +9,7 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.engine.scenegraph.GameObject;
@ -46,18 +47,18 @@ public class JobBoard extends GameObject {
super.render(); super.render();
if(HadeanGame.debugView) { if(HadeanGame.debugView) {
float opacity = 0.6f; float opacity = 0.6f;
Assets.flat.pushColor(new Vector4f(1, 0.8f, 0, opacity)); Assets.flat.pushColor(Color.orange.withAlpha(opacity));
for(Job job : availableJobs) { for(Job job : availableJobs) {
for(Vector2i position : job.getLocations()) { for(Vector2i position : job.getLocations()) {
if(job.isValid()) { if(job.isValid()) {
Assets.flat.swapColor(new Vector4f(1, 0.8f, 0, opacity)); Assets.flat.swapColor(Color.orange.withAlpha(opacity));
} else { } else {
Assets.flat.swapColor(new Vector4f(1.0f, 0.2f, 0, opacity)); Assets.flat.swapColor(Color.red.withAlpha(opacity));
} }
camera.draw(Layers.GROUND_MARKERS, Assets.fillTile, position.asFloat()); camera.draw(Layers.GROUND_MARKERS, Assets.fillTile, position.asFloat());
} }
} }
Assets.flat.swapColor(new Vector4f(0.2f, 1.0f, 0, opacity)); Assets.flat.swapColor(Color.lime.withAlpha(opacity));
for(Job job : allocations.values()) { for(Job job : allocations.values()) {
for(Vector2i position : job.getLocations()) { for(Vector2i position : job.getLocations()) {
camera.draw(Layers.GROUND_MARKERS, Assets.fillTile, position.asFloat()); camera.draw(Layers.GROUND_MARKERS, Assets.fillTile, position.asFloat());

View File

@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.math.Vector4i;
@ -27,7 +28,7 @@ public class Tile extends WorldObject implements IWorkable {
private static int greenSeed = (int)(Math.random() * 10000); private static int greenSeed = (int)(Math.random() * 10000);
private static int blueSeed = (int)(Math.random() * 10000); private static int blueSeed = (int)(Math.random() * 10000);
private Vector4f color; private Color color;
private final int tileSelector = (int)Math.floor(Math.random() * 4); private final int tileSelector = (int)Math.floor(Math.random() * 4);
private boolean rocks = false; private boolean rocks = false;
@ -55,7 +56,7 @@ public class Tile extends WorldObject implements IWorkable {
float green = (float) terrain.getNoise(greenSeed, pos.x * scale, pos.y * scale); float green = (float) terrain.getNoise(greenSeed, pos.x * scale, pos.y * scale);
float blue = (float) terrain.getNoise(blueSeed, pos.x * scale, pos.y * scale); float blue = (float) terrain.getNoise(blueSeed, pos.x * scale, pos.y * scale);
if(color == null) color = new Vector4f(red * 0.1f, 0.4f + green * 0.15f, blue * 0.05f, 1f); if(color == null) color = new Color(red * 0.1f, 0.4f + green * 0.15f, blue * 0.05f, 1f);
} }
@Override @Override
@ -166,7 +167,7 @@ public class Tile extends WorldObject implements IWorkable {
if(rocks) camera.draw(Layers.TILES, Assets.rocks, pos.x, pos.y); if(rocks) camera.draw(Layers.TILES, Assets.rocks, pos.x, pos.y);
} }
if(tillLevel > 0f) { if(tillLevel > 0f) {
Assets.flat.pushColor(Vector4f.opacity(tillLevel)); Assets.flat.pushColor(Color.white.withAlpha(tillLevel));
camera.draw(Layers.TILES, Assets.farmPlot[tileSelector], pos.x, pos.y); camera.draw(Layers.TILES, Assets.farmPlot[tileSelector], pos.x, pos.y);
Assets.flat.popColor(); Assets.flat.popColor();
} }

View File

@ -3,8 +3,8 @@ package xyz.valnet.hadean.gameobjects.inputlayer;
import java.util.List; import java.util.List;
import xyz.valnet.engine.App; import xyz.valnet.engine.App;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.engine.scenegraph.GameObject;
import xyz.valnet.engine.scenegraph.IMouseCaptureArea; import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
import xyz.valnet.engine.scenegraph.ITransient; import xyz.valnet.engine.scenegraph.ITransient;
@ -121,8 +121,6 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
} }
} }
private Vector2i[] orderCoords(Vector2i a, Vector2i b) { private Vector2i[] orderCoords(Vector2i a, Vector2i b) {
return new Vector2i[] { return new Vector2i[] {
new Vector2i(Math.min(a.x, b.x), Math.min(a.y, b.y)), new Vector2i(Math.min(a.x, b.x), Math.min(a.y, b.y)),
@ -132,8 +130,8 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
} }
@Override @Override
public List<Vector4f> getGuiBoxes() { public List<Box> getGuiBoxes() {
return List.of(active ? new Vector4f(0, 0, 1024, 576) : Vector4f.zero); return List.of(active ? new Box(0, 0, 1024, 576) : Box.none);
} }
@Override @Override

View File

@ -7,6 +7,7 @@ import java.util.List;
import xyz.valnet.engine.App; import xyz.valnet.engine.App;
import xyz.valnet.engine.graphics.Drawing; import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector2f; import xyz.valnet.engine.math.Vector2f;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -92,13 +93,10 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
} }
if(initialCoords != null) { if(initialCoords != null) {
Vector2i screenPos = camera.world2screen(initialCoords); camera.draw(Layers.AREA_SELECT_BOX, Assets.selectionFrame, Box.fromPoints(
Assets.selectionFrame.draw(new Vector4i( initialCoords,
screenPos.x, camera.getWorldMouse()
screenPos.y, ));
App.mouseX,
App.mouseY
).toXYWH());
} }
} }
@ -189,8 +187,8 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
} }
@Override @Override
public List<Vector4f> getGuiBoxes() { public List<Box> getGuiBoxes() {
return List.of(new Vector4f(0, 0, 1000, 1000)); return List.of(new Box(0, 0, 10000, 10000));
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.graphics.Drawing; import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -109,12 +110,12 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
if(!opened || selectedBuildable == null) return; if(!opened || selectedBuildable == null) return;
// draw the currently selected build item // draw the currently selected build item
Assets.flat.pushColor(new Vector4f(1f, 1f, 1f, 1.0f)); Assets.flat.pushColor(Color.white);
Vector2i topLeft = camera.world2screen(x, y); Vector2i topLeft = camera.world2screen(x, y);
Assets.font.drawString(selectedBuildable.name, topLeft.x, topLeft.y - 20); Assets.font.drawString(selectedBuildable.name, topLeft.x, topLeft.y - 20);
Assets.flat.swapColor(new Vector4f(1f, 1f, 1f, 0.6f)); Assets.flat.swapColor(Color.white.withAlpha(0.6f));
camera.draw(Layers.BUILD_INTERACTABLE, Assets.selectionFrame, x, y, w, h); camera.draw(Layers.BUILD_INTERACTABLE, Assets.selectionFrame, x, y, w, h);
Assets.flat.swapColor(new Vector4f(1f, 1f, 1f, 0.35f)); Assets.flat.swapColor(Color.white.withAlpha(0.35f));
for(int i = 0; i < w; i ++) for(int j = 0; j < h; j ++) {{ 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); camera.draw(Layers.BUILD_INTERACTABLE, Assets.checkerBoard, x + i, y + j);
}} }}

View File

@ -1,6 +1,6 @@
package xyz.valnet.hadean.gameobjects.worldobjects; package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.hadean.gameobjects.Tile; import xyz.valnet.hadean.gameobjects.Tile;
import xyz.valnet.hadean.interfaces.BuildableMetadata; import xyz.valnet.hadean.interfaces.BuildableMetadata;
@ -16,7 +16,7 @@ public class FarmPlot extends Buildable {
public void renderAlpha() { public void renderAlpha() {
if(!visible) return; if(!visible) return;
Vector4i pos = getWorldPosition(); Vector4i pos = getWorldPosition();
Assets.flat.pushColor(new Vector4f(0.4f, 1f, 0.3f, 0.2f)); Assets.flat.pushColor(new Color(0.4f, 1f, 0.3f, 0.2f));
camera.draw(Layers.GROUND, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w); camera.draw(Layers.GROUND, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w);
Assets.flat.popColor(); Assets.flat.popColor();
} }

View File

@ -1,7 +1,7 @@
package xyz.valnet.hadean.gameobjects.worldobjects; package xyz.valnet.hadean.gameobjects.worldobjects;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item; import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
import xyz.valnet.hadean.util.Action; import xyz.valnet.hadean.util.Action;
import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Assets;
@ -20,7 +20,7 @@ public class Rice extends Item {
Vector2i pos = getWorldPosition().xy(); Vector2i pos = getWorldPosition().xy();
camera.draw(Layers.AIR, Assets.riceBag, pos.x, pos.y); camera.draw(Layers.AIR, Assets.riceBag, pos.x, pos.y);
Assets.flat.pushColor(Vector4f.black); Assets.flat.pushColor(Color.black);
Vector2i screeCoords = camera.world2screen(pos.x, pos.y); Vector2i screeCoords = camera.world2screen(pos.x, pos.y);
Assets.miniFont.drawString("123", (int)screeCoords.x, (int)screeCoords.y); Assets.miniFont.drawString("123", (int)screeCoords.x, (int)screeCoords.y);
Assets.flat.popColor(); Assets.flat.popColor();

View File

@ -2,8 +2,8 @@ package xyz.valnet.hadean.gameobjects.worldobjects;
import java.util.Set; import java.util.Set;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.hadean.gameobjects.Tile; import xyz.valnet.hadean.gameobjects.Tile;
import xyz.valnet.hadean.interfaces.BuildableMetadata; import xyz.valnet.hadean.interfaces.BuildableMetadata;
@ -24,7 +24,7 @@ public class Stockpile extends Buildable {
public void renderAlpha() { public void renderAlpha() {
if(!visible) return; if(!visible) return;
Vector4i pos = getWorldPosition(); Vector4i pos = getWorldPosition();
Assets.flat.pushColor(new Vector4f(1f, 0.2f, 0.1f, 0.3f)); Assets.flat.pushColor(new Color(1f, 0.2f, 0.1f, 0.3f));
camera.draw(Layers.TILES, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w); camera.draw(Layers.TILES, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w);
Assets.flat.popColor(); Assets.flat.popColor();
} }

View File

@ -6,6 +6,7 @@ import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glVertex3f; import static org.lwjgl.opengl.GL11.glVertex3f;
import static org.lwjgl.opengl.GL20.glVertexAttrib2f; import static org.lwjgl.opengl.GL20.glVertexAttrib2f;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.graphics.Drawing; import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.math.Vector2f; import xyz.valnet.engine.math.Vector2f;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
@ -160,7 +161,7 @@ public abstract class Agent extends WorldObject implements ISelectable {
public void renderAlpha() { public void renderAlpha() {
if(!HadeanGame.debugView) return; if(!HadeanGame.debugView) return;
Drawing.setLayer(Layers.GROUND_MARKERS); Drawing.setLayer(Layers.GROUND_MARKERS);
Assets.flat.pushColor(Vector4f.opacity(0.6f)); Assets.flat.pushColor(Color.white.withAlpha(0.6f));
if(path != null) { if(path != null) {
int count = 0; int count = 0;
for(Node node : path) { for(Node node : path) {
@ -184,15 +185,7 @@ public abstract class Agent extends WorldObject implements ISelectable {
count ++; count ++;
} }
Assets.selectionFrame.draw( camera.draw(Layers.GROUND_MARKERS, Assets.selectionFrame, path.getDestination().getPosition().getTileBox());
camera.world2screen(
terrain.getTile(
path.getDestination().getPosition()
)
.getWorldBox()
)
.toXYWH()
);
} }
Assets.flat.popColor(); Assets.flat.popColor();
} }

View File

@ -1,5 +1,6 @@
package xyz.valnet.hadean.gameobjects.worldobjects.constructions; package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.Job; import xyz.valnet.hadean.gameobjects.Job;
@ -53,7 +54,7 @@ public class Bed extends Buildable implements IItemReceiver, IWorkable {
float p = work / maxWork; float p = work / maxWork;
float b = 4; float b = 4;
Assets.flat.pushColor(new Vector4f(b, b, b, 0.5f)); Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2); camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2);
Assets.flat.popColor(); Assets.flat.popColor();

View File

@ -1,5 +1,6 @@
package xyz.valnet.hadean.gameobjects.worldobjects.constructions; package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.hadean.gameobjects.Job; import xyz.valnet.hadean.gameobjects.Job;
@ -29,7 +30,7 @@ public class Quarry extends Construction {
} else { } else {
float b = 4; float b = 4;
Assets.flat.pushColor(new Vector4f(b, b, b, 0.5f)); Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
camera.draw(Layers.GROUND, Assets.quarry, getWorldPosition()); camera.draw(Layers.GROUND, Assets.quarry, getWorldPosition());
Assets.flat.popColor(); Assets.flat.popColor();

View File

@ -2,6 +2,7 @@ package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
import java.util.EnumSet; import java.util.EnumSet;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.graphics.Tile16.Direction; import xyz.valnet.engine.graphics.Tile16.Direction;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -58,14 +59,14 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
if(isBuilt()) { if(isBuilt()) {
float b = 0.7f; float b = 0.7f;
Assets.flat.pushColor(new Vector4f(b, b, b, 1f)); Assets.flat.pushColor(Color.grey(b));
camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y); camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y);
Assets.flat.popColor(); Assets.flat.popColor();
} else { } else {
float p = work / maxWork; float p = work / maxWork;
float b = 4; float b = 4;
Assets.flat.pushColor(new Vector4f(b, b, b, 0.5f)); Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y); camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y);
Assets.flat.popColor(); Assets.flat.popColor();

View File

@ -5,6 +5,7 @@ import static xyz.valnet.hadean.util.detail.Detail.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.math.Vector2f; import xyz.valnet.engine.math.Vector2f;
import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
@ -111,9 +112,9 @@ public class Pawn extends Agent {
public void render() { public void render() {
super.render(); super.render();
if(currentActivity instanceof SleepActivity) { if(currentActivity instanceof SleepActivity) {
Assets.flat.pushColor(new Vector4f(0.5f, 0.5f, 0.5f, 1.0f)); Assets.flat.pushColor(Color.grey(0.5f));
} else { } else {
Assets.flat.pushColor(Vector4f.one); Assets.flat.pushColor(Color.white);
} }
camera.draw(Layers.PAWNS, Assets.pawn, getCalculatedPosition()); camera.draw(Layers.PAWNS, Assets.pawn, getCalculatedPosition());
Assets.flat.popColor(); Assets.flat.popColor();

View File

@ -4,8 +4,10 @@ import static xyz.valnet.engine.util.Math.*;
import java.util.List; import java.util.List;
import xyz.valnet.engine.graphics.Color;
import xyz.valnet.engine.graphics.Drawing; import xyz.valnet.engine.graphics.Drawing;
import xyz.valnet.engine.graphics.Tile9; import xyz.valnet.engine.graphics.Tile9;
import xyz.valnet.engine.math.Box;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.math.Vector4i;
import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.engine.scenegraph.GameObject;
@ -80,10 +82,10 @@ public class Button extends GameObject implements IMouseCaptureArea, ITransient
Assets.uiFrame.draw(box.x, box.y, box.z, box.w); Assets.uiFrame.draw(box.x, box.y, box.z, box.w);
} }
Assets.flat.pushColor(Vector4f.black); Assets.flat.pushColor(Color.black);
Assets.font.drawString(text, 1 + x + (width - textWidth) / 2, 1 + y + (height - textHeight) / 2); Assets.font.drawString(text, 1 + x + (width - textWidth) / 2, 1 + y + (height - textHeight) / 2);
Assets.flat.swapColor(Vector4f.one); Assets.flat.swapColor(Color.white);
Assets.font.drawString(text, x + (width - textWidth) / 2, y + (height - textHeight) / 2); Assets.font.drawString(text, x + (width - textWidth) / 2, y + (height - textHeight) / 2);
Assets.flat.popColor(); Assets.flat.popColor();
@ -224,8 +226,8 @@ public class Button extends GameObject implements IMouseCaptureArea, ITransient
} }
@Override @Override
public List<Vector4f> getGuiBoxes() { public List<Box> getGuiBoxes() {
return List.of(new Vector4f(x, y, width, height)); return List.of(new Box(x, y, width, height));
} }
@Override @Override

View File

@ -1,100 +0,0 @@
package xyz.valnet.hadean.scenes;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.IScene;
import xyz.valnet.hadean.input.Button;
import xyz.valnet.hadean.input.IButtonListener;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
import static xyz.valnet.hadean.HadeanGame.Hadean;
// TODO convert this to a scenegraph
public class MenuScene implements IScene, IButtonListener {
private Button btnNewGame = new Button(Assets.frame, "New Game", 50, 200, 128, 32, Layers.GENERAL_UI);
private Button btnLoadGame = new Button(Assets.frame, "Load Game", 50, 240, 128, 32, Layers.GENERAL_UI);
private Button btnOptions = new Button(Assets.frame, "Options", 50, 280, 128, 32, Layers.GENERAL_UI);
private Button btnQuit = new Button(Assets.frame, "Quit", 50, 320, 128, 32, Layers.GENERAL_UI);
public MenuScene() {
btnNewGame.registerClickListener(this);
btnLoadGame.registerClickListener(this);
btnOptions.registerClickListener(this);
btnQuit.registerClickListener(this);
}
public Vector4f green = new Vector4f(0.0f, 1.0f, 0.2f, 1.0f);
public Vector4f cyan = new Vector4f(0.1f, 0.7f, 1.0f, 1.0f);
public Vector4f yellow = new Vector4f(1.0f, 1.0f, 0.0f, 1.0f);
public Vector4f red = new Vector4f(1.0f, 0.1f, 0.1f, 1.0f);
@Override
public void render() {
Assets.flat.pushColor(green);
btnNewGame.render();
Assets.flat.swapColor(cyan);
btnLoadGame.render();
Assets.flat.swapColor(yellow);
btnOptions.render();
Assets.flat.swapColor(red);
btnQuit.render();
Assets.flat.popColor();
}
@Override
public void update(float dTime) {
// btnNewGame.setMouseCoords(App.mouseX, App.mouseY);
// btnLoadGame.setMouseCoords(App.mouseX, App.mouseY);
// btnOptions.setMouseCoords(App.mouseX, App.mouseY);
// btnQuit.setMouseCoords(App.mouseX, App.mouseY);
btnNewGame.update();
btnLoadGame.update();
btnOptions.update();
btnQuit.update();
}
@Override
public void click(Button target) {
if(target == btnNewGame) {
newGame();
} else if(target == btnQuit) {
quit();
}
}
private void newGame() {
Hadean.changeScene(new GameScene());
}
private void quit() {
}
@Override
public void enable() {
}
@Override
public void disable() {
}
@Override
public void mouseDown(int button) {
btnNewGame.mouseDown(button);
btnLoadGame.mouseDown(button);
btnOptions.mouseDown(button);
btnQuit.mouseDown(button);
}
@Override
public void mouseUp(int button) {
btnNewGame.mouseUp(button);
btnLoadGame.mouseUp(button);
btnOptions.mouseUp(button);
btnQuit.mouseUp(button);
}
}