Added controller support to the GUI buttons
This commit is contained in:
parent
7ca1d80e6a
commit
fe759d7b28
|
|
@ -12,6 +12,7 @@ public class CursorPosCallback implements GLFWCursorPosCallbackI
|
||||||
public void invoke(long window, double x, double y) {
|
public void invoke(long window, double x, double y) {
|
||||||
Main.menu.input.mousePos(new Vec2d(x, y));
|
Main.menu.input.mousePos(new Vec2d(x, y));
|
||||||
Main.window.setMouseVisibility(!Main.menu.keepMouse);
|
Main.window.setMouseVisibility(!Main.menu.keepMouse);
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
if(!Main.menu.keepMouse) {
|
if(!Main.menu.keepMouse) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class GameInput
|
||||||
|
|
||||||
static boolean startButton_last = false;
|
static boolean startButton_last = false;
|
||||||
static boolean backButton_last = false;
|
static boolean backButton_last = false;
|
||||||
|
static boolean activate_last = false;
|
||||||
|
|
||||||
static boolean moveLeft = false;
|
static boolean moveLeft = false;
|
||||||
static boolean moveRight = false;
|
static boolean moveRight = false;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
public class InputMode {
|
||||||
|
public static boolean Controller = false;
|
||||||
|
}
|
||||||
|
|
@ -151,6 +151,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
input.move(true, angle);
|
input.move(true, angle);
|
||||||
move_last = true;
|
move_last = true;
|
||||||
|
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,17 +164,20 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
// Is the right x axis stick moved into a position (camera stick)
|
// Is the right x axis stick moved into a position (camera stick)
|
||||||
if(right_x > 0.3 || right_x < -0.3) {
|
if(right_x > 0.3 || right_x < -0.3) {
|
||||||
input.camera(true, right_x);
|
input.camera(true, right_x);
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gun trigger
|
// Gun trigger
|
||||||
if(right_trigger > 0.3 && !fireGun) {
|
if(right_trigger > 0.3 && !fireGun) {
|
||||||
input.fire(true);
|
input.fire(true);
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Item trigger
|
// Item trigger
|
||||||
if(left_trigger > 0.3) {
|
if(left_trigger > 0.3) {
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
if(!activateItem_last)
|
if(!activateItem_last)
|
||||||
{
|
{
|
||||||
|
|
@ -187,6 +191,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shoulder_left) {
|
if(shoulder_left) {
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
if(!hotbar_l) {
|
if(!hotbar_l) {
|
||||||
hotbar_l = true;
|
hotbar_l = true;
|
||||||
|
|
@ -199,6 +204,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shoulder_right) {
|
if(shoulder_right) {
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
if(!hotbar_r) {
|
if(!hotbar_r) {
|
||||||
hotbar_r = true;
|
hotbar_r = true;
|
||||||
|
|
@ -212,6 +218,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
|
|
||||||
// Activate tile
|
// Activate tile
|
||||||
if(button_x) {
|
if(button_x) {
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
if(!activateTile_last) {
|
if(!activateTile_last) {
|
||||||
input.activateTile(true);
|
input.activateTile(true);
|
||||||
|
|
@ -223,8 +230,23 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
activateTile_last = false;
|
activateTile_last = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Activate button (A Button)
|
||||||
|
if(button_a) {
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
if(!activate_last) {
|
||||||
|
input.activate(true);
|
||||||
|
activate_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(activate_last) {
|
||||||
|
activate_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Drop item
|
// Drop item
|
||||||
if(button_b) {
|
if(button_b) {
|
||||||
|
InputMode.Controller = true;
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
if(!dropItem_last) {
|
if(!dropItem_last) {
|
||||||
input.itemDrop(true);
|
input.itemDrop(true);
|
||||||
|
|
@ -251,6 +273,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
// Pause the game
|
// Pause the game
|
||||||
if(button_start) {
|
if(button_start) {
|
||||||
Main.window.setMouseVisibility(false);
|
Main.window.setMouseVisibility(false);
|
||||||
|
InputMode.Controller = true;
|
||||||
if(!startButton_last) {
|
if(!startButton_last) {
|
||||||
startButton_last = true;
|
startButton_last = true;
|
||||||
input.pause(true);
|
input.pause(true);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
Input input = Main.menu.input;
|
Input input = Main.menu.input;
|
||||||
boolean pressed = ! ( action == GLFW_RELEASE );
|
boolean pressed = ! ( action == GLFW_RELEASE );
|
||||||
|
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
if(key == GLFW_KEY_W) {
|
if(key == GLFW_KEY_W) {
|
||||||
moveUp = pressed;
|
moveUp = pressed;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ public class KeyCharCallback implements GLFWCharCallbackI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long arg0, int arg1) {
|
public void invoke(long arg0, int arg1) {
|
||||||
// TODO Auto-generated method stub
|
InputMode.Controller = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ public class MouseButtonCallback implements GLFWMouseButtonCallbackI
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long window, int button, int action, int mods)
|
public void invoke(long window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
GameInput.fireGun = action == 1;
|
GameInput.fireGun = action == 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ public class ScrollWheelCallback implements GLFWScrollCallbackI
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long window, double x, double y)
|
public void invoke(long window, double x, double y)
|
||||||
{
|
{
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
if(y > 0) {
|
if(y > 0) {
|
||||||
Main.menu.input.hotbarShift(true, 1);
|
Main.menu.input.hotbarShift(true, 1);
|
||||||
} if(y < 0) {
|
} if(y < 0) {
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,5 @@ public interface Input
|
||||||
public void hotbarShift(boolean state, int amount);
|
public void hotbarShift(boolean state, int amount);
|
||||||
public void mousePos(Vec2d pos);
|
public void mousePos(Vec2d pos);
|
||||||
public void back(boolean state);
|
public void back(boolean state);
|
||||||
|
public void activate(boolean state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class InputGUI implements Input
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void move(boolean state, double angle) {
|
public void move(boolean state, double angle) {
|
||||||
this.gui.onMove(angle);
|
this.gui.onMove(state, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -59,5 +59,10 @@ public class InputGUI implements Input
|
||||||
public void back(boolean state) {
|
public void back(boolean state) {
|
||||||
gui.onBack();
|
gui.onBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activate(boolean state) {
|
||||||
|
gui.onActivate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,5 +74,9 @@ public class InputGame implements Input
|
||||||
@Override
|
@Override
|
||||||
public void back(boolean state) {
|
public void back(boolean state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activate(boolean state) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,10 @@ import projectzombie.Main;
|
||||||
import projectzombie.input.types.InputGUI;
|
import projectzombie.input.types.InputGUI;
|
||||||
import projectzombie.menu.gui.ButtonGroup;
|
import projectzombie.menu.gui.ButtonGroup;
|
||||||
import projectzombie.menu.gui.GUI;
|
import projectzombie.menu.gui.GUI;
|
||||||
import projectzombie.menu.gui.components.ButtonBasic;
|
|
||||||
import projectzombie.menu.gui.components.ButtonGroupPause;
|
import projectzombie.menu.gui.components.ButtonGroupPause;
|
||||||
import projectzombie.menu.gui.components.GUIBackToMenu;
|
import projectzombie.menu.gui.components.GUIBackToMenu;
|
||||||
import projectzombie.menu.gui.components.LabelPause;
|
import projectzombie.menu.gui.components.LabelPause;
|
||||||
import projectzombie.menu.gui.components.OverlayBackground;
|
import projectzombie.menu.gui.components.OverlayBackground;
|
||||||
import projectzombie.util.math.vec.Vec2d;
|
|
||||||
|
|
||||||
public class MenuGamePause extends Menu
|
public class MenuGamePause extends Menu
|
||||||
{
|
{
|
||||||
|
|
@ -25,7 +23,10 @@ public class MenuGamePause extends Menu
|
||||||
|
|
||||||
gui.add(new OverlayBackground());
|
gui.add(new OverlayBackground());
|
||||||
gui.add(new LabelPause("Game Paused"));
|
gui.add(new LabelPause("Game Paused"));
|
||||||
gui.add(new ButtonGroupPause());
|
|
||||||
|
ButtonGroup group = new ButtonGroupPause();
|
||||||
|
gui.setSelected(group.get(0));
|
||||||
|
gui.add(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ public class MenuMain extends Menu
|
||||||
}));
|
}));
|
||||||
|
|
||||||
gui.add(group);
|
gui.add(group);
|
||||||
|
gui.setSelected(group.get(0));
|
||||||
|
|
||||||
Main.respawn();
|
Main.respawn();
|
||||||
Main.player.dead = true;
|
Main.player.dead = true;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ package projectzombie.menu;
|
||||||
import projectzombie.Main;
|
import projectzombie.Main;
|
||||||
import projectzombie.display.DisplayRenderUI;
|
import projectzombie.display.DisplayRenderUI;
|
||||||
import projectzombie.input.types.InputGUI;
|
import projectzombie.input.types.InputGUI;
|
||||||
|
import projectzombie.menu.gui.Button;
|
||||||
import projectzombie.menu.gui.ButtonGroup;
|
import projectzombie.menu.gui.ButtonGroup;
|
||||||
import projectzombie.menu.gui.GUI;
|
import projectzombie.menu.gui.GUI;
|
||||||
|
import projectzombie.menu.gui.GUISelectableDirection;
|
||||||
import projectzombie.menu.gui.Label;
|
import projectzombie.menu.gui.Label;
|
||||||
import projectzombie.menu.gui.components.ButtonBasic;
|
import projectzombie.menu.gui.components.ButtonBasic;
|
||||||
import projectzombie.menu.gui.components.ButtonSetting;
|
import projectzombie.menu.gui.components.ButtonSetting;
|
||||||
|
|
@ -78,9 +80,15 @@ public class MenuSettings extends Menu
|
||||||
labelSettings.setPos(new Vec2d(0, 6.8));
|
labelSettings.setPos(new Vec2d(0, 6.8));
|
||||||
gui.add(labelSettings);
|
gui.add(labelSettings);
|
||||||
|
|
||||||
gui.add(new ButtonBasic("Back", new Vec2d(0, -8), button -> {
|
Button buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> {
|
||||||
Main.menu = menuOld;
|
Main.menu = menuOld;
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
group.get(group.size() - 1).setNeighbour(buttonBack, GUISelectableDirection.DOWN);
|
||||||
|
buttonBack.setNeighbour(group.get(group.size() - 1), GUISelectableDirection.UP);
|
||||||
|
|
||||||
|
gui.add(buttonBack);
|
||||||
|
gui.setSelected(buttonBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,22 @@ package projectzombie.menu.gui;
|
||||||
|
|
||||||
import projectzombie.Main;
|
import projectzombie.Main;
|
||||||
import projectzombie.init.Textures;
|
import projectzombie.init.Textures;
|
||||||
|
import projectzombie.input.InputMode;
|
||||||
import projectzombie.text.Text;
|
import projectzombie.text.Text;
|
||||||
import projectzombie.util.gl.GlHelpers;
|
import projectzombie.util.gl.GlHelpers;
|
||||||
import projectzombie.util.gl.texture.TextureReference;
|
import projectzombie.util.gl.texture.TextureReference;
|
||||||
import projectzombie.util.math.vec.Vec2d;
|
import projectzombie.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class Button implements GUIComponent
|
public class Button implements GUIComponent, GUISelectable
|
||||||
{
|
{
|
||||||
private Vec2d pos = new Vec2d(0, 0);
|
private Vec2d pos = new Vec2d(0, 0);
|
||||||
private String text = "";
|
private String text = "";
|
||||||
private Alignment alignment = Alignment.CENTRE;
|
private Alignment alignment = Alignment.CENTRE;
|
||||||
|
|
||||||
|
private boolean selected = false;
|
||||||
|
|
||||||
|
private GUISelectable[] SELECTABLE = {null, null, null, null};
|
||||||
|
|
||||||
public static final Vec2d textSize = new Vec2d(0.5, 0.5);
|
public static final Vec2d textSize = new Vec2d(0.5, 0.5);
|
||||||
|
|
||||||
public void setPos(Vec2d pos) {
|
public void setPos(Vec2d pos) {
|
||||||
|
|
@ -59,7 +64,7 @@ public class Button implements GUIComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureReference tex;
|
TextureReference tex;
|
||||||
boolean mouseHover = this.checkMouseHover(mousePos);
|
boolean mouseHover = InputMode.Controller ? this.selected : this.checkMouseHover(mousePos);
|
||||||
if(mouseHover) {
|
if(mouseHover) {
|
||||||
tex = Textures.BUTTON_HOVER;
|
tex = Textures.BUTTON_HOVER;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -133,4 +138,55 @@ public class Button implements GUIComponent
|
||||||
@Override
|
@Override
|
||||||
public void onBack() {
|
public void onBack() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(boolean status) {
|
||||||
|
this.selected = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getSelected() {
|
||||||
|
return this.selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GUISelectable getNeighbour(GUISelectableDirection direction) {
|
||||||
|
if(direction == GUISelectableDirection.UP) {
|
||||||
|
return SELECTABLE[0];
|
||||||
|
}
|
||||||
|
if(direction == GUISelectableDirection.LEFT) {
|
||||||
|
return SELECTABLE[1];
|
||||||
|
}
|
||||||
|
if(direction == GUISelectableDirection.DOWN) {
|
||||||
|
return SELECTABLE[2];
|
||||||
|
}
|
||||||
|
if(direction == GUISelectableDirection.RIGHT) {
|
||||||
|
return SELECTABLE[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNeighbour(GUISelectable selectable, GUISelectableDirection direction) {
|
||||||
|
if(direction == GUISelectableDirection.UP) {
|
||||||
|
SELECTABLE[0] = selectable;
|
||||||
|
}
|
||||||
|
if(direction == GUISelectableDirection.LEFT) {
|
||||||
|
SELECTABLE[1] = selectable;
|
||||||
|
}
|
||||||
|
if(direction == GUISelectableDirection.DOWN) {
|
||||||
|
SELECTABLE[2] = selectable;
|
||||||
|
}
|
||||||
|
if(direction == GUISelectableDirection.RIGHT) {
|
||||||
|
SELECTABLE[3] = selectable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivate() {
|
||||||
|
if(this.selected) {
|
||||||
|
this.onMouseClick(new Vec2d(0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,14 @@ public class ButtonGroup implements GUIContainer
|
||||||
for(int i=0;i<buttons.size();i++) {
|
for(int i=0;i<buttons.size();i++) {
|
||||||
Button b = buttons.get(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 + Button.textSize.y * -i * 3.6));
|
||||||
|
|
||||||
|
if(i > 0) {
|
||||||
|
b.setNeighbour(buttons.get(i - 1), GUISelectableDirection.UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i < buttons.size() - 1) {
|
||||||
|
b.setNeighbour(buttons.get(i + 1), GUISelectableDirection.DOWN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,5 +67,20 @@ public class ButtonGroup implements GUIContainer
|
||||||
b.onBack();
|
b.onBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Button get(int n) {
|
||||||
|
return buttons.get(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return buttons.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivate() {
|
||||||
|
for(Button b : buttons) {
|
||||||
|
b.onActivate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package projectzombie.menu.gui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import projectzombie.menu.Menu;
|
|
||||||
import projectzombie.util.math.vec.Vec2d;
|
import projectzombie.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class GUI implements GUIContainer
|
public class GUI implements GUIContainer
|
||||||
|
|
@ -10,6 +9,20 @@ public class GUI implements GUIContainer
|
||||||
private ArrayList<GUIComponent> components = new ArrayList<GUIComponent>();
|
private ArrayList<GUIComponent> components = new ArrayList<GUIComponent>();
|
||||||
private Vec2d mousePos = new Vec2d(0, 0);
|
private Vec2d mousePos = new Vec2d(0, 0);
|
||||||
|
|
||||||
|
public GUISelectable selected;
|
||||||
|
|
||||||
|
private static boolean move_last = false;
|
||||||
|
|
||||||
|
public void setSelected(GUISelectable selected) {
|
||||||
|
if(this.selected != null) {
|
||||||
|
this.selected.setSelected(false);
|
||||||
|
}
|
||||||
|
this.selected = selected;
|
||||||
|
if(this.selected != null) {
|
||||||
|
this.selected.setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d mousePos) {
|
public void render(Vec2d mousePos) {
|
||||||
for(GUIComponent c : components) {
|
for(GUIComponent c : components) {
|
||||||
|
|
@ -30,8 +43,50 @@ public class GUI implements GUIContainer
|
||||||
this.mousePos = pos;
|
this.mousePos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMove(double angle) {
|
public void onMove(boolean status, double angle)
|
||||||
|
{
|
||||||
|
if(this.selected == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(status) {
|
||||||
|
if(!move_last) {
|
||||||
|
move_last = true;
|
||||||
|
|
||||||
|
this.selected.setSelected(false);
|
||||||
|
GUISelectable selected = null;
|
||||||
|
|
||||||
|
// Up / North
|
||||||
|
if(angle > 315 || angle <= 45) {
|
||||||
|
selected = this.selected.getNeighbour(GUISelectableDirection.UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right / East
|
||||||
|
if(angle > 45 && angle <= 135) {
|
||||||
|
selected = this.selected.getNeighbour(GUISelectableDirection.RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Down / South
|
||||||
|
if(angle > 135 && angle <= 225) {
|
||||||
|
selected = this.selected.getNeighbour(GUISelectableDirection.DOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left / West
|
||||||
|
if(angle > 225 && angle <= 315) {
|
||||||
|
selected = this.selected.getNeighbour(GUISelectableDirection.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(selected != null) {
|
||||||
|
this.selected = selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selected.setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(move_last) {
|
||||||
|
move_last = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -59,4 +114,11 @@ public class GUI implements GUIContainer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivate() {
|
||||||
|
for(GUIComponent c : components) {
|
||||||
|
c.onActivate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,6 @@ public interface GUIComponent
|
||||||
public boolean checkMouseHover(Vec2d pos);
|
public boolean checkMouseHover(Vec2d pos);
|
||||||
|
|
||||||
public void onMouseClick(Vec2d pos);
|
public void onMouseClick(Vec2d pos);
|
||||||
|
public void onActivate();
|
||||||
public void onBack();
|
public void onBack();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package projectzombie.menu.gui;
|
||||||
|
|
||||||
|
public interface GUISelectable {
|
||||||
|
public void setSelected(boolean status);
|
||||||
|
public boolean getSelected();
|
||||||
|
public GUISelectable getNeighbour(GUISelectableDirection direction);
|
||||||
|
public void setNeighbour(GUISelectable selectable, GUISelectableDirection direction);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package projectzombie.menu.gui;
|
||||||
|
|
||||||
|
public enum GUISelectableDirection {
|
||||||
|
UP, DOWN, LEFT, RIGHT
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ public class Label implements GUIComponent
|
||||||
{
|
{
|
||||||
private Vec2d pos = new Vec2d(0, 0);
|
private Vec2d pos = new Vec2d(0, 0);
|
||||||
private Vec2d size = new Vec2d(0.5, 0.5);
|
private Vec2d size = new Vec2d(0.5, 0.5);
|
||||||
private Vec3d color = new Vec3d(1, 1, 1);
|
private Vec3d color = new Vec3d(0.92, 0.92, 0.92);
|
||||||
private String text = "";
|
private String text = "";
|
||||||
private Alignment alignment = Alignment.CENTRE;
|
private Alignment alignment = Alignment.CENTRE;
|
||||||
|
|
||||||
|
|
@ -61,5 +61,9 @@ public class Label implements GUIComponent
|
||||||
@Override
|
@Override
|
||||||
public void onBack() {
|
public void onBack() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivate() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,8 @@ public class Overlay implements GUIComponent
|
||||||
public void onBack() {
|
public void onBack() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivate() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package projectzombie.menu.gui.components;
|
||||||
|
|
||||||
import projectzombie.menu.gui.Label;
|
import projectzombie.menu.gui.Label;
|
||||||
import projectzombie.util.math.vec.Vec2d;
|
import projectzombie.util.math.vec.Vec2d;
|
||||||
import projectzombie.util.math.vec.Vec3d;
|
|
||||||
|
|
||||||
public class LabelPause extends Label
|
public class LabelPause extends Label
|
||||||
{
|
{
|
||||||
|
|
@ -10,6 +9,5 @@ public class LabelPause extends Label
|
||||||
setText(text);
|
setText(text);
|
||||||
setPos(new Vec2d(0, 2.4));
|
setPos(new Vec2d(0, 2.4));
|
||||||
setSize(new Vec2d(1, 1));
|
setSize(new Vec2d(1, 1));
|
||||||
setColor(new Vec3d(0.92, 0.92, 0.92));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue