diff --git a/CHANGES b/CHANGES index 4416f10e..7f2cc919 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ - [BREAK CHANGE] Update Spine Support to `4.0.18.1` - Update libGDX to 1.10.1-SNAPSHOT - Support mono space fonts +- Support Circle shapes for physics bodies = Editor = - Update LWJGL to 3.3.0-SNAPSHOT diff --git a/hyperlap2d-common-api b/hyperlap2d-common-api index f09f5349..df1e9397 160000 --- a/hyperlap2d-common-api +++ b/hyperlap2d-common-api @@ -1 +1 @@ -Subproject commit f09f53498ab11a36acd62cf63bdf43781b3da7b7 +Subproject commit df1e939700f56406ced63fd9e31f6453e2741350 diff --git a/hyperlap2d-runtime-libgdx b/hyperlap2d-runtime-libgdx index f15c8751..2eb93b25 160000 --- a/hyperlap2d-runtime-libgdx +++ b/hyperlap2d-runtime-libgdx @@ -1 +1 @@ -Subproject commit f15c8751a50e5911bc22b269742cdbe0f156624f +Subproject commit 2eb93b25233a833ad5e51294ca4de60950125e75 diff --git a/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java b/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java index 7d296967..7f8fdf02 100644 --- a/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java +++ b/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java @@ -91,6 +91,7 @@ public class BootstrapCommand extends SimpleCommand { facade.registerCommand(MsgAPI.ACTION_UPDATE_PARTICLE_DATA, UpdateParticleDataCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_TALOS_DATA, UpdateTalosDataCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_BODY_LIGHT_DATA, UpdateLightBodyDataCommand::new); + facade.registerCommand(MsgAPI.ACTION_UPDATE_CIRCLE_SHAPE, UpdateCircleShapeCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_PHYSICS_BODY_DATA, UpdatePhysicsDataCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_SENSOR_DATA, UpdateSensorDataCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_SHADER_DATA, UpdateShaderDataCommand::new); diff --git a/src/main/java/games/rednblack/editor/controller/commands/CreatePrimitiveCommand.java b/src/main/java/games/rednblack/editor/controller/commands/CreatePrimitiveCommand.java index 3a06f155..d118b02b 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/CreatePrimitiveCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/CreatePrimitiveCommand.java @@ -20,7 +20,7 @@ package games.rednblack.editor.controller.commands; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.factory.ItemFactory; -import games.rednblack.editor.renderer.data.ShapeVO; +import games.rednblack.editor.renderer.data.PolygonShapeVO; /** * Created by azakhary on 10/21/2015. @@ -30,7 +30,7 @@ public class CreatePrimitiveCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Vector2 position = new Vector2(0, 0); - ShapeVO shape = ShapeVO.createRect(100f / sandbox.getPixelPerWU(), 100f / sandbox.getPixelPerWU()); + PolygonShapeVO shape = PolygonShapeVO.createRect(100f / sandbox.getPixelPerWU(), 100f / sandbox.getPixelPerWU()); ItemFactory.get().createPrimitive(position, shape); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCircleShapeCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCircleShapeCommand.java new file mode 100644 index 00000000..dcce5aa6 --- /dev/null +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCircleShapeCommand.java @@ -0,0 +1,54 @@ +package games.rednblack.editor.controller.commands.component; + +import games.rednblack.editor.HyperLap2DFacade; +import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; +import games.rednblack.editor.renderer.components.CircleShapeComponent; +import games.rednblack.editor.renderer.components.physics.PhysicsBodyComponent; +import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; +import games.rednblack.h2d.common.MsgAPI; + +public class UpdateCircleShapeCommand extends EntityModifyRevertibleCommand { + private int entityId; + private float radiusBackup; + + @Override + public void doAction() { + Object[] payload = getNotification().getBody(); + int entity = (int) payload[0]; + float radius = (float) payload[1]; + entityId = EntityUtils.getEntityId(entity); + + CircleShapeComponent circleShapeComponent = SandboxComponentRetriever.get(entity, CircleShapeComponent.class); + + radiusBackup = circleShapeComponent.radius; + + circleShapeComponent.radius = radius; + + PhysicsBodyComponent physicsBodyComponent = SandboxComponentRetriever.get(entity, PhysicsBodyComponent.class); + physicsBodyComponent.scheduleRefresh(); + + HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); + } + + @Override + public void undoAction() { + int entity = EntityUtils.getByUniqueId(entityId); + + CircleShapeComponent circleShapeComponent = SandboxComponentRetriever.get(entity, CircleShapeComponent.class); + circleShapeComponent.radius = radiusBackup; + + PhysicsBodyComponent physicsBodyComponent = SandboxComponentRetriever.get(entity, PhysicsBodyComponent.class); + physicsBodyComponent.scheduleRefresh(); + + HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); + } + + public static Object payload(int entity, float radius) { + Object[] payload = new Object[2]; + payload[0] = entity; + payload[1] = radius; + + return payload; + } +} diff --git a/src/main/java/games/rednblack/editor/factory/ItemFactory.java b/src/main/java/games/rednblack/editor/factory/ItemFactory.java index e3a49d5e..74f6969e 100644 --- a/src/main/java/games/rednblack/editor/factory/ItemFactory.java +++ b/src/main/java/games/rednblack/editor/factory/ItemFactory.java @@ -135,7 +135,7 @@ public class ItemFactory implements IFactory { return true; } - public boolean createPrimitive(Vector2 position, ShapeVO shape) { + public boolean createPrimitive(Vector2 position, PolygonShapeVO shape) { ColorPrimitiveVO vo = new ColorPrimitiveVO(); vo.shape = shape.clone(); vo.originX = vo.shape.polygons[0][2].x / 2; diff --git a/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java b/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java index d41000d8..8904fb93 100644 --- a/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java @@ -23,6 +23,7 @@ import com.badlogic.gdx.utils.reflect.ReflectionException; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.AddComponentToItemCommand; import games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand; +import games.rednblack.editor.renderer.components.CircleShapeComponent; import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.components.ShaderComponent; import games.rednblack.editor.renderer.components.light.LightBodyComponent; @@ -192,6 +193,7 @@ public class UIMultiPropertyBoxMediator extends PanelMediator { + private static final String TAG = UICircleShapePropertiesMediator.class.getCanonicalName(); + public static final String NAME = TAG; + + public UICircleShapePropertiesMediator() { + super(NAME, new UICircleShapeProperties()); + } + + @Override + public String[] listNotificationInterests() { + String[] defaultNotifications = super.listNotificationInterests(); + String[] notificationInterests = new String[]{ + UICircleShapeProperties.CLOSE_CLICKED, + }; + + return ArrayUtils.addAll(defaultNotifications, notificationInterests); + } + + @Override + public void handleNotification(INotification notification) { + super.handleNotification(notification); + + switch (notification.getName()) { + case UICircleShapeProperties.CLOSE_CLICKED: + HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand.payload(observableReference, CircleShapeComponent.class)); + break; + } + } + + @Override + protected void translateObservableDataToView(int item) { + CircleShapeComponent component = SandboxComponentRetriever.get(item, CircleShapeComponent.class); + viewComponent.setRadius(component.radius); + } + + @Override + protected void translateViewToItemData() { + CircleShapeComponent component = SandboxComponentRetriever.get(observableReference, CircleShapeComponent.class); + + float radius = Float.parseFloat(viewComponent.getRadius()); + if (component.radius != radius) { + Object payload = UpdateCircleShapeCommand.payload(observableReference, radius); + facade.sendNotification(MsgAPI.ACTION_UPDATE_CIRCLE_SHAPE, payload); + } + } +}