bottom bar & special render for selected items
parent
e869abf9fb
commit
08f371cfd1
|
|
@ -0,0 +1,22 @@
|
|||
# Job Board
|
||||
|
||||
A job board is a class whos main function
|
||||
is a map from pawns (IWorkers?) to jobs (IWorkables)
|
||||
|
||||
the intention is that a pawn or job does not know, itself
|
||||
what its doing, but contacts the job board each frame
|
||||
to get what its current job is.
|
||||
|
||||
when a IWorkable begins to have work, it may post itself
|
||||
to the board, and when it is finished it will remove itself
|
||||
from the board, by sending messages to the board.
|
||||
|
||||
IWorkers on the other hand, are able to request a job
|
||||
from the board, and once they have it, will wimply ask
|
||||
the board for its current job each from, to attempt to do
|
||||
work. at some point, the board will simply start returning
|
||||
null instead of the IWorker's current job. to is when the
|
||||
worker knows it can move on to another action.
|
||||
|
||||
A Worker may also tell a job board, that it no longer
|
||||
wishes to do work, and the job will be released.
|
||||
|
|
@ -2,6 +2,7 @@ package xyz.valnet.hadean;
|
|||
|
||||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.Game;
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Matrix4f;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
|
||||
|
|
@ -24,7 +25,9 @@ public class HadeanGame extends Game {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
Drawing.setLayer(0);
|
||||
super.render();
|
||||
Drawing.setLayer(99);
|
||||
renderDebugInfo();
|
||||
}
|
||||
|
||||
|
|
@ -32,6 +35,7 @@ public class HadeanGame extends Game {
|
|||
private static Vector4f fontColor = new Vector4f(0, 1, 1, 1);
|
||||
|
||||
private void renderDebugInfo() {
|
||||
|
||||
long allocated = runtime.totalMemory();
|
||||
long max = runtime.maxMemory();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.input.Button;
|
||||
import xyz.valnet.hadean.input.IButtonListener;
|
||||
import xyz.valnet.hadean.input.SimpleButton;
|
||||
|
||||
public class BottomBar extends GameObject implements IButtonListener {
|
||||
public static final int bottomBarHeight = 32;
|
||||
private int screenWidth = 1024;
|
||||
|
||||
private Map<Button, IBottomBarItem> btnItemTable = new HashMap<Button, IBottomBarItem>();
|
||||
|
||||
private List<IBottomBarItem> items = new ArrayList<IBottomBarItem>();
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
items.clear();
|
||||
btnItemTable.clear();
|
||||
}
|
||||
|
||||
public void registerButton(IBottomBarItem newItem) {
|
||||
btnItemTable.clear();
|
||||
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 w = r - l;
|
||||
Button btn = new SimpleButton(item.getTabName(), l, 576 - bottomBarHeight, w, bottomBarHeight);
|
||||
|
||||
btn.registerClickListener(this);
|
||||
|
||||
btnItemTable.put(btn, item);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
for(Button btn : btnItemTable.keySet()) {
|
||||
btn.draw();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void tick(float dTime) {
|
||||
for(Button btn : btnItemTable.keySet()) {
|
||||
btn.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(Button target) {
|
||||
if(btnItemTable.containsKey(target)) {
|
||||
btnItemTable.get(target).evoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
public interface IBottomBarItem {
|
||||
public void evoke();
|
||||
|
||||
public String getTabName();
|
||||
}
|
||||
|
|
@ -8,4 +8,5 @@ public interface ISelectable {
|
|||
public Action[] getActions();
|
||||
public void runAction(Action action);
|
||||
public String details();
|
||||
public default void selectedRender() {}
|
||||
}
|
||||
|
|
@ -47,6 +47,26 @@ public class Pawn extends GameObject implements ISelectable {
|
|||
pathfinder = new AStarPathfinder(terrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectedRender() {
|
||||
if(path != null) {
|
||||
for(Node node : path) {
|
||||
glBegin(GL_LINES);
|
||||
Vector2f u, v;
|
||||
|
||||
if(node.from == null) u = camera.world2screen(x, y);
|
||||
else u = camera.world2screen(node.from.x + 0.5f, node.from.y + 0.5f);
|
||||
|
||||
v = camera.world2screen(node.x + 0.5f, node.y + 0.5f);
|
||||
glVertexAttrib2f(SimpleShader.TEX_COORD, 0, 88 / 256f);
|
||||
glVertex3f(u.x, u.y, 3f);
|
||||
glVertexAttrib2f(SimpleShader.TEX_COORD, 0, 88 / 255f);
|
||||
glVertex3f(v.x, v.y, 3f);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ public class Selection extends GameObject {
|
|||
Vector2f min = camera.world2screen(box.x - p, box.y - p);
|
||||
Vector2f max = camera.world2screen(box.z + p, box.w + p);
|
||||
Assets.selectedFrame.draw((int)min.x, (int)min.y, (int)(max.x - min.x), (int)(max.y - min.y));
|
||||
thing.selectedRender();
|
||||
}
|
||||
|
||||
if(initialCoords != null) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.Tile;
|
||||
import xyz.valnet.hadean.pathfinding.IPathable;
|
||||
import xyz.valnet.hadean.scenes.GameScene;
|
||||
|
||||
// TODO SPLIT PATHABLES. | implements IPathable, the thing that has callbacks for interfacing with a pathfinder.
|
||||
public class Terrain extends GameObject implements IPathable {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
package xyz.valnet.hadean.gameobjects.tabs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.ISelectable;
|
||||
import xyz.valnet.hadean.gameobjects.ISelectionChangeListener;
|
||||
import xyz.valnet.hadean.gameobjects.Selection;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
import static xyz.valnet.engine.util.Math.lerp;
|
||||
|
||||
public class ArchitectTab extends Tab implements ISelectionChangeListener {
|
||||
|
||||
private Selection selection;
|
||||
|
||||
private boolean opened = false;
|
||||
private float progress = 0f;
|
||||
private float width = 200;
|
||||
|
||||
private int padding = 10;
|
||||
|
||||
private float toRange(float n, float a, float b) {
|
||||
float l = b - a;
|
||||
float p = n * l;
|
||||
return a + p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
float x = toRange(progress, -width - padding, padding);
|
||||
Assets.uiFrame.draw((int) x, padding, (int) width, 576 - padding * 2 - BottomBar.bottomBarHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
selection = get(Selection.class);
|
||||
selection.subscribe(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(float dTime) {
|
||||
progress = lerp(progress, opened ? 1 : 0, 0.05f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(List<ISelectable> selected) {
|
||||
if(selected.isEmpty()) return;
|
||||
opened = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evoke() {
|
||||
opened = !opened;
|
||||
if(opened) {
|
||||
selection.updateSelection(new ArrayList<ISelectable>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabName() {
|
||||
return "Build";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package xyz.valnet.hadean.gameobjects.tabs;
|
||||
|
||||
public class MenuTab extends Tab {
|
||||
|
||||
@Override
|
||||
public void evoke() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabName() {
|
||||
return "Menu";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package xyz.valnet.hadean.gameobjects.tabs;
|
||||
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.IBottomBarItem;
|
||||
|
||||
public abstract class Tab extends GameObject implements IBottomBarItem {
|
||||
|
||||
private BottomBar bottombar;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
bottombar = get(BottomBar.class);
|
||||
bottombar.registerButton(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,14 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.IScene;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.Pawn;
|
||||
import xyz.valnet.hadean.gameobjects.Selection;
|
||||
import xyz.valnet.hadean.gameobjects.SelectionUI;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.tabs.ArchitectTab;
|
||||
import xyz.valnet.hadean.gameobjects.tabs.MenuTab;
|
||||
|
||||
public class GameScene implements IScene {
|
||||
|
||||
|
|
@ -84,6 +87,9 @@ public class GameScene implements IScene {
|
|||
objects.add(new Camera());
|
||||
objects.add(new Selection());
|
||||
objects.add(new SelectionUI());
|
||||
objects.add(new BottomBar());
|
||||
objects.add(new ArchitectTab());
|
||||
objects.add(new MenuTab());
|
||||
|
||||
for(GameObject obj : objects) {
|
||||
obj.link(this);
|
||||
|
|
|
|||
Loading…
Reference in New Issue