From f087a89081a8d67b1a42925887565062633ff014 Mon Sep 17 00:00:00 2001 From: fgnm Date: Sun, 9 Jul 2023 10:30:57 +0200 Subject: [PATCH] Sensor component custom width/height --- CHANGES | 1 + hyperlap2d-runtime-libgdx | 2 +- .../component/UpdateSensorDataCommand.java | 10 ++++ .../properties/panels/UISensorProperties.java | 59 +++++++++++++++++-- .../panels/UISensorPropertiesMediator.java | 10 ++++ 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index fe994833..b3604c0d 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ - Update libGDX to 1.12.0 - Update gradle to 7.6 - Replace PureMVC with gdx-puremvc +- Sensor component custom width/height - Bug fixing and stability improvements **Runtime** diff --git a/hyperlap2d-runtime-libgdx b/hyperlap2d-runtime-libgdx index 327be045..334a64c1 160000 --- a/hyperlap2d-runtime-libgdx +++ b/hyperlap2d-runtime-libgdx @@ -1 +1 @@ -Subproject commit 327be0455dd2f8f193d04f3ade7f6cf1ff19f67f +Subproject commit 334a64c1120a54a19fac7b0783306892d419a547 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 index dc6b0e23..7114de0d 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java @@ -43,6 +43,11 @@ public class UpdateSensorDataCommand extends EntityModifyRevertibleCommand { sensorComponent.rightSpanPercent = vo.rightSpanPercent; sensorComponent.topSpanPercent = vo.topSpanPercent; + sensorComponent.bottomHeightPercent = vo.bottomHeightPercent; + sensorComponent.leftWidthPercent = vo.leftWidthPercent; + sensorComponent.rightWidthPercent = vo.rightWidthPercent; + sensorComponent.topHeightPercent = vo.topHeightPercent; + Facade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } @@ -61,6 +66,11 @@ public class UpdateSensorDataCommand extends EntityModifyRevertibleCommand { sensorComponent.rightSpanPercent = backup.rightSpanPercent; sensorComponent.topSpanPercent = backup.topSpanPercent; + sensorComponent.bottomHeightPercent = backup.bottomHeightPercent; + sensorComponent.leftWidthPercent = backup.leftWidthPercent; + sensorComponent.rightWidthPercent = backup.rightWidthPercent; + sensorComponent.topHeightPercent = backup.topHeightPercent; + Facade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorProperties.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorProperties.java index a3c17343..92071822 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorProperties.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorProperties.java @@ -28,6 +28,11 @@ public class UISensorProperties extends UIRemovableProperties { private VisValidatableTextField sensorSpanPercentLeft; private VisValidatableTextField sensorSpanPercentRight; private VisValidatableTextField sensorSpanPercentTop; + + private VisValidatableTextField sensorHeightPercentBottom; + private VisValidatableTextField sensorWidthPercentLeft; + private VisValidatableTextField sensorWidthPercentRight; + private VisValidatableTextField sensorHeightPercentTop; public UISensorProperties() { super("Physics Sensors"); @@ -50,6 +55,11 @@ public class UISensorProperties extends UIRemovableProperties { sensorSpanPercentRight = StandardWidgetsFactory.createValidableTextField(floatValidator); sensorSpanPercentTop = StandardWidgetsFactory.createValidableTextField(floatValidator); + sensorHeightPercentBottom = StandardWidgetsFactory.createValidableTextField(floatValidator); + sensorWidthPercentLeft = StandardWidgetsFactory.createValidableTextField(floatValidator); + sensorWidthPercentRight = StandardWidgetsFactory.createValidableTextField(floatValidator); + sensorHeightPercentTop = StandardWidgetsFactory.createValidableTextField(floatValidator); + mainTable.add(new VisLabel("Add sensors to body:", Align.left)).padRight(5).colspan(2).fillX(); mainTable.row().padTop(5); @@ -57,16 +67,28 @@ public class UISensorProperties extends UIRemovableProperties { VisTable sensorTable = new VisTable(); sensorTable.defaults().left(); sensorTable.add(sensorTop).padRight(5); + sensorTable.add("W:"); sensorTable.add(sensorSpanPercentTop).width(50).padRight(5); + sensorTable.add("H:"); + sensorTable.add(sensorHeightPercentTop).width(50).padRight(5); sensorTable.row(); sensorTable.add(sensorLeft).padRight(5); + sensorTable.add("H:"); sensorTable.add(sensorSpanPercentLeft).width(50).padRight(5); + sensorTable.add("W:"); + sensorTable.add(sensorWidthPercentLeft).width(50).padRight(5); sensorTable.row(); sensorTable.add(sensorRight).padRight(5); + sensorTable.add("H:"); sensorTable.add(sensorSpanPercentRight).width(50).padRight(5); + sensorTable.add("W:"); + sensorTable.add(sensorWidthPercentRight).width(50).padRight(5); sensorTable.row(); sensorTable.add(sensorBottom).padRight(5); + sensorTable.add("W:"); sensorTable.add(sensorSpanPercentBottom).width(50).padRight(5); + sensorTable.add("H:"); + sensorTable.add(sensorHeightPercentBottom).width(50).padRight(5); mainTable.add(sensorTable).padBottom(5).colspan(2); mainTable.row().padTop(5); @@ -76,10 +98,18 @@ public class UISensorProperties extends UIRemovableProperties { * Initializes the tooltips. */ private void initTooltip() { - StandardWidgetsFactory.addTooltip(sensorBottom, "Adds a sensor to the bottom of the body. The value gives the percentage of the body width where 1.0 equals 100%."); - StandardWidgetsFactory.addTooltip(sensorLeft, "Adds a sensor to the left of the body. The value gives the percentage of the body height where 1.0 equals 100%."); - StandardWidgetsFactory.addTooltip(sensorRight, "Adds a sensor to the right of the body. The value gives the percentage of the body height where 1.0 equals 100%."); - StandardWidgetsFactory.addTooltip(sensorTop, "Adds a sensor to the top of the body. The value gives the percentage of the body width where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorBottom, "Adds a sensor to the bottom of the body."); + StandardWidgetsFactory.addTooltip(sensorSpanPercentBottom, "The value gives the percentage of the body sensor width where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorHeightPercentBottom, "The value gives the percentage of the body sensor height where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorLeft, "Adds a sensor to the left of the body."); + StandardWidgetsFactory.addTooltip(sensorSpanPercentLeft, "The value gives the percentage of the body sensor height where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorWidthPercentLeft, "The value gives the percentage of the body sensor width where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorRight, "Adds a sensor to the right of the body."); + StandardWidgetsFactory.addTooltip(sensorSpanPercentRight, "The value gives the percentage of the body sensor height where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorWidthPercentRight, "The value gives the percentage of the body sensor width where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorTop, "Adds a sensor to the top of the body."); + StandardWidgetsFactory.addTooltip(sensorSpanPercentTop, "The value gives the percentage of the body sensor width where 1.0 equals 100%."); + StandardWidgetsFactory.addTooltip(sensorHeightPercentTop, "The value gives the percentage of the body sensor height where 1.0 equals 100%."); } private void initListeners() { @@ -92,6 +122,11 @@ public class UISensorProperties extends UIRemovableProperties { sensorSpanPercentLeft.addListener(new KeyboardListener(getUpdateEventName())); sensorSpanPercentRight.addListener(new KeyboardListener(getUpdateEventName())); sensorSpanPercentTop.addListener(new KeyboardListener(getUpdateEventName())); + + sensorHeightPercentBottom.addListener(new KeyboardListener(getUpdateEventName())); + sensorWidthPercentLeft.addListener(new KeyboardListener(getUpdateEventName())); + sensorWidthPercentRight.addListener(new KeyboardListener(getUpdateEventName())); + sensorHeightPercentTop.addListener(new KeyboardListener(getUpdateEventName())); } public VisCheckBox getSensorBottomBox() { @@ -126,6 +161,22 @@ public class UISensorProperties extends UIRemovableProperties { return sensorSpanPercentTop; } + public VisTextField getSensorHeightPercentBottomTextfield() { + return sensorHeightPercentBottom; + } + + public VisTextField getSensorWidthPercentLeftTextfield() { + return sensorWidthPercentLeft; + } + + public VisTextField getSensorWidthPercentRightTextfield() { + return sensorWidthPercentRight; + } + + public VisTextField getSensorHeightPercentTopTextfield() { + return sensorHeightPercentTop; + } + @Override public void onRemove() { Facade.getInstance().sendNotification(CLOSE_CLICKED); diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java index 46e263a9..d1f1e7d3 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java @@ -59,6 +59,11 @@ public class UISensorPropertiesMediator extends UIItemPropertiesMediator