use of com.bladecoder.engine.actions.AbstractControlAction 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());
}
}
}
}
});
}
use of com.bladecoder.engine.actions.AbstractControlAction 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();
}
use of com.bladecoder.engine.actions.AbstractControlAction 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();
}
});
}
use of com.bladecoder.engine.actions.AbstractControlAction in project bladecoder-adventure-engine by bladecoder.
the class ActionList method deleteFirstActionNamed.
private int deleteFirstActionNamed(int pos, String actionId) {
while (!(list.getItems().get(pos) instanceof AbstractControlAction && getOrCreateControlActionId((AbstractControlAction) list.getItems().get(pos)).equals(actionId))) pos++;
Action e2 = list.getItems().removeIndex(pos);
parent.getActions().remove(e2);
return pos;
}
use of com.bladecoder.engine.actions.AbstractControlAction 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();
}
Aggregations