use of com.bladecoder.engine.actions.Action 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.Action 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.Action in project bladecoder-adventure-engine by bladecoder.
the class ActionList method down.
private void down() {
if (parent == null || list.getSelection().size() == 0)
return;
Array<Action> sel = new Array<Action>();
Array<Action> sortedSelection = getSortedSelection();
for (int i = sortedSelection.size - 1; i >= 0; i--) {
int pos = list.getItems().indexOf(sortedSelection.get(i), true);
Array<Action> items = list.getItems();
if (pos == -1 || pos == items.size - 1)
return;
Action e = items.get(pos);
Action e2 = items.get(pos + 1);
sel.add(e);
if (isControlAction(e) && isControlAction(e2)) {
continue;
}
parent.getActions().set(pos + 1, e);
parent.getActions().set(pos, e2);
items.set(pos + 1, e);
items.set(pos, e2);
}
list.getSelection().clear();
list.getSelection().addAll(sel);
upBtn.setDisabled(list.getSelectedIndex() == 0);
downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);
Ctx.project.setModified();
}
use of com.bladecoder.engine.actions.Action 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.Action 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;
}
Aggregations