Search in sources :

Example 1 with GraphNodeInput

use of games.rednblack.editor.graph.data.GraphNodeInput in project HyperLap2D by rednblackgames.

the class ArrayActionBoxProducer method addPart.

private void addPart(Skin skin, GraphBoxImpl<ActionFieldType> graphBox) {
    Map<String, GraphNodeInput<ActionFieldType>> inputs = graphBox.getConfiguration().getNodeInputs();
    VisTextButton addButton = StandardWidgetsFactory.createTextButton("+ Add Pin");
    VisTextButton removeButton = StandardWidgetsFactory.createTextButton("- Remove Pin");
    removeButton.setDisabled(inputs.size() <= 2);
    addButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            addPin(skin, graphBox);
            addButton.fire(new GraphChangedEvent(true, false));
            if (inputs.size() > 2) {
                removeButton.setDisabled(false);
            }
        }
    });
    addButton.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.cancel();
            return true;
        }
    });
    GraphBoxPartImpl<ActionFieldType> addPart = new GraphBoxPartImpl<>(addButton, null);
    graphBox.addHeaderGraphBoxPart(addPart);
    removeButton.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.cancel();
            return true;
        }
    });
    removeButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Map<String, GraphNodeInput<ActionFieldType>> inputs = graphBox.getConfiguration().getNodeInputs();
            GraphNodeInput<ActionFieldType> n = inputs.get("action" + (inputs.size() - 1));
            inputs.remove(n.getFieldId());
            graphBox.removeGraphBoxPart(inputs.size());
            graphBox.invalidate();
            addButton.fire(new GraphChangedEvent(true, false));
            if (inputs.size() == 2) {
                removeButton.setDisabled(true);
            }
        }
    });
    GraphBoxPartImpl<ActionFieldType> removePart = new GraphBoxPartImpl<>(removeButton, null);
    graphBox.addFooterGraphBoxPart(removePart);
    graphBox.setSerializeCallback(object -> {
        object.put("pins", String.valueOf(inputs.size()));
    });
}
Also used : VisTextButton(com.kotcrab.vis.ui.widget.VisTextButton) GraphChangedEvent(games.rednblack.editor.graph.GraphChangedEvent) GraphBoxPartImpl(games.rednblack.editor.graph.GraphBoxPartImpl) ActionFieldType(games.rednblack.editor.graph.actions.ActionFieldType) GraphNodeInput(games.rednblack.editor.graph.data.GraphNodeInput) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) HashMap(java.util.HashMap) Map(java.util.Map) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 VisTextButton (com.kotcrab.vis.ui.widget.VisTextButton)1 GraphBoxPartImpl (games.rednblack.editor.graph.GraphBoxPartImpl)1 GraphChangedEvent (games.rednblack.editor.graph.GraphChangedEvent)1 ActionFieldType (games.rednblack.editor.graph.actions.ActionFieldType)1 GraphNodeInput (games.rednblack.editor.graph.data.GraphNodeInput)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1