Compare commits
2 Commits
7afa863ee8
...
dd775f6d9c
| Author | SHA1 | Date |
|---|---|---|
|
|
dd775f6d9c | |
|
|
634f48d941 |
|
|
@ -25,7 +25,8 @@ public class App {
|
|||
|
||||
// The window handle
|
||||
private long window;
|
||||
private int width = 1024, height = 576;
|
||||
// private int width = 1024, height = 576;
|
||||
private int width = 1600, height = 900;
|
||||
private Matrix4f matrix = Matrix4f.orthographic(0, width, height, 0, 0, 100);
|
||||
public static int mouseX, mouseY;
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ public class App {
|
|||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // the window will be resizable
|
||||
|
||||
// Create the window
|
||||
window = glfwCreateWindow(width, height, "Hello World!", NULL, NULL);
|
||||
window = glfwCreateWindow(width, height, "Val Engine", NULL, NULL);
|
||||
if ( window == NULL )
|
||||
throw new RuntimeException("Failed to create the GLFW window");
|
||||
|
||||
|
|
@ -94,11 +95,6 @@ public class App {
|
|||
game.scrollUp();
|
||||
else if(yOffset < 0)
|
||||
game.scrollDown();
|
||||
|
||||
// if(yOffset > 0)
|
||||
// game.scrollLeft();
|
||||
// else if(yOffset < 0)
|
||||
// game.scrollRight();
|
||||
});
|
||||
|
||||
glfwSetMouseButtonCallback(window, (long window, int button, int action, int mods) -> {
|
||||
|
|
@ -179,7 +175,7 @@ public class App {
|
|||
glDepthMask(true);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
|
||||
game.resize(width, height);
|
||||
game.start();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package xyz.valnet.engine;
|
|||
import static xyz.valnet.engine.util.Math.lerp;
|
||||
|
||||
import xyz.valnet.engine.math.Matrix4f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.IScene;
|
||||
|
||||
public abstract class Game {
|
||||
|
|
@ -14,6 +15,8 @@ public abstract class Game {
|
|||
private int framesSinceKeyframe = 0;
|
||||
private long lastFrame = System.nanoTime();
|
||||
private long lastKeyframe = System.nanoTime();
|
||||
|
||||
private Vector2i bufferDimensions = new Vector2i(0, 0);
|
||||
|
||||
public abstract void start();
|
||||
|
||||
|
|
@ -88,4 +91,12 @@ public abstract class Game {
|
|||
public final void keyRepeat(int key) {
|
||||
scene.keyRepeat(key);
|
||||
}
|
||||
|
||||
public Vector2i getBufferDimensions() {
|
||||
return bufferDimensions;
|
||||
}
|
||||
|
||||
public void resize(int width, int height) {
|
||||
bufferDimensions = new Vector2i(width, height);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
|
|||
private boolean mouseDown;
|
||||
|
||||
public void render() {
|
||||
Vector2i screenSize = getBufferDimensions();
|
||||
begin();
|
||||
gui();
|
||||
gui(screenSize.x, screenSize.y);
|
||||
end();
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
|
|||
return Layers.GENERAL_UI_INTERACTABLE;
|
||||
}
|
||||
|
||||
protected abstract void gui();
|
||||
protected abstract void gui(int screenWidth, int screenHeight);
|
||||
|
||||
private record StackingContext(
|
||||
boolean fixedSize,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
|||
|
||||
public class Vector2i implements Serializable {
|
||||
|
||||
public int x, y;
|
||||
public final int x, y;
|
||||
|
||||
public static Vector2i one = new Vector2i(1, 1);
|
||||
public static Vector2i zero = new Vector2i(0, 0);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package xyz.valnet.engine.scenegraph;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.SceneGraph.GameObjectCallback;
|
||||
import xyz.valnet.hadean.util.Pair;
|
||||
|
||||
|
|
@ -101,6 +102,10 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
|||
scene.registerRemoveListener(listener);
|
||||
}
|
||||
|
||||
protected Vector2i getBufferDimensions() {
|
||||
return scene.getBufferDimensions();
|
||||
}
|
||||
|
||||
protected void beforeRemoved() {}
|
||||
|
||||
protected void afterRemoved() {}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
|||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.Game;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
||||
import xyz.valnet.hadean.util.Pair;
|
||||
|
||||
|
|
@ -374,4 +375,8 @@ public abstract class SceneGraph implements IScene {
|
|||
public Pair<Float, Integer> getFPS() {
|
||||
return new Pair<Float, Integer>(game.getAverageFPS(), game.getMeasuredFPS());
|
||||
}
|
||||
|
||||
protected Vector2i getBufferDimensions() {
|
||||
return game.getBufferDimensions();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ import static xyz.valnet.engine.util.Math.lerp;
|
|||
public class Camera extends GameObject implements ITransient, IMouseCaptureArea {
|
||||
|
||||
private int tileWidth = 16;
|
||||
// TODO link these in some way to the real resolution. lot of work here.
|
||||
private int screenWidth = 1024, screenHeight = 576;
|
||||
|
||||
private Vector2f focus = new Vector2f(0, 0);
|
||||
|
||||
|
|
@ -90,7 +88,8 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
}
|
||||
|
||||
public final Vector2i world2screen(float x, float y) {
|
||||
return new Vector2i((int)(x * tileWidth + screenWidth / 2 - focus.x * tileWidth), (int)(y * tileWidth + screenHeight / 2 - focus.y * tileWidth));
|
||||
Vector2i bufferDim = getBufferDimensions();
|
||||
return new Vector2i((int)(x * tileWidth + bufferDim.x / 2 - focus.x * tileWidth), (int)(y * tileWidth + bufferDim.y / 2 - focus.y * tileWidth));
|
||||
}
|
||||
|
||||
public final Vector2i world2screen(Vector2f pos) {
|
||||
|
|
@ -102,7 +101,8 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
}
|
||||
|
||||
public final Vector2f screen2world(float x, float y) {
|
||||
return new Vector2f((x - screenWidth / 2 + focus.x * tileWidth) / tileWidth, (y - screenHeight / 2 + focus.y * tileWidth) / tileWidth);
|
||||
Vector2i bufferDim = getBufferDimensions();
|
||||
return new Vector2f((x - bufferDim.x / 2 + focus.x * tileWidth) / tileWidth, (y - bufferDim.y / 2 + focus.y * tileWidth) / tileWidth);
|
||||
}
|
||||
|
||||
public final Vector2f screen2world(Vector2f pos) {
|
||||
|
|
@ -111,11 +111,12 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
|
||||
// !! this takes an AABB and returns and AABB
|
||||
public final Vector4f world2screen(Vector4f input) {
|
||||
Vector2i bufferDim = getBufferDimensions();
|
||||
return new Vector4f(
|
||||
input.x * tileWidth + screenWidth / 2 - focus.x * tileWidth,
|
||||
input.y * tileWidth + screenHeight / 2 - focus.y * tileWidth,
|
||||
input.z * tileWidth + screenWidth / 2 - focus.x * tileWidth,
|
||||
input.w * tileWidth + screenHeight / 2 - focus.y * tileWidth
|
||||
input.x * tileWidth + bufferDim.x / 2 - focus.x * tileWidth,
|
||||
input.y * tileWidth + bufferDim.y / 2 - focus.y * tileWidth,
|
||||
input.z * tileWidth + bufferDim.x / 2 - focus.x * tileWidth,
|
||||
input.w * tileWidth + bufferDim.y / 2 - focus.y * tileWidth
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -216,7 +217,7 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
@Override
|
||||
public void scrollUp() {
|
||||
tileWidth *= 2;
|
||||
tileWidth = Math.min(tileWidth, 32);
|
||||
tileWidth = Math.min(tileWidth, 64);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ public class Clock extends GameObject {
|
|||
public void render() {
|
||||
Drawing.setLayer(Layers.GENERAL_UI);
|
||||
String str = toString();
|
||||
int left = 950;
|
||||
Assets.font.drawStringOutlined(str, left, 520);
|
||||
int left = getBufferDimensions().x - (1024 - 950);
|
||||
Assets.font.drawStringOutlined(str, left, getBufferDimensions().y - 56);
|
||||
}
|
||||
|
||||
public float getSunlight() {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
|
||||
@Override
|
||||
public List<Box> getGuiBoxes() {
|
||||
return List.of(active ? new Box(0, 0, 1024, 576) : Box.none);
|
||||
return List.of(active ? new Box(0, 0, getBufferDimensions()) : Box.none);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.input.Button;
|
||||
|
|
@ -28,17 +29,18 @@ public class BottomBar extends GameObject implements IButtonListener, ITransient
|
|||
}
|
||||
|
||||
public void registerButton(IBottomBarItem newItem) {
|
||||
Vector2i screen = getBufferDimensions();
|
||||
clearButtons();
|
||||
items.add(newItem);
|
||||
int n = items.size();
|
||||
|
||||
int i = 0;
|
||||
for(IBottomBarItem item : items) {
|
||||
int l = (int)((i / (float) n) * screenWidth);
|
||||
int r = (int)(((i + 1) / (float) n) * screenWidth);
|
||||
int l = (int)((i / (float) n) * screen.x);
|
||||
int r = (int)(((i + 1) / (float) n) * screen.x);
|
||||
|
||||
int w = r - l;
|
||||
Button btn = new SimpleButton(item.getTabName(), l, 576 - bottomBarHeight, w, bottomBarHeight, Layers.BOTTOM_BAR);
|
||||
Button btn = new SimpleButton(item.getTabName(), l, screen.y - bottomBarHeight, w, bottomBarHeight, Layers.BOTTOM_BAR);
|
||||
if(item.isButtonClickSilent()) btn = btn.setClickSound(false);
|
||||
btn.registerClickListener(this);
|
||||
add(btn);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class HoverQuery extends GameObject implements ITransient {
|
|||
public void render() {
|
||||
if(!visible) return;
|
||||
Drawing.setLayer(Layers.LOW_PRIORITY_UI);
|
||||
int i = 576 - BottomBar.bottomBarHeight - 24;
|
||||
int i = getBufferDimensions().y - BottomBar.bottomBarHeight - 24;
|
||||
for(String thingString : thingStrings) {
|
||||
for(String str : thingString.split("\n")) {
|
||||
Assets.font.drawStringOutlined(str, 8, i);
|
||||
|
|
|
|||
|
|
@ -6,9 +6,17 @@ import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
|||
public class Popup extends ImmediateUI {
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
protected void gui(int screenWidth, int screenHeight) {
|
||||
|
||||
window(10, 100, 1004, 200, () -> {
|
||||
int desireWidth = 500;
|
||||
int desiredHeight = 300;
|
||||
|
||||
window(
|
||||
screenWidth / 2 - desireWidth / 2,
|
||||
screenHeight / 2 - desiredHeight / 2,
|
||||
desireWidth,
|
||||
desiredHeight,
|
||||
() -> {
|
||||
header(" Popup Test");
|
||||
|
||||
horizontal(() -> {
|
||||
|
|
|
|||
|
|
@ -117,12 +117,12 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
protected void gui(int screenWidth, int screenHeight) {
|
||||
// if(selected.isEmpty()) return;
|
||||
if(!opened && openness <= 0.0001f) return;
|
||||
|
||||
// main window
|
||||
window(animate(-width - 50, 0), 576 - height - BottomBar.bottomBarHeight + 1, width, height, () -> {
|
||||
window(animate(-width - 50, 0), screenHeight - height - BottomBar.bottomBarHeight + 1, width, height, () -> {
|
||||
if(selectedByType.size() == 1) {
|
||||
if(selectedCount == 1) {
|
||||
text(properName);
|
||||
|
|
@ -132,7 +132,7 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
|
|||
if(details.length == 0) {
|
||||
text("No details available.");
|
||||
} else for(Detail detail : details) {
|
||||
text(detail.toString(30));
|
||||
text(detail.toString(20));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
@ -156,7 +156,7 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
|
|||
});
|
||||
|
||||
// actions
|
||||
window(width - 1, animate(576 + 50, 576 - 48 - BottomBar.bottomBarHeight + 1), 1024 - width + 1, 48, () -> {
|
||||
window(width - 1, animate(screenHeight + 50, screenHeight - 48 - BottomBar.bottomBarHeight + 1), screenWidth - width + 1, 48, () -> {
|
||||
if(selectedByType.size() == 1) {
|
||||
horizontal(() -> {
|
||||
for(Action action : actions) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class WorkshopOrdersUI extends ImmediateUI implements ITransient {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
protected void gui(int screenWidth, int screenHeight) {
|
||||
if(shop == null) return;
|
||||
|
||||
window(0, 0, 200, 300, () -> {
|
||||
|
|
|
|||
|
|
@ -186,12 +186,12 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
return "Build";
|
||||
}
|
||||
|
||||
public void gui() {
|
||||
public void gui(int screenWidth, int screenHeight) {
|
||||
if(!shouldRender()) return;
|
||||
|
||||
int height = 8 + 16 + 8 + buildables.size() * (32 + 8);
|
||||
|
||||
window(animate(-180, 0), 576 - BottomBar.bottomBarHeight - height + 1, 150, height, () -> {
|
||||
window(animate(-180, 0), screenHeight - BottomBar.bottomBarHeight - height + 1, 150, height, () -> {
|
||||
text("Build");
|
||||
|
||||
for(String category : buildables.keySet()) {
|
||||
|
|
@ -206,7 +206,10 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
}
|
||||
});
|
||||
|
||||
window(149, animate(576 + 50, 576 - BottomBar.bottomBarHeight - 16 - 32 + 1 - 24), 875, 48 + 24, () -> {
|
||||
window(149, animate(screenHeight + 50, screenHeight - BottomBar.bottomBarHeight - 16 - 32 + 1 - 24),
|
||||
screenWidth - (1024 - 875),
|
||||
48 + 24,
|
||||
() -> {
|
||||
if(selectedCategory == null) {
|
||||
space(20);
|
||||
text(" Select a Category...");
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
|||
protected void onOpen() {}
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
protected void gui(int screenWidth, int screenHeight) {
|
||||
if(!shouldRender()) return;
|
||||
|
||||
window(0, animate(-200, 0), 1024 - width + 1, 176, () -> {
|
||||
window(0, animate(-200, 0), screenWidth - width + 1, 176, () -> {
|
||||
for(int i = 10; i > logs.size(); i --) {
|
||||
text(" ");
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
|||
}
|
||||
});
|
||||
|
||||
window(animate(1050, 1024 - width), 0, width, 576 - BottomBar.bottomBarHeight + 1, () -> {
|
||||
window(animate(screenWidth + 30, screenWidth - width), 0, width, screenHeight - BottomBar.bottomBarHeight + 1, () -> {
|
||||
text("Debug");
|
||||
space(8);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ public class JobBoardTab extends Tab {
|
|||
private int height = 200;
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
protected void gui(int screenWidth, int screenHeight) {
|
||||
if(!shouldRender()) return;
|
||||
|
||||
window(0, animate(576 + 50, 576 - BottomBar.bottomBarHeight - height + 1), 1024, height, () -> {
|
||||
window(0, animate(screenHeight + 50, screenHeight - BottomBar.bottomBarHeight - height + 1), screenWidth, height, () -> {
|
||||
horizontal(() -> {
|
||||
vertical(() -> {
|
||||
text("Valid");
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ public class MenuTab extends Tab implements IPauser {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
protected void gui(int screenWidth, int screenHeight) {
|
||||
if(!shouldRender()) return;
|
||||
|
||||
window(1024 / 2 - width / 2, animate(-height - 50, 576 / 2 - height / 2), width, height, () -> {
|
||||
window(screenWidth / 2 - width / 2, animate(-height - 50, screenHeight / 2 - height / 2), width, height, () -> {
|
||||
text(" === Paused ===");
|
||||
space(8);
|
||||
if(button("Resume")) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ public class Tree extends WorldObject implements ISelectable, IWorkable {
|
|||
|
||||
@Override
|
||||
protected void beforeRemoved() {
|
||||
super.beforeRemoved();
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
add(new Log(pos.x, pos.y));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,13 +68,14 @@ public abstract class WorldObject extends GameObject implements IWorldObject {
|
|||
tile.placeThing(this);
|
||||
}
|
||||
|
||||
if(linkedTiles.size() == 0 && inScene()) {
|
||||
remove(this);
|
||||
}
|
||||
// ?? this shouldnt bew pivotal to anything?
|
||||
// if(linkedTiles.size() == 0 && inScene()) {
|
||||
// remove(this);
|
||||
// }
|
||||
|
||||
if(linkedTiles.size() != 0 && !inScene()) {
|
||||
add(this);
|
||||
}
|
||||
// if(linkedTiles.size() != 0 && !inScene()) {
|
||||
// add(this);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -133,4 +134,11 @@ public abstract class WorldObject extends GameObject implements IWorldObject {
|
|||
return new Box(x, y, w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeRemoved() {
|
||||
for(Tile tile : this.getTiles()) {
|
||||
tile.removeThing(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,6 +240,6 @@ public class Pawn extends Agent {
|
|||
@Override
|
||||
public boolean isWalkable() {
|
||||
// TODO thiss could be an interesting mechanic, but it may be bad
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue