Search in sources :

Example 1 with EndAction

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

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

the class ActionList method delete.

@Override
protected void delete() {
    if (list.getSelection().size() == 0)
        return;
    multiClipboard.clear();
    int pos = list.getSelectedIndex();
    for (Action e : getSortedSelection()) {
        if (e instanceof EndAction)
            continue;
        int pos2 = list.getItems().indexOf(e, true);
        list.getItems().removeValue(e, true);
        int idx = parent.getActions().indexOf(e);
        parent.getActions().remove(e);
        multiClipboard.add(e);
        // TRANSLATIONS
        if (scope.equals(ScopePanel.WORLD_SCOPE))
            Ctx.project.getI18N().putTranslationsInElement(e, true);
        else
            Ctx.project.getI18N().putTranslationsInElement(e, false);
        // UNDO
        Ctx.project.getUndoStack().add(new UndoDeleteAction(parent, e, idx));
        if (isControlAction(e))
            deleteControlAction(pos2, (AbstractControlAction) e);
    }
    if (list.getItems().size == 0) {
        list.getSelection().clear();
    } else if (pos >= list.getItems().size) {
        list.getSelection().choose(list.getItems().get(list.getItems().size - 1));
    } else {
        list.getSelection().choose(list.getItems().get(pos));
    }
    toolbar.disablePaste(false);
    Ctx.project.setModified();
}
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) UndoDeleteAction(com.bladecoder.engineeditor.undo.UndoDeleteAction) EndAction(com.bladecoder.engine.actions.EndAction)

Example 3 with EndAction

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

the class ActionList method insertEndAction.

private void insertEndAction(int pos, String id) {
    final Action e = new EndAction();
    try {
        ActionUtils.setParam(e, CONTROL_ACTION_ID_ATTR, id);
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
        EditorLogger.error(e1.getMessage());
    }
    list.getItems().insert(pos, e);
    parent.getActions().add(pos, e);
}
Also used : 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) EndAction(com.bladecoder.engine.actions.EndAction)

Example 4 with EndAction

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

the class ActionList method copy.

@Override
protected void copy() {
    if (parent == null || list.getSelection().size() == 0)
        return;
    multiClipboard.clear();
    for (Action e : getSortedSelection()) {
        if (e == null || e instanceof EndAction)
            return;
        Action cloned = (Action) ElementUtils.cloneElement(e);
        multiClipboard.add(cloned);
        toolbar.disablePaste(false);
        // TRANSLATIONS
        if (scope.equals(ScopePanel.WORLD_SCOPE))
            Ctx.project.getI18N().putTranslationsInElement(cloned, true);
        else
            Ctx.project.getI18N().putTranslationsInElement(cloned, false);
    }
}
Also used : 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) EndAction(com.bladecoder.engine.actions.EndAction)

Aggregations

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