I just wanted to create my own solution for gui from xml/code and i started yesterday writing this thing. I will include later effects/checkbox/selectbox.
working for XML with box like div element in html and input/text elements. rootelement is stateName for gui
usable:
gameGUI.readFile("/Interface/States/loading.xml");
gameGUI.removeState(“loading”); // loading is from rootelement of loading tag name
MyCallback.java
[java]
/**
*
-
@author oxplay
- Radosław Kwolek
/
import java.util.ArrayList;
public abstract class MyCallback {
public ArrayList<String> args = new ArrayList<String>();
public void end(){};
}
[/java]
it is using ControlManager:
http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/controlmanager/
MyGUI.java // again Debug is just for debugging, FontConfig contains actual font
[java]
import com.jme3.app.state.AbstractAppState;
import com.jme3.asset.AssetManager;
import com.jme3.font.BitmapText;
import com.jme3.input.InputManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.ui.Picture;
import com.jme3.renderer.Camera;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import oxplay.app.controls.ControlIO;
import oxplay.datatypes.MyCallback;
import java.io.File;
import java.net.URL;
import org.w3c.dom.;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import oxplay.app.configuration.FontConfiguration;
import oxplay.debug.Debug;
/**
*
-
@author oxplay
- Radosław Kwolek
/
public class MyGUI extends AbstractAppState {
AssetManager assetManager;
InputManager inputManager;
com.jme3.scene.Node guiNode;
Camera camera;
FontConfiguration fontConfig;
long lastBlinkUpdate = System.currentTimeMillis();
public boolean sign = false;
private ArrayList<MyCallback> rendererUpdateList = new ArrayList<MyCallback>();
private ArrayList<CreationElement> elementList = new ArrayList<CreationElement>();
MyGUI(AssetManager assetManager, InputManager inputManager, com.jme3.scene.Node guiNode, Camera camera, FontConfiguration fontConfig){
this.assetManager = assetManager;
this.inputManager = inputManager;
this.guiNode = guiNode;
this.camera = camera;
this.fontConfig = fontConfig;
}
public CreationElement getElementByID(String id) {
Iterator<CreationElement> i = elementList.iterator();
while (i.hasNext()) {
CreationElement element = i.next();
if (element.ID.equals(id)) {
return element;
}
}
return null;
}
public boolean issetState(String state) {
Iterator<CreationElement> i = elementList.iterator();
while (i.hasNext()) {
CreationElement element = i.next();
if (element.stateName != null && element.stateName.equals(state)) {
return true;
}
}
return false;
}
public void removeState(String state) {
Iterator<CreationElement> i = elementList.iterator();
while (i.hasNext()) {
CreationElement element = i.next();
if (element.stateName != null && element.stateName.equals(state)) {
element.detachSaveList();
i.remove();
}
}
}
public Box getBoxByID(String id) {
return (Box) getElementByID(id);
}
public Text getTextByID(String id) {
return (Text) getElementByID(id);
}
public Input getInputByID(String id) {
return (Input) getElementByID(id);
}
public abstract class CreationElement {
String stateName = null;
String ID = null;
int x = 0;
int y = 0;
boolean centerX = false;
boolean centerY = false;
int width = 1;
int height = 1;
public void setStateName(String stateName) {
this.stateName = stateName;
}
public void setID(String ID) {
this.ID = ID;
}
public void setX(int x) {
this.x = x;
}
public int getX() {
return x;
}
public void setY(int y) {
this.y = y;
}
public int getY() {
return y;
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return width;
}
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return height;
}
public void setCenterX(boolean set) {
this.centerX = set;
}
public void setCenterY(boolean set) {
this.centerY = set;
}
public abstract void attachWork();
public abstract void detachWork();
public abstract void updateWork();
public void updateData() {
Debug.reportInfo(Debug.PRIORITY_TWO, “GUI updateData()”);
try {
rendererUpdateList.add(new MyCallback() {
@Override
public void end() {
updateWork();
}
});
} catch (Exception error) {
Debug.reportInfo(Debug.PRIORITY_ZERO, “GUI updateData()”, error);
}
}
public void attach() {
try {
elementList.add(this);
rendererUpdateList.add(new MyCallback() {
@Override
public void end() {
updateWork();
attachWork();
}
});
} catch (Exception error) {
Debug.reportInfo(Debug.PRIORITY_ZERO, "GUI attach() error: " + error);
}
}
public void attachFast() {
updateWork();
attachWork();
elementList.add(this);
}
public void detach() {
try {
elementList.remove(this);
rendererUpdateList.add(new MyCallback() {
@Override
public void end() {
detachWork();
}
});
} catch (Exception error) {
Debug.reportInfo(Debug.PRIORITY_ZERO, “GUI detach() error: " + error);
}
}
public void detachSaveList() {
try {
rendererUpdateList.add(new MyCallback() {
@Override
public void end() {
detachWork();
}
});
} catch (Exception error) {
Debug.reportInfo(Debug.PRIORITY_ZERO, “GUI detach() error: " + error);
}
}
public void detachFast() {
detachWork();
elementList.remove(this);
}
public abstract boolean mouseAction(int mouseX, int mouseY, boolean clicked);
public abstract boolean keaAction(String key);
}
class RootParent extends CreationElement {
RootParent() {
x = 0;
y = 0;
width = camera.getWidth();
height = camera.getHeight();
}
public void updateWork() {
}
public void attachWork() {
}
public void detachWork() {
}
public boolean mouseAction(int mouseX, int mouseY, boolean clicked) {
return false;
}
public boolean keaAction(String key) {
return false;
}
}
public class Box extends CreationElement {
private float alpha = 1.0f;
private ColorRGBA color = null;
public boolean over = false;
private float imageRepeat = 1.0f;
public String image = null;
public Picture view = null;
public MyCallback mouseover = null;
public MyCallback mouseout = null;
public MyCallback mouseclick = null;
Box() {
view = new Picture(ID);
}
public void setImage(String image) {
this.image = image;
}
public void setImageRepeat(float imageRepeat) {
this.imageRepeat = imageRepeat;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
}
public float getAlpha() {
return alpha;
}
public boolean isMouseOver() {
if ((int) inputManager.getCursorPosition().x > this.x && (int) inputManager.getCursorPosition().x < this.x + this.width && (int) inputManager.getCursorPosition().y > this.y && (int) inputManager.getCursorPosition().y < this.y + this.height) {
return true;
}
return false;
}
public void updateWork() {
Debug.reportInfo(Debug.PRIORITY_TWO, “updateWork() " + width + " " + height + " [” + x + " " + y + “]”);
view.setWidth(width);
view.setHeight(height);
view.setPosition(x, y);
if (image != null) {
try {
Texture2D tex2 = (Texture2D) ApplicationControl.appControl.getAssetManager().loadTexture(image);
tex2.setWrap(Texture.WrapMode.Repeat);
view.setTexture(ApplicationControl.appControl.getAssetManager(), tex2, true);
} catch (Exception err) {
Debug.reportInfo(Debug.PRIORITY_ZERO, “box updateWork() texture”, err);
}
} else if (color != null) {
try {
this.color.a = alpha;
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”, this.color);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
view.setMaterial(mat);
} catch (Exception err) {
Debug.reportInfo(Debug.PRIORITY_ZERO, “box updateWork() color”, err);
}
} else {
Debug.reportInfo(Debug.PRIORITY_ZERO, “Box gui without color/texture exception”);
}
}
public ColorRGBA getColor() {
return color;
}
public String getImage() {
return image;
}
public void setColor(ColorRGBA color) {
this.color = color;
}
public void attachWork() {
updateWork();
view.getMesh().scaleTextureCoordinates(new Vector2f(imageRepeat, imageRepeat));
guiNode.attachChild(view);
}
public void detachWork() {
if (view != null && view.getParent() != null) {
view.removeFromParent();
}
}
public boolean mouseAction(int mouseX, int mouseY, boolean clicked) {
boolean usingClick = false;
if (clicked) {
updateData();
}
if (mouseX >= x && mouseX <= (x + width) && mouseY >= y && mouseY <= (y + height)) {
if (!over) {
over = true;
if (mouseover != null) {
mouseover.end();
}
}
if (clicked && mouseclick != null) {
usingClick = true;
mouseclick.end();
}
updateData();
} else {
if (over) {
over = false;
if (mouseout != null) {
mouseout.end();
}
}
}
return usingClick;
}
public boolean keaAction(String key) {
return false;
}
}
public class Text extends CreationElement {
private String str;
private float fontSize = 1.0f;
public boolean over = false;
public BitmapText txt = null;
public MyCallback mouseover = null;
public MyCallback mouseout = null;
public MyCallback mouseclick = null;
Text() {
txt = new BitmapText(fontConfig.myFont, false);
}
public void setValue(String str) {
this.str = str;
}
public String getValue() {
return str;
}
public void setFontSize(float fontSize) {
this.fontSize = fontSize;
}
public void attachWork() {
updateWork();
guiNode.attachChild(txt);
}
public void detachWork() {
if (txt != null && txt.getParent() != null) {
txt.removeFromParent();
}
}
public void updateWork() {
txt.setSize(fontConfig.myFont.getPreferredSize() * fontSize);
txt.setText(str);
txt.setLocalTranslation(x - (txt.getLineWidth() / 2) + (width / 2), y + (txt.getHeight() / 2) + (height / 2), 0);
}
public boolean mouseAction(int mouseX, int mouseY, boolean clicked) {
boolean usingClick = false;
if (clicked) {
updateData();
}
if (mouseX >= x && mouseX <= (x + width) && mouseY >= y && mouseY <= (y + height)) {
if (!over) {
over = true;
if (mouseover != null) {
mouseover.end();
}
}
if (clicked && mouseclick != null) {
usingClick = true;
mouseclick.end();
}
updateData();
} else {
if (over) {
over = false;
if (mouseout != null) {
mouseout.end();
}
}
}
return usingClick;
}
public boolean keaAction(String key) {
return false;
}
}
public class Input extends CreationElement {
public boolean active = false;
public boolean blinking = false;
private String str;
public boolean over = false;
private float fontSize = 1.0f;
private float alpha = 1.0f;
private ColorRGBA color = null;
private ColorRGBA colorOver = null;
private float imageRepeat = 1f;
private String image = null;
private String imageOver = null;
public Box box;
public Text text;
public MyCallback mouseover = null;
public MyCallback mouseout = null;
public MyCallback mouseclick = null;
Input() {
box = new Box();
box.setID(ID + “__box”);
text = new Text();
text.setID(ID + “__text”);
}
public void setValue(String str) {
this.str = str;
}
public void setFontSize(float fontSize) {
this.fontSize = fontSize;
}
public void setColor(ColorRGBA color) {
this.color = color;
}
public void setColorOver(ColorRGBA colorOver) {
this.colorOver = colorOver;
}
public void setImage(String image) {
this.image = image;
}
public void setImageOver(String imageOver) {
this.imageOver = imageOver;
}
public void setImageRepeat(float imageRepeat) {
this.imageRepeat = imageRepeat;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
}
public float getAlpha() {
return alpha;
}
public void attachWork() {
text.attachWork();
box.attachWork();
}
public void detachWork() {
text.detachWork();
box.detachWork();
}
public void updateWork() {
text.setID(ID + “__text”);
text.x = x;
text.y = y;
text.width = width;
text.height = height;
text.fontSize = fontSize;
text.str = str;
text.updateWork();
box.setID(ID + “__box”);
box.x = x;
box.y = y;
box.width = width;
box.height = height;
box.color = color;
box.image = image;
box.imageRepeat = imageRepeat;
box.alpha = alpha;
box.updateWork();
}
public boolean mouseAction(int mouseX, int mouseY, boolean clicked) {
boolean usingClick = false;
if (clicked) {
active = false;
updateData();
}
if (box.image != null) {
if (box.image.equals(imageOver)) {
box.image = image;
box.updateData();
}
} else {
box.color = color;
}
if (mouseX >= x && mouseX <= (x + width) && mouseY >= y && mouseY <= (y + height)) {
if (box.image != null) {
box.image = imageOver;
} else {
box.color = colorOver;
}
if (!over) {
over = true;
if (mouseover != null) {
mouseover.end();
}
}
if (clicked) {
active = true;
if (mouseclick != null) {
usingClick = true;
mouseclick.end();
}
}
updateData();
} else {
if (over) {
over = false;
if (mouseout != null) {
mouseout.end();
}
}
}
return usingClick;
}
public boolean keaAction(String key) {
if (active) {
if (key.equals(“backspace”)) {
try {
text.str = text.str.substring(0, text.str.length() - 1);
} catch (Exception err) {
}
} else {
text.str = text.str + key;
}
text.updateData();
return true;
}
return false;
}
}
private boolean isPercentValue(String attrValue) {
if (attrValue.substring(attrValue.length() - 1, attrValue.length()).equals(”%”)) {
Debug.reportInfo(Debug.PRIORITY_TWO, “isPercentValue true”);
return true;
}
Debug.reportInfo(Debug.PRIORITY_TWO, “isPercentValue false”);
return false;
}
private boolean isPixelValue(String attrValue) {
if (attrValue.substring(attrValue.length() - 2, attrValue.length()).equals(“px”)) {
Debug.reportInfo(Debug.PRIORITY_TWO, “isPixelValue true”);
return true;
}
Debug.reportInfo(Debug.PRIORITY_TWO, “isPixelValue false”);
return false;
}
private int getPercentToInt(String attrValue, int scale) {
attrValue = attrValue.substring(0, attrValue.length() - 1);
Debug.reportInfo(Debug.PRIORITY_TWO, “getPercentToInt scale:” + scale + " attrValue " + attrValue);
int attrIntValue = (int) Math.round((Float.parseFloat(attrValue) / 100f) * scale);
Debug.reportInfo(Debug.PRIORITY_TWO, “getPercentToInt scale:” + scale + " true value " + attrIntValue);
return attrIntValue;
}
private int getPixelToInt(String attrValue) {
attrValue = attrValue.substring(0, attrValue.length() - 2);
Debug.reportInfo(Debug.PRIORITY_TWO, "getPixelToInt attrValue " + attrValue);
int attrIntValue = Integer.parseInt(attrValue);
Debug.reportInfo(Debug.PRIORITY_TWO, "getPixelToInt true value " + attrIntValue);
return attrIntValue;
}
private int processArgumentWidth(String attrValue, CreationElement creationElement, CreationElement parent) throws Exception {
if (isPixelValue(attrValue)) {
return getPixelToInt(attrValue);
} else if (isPercentValue(attrValue)) {
return getPercentToInt(attrValue, parent.getWidth());
} else {
throw new Exception(“GUI value must contain ‘px’ or ‘%’”);
}
}
private int processArgumentHeight(String attrValue, CreationElement creationElement, CreationElement parent) throws Exception {
if (isPixelValue(attrValue)) {
return getPixelToInt(attrValue);
} else if (isPercentValue(attrValue)) {
return getPercentToInt(attrValue, parent.getHeight());
} else {
throw new Exception(“GUI value must contain ‘px’ or ‘%’”);
}
}
private int processArgumentX(String attrValue, CreationElement creationElement, CreationElement parent) throws Exception {
if (attrValue.equals(“center”)) {
creationElement.centerX = true;
return 1;
} else {
return processArgumentWidth(attrValue, creationElement, parent) + parent.getX();
}
}
private int processArgumentY(String attrValue, CreationElement creationElement, CreationElement parent) throws Exception {
int flipValue = parent.getHeight() - creationElement.getHeight();
if (attrValue.equals(“center”)) {
creationElement.centerY = true;
return 1;
} else {
return flipValue - processArgumentHeight(attrValue, creationElement, parent) + parent.getY();
}
}
private ColorRGBA processArgumentColor(String attrValue) {
Color bColor = Color.decode(“0x” + attrValue);
float[] color = bColor.getRGBComponents(new float[4]);
Debug.reportInfo(Debug.PRIORITY_TWO, "processArgumentColor() " + “0x” + attrValue + " -> " + bColor.getRed() + “(” + color[0] + "), " + bColor.getGreen() + “(” + color[1] + "), " + bColor.getBlue() + “(” + color[2] + “) alpha:(” + color[3] + “)”);
ColorRGBA trueColor = new ColorRGBA(color[0], color[1], color[2], 1.0f);
return trueColor;
}
private Attr[] getNodeAttributesArray(Node element) {
int length = (element.getAttributes() != null) ? element.getAttributes().getLength() : 0;
Attr attributes[] = new Attr[length];
for (int loopIndex = 0; loopIndex < length; loopIndex++) {
attributes[loopIndex] = (Attr) element.getAttributes().item(loopIndex);
}
return attributes;
}
private void centeringOperation(CreationElement creationElement, CreationElement parent) {
if (creationElement.centerX) {
creationElement.setX(parent.getX() + Math.round(parent.getWidth() / 2) - Math.round(creationElement.getWidth() / 2));
}
if (creationElement.centerY) {
creationElement.setY(parent.getY() + Math.round(parent.getHeight() / 2) - Math.round(creationElement.getHeight() / 2));
}
}
public CreationElement processBox(String stateName, Node element, CreationElement parent) throws Exception {
Debug.reportInfo(Debug.PRIORITY_TWO, “processBox()”);
///////////////////////////////
Box creationBox = new Box();
creationBox.setStateName(stateName);
Attr attributes[] = getNodeAttributesArray(element);
for (int loopIndex = 0; loopIndex < attributes.length; loopIndex++) {
String attrName = attributes[loopIndex].getNodeName();
String attrValue = attributes[loopIndex].getNodeValue();
Debug.reportInfo(Debug.PRIORITY_TWO, attrName + “=” + attrValue);
if (attrName.equals(“ID”) || attrName.equals(“id”)) {
creationBox.setID(attrValue);
} else if (attrName.equals(“top”)) {
creationBox.setY(processArgumentY(attrValue, creationBox, parent));
} else if (attrName.equals(“left”)) {
creationBox.setX(processArgumentX(attrValue, creationBox, parent));
} else if (attrName.equals(“width”)) {
creationBox.setWidth(processArgumentWidth(attrValue, creationBox, parent));
} else if (attrName.equals(“height”)) {
creationBox.setHeight(processArgumentHeight(attrValue, creationBox, parent));
} else if (attrName.equals(“color”)) {
creationBox.setColor(processArgumentColor(attrValue));
} else if (attrName.equals(“alpha”)) {
creationBox.setAlpha(Float.parseFloat(attrValue));
} else if (attrName.equals(“image_repeat”)) {
creationBox.setImageRepeat(Float.parseFloat(attrValue));
} else if (attrName.equals(“image”)) {
creationBox.setImage(attrValue);
} else {
throw new Exception(“GUI Box unknown argment”);
}
}
centeringOperation(creationBox, parent);
creationBox.attach();
return creationBox;
}
public CreationElement processInput(String stateName, Node element, CreationElement parent) throws Exception {
Debug.reportInfo(Debug.PRIORITY_TWO, “processInput()”);
Input creationInput = new Input();
creationInput.setStateName(stateName);
Attr attributes[] = getNodeAttributesArray(element);
for (int loopIndex = 0; loopIndex < attributes.length; loopIndex++) {
String attrName = attributes[loopIndex].getNodeName();
String attrValue = attributes[loopIndex].getNodeValue();
Debug.reportInfo(Debug.PRIORITY_TWO, attrName + “=” + attrValue);
if (attrName.equals(“ID”) || attrName.equals(“id”)) {
creationInput.setID(attrValue);
} else if (attrName.equals(“top”)) {
creationInput.setY(processArgumentY(attrValue, creationInput, parent));
} else if (attrName.equals(“left”)) {
creationInput.setX(processArgumentX(attrValue, creationInput, parent));
} else if (attrName.equals(“width”)) {
creationInput.setWidth(processArgumentWidth(attrValue, creationInput, parent));
} else if (attrName.equals(“height”)) {
creationInput.setHeight(processArgumentHeight(attrValue, creationInput, parent));
} else if (attrName.equals(“color”)) {
creationInput.setColor(processArgumentColor(attrValue));
} else if (attrName.equals(“color_over”)) {
creationInput.setColorOver(processArgumentColor(attrValue));
} else if (attrName.equals(“alpha”)) {
creationInput.setAlpha(Float.parseFloat(attrValue));
} else if (attrName.equals(“image_repeat”)) {
creationInput.setImageRepeat(Float.parseFloat(attrValue));
} else if (attrName.equals(“image”)) {
creationInput.setImage(attrValue);
} else if (attrName.equals(“image_over”)) {
creationInput.setImageOver(attrValue);
} else {
throw new Exception(“GUI Box unknown argment”);
}
}
centeringOperation(creationInput, parent);
creationInput.attach();
return creationInput;
}
public CreationElement processText(String stateName, Node element, CreationElement parent) throws Exception {
Debug.reportInfo(Debug.PRIORITY_TWO, "processText() " + stateName + “”);
Text creationText = new Text();
creationText.setStateName(stateName);
Attr attributes[] = getNodeAttributesArray(element);
for (int loopIndex = 0; loopIndex < attributes.length; loopIndex++) {
String attrName = attributes[loopIndex].getNodeName();
String attrValue = attributes[loopIndex].getNodeValue();
Debug.reportInfo(Debug.PRIORITY_TWO, attrName + “=” + attrValue);
if (attrName.equals(“ID”) || attrName.equals(“id”)) {
creationText.setID(attrValue);
} else if (attrName.equals(“top”)) {
creationText.setY(processArgumentY(attrValue, creationText, parent));
} else if (attrName.equals(“left”)) {
creationText.setX(processArgumentX(attrValue, creationText, parent));
} else if (attrName.equals(“width”)) {
creationText.setWidth(processArgumentWidth(attrValue, creationText, parent));
} else if (attrName.equals(“height”)) {
creationText.setHeight(processArgumentHeight(attrValue, creationText, parent));
} else if (attrName.equals(“font_size”)) {
creationText.setID(attrValue);
} else {
throw new Exception(“GUI text unknown argment”);
}
}
centeringOperation(creationText, parent);
creationText.setValue(element.getTextContent());
creationText.attach();
return creationText;
}
public void processElements(Document doc, Node node, CreationElement parent) {
NodeList listOfChilds = node.getChildNodes();
int totalChilds = listOfChilds.getLength();
Debug.reportInfo(Debug.PRIORITY_TWO, "Total no of childs: " + totalChilds);
for (int i = 0; i < listOfChilds.getLength(); i++) {
Node childNode = listOfChilds.item(i);
String childName = childNode.getNodeName();
try {
if (childNode.getNodeType() == Node.ENTITY_NODE) {
Debug.reportInfo(Debug.PRIORITY_TWO, "ENTITY_NODE : " + childName);
if (childName.equals(“input”)) {
CreationElement createdElement = processBox(doc.getDocumentElement().getNodeName(), childNode, parent);
}
}
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
Debug.reportInfo(Debug.PRIORITY_TWO, "ELEMENT_NODE : " + childName);
if (childName.equals(“box”)) {
CreationElement createdElement = processBox(doc.getDocumentElement().getNodeName(), childNode, parent);
processElements(doc, childNode, createdElement);
}
if (childName.equals(“text”)) {
CreationElement createdElement = processText(doc.getDocumentElement().getNodeName(), childNode, parent);
}
}
} catch (Exception err) {
Debug.reportInfo(Debug.PRIORITY_TWO, “processElements”, err);
}
}
}
public void readFile(String file) {
try {
Debug.reportInfo(Debug.PRIORITY_TWO, “readFile()”);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
URL xmlUrl = this.getClass().getResource(file);
Document doc = docBuilder.parse(new File(xmlUrl.getFile()));
doc.getDocumentElement().normalize(); // normalize text representation
Debug.reportInfo(Debug.PRIORITY_TWO, "Root element of the xml doc is " + doc.getDocumentElement().getNodeName());
RootParent rootParent = new RootParent();
processElements(doc, doc.getDocumentElement(), rootParent);
///////////////////////////////////////////////////////////////
} catch (SAXParseException err) {
Debug.reportInfo(Debug.PRIORITY_ONE, "* Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
Debug.reportInfo(Debug.PRIORITY_ONE, " " + err);
} catch (SAXException err) {
Debug.reportInfo(Debug.PRIORITY_ONE, " " + err);
} catch (Throwable t) {
Debug.reportInfo(Debug.PRIORITY_ONE, " " + t);
}
}
@Override
public void update(float tpf) {
ArrayList<MyCallback> tmpUpdateList = (ArrayList<MyCallback>) rendererUpdateList.clone();
synchronized (tmpUpdateList) {
Iterator<MyCallback> it = tmpUpdateList.iterator();
while (it.hasNext()) {
MyCallback renderCallback = it.next();
renderCallback.end();
it.remove();
}
}
rendererUpdateList.clear();
blinkUpdate();
}
public void blinkUpdate() {
long actBlinkUpdate = System.currentTimeMillis();
if (Math.abs(actBlinkUpdate - lastBlinkUpdate) > 400) {
lastBlinkUpdate = System.currentTimeMillis();
sign = !sign;
for (int i = 0; i < elementList.size(); i++) {
if (elementList.get(i) instanceof Input) {
Input input = ((Input) elementList.get(i));
if (input != null && input.text != null && input.text.txt != null) {
if (input.active) {
if (sign) {
input.text.txt.setText(input.text.str + “|”);
} else {
input.text.txt.setText(input.text.str + “”);
}
} else {
input.text.txt.setText(input.text.str + “”);
}
}
}
}
}
}
public class GUIControls extends ControlIO {
GUIControls() {
this.setPriority(0);
}
@Override
public boolean keyEvent(String key) {
for (int i = 0; i < elementList.size(); i++) {
if (elementList.get(i) instanceof CreationElement) {
Input input = ((Input) elementList.get(i));
if (input.keaAction(key)) {
return true;
}
}
}
return false;
}
@Override
public boolean mouseEvent(int mouseX, int mouseY, boolean clicked, boolean clickState) {
Debug.reportInfo(Debug.PRIORITY_TWO, "GUI mouseEvent " + mouseX + " " + mouseY + " " + clicked + " " + clickState);
for (int i = 0; i < elementList.size(); i++) {
if (elementList.get(i).mouseAction(mouseX, mouseY, clicked)) {
return true;
}
}
return false;
}
}
GUIControls controls = new GUIControls();
public void detachElement(String name) {
CreationElement element = getElementByID(name);
if (element != null) {
element.detach();
}
}
public Input newInput(String ID, float fontSize, int x, int y, int width, int height, String image, String imageOver, String str) {
Input input = new Input();
input.ID = ID;
input.fontSize = fontSize;
input.x = x;
input.y = y;
input.width = width;
input.height = height;
input.image = image;
input.imageOver = imageOver;
input.str = str;
return input;
}
public Input newInput(String ID, float fontSize, int x, int y, int width, int height, ColorRGBA color, ColorRGBA colorOver, String str) {
Input input = new Input();
input.ID = ID;
input.fontSize = fontSize;
input.x = x;
input.y = y;
input.width = width;
input.height = height;
input.color = color;
input.colorOver = colorOver;
input.str = str;
return input;
}
public Text newText(String ID, float fontSize, int x, int y, int width, int height, String str) {
Text text = new Text();
text.ID = ID;
text.fontSize = fontSize;
text.x = x;
text.y = y;
text.width = width;
text.height = height;
text.str = str;
return text;
}
public Box newBox(String ID, int x, int y, int width, int height, String image) {
Box box = new Box();
box.ID = ID;
box.x = x;
box.y = y;
box.width = width;
box.height = height;
box.image = image;
return box;
}
public Box newBox(String ID, int x, int y, int width, int height, ColorRGBA color) {
Box box = new Box();
box.ID = ID;
box.x = x;
box.y = y;
box.width = width;
box.height = height;
box.color = color;
return box;
}
}[/java]