Avarra GUI, still in progress. I lost some time trying to integrate an emulator (based on java boy for example) but there is nothing with a license compatible with jme so i just gave up.
For the record, the artist of the picture used is BoChengChou, licensed CCBY, found on the site (closed since then) en.free-photos.gatag.net, modified by me to add the black&white&red thing.
The hud gui is made with an xml file
<?xml version="1.0" encoding="UTF-8"?>
<area>
<script>
var name;
name = 'Toto';
</script>
<tabs>
<tab title="buttons">
<script>
var x;
x = 'Salut '+name;
var i = 0;
function number()
{
return i++;
}
function hide(elt)
{
tools.topLevelAncestor(elt).style().visible = false;
tools.setCursorVisible(false);
}
</script>
<button id="button1" text="Hello" x="0" y="10"
onClick="if ( self.text() == 'Hello' ) self.setText(x+' '+number()); else self.setText('Hello');" />
<button id="button2" text="World" x="200" y="30"
onClick="hide(self)" />
</tab>
<tab title="table">
<table>
<th>
<td>Nom</td>
<td>Age</td>
<td>Sexe</td>
</th>
<tr>
<td>David KELLER</td>
<td>28</td>
<td>Masculin</td>
</tr>
<tr>
<td>Méline AVDALIAN</td>
<td>?</td>
<td>Féminin</td>
</tr>
</table>
</tab>
<tab title="text">
Coucou
Comment ça va ?
</tab>
</tabs>
</area>
The script is dumb, i know, but it’s only to show the feature.
I wanted to have an xml file easy to read and keep the possibility to extend it. You can register factories that will say “ok, i take this tag, here is the gui element that goes with it” and add new tag that way.
The script part is done with the rhino engine embeded in java.
The Main looks like this :
package avarra;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetKey;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import java.io.IOException;
import java.io.InputStream;
import avarra.gui.AGUI;
import avarra.gui.GuiElement;
import avarra.gui.os.OS;
import avarra.gui.os.OSApplication;
import avarra.gui.widgets.games.Demineur;
import avarra.gui.widgets.games.Tetrix;
import avarra.inputs.DeviceManager;
import avarra.inputs.MouseDevice;
import avarra.inputs.VirtualDevice;
import avarra.scripts.ScriptAppState;
import com.jme3.input.MouseInput;
import ximl.Parser;
/**
*
*
* @author Bubuche
*/
public class Main extends SimpleApplication
{
public static void main(String[] args)
{
Main app = new Main();
app.setDisplayStatView(false);
app.setDisplayFps(false);
app.start();
}
@Override
public void simpleInitApp()
{
AGUI.initialize(this);
cam.setLocation(new Vector3f(0, 0, 4));
stateManager.getState(ScriptAppState.class).tools().setCursorVisible(true);
//stateManager.attach(new VideoRecorderAppState(new File("video.avi")));
initMapping();
initTestAGUI();
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.White);
mat.setTexture("ColorMap", assetManager.loadTexture("Textures/screen3.png"));
geom.setMaterial(mat);
OS os = new OS();
os.desktop().addApplication(new OSApplication(
"Démineur",
new Demineur(16, 16, 32, 0),
assetManager.loadTexture("Textures/demineur_icon.png")));
os.desktop().addApplication(new OSApplication(
"Tetrix",
new Tetrix(9, 10, 16),
assetManager.loadTexture("Textures/blockscrush.png")));
geom.addControl(os);
rootNode.attachChild(geom);
}
private void initMapping()
{
DeviceManager devicesManager = AGUI.instance.deviceManager();
VirtualDevice vd = devicesManager.virtual();
MouseDevice md = devicesManager.mouse();
vd.addMapping(md, MouseInput.BUTTON_LEFT, avarra.inputs.Action.Activate);
vd.addMapping(md, MouseInput.BUTTON_RIGHT, avarra.inputs.Action.AlternateActivate);
}
private void initTestAGUI()
{
AGUI.instance.deviceManager().mouse().press(MouseDevice.VISIBLE);
try (InputStream input = assetManager.locateAsset(new AssetKey<>("GUI/test.xml")).openStream())
{
GuiElement elt = AGUI.instance.xmlBuilder().attemptCreateElement(Parser.getTree(input));
AGUI.instance.hud().addElement(elt);
AGUI.centerInContainer(elt);
}
catch(IOException ex) {}
}
}
Next is: improve the viewport/scrollarea (with the 1 million dollar question: is it possible to use a subpart of a texture as framebuffer of a viewport), add a layout system, finish the lineedit with mouse handling …
An a lot of other cool stuff which i need to bang my head on to find THE good way to handle them.