SimplyGladiators/core/src/com/saltosion/gladiator/gui/GUIManager.java

57 lines
1.5 KiB
Java
Raw Normal View History

2015-05-11 12:44:43 +02:00
package com.saltosion.gladiator.gui;
import java.util.ArrayList;
import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.systems.RenderingSystem;
import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Global;
2015-05-11 12:44:43 +02:00
public class GUIManager {
private final GUINode rootNode;
public GUIManager() {
2015-05-11 21:02:29 +02:00
this.rootNode = new GUINode("root").setPosition(-.5f, -.5f);
2015-05-11 12:44:43 +02:00
}
public GUINode getRootNode() {
return this.rootNode;
}
public ArrayList<GUINode> getAllRecursiveChildren(GUINode guiNode) {
ArrayList<GUINode> list = new ArrayList<GUINode>();
for (GUINode child : guiNode.getChildren()) {
list.add(child);
list.addAll(getAllRecursiveChildren(child));
}
return list;
}
public GUINode getNode(String id) {
for (GUINode node : getAllRecursiveChildren(rootNode)) {
if (node.getID().equals(id)) {
return node;
}
}
return null;
}
public static Vector2 physicsLocationToGUILocation(Vector2 physicslocation ) {
RenderingSystem rs = AppUtil.engine.getSystem(RenderingSystem.class);
float cameraY = 1-(rs.getCameraLocation().y/AppUtil.VPHEIGHT_CONST
+.5f);
float cameraX = 1-(rs.getCameraLocation().x/(AppUtil.VPHEIGHT_CONST*RenderingSystem.aspectratio)
+.5f);
System.out.println(cameraX + ":" + cameraY);
float y = physicslocation.y/AppUtil.VPHEIGHT_CONST
+ cameraY;
float x = physicslocation.x/(AppUtil.VPHEIGHT_CONST*RenderingSystem.aspectratio)
+ cameraX;
Vector2 v = new Vector2(x, y);
return v;
}
2015-05-11 12:44:43 +02:00
}