Search in sources :

Example 1 with GUIPositionEffect

use of net.drewke.tdme.gui.effects.GUIPositionEffect in project tdme by andreasdr.

the class GUITest method init.

/*
	 * (non-Javadoc)
	 * @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
	 */
public void init(GLAutoDrawable drawable) {
    // init engine
    engine.init(drawable);
    // register gui to mouse, keyboard events
    glWindow.addMouseListener(engine.getGUI());
    glWindow.addKeyListener(engine.getGUI());
    //
    try {
        engine.getGUI().addScreen("test", GUIParser.parse("resources/tests/gui", "test.xml"));
        engine.getGUI().getScreen("test").setScreenSize(640, 480);
        engine.getGUI().getScreen("test").addActionListener(new GUIActionListener() {

            public void onActionPerformed(GUIActionListener.Type type, GUIElementNode node) {
                // check if button 1 is pressed
                if (type == Type.PERFORMED && node.getName().equals("button")) {
                    // action performed
                    System.out.println(node.getId() + ".actionPerformed()");
                    // test get values
                    HashMap<String, MutableString> values = new HashMap<String, MutableString>();
                    node.getScreenNode().getValues(values);
                    System.out.println(values);
                    // test set values
                    values.clear();
                    values.put("select", new MutableString("8"));
                    values.put("input", new MutableString("Enter some more text here!"));
                    values.put("checkbox1", new MutableString("1"));
                    values.put("checkbox2", new MutableString("1"));
                    values.put("checkbox3", new MutableString("1"));
                    values.put("dropdown", new MutableString("11"));
                    values.put("radio", new MutableString("3"));
                    values.put("selectmultiple", new MutableString("|1|2|3|15|16|17|"));
                    node.getScreenNode().setValues(values);
                    // test GUI tab controller select tab method
                    ((GUITabController) node.getScreenNode().getNodeById("tab1").getController()).selectTab();
                } else // check if button 2 is pressed
                if (type == Type.PERFORMED && node.getName().equals("button2")) {
                    try {
                        {
                            GUIParentNode parentNode = (GUIParentNode) (node.getScreenNode().getNodeById("sadd_inner"));
                            parentNode.replaceSubNodes("<dropdown-option text=\"Option 1\" value=\"1\" />" + "<dropdown-option text=\"Option 2\" value=\"2\" />" + "<dropdown-option text=\"Option 3\" value=\"3\" />" + "<dropdown-option text=\"Option 4\" value=\"4\" />" + "<dropdown-option text=\"Option 5\" value=\"5\" />" + "<dropdown-option text=\"Option 6\" value=\"6\" />" + "<dropdown-option text=\"Option 7\" value=\"7\" />" + "<dropdown-option text=\"Option 8\" value=\"8\" selected=\"true\" />" + "<dropdown-option text=\"Option 9\" value=\"9\" />" + "<dropdown-option text=\"Option 10\" value=\"10\" />", true);
                        }
                        {
                            //
                            GUIParentNode parentNode = (GUIParentNode) (node.getScreenNode().getNodeById("sasb_inner"));
                            parentNode.replaceSubNodes("<selectbox-option text=\"Option 1\" value=\"1\" />" + "<selectbox-option text=\"Option 2\" value=\"2\" />" + "<selectbox-option text=\"Option 3\" value=\"3\" />" + "<selectbox-option text=\"Option 4\" value=\"4\" selected=\"true\" />" + "<selectbox-option text=\"Option 5\" value=\"5\" />" + "<selectbox-option text=\"Option 6\" value=\"6\" />" + "<selectbox-option text=\"Option 7\" value=\"7\" />" + "<selectbox-option text=\"Option 8\" value=\"8\" />" + "<selectbox-option text=\"Option 9\" value=\"9\" />" + "<selectbox-option text=\"Option 10\" value=\"10\" />", true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    // test GUI tab controller select tab method
                    ((GUITabController) node.getScreenNode().getNodeById("tab2").getController()).selectTab();
                }
            }
        });
        engine.getGUI().getScreen("test").addChangeListener(new GUIChangeListener() {

            public void onValueChanged(GUIElementNode node) {
                System.out.println(node.getName() + ":onValueChanged: " + node.getController().getValue());
            }
        });
        // layout
        engine.getGUI().getScreen("test").layout();
        // add fade in effect
        GUIColorEffect effectFadeIn = new GUIColorEffect();
        effectFadeIn.getColorMulStart().set(0f, 0f, 0f, 1f);
        effectFadeIn.getColorMulEnd().set(1f, 1f, 1f, 1f);
        effectFadeIn.setTimeTotal(1f);
        effectFadeIn.start();
        engine.getGUI().getScreen("test").addEffect("fadein", effectFadeIn);
        // add scroll in effect
        GUIPositionEffect effectScrollIn = new GUIPositionEffect();
        effectScrollIn.setPositionXStart(-800f);
        effectScrollIn.setPositionXEnd(0f);
        effectScrollIn.setTimeTotal(1f);
        effectScrollIn.start();
        engine.getGUI().getScreen("test").addEffect("scrollin", effectScrollIn);
        // add to render queue
        engine.getGUI().addRenderScreen("test");
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}
Also used : GUITabController(net.drewke.tdme.gui.elements.GUITabController) GUIParentNode(net.drewke.tdme.gui.nodes.GUIParentNode) HashMap(net.drewke.tdme.utils.HashMap) GUIChangeListener(net.drewke.tdme.gui.events.GUIChangeListener) MutableString(net.drewke.tdme.utils.MutableString) GUIColorEffect(net.drewke.tdme.gui.effects.GUIColorEffect) MutableString(net.drewke.tdme.utils.MutableString) GUIElementNode(net.drewke.tdme.gui.nodes.GUIElementNode) GUIActionListener(net.drewke.tdme.gui.events.GUIActionListener) GUIPositionEffect(net.drewke.tdme.gui.effects.GUIPositionEffect)

Aggregations

GUIColorEffect (net.drewke.tdme.gui.effects.GUIColorEffect)1 GUIPositionEffect (net.drewke.tdme.gui.effects.GUIPositionEffect)1 GUITabController (net.drewke.tdme.gui.elements.GUITabController)1 GUIActionListener (net.drewke.tdme.gui.events.GUIActionListener)1 GUIChangeListener (net.drewke.tdme.gui.events.GUIChangeListener)1 GUIElementNode (net.drewke.tdme.gui.nodes.GUIElementNode)1 GUIParentNode (net.drewke.tdme.gui.nodes.GUIParentNode)1 HashMap (net.drewke.tdme.utils.HashMap)1 MutableString (net.drewke.tdme.utils.MutableString)1