Center Origin Command
This commit is contained in:
+1
-1
Submodule hyperlap2d-common-api updated: afae073916...328049ce96
@@ -80,6 +80,7 @@ public class BootstrapCommand extends SimpleCommand {
|
||||
facade.registerCommand(MsgAPI.ACTION_CHANGE_POLYGON_VERTEX_POSITION, ChangePolygonVertexPositionCommand::new);
|
||||
facade.registerCommand(MsgAPI.ACTION_DELETE_POLYGON_VERTEX, DeletePolygonVertexCommand::new);
|
||||
facade.registerCommand(MsgAPI.ACTION_CHANGE_ORIGIN_POSITION, ChangeOriginPointPosition::new);
|
||||
facade.registerCommand(MsgAPI.ACTION_CENTER_ORIGIN_POSITION, CenterOriginPointCommand::new);
|
||||
|
||||
// DATA MODIFY by components
|
||||
facade.registerCommand(MsgAPI.ACTION_UPDATE_SCENE_DATA, UpdateSceneDataCommand::new);
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package games.rednblack.editor.controller.commands;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.renderer.components.DimensionsComponent;
|
||||
import games.rednblack.editor.renderer.components.TransformComponent;
|
||||
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
|
||||
import games.rednblack.h2d.common.command.TransformCommandBuilder;
|
||||
|
||||
public class CenterOriginPointCommand extends EntityModifyRevertibleCommand {
|
||||
|
||||
private int entity;
|
||||
private final Vector2 backupOrigin = new Vector2();
|
||||
|
||||
@Override
|
||||
public void doAction() {
|
||||
entity = notification.getBody();
|
||||
|
||||
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());
|
||||
commandBuilder.setOrigin(dimensionsComponent.width / 2f, dimensionsComponent.height / 2f);
|
||||
commandBuilder.execute(HyperLap2DFacade.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoAction() {
|
||||
TransformCommandBuilder commandBuilder = new TransformCommandBuilder();
|
||||
commandBuilder.begin(entity, sandbox.getEngine());
|
||||
commandBuilder.setOrigin(backupOrigin.x, backupOrigin.y);
|
||||
commandBuilder.execute(HyperLap2DFacade.getInstance());
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@ public class UIDropDownMenu extends H2DPopupMenu {
|
||||
actionNames.put(MsgAPI.ACTION_DELETE_POLYGON_VERTEX, "Delete Vertex");
|
||||
|
||||
actionNames.put(MsgAPI.ACTION_CHANGE_ORIGIN_POSITION, "Change Origin Position");
|
||||
actionNames.put(MsgAPI.ACTION_CENTER_ORIGIN_POSITION, "Center Origin");
|
||||
|
||||
actionNames.put(MsgAPI.ACTION_DUPLICATE_LIBRARY_ACTION, "Duplicate");
|
||||
actionNames.put(MsgAPI.ACTION_DELETE_LIBRARY_ACTION, "Delete");
|
||||
|
||||
@@ -120,6 +120,7 @@ public class UIDropDownMenuMediator extends Mediator<UIDropDownMenu> {
|
||||
|
||||
actionSets.put(ORIGIN_POINT_ACTION_SET, new Array<>());
|
||||
actionSets.get(ORIGIN_POINT_ACTION_SET).add(MsgAPI.ACTION_CHANGE_ORIGIN_POSITION);
|
||||
actionSets.get(ORIGIN_POINT_ACTION_SET).add(MsgAPI.ACTION_CENTER_ORIGIN_POSITION);
|
||||
|
||||
facade = HyperLap2DFacade.getInstance();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user