Started working on buttons
This commit is contained in:
parent
eacf39f27b
commit
7b8de0fa63
|
|
@ -20,6 +20,8 @@ public class DisplayRenderUI
|
|||
public static boolean showPos = false;
|
||||
public static int guiScale = 2;
|
||||
|
||||
public static Matrix4 camera, projection;
|
||||
|
||||
public static void renderGameGui()
|
||||
{
|
||||
{
|
||||
|
|
@ -85,8 +87,8 @@ public class DisplayRenderUI
|
|||
|
||||
public static void render()
|
||||
{
|
||||
Matrix4 camera = Matrix4.identity();
|
||||
Matrix4 projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
|
||||
camera = Matrix4.identity();
|
||||
projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
|
||||
|
||||
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray());
|
||||
GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, camera.getArray());
|
||||
|
|
@ -99,6 +101,6 @@ public class DisplayRenderUI
|
|||
}
|
||||
|
||||
// Render the loaded menu
|
||||
//Main.menu.render();
|
||||
Main.menu.render();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,13 +76,13 @@ public class DisplayWindow implements IMainloopTask
|
|||
width = w.get()*4;
|
||||
height = h.get()*4;
|
||||
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
|
||||
//GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
|
||||
|
||||
// Create the window
|
||||
window = GraphicsHelpers.initWindow("Project Zombie", width, height, monitor);
|
||||
|
||||
// Make the context current
|
||||
//GLFW.glfwMakeContextCurrent(this.window);
|
||||
GLFW.glfwMakeContextCurrent(this.window);
|
||||
|
||||
// Set the key handlers
|
||||
GLFW.glfwSetCursorPosCallback(this.window, new CursorPosCallback());
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ public class Models
|
|||
public static final Model TILE_LAVA_FLOW = new ModelTile(Resources.ATLAS.get("/tile/lava_flow.png"), 16, 50);
|
||||
public static final Model TILE_LANTERN = new ModelVertical(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
|
||||
|
||||
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_idle.png"), new Vec2d(4, 4));
|
||||
public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 10);
|
||||
public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 10);
|
||||
public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 10);
|
||||
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4), 4, 50);
|
||||
public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50);
|
||||
public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50);
|
||||
public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50);
|
||||
public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png"));
|
||||
public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png"));
|
||||
public static final Model ENTITY_DUMMY = new ModelVertical(Resources.ATLAS.get("/entity/dummy.png"));
|
||||
|
|
@ -53,8 +53,8 @@ public class Models
|
|||
new ModelVertical(Resources.ATLAS.get("/particle/smoke_4.png")),
|
||||
new ModelVertical(Resources.ATLAS.get("/particle/smoke_5.png")));
|
||||
|
||||
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button.png"));
|
||||
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/tile/tree.png"));
|
||||
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5));
|
||||
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5));
|
||||
|
||||
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(8, 0.5));
|
||||
public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(8, 0.5));
|
||||
|
|
@ -74,7 +74,7 @@ public class Models
|
|||
public static final ModelItem ITEM_TNT = new ModelItem(Resources.ATLAS.get("/entity/tnt.png"));
|
||||
public static final ModelItem ITEM_FLARE = new ModelItem(Resources.ATLAS.get("/entity/flare.png"));
|
||||
public static final ModelItem ITEM_LANTERN = new ModelItem(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
|
||||
public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_back_moving.png"), 4, 10);
|
||||
public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);
|
||||
public static final ModelItem ITEM_SPAWN_DUMMY = new ModelItem(Resources.ATLAS.get("/entity/dummy.png"));
|
||||
|
||||
// Player Back White Varient
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ package projectzombie.menu.gui;
|
|||
|
||||
import gl_engine.matrix.Matrix4;
|
||||
import gl_engine.vec.Vec2d;
|
||||
import gl_engine.vec.Vec3d;
|
||||
import projectzombie.Main;
|
||||
import projectzombie.display.DisplayRenderUI;
|
||||
import projectzombie.init.Models;
|
||||
import projectzombie.input.InputMode;
|
||||
import projectzombie.model.Model;
|
||||
import projectzombie.model.ModelGui;
|
||||
import projectzombie.text.Text;
|
||||
import projectzombie.util.gl.GlHelpers;
|
||||
|
||||
|
|
@ -14,55 +17,70 @@ public class Button implements GUIComponent, GUISelectable
|
|||
private Vec2d pos = new Vec2d(0, 0);
|
||||
private String text = "";
|
||||
private Alignment alignment = Alignment.CENTRE;
|
||||
private Matrix4 matrix, matrix_text;
|
||||
|
||||
private boolean selected = false;
|
||||
private boolean dirty = true;
|
||||
|
||||
private GUISelectable[] SELECTABLE = {null, null, null, null};
|
||||
|
||||
public static final Vec2d textSize = new Vec2d(0.5, 0.5);
|
||||
private void updateMatrix()
|
||||
{
|
||||
double offset;
|
||||
|
||||
switch(alignment) {
|
||||
|
||||
case CENTRE:
|
||||
offset = Models.UI_BUTTON.getWidth() / 2;
|
||||
break;
|
||||
case RIGHT:
|
||||
offset = Models.UI_BUTTON.getWidth();
|
||||
break;
|
||||
default:
|
||||
offset = 0;
|
||||
|
||||
}
|
||||
|
||||
matrix = Matrix4.translate(pos.x - offset, pos.y, 0);
|
||||
|
||||
matrix_text = Matrix4.multiply(matrix, Matrix4.translate(
|
||||
Models.UI_BUTTON.getWidth() / 2 - 0.25 * text.length(),
|
||||
Models.UI_BUTTON.getHeight() / 2 - 0.25, 0));
|
||||
|
||||
matrix_text = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), matrix_text);
|
||||
}
|
||||
|
||||
public Button()
|
||||
{
|
||||
this.text = "";
|
||||
this.alignment = Alignment.CENTRE;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
public void setPos(Vec2d pos) {
|
||||
this.pos = pos;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
public void setAlign(Alignment alignment) {
|
||||
this.alignment = alignment;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Vec2d mousePos)
|
||||
{
|
||||
double m = 3;
|
||||
double w = textSize.x * m * 8;
|
||||
double h = textSize.x * m / 2;
|
||||
|
||||
double w1 = 0;
|
||||
double w2 = 0;
|
||||
double wt = 0;
|
||||
|
||||
if(alignment == Alignment.LEFT) {
|
||||
w1 = 0;
|
||||
w2 = w;
|
||||
wt = w/2;
|
||||
if(this.dirty) {
|
||||
this.updateMatrix();
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
if(alignment == Alignment.CENTRE) {
|
||||
w1 = -w/2;
|
||||
w2 = w/2;
|
||||
wt = 0;
|
||||
}
|
||||
|
||||
if(alignment == Alignment.RIGHT) {
|
||||
w1 = -w;
|
||||
w2 = 0;
|
||||
wt = -w/2;
|
||||
}
|
||||
|
||||
Model model;
|
||||
ModelGui model;
|
||||
boolean mouseHover = InputMode.Controller ? this.selected : this.checkMouseHover(mousePos);
|
||||
if(mouseHover) {
|
||||
model = Models.UI_BUTTON_HOVER;
|
||||
|
|
@ -70,55 +88,34 @@ public class Button implements GUIComponent, GUISelectable
|
|||
model = Models.UI_BUTTON;
|
||||
}
|
||||
|
||||
Matrix4 matrix = Matrix4.translate(pos.x, pos.y, 0);
|
||||
|
||||
model.bind();
|
||||
model.setModel(matrix);
|
||||
model.render();
|
||||
|
||||
if(mouseHover) {
|
||||
//GlHelpers.color3(0.8, 0.8, 0.8);
|
||||
} else {
|
||||
//GlHelpers.color3(0.68, 0.68, 0.68);
|
||||
}
|
||||
//Text.render(text, textSize);
|
||||
Text.render(text, matrix_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkMouseHover(Vec2d pos) {
|
||||
|
||||
double mx = pos.x / Main.window.getWidth() * 20 - 10;
|
||||
double my = pos.y / Main.window.getHeight() * 20 - 10;
|
||||
|
||||
mx = mx * GlHelpers.getScale() / 10;
|
||||
my = my * GlHelpers.getScale() / 10;
|
||||
|
||||
double m = 3;
|
||||
double w = textSize.x * m * 8 / GlHelpers.getAspectRatio();
|
||||
double h = textSize.x * m / 2;
|
||||
|
||||
double w1 = 0;
|
||||
double w2 = 0;
|
||||
|
||||
if(alignment == Alignment.LEFT) {
|
||||
w1 = 0;
|
||||
w2 = w;
|
||||
public boolean checkMouseHover(Vec2d pos)
|
||||
{
|
||||
if(this.dirty) {
|
||||
this.updateMatrix();
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
if(alignment == Alignment.CENTRE) {
|
||||
w1 = -w/2;
|
||||
w2 = w/2;
|
||||
}
|
||||
double mx = -pos.x / Main.window.getWidth() * 2 + 1;
|
||||
double my = -pos.y / Main.window.getHeight() * 2 + 1;
|
||||
|
||||
if(alignment == Alignment.RIGHT) {
|
||||
w1 = -w;
|
||||
w2 = 0;
|
||||
}
|
||||
ModelGui model = Models.UI_BUTTON;
|
||||
Matrix4 mat = Matrix4.multiply(matrix, DisplayRenderUI.projection);
|
||||
Vec3d point_s = Matrix4.multiply(mat, this.pos.xyn());
|
||||
Vec3d point_e = Matrix4.multiply(mat, new Vec3d(
|
||||
model.getWidth() + this.pos.x,
|
||||
model.getHeight() + this.pos.y, 0));
|
||||
|
||||
return (
|
||||
mx > w1 + this.pos.x &&
|
||||
mx < w2 + this.pos.x &&
|
||||
my > -h - this.pos.y &&
|
||||
my < h - this.pos.y);
|
||||
//System.out.println("mx="+mx+" my="+my+" bx="+point.x+" by="+point.y+" w="+Models.UI_BUTTON.getWidth()+" h="+Models.UI_BUTTON.getHeight());
|
||||
|
||||
return (mx > point_s.x && mx < point_e.x &&
|
||||
my > point_s.y && my < point_e.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class ButtonGroup implements GUIContainer
|
|||
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
Button b = buttons.get(i);
|
||||
b.setPos(new Vec2d(pos.x, pos.y + Button.textSize.y * -i * 3.6));
|
||||
b.setPos(new Vec2d(pos.x, pos.y + 0.5 * -i * 3.6));
|
||||
|
||||
if(i > 0) {
|
||||
b.setNeighbour(buttons.get(i - 1), GUISelectableDirection.UP);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ public class ButtonBasic extends Button {
|
|||
|
||||
public ButtonBasic(String text, Vec2d pos, ButtonCallback callback) {
|
||||
this(text, callback);
|
||||
this.setPos(pos);
|
||||
|
||||
setPos(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -32,8 +32,12 @@ public abstract class Model
|
|||
|
||||
private static Model bound = null;
|
||||
|
||||
private void generate()
|
||||
protected void generate()
|
||||
{
|
||||
if(loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
float[] verticies = this.getVerticies();
|
||||
TextureRef3D[] refs = this.getTextures();
|
||||
|
||||
|
|
@ -109,4 +113,8 @@ public abstract class Model
|
|||
public void setModel(Matrix4 model) {
|
||||
GL33.glUniformMatrix4fv(Main.window.glsl_model, true, model.getArray());
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,10 +70,12 @@ public class ModelGui extends Model
|
|||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
generate();
|
||||
return height;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
generate();
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ public class ModelVertical extends Model
|
|||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
generate();
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ public class Text
|
|||
public static final Model CHAR_e = new ModelGui(Resources.ATLAS.get("/text/char_l_e.png"));
|
||||
public static final Model CHAR_f = new ModelGui(Resources.ATLAS.get("/text/char_l_f.png"));
|
||||
public static final Model CHAR_g = new ModelGui(Resources.ATLAS.get("/text/char_l_g.png"));
|
||||
public static final Model CHAR_i = new ModelGui(Resources.ATLAS.get("/text/char_l_h.png"));
|
||||
public static final Model CHAR_h = new ModelGui(Resources.ATLAS.get("/text/char_l_i.png"));
|
||||
public static final Model CHAR_i = new ModelGui(Resources.ATLAS.get("/text/char_l_i.png"));
|
||||
public static final Model CHAR_h = new ModelGui(Resources.ATLAS.get("/text/char_l_h.png"));
|
||||
public static final Model CHAR_j = new ModelGui(Resources.ATLAS.get("/text/char_l_j.png"));
|
||||
public static final Model CHAR_k = new ModelGui(Resources.ATLAS.get("/text/char_l_k.png"));
|
||||
public static final Model CHAR_l = new ModelGui(Resources.ATLAS.get("/text/char_l_l.png"));
|
||||
|
|
@ -188,10 +188,13 @@ public class Text
|
|||
case('<'): l = CHAR_L_THAN; break;
|
||||
}
|
||||
|
||||
if(l != null)
|
||||
{
|
||||
Matrix4 model = Matrix4.multiply(Matrix4.translate(i, 0, 0), matrix);
|
||||
|
||||
l.setModel(model);
|
||||
l.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue