drag to drop item

This commit is contained in:
austin 2022-02-25 16:34:48 -05:00
parent 784279e13f
commit 991753962b
57 changed files with 3650 additions and 1458 deletions

View File

@ -7,8 +7,8 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<lwjgl.version>3.2.3</lwjgl.version>
<joml.version>1.9.19</joml.version>
</properties>

View File

@ -1,26 +1,39 @@
package electrosphere.controls;
import electrosphere.renderer.ui.events.MouseEvent;
public class Control {
boolean isKey;
boolean isMouse;
public static enum ControlType {
KEY,
MOUSE_BUTTON,
MOUSE_MOVEMENT,
}
ControlType type;
boolean state;
int keyValue;
ControlMethod onPress;
ControlMethod onRelease;
ControlMethod onRepeat;
MouseCallback onMove;
public boolean isIsKey() {
return isKey;
return type == ControlType.KEY;
}
public boolean isIsMouse() {
return isMouse;
return type == ControlType.MOUSE_BUTTON;
}
public boolean isState() {
return state;
}
public ControlType getType(){
return type;
}
public int getKeyValue() {
return keyValue;
}
@ -29,9 +42,8 @@ public class Control {
this.state = state;
}
public Control(boolean isKey, boolean isMouse, int keyValue) {
this.isKey = isKey;
this.isMouse = isMouse;
public Control(ControlType type, int keyValue) {
this.type = type;
this.keyValue = keyValue;
this.state = false;
}
@ -48,6 +60,10 @@ public class Control {
onRepeat = method;
}
public void setOnMove(MouseCallback method){
onMove = method;
}
public void onPress(){
if(onPress != null){
onPress.execute();
@ -65,10 +81,20 @@ public class Control {
onRepeat.execute();
}
}
public void onMove(MouseEvent event){
if(onMove != null){
onMove.execute(event);
}
}
public interface ControlMethod {
public void execute();
}
public interface MouseCallback {
public void execute(MouseEvent event);
}
}

View File

@ -1,7 +1,7 @@
package electrosphere.controls;
import electrosphere.controls.Control.ControlMethod;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.controls.Control.ControlType;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.types.creature.CreatureUtils;
@ -14,12 +14,24 @@ import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
import electrosphere.entity.state.movement.SprintTree;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.client.targeting.crosshair.Crosshair;
import electrosphere.main.Globals;
import electrosphere.menu.MenuTransition;
import electrosphere.menu.MenuUtils;
import electrosphere.main.Main;
import electrosphere.menu.WindowStrings;
import electrosphere.menu.WindowUtils;
import electrosphere.menu.MenuCallbacks;
import electrosphere.menu.MenuGenerators;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.Window;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.DragEvent;
import electrosphere.renderer.ui.events.KeyboardEvent;
import electrosphere.renderer.ui.events.MouseEvent;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@ -38,6 +50,7 @@ import static org.lwjgl.glfw.GLFW.glfwSetInputMode;
*/
public class ControlHandler {
public static final String INPUT_CODE_CAMERA_ROTATION = "cameraRotation";
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD = "moveForward";
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD = "moveBackward";
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_LEFT = "moveLeft";
@ -103,6 +116,7 @@ public class ControlHandler {
public static final String INPUT_CODE_INVENTORY_CLOSE = "inventoryClose";
public static final String INPUT_CODE_INVENTORY_ITEM_MANIPULATE = "inventoryItemManipulate";
public static final String INPUT_CODE_INVENTORY_ITEM_DRAG = "inventoryDrag";
public static enum ControlsState {
@ -117,6 +131,20 @@ public class ControlHandler {
ControlsState state = ControlsState.TITLE_MENU;
boolean mouseIsVisible = true;
/*
Mouse event parsing related stuff
*/
float mouse_lastX = 400;
float mouse_lastY = 300;
double xpos = 400;
double ypos = 300;
double mouse_X_Buffer[] = new double[1];
double mouse_Y_Buffer[] = new double[1];
boolean dragging = false;
HashMap<String, Control> controls;
@ -139,77 +167,79 @@ public class ControlHandler {
/*
Map the controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(true,false,GLFW_KEY_W));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(true,false,GLFW_KEY_S));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(true,false,GLFW_KEY_A));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(true,false,GLFW_KEY_D));
handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_LEFT, new Control(true,false,GLFW_KEY_F24));
handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_RIGHT, new Control(true,false,GLFW_KEY_F24));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(true,false,GLFW_KEY_SPACE));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(true,false,GLFW_KEY_LEFT_CONTROL));
handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(false,true,GLFW_MOUSE_BUTTON_LEFT));
handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(true,false,GLFW_KEY_ESCAPE));
handler.addControl(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR, new Control(false,true,GLFW_MOUSE_BUTTON_RIGHT));
handler.addControl(INPUT_CODE_SPRINT, new Control(true,false,GLFW_KEY_LEFT_SHIFT));
handler.addControl(INPUT_CODE_INTERACT, new Control(true,false,GLFW_KEY_E));
handler.addControl(INPUT_CODE_DROP, new Control(true,false,GLFW_KEY_Y));
handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(true,false,GLFW_KEY_I));
handler.addControl(INPUT_CODE_CAMERA_ROTATION, new Control(ControlType.MOUSE_MOVEMENT,0));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(ControlType.KEY,GLFW_KEY_W));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(ControlType.KEY,GLFW_KEY_S));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(ControlType.KEY,GLFW_KEY_A));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(ControlType.KEY,GLFW_KEY_D));
handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_LEFT, new Control(ControlType.KEY,GLFW_KEY_F24));
handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_RIGHT, new Control(ControlType.KEY,GLFW_KEY_F24));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(ControlType.KEY,GLFW_KEY_SPACE));
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(ControlType.KEY,GLFW_KEY_LEFT_CONTROL));
handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_LEFT));
handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(ControlType.KEY,GLFW_KEY_ESCAPE));
handler.addControl(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_RIGHT));
handler.addControl(INPUT_CODE_SPRINT, new Control(ControlType.KEY,GLFW_KEY_LEFT_SHIFT));
handler.addControl(INPUT_CODE_INTERACT, new Control(ControlType.KEY,GLFW_KEY_E));
handler.addControl(INPUT_CODE_DROP, new Control(ControlType.KEY,GLFW_KEY_Y));
handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW_KEY_I));
/*
Map the menu navigation controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, new Control(true,false,GLFW_KEY_DOWN));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(true,false,GLFW_KEY_UP));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(true,false,GLFW_KEY_ENTER));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(true,false,GLFW_KEY_ESCAPE));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, new Control(ControlType.KEY,GLFW_KEY_DOWN));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(ControlType.KEY,GLFW_KEY_UP));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(ControlType.KEY,GLFW_KEY_ENTER));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(ControlType.KEY,GLFW_KEY_ESCAPE));
/*
Map the typing controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, new Control(true,false,GLFW_KEY_BACKSPACE));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, new Control(true,false,GLFW_KEY_0));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, new Control(true,false,GLFW_KEY_1));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, new Control(true,false,GLFW_KEY_2));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, new Control(true,false,GLFW_KEY_3));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, new Control(true,false,GLFW_KEY_4));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, new Control(true,false,GLFW_KEY_5));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, new Control(true,false,GLFW_KEY_6));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, new Control(true,false,GLFW_KEY_7));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, new Control(true,false,GLFW_KEY_8));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, new Control(true,false,GLFW_KEY_9));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, new Control(true,false,GLFW_KEY_PERIOD));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_A, new Control(true,false,GLFW_KEY_A));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_B, new Control(true,false,GLFW_KEY_B));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_C, new Control(true,false,GLFW_KEY_C));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_D, new Control(true,false,GLFW_KEY_D));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_E, new Control(true,false,GLFW_KEY_E));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_F, new Control(true,false,GLFW_KEY_F));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_G, new Control(true,false,GLFW_KEY_G));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_H, new Control(true,false,GLFW_KEY_H));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_I, new Control(true,false,GLFW_KEY_I));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_J, new Control(true,false,GLFW_KEY_J));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_K, new Control(true,false,GLFW_KEY_K));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_L, new Control(true,false,GLFW_KEY_L));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_M, new Control(true,false,GLFW_KEY_M));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_N, new Control(true,false,GLFW_KEY_N));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_O, new Control(true,false,GLFW_KEY_O));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_P, new Control(true,false,GLFW_KEY_P));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Q, new Control(true,false,GLFW_KEY_Q));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_R, new Control(true,false,GLFW_KEY_R));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_S, new Control(true,false,GLFW_KEY_S));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_T, new Control(true,false,GLFW_KEY_T));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_U, new Control(true,false,GLFW_KEY_U));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_V, new Control(true,false,GLFW_KEY_V));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_W, new Control(true,false,GLFW_KEY_W));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_X, new Control(true,false,GLFW_KEY_X));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Y, new Control(true,false,GLFW_KEY_Y));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Z, new Control(true,false,GLFW_KEY_Z));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, new Control(ControlType.KEY,GLFW_KEY_BACKSPACE));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, new Control(ControlType.KEY,GLFW_KEY_0));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, new Control(ControlType.KEY,GLFW_KEY_1));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, new Control(ControlType.KEY,GLFW_KEY_2));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, new Control(ControlType.KEY,GLFW_KEY_3));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, new Control(ControlType.KEY,GLFW_KEY_4));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, new Control(ControlType.KEY,GLFW_KEY_5));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, new Control(ControlType.KEY,GLFW_KEY_6));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, new Control(ControlType.KEY,GLFW_KEY_7));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, new Control(ControlType.KEY,GLFW_KEY_8));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, new Control(ControlType.KEY,GLFW_KEY_9));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, new Control(ControlType.KEY,GLFW_KEY_PERIOD));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_A, new Control(ControlType.KEY,GLFW_KEY_A));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_B, new Control(ControlType.KEY,GLFW_KEY_B));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_C, new Control(ControlType.KEY,GLFW_KEY_C));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_D, new Control(ControlType.KEY,GLFW_KEY_D));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_E, new Control(ControlType.KEY,GLFW_KEY_E));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_F, new Control(ControlType.KEY,GLFW_KEY_F));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_G, new Control(ControlType.KEY,GLFW_KEY_G));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_H, new Control(ControlType.KEY,GLFW_KEY_H));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_I, new Control(ControlType.KEY,GLFW_KEY_I));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_J, new Control(ControlType.KEY,GLFW_KEY_J));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_K, new Control(ControlType.KEY,GLFW_KEY_K));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_L, new Control(ControlType.KEY,GLFW_KEY_L));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_M, new Control(ControlType.KEY,GLFW_KEY_M));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_N, new Control(ControlType.KEY,GLFW_KEY_N));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_O, new Control(ControlType.KEY,GLFW_KEY_O));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_P, new Control(ControlType.KEY,GLFW_KEY_P));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Q, new Control(ControlType.KEY,GLFW_KEY_Q));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_R, new Control(ControlType.KEY,GLFW_KEY_R));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_S, new Control(ControlType.KEY,GLFW_KEY_S));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_T, new Control(ControlType.KEY,GLFW_KEY_T));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_U, new Control(ControlType.KEY,GLFW_KEY_U));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_V, new Control(ControlType.KEY,GLFW_KEY_V));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_W, new Control(ControlType.KEY,GLFW_KEY_W));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_X, new Control(ControlType.KEY,GLFW_KEY_X));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Y, new Control(ControlType.KEY,GLFW_KEY_Y));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Z, new Control(ControlType.KEY,GLFW_KEY_Z));
/*
Inventory controls
*/
handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(true,false,GLFW_KEY_I));
handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(false,true,GLFW_MOUSE_BUTTON_1));
handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(ControlType.KEY,GLFW_KEY_I));
handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_1));
handler.addControl(INPUT_CODE_INVENTORY_ITEM_DRAG, new Control(ControlType.MOUSE_MOVEMENT,0));
/*
set state
@ -224,7 +254,7 @@ public class ControlHandler {
/*
Debug controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM, new Control(true,false,GLFW_KEY_Q));
handler.addControl(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM, new Control(ControlType.KEY,GLFW_KEY_Q));
/*
return
@ -284,6 +314,70 @@ public class ControlHandler {
}
void setMainGameControls(){
/*
Camera rotation
*/
mainGameControlList.add(controls.get(INPUT_CODE_CAMERA_ROTATION));
controls.get(INPUT_CODE_CAMERA_ROTATION).setOnMove(new Control.MouseCallback(){
float mouseSensitivity = .1f;
float cameraSpeed;
float yaw = 150;
float pitch = 50;
Vector3f cameraRotationVector = new Vector3f();
public void execute(MouseEvent event){
cameraSpeed = 2.5f * Main.deltaTime;
if(Globals.controlHandler != null && !Globals.controlHandler.isMouseVisible()){
yaw = yaw + event.getDeltaX() * mouseSensitivity;
pitch = pitch - event.getDeltaY() * mouseSensitivity;
if (pitch > 100.0f) {
pitch = 100.0f;
}
if (pitch < -99.0f) {
pitch = -99.0f;
}
}
if(Crosshair.getCrosshairActive()){
// if(Globals.playerCharacter != null){
// Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
// CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
// }
Vector3d characterPos = EntityUtils.getPosition(Globals.playerCharacter);
Vector3d targetPos = Crosshair.getTargetPosition();
Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize();
cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize();
yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x));
CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
} else {
CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
// if(Globals.playerCharacter != null){
// Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
// CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
// }
float cam_Player_Orbit_Magnitude = 5f;
cameraRotationVector.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
cameraRotationVector.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
cameraRotationVector.z = 0 + (float) Math.sin(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
cameraRotationVector.normalize();
}
CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
}});
/*
Move forward
*/
@ -627,9 +721,20 @@ public class ControlHandler {
*/
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU));
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setOnPress(new ControlMethod(){public void execute(){
Globals.currentMenu = MenuUtils.createInGameMainMenu();
MenuUtils.makeMenuDrawable(Globals.currentMenu);
// Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, MenuGenerators.createInGameMainMenu());
// Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Element mainMenuInGame = MenuGenerators.createInGameMainMenu();
mainMenuWindow.addChild(mainMenuInGame);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenuWindow);
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), true);
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
Globals.controlHandler.showMouse();
// Element mainMenu = MenuGenerators.createInGameMainMenu();
// Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenu);
// MenuGenerators.makeMenuDrawable(mainMenu);
// Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
}});
/*
@ -638,9 +743,18 @@ public class ControlHandler {
mainGameControlList.add(controls.get(INPUT_CODE_INVENTORY_OPEN));
controls.get(INPUT_CODE_INVENTORY_OPEN).setOnPress(new ControlMethod(){public void execute(){
if(InventoryUtils.hasNaturalInventory(Globals.playerCharacter)){
//create window
Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerCharacter);
Globals.currentMenu = MenuUtils.createNaturalInventoryMenu(inventory);
MenuUtils.makeMenuDrawable(Globals.currentMenu);
//create window contents
Element inventoryUI = MenuGenerators.createNaturalInventoryMenu(inventory);
//add contents
mainMenuWindow.addChild(inventoryUI);
//register
Globals.elementManager.registerWindow(WindowUtils.getInventoryWindowID(inventory.getId()), mainMenuWindow);
//make visible
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowUtils.getInventoryWindowID(inventory.getId())), true);
//controls
Globals.controlHandler.setHandlerState(ControlsState.INVENTORY);
Globals.controlHandler.showMouse();
}
@ -660,66 +774,32 @@ public class ControlHandler {
void setMenuNavigationControls(){
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT));
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setOnPress(new ControlMethod(){public void execute(){
Globals.currentMenu.incrementMenuOption();
// Globals.currentMenu.incrementMenuOption();
Globals.elementManager.focusNextElement(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN));
}});
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT));
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setOnPress(new ControlMethod(){public void execute(){
Globals.currentMenu.decrementMenuOption();
// Globals.currentMenu.decrementMenuOption();
Globals.elementManager.focusPreviousElement(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN));
}});
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT));
controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setOnPress(new ControlMethod(){public void execute(){
MenuTransition.selectOption(Globals.currentMenu);
Globals.elementManager.click(new ClickEvent(
Globals.elementManager.getFocusedElement().getPositionX(),
Globals.elementManager.getFocusedElement().getPositionY(),
true,
Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2)
));
// MenuCallbacks.selectOption(Globals.currentMenu);
}});
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT));
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setOnPress(new ControlMethod(){public void execute(){
MenuTransition.backout(Globals.currentMenu);
// MenuCallbacks.backout(Globals.currentMenu);
}});
}
public void runHandlers(List<Control> controls){
for(Control control : controls){
if(control.isIsKey()){
if(Globals.controlCallback.getKey(control.getKeyValue())){
if(!control.isState()){
//on press
control.onPress();
} else {
//on repeat
control.onRepeat();
}
control.setState(true);
} else {
if(control.isState()){
//on release
control.onRelease();
} else {
}
control.setState(false);
}
} else if(control.isIsMouse()){
if(Globals.mouseCallback.getButton(control.getKeyValue())){
if(!control.isState()){
//on press
control.onPress();
} else {
//on repeat
control.onRepeat();
}
control.setState(true);
} else {
if(control.isState()){
//on release
control.onRelease();
} else {
}
control.setState(false);
}
}
}
}
void setTypingControls(){
@ -766,7 +846,12 @@ public class ControlHandler {
for(String currentKey : typeKeybinds){
typingControlList.add(controls.get(currentKey));
controls.get(currentKey).setOnPress(new ControlMethod(){public void execute(){
MenuTransition.menuHandleKeypress(Globals.currentMenu,currentKey);
Globals.elementManager.fireEvent(
new KeyboardEvent(currentKey),
Globals.elementManager.getFocusedElement().getPositionX(),
Globals.elementManager.getFocusedElement().getPositionY()
);
// MenuCallbacks.menuHandleKeypress(Globals.currentMenu,currentKey);
}});
// if(controls.get(currentKey).isIsKey() && Globals.controlCallback.getKey(controls.get(currentKey).getKeyValue())){
// controls.get(currentKey).setState(true);
@ -785,15 +870,109 @@ public class ControlHandler {
*/
inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_CLOSE));
controls.get(INPUT_CODE_INVENTORY_CLOSE).setOnPress(new ControlMethod(){public void execute(){
MenuTransition.backout(Globals.currentMenu);
// MenuCallbacks.backout(Globals.currentMenu);
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerCharacter);
Element inventoryWindow = Globals.elementManager.getWindow(WindowUtils.getInventoryWindowID(inventory.getId()));
WindowUtils.recursiveSetVisible(inventoryWindow, false);
hideMouse();
Globals.elementManager.unregisterWindow(WindowUtils.getInventoryWindowID(inventory.getId()));
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
}});
/*
Item manipulation
*/
inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE));
controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnPress(new ControlMethod(){public void execute(){
}});
controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnRelease(new ControlMethod(){public void execute(){
if(dragging){
dragging = false;
//fire dragrelease event to elementmanager
Globals.elementManager.dragRelease((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos));
} else {
//fire onclick event to elementmanager
Globals.elementManager.click(new ClickEvent((int)xpos,(int)ypos,true,Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2)));
}
}});
/*
item dragging
*/
inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_ITEM_DRAG));
controls.get(INPUT_CODE_INVENTORY_ITEM_DRAG).setOnMove(new Control.MouseCallback(){public void execute(MouseEvent event){
if(!dragging && event.getButton1()){
dragging = true;
//fire dragstart event to elementmanager
Globals.elementManager.dragStart((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos));
}
if(dragging){
//fire drag event to elementmanager
Globals.elementManager.drag((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos));
}
}});
}
public void runHandlers(List<Control> controls){
//construct mouse event
glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
xpos = mouse_X_Buffer[0];
ypos = mouse_Y_Buffer[0];
float xoffset = (float) (xpos - mouse_lastX);
float yoffset = (float) (mouse_lastY - ypos);
mouse_lastX = (float) xpos;
mouse_lastY = (float) ypos;
MouseEvent currentMouseEvent = new MouseEvent((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)xoffset,(int)yoffset,Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_1),Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2));
boolean mouseMoveEvent = xoffset != 0 || yoffset != 0;
for(Control control : controls){
switch(control.getType()){
case KEY:
if(Globals.controlCallback.getKey(control.getKeyValue())){
if(!control.isState()){
//on press
control.onPress();
} else {
//on repeat
control.onRepeat();
}
control.setState(true);
} else {
if(control.isState()){
//on release
control.onRelease();
} else {
}
control.setState(false);
}
break;
case MOUSE_BUTTON:
if(Globals.mouseCallback.getButton(control.getKeyValue())){
if(!control.isState()){
//on press
control.onPress();
} else {
//on repeat
control.onRepeat();
}
control.setState(true);
} else {
if(control.isState()){
//on release
control.onRelease();
} else {
}
control.setState(false);
}
break;
case MOUSE_MOVEMENT:
if(mouseMoveEvent){
control.onMove(currentMouseEvent);
}
break;
}
}
}
public Control getControl(String controlName){

View File

@ -2,7 +2,6 @@ package electrosphere.engine;
import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.ApplyRotationTree;
@ -18,6 +17,7 @@ import electrosphere.game.simulation.MacroSimulation;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.particle.ParticleUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.foliage.FoliageUtils;
@ -34,8 +34,9 @@ import electrosphere.game.server.datacell.DataCellManager;
import electrosphere.game.simulation.MicroSimulation;
import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import static electrosphere.main.Globals.loadingBox;
import electrosphere.menu.MenuUtils;
import electrosphere.menu.MenuGenerators;
import electrosphere.menu.WindowStrings;
import electrosphere.menu.WindowUtils;
import electrosphere.net.NetUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
@ -49,8 +50,10 @@ import electrosphere.game.server.pathfinding.NavMeshPathfinder;
import electrosphere.game.server.pathfinding.navmesh.NavCube;
import electrosphere.game.server.pathfinding.navmesh.NavMesh;
import electrosphere.game.server.unit.UnitUtils;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.WidgetUtils;
import electrosphere.renderer.ui.Window;
import java.util.Random;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@ -83,6 +86,7 @@ public class LoadingThread extends Thread {
@Override
public void run(){
lock.acquireUninterruptibly();
Window loadingWindow = (Window)Globals.elementManager.getWindow(WindowStrings.WINDOW_LOADING);
switch(threadType){
@ -93,13 +97,8 @@ public class LoadingThread extends Thread {
case LOAD_TITLE_MENU:
Globals.currentMenu = MenuUtils.createTitleMenu();
loadingBox.setVisible(false);
MenuUtils.makeMenuDrawable(Globals.currentMenu);
WindowUtils.recursiveSetVisible(loadingWindow,false);
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), true);
break;
@ -111,8 +110,8 @@ public class LoadingThread extends Thread {
case LOAD_MAIN_GAME:
loadingBox.setVisible(true);
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
loadingWindow.setVisible(true);
//disable menu input
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
@ -188,11 +187,8 @@ public class LoadingThread extends Thread {
//hide cursor
Globals.controlHandler.hideMouse();
//create in game ui
showInGameUI();
loadingBox.setVisible(false);
loadingWindow.setVisible(false);
RenderUtils.recaptureScreen();
@ -217,8 +213,8 @@ public class LoadingThread extends Thread {
case LOAD_ARENA:
loadingBox.setVisible(true);
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
loadingWindow.setVisible(true);
//disable menu input
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
@ -278,10 +274,7 @@ public class LoadingThread extends Thread {
//hide cursor
Globals.controlHandler.hideMouse();
//create in game ui
showInGameUI();
loadingBox.setVisible(false);
loadingWindow.setVisible(false);
RenderUtils.recaptureScreen();
@ -554,7 +547,7 @@ public class LoadingThread extends Thread {
Player Camera
*/
Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,0));
Globals.playerCamera = CameraEntityUtils.spawnEntityTrackingCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,0), Globals.playerCharacter);
@ -583,13 +576,6 @@ public class LoadingThread extends Thread {
Globals.microSimulation = new MicroSimulation();
}
static void showInGameUI(){
for(Widget widget : Globals.inGameUI){
// System.out.println("Set widget visible");
widget.setVisible(true);
}
}
static void setSimulationsToReady(){
Globals.microSimulation.setReady(true);
if(Globals.macroSimulation != null){

View File

@ -7,14 +7,26 @@ import electrosphere.entity.Entity;
public class UnrelationalInventoryState {
static int inventoryIncrementer = 0;
int capacity;
int id;
List<Entity> items = new LinkedList<Entity>();
public UnrelationalInventoryState(int capacity){
public static UnrelationalInventoryState createUnrelationalInventory(int capacity){
return new UnrelationalInventoryState(inventoryIncrementer++,capacity);
}
UnrelationalInventoryState(int id, int capacity){
this.id = id;
this.capacity = capacity;
}
// public UnrelationalInventoryState(int capacity){
// this.capacity = capacity;
// }
public void addItem(Entity item){
items.add(item);
}
@ -31,5 +43,9 @@ public class UnrelationalInventoryState {
return capacity;
}
public int getId(){
return id;
}
}

View File

@ -5,7 +5,7 @@ import electrosphere.entity.state.gravity.GravityTree;
import electrosphere.entity.state.gravity.GravityUtils;
import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.dynamics.RigidBody;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;

View File

@ -1,8 +1,13 @@
package electrosphere.entity;
package electrosphere.entity.types.camera;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.main.Globals;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3d;
import org.joml.Vector3f;
/**
@ -23,7 +28,7 @@ public class CameraEntityUtils {
return rVal;
}
public static Entity spawnPointTrackingCameraEntity(Vector3f center, Vector3f eye){
public static Entity spawnEntityTrackingCameraEntity(Vector3f center, Vector3f eye, Entity toTrack){
Entity rVal = new Entity();
Globals.entityManager.registerEntity(rVal);
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT);
@ -31,6 +36,17 @@ public class CameraEntityUtils {
rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_EYE, eye);
rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f);
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
BehaviorTree entityTrackingTree = new BehaviorTree() {
@Override
public void simulate() {
// TODO Auto-generated method stub
if(toTrack != null){
Vector3d entityPos = EntityUtils.getPosition(toTrack);
CameraEntityUtils.setCameraCenter(rVal, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z));
}
}
};
Globals.entityManager.registerBehaviorTree(entityTrackingTree);
return rVal;
}

View File

@ -192,7 +192,7 @@ public class CreatureUtils {
// rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,"MiddleLower.R"));
break;
case "INVENTORY":
rVal.putData(EntityDataStrings.NATURAL_INVENTORY,new UnrelationalInventoryState(10));
rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10));
break;
}
}

View File

@ -1,10 +1,10 @@
package electrosphere.entity.types.particle;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.ParticleTree;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.main.Globals;
import org.joml.AxisAngle4f;
import org.joml.Matrix4f;

View File

@ -1,7 +1,7 @@
package electrosphere.game.client;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.main.Globals;
import org.joml.Vector3f;

View File

@ -1,8 +1,8 @@
package electrosphere.game.client.targeting.crosshair;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.main.Globals;
import org.joml.Vector3d;

View File

@ -13,6 +13,7 @@ import electrosphere.controls.ControlHandler;
import electrosphere.controls.MouseCallback;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
import electrosphere.game.collision.CollisionEngine;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.game.client.cells.DrawCellManager;
@ -38,7 +39,9 @@ import electrosphere.game.server.world.MacroData;
import electrosphere.game.server.datacell.DataCellManager;
import electrosphere.game.simulation.MicroSimulation;
import electrosphere.logger.LoggerInterface;
import electrosphere.menu.Menu;
import electrosphere.menu.MenuGenerators;
import electrosphere.menu.WindowStrings;
import electrosphere.menu.WindowUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Player;
import electrosphere.net.server.PlayerManager;
@ -50,13 +53,13 @@ import electrosphere.renderer.ShaderProgram;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.engine.assetmanager.AssetManager;
import electrosphere.game.server.pathfinding.NavMeshManager;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.WidgetManager;
import electrosphere.renderer.ui.ElementManager;
import electrosphere.renderer.ui.WidgetUtils;
import electrosphere.renderer.ui.WindowManager;
import electrosphere.renderer.ui.Window;
import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.font.FontUtils;
import electrosphere.renderer.ui.font.RawFontMap;
import electrosphere.renderer.ui.font.TextBox;
import electrosphere.util.FileUtils;
import java.io.File;
import java.io.IOException;
@ -218,10 +221,6 @@ public class Globals {
public static ShaderProgram defaultMeshShader;
public static ShaderProgram terrainShaderProgram;
public static Menu currentMenu;
public static List<Widget> inGameUI = new LinkedList<Widget>();
public static String particleBillboardModel;
@ -275,15 +274,9 @@ public class Globals {
//thread for loading different game states
public static LoadingThread loadingThread;
//manages all windows to be drawn to the screen
public static WindowManager windowManager;
//manager for all widgets currently being drawn to screen
public static WidgetManager widgetManager;
//ui text box for loading text
public static TextBox loadingBox;
public static ElementManager elementManager;
//collision world data
public static CommonWorldData commonWorldData;
@ -304,6 +297,10 @@ public class Globals {
//ai manager
public static AIManager aiManager;
//drag item state
public static Entity draggedItem = null;
public static UnrelationalInventoryState dragSourceInventory = null;
@ -336,7 +333,7 @@ public class Globals {
//load asset manager
assetManager = new AssetManager();
//load widget manager
widgetManager = new WidgetManager();
elementManager = new ElementManager();
//hitbox manager
hitboxManager = new HitboxManager();
//ai manager
@ -385,8 +382,8 @@ public class Globals {
//off white texture for backgrounds
offWhiteTexture = "Textures/ow1.png";
Globals.assetManager.addTexturePathtoQueue(offWhiteTexture);
//loading box
loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
//initialize required windows
WindowUtils.initBaseWindows();
//init default shaderProgram
defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true);
//init terrain shader program
@ -402,6 +399,10 @@ public class Globals {
assetManager.addModelPathToQueue("Models/unitplane.fbx");
assetManager.addModelPathToQueue("Models/unitcube.fbx");
planeModelID = assetManager.registerModel(RenderUtils.createPlaneModel());
//image panel
ImagePanel.imagePanelModelPath = assetManager.registerModel(RenderUtils.createPlaneModel());
Globals.assetManager.queueOverrideMeshShader(ImagePanel.imagePanelModelPath, "plane", "Shaders/font/bitmapchar/bitmapchar.vs", "Shaders/font/bitmapchar/bitmapchar.fs");
//init ui images
assetManager.addTexturePathtoQueue("Textures/ui/WindowBorder.png");
@ -409,8 +410,8 @@ public class Globals {
testingTexture = "Textures/Testing1.png";
Globals.assetManager.addTexturePathtoQueue(testingTexture);
//in game ui stuff
inGameUI.add(WidgetUtils.createInGameMainMenuButton());
// //in game ui stuff
// elementManager.registerWindow(WindowStrings.WINDOW_MENU_MAIN,WidgetUtils.createInGameMainMenuButton());
@ -418,4 +419,7 @@ public class Globals {
//load them into memory now. The loading time penalty is worth it I think.
Globals.assetManager.loadAssetsInQueue();
}
}

View File

@ -5,7 +5,6 @@ import electrosphere.audio.AudioEngine;
import electrosphere.audio.AudioSource;
import electrosphere.audio.AudioUtils;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
@ -16,6 +15,7 @@ import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.engine.LoadingThread;
import electrosphere.game.client.ClientFunctions;
import electrosphere.game.client.targeting.crosshair.Crosshair;
@ -74,16 +74,16 @@ public class Main {
/*
Mouse Controls
*/
static float mouse_lastX = 400;
static float mouse_lastY = 300;
static double xpos = 400;
static double ypos = 300;
static float mouseSensitivity = .1f;
static double mouse_X_Buffer[] = new double[1];
static double mouse_Y_Buffer[] = new double[1];
static float cameraSpeed;
static float yaw = 150;
static float pitch = 50;
// static float mouse_lastX = 400;
// static float mouse_lastY = 300;
// static double xpos = 400;
// static double ypos = 300;
// static float mouseSensitivity = .1f;
// static double mouse_X_Buffer[] = new double[1];
// static double mouse_Y_Buffer[] = new double[1];
// static float cameraSpeed;
// static float yaw = 150;
// static float pitch = 50;
@ -216,7 +216,7 @@ public class Main {
///
/// C A M E R A C R E A T I O N
///
Vector3f cameraRotationVector = new Vector3f();
// Vector3f cameraRotationVector = new Vector3f();
//main loop
while (running) {
@ -250,7 +250,7 @@ public class Main {
///
/// I N P U T C O N T R O L S
///
cameraSpeed = 2.5f * deltaTime;
// cameraSpeed = 2.5f * deltaTime;
// if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS && Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT) {
// break;
// }
@ -308,67 +308,67 @@ public class Main {
/// C A M E R A S T U F F
///
//poll mouse variables and update camera variables
if(Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT){
// if(Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT){
updateMouseVariables();
// updateMouseVariables();
if(Crosshair.getCrosshairActive()){
// if(Crosshair.getCrosshairActive()){
if(Globals.playerCharacter != null){
Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
}
// if(Globals.playerCharacter != null){
// Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
// CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
// }
Vector3d characterPos = EntityUtils.getPosition(Globals.playerCharacter);
Vector3d targetPos = Crosshair.getTargetPosition();
Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize();
cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize();
// Vector3d characterPos = EntityUtils.getPosition(Globals.playerCharacter);
// Vector3d targetPos = Crosshair.getTargetPosition();
// Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize();
// cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize();
yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x));
// yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x));
CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
// CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
// CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
} else {
CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
// } else {
// CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
// CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
if(Globals.playerCharacter != null){
Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
}
// if(Globals.playerCharacter != null){
// Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
// CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
// }
float cam_Player_Orbit_Magnitude = 5f;
cameraRotationVector.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
cameraRotationVector.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
cameraRotationVector.z = 0 + (float) Math.sin(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
cameraRotationVector.normalize();
}
// float cam_Player_Orbit_Magnitude = 5f;
// cameraRotationVector.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
// cameraRotationVector.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
// cameraRotationVector.z = 0 + (float) Math.sin(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
// cameraRotationVector.normalize();
// }
CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
// CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
// if(Crosshair.getCrosshairActive()){
// CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
// } else {
// CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
// }
// // if(Crosshair.getCrosshairActive()){
// // CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
// // } else {
// // CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
// // }
// if(Globals.playerCharacter != null){
// Vector3f playerPos = EntityUtils.getPosition(Globals.playerCharacter);
// if(posX == -1 && playerPos.x > 100){
// posX = playerPos.x;
// posZ = playerPos.z;
// }
// posX = posX - (cameraRotationVector.x * 0.01);
// posZ = posZ - (cameraRotationVector.z * 0.01);
// Vector3f moveVec = new Vector3f(-cameraRotationVector.x,0,-cameraRotationVector.z);
// Quaternionf playerRot = new Quaternionf().rotationTo(new Vector3f(0,0,1), moveVec);
// EntityUtils.getRotation(Globals.playerCharacter).set(playerRot);
// EntityUtils.getPosition(Globals.playerCharacter).set((float)posX,playerPos.y,(float)posZ);
// }
// // if(Globals.playerCharacter != null){
// // Vector3f playerPos = EntityUtils.getPosition(Globals.playerCharacter);
// // if(posX == -1 && playerPos.x > 100){
// // posX = playerPos.x;
// // posZ = playerPos.z;
// // }
// // posX = posX - (cameraRotationVector.x * 0.01);
// // posZ = posZ - (cameraRotationVector.z * 0.01);
// // Vector3f moveVec = new Vector3f(-cameraRotationVector.x,0,-cameraRotationVector.z);
// // Quaternionf playerRot = new Quaternionf().rotationTo(new Vector3f(0,0,1), moveVec);
// // EntityUtils.getRotation(Globals.playerCharacter).set(playerRot);
// // EntityUtils.getPosition(Globals.playerCharacter).set((float)posX,playerPos.y,(float)posZ);
// // }
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
}
// Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
// }
@ -426,27 +426,27 @@ public class Main {
public static void updateMouseVariables(){
glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
xpos = mouse_X_Buffer[0];
ypos = mouse_Y_Buffer[0];
float xoffset = (float) (xpos - mouse_lastX) * mouseSensitivity;
float yoffset = (float) (mouse_lastY - ypos) * mouseSensitivity;
mouse_lastX = (float) xpos;
mouse_lastY = (float) ypos;
// public static void updateMouseVariables(){
// glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
// xpos = mouse_X_Buffer[0];
// ypos = mouse_Y_Buffer[0];
// float xoffset = (float) (xpos - mouse_lastX) * mouseSensitivity;
// float yoffset = (float) (mouse_lastY - ypos) * mouseSensitivity;
// mouse_lastX = (float) xpos;
// mouse_lastY = (float) ypos;
if(Globals.controlHandler != null && !Globals.controlHandler.isMouseVisible()){
yaw = yaw + xoffset;
pitch = pitch - yoffset;
// if(Globals.controlHandler != null && !Globals.controlHandler.isMouseVisible()){
// yaw = yaw + xoffset;
// pitch = pitch - yoffset;
if (pitch > 100.0f) {
pitch = 100.0f;
}
if (pitch < -99.0f) {
pitch = -99.0f;
}
}
}
// if (pitch > 100.0f) {
// pitch = 100.0f;
// }
// if (pitch < -99.0f) {
// pitch = -99.0f;
// }
// }
// }

View File

@ -1,104 +0,0 @@
package electrosphere.menu;
import electrosphere.audio.AudioSource;
import electrosphere.audio.AudioUtils;
import electrosphere.main.Globals;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.font.TextBox;
import java.util.ArrayList;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class Menu {
public enum MenuType {
TITLE_MENU,
WORLD_SELECT_MENU, //select preexisting world (Char already created)
WORLD_CREATE_MENU, //create world
SAVE_CREATE_MENU, //select basic save settings
CHARACTER_CREATE_MENU, //create character
FINALIZE_SAVE_CREATION_MENU, //finalize the save before we commit
MULTIPLAYER_MENU,
IP_MENU,
OPTIONS_MAIN_MENU,
IN_GAME_MAIN_MENU,
TEST,
INVENTORY_NATURAL,
}
MenuType type;
int option = 0;
int optionMax = 0;
List<Widget> widgetList = new ArrayList<Widget>();
List<Widget> optionList = new ArrayList<Widget>();
public Menu(MenuType type){
this.type = type;
}
public void addOption(Widget option){
widgetList.add(option);
optionList.add(option);
optionMax++;
}
public void addElement(Widget element){
widgetList.add(element);
}
public void dispose(){
for(Widget w : widgetList){
Globals.widgetManager.unregisterWidget(w);
}
widgetList.clear();
optionList.clear();
}
public void incrementMenuOption(){
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,1.0f));
option++;
if(option>=optionMax){
option = 0;
}
setMenuOptionColor(option,new Vector3f(0.2f,0.8f,0.5f));
AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuChangeOption.ogg", new Vector3f(0,0,0));
}
public void decrementMenuOption(){
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,1.0f));
option--;
if(option < 0){
option = optionMax - 1;
}
setMenuOptionColor(option,new Vector3f(0.2f,0.8f,0.5f));
AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuChangeOption.ogg", new Vector3f(0,0,0));
}
public Widget getCurrentOption(){
return optionList.get(option);
}
public MenuType getType(){
return type;
}
public void setMenuOptionColor(int option, Vector3f color){
if(optionList.get(option) instanceof TextBox){
((TextBox)optionList.get(option)).setColor(color);
}
}
public List<Widget> getOptions(){
return optionList;
}
public List<Widget> getWidgets(){
return widgetList;
}
}

View File

@ -0,0 +1,357 @@
package electrosphere.menu;
import electrosphere.audio.AudioSource;
import electrosphere.audio.AudioUtils;
import electrosphere.controls.ControlHandler;
import electrosphere.controls.ControlHandler.ControlsState;
import electrosphere.engine.LoadingThread;
import electrosphere.game.server.saves.SaveUtils;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.NetUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.elements.Label;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class MenuCallbacks {
// public static void selectOption(Menu m){
// switch(m.getType()){
// case TITLE_MENU:
// switch(((TextBox)m.getCurrentOption()).getText()){
// //single player
// case "SINGLEPLAYER":
// // m.dispose();
// // Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
// // Globals.RUN_CLIENT = true;
// // Globals.RUN_SERVER = true;
// // Globals.loadingThread.start();
// m.dispose();
// Globals.currentMenu = MenuGenerators.createWorldSelectMenu();
// break;
// //multi player
// case "MULTIPLAYER":
// m.dispose();
// Globals.currentMenu = MenuGenerators.createMultiplayerMenu();
// break;
// //arena
// case "ARENA":
// m.dispose();
// Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
// Globals.RUN_CLIENT = true;
// Globals.RUN_SERVER = true;
// Globals.loadingThread.start();
// break;
// //options
// case "OPTIONS":
// m.dispose();
// Globals.currentMenu = MenuGenerators.createOptionsMainMenu();
// break;
// //test
// case "UI TESTING":
// m.dispose();
// Globals.currentMenu = MenuGenerators.createTestMainMenu();
// break;
// }
// break;
// case WORLD_SELECT_MENU:
// switch(((TextBox)m.getCurrentOption()).getText()){
// case "CREATE WORLD":
// m.dispose();
// Globals.currentMenu = MenuGenerators.createWorldCreationMenu();
// break;
// default:
// String worldName = ((TextBox)m.getCurrentOption()).getText();
// m.dispose();
// //check if has save or not
// if(SaveUtils.worldHasSave(worldName.toLowerCase())){
// Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
// Globals.RUN_CLIENT = true;
// Globals.RUN_SERVER = true;
// Globals.loadingThread.start();
// } else {
// Globals.currentSaveName = worldName.toLowerCase();
// SaveUtils.loadTerrainAndCreateWorldData();
// Globals.currentMenu = MenuGenerators.createSaveCreationMenu();
// }
// break;
// }
// break;
// case WORLD_CREATE_MENU:
// break;
// case SAVE_CREATE_MENU:
// switch(((TextBox)m.getCurrentOption()).getText()){
// case "SAVE":
// m.dispose();
// SaveUtils.saveWorldDataToSave(Globals.currentSaveName);
// Globals.currentMenu = MenuGenerators.createWorldSelectMenu();
// break;
// case "CANCEL":
// m.dispose();
// Globals.currentMenu = MenuGenerators.createWorldSelectMenu();
// break;
// }
// break;
// case CHARACTER_CREATE_MENU:
// break;
// case FINALIZE_SAVE_CREATION_MENU:
// break;
// case MULTIPLAYER_MENU:
// switch(((TextBox)m.getCurrentOption()).getText()){
// //HOST
// case "HOST":
// m.dispose();
// Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
// Globals.RUN_CLIENT = true;
// Globals.RUN_SERVER = true;
// Globals.loadingThread.start();
// break;
// //JOIN
// case "JOIN":
// m.dispose();
// Globals.currentMenu = MenuGenerators.createIPMenu();
// break;
// //back
// case "BACK":
// backout(m);
// break;
// }
// break;
// case IP_MENU:
// switch(((TextBox)m.getCurrentOption()).getText()){
// //connect
// case "CONNECT":
// NetUtils.setAddress( ( (TextBox)m.getOptions().get(0) ).getText() );
// NetUtils.setPort( Integer.parseInt( ( (TextBox)m.getOptions().get(1) ).getText() ) );
// m.dispose();
// Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
// Globals.RUN_CLIENT = true;
// Globals.RUN_SERVER = false;
// Globals.loadingThread.start();
// break;
// //back
// case "BACK":
// backout(m);
// break;
// }
// break;
// case IN_GAME_MAIN_MENU:
// switch(((Label)m.getCurrentOption()).getText()){
// //connect
// case "QUIT":
// //TODO: actually shut down program
// Globals.ENGINE_SHUTDOWN_FLAG = true;
// break;
// //back
// case "BACK":
// MenuGenerators.makeMenuUndrawable(Globals.currentMenu);
// Globals.currentMenu.dispose();
// Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
// break;
// }
// break;
// }
// }
// public static void backout(Menu m){
// AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuBackspace.ogg", new Vector3f(0,0,0));
// switch(m.getType()){
// case TITLE_MENU:
// Main.running = false;
// break;
// case WORLD_SELECT_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createTitleMenu();
// break;
// case WORLD_CREATE_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createWorldSelectMenu();
// break;
// case SAVE_CREATE_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createWorldSelectMenu();
// break;
// case CHARACTER_CREATE_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createSaveCreationMenu();
// break;
// case FINALIZE_SAVE_CREATION_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createCharacterCreationMenu();
// break;
// case MULTIPLAYER_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createTitleMenu();
// break;
// case IP_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createMultiplayerMenu();
// break;
// case OPTIONS_MAIN_MENU:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createTitleMenu();
// break;
// case TEST:
// m.dispose();
// Globals.currentMenu = MenuGenerators.createTitleMenu();
// break;
// case IN_GAME_MAIN_MENU:
// MenuGenerators.makeMenuUndrawable(Globals.currentMenu);
// Globals.currentMenu.dispose();
// Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
// break;
// case INVENTORY_NATURAL:
// MenuGenerators.makeMenuUndrawable(Globals.currentMenu);
// Globals.currentMenu.dispose();
// Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
// Globals.controlHandler.hideMouse();
// break;
// }
// }
// public static void menuHandleKeypress(Menu m, String keycode){
// char toWrite = ' ';
// DrawableElement currentOption = m.getCurrentOption();
// boolean backspace = false;
// switch(keycode){
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE:
// if(currentOption instanceof TextBox){
// TextBox currentTextBox = (TextBox)currentOption;
// String currentText = currentTextBox.getText();
// if(currentText.length() > 0){
// currentTextBox.setText(currentText.substring(0, currentText.length() - 1));
// AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuBackspace.ogg", new Vector3f(0,0,0));
// }
// }
// backspace = true;
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_0:
// toWrite = '0';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_1:
// toWrite = '1';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_2:
// toWrite = '2';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_3:
// toWrite = '3';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_4:
// toWrite = '4';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_5:
// toWrite = '5';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_6:
// toWrite = '6';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_7:
// toWrite = '7';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_8:
// toWrite = '8';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_9:
// toWrite = '9';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_A:
// toWrite = 'A';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_B:
// toWrite = 'B';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_C:
// toWrite = 'C';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_D:
// toWrite = 'D';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_E:
// toWrite = 'E';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_F:
// toWrite = 'F';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_G:
// toWrite = 'G';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_H:
// toWrite = 'H';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_I:
// toWrite = 'I';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_J:
// toWrite = 'J';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_K:
// toWrite = 'K';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_L:
// toWrite = 'L';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_M:
// toWrite = 'M';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_N:
// toWrite = 'N';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_O:
// toWrite = 'O';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_P:
// toWrite = 'P';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_Q:
// toWrite = 'Q';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_R:
// toWrite = 'R';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_S:
// toWrite = 'S';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_T:
// toWrite = 'T';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_U:
// toWrite = 'U';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_V:
// toWrite = 'V';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_W:
// toWrite = 'W';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_X:
// toWrite = 'X';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_Y:
// toWrite = 'Y';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_Z:
// toWrite = 'Z';
// break;
// case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD:
// toWrite = '.';
// break;
// }
// if(!backspace){
// if(currentOption instanceof TextBox){
// TextBox currentTextBox = (TextBox)currentOption;
// String currentText = currentTextBox.getText();
// if(currentText.length() < currentTextBox.getCols()){
// currentTextBox.setText(currentText + toWrite);
// AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuType.ogg", new Vector3f(0,0,0));
// }
// }
// }
// }
}

View File

@ -0,0 +1,548 @@
package electrosphere.menu;
import electrosphere.engine.LoadingThread;
import electrosphere.entity.Entity;
import electrosphere.entity.state.inventory.InventoryUtils;
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.server.saves.SaveUtils;
import electrosphere.main.Globals;
import electrosphere.net.NetUtils;
import electrosphere.net.server.Server;
import electrosphere.renderer.ui.ClickableElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.FocusableElement;
import electrosphere.renderer.ui.WidgetUtils;
import electrosphere.renderer.ui.Window;
import electrosphere.renderer.ui.DraggableElement.DragEventCallback;
import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elements.TextInput;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.DragEvent;
import electrosphere.renderer.ui.form.FormElement;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class MenuGenerators {
public static Element createTitleMenu(){
FormElement rVal = new FormElement();
//label (title)
Label titleLabel = new Label(100,150,1.0f);
titleLabel.setText("ORPG");
rVal.addChild(titleLabel);
//button (multiplayer)
Button singleplayerButton = new Button();
Label singleplayerLabel = new Label(100,275,1.0f);
singleplayerLabel.setText("Singleplayer");
singleplayerButton.addChild(singleplayerLabel);
rVal.addChild(singleplayerButton);
singleplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
return false;
}});
//button (multiplayer)
Button multiplayerButton = new Button();
Label multiplayerLabel = new Label(100,350,1.0f);
multiplayerLabel.setText("Multiplayer");
multiplayerButton.addChild(multiplayerLabel);
rVal.addChild(multiplayerButton);
multiplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
return false;
}});
//button (arena)
Button arenaButton = new Button();
Label arenaLabel = new Label(100,425,1.0f);
arenaLabel.setText("Arena");
arenaButton.addChild(arenaLabel);
rVal.addChild(arenaButton);
arenaButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
return false;
}});
//button (options)
Button optionsButton = new Button();
Label optionsLabel = new Label(100,500,1.0f);
optionsLabel.setText("Options");
optionsButton.addChild(optionsLabel);
rVal.addChild(optionsButton);
optionsButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu());
return false;
}});
//button (ui testing)
Button uiTestingButton = new Button();
Label uiTestingLabel = new Label(100,575,1.0f);
uiTestingLabel.setText("UI Testing");
uiTestingButton.addChild(uiTestingLabel);
rVal.addChild(uiTestingButton);
uiTestingButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createUITestMenu());
return false;
}});
return rVal;
}
public static Element createWorldSelectMenu(){
FormElement rVal = new FormElement();
int screenTop = Globals.WINDOW_HEIGHT - 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
for(String saveName : saveNames){
if(!saveName.startsWith(".")){
//button (select save)
Button selectButton = new Button();
Label selectLabel = new Label(100,125 + verticalPosition,1.0f);
selectLabel.setText(saveName.toUpperCase());
selectButton.addChild(selectLabel);
rVal.addChild(selectButton);
selectButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
if(SaveUtils.worldHasSave(saveName.toLowerCase())){
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
} else {
Globals.currentSaveName = saveName.toLowerCase();
SaveUtils.loadTerrainAndCreateWorldData();
WindowUtils.replaceMainMenuContents(MenuGenerators.createSaveCreationMenu());
}
return false;
}});
verticalPosition = verticalPosition + 75;
}
}
//button (create)
Button createButton = new Button();
Label createLabel = new Label(100,125 + verticalPosition + 200,1.0f);
createLabel.setText("Create World");
createButton.addChild(createLabel);
rVal.addChild(createButton);
createButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldCreationMenu());
return false;
}});
return rVal;
}
public static Element createWorldCreationMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
//TODO: add text input to name world
//button (create)
Button createButton = new Button();
Label createLabel = new Label(100,screenTop + verticalPosition,1.0f);
createLabel.setText("Not implemented");
createButton.addChild(createLabel);
rVal.addChild(createButton);
createButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldCreationMenu());
return false;
}});
return rVal;
}
public static Element createSaveCreationMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
//button (save)
Button saveButton = new Button();
Label saveLabel = new Label(100,screenTop + 125,1.0f);
saveLabel.setText("Save");
saveButton.addChild(saveLabel);
rVal.addChild(saveButton);
saveButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
SaveUtils.saveWorldDataToSave(Globals.currentSaveName);
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
return false;
}});
//button (cancel)
Button cancelButton = new Button();
Label cancelLabel = new Label(100,screenTop + 200,1.0f);
cancelLabel.setText("Cancel");
cancelButton.addChild(cancelLabel);
rVal.addChild(cancelButton);
saveButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
return false;
}});
return rVal;
}
public static Element createCharacterCreationMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
//TODO: add text input to name world
//button (create)
Button createButton = new Button();
Label createLabel = new Label(100,screenTop + verticalPosition,1.0f);
createLabel.setText("Create World");
createButton.addChild(createLabel);
rVal.addChild(createButton);
return rVal;
}
public static Element createFinalizeSaveCreationMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
//TODO: add text input to name world
//button (create)
Button createButton = new Button();
Label createLabel = new Label(100,screenTop + verticalPosition,1.0f);
createLabel.setText("Create World");
createButton.addChild(createLabel);
rVal.addChild(createButton);
return rVal;
}
public static Element createMultiplayerMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
//button (host)
Button hostButton = new Button();
Label hostLabel = new Label(100,screenTop + 125,1.0f);
hostLabel.setText("Host");
hostButton.addChild(hostLabel);
rVal.addChild(hostButton);
hostButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
return false;
}});
//button (join)
Button joinButton = new Button();
Label joinLabel = new Label(100,screenTop + 200,1.0f);
joinLabel.setText("Join");
joinButton.addChild(joinLabel);
rVal.addChild(joinButton);
joinButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createIPMenu());
return false;
}});
//button (back)
Button connectButton = new Button();
Label connectLabel = new Label(100,screenTop + 275,1.0f);
connectLabel.setText("Back");
connectButton.addChild(connectLabel);
rVal.addChild(connectButton);
connectButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
return false;
}});
return rVal;
}
public static Element createIPMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
//label (address)
Label addressLabel = new Label(100,screenTop + 50,1.0f);
addressLabel.setText("IP Address");
rVal.addChild(addressLabel);
//text entry (address)
TextInput addressInput = new TextInput(100,screenTop + 125,40*15, 40);
addressInput.setText(NetUtils.getAddress());
rVal.addChild(addressInput);
//label (port)
Label portLabel = new Label(100,screenTop + 200,1.0f);
portLabel.setText("Port");
rVal.addChild(portLabel);
//text entry (port)
TextInput portInput = new TextInput(100,screenTop + 275,40*5, 40);
rVal.addChild(portInput);
//button (connect)
Button connectButton = new Button();
Label connectLabel = new Label(100,screenTop + 350,1.0f);
connectLabel.setText("Back");
connectButton.addChild(connectLabel);
rVal.addChild(connectButton);
connectButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
NetUtils.setAddress(addressInput.getText());
NetUtils.setPort(Integer.parseInt(portInput.getText()));
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = false;
Globals.loadingThread.start();
return false;
}});
//button (back)
Button backButton = new Button();
Label backLabel = new Label(100,screenTop + 425,1.0f);
backLabel.setText("Back");
backButton.addChild(backLabel);
rVal.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
return false;
}});
return rVal;
}
public static Element createOptionsMainMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
//label (options)
Label optionsLabel = new Label(100,screenTop + 50,1.0f);
optionsLabel.setText("Options");
rVal.addChild(optionsLabel);
//button (back)
Button backButton = new Button();
Label backLabel = new Label(100,screenTop + 275,1.0f);
backLabel.setText("Back");
backButton.addChild(backLabel);
rVal.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
return false;
}});
return rVal;
}
public static Element createUITestMenu(){
FormElement rVal = new FormElement();
int screenTop = 150;
//button (back)
Button backButton = new Button();
Label backLabel = new Label(100,screenTop + 275,1.0f);
backLabel.setText("Back");
backButton.addChild(backLabel);
rVal.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
return false;
}});
return rVal;
}
public static Element worldItemDropCaptureWindow(){
Div rVal = new Div();
rVal.setOnDragRelease(new DragEventCallback() {public boolean execute(DragEvent event){
if(Globals.draggedItem != null){
//remove item from inventory
Globals.dragSourceInventory.removeItem(Globals.draggedItem);
//drop item
InventoryUtils.attemptEjectItem(Globals.playerCharacter,Globals.draggedItem);
//clear ui
WindowUtils.cleanItemWindow();
String sourceWindowId = WindowUtils.getInventoryWindowID(Globals.dragSourceInventory.getId());
WindowUtils.replaceWindowContents(sourceWindowId,MenuGenerators.createNaturalInventoryMenu(Globals.dragSourceInventory));
//null globals
Globals.dragSourceInventory = null;
Globals.draggedItem = null;
return false;
}
return true;
}});
rVal.setPositionX(0);
rVal.setPositionY(0);
rVal.setWidth(Globals.WINDOW_WIDTH);
rVal.setHeight(Globals.WINDOW_HEIGHT);
return rVal;
}
public static Element createInGameMainMenu(){
int screenTop = Globals.WINDOW_HEIGHT - 150;
int width = 500;
int height = 500;
int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
FormElement rVal = new FormElement();
//black texture background
ImagePanel imagePanel = new ImagePanel(0,0,width,height,Globals.blackTexture);
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
rVal.addChild(imagePanel);
//label 1 (back)
Label backLabel = new Label(100,50,1.0f);
backLabel.setText("Back");
rVal.addChild(backLabel);
//label 2 (quit)
Label quitLabel = new Label(100,150,1.0f);
quitLabel.setText("Quit");
rVal.addChild(quitLabel);
return rVal;
}
public static Element createNaturalInventoryMenu(UnrelationalInventoryState inventory){
int screenTop = Globals.WINDOW_HEIGHT - 150;
int width = 500;
int height = 500;
int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
Div rVal = new Div();
rVal.setOnDragRelease(new DragEventCallback() {public boolean execute(DragEvent event){
if(Globals.draggedItem != null){
if(Globals.dragSourceInventory != inventory){
UnrelationalInventoryState sourceInventory = Globals.dragSourceInventory;
//transfer item
Globals.dragSourceInventory.removeItem(Globals.draggedItem);
inventory.addItem(Globals.draggedItem);
//null out global state
Globals.dragSourceInventory = null;
Globals.draggedItem = null;
//clear item container ui
WindowUtils.cleanItemWindow();
//rerender both inventories
//re-render inventory
WindowUtils.replaceWindowContents(WindowUtils.getInventoryWindowID(inventory.getId()), MenuGenerators.createNaturalInventoryMenu(inventory));
//re-render inventory
WindowUtils.replaceWindowContents(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGenerators.createNaturalInventoryMenu(sourceInventory));
} else {
//clear ui
WindowUtils.cleanItemWindow();
//re-render inventory
WindowUtils.replaceWindowContents(WindowUtils.getInventoryWindowID(inventory.getId()), MenuGenerators.createNaturalInventoryMenu(inventory));
}
return false;
}
return true;
}});
//black texture background
ImagePanel imagePanel = new ImagePanel(0,0,width,height,Globals.blackTexture);
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
rVal.addChild(imagePanel);
//label 1 (inventory)
Label inventoryLabel = new Label(10,10,1.0f);
inventoryLabel.setText("INVENTORY");
rVal.addChild(inventoryLabel);
int columns = 8;
int columnWidth = 60;
int rowHeight = 60;
for(int i = 0; i < inventory.getCapacity(); i++){
String texturePath = "Textures/icons/itemIconEmpty.png";
boolean hasItem = false;
if(i < inventory.getItems().size()){
Entity currentItem = inventory.getItems().get(i);
//get texture path from item
texturePath = ItemUtils.getItemIcon(currentItem);
//flag that this isn't an empty slot
hasItem = true;
}
if(!Globals.assetManager.hasLoadedTexture(texturePath)){
Globals.assetManager.addTexturePathtoQueue(texturePath);
}
int posX = (10 + i % columns * columnWidth);
int posY = 60 + (i / columns * rowHeight);
int panelWidth = 50;
int panelHeight = 50;
ImagePanel panel = new ImagePanel(posX,posY,panelWidth,panelHeight,texturePath);
if(hasItem == true){
int itemId = i;
panel.setOnDragStart(new DragEventCallback() {public boolean execute(DragEvent event){
// System.out.println("Drag start");
Globals.dragSourceInventory = inventory;
Globals.draggedItem = inventory.getItems().get(itemId);
rVal.removeChild(panel);
WindowUtils.pushItemIconToItemWindow(panel);
return false;
}});
panel.setOnDrag(new DragEventCallback() {public boolean execute(DragEvent event){
// System.out.println("Drag");
panel.setPositionX(event.getCurrentX() - panelWidth / 2);
panel.setPositionY(event.getCurrentY() - panelHeight / 2);
return false;
}});
// panel.setOnDragRelease(new DragEventCallback(){public boolean execute(DragEvent event){
// // panel.setPositionX(posX);
// // panel.setPositionY(posY);
// //now the fun begins :)
// //if transfer item
// // remove item from current inventory
// // place item in new inventory
// // trigger recreation of the menu
// //if drop item
// // remove item from current inventory
// // create item in world in front of character
// // trigger recreation of the menu
// //if neither of above
// // replace item icon position to origin
// // System.out.println("Release drag");
// return false;
// }});
}
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
rVal.addChild(panel);
}
return rVal;
}
}

View File

@ -1,357 +0,0 @@
package electrosphere.menu;
import electrosphere.audio.AudioSource;
import electrosphere.audio.AudioUtils;
import electrosphere.controls.ControlHandler;
import electrosphere.controls.ControlHandler.ControlsState;
import electrosphere.engine.LoadingThread;
import electrosphere.game.server.saves.SaveUtils;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.NetUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.font.TextBox;
import electrosphere.renderer.ui.label.Label;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class MenuTransition {
public static void selectOption(Menu m){
switch(m.getType()){
case TITLE_MENU:
switch(((TextBox)m.getCurrentOption()).getText()){
//single player
case "SINGLEPLAYER":
// m.dispose();
// Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
// Globals.RUN_CLIENT = true;
// Globals.RUN_SERVER = true;
// Globals.loadingThread.start();
m.dispose();
Globals.currentMenu = MenuUtils.createWorldSelectMenu();
break;
//multi player
case "MULTIPLAYER":
m.dispose();
Globals.currentMenu = MenuUtils.createMultiplayerMenu();
break;
//arena
case "ARENA":
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
break;
//options
case "OPTIONS":
m.dispose();
Globals.currentMenu = MenuUtils.createOptionsMainMenu();
break;
//test
case "UI TESTING":
m.dispose();
Globals.currentMenu = MenuUtils.createTestMainMenu();
break;
}
break;
case WORLD_SELECT_MENU:
switch(((TextBox)m.getCurrentOption()).getText()){
case "CREATE WORLD":
m.dispose();
Globals.currentMenu = MenuUtils.createWorldCreationMenu();
break;
default:
String worldName = ((TextBox)m.getCurrentOption()).getText();
m.dispose();
//check if has save or not
if(SaveUtils.worldHasSave(worldName.toLowerCase())){
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
} else {
Globals.currentSaveName = worldName.toLowerCase();
SaveUtils.loadTerrainAndCreateWorldData();
Globals.currentMenu = MenuUtils.createSaveCreationMenu();
}
break;
}
break;
case WORLD_CREATE_MENU:
break;
case SAVE_CREATE_MENU:
switch(((TextBox)m.getCurrentOption()).getText()){
case "SAVE":
m.dispose();
SaveUtils.saveWorldDataToSave(Globals.currentSaveName);
Globals.currentMenu = MenuUtils.createWorldSelectMenu();
break;
case "CANCEL":
m.dispose();
Globals.currentMenu = MenuUtils.createWorldSelectMenu();
break;
}
break;
case CHARACTER_CREATE_MENU:
break;
case FINALIZE_SAVE_CREATION_MENU:
break;
case MULTIPLAYER_MENU:
switch(((TextBox)m.getCurrentOption()).getText()){
//HOST
case "HOST":
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.loadingThread.start();
break;
//JOIN
case "JOIN":
m.dispose();
Globals.currentMenu = MenuUtils.createIPMenu();
break;
//back
case "BACK":
backout(m);
break;
}
break;
case IP_MENU:
switch(((TextBox)m.getCurrentOption()).getText()){
//connect
case "CONNECT":
NetUtils.setAddress( ( (TextBox)m.getOptions().get(0) ).getText() );
NetUtils.setPort( Integer.parseInt( ( (TextBox)m.getOptions().get(1) ).getText() ) );
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = false;
Globals.loadingThread.start();
break;
//back
case "BACK":
backout(m);
break;
}
break;
case IN_GAME_MAIN_MENU:
switch(((Label)m.getCurrentOption()).getText()){
//connect
case "QUIT":
//TODO: actually shut down program
Globals.ENGINE_SHUTDOWN_FLAG = true;
break;
//back
case "BACK":
MenuUtils.makeMenuUndrawable(Globals.currentMenu);
Globals.currentMenu.dispose();
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
break;
}
break;
}
}
public static void backout(Menu m){
AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuBackspace.ogg", new Vector3f(0,0,0));
switch(m.getType()){
case TITLE_MENU:
Main.running = false;
break;
case WORLD_SELECT_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
case WORLD_CREATE_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createWorldSelectMenu();
break;
case SAVE_CREATE_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createWorldSelectMenu();
break;
case CHARACTER_CREATE_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createSaveCreationMenu();
break;
case FINALIZE_SAVE_CREATION_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createCharacterCreationMenu();
break;
case MULTIPLAYER_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
case IP_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createMultiplayerMenu();
break;
case OPTIONS_MAIN_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
case TEST:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
case IN_GAME_MAIN_MENU:
MenuUtils.makeMenuUndrawable(Globals.currentMenu);
Globals.currentMenu.dispose();
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
break;
case INVENTORY_NATURAL:
MenuUtils.makeMenuUndrawable(Globals.currentMenu);
Globals.currentMenu.dispose();
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
Globals.controlHandler.hideMouse();
break;
}
}
public static void menuHandleKeypress(Menu m, String keycode){
char toWrite = ' ';
Widget currentOption = m.getCurrentOption();
boolean backspace = false;
switch(keycode){
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE:
if(currentOption instanceof TextBox){
TextBox currentTextBox = (TextBox)currentOption;
String currentText = currentTextBox.getText();
if(currentText.length() > 0){
currentTextBox.setText(currentText.substring(0, currentText.length() - 1));
AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuBackspace.ogg", new Vector3f(0,0,0));
}
}
backspace = true;
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_0:
toWrite = '0';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_1:
toWrite = '1';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_2:
toWrite = '2';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_3:
toWrite = '3';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_4:
toWrite = '4';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_5:
toWrite = '5';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_6:
toWrite = '6';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_7:
toWrite = '7';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_8:
toWrite = '8';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_9:
toWrite = '9';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_A:
toWrite = 'A';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_B:
toWrite = 'B';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_C:
toWrite = 'C';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_D:
toWrite = 'D';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_E:
toWrite = 'E';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_F:
toWrite = 'F';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_G:
toWrite = 'G';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_H:
toWrite = 'H';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_I:
toWrite = 'I';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_J:
toWrite = 'J';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_K:
toWrite = 'K';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_L:
toWrite = 'L';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_M:
toWrite = 'M';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_N:
toWrite = 'N';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_O:
toWrite = 'O';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_P:
toWrite = 'P';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_Q:
toWrite = 'Q';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_R:
toWrite = 'R';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_S:
toWrite = 'S';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_T:
toWrite = 'T';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_U:
toWrite = 'U';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_V:
toWrite = 'V';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_W:
toWrite = 'W';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_X:
toWrite = 'X';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_Y:
toWrite = 'Y';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_Z:
toWrite = 'Z';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD:
toWrite = '.';
break;
}
if(!backspace){
if(currentOption instanceof TextBox){
TextBox currentTextBox = (TextBox)currentOption;
String currentText = currentTextBox.getText();
if(currentText.length() < currentTextBox.getCols()){
currentTextBox.setText(currentText + toWrite);
AudioSource startupSound = AudioUtils.playAudioAtLocation("/Audio/MenuType.ogg", new Vector3f(0,0,0));
}
}
}
}
}

View File

@ -1,228 +0,0 @@
package electrosphere.menu;
import electrosphere.entity.Entity;
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.server.saves.SaveUtils;
import electrosphere.main.Globals;
import electrosphere.menu.Menu.MenuType;
import electrosphere.net.NetUtils;
import electrosphere.net.server.Server;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.WidgetUtils;
import electrosphere.renderer.ui.Window;
import electrosphere.renderer.ui.label.Label;
import electrosphere.renderer.ui.widgets.ImagePanel;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class MenuUtils {
public static Menu createTitleMenu(){
Menu rVal = new Menu(MenuType.TITLE_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop, "ORPG", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 125, "SINGLEPLAYER", true));
rVal.setMenuOptionColor(0, new Vector3f(0.2f,0.8f,0.5f));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "MULTIPLAYER", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "ARENA", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "OPTIONS", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 425, "UI TESTING", true));
return rVal;
}
public static Menu createWorldSelectMenu(){
Menu rVal = new Menu(MenuType.WORLD_SELECT_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
for(String saveName : saveNames){
if(!saveName.startsWith(".")){
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - verticalPosition, saveName.toUpperCase(), true));
verticalPosition = verticalPosition + 75;
}
}
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - verticalPosition - 200, "CREATE WORLD", true));
return rVal;
}
public static Menu createWorldCreationMenu(){
Menu rVal = new Menu(MenuType.WORLD_CREATE_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
//TODO: add text input to name world
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 125, "CREATE WORLD", true));
return rVal;
}
public static Menu createSaveCreationMenu(){
Menu rVal = new Menu(MenuType.SAVE_CREATE_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 125, "SAVE", true));
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "CANCEL", true));
return rVal;
}
public static Menu createCharacterCreationMenu(){
Menu rVal = new Menu(MenuType.CHARACTER_CREATE_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
//TODO: add text input to name world
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - verticalPosition, "CREATE WORLD", true));
return rVal;
}
public static Menu createFinalizeSaveCReationMenu(){
Menu rVal = new Menu(MenuType.FINALIZE_SAVE_CREATION_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
List<String> saveNames = SaveUtils.getSaves();
int verticalPosition = 125;
//TODO: add text input to name world
rVal.addOption(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - verticalPosition, "CREATE WORLD", true));
return rVal;
}
public static Menu createMultiplayerMenu(){
Menu rVal = new Menu(MenuType.MULTIPLAYER_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 125, "HOST", true));
rVal.setMenuOptionColor(0, new Vector3f(0.2f,0.8f,0.5f));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "JOIN", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "BACK", true));
return rVal;
}
public static Menu createIPMenu(){
Menu rVal = new Menu(MenuType.IP_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "IP ADDRESS", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedEditableTextBox(40*15, 40, screenTop - 125, 15, 1, NetUtils.getAddress(), true));
rVal.setMenuOptionColor(0, new Vector3f(0.2f,0.8f,0.5f));
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "PORT", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedEditableTextBox(40*5, 40, screenTop - 275, 5, 1, NetUtils.DEFAULT_PORT + "", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "CONNECT", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 425, "BACK", true));
return rVal;
}
public static Menu createOptionsMainMenu(){
Menu rVal = new Menu(MenuType.OPTIONS_MAIN_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "OPTIONS", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "BACK", true));
return rVal;
}
public static Menu createInGameMainMenu(){
Menu rVal = new Menu(MenuType.IN_GAME_MAIN_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
int width = 500;
int height = 500;
int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
Window menuWindow = new Window(100, 100, 500, 500);
//black texture background
ImagePanel imagePanel = new ImagePanel(0,0,width,height,Globals.blackTexture);
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
menuWindow.addWidget(imagePanel);
//label 1 (back)
Label backLabel = new Label(100,50,1.0f);
backLabel.setText("BACK");
menuWindow.addWidget(backLabel);
rVal.addOption(backLabel);
//label 2 (quit)
Label quitLabel = new Label(100,150,1.0f);
quitLabel.setText("QUIT");
menuWindow.addWidget(quitLabel);
rVal.addOption(quitLabel);
rVal.addElement(menuWindow);
Globals.widgetManager.registerWidget(menuWindow);
// rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "BACK", true));
// rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "QUIT", true));
return rVal;
}
public static Menu createTestMainMenu(){
Menu rVal = new Menu(MenuType.TEST);
rVal.addElement(WidgetUtils.createWindowTEST());
return rVal;
}
public static Menu createNaturalInventoryMenu(UnrelationalInventoryState inventory){
Menu rVal = new Menu(MenuType.INVENTORY_NATURAL);
int screenTop = Globals.WINDOW_HEIGHT - 150;
int width = 500;
int height = 500;
int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
Window menuWindow = new Window(100, 100, 500, 500);
//black texture background
ImagePanel imagePanel = new ImagePanel(0,0,width,height,Globals.blackTexture);
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
menuWindow.addWidget(imagePanel);
//label 1 (inventory)
Label inventoryLabel = new Label(10,10,1.0f);
inventoryLabel.setText("INVENTORY");
menuWindow.addWidget(inventoryLabel);
rVal.addOption(inventoryLabel);
int columns = 8;
int columnWidth = 60;
int rowHeight = 60;
for(int i = 0; i < inventory.getCapacity(); i++){
String texturePath = "Textures/icons/itemIconEmpty.png";
if(i < inventory.getItems().size()){
Entity currentItem = inventory.getItems().get(i);
//get texture path from item
texturePath = ItemUtils.getItemIcon(currentItem);
}
if(!Globals.assetManager.hasLoadedTexture(texturePath)){
Globals.assetManager.addTexturePathtoQueue(texturePath);
}
ImagePanel panel = new ImagePanel((10 + i % columns * columnWidth),height - (110 + i / columns * rowHeight),50,50,texturePath);
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
menuWindow.addWidget(panel);
}
rVal.addElement(menuWindow);
Globals.widgetManager.registerWidget(menuWindow);
// rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "BACK", true));
// rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "QUIT", true));
return rVal;
}
public static void makeMenuDrawable(Menu m){
for(Widget w : m.widgetList){
w.setVisible(true);
}
}
public static void makeMenuUndrawable(Menu m){
for(Widget w : m.widgetList){
w.setVisible(false);
}
}
}

View File

@ -0,0 +1,13 @@
package electrosphere.menu;
public class WindowStrings {
public static final String WINDOW_MENU_MAIN = "windowMenuMain";
public static final String WINDOW_MENU_INGAME_MAIN = "windowMenuInGameMain";
public static final String WINDOW_MENU_INVENTORY = "windowMenuInventory";
public static final String WINDOW_LOADING = "windowLoading";
public static final String WINDDOW_ITEM_DROP = "itemDrop";
public static final String WINDOW_ITEM_DRAG_CONTAINER = "itemDragContainer";
}

View File

@ -0,0 +1,102 @@
package electrosphere.menu;
import electrosphere.main.Globals;
import electrosphere.renderer.ui.ContainerElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.Window;
import electrosphere.renderer.ui.elements.Label;
public class WindowUtils {
public static void replaceMainMenuContents(Element newMenu){
Element mainMenuEl = Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN);
if(mainMenuEl != null && mainMenuEl instanceof Window){
Window mainMenu = (Window) mainMenuEl;
//todo: destroy elements as well
mainMenu.getChildren().clear();
mainMenu.addChild(newMenu);
Globals.elementManager.focusFirstElement(mainMenu);
}
}
public static void recursiveSetVisible(Element topLevelMenu, boolean visible){
if(topLevelMenu instanceof DrawableElement){
((DrawableElement)topLevelMenu).setVisible(visible);
}
if(topLevelMenu instanceof ContainerElement){
for(Element child : ((ContainerElement)topLevelMenu).getChildren()){
recursiveSetVisible(child, visible);
}
}
}
public static String getInventoryWindowID(int id){
return "INVENTORY-" + id;
}
public static void replaceWindowContents(String window, Element content){
Element mainMenuEl = Globals.elementManager.getWindow(window);
if(mainMenuEl != null && mainMenuEl instanceof Window){
Window mainMenu = (Window) mainMenuEl;
//todo: destroy elements as well
mainMenu.getChildren().clear();
mainMenu.addChild(content);
Globals.elementManager.focusFirstElement(mainMenu);
}
}
public static void pushItemIconToItemWindow(Element itemIcon){
Window targetWindow = (Window) Globals.elementManager.getWindow(WindowStrings.WINDOW_ITEM_DRAG_CONTAINER);
targetWindow.addChild(itemIcon);
recursiveSetVisible(targetWindow,true);
Globals.elementManager.pushWindowToFront(targetWindow);
}
public static void cleanItemWindow(){
Window targetWindow = (Window) Globals.elementManager.getWindow(WindowStrings.WINDOW_ITEM_DRAG_CONTAINER);
targetWindow.getChildren().clear();
recursiveSetVisible(targetWindow, false);
}
public static void initBaseWindows(){
initLoadingWindow();
initItemDropWindow();
initItemDragContainerWindow();
initMainMenuWindow();
}
static void initLoadingWindow(){
Window loadingWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Label loadingLabel = new Label(100,50,1.0f);
loadingLabel.setText("LOADING");
loadingWindow.addChild(loadingLabel);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_LOADING, loadingWindow);
WindowUtils.recursiveSetVisible(loadingWindow, true);
}
static void initMainMenuWindow(){
Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_MAIN, mainMenuWindow);
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
}
static void initItemDropWindow(){
Window itemDropWindow = new Window(0,0,Globals.WINDOW_WIDTH,Globals.WINDOW_HEIGHT);
Globals.elementManager.registerWindow(WindowStrings.WINDDOW_ITEM_DROP, itemDropWindow);
WindowUtils.replaceWindowContents(WindowStrings.WINDDOW_ITEM_DROP, MenuGenerators.worldItemDropCaptureWindow());
}
static void initItemDragContainerWindow(){
Window itemDragContainerWindow = new Window(0,0,Globals.WINDOW_WIDTH,Globals.WINDOW_HEIGHT);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_ITEM_DRAG_CONTAINER, itemDragContainerWindow);
}
}

