Search in sources :

Example 1 with Param

use of com.bladecoder.engine.actions.Param in project bladecoder-adventure-engine by bladecoder.

the class ActionUtils method getParams.

public static Param[] getParams(Action action) {
    List<Param> params = new ArrayList<>();
    Class<?> clazz = action.getClass();
    while (clazz != null && clazz != Object.class) {
        for (Field field : clazz.getDeclaredFields()) {
            final ActionProperty property = field.getAnnotation(ActionProperty.class);
            if (property == null) {
                continue;
            }
            final ActionPropertyDescription propertyDescription = field.getAnnotation(ActionPropertyDescription.class);
            // saved in the model.
            if (propertyDescription == null)
                continue;
            final String name = field.getName();
            Param.Type type = property.type();
            Enum<?>[] options = null;
            if (field.getType().isEnum()) {
                final boolean accessible = field.isAccessible();
                field.setAccessible(true);
                options = (Enum[]) field.getType().getEnumConstants();
                field.setAccessible(accessible);
                type = Param.Type.OPTION;
            } else if (property.type() == Param.Type.NOT_SET) {
                type = getType(field);
            }
            params.add(new Param(name, propertyDescription != null ? propertyDescription.value() : "", type, property.required(), property.defaultValue(), options));
        }
        clazz = clazz.getSuperclass();
    }
    return params.toArray(new Param[params.size()]);
}
Also used : ActionProperty(com.bladecoder.engine.actions.ActionProperty) ArrayList(java.util.ArrayList) Type(com.bladecoder.engine.actions.Param.Type) Field(java.lang.reflect.Field) ActionPropertyDescription(com.bladecoder.engine.actions.ActionPropertyDescription) Param(com.bladecoder.engine.actions.Param)

Example 2 with Param

use of com.bladecoder.engine.actions.Param in project bladecoder-adventure-engine by bladecoder.

the class EditActionDialog method setAction.

private void setAction() {
    String id = actionPanel.getText();
    getCenterPanel().clear();
    addInputPanel(actionPanel);
    Action tmp = null;
    tmp = ActionDetector.create(id, null);
    String info = ActionUtils.getInfo(tmp.getClass());
    if (ActionUtils.isDeprecated(tmp.getClass()))
        info = "[RED]DEPRECATED[]\n" + info;
    setInfo(info);
    if (e == null || tmp == null || !(e.getClass().getName().equals(tmp.getClass().getName())))
        e = tmp;
    if (e != null) {
        Param[] params = ActionUtils.getParams(e);
        i = new InputPanel[params.length];
        for (int j = 0; j < params.length; j++) {
            if (params[j].options instanceof Enum[]) {
                i[j] = InputPanelFactory.createInputPanel(getSkin(), params[j].name, params[j].desc, params[j].type, params[j].mandatory, params[j].defaultValue, (Enum[]) params[j].options);
            } else {
                i[j] = InputPanelFactory.createInputPanel(getSkin(), params[j].name, params[j].desc, params[j].type, params[j].mandatory, params[j].defaultValue, (String[]) params[j].options);
            }
            addInputPanel(i[j]);
            if ((i[j].getField() instanceof TextField && params[j].name.toLowerCase().endsWith("text")) || i[j].getField() instanceof ScrollPane) {
                i[j].getCell(i[j].getField()).fillX();
            }
        }
    } else {
        i = new InputPanel[0];
    }
}
Also used : Action(com.bladecoder.engine.actions.Action) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Param(com.bladecoder.engine.actions.Param) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField)

Aggregations

Param (com.bladecoder.engine.actions.Param)2 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 Action (com.bladecoder.engine.actions.Action)1 ActionProperty (com.bladecoder.engine.actions.ActionProperty)1 ActionPropertyDescription (com.bladecoder.engine.actions.ActionPropertyDescription)1 Type (com.bladecoder.engine.actions.Param.Type)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1