Search in sources :

Example 1 with DisableActionAction

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

the class ActionList method toggleEnabled.

private void toggleEnabled() {
    if (list.getSelection().size() <= 0)
        return;
    Array<Action> sel = new Array<Action>();
    for (Action a : list.getSelection().toArray()) {
        // CONTROL ACTIONS CAN'T BE DISABLED
        if (a == null || isControlAction(a))
            continue;
        Array<Action> items = list.getItems();
        int pos = items.indexOf(a, true);
        if (a instanceof DisableActionAction) {
            Action a2 = ((DisableActionAction) a).getAction();
            parent.getActions().set(pos, a2);
            items.set(pos, a2);
            sel.add(a2);
        } else {
            DisableActionAction a2 = new DisableActionAction();
            a2.setAction(a);
            parent.getActions().set(pos, a2);
            items.set(pos, a2);
            sel.add(a2);
        }
    }
    Ctx.project.setModified();
    list.getSelection().clear();
    list.getSelection().addAll(sel);
}
Also used : Array(com.badlogic.gdx.utils.Array) UndoDeleteAction(com.bladecoder.engineeditor.undo.UndoDeleteAction) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction) CommentAction(com.bladecoder.engine.actions.CommentAction) EndAction(com.bladecoder.engine.actions.EndAction) Action(com.bladecoder.engine.actions.Action) AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction)

Example 2 with DisableActionAction

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

the class ActionList method edit.

@Override
protected void edit() {
    Action e = list.getSelected();
    if (e == null || e instanceof EndAction || e instanceof DisableActionAction)
        return;
    editedElement = (Action) ElementUtils.cloneElement(e);
    EditModelDialog<Verb, Action> dialog = getEditElementDialogInstance(e);
    dialog.show(getStage());
    dialog.setListener(new ChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Action e = ((EditModelDialog<Verb, Action>) actor).getElement();
            int pos = list.getSelectedIndex();
            list.getItems().set(pos, e);
            parent.getActions().set(pos, e);
            Ctx.project.setModified();
            if (isControlAction(editedElement)) {
                if (!editedElement.getClass().getName().equals(e.getClass().getName())) {
                    deleteControlAction(pos, (AbstractControlAction) editedElement);
                    if (isControlAction(e)) {
                        insertEndAction(pos + 1, getOrCreateControlActionId((AbstractControlAction) e));
                        if (e instanceof AbstractIfAction)
                            insertEndAction(pos + 2, getOrCreateControlActionId((AbstractControlAction) e));
                    }
                } else {
                    // insert previous caId
                    try {
                        ActionUtils.setParam(e, CONTROL_ACTION_ID_ATTR, getOrCreateControlActionId((AbstractControlAction) editedElement));
                    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
                        EditorLogger.error(e1.getMessage());
                    }
                }
            }
        }
    });
}
Also used : AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) UndoDeleteAction(com.bladecoder.engineeditor.undo.UndoDeleteAction) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction) CommentAction(com.bladecoder.engine.actions.CommentAction) EndAction(com.bladecoder.engine.actions.EndAction) Action(com.bladecoder.engine.actions.Action) AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction) PropertyChangeEvent(java.beans.PropertyChangeEvent) EndAction(com.bladecoder.engine.actions.EndAction) Verb(com.bladecoder.engine.model.Verb) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction)

Aggregations

AbstractControlAction (com.bladecoder.engine.actions.AbstractControlAction)2 AbstractIfAction (com.bladecoder.engine.actions.AbstractIfAction)2 Action (com.bladecoder.engine.actions.Action)2 CommentAction (com.bladecoder.engine.actions.CommentAction)2 DisableActionAction (com.bladecoder.engine.actions.DisableActionAction)2 EndAction (com.bladecoder.engine.actions.EndAction)2 UndoDeleteAction (com.bladecoder.engineeditor.undo.UndoDeleteAction)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 Array (com.badlogic.gdx.utils.Array)1 Verb (com.bladecoder.engine.model.Verb)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1