View File

@ -1,6 +1,6 @@
package electrosphere.renderer;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import electrosphere.main.Main;

View File

@ -1,7 +1,8 @@
package electrosphere.renderer;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;

View File

@ -2,10 +2,10 @@ package electrosphere.renderer;
import electrosphere.controls.ControlCallback;
import electrosphere.controls.MouseCallback;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.creature.type.CollidableTemplate;
@ -23,9 +23,13 @@ import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.framebuffer.Renderbuffer;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ListIterator;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3d;
@ -674,9 +678,12 @@ public class RenderingEngine {
static void renderUI(){
glDisable(GL_DEPTH_TEST);
for(Widget currentWidget : Globals.widgetManager.getWidgetList()){
if(currentWidget.getVisible()){
currentWidget.draw(GL_DEFAULT_FRAMEBUFFER, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
for(Element currentElement : Globals.elementManager.getWindowList()){
if(currentElement instanceof DrawableElement){
DrawableElement drawable = (DrawableElement) currentElement;
if(drawable.getVisible()){
drawable.draw(GL_DEFAULT_FRAMEBUFFER, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
}
}
}

View File

@ -0,0 +1,13 @@
package electrosphere.renderer.ui;
import electrosphere.renderer.ui.events.ClickEvent;
public interface ClickableElement extends Element {
public void setOnClick(ClickEventCallback callback);
public interface ClickEventCallback {
public boolean execute(ClickEvent event);
}
}

View File

@ -0,0 +1,13 @@
package electrosphere.renderer.ui;
import java.util.List;
public interface ContainerElement extends Element {
public void addChild(Element child);
public List<Element> getChildren();
public void removeChild(Element child);
}

View File

@ -0,0 +1,20 @@
package electrosphere.renderer.ui;
import electrosphere.renderer.ui.events.DragEvent;
public interface DraggableElement extends Element {
public void setOnDragStart(DragEventCallback callback);
public void setOnDrag(DragEventCallback callback);
public void setOnDragRelease(DragEventCallback callback);
public interface DragEventCallback{
public boolean execute(DragEvent event);
}
}

View File

@ -0,0 +1,16 @@
package electrosphere.renderer.ui;
/**
*
* @author amaterasu
*/
public interface DrawableElement extends Element {
public boolean getVisible();
public void setVisible(boolean draw);
public abstract void draw(int parentFramebufferPointer, int parentWidth, int parentHeight);
}

View File

@ -0,0 +1,34 @@
package electrosphere.renderer.ui;
import electrosphere.renderer.ui.events.Event;
public interface Element {
public int getWidth();
public int getHeight();
public int getPositionX();
public int getPositionY();
public void setWidth(int width);
public void setHeight(int height);
public void setPositionX(int positionX);
public void setPositionY(int positionY);
public void setParentWidth(int width);
public void setParentHeight(int height);
/**
*
* @param event the even to handle
* @return true if the event should continue to propagate
*/
public boolean handleEvent(Event event);
}

View File

@ -0,0 +1,211 @@
package electrosphere.renderer.ui;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.DragEvent;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.events.FocusEvent;
import electrosphere.renderer.ui.events.MouseEvent;
import electrosphere.renderer.ui.events.DragEvent.DragEventType;
/**
*
* @author amaterasu
*/
public class ElementManager {
Map<String,Element> elementMap = new ConcurrentHashMap<String,Element>();
List<Element> elementList = new CopyOnWriteArrayList<Element>();
FocusableElement currentFocusedElement = null;
DraggableElement currentDragElement = null;
public void registerWindow(String name, Element w){
elementMap.put(name,w);
if(!elementList.contains(w)){
elementList.add(w);
}
if(elementList.size() == 1){
focusFirstElement(w);
}
}
public Element getWindow(String name){
return elementMap.get(name);
}
public List<Element> getWindowList(){
return elementList;
}
public void unregisterWindow(String name){
Element w = elementMap.remove(name);
if(elementList.contains(w)){
elementList.remove(w);
}
}
public void pushWindowToFront(Window window){
elementList.remove(window);
elementList.add(window);
}
List<FocusableElement> getFocusableList(Element topLevel, List<FocusableElement> input){
if(topLevel instanceof FocusableElement){
input.add((FocusableElement)topLevel);
}
if(topLevel instanceof ContainerElement){
ContainerElement container = (ContainerElement) topLevel;
for(Element child : container.getChildren()){
getFocusableList(child,input);
}
}
return input;
}
public FocusableElement getFocusedElement(){
return currentFocusedElement;
}
public void focusFirstElement(Element topLevel){
List<FocusableElement> focusables = getFocusableList(topLevel,new LinkedList<FocusableElement>());
if(focusables.size() > 0){
if(currentFocusedElement != null){
currentFocusedElement.handleEvent(new FocusEvent(false));
}
currentFocusedElement = focusables.get(0);
currentFocusedElement.handleEvent(new FocusEvent(true));
}
}
public void focusNextElement(Element topLevel){
List<FocusableElement> focusables = getFocusableList(topLevel,new LinkedList<FocusableElement>());
if(focusables.contains(currentFocusedElement)){
int index = focusables.indexOf(currentFocusedElement);
if(index + 1 >= focusables.size()){
index = 0;
} else {
index++;
}
if(currentFocusedElement != null){
currentFocusedElement.handleEvent(new FocusEvent(false));
}
currentFocusedElement = focusables.get(index);
currentFocusedElement.handleEvent(new FocusEvent(true));
}
}
public void focusPreviousElement(Element topLevel){
List<FocusableElement> focusables = getFocusableList(topLevel,new LinkedList<FocusableElement>());
if(focusables.contains(currentFocusedElement)){
int index = focusables.indexOf(currentFocusedElement);
if(index - 1 < 0){
index = focusables.size() - 1;
} else {
index--;
}
if(currentFocusedElement != null){
currentFocusedElement.handleEvent(new FocusEvent(false));
}
currentFocusedElement = focusables.get(index);
currentFocusedElement.handleEvent(new FocusEvent(true));
}
}
public void fireEvent(Event event, int x, int y){
boolean propagate = true;
ListIterator<Element> windowIterator = elementList.listIterator(elementList.size());
while(windowIterator.hasPrevious()){
Element currentWindow = windowIterator.previous();
Stack<Element> elementStack = buildElementPositionalStack(new Stack<Element>(), currentWindow, x, y, 0, 0);
Element currentElement = null;
while(elementStack.size() > 0 && propagate == true){
currentElement = elementStack.pop();
propagate = currentElement.handleEvent(event);
}
if(!propagate){
break;
}
}
}
Stack<Element> buildElementPositionalStack(Stack<Element> inputStack, Element current, int x, int y, int offsetX, int offsetY){
inputStack.push(current);
if(current instanceof ContainerElement){
for(Element el : ((ContainerElement)current).getChildren()){
//if contains x,y, call function on el
if(elementContainsPoint(el,x,y)){
buildElementPositionalStack(inputStack, el, x, y, offsetX + el.getPositionX(), offsetY + el.getPositionY());
}
}
}
return inputStack;
}
public Element resolveFirstDraggable(DragEvent event){
ListIterator<Element> windowIterator = elementList.listIterator(elementList.size());
while(windowIterator.hasPrevious()){
Element currentWindow = windowIterator.previous();
Stack<Element> elementStack = buildElementPositionalStack(new Stack<Element>(), currentWindow, event.getCurrentX(), event.getCurrentY(), 0, 0);
Element currentElement = null;
while(elementStack.size() > 0){
currentElement = elementStack.pop();
if(currentElement instanceof DraggableElement){
return currentElement;
}
}
}
return null;
}
boolean elementContainsPoint(Element el, int x, int y){
return
x >= el.getPositionX() &&
x <= el.getPositionX() + el.getWidth() &&
y >= el.getPositionY() &&
y <= el.getPositionY() + el.getHeight();
}
// public void click(MouseEvent event){
// if(currentFocusedElement instanceof ClickableElement){
// ((ClickableElement)currentFocusedElement).onClick();
// }
// }
public void click(ClickEvent event){
fireEvent(event,event.getCurrentX(),event.getCurrentY());
}
public void dragStart(int x, int y, int lastX, int lastY, int deltaX, int deltaY){
DragEvent event = new DragEvent(x, y, lastX, lastY, deltaX, deltaY, DragEventType.START, null);
currentDragElement = (DraggableElement)resolveFirstDraggable(event);
event.setTarget(currentDragElement);
fireEvent(event,x,y);
}
public void drag(int x, int y, int lastX, int lastY, int deltaX, int deltaY){
DragEvent event = new DragEvent(x, y, lastX, lastY, deltaX, deltaY, DragEventType.DRAG, currentDragElement);
if(currentDragElement != null){
currentDragElement.handleEvent(event);
}
// fireEvent(event,event.getCurrentX(),event.getCurrentY());
}
public void dragRelease(int x, int y, int lastX, int lastY, int deltaX, int deltaY){
DragEvent event = new DragEvent(x, y, lastX, lastY, deltaX, deltaY, DragEventType.RELEASE, currentDragElement);
if(currentDragElement != null){
currentDragElement.handleEvent(event);
currentDragElement = null;
}
fireEvent(event,event.getCurrentX(),event.getCurrentY());
}
}

View File

@ -0,0 +1,20 @@
package electrosphere.renderer.ui;
import electrosphere.renderer.ui.events.FocusEvent;
public interface FocusableElement extends Element {
public boolean isFocused();
public abstract void setOnFocus(FocusEventCallback callback);
public abstract void setOnLoseFocus(FocusEventCallback callback);
public abstract interface FocusEventCallback {
public boolean execute(FocusEvent event);
}
}

View File

@ -0,0 +1,15 @@
package electrosphere.renderer.ui;
import electrosphere.renderer.ui.events.NavigationEvent;
public interface NavigableElement extends Element {
public void setOnNavigationCallback(NavigationEventCallback callback);
public interface NavigationEventCallback {
public void execute(NavigationEvent event);
}
}

View File

@ -1,70 +0,0 @@
package electrosphere.renderer.ui;
/**
*
* @author amaterasu
*/
public abstract class Widget {
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
parentHeight = height;
}
public abstract void draw(int parentFramebufferPointer, int parentWidth, int parentHeight);
}

View File

@ -1,36 +0,0 @@
package electrosphere.renderer.ui;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
* @author amaterasu
*/
public class WidgetManager {
CopyOnWriteArrayList<Widget> widgetList = new CopyOnWriteArrayList();
public WidgetManager(){
}
public void registerWidget(Widget w){
if(!widgetList.contains(w)){
widgetList.add(w);
}
}
public CopyOnWriteArrayList<Widget> getWidgetList(){
return widgetList;
}
public void unregisterWidget(Widget w){
if(widgetList.contains(w)){
widgetList.remove(w);
}
}
}

View File

@ -2,13 +2,12 @@ package electrosphere.renderer.ui;
import electrosphere.controls.ControlHandler;
import electrosphere.main.Globals;
import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elements.TextInput;
import electrosphere.renderer.ui.font.FontUtils;
import electrosphere.renderer.ui.font.TextBox;
import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter;
import electrosphere.renderer.ui.label.Label;
import electrosphere.renderer.ui.layout.LayoutSchemeListScrollable;
import electrosphere.renderer.ui.widgets.ImagePanel;
import electrosphere.renderer.ui.widgets.TextInput;
/**
*
@ -17,111 +16,111 @@ import electrosphere.renderer.ui.widgets.TextInput;
public class WidgetUtils {
public static TextBox createTextBox(int positionX, int positionY, int width, int height, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-width/2, positionY, width, height, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// public static TextBox createTextBox(int positionX, int positionY, int width, int height, int cols, int rows, String text, boolean render){
// TextBox rVal = new TextBox(-width/2, positionY, width, height, rows, cols, text, render, false);
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static TextBox createVerticallyAlignedTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-width/2, windowTop, width, height, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// public static TextBox createVerticallyAlignedTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
// TextBox rVal = new TextBox(-width/2, windowTop, width, height, rows, cols, text, render, false);
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static TextBox createVerticallyAlignedMinSizeTextBox(int charWidth, int charHeight, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// public static TextBox createVerticallyAlignedMinSizeTextBox(int charWidth, int charHeight, int windowTop, int cols, int rows, String text, boolean render){
// TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static TextBox createVerticallyAlignedMinSizeTextBoxFromCharCount(int charWidth, int charHeight, int windowTop, String text, boolean render){
int cols = text.length();
int rows = 1;
TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
rVal.setVisible(true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// public static TextBox createVerticallyAlignedMinSizeTextBoxFromCharCount(int charWidth, int charHeight, int windowTop, String text, boolean render){
// int cols = text.length();
// int rows = 1;
// TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
// rVal.setVisible(true);
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static TextBox createVerticallyAlignedEditableTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-(int)(width/2.5), windowTop, width, height, rows, cols, text, render, true);
rVal.setVisible(true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// public static TextBox createVerticallyAlignedEditableTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
// TextBox rVal = new TextBox(-(int)(width/2.5), windowTop, width, height, rows, cols, text, render, true);
// rVal.setVisible(true);
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static LayoutSchemeListScrollable createListTEST(){
LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(200, 200, 500, 500, true);
rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
rVal.addWidget(WidgetUtils.createTextBox(100, 100, 500, 500, 3, 10, "TEST", true));
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// public static LayoutSchemeListScrollable createListTEST(){
// LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(200, 200, 500, 500, true);
// rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
// rVal.addWidget(WidgetUtils.createTextBox(100, 100, 500, 500, 3, 10, "TEST", true));
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static Widget createWindowTEST(){
Window rVal = new Window(0, 0, 1920, 1080);
// //panel 1
// ImagePanel imagePanel = new ImagePanel();
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
// imagePanel.setPositionX(100);
// imagePanel.setPositionY(100);
// imagePanel.setVisible(true);
// rVal.addWidget(imagePanel);
// //panel 2
// imagePanel = new ImagePanel();
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
// imagePanel.setVisible(true);
// rVal.addWidget(imagePanel);
// rVal.setVisible(true);
// //window top
// imagePanel = new ImagePanel();
// imagePanel.setTexture(Globals.assetManager.fetchTexture("Textures/ui/WindowBorder.png"));
// imagePanel.setWidth(100);
// imagePanel.setHeight(50);
// imagePanel.setPositionX(200);
// imagePanel.setPositionY(50);
// imagePanel.setVisible(true);
// rVal.addWidget(imagePanel);
// TextInput textInput = new TextInput();
// textInput.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\n");
// textInput.setPositionX(0);
// textInput.setPositionY(0);
// textInput.setWidth(500);
// textInput.setHeight(500);
// textInput.setFontWidth(10);
// textInput.setFontHeight(27);
// textInput.setVisible(true);
// rVal.addWidget(textInput);
// public static DrawableElement createWindowTEST(){
// Window rVal = new Window(0, 0, 1920, 1080);
// // //panel 1
// // ImagePanel imagePanel = new ImagePanel();
// // imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
// // imagePanel.setPositionX(100);
// // imagePanel.setPositionY(100);
// // imagePanel.setVisible(true);
// // rVal.addWidget(imagePanel);
// // //panel 2
// // imagePanel = new ImagePanel();
// // imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
// // imagePanel.setVisible(true);
// // rVal.addWidget(imagePanel);
// // rVal.setVisible(true);
// // //window top
// // imagePanel = new ImagePanel();
// // imagePanel.setTexture(Globals.assetManager.fetchTexture("Textures/ui/WindowBorder.png"));
// // imagePanel.setWidth(100);
// // imagePanel.setHeight(50);
// // imagePanel.setPositionX(200);
// // imagePanel.setPositionY(50);
// // imagePanel.setVisible(true);
// // rVal.addWidget(imagePanel);
// // TextInput textInput = new TextInput();
// // textInput.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\n");
// // textInput.setPositionX(0);
// // textInput.setPositionY(0);
// // textInput.setWidth(500);
// // textInput.setHeight(500);
// // textInput.setFontWidth(10);
// // textInput.setFontHeight(27);
// // textInput.setVisible(true);
// // rVal.addWidget(textInput);
// BitmapCharacter characterDisp = new BitmapCharacter(0,0,500,500,'A');
// rVal.addWidget(characterDisp);
// // BitmapCharacter characterDisp = new BitmapCharacter(0,0,500,500,'A');
// // rVal.addWidget(characterDisp);
Label label = new Label(100,100,1);
label.setText("TESTING");
rVal.addWidget(label);
// Label label = new Label(100,100,1);
// label.setText("TESTING");
// rVal.addChild(label);
// TextInput textInput2 = new TextInput();
// textInput2.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\n");
// textInput2.setPositionX(500);
// textInput2.setPositionY(0);
// textInput2.setWidth(500);
// textInput2.setHeight(500);
// textInput2.setFontWidth(20);
// textInput2.setFontHeight(40);
// textInput2.setVisible(true);
// rVal.addWidget(textInput2);
// // TextInput textInput2 = new TextInput();
// // textInput2.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\n");
// // textInput2.setPositionX(500);
// // textInput2.setPositionY(0);
// // textInput2.setWidth(500);
// // textInput2.setHeight(500);
// // textInput2.setFontWidth(20);
// // textInput2.setFontHeight(40);
// // textInput2.setVisible(true);
// // rVal.addWidget(textInput2);
rVal.setVisible(true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
// rVal.setVisible(true);
// // Globals.widgetManager.registerWidget(rVal);
// return rVal;
// }
public static Widget createInGameMainMenuButton(){
public static DrawableElement createInGameMainMenuButton(){
int width = (int)(Globals.WINDOW_WIDTH * 0.05);
int height = (int)(Globals.WINDOW_HEIGHT * 0.05);
int x = Globals.WINDOW_WIDTH - width;
@ -139,17 +138,17 @@ public class WidgetUtils {
Label menuLabel = new Label(0,0,0.3f);
menuLabel.setText("Menu");
menuLabel.setVisible(true);
rVal.addWidget(menuLabel);
rVal.addChild(menuLabel);
//label telling player what key they have their menu bound to
Label keyCodeLabel = new Label(0,10,0.3f);
keyCodeLabel.setText(ControlHandler.convertKeycodeToName(Globals.controlHandler.getControl(ControlHandler.DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue()));
keyCodeLabel.setVisible(true);
rVal.addWidget(keyCodeLabel);
rVal.addChild(keyCodeLabel);
rVal.setVisible(false);
// Globals.inGameUI.add(rVal);
Globals.widgetManager.registerWidget(rVal);
// Globals.widgetManager.registerWidget(rVal);
return rVal;
}

View File

@ -5,6 +5,8 @@ import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.ui.events.Event;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector3f;
@ -15,8 +17,8 @@ import static org.lwjgl.opengl.GL30.*;
*
* @author amaterasu
*/
public class Window extends Widget {
List<Widget> widgetList = new LinkedList();
public class Window implements DrawableElement, ContainerElement {
List<Element> childList = new LinkedList<Element>();
Framebuffer widgetBuffer;
Material customMat = new Material();
@ -50,8 +52,11 @@ public class Window extends Widget {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(Widget child : widgetList){
child.draw(widgetBuffer.getFramebufferPointer(),width,height);
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.draw(widgetBuffer.getFramebufferPointer(),width,height);
}
}
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
@ -70,33 +75,28 @@ public class Window extends Widget {
public void pack() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void addWidget(Widget widget) {
widgetList.add(widget);
widget.setParentWidth(width);
widget.setParentHeight(height);
widget.setVisible(false);
}
public List<Widget> getWidgets() {
return widgetList;
}
@Override
public void setWidth(int width){
this.width = width;
for(Widget widget : widgetList){
widget.setParentWidth(width);
widget.setParentHeight(height);
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
}
}
}
@Override
public void setHeight(int height){
this.height = height;
for(Widget widget : widgetList){
widget.setParentWidth(height);
widget.setParentHeight(height);
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
}
}
}
@ -115,4 +115,89 @@ public class Window extends Widget {
float ndcHeight = (float)y/Globals.WINDOW_HEIGHT;
texScale = new Vector3f(ndcWidth,ndcHeight,0);
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
@Override
public void setPositionX(int positionX) {
// TODO Auto-generated method stub
}
@Override
public void setPositionY(int positionY) {
// TODO Auto-generated method stub
}
@Override
public void setParentWidth(int width) {
// TODO Auto-generated method stub
}
@Override
public void setParentHeight(int height) {
// TODO Auto-generated method stub
}
@Override
public void addChild(Element child) {
childList.add(child);
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
drawableChild.setVisible(false);
}
}
@Override
public List<Element> getChildren() {
return childList;
}
@Override
public void removeChild(Element child) {
childList.remove(child);
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -1,38 +0,0 @@
package electrosphere.renderer.ui;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class WindowManager {
Map<String,Window> windowManager = new HashMap<String,Window>();
List<Window> windowPriorityList = new LinkedList<Window>();
public void registerWindow(String windowName, Window window){
windowManager.put(windowName,window);
windowPriorityList.add(window);
}
public Window getWindow(String windowName){
return windowManager.get(windowName);
}
public void unregisterWindow(String windowName){
Window toRemove = windowManager.remove(windowName);
if(toRemove != null){
windowPriorityList.remove(toRemove);
}
}
/**
* windows should be drawn in this order
* @return
*/
public List<Window> getWindowPriorityList(){
return windowPriorityList;
}
}

View File

@ -0,0 +1,253 @@
package electrosphere.renderer.ui.elements;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector3f;
import electrosphere.renderer.ui.ClickableElement;
import electrosphere.renderer.ui.ContainerElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.FocusableElement;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.events.FocusEvent;
import electrosphere.renderer.ui.events.MouseEvent;
public class Button implements DrawableElement, FocusableElement, ContainerElement, ClickableElement {
List<Element> childList = new LinkedList<Element>();
int width = 1;
int height = 1;
int positionX = 0;
int positionY = 0;
int parentWidth = 1;
int parentHeight = 1;
boolean visible = false;
boolean focused = false;
FocusEventCallback onFocusCallback;
FocusEventCallback onLoseFocusCallback;
ClickEventCallback clickCallback;
public int getWidth() {
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
}
}
if(minX == -1){
minX = 0;
}
if(maxX == -1){
maxX = 0;
}
return maxX - minX;
}
public int getHeight() {
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
}
}
if(minY == -1){
minY = 0;
}
if(maxY == -1){
maxY = 0;
}
return maxY - minY;
}
public int getPositionX() {
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
}
if(minX == -1){
minX = 0;
}
return minX;
}
public int getPositionY() {
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
}
if(minY == -1){
minY = 0;
}
return minY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
@Override
public boolean isFocused() {
return focused;
}
void onFocus(FocusEvent event) {
// TODO Auto-generated method stub
if(onFocusCallback != null){
onFocusCallback.execute(event);
} else {
for(Element child : childList){
if(child instanceof Label){
Label childLabel = (Label) child;
childLabel.setColor(new Vector3f(1,0,0));
}
}
}
}
void onLoseFocus(FocusEvent event) {
// TODO Auto-generated method stub
if(onLoseFocusCallback != null){
onLoseFocusCallback.execute(event);
} else {
for(Element child : childList){
if(child instanceof Label){
Label childLabel = (Label) child;
childLabel.setColor(new Vector3f(1,1,1));
}
}
}
}
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
// TODO Auto-generated method stub
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.draw(parentFramebufferPointer,parentWidth,parentHeight);
}
}
}
@Override
public void addChild(Element child) {
childList.add(child);
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
drawableChild.setVisible(false);
}
}
@Override
public List<Element> getChildren() {
return childList;
}
@Override
public void removeChild(Element child) {
childList.remove(child);
}
@Override
public void setOnFocus(FocusEventCallback callback) {
// TODO Auto-generated method stub
onFocusCallback = callback;
}
@Override
public void setOnLoseFocus(FocusEventCallback callback) {
// TODO Auto-generated method stub
onLoseFocusCallback = callback;
}
@Override
public void setOnClick(ClickEventCallback callback) {
// TODO Auto-generated method stub
clickCallback = callback;
}
public boolean handleEvent(Event event){
if(event instanceof MouseEvent){
return false;
}
if(event instanceof FocusEvent){
FocusEvent focusEvent = (FocusEvent) event;
if(focusEvent.isFocused()){
this.focused = true;
onFocus(focusEvent);
} else {
this.focused = false;
onLoseFocus(focusEvent);
}
return false;
}
if(event instanceof ClickEvent){
if(clickCallback != null){
clickCallback.execute((ClickEvent)event);
}
}
return true;
}
}

View File

@ -0,0 +1,329 @@
package electrosphere.renderer.ui.elements;
import java.util.LinkedList;
import java.util.List;
import electrosphere.renderer.ui.ClickableElement;
import electrosphere.renderer.ui.ContainerElement;
import electrosphere.renderer.ui.DraggableElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.FocusableElement;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.DragEvent;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.events.FocusEvent;
import electrosphere.renderer.ui.events.DragEvent.DragEventType;
public class Div implements ClickableElement,ContainerElement,DraggableElement,FocusableElement,DrawableElement {
ClickEventCallback onClick;
FocusEventCallback onFocus;
FocusEventCallback onLoseFocus;
DragEventCallback onDragStart;
DragEventCallback onDrag;
DragEventCallback onDragRelease;
boolean focused = false;
List<Element> childList = new LinkedList<Element>();
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
@Override
public int getWidth() {
if(childList.size() > 0){
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
}
}
if(minX == -1){
minX = 0;
}
if(maxX == -1){
maxX = 0;
}
return maxX - minX;
} else {
return width;
}
}
@Override
public int getHeight() {
if(childList.size() > 0){
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
}
}
if(minY == -1){
minY = 0;
}
if(maxY == -1){
maxY = 0;
}
return maxY - minY;
} else {
return height;
}
}
@Override
public int getPositionX() {
if(childList.size() > 0){
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
}
if(minX == -1){
minX = 0;
}
return minX;
} else {
return positionX;
}
}
@Override
public int getPositionY() {
if(childList.size() > 0){
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
}
if(minY == -1){
minY = 0;
}
return minY;
} else {
return positionY;
}
}
@Override
public void setWidth(int width) {
// TODO Auto-generated method stub
this.width = width;
}
@Override
public void setHeight(int height) {
// TODO Auto-generated method stub
this.height = height;
}
@Override
public void setPositionX(int positionX) {
// TODO Auto-generated method stub
this.positionX = positionX;
}
@Override
public void setPositionY(int positionY) {
// TODO Auto-generated method stub
this.positionY = positionY;
}
@Override
public void setParentWidth(int width) {
// TODO Auto-generated method stub
}
@Override
public void setParentHeight(int height) {
// TODO Auto-generated method stub
}
@Override
public void addChild(Element child) {
childList.add(child);
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
drawableChild.setVisible(false);
}
}
@Override
public List<Element> getChildren() {
return childList;
}
@Override
public void removeChild(Element child) {
childList.remove(child);
}
public void setFocus(boolean focus){
this.focused = focus;
}
@Override
public boolean isFocused() {
// TODO Auto-generated method stub
return focused;
}
@Override
public void setOnFocus(FocusEventCallback callback) {
// TODO Auto-generated method stub
this.onFocus = callback;
}
@Override
public void setOnLoseFocus(FocusEventCallback callback) {
// TODO Auto-generated method stub
this.onLoseFocus = callback;
}
@Override
public void setOnDragStart(DragEventCallback callback) {
// TODO Auto-generated method stub
this.onDragStart = callback;
}
@Override
public void setOnDrag(DragEventCallback callback) {
// TODO Auto-generated method stub
this.onDrag = callback;
}
@Override
public void setOnDragRelease(DragEventCallback callback) {
// TODO Auto-generated method stub
this.onDragRelease = callback;
}
@Override
public void setOnClick(ClickEventCallback callback) {
// TODO Auto-generated method stub
this.onClick = callback;
}
@Override
public boolean handleEvent(Event event) {
boolean propagate = true;
if(onClick != null){
if(event instanceof ClickEvent){
if(!onClick.execute((ClickEvent)event)){
propagate = false;
}
}
}
if(onFocus != null){
if(event instanceof FocusEvent){
if(!onFocus.execute((FocusEvent)event)){
propagate = false;
}
}
}
if(onLoseFocus != null){
if(event instanceof FocusEvent){
if(!onLoseFocus.execute((FocusEvent)event)){
propagate = false;
}
}
}
if(event instanceof DragEvent){
if(onDragStart != null && ((DragEvent)event).getType() == DragEventType.START){
if(!onDragStart.execute((DragEvent)event)){
propagate = false;
}
}
if(onDrag != null && ((DragEvent)event).getType() == DragEventType.DRAG){
if(!onDrag.execute((DragEvent)event)){
propagate = false;
}
}
if(onDragRelease != null && ((DragEvent)event).getType() == DragEventType.RELEASE){
if(!onDragRelease.execute((DragEvent)event)){
propagate = false;
}
}
}
return propagate;
}
@Override
public boolean getVisible() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setVisible(boolean draw) {
// TODO Auto-generated method stub
}
@Override
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
// TODO Auto-generated method stub
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.draw(parentFramebufferPointer,parentWidth,parentHeight);
}
}
}
}

View File

@ -1,4 +1,4 @@
package electrosphere.renderer.ui.widgets;
package electrosphere.renderer.ui.elements;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
@ -6,7 +6,12 @@ import electrosphere.renderer.Model;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DraggableElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.events.DragEvent;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.events.DragEvent.DragEventType;
import org.joml.Vector3f;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
@ -19,8 +24,10 @@ import static org.lwjgl.opengl.GL30.glBindFramebuffer;
*
* @author amaterasu
*/
public class ImagePanel extends Widget {
public class ImagePanel implements DrawableElement, DraggableElement {
public static String imagePanelModelPath;
String texturePath;
Material customMat = new Material();
boolean hasLoadedTexture = false;
@ -29,6 +36,10 @@ public class ImagePanel extends Widget {
Vector3f texPosition = new Vector3f(0,0,0);
Vector3f texScale = new Vector3f(1,1,0);
DragEventCallback onDragStart;
DragEventCallback onDrag;
DragEventCallback onDragRelease;
public ImagePanel(int x, int y, int width, int height, String texturePath){
this.texturePath = texturePath;
@ -76,7 +87,7 @@ public class ImagePanel extends Widget {
Vector3f boxPosition = new Vector3f(ndcX,ndcY,0);
Vector3f boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
Model planeModel = Globals.assetManager.fetchModel(Globals.planeModelID);
Model planeModel = Globals.assetManager.fetchModel(imagePanelModelPath);
planeModel.pushUniformToMesh("plane", "mPosition", boxPosition);
planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions);
planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
@ -84,5 +95,101 @@ public class ImagePanel extends Widget {
planeModel.meshes.get(0).setMaterial(customMat);
planeModel.drawUI();
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
public boolean handleEvent(Event event){
boolean propagate = true;
if(event instanceof DragEvent){
if(onDragStart != null && ((DragEvent)event).getType() == DragEventType.START){
if(!onDragStart.execute((DragEvent)event)){
propagate = false;
}
}
if(onDrag != null && ((DragEvent)event).getType() == DragEventType.DRAG){
if(!onDrag.execute((DragEvent)event)){
propagate = false;
}
}
if(onDragRelease != null && ((DragEvent)event).getType() == DragEventType.RELEASE){
if(!onDragRelease.execute((DragEvent)event)){
propagate = false;
}
}
}
return propagate;
}
@Override
public void setOnDragStart(DragEventCallback callback) {
onDragStart = callback;
}
@Override
public void setOnDrag(DragEventCallback callback) {
onDrag = callback;
}
@Override
public void setOnDragRelease(DragEventCallback callback) {
onDragRelease = callback;
}
}

View File

@ -0,0 +1,199 @@
package electrosphere.renderer.ui.elements;
import electrosphere.main.Globals;
import electrosphere.renderer.Model;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.font.FontUtils;
import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class Label implements DrawableElement {
String text = "";
int textPixelWidth = 0;
float fontSize = 1.0f;
List<BitmapCharacter> childrenElements = new LinkedList<BitmapCharacter>();
public Label(int x, int y, float fontSize){
this.positionX = x;
this.positionY = y;
this.width = 0;
this.height = (int)(FontUtils.getFontHeight() * fontSize);
this.fontSize = fontSize;
}
void generateLetters(){
childrenElements.clear();
int rollingOffset = 0;
for(int i = 0; i < text.length(); i++){
char toDraw = text.charAt(i);
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacterDiscrete(toDraw);
BitmapCharacter newLetter = new BitmapCharacter((int)(rollingOffset * fontSize) + positionX, positionY, (int)(bitMapDimension.x * fontSize), this.height, toDraw);
rollingOffset += (int)bitMapDimension.x;
childrenElements.add(newLetter);
}
}
public void setText(String text){
this.text = text;
textPixelWidth = 0;
for(int i = 0; i < text.length(); i++){
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacterDiscrete(text.charAt(i));
textPixelWidth = textPixelWidth + (int)bitMapDimension.x;
}
generateLetters();
}
public void setColor(Vector3f color){
for(BitmapCharacter character : childrenElements){
character.setColor(color);
}
}
public String getText(){
return text;
}
@Override
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
for(DrawableElement child : childrenElements){
child.draw(parentFramebufferPointer, parentWidth, parentHeight);
}
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
int minX = -1;
int maxX = -1;
for(BitmapCharacter child : childrenElements){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
}
}
if(minX == -1){
minX = 0;
}
if(maxX == -1){
maxX = 0;
}
return maxX - minX;
}
public int getHeight() {
int minY = -1;
int maxY = -1;
for(BitmapCharacter child : childrenElements){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
}
}
if(minY == -1){
minY = 0;
}
if(maxY == -1){
maxY = 0;
}
return maxY - minY;
}
public int getPositionX() {
int minX = -1;
for(BitmapCharacter child : childrenElements){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
}
if(minX == -1){
minX = 0;
}
return minX;
}
public int getPositionY() {
int minY = -1;
for(BitmapCharacter child : childrenElements){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
}
if(minY == -1){
minY = 0;
}
return minY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -1,19 +1,16 @@
package electrosphere.renderer.ui.transparenttextbox;
package electrosphere.renderer.ui.elements;
import electrosphere.main.Globals;
import electrosphere.renderer.Model;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.font.FontUtils;
import org.joml.Vector3f;
public class TextBox extends Widget{
public class TextBox implements DrawableElement {
int positionX;
int positionY;
int width;
int height;
String text;
boolean editable;
@ -86,4 +83,68 @@ public class TextBox extends Widget{
// }
// }
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -1,4 +1,4 @@
package electrosphere.renderer.ui.widgets;
package electrosphere.renderer.ui.elements;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
@ -7,7 +7,8 @@ import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.font.FontUtils;
import org.joml.Vector3f;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
@ -17,7 +18,7 @@ import static org.lwjgl.opengl.GL30.glBindFramebuffer;
*
* @author amaterasu
*/
public class TextInput extends Widget {
public class TextInput implements DrawableElement {
Framebuffer widgetBuffer;
Material customMat = new Material();
@ -37,27 +38,31 @@ public class TextInput extends Widget {
Vector3f color = new Vector3f(0,0,0);
public TextInput(){
public TextInput(int positionX, int positionY, int width, int height){
//TODO: figure out why this has to be 1920x1080
// widgetBuffer = FramebufferUtils.generateTextureFramebuffer(500, 500);
widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
customMat.setTexturePointer(widgetBuffer.getTexturePointer());
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/default_diffuse.png").getTexturePointer());
setPositionX(positionX);
setPositionY(positionY);
setWidth(width);
setHeight(height);
}
@Override
public void setPositionY(int positionY) {
float ndcY = (float)positionY/(float)Globals.WINDOW_HEIGHT;
boxPosition.y = ndcY;
super.setPositionY(positionY);
this.positionY = positionY;
}
@Override
public void setPositionX(int positionX) {
float ndcX = (float)positionX/(float)Globals.WINDOW_WIDTH;
boxPosition.x = ndcX;
super.setPositionX(positionX);
this.positionX = positionX;
}
@Override
@ -70,7 +75,7 @@ public class TextInput extends Widget {
customMat.setTexturePointer(widgetBuffer.getTexturePointer());
oldBuffer.free();
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
super.setHeight(height);
this.height = height;
}
@Override
@ -85,19 +90,17 @@ public class TextInput extends Widget {
oldBuffer.free();
// widgetBuffer = FramebufferUtils.generateTextureFramebuffer(width, height);
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
super.setWidth(width);
this.width = width;
}
@Override
public void setParentWidth(int parentWidth){
this.parentWidth = parentWidth;
setWidth(width);
}
@Override
public void setParentHeight(int parentHeight){
this.parentHeight = parentHeight;
setHeight(height);
}
public void setFontWidth(int width){
@ -115,6 +118,10 @@ public class TextInput extends Widget {
public int getFontHeight(){
return fontHeight;
}
public String getText(){
return text;
}
public void setText(String text){
this.text = text;
@ -173,5 +180,44 @@ public class TextInput extends Widget {
planeModel.meshes.get(0).setMaterial(customMat);
planeModel.drawUI();
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -0,0 +1,33 @@
package electrosphere.renderer.ui.events;
public class ClickEvent implements Event {
int currentX;
int currentY;
boolean button1;
boolean button2;
public ClickEvent(int currentX,int currentY,boolean button1,boolean button2){
this.currentX = currentX;
this.currentY = currentY;
this.button1 = button1;
this.button2 = button2;
}
public int getCurrentX(){
return currentX;
}
public int getCurrentY(){
return currentY;
}
public boolean getButton1(){
return button1;
}
public boolean getButton2(){
return button2;
}
}

View File

@ -0,0 +1,69 @@
package electrosphere.renderer.ui.events;
import electrosphere.renderer.ui.Element;
public class DragEvent implements Event {
public static enum DragEventType {
START,
DRAG,
RELEASE,
}
int currentX;
int currentY;
int previousX;
int previousY;
int deltaX;
int deltaY;
DragEventType type;
Element target;
public DragEvent(int currentX,int currentY,int previousX,int previousY,int deltaX,int deltaY,DragEventType type,Element target){
this.currentX = currentX;
this.currentY = currentY;
this.previousX = previousX;
this.previousY = previousY;
this.deltaX = deltaX;
this.deltaY = deltaY;
this.type = type;
this.target = target;
}
public int getCurrentX(){
return currentX;
}
public int getCurrentY(){
return currentY;
}
public int getPreviousX(){
return previousX;
}
public int getPreviousY(){
return previousY;
}
public int getDeltaX(){
return deltaX;
}
public int getDeltaY(){
return deltaY;
}
public DragEventType getType(){
return type;
}
public Element getTarget(){
return target;
}
public void setTarget(Element target){
this.target = target;
}
}

View File

@ -0,0 +1,5 @@
package electrosphere.renderer.ui.events;
public interface Event {
}

View File

@ -0,0 +1,15 @@
package electrosphere.renderer.ui.events;
public class FocusEvent implements Event {
boolean isFocused;
public FocusEvent(boolean isFocused){
this.isFocused = isFocused;
}
public boolean isFocused(){
return isFocused;
}
}

View File

@ -0,0 +1,15 @@
package electrosphere.renderer.ui.events;
public class KeyboardEvent implements Event {
String key;
public KeyboardEvent(String key){
this.key = key;
}
public String getKey(){
return key;
}
}

View File

@ -0,0 +1,57 @@
package electrosphere.renderer.ui.events;
public class MouseEvent implements Event {
int currentX;
int currentY;
int previousX;
int previousY;
int deltaX;
int deltaY;
boolean button1;
boolean button2;
public MouseEvent(int currentX,int currentY,int previousX,int previousY,int deltaX,int deltaY,boolean button1,boolean button2){
this.currentX = currentX;
this.currentY = currentY;
this.previousX = previousX;
this.previousY = previousY;
this.deltaX = deltaX;
this.deltaY = deltaY;
this.button1 = button1;
this.button2 = button2;
}
public int getCurrentX(){
return currentX;
}
public int getCurrentY(){
return currentY;
}
public int getPreviousX(){
return previousX;
}
public int getPreviousY(){
return previousY;
}
public int getDeltaX(){
return deltaX;
}
public int getDeltaY(){
return deltaY;
}
public boolean getButton1(){
return button1;
}
public boolean getButton2(){
return button2;
}
}

View File

@ -0,0 +1,5 @@
package electrosphere.renderer.ui.events;
public class NavigationEvent implements Event {
}

View File

@ -21,8 +21,8 @@ public class FontUtils {
static RawFontMap rawFontMap;
static HashMap<Character,Vector3f> positionMap = new HashMap();
static HashMap<Character,Vector3f> dimensionMap = new HashMap();
static HashMap<Character,Vector3f> positionMap = new HashMap<Character,Vector3f>();
static HashMap<Character,Vector3f> dimensionMap = new HashMap<Character,Vector3f>();
static int width = 10;
static int height = 10;

View File

@ -1,108 +0,0 @@
package electrosphere.renderer.ui.font;
import electrosphere.main.Globals;
import electrosphere.renderer.Model;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.ui.Widget;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class TextBox extends Widget{
int positionX;
int positionY;
int width;
int height;
int rows;
int cols;
String text;
boolean editable;
Vector3f color = new Vector3f(0,0,0);
public TextBox(int positionX, int positionY, int width, int height, int rows, int cols, String text, boolean render, boolean editable) {
this.positionX = positionX;
this.positionY = positionY;
this.width = width;
this.height = height;
this.rows = rows;
this.cols = cols;
this.text = text;
}
public int getRows() {
return rows;
}
public int getCols() {
return cols;
}
public String getText() {
return text;
}
public void setRows(int rows) {
this.rows = rows;
}
public void setCols(int cols) {
this.cols = cols;
}
public void setText(String text) {
this.text = text;
}
public void setColor(Vector3f color) {
this.color = color;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
@Override
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight){
Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer);
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
//monowidth for the moment
float charWidth = ndcWidth/cols;
float charHeight = ndcHeight/rows;
for(int y = 0; y < rows; y++){
for(int x = 0; x < cols; x++){
char toDraw = ' ';
if(x + y * cols < text.length()){
toDraw = text.charAt(x + y * cols);
}
Vector3f characterPosition = new Vector3f(ndcX + x * charWidth,ndcY + y * charHeight,0);
Vector3f characterDimensions = new Vector3f(charWidth,charHeight,0);
Vector3f bitMapPosition = FontUtils.getPositionOfCharacter(toDraw);
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacter(toDraw);
Model charModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_BITMAP_FONT);
if(charModel != null && toDraw != ' '){
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mPosition", characterPosition);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mDimension", characterDimensions);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tPosition", bitMapPosition);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tDimension", bitMapDimension);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "color", color);
charModel.drawUI();
}
}
}
}
}

View File

@ -3,7 +3,8 @@ package electrosphere.renderer.ui.font.bitmapchar;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.main.Globals;
import electrosphere.renderer.Model;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.font.FontUtils;
import org.joml.Vector3f;
@ -11,12 +12,8 @@ import org.joml.Vector3f;
*
* @author satellite
*/
public class BitmapCharacter extends Widget {
public class BitmapCharacter implements DrawableElement {
int positionX;
int positionY;
int width;
int height;
String text;
Vector3f color = new Vector3f(0,0,0);
@ -24,11 +21,11 @@ public class BitmapCharacter extends Widget {
public BitmapCharacter(int posX, int posY, int width, int height, char toDraw){
positionX = posX;
positionY = posY;
this.positionX = posX;
this.positionY = posY;
this.width = width;
this.height = height;
text = "" + toDraw;
this.text = "" + toDraw;
}
@ -75,5 +72,68 @@ public class BitmapCharacter extends Widget {
charModel.drawUI();
}
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -0,0 +1,202 @@
package electrosphere.renderer.ui.form;
import java.util.LinkedList;
import java.util.List;
import electrosphere.renderer.ui.ContainerElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.events.Event;
public class FormElement implements DrawableElement, ContainerElement {
List<Element> childList = new LinkedList<Element>();
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
// TODO Auto-generated method stub
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.draw(parentFramebufferPointer,parentWidth,parentHeight);
}
}
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public boolean focused = false;
public void onFocus(){
}
public int getWidth() {
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
}
}
if(minX == -1){
minX = 0;
}
if(maxX == -1){
maxX = 0;
}
return maxX - minX;
}
public int getHeight() {
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
}
}
if(minY == -1){
minY = 0;
}
if(maxY == -1){
maxY = 0;
}
return maxY - minY;
}
public int getPositionX() {
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
}
if(minX == -1){
minX = 0;
}
return minX;
}
public int getPositionY() {
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
}
if(minY == -1){
minY = 0;
}
return minY;
}
public boolean getVisible() {
return visible;
}
public boolean isFocused(){
return focused;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setVisible(draw);
}
}
}
public void setParentWidth(int width){
parentWidth = width;
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
}
}
}
public void setParentHeight(int height){
this.parentHeight = height;
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
}
}
}
public void setFocused(boolean focused){
this.focused = focused;
}
@Override
public void addChild(Element child) {
childList.add(child);
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
drawableChild.setVisible(false);
}
}
@Override
public List<Element> getChildren() {
return childList;
}
@Override
public void removeChild(Element child) {
childList.remove(child);
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -1,66 +0,0 @@
package electrosphere.renderer.ui.label;
import electrosphere.main.Globals;
import electrosphere.renderer.Model;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.font.FontUtils;
import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class Label extends Widget{
String text = "";
int textPixelWidth = 0;
float fontSize = 1.0f;
List<Widget> childrenElements = new LinkedList();
public Label(int x, int y, float fontSize){
this.positionX = x;
this.positionY = y;
this.width = 0;
this.height = (int)(FontUtils.getFontHeight() * fontSize);
this.fontSize = fontSize;
}
void generateLetters(){
childrenElements.clear();
int rollingOffset = 0;
for(int i = 0; i < text.length(); i++){
char toDraw = text.charAt(i);
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacterDiscrete(toDraw);
Widget newLetter = new BitmapCharacter((int)(rollingOffset * fontSize) + positionX, positionY, (int)(bitMapDimension.x * fontSize), this.height, toDraw);
rollingOffset += (int)bitMapDimension.x;
childrenElements.add(newLetter);
}
}
public void setText(String text){
this.text = text;
textPixelWidth = 0;
for(int i = 0; i < text.length(); i++){
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacterDiscrete(text.charAt(i));
textPixelWidth = textPixelWidth + (int)bitMapDimension.x;
}
generateLetters();
}
public String getText(){
return text;
}
@Override
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
for(Widget child : childrenElements){
child.draw(parentFramebufferPointer, parentWidth, parentHeight);
}
}
}

View File

@ -1,6 +1,7 @@
package electrosphere.renderer.ui.layout;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.ContainerElement;
import electrosphere.renderer.ui.DrawableElement;
import java.util.LinkedList;
import java.util.List;
@ -8,14 +9,8 @@ import java.util.List;
*
* @author amaterasu
*/
public abstract interface LayoutScheme {
public abstract interface LayoutScheme extends ContainerElement {
public abstract void pack();
public abstract void addWidget(Widget widget);
public abstract List<Widget> getWidgets();
public abstract void destroy();
}

View File

@ -3,7 +3,9 @@ package electrosphere.renderer.ui.layout;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.Model;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.framebuffer.FramebufferUtils;
@ -28,9 +30,9 @@ import static org.lwjgl.opengl.GL30.glBindFramebuffer;
*
* @author amaterasu
*/
public class LayoutSchemeListScrollable extends Widget {
public class LayoutSchemeListScrollable implements DrawableElement,LayoutScheme {
List<Widget> widgetList = new LinkedList();
List<Element> childList = new LinkedList<Element>();
Framebuffer widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
Material customMat = new Material();
@ -58,8 +60,11 @@ public class LayoutSchemeListScrollable extends Widget {
widgetBuffer.bind();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(Widget child : widgetList){
child.draw(widgetBuffer.getFramebufferPointer(),width,height);
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.draw(widgetBuffer.getFramebufferPointer(),width,height);
}
}
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
@ -82,17 +87,88 @@ public class LayoutSchemeListScrollable extends Widget {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void addWidget(Widget widget) {
widgetList.add(widget);
widget.setVisible(false);
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public List<Widget> getWidgets() {
return widgetList;
public int getHeight() {
return height;
}
public void destroy() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
@Override
public void addChild(Element child) {
childList.add(child);
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
drawableChild.setVisible(false);
}
}
@Override
public List<Element> getChildren() {
return childList;
}
@Override
public void removeChild(Element child) {
childList.remove(child);
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -1,9 +0,0 @@
package electrosphere.renderer.ui.transparenttextbox;
/**
*
* @author amaterasu
*/
public class TextBoxUtils {
}