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()));
});
}
Aggregations