Created GUI, not rendered yet
This commit is contained in:
parent
48402a31a9
commit
a06d8beffc
@ -5,11 +5,14 @@ import com.badlogic.ashley.core.Entity;
|
|||||||
import com.badlogic.ashley.core.EntityListener;
|
import com.badlogic.ashley.core.EntityListener;
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.saltosion.gladiator.components.CCombat;
|
import com.saltosion.gladiator.components.CCombat;
|
||||||
import com.saltosion.gladiator.components.CPhysics;
|
import com.saltosion.gladiator.components.CPhysics;
|
||||||
import com.saltosion.gladiator.components.CRenderedObject;
|
import com.saltosion.gladiator.components.CRenderedObject;
|
||||||
|
import com.saltosion.gladiator.gui.ButtonNode;
|
||||||
|
import com.saltosion.gladiator.gui.GUIManager;
|
||||||
import com.saltosion.gladiator.input.InputHandler;
|
import com.saltosion.gladiator.input.InputHandler;
|
||||||
import com.saltosion.gladiator.listeners.CombatListener;
|
import com.saltosion.gladiator.listeners.CombatListener;
|
||||||
import com.saltosion.gladiator.systems.CombatSystem;
|
import com.saltosion.gladiator.systems.CombatSystem;
|
||||||
@ -19,6 +22,7 @@ import com.saltosion.gladiator.systems.RenderingSystem;
|
|||||||
import com.saltosion.gladiator.util.AppUtil;
|
import com.saltosion.gladiator.util.AppUtil;
|
||||||
import com.saltosion.gladiator.util.Direction;
|
import com.saltosion.gladiator.util.Direction;
|
||||||
import com.saltosion.gladiator.util.Global;
|
import com.saltosion.gladiator.util.Global;
|
||||||
|
import com.saltosion.gladiator.util.Log;
|
||||||
import com.saltosion.gladiator.util.Name;
|
import com.saltosion.gladiator.util.Name;
|
||||||
import com.saltosion.gladiator.util.SpriteLoader;
|
import com.saltosion.gladiator.util.SpriteLoader;
|
||||||
import com.saltosion.gladiator.util.SpriteSequence;
|
import com.saltosion.gladiator.util.SpriteSequence;
|
||||||
@ -26,6 +30,7 @@ import com.saltosion.gladiator.util.SpriteSequence;
|
|||||||
public class GladiatorBrawler extends ApplicationAdapter {
|
public class GladiatorBrawler extends ApplicationAdapter {
|
||||||
|
|
||||||
private Engine engine;
|
private Engine engine;
|
||||||
|
private GUIManager guiManager;
|
||||||
private InputHandler inputHandler;
|
private InputHandler inputHandler;
|
||||||
|
|
||||||
private Entity player;
|
private Entity player;
|
||||||
@ -66,6 +71,11 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initialize GUI
|
||||||
|
guiManager = new GUIManager();
|
||||||
|
AppUtil.guiManager = this.guiManager;
|
||||||
|
initializeTestGUI();
|
||||||
|
|
||||||
// Initialize stuff in the world
|
// Initialize stuff in the world
|
||||||
initializePlayer();
|
initializePlayer();
|
||||||
initializeTestDummy();
|
initializeTestDummy();
|
||||||
@ -162,6 +172,17 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
engine.addEntity(wall1);
|
engine.addEntity(wall1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initializeTestGUI() {
|
||||||
|
Sprite img = SpriteLoader.loadSprite(Name.GROUNDIMG);
|
||||||
|
ButtonNode button = new ButtonNode("test-button", img, img) {
|
||||||
|
@Override
|
||||||
|
public void click(float x, float y, Input.Buttons mouseButton) {
|
||||||
|
Log.info("I should never be pressed!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
guiManager.getRootNode().addChild(button);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
super.resize(width, height);
|
super.resize(width, height);
|
||||||
|
33
core/src/com/saltosion/gladiator/gui/ButtonNode.java
Normal file
33
core/src/com/saltosion/gladiator/gui/ButtonNode.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.saltosion.gladiator.gui;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
|
|
||||||
|
public abstract class ButtonNode extends GUINode implements InteractiveNode, ImageNode {
|
||||||
|
private final Sprite onHover;
|
||||||
|
private final Sprite normal;
|
||||||
|
private boolean hovered = false;
|
||||||
|
|
||||||
|
public ButtonNode(String ID, Sprite onHover, Sprite normal) {
|
||||||
|
super(ID);
|
||||||
|
this.onHover = onHover;
|
||||||
|
this.normal = normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEnter(float x, float y) {
|
||||||
|
hovered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseLeave(float x, float y){
|
||||||
|
hovered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Sprite getImage() {
|
||||||
|
if (hovered) {
|
||||||
|
return onHover;
|
||||||
|
}
|
||||||
|
return normal;
|
||||||
|
}
|
||||||
|
}
|
14
core/src/com/saltosion/gladiator/gui/GUIManager.java
Normal file
14
core/src/com/saltosion/gladiator/gui/GUIManager.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.saltosion.gladiator.gui;
|
||||||
|
|
||||||
|
public class GUIManager {
|
||||||
|
private final GUINode rootNode;
|
||||||
|
|
||||||
|
public GUIManager() {
|
||||||
|
this.rootNode = new GUINode("root");
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode getRootNode() {
|
||||||
|
return this.rootNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
core/src/com/saltosion/gladiator/gui/GUINode.java
Normal file
64
core/src/com/saltosion/gladiator/gui/GUINode.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package com.saltosion.gladiator.gui;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class GUINode {
|
||||||
|
private final Vector2 position;
|
||||||
|
private final ArrayList<GUINode> children;
|
||||||
|
private String ID = "";
|
||||||
|
|
||||||
|
public GUINode(String ID) {
|
||||||
|
this.ID = ID;
|
||||||
|
this.position = new Vector2();
|
||||||
|
this.children = new ArrayList<GUINode>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode setPosition(float x, float y) {
|
||||||
|
this.position.set(x, y);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode setPosition(Vector2 pos) {
|
||||||
|
this.position.set(pos);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode setID(String ID) {
|
||||||
|
this.ID = ID;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode addChild(GUINode node) {
|
||||||
|
this.children.add(node);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode removeChild(String id) {
|
||||||
|
for (GUINode child : this.children) {
|
||||||
|
if (child.ID.equals(id)) {
|
||||||
|
this.children.remove(child);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode removeChild(GUINode node) {
|
||||||
|
this.children.remove(node);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUINode clearChildren() {
|
||||||
|
this.children.clear();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2 getPosition() {
|
||||||
|
return this.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return this.ID;
|
||||||
|
}
|
||||||
|
}
|
8
core/src/com/saltosion/gladiator/gui/ImageNode.java
Normal file
8
core/src/com/saltosion/gladiator/gui/ImageNode.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package com.saltosion.gladiator.gui;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
|
|
||||||
|
public interface ImageNode {
|
||||||
|
|
||||||
|
public Sprite getImage();
|
||||||
|
}
|
27
core/src/com/saltosion/gladiator/gui/InteractiveNode.java
Normal file
27
core/src/com/saltosion/gladiator/gui/InteractiveNode.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.saltosion.gladiator.gui;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input.Buttons;
|
||||||
|
|
||||||
|
public interface InteractiveNode {
|
||||||
|
/**
|
||||||
|
* Called when the mouse enters the node's elements.
|
||||||
|
* @param x position of the mouse.
|
||||||
|
* @param y position of the mouse.
|
||||||
|
*/
|
||||||
|
public void mouseEnter(float x, float y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the mouse leaves the node's elements.
|
||||||
|
* @param x position of the mouse.
|
||||||
|
* @param y position of the mouse.
|
||||||
|
*/
|
||||||
|
public void mouseLeave(float x, float y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when someone presses a mouse button on the node's elements.
|
||||||
|
* @param x position of the mouse.
|
||||||
|
* @param y position of the mouse.
|
||||||
|
* @param mouseButton button pressed.
|
||||||
|
*/
|
||||||
|
public void click(float x, float y, Buttons mouseButton);
|
||||||
|
}
|
@ -3,11 +3,13 @@ package com.saltosion.gladiator.util;
|
|||||||
import com.badlogic.ashley.core.Engine;
|
import com.badlogic.ashley.core.Engine;
|
||||||
import com.badlogic.ashley.core.Entity;
|
import com.badlogic.ashley.core.Entity;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.saltosion.gladiator.gui.GUIManager;
|
||||||
|
|
||||||
public class AppUtil {
|
public class AppUtil {
|
||||||
|
|
||||||
public static Entity player;
|
public static Entity player;
|
||||||
public static Engine engine;
|
public static Engine engine;
|
||||||
|
public static GUIManager guiManager;
|
||||||
|
|
||||||
public static final int VPHEIGHT_CONST = 24;
|
public static final int VPHEIGHT_CONST = 24;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user