From 21ef61ffcd03e3a601485ac93009dc8b42cf6583 Mon Sep 17 00:00:00 2001 From: Jan-Thierry Wegener Date: Sun, 30 May 2021 21:48:14 +0200 Subject: [PATCH] Added sensor data that can be used to add to a physical body. They can be added to the bottom, left, right and top to check which side has contact with another box2d object. --- .../editor/controller/BootstrapCommand.java | 77 ++++++++++++++-- .../component/UpdateSensorDataCommand.java | 70 +++++++++++++++ .../ui/box/UIMultiPropertyBoxMediator.java | 46 +++++++--- .../panels/UIBasicItemPropertiesMediator.java | 34 +++++--- .../properties/panels/UISensorProperties.java | 87 +++++++++++++++++++ .../panels/UISensorPropertiesMediator.java | 85 ++++++++++++++++++ 6 files changed, 369 insertions(+), 30 deletions(-) create mode 100644 src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java create mode 100644 src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorProperties.java create mode 100644 src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java diff --git a/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java b/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java index 391156d1..2e654a29 100644 --- a/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java +++ b/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java @@ -18,21 +18,83 @@ package games.rednblack.editor.controller; -import games.rednblack.editor.controller.commands.component.*; -import games.rednblack.editor.splash.SplashScreenAdapter; -import games.rednblack.h2d.common.MsgAPI; -import games.rednblack.editor.HyperLap2DFacade; -import games.rednblack.editor.controller.commands.*; -import games.rednblack.editor.controller.commands.resource.*; import org.puremvc.java.interfaces.INotification; import org.puremvc.java.patterns.command.SimpleCommand; +import games.rednblack.editor.HyperLap2DFacade; +import games.rednblack.editor.controller.commands.AddComponentToItemCommand; +import games.rednblack.editor.controller.commands.AddSelectionCommand; +import games.rednblack.editor.controller.commands.AddToLibraryAction; +import games.rednblack.editor.controller.commands.AddToLibraryCommand; +import games.rednblack.editor.controller.commands.ChangeOriginPointPosition; +import games.rednblack.editor.controller.commands.ChangePolygonVertexPositionCommand; +import games.rednblack.editor.controller.commands.ChangeRulerPositionCommand; +import games.rednblack.editor.controller.commands.CompositeCameraChangeCommand; +import games.rednblack.editor.controller.commands.ConvertToButtonCommand; +import games.rednblack.editor.controller.commands.ConvertToCompositeCommand; +import games.rednblack.editor.controller.commands.CopyItemsCommand; +import games.rednblack.editor.controller.commands.CreateItemCommand; +import games.rednblack.editor.controller.commands.CreatePrimitiveCommand; +import games.rednblack.editor.controller.commands.CreateStickyNoteCommand; +import games.rednblack.editor.controller.commands.CustomVariableModifyCommand; +import games.rednblack.editor.controller.commands.CutItemsCommand; +import games.rednblack.editor.controller.commands.DeleteItemsCommand; +import games.rednblack.editor.controller.commands.DeleteLayerCommand; +import games.rednblack.editor.controller.commands.DeletePolygonVertexCommand; +import games.rednblack.editor.controller.commands.ExportProjectCommand; +import games.rednblack.editor.controller.commands.ItemChildrenTransformCommand; +import games.rednblack.editor.controller.commands.ItemTransformCommand; +import games.rednblack.editor.controller.commands.ItemsMoveCommand; +import games.rednblack.editor.controller.commands.LayerSwapCommand; +import games.rednblack.editor.controller.commands.ModifyStickyNoteCommand; +import games.rednblack.editor.controller.commands.NewLayerCommand; +import games.rednblack.editor.controller.commands.PasteItemsCommand; +import games.rednblack.editor.controller.commands.PluginItemCommand; +import games.rednblack.editor.controller.commands.ReleaseSelectionCommand; +import games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand; +import games.rednblack.editor.controller.commands.RemoveStickyNoteCommand; +import games.rednblack.editor.controller.commands.RenameLayerCommand; +import games.rednblack.editor.controller.commands.SaveExportPathCommand; +import games.rednblack.editor.controller.commands.SetSelectionCommand; +import games.rednblack.editor.controller.commands.ShowNotificationCommand; +import games.rednblack.editor.controller.commands.UpdateEntityComponentsCommand; +import games.rednblack.editor.controller.commands.UpdateSceneDataCommand; +import games.rednblack.editor.controller.commands.component.ReplaceRegionCommand; +import games.rednblack.editor.controller.commands.component.ReplaceSpineCommand; +import games.rednblack.editor.controller.commands.component.ReplaceSpriteAnimationCommand; +import games.rednblack.editor.controller.commands.component.UpdateCompositeDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateImageItemDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateLabelDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateLightBodyDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateLightDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateParticleDataCommand; +import games.rednblack.editor.controller.commands.component.UpdatePhysicsDataCommand; +import games.rednblack.editor.controller.commands.component.UpdatePolygonDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateSensorDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateShaderDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateSpineDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateSpriteAnimationDataCommand; +import games.rednblack.editor.controller.commands.component.UpdateTalosDataCommand; +import games.rednblack.editor.controller.commands.resource.DeleteImageResource; +import games.rednblack.editor.controller.commands.resource.DeleteLibraryAction; +import games.rednblack.editor.controller.commands.resource.DeleteLibraryItem; +import games.rednblack.editor.controller.commands.resource.DeleteParticleEffect; +import games.rednblack.editor.controller.commands.resource.DeleteSpineAnimation; +import games.rednblack.editor.controller.commands.resource.DeleteSpriteAnimation; +import games.rednblack.editor.controller.commands.resource.DeleteTalosVFX; +import games.rednblack.editor.controller.commands.resource.DuplicateLibraryAction; +import games.rednblack.editor.controller.commands.resource.ExportActionCommand; +import games.rednblack.editor.controller.commands.resource.ExportLibraryItemCommand; +import games.rednblack.editor.splash.SplashScreenAdapter; +import games.rednblack.h2d.common.MsgAPI; + /** * Created by azakhary on 4/28/2015. */ public class BootstrapCommand extends SimpleCommand { - public void execute(INotification notification) { + @Override + public void execute(INotification notification) { super.execute(notification); facade = HyperLap2DFacade.getInstance(); facade.sendNotification(SplashScreenAdapter.UPDATE_SPLASH, "Loading Commands..."); @@ -90,6 +152,7 @@ public class BootstrapCommand extends SimpleCommand { facade.registerCommand(MsgAPI.ACTION_UPDATE_TALOS_DATA, UpdateTalosDataCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_BODY_LIGHT_DATA, UpdateLightBodyDataCommand::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); facade.registerCommand(MsgAPI.ACTION_UPDATE_IMAGE_ITEM_DATA, UpdateImageItemDataCommand::new); facade.registerCommand(MsgAPI.ACTION_UPDATE_SPRITE_ANIMATION_DATA, UpdateSpriteAnimationDataCommand::new); diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java new file mode 100644 index 00000000..92a27954 --- /dev/null +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java @@ -0,0 +1,70 @@ +package games.rednblack.editor.controller.commands.component; + +import com.badlogic.ashley.core.Entity; + +import games.rednblack.editor.HyperLap2DFacade; +import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; +import games.rednblack.editor.renderer.components.physics.SensorComponent; +import games.rednblack.editor.renderer.data.SensorDataVO; +import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.h2d.common.MsgAPI; + +/** + * Update command for the sensor data. + * + * @author Jan-Thierry Wegener + */ +public class UpdateSensorDataCommand extends EntityModifyRevertibleCommand { + + private Integer entityId; + private SensorDataVO backup; + + public UpdateSensorDataCommand() { + } + + @Override + public void doAction() { + Object[] payload = getNotification().getBody(); + Entity entity = (Entity) payload[0]; + SensorDataVO vo = (SensorDataVO) payload[1]; + entityId = EntityUtils.getEntityId(entity); + + SensorComponent sensorComponent = ComponentRetriever.get(entity, SensorComponent.class); + + backup = new SensorDataVO(); + backup.loadFromComponent(sensorComponent); + + sensorComponent.bottom = vo.bottom; + sensorComponent.left = vo.left; + sensorComponent.right = vo.right; + sensorComponent.top = vo.top; + + sensorComponent.scheduleRefresh(); + + HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); + } + + @Override + public void undoAction() { + Entity entity = EntityUtils.getByUniqueId(entityId); + SensorComponent sensorComponent = ComponentRetriever.get(entity, SensorComponent.class); + + sensorComponent.bottom = backup.bottom; + sensorComponent.left = backup.left; + sensorComponent.right = backup.right; + sensorComponent.top = backup.top; + + sensorComponent.scheduleRefresh(); + + HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); + } + + public static Object payload(Entity entity, SensorDataVO vo) { + Object[] payload = new Object[2]; + payload[0] = entity; + payload[1] = vo; + + return payload; + } +} 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 2d8303c8..4f259e16 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 @@ -18,18 +18,27 @@ package games.rednblack.editor.view.ui.box; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Set; +import java.util.stream.Stream; + +import org.puremvc.java.interfaces.IMediator; +import org.puremvc.java.interfaces.INotification; + import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.ReflectionException; -import games.rednblack.editor.renderer.components.label.TypingLabelComponent; -import games.rednblack.editor.renderer.components.light.LightBodyComponent; -import games.rednblack.h2d.common.MsgAPI; + 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.PolygonComponent; import games.rednblack.editor.renderer.components.ShaderComponent; +import games.rednblack.editor.renderer.components.label.TypingLabelComponent; +import games.rednblack.editor.renderer.components.light.LightBodyComponent; import games.rednblack.editor.renderer.components.physics.PhysicsBodyComponent; +import games.rednblack.editor.renderer.components.physics.SensorComponent; import games.rednblack.editor.renderer.data.SceneVO; import games.rednblack.editor.renderer.factory.EntityFactory; import games.rednblack.editor.renderer.utils.ComponentRetriever; @@ -39,14 +48,25 @@ import games.rednblack.editor.view.stage.SandboxMediator; import games.rednblack.editor.view.stage.tools.TextTool; import games.rednblack.editor.view.ui.properties.UIAbstractProperties; import games.rednblack.editor.view.ui.properties.UIAbstractPropertiesMediator; -import games.rednblack.editor.view.ui.properties.panels.*; -import org.puremvc.java.interfaces.IMediator; -import org.puremvc.java.interfaces.INotification; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Set; -import java.util.stream.Stream; +import games.rednblack.editor.view.ui.properties.panels.UIBasicItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UICompositeItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIImageItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UILabelItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UILightBodyPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UILightItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIMultipleSelectPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIParticlePropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIPhysicsPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIPolygonComponentPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIScenePropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UISensorPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UIShaderPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UISpineAnimationItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UISpriteAnimationItemPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UITalosPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UITextToolPropertiesMediator; +import games.rednblack.editor.view.ui.properties.panels.UITypingLabelPropertiesMediator; +import games.rednblack.h2d.common.MsgAPI; /** * Created by azakhary on 4/15/2015. @@ -189,6 +209,7 @@ public class UIMultiPropertyBoxMediator extends PanelMediator { + + private static final String TAG = UISensorPropertiesMediator.class.getCanonicalName(); + public static final String NAME = TAG; + + private SensorComponent sensorComponent; + + public UISensorPropertiesMediator() { + super(NAME, new UISensorProperties()); + } + + @Override + public String[] listNotificationInterests() { + String[] defaultNotifications = super.listNotificationInterests(); + String[] notificationInterests = new String[]{ + UISensorProperties.CLOSE_CLICKED + }; + + return ArrayUtils.addAll(defaultNotifications, notificationInterests); + } + + @Override + public void handleNotification(INotification notification) { + super.handleNotification(notification); + + switch (notification.getName()) { + case UISensorProperties.CLOSE_CLICKED: + HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand.payload(observableReference, SensorComponent.class)); + break; + } + } + + @Override + protected void translateObservableDataToView(Entity item) { + sensorComponent = item.getComponent(SensorComponent.class); + + viewComponent.getSensorBottomBox().setChecked(sensorComponent.bottom); + viewComponent.getSensorLeftBox().setChecked(sensorComponent.left); + viewComponent.getSensorRightBox().setChecked(sensorComponent.right); + viewComponent.getSensorTopBox().setChecked(sensorComponent.top); + } + + @Override + protected void translateViewToItemData() { + sensorComponent = observableReference.getComponent(SensorComponent.class); + + SensorDataVO oldPayloadVo = new SensorDataVO(); + oldPayloadVo.loadFromComponent(sensorComponent); + + SensorDataVO payloadVo = new SensorDataVO(); + + payloadVo.bottom = viewComponent.getSensorBottomBox().isChecked(); + payloadVo.left = viewComponent.getSensorLeftBox().isChecked(); + payloadVo.right = viewComponent.getSensorRightBox().isChecked(); + payloadVo.top = viewComponent.getSensorTopBox().isChecked(); + + if (!oldPayloadVo.equals(payloadVo)) { + Object payload = UpdateSensorDataCommand.payload(observableReference, payloadVo); + facade.sendNotification(MsgAPI.ACTION_UPDATE_SENSOR_DATA, payload); + } + } + + + +}