Search in sources :

Example 1 with AbstractIfAction

use of com.bladecoder.engine.actions.AbstractIfAction 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)

Example 2 with AbstractIfAction

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

the class ActionList method paste.

@Override
protected void paste() {
    if (parent == null || multiClipboard.size() == 0)
        return;
    Array<Action> sel = new Array<Action>();
    for (int i = multiClipboard.size() - 1; i >= 0; i--) {
        Action newElement = (Action) ElementUtils.cloneElement(multiClipboard.get(i));
        int pos = list.getSelectedIndex() + 1;
        list.getItems().insert(pos, newElement);
        parent.getActions().add(pos, newElement);
        if (scope.equals(ScopePanel.WORLD_SCOPE))
            Ctx.project.getI18N().extractStrings(null, null, parent.getHashKey(), pos, newElement);
        else if (scope.equals(ScopePanel.SCENE_SCOPE))
            Ctx.project.getI18N().extractStrings(Ctx.project.getSelectedScene().getId(), null, parent.getHashKey(), pos, newElement);
        else
            Ctx.project.getI18N().extractStrings(Ctx.project.getSelectedScene().getId(), Ctx.project.getSelectedActor().getId(), parent.getHashKey(), pos, newElement);
        list.invalidateHierarchy();
        if (isControlAction(newElement)) {
            try {
                ActionUtils.setParam(newElement, CONTROL_ACTION_ID_ATTR, null);
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                EditorLogger.error(e.getMessage());
            }
            insertEndAction(pos + 1, getOrCreateControlActionId((AbstractControlAction) newElement));
            if (newElement instanceof AbstractIfAction)
                insertEndAction(pos + 2, getOrCreateControlActionId((AbstractControlAction) newElement));
        }
        sel.add(newElement);
    }
    list.getSelection().clear();
    list.getSelection().addAll(sel);
    Ctx.project.setModified();
}
Also used : Array(com.badlogic.gdx.utils.Array) 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) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction)

Example 3 with AbstractIfAction

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

the class ActionList method create.

@Override
protected void create() {
    EditModelDialog<Verb, Action> dialog = getEditElementDialogInstance(null);
    dialog.show(getStage());
    dialog.setListener(new ChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            int pos = list.getSelectedIndex() + 1;
            Action e = ((EditModelDialog<Verb, Action>) actor).getElement();
            list.getItems().insert(pos, e);
            parent.getActions().add(pos, e);
            list.getSelection().choose(list.getItems().get(pos));
            if (isControlAction(e)) {
                insertEndAction(pos + 1, getOrCreateControlActionId((AbstractControlAction) e));
                if (e instanceof AbstractIfAction)
                    insertEndAction(pos + 2, getOrCreateControlActionId((AbstractControlAction) e));
            }
            list.invalidateHierarchy();
        }
    });
}
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) PropertyChangeEvent(java.beans.PropertyChangeEvent) 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)3 AbstractIfAction (com.bladecoder.engine.actions.AbstractIfAction)3 Action (com.bladecoder.engine.actions.Action)3 CommentAction (com.bladecoder.engine.actions.CommentAction)3 DisableActionAction (com.bladecoder.engine.actions.DisableActionAction)3 EndAction (com.bladecoder.engine.actions.EndAction)3 UndoDeleteAction (com.bladecoder.engineeditor.undo.UndoDeleteAction)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 Verb (com.bladecoder.engine.model.Verb)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Array (com.badlogic.gdx.utils.Array)1