Fix undo/redo for some commands
This commit is contained in:
@@ -68,7 +68,7 @@ public class BootstrapCommand extends SimpleCommand {
|
||||
facade.registerCommand(MsgAPI.ACTION_REPLACE_SPRITE_ANIMATION_DATA, ReplaceSpriteAnimationCommand.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_REPLACE_SPINE_ANIMATION_DATA, ReplaceSpineCommand.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_ADD_TO_LIBRARY, AddToLibraryCommand.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_ADD_TO_LIBRARY_ACTION, AddToLibraryAction.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_ADD_TO_LIBRARY_ACTION, AddToLibraryActionCommand.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_CHANGE_LIBRARY_ACTION, ChangeLibraryActionCommand.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_CONVERT_TO_BUTTON, ConvertToButtonCommand.class);
|
||||
facade.registerCommand(MsgAPI.ACTION_GROUP_ITEMS, ConvertToCompositeCommand.class);
|
||||
|
||||
+8
-4
@@ -1,6 +1,7 @@
|
||||
package games.rednblack.editor.controller.commands;
|
||||
|
||||
import com.artemis.Component;
|
||||
import games.rednblack.editor.utils.runtime.EntityUtils;
|
||||
import games.rednblack.editor.view.stage.Sandbox;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.puremvc.Facade;
|
||||
@@ -11,14 +12,14 @@ import games.rednblack.puremvc.Facade;
|
||||
public class AddComponentToItemCommand extends EntityModifyRevertibleCommand {
|
||||
|
||||
private static final String CLASS_NAME = "games.rednblack.editor.controller.commands.AddComponentToItemCommand";
|
||||
public static final String DONE = CLASS_NAME + "DONE";
|
||||
public static final String DONE = CLASS_NAME + ".DONE";
|
||||
|
||||
private int entity;
|
||||
private String entityId;
|
||||
private Class<? extends Component> component;
|
||||
|
||||
private void collectData() {
|
||||
Object[] payload = getNotification().getBody();
|
||||
entity = (int) payload[0];
|
||||
entityId = (String) payload[0];
|
||||
component = (Class<? extends Component>) payload[1];
|
||||
}
|
||||
|
||||
@@ -26,6 +27,7 @@ public class AddComponentToItemCommand extends EntityModifyRevertibleCommand {
|
||||
public void doAction() {
|
||||
collectData();
|
||||
|
||||
int entity = EntityUtils.getByUniqueId(entityId);
|
||||
Component newComponent = Sandbox.getInstance().getEngine().edit(entity).create(component);
|
||||
sandbox.getEngine().inject(newComponent);
|
||||
|
||||
@@ -35,6 +37,8 @@ public class AddComponentToItemCommand extends EntityModifyRevertibleCommand {
|
||||
|
||||
@Override
|
||||
public void undoAction() {
|
||||
int entity = EntityUtils.getByUniqueId(entityId);
|
||||
|
||||
Sandbox.getInstance().getEngine().edit(entity).remove(component);
|
||||
Sandbox.getInstance().getEngine().process();
|
||||
|
||||
@@ -44,7 +48,7 @@ public class AddComponentToItemCommand extends EntityModifyRevertibleCommand {
|
||||
|
||||
public static Object[] payload(int entity, Class<? extends Component> component) {
|
||||
Object[] payload = new Object[2];
|
||||
payload[0] = entity;
|
||||
payload[0] = EntityUtils.getEntityId(entity);
|
||||
payload[1] = component;
|
||||
return payload;
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,9 +4,9 @@ import games.rednblack.editor.renderer.data.GraphVO;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.puremvc.Facade;
|
||||
|
||||
public class AddToLibraryAction extends NonRevertibleCommand {
|
||||
public class AddToLibraryActionCommand extends NonRevertibleCommand {
|
||||
|
||||
public AddToLibraryAction() {
|
||||
public AddToLibraryActionCommand() {
|
||||
setShowConfirmDialog(false);
|
||||
}
|
||||
|
||||
+19
-11
@@ -3,41 +3,49 @@ package games.rednblack.editor.controller.commands;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import games.rednblack.editor.renderer.components.DimensionsComponent;
|
||||
import games.rednblack.editor.renderer.components.TransformComponent;
|
||||
import games.rednblack.editor.utils.runtime.EntityUtils;
|
||||
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
|
||||
import games.rednblack.h2d.common.command.TransformCommandBuilder;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.puremvc.Facade;
|
||||
|
||||
public class CenterOriginPointCommand extends EntityModifyRevertibleCommand {
|
||||
|
||||
private int entity;
|
||||
private String entityId;
|
||||
private final Vector2 backupOrigin = new Vector2();
|
||||
|
||||
@Override
|
||||
public void doAction() {
|
||||
entity = notification.getBody();
|
||||
if (entityId == null) entityId = EntityUtils.getEntityId((int) notification.getBody());
|
||||
int entity = EntityUtils.getByUniqueId(entityId);
|
||||
|
||||
TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class);
|
||||
backupOrigin.set(transformComponent.originX, transformComponent.originY);
|
||||
|
||||
DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class);
|
||||
|
||||
TransformCommandBuilder commandBuilder = new TransformCommandBuilder();
|
||||
commandBuilder.begin(entity, sandbox.getEngine());
|
||||
float originX = dimensionsComponent.width * 0.5f;
|
||||
float originY = dimensionsComponent.height * 0.5f;
|
||||
if (dimensionsComponent.polygon != null) {
|
||||
originX = dimensionsComponent.polygon.getBoundingRectangle().width * 0.5f;
|
||||
originY = dimensionsComponent.polygon.getBoundingRectangle().height * 0.5f;
|
||||
}
|
||||
commandBuilder.setOrigin(originX, originY);
|
||||
commandBuilder.execute(Facade.getInstance());
|
||||
transformComponent.originX = originX;
|
||||
transformComponent.originY = originY;
|
||||
|
||||
EntityUtils.refreshComponents(entity);
|
||||
Facade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoAction() {
|
||||
TransformCommandBuilder commandBuilder = new TransformCommandBuilder();
|
||||
commandBuilder.begin(entity, sandbox.getEngine());
|
||||
commandBuilder.setOrigin(backupOrigin.x, backupOrigin.y);
|
||||
commandBuilder.execute(Facade.getInstance());
|
||||
int entity = EntityUtils.getByUniqueId(entityId);
|
||||
|
||||
TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class);
|
||||
|
||||
transformComponent.originX = backupOrigin.x;
|
||||
transformComponent.originY = backupOrigin.y;
|
||||
|
||||
EntityUtils.refreshComponents(entity);
|
||||
Facade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -17,12 +17,14 @@ public class UpdatePolygonDataCommand extends EntityModifyRevertibleCommand {
|
||||
@Override
|
||||
public void doAction() {
|
||||
Object[] payload = notification.getBody();
|
||||
int entity = (int) payload[0];
|
||||
if (entityId == null)
|
||||
entityId = EntityUtils.getEntityId((int) payload[0]);
|
||||
int entity = EntityUtils.getByUniqueId(entityId);
|
||||
boolean openPath = (boolean) payload[1];
|
||||
|
||||
PolygonShapeComponent polygonShapeComponent = SandboxComponentRetriever.get(entity, PolygonShapeComponent.class);
|
||||
|
||||
entityId = EntityUtils.getEntityId(entity);
|
||||
|
||||
openPathBackup = polygonShapeComponent.openEnded;
|
||||
|
||||
polygonShapeComponent.openEnded = openPath;
|
||||
|
||||
+2
-1
@@ -20,7 +20,8 @@ public class UpdatePolygonVerticesCommand extends EntityModifyRevertibleCommand
|
||||
|
||||
private void collectData() {
|
||||
Object[] payload = getNotification().getBody();
|
||||
entityId = EntityUtils.getEntityId((int) payload[0]);
|
||||
if (entityId == null)
|
||||
entityId = EntityUtils.getEntityId((int) payload[0]);
|
||||
polygonizedDataFrom = (Vector2[][]) payload[1];
|
||||
dataFrom = (Array<Vector2>) payload[2];
|
||||
polygonizedDataTo = (Vector2[][]) payload[3];
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package games.rednblack.editor.controller.commands.resource;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.kotcrab.vis.ui.util.dialog.Dialogs;
|
||||
import com.kotcrab.vis.ui.util.dialog.InputDialogListener;
|
||||
import games.rednblack.editor.controller.commands.AddToLibraryAction;
|
||||
import games.rednblack.editor.controller.commands.AddToLibraryActionCommand;
|
||||
import games.rednblack.editor.controller.commands.NonRevertibleCommand;
|
||||
import games.rednblack.editor.proxy.ProjectManager;
|
||||
import games.rednblack.editor.renderer.data.GraphVO;
|
||||
@@ -40,7 +40,7 @@ public class DuplicateLibraryAction extends NonRevertibleCommand {
|
||||
Json json = HyperJson.getJson();
|
||||
GraphVO duplicated = json.fromJson(GraphVO.class, json.toJson(actionToDuplicate));
|
||||
|
||||
Object[] payload = AddToLibraryAction.getPayload(input, duplicated);
|
||||
Object[] payload = AddToLibraryActionCommand.getPayload(input, duplicated);
|
||||
Facade.getInstance().sendNotification(MsgAPI.ACTION_ADD_TO_LIBRARY_ACTION, payload);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.kotcrab.vis.ui.VisUI;
|
||||
import com.kotcrab.vis.ui.widget.MenuItem;
|
||||
import com.kotcrab.vis.ui.widget.PopupMenu;
|
||||
import com.kotcrab.vis.ui.widget.VisTextButton;
|
||||
import games.rednblack.editor.controller.commands.AddToLibraryAction;
|
||||
import games.rednblack.editor.controller.commands.AddToLibraryActionCommand;
|
||||
import games.rednblack.editor.graph.*;
|
||||
import games.rednblack.editor.graph.actions.ActionFieldType;
|
||||
import games.rednblack.editor.graph.actions.config.*;
|
||||
@@ -143,7 +143,7 @@ public class NodeEditorDialog extends H2DDialog implements Graph<GraphBox<Action
|
||||
saveButton.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Object[] payload = AddToLibraryAction.getPayload(actionName, graphContainer.serializeGraph());
|
||||
Object[] payload = AddToLibraryActionCommand.getPayload(actionName, graphContainer.serializeGraph());
|
||||
Facade.getInstance().sendNotification(MsgAPI.ACTION_ADD_TO_LIBRARY_ACTION, payload);
|
||||
close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user