From b68971731c8d4fbc8c96f53622af943c7eb5596a Mon Sep 17 00:00:00 2001 From: freezy Date: Sun, 21 Aug 2022 00:59:55 +0200 Subject: [PATCH 01/84] fix: Additionally map string-parsed IDs when mapping coils. --- .../VisualPinball.Unity/Game/CoilPlayer.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/VisualPinball.Unity/VisualPinball.Unity/Game/CoilPlayer.cs b/VisualPinball.Unity/VisualPinball.Unity/Game/CoilPlayer.cs index c1e0692bc..fc5f7efb9 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Game/CoilPlayer.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Game/CoilPlayer.cs @@ -107,18 +107,32 @@ public void OnStart() } } + /// + /// Assigns a coil mapping with the coil's ID, but also with an int-parsed ID, + /// so we can name them "01" and it still works with PinMAME. + /// + /// Mapping to assign + /// If it's a flasher private void AssignCoilMapping(CoilMapping coilMapping, bool isLampCoil) { - if (!_coilAssignments.ContainsKey(coilMapping.Id)) { - _coilAssignments[coilMapping.Id] = new List(); + AssignCoilMapping(coilMapping.Id, coilMapping, isLampCoil); + if (int.TryParse(coilMapping.Id, out var id) && id.ToString() != coilMapping.Id) { + AssignCoilMapping(id.ToString(), coilMapping, isLampCoil); + } + } + + private void AssignCoilMapping(string id, CoilMapping coilMapping, bool isLampCoil) + { + if (!_coilAssignments.ContainsKey(id)) { + _coilAssignments[id] = new List(); } var hasDynamicWire = _tableComponent!.MappingConfig.Wires.FirstOrDefault(w => w.DestinationDevice == coilMapping.Device && w.DestinationDeviceItem == coilMapping.DeviceItem && w.IsDynamic) != null; - _coilAssignments[coilMapping.Id].Add(new CoilDestConfig(coilMapping.Device, coilMapping.DeviceItem, isLampCoil, hasDynamicWire)); - CoilStatuses[coilMapping.Id] = false; + _coilAssignments[id].Add(new CoilDestConfig(coilMapping.Device, coilMapping.DeviceItem, isLampCoil, hasDynamicWire)); + CoilStatuses[id] = false; } private void HandleCoilEvent(object sender, CoilEventArgs coilEvent) From 4a2cb9913ca8ea794bc57e967f41345ce81ff019 Mon Sep 17 00:00:00 2001 From: freezy Date: Sat, 17 Sep 2022 23:46:35 +0200 Subject: [PATCH 02/84] drag-points: Add reverse feature. --- .../DragPoint/DragPointMenuItems.cs | 11 +++++++++++ .../DragPoint/DragPointsHandler.cs | 8 ++++++++ .../DragPoint/DragPointsInspectorHelper.cs | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs index 91a3876c5..027be7449 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointMenuItems.cs @@ -197,5 +197,16 @@ private static void FlipZ(MenuCommand command) inspector.DragPointsHelper.FlipDragPoints(FlipAxis.Z); } + + [MenuItem(CurveTravellerMenuPath + "/Reverse", false, 501)] + [MenuItem(ControlPointsMenuPath + "/Reverse", false, 601)] + private static void Reverse(MenuCommand command) + { + if (!(command.context is IDragPointsInspector inspector)) { + return; + } + + inspector.DragPointsHelper.Reverse(); + } } } diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs index 4ad8d8d5b..01c789d50 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsHandler.cs @@ -222,6 +222,14 @@ public void FlipDragPoints(FlipAxis flipAxis) } } + public void ReverseDragPoints() + { + var dragPoints = DragPointInspector.DragPoints.ToList(); + dragPoints.Reverse(1, dragPoints.Count - 1); + DragPointInspector.DragPoints = dragPoints.ToArray(); + RebuildControlPoints(); + } + /// /// Updates the lock status on all drag points to the given value. /// diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs index 4c7c32de4..598f111f2 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/DragPoint/DragPointsInspectorHelper.cs @@ -177,6 +177,13 @@ public void RemoveDragPoint(int controlId) RebuildMeshes(); } + public void Reverse() + { + PrepareUndo("Reverse Drag Points"); + DragPointsHandler.ReverseDragPoints(); + RebuildMeshes(); + } + /// /// Sets an UNDO point before the next operation. /// From 0089d6b6b5bee1722855c6efec384b23c9c9c694 Mon Sep 17 00:00:00 2001 From: freezy Date: Sun, 18 Sep 2022 12:58:56 +0200 Subject: [PATCH 03/84] editor: Add "Make Collider" option that speeds up collider-from-mesh creation. --- .../VPT/ColliderInspector.cs | 1 - .../VPT/Primitive/PrimitiveInspector.cs | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ColliderInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ColliderInspector.cs index c60cdc296..cef88ce5d 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ColliderInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/ColliderInspector.cs @@ -16,7 +16,6 @@ // ReSharper disable AssignmentInConditionalExpression -using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Primitive/PrimitiveInspector.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Primitive/PrimitiveInspector.cs index ca4863858..ec57c43ec 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Primitive/PrimitiveInspector.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Primitive/PrimitiveInspector.cs @@ -17,6 +17,7 @@ // ReSharper disable AssignmentInConditionalExpression using System.Linq; +using Unity.Entities; using UnityEditor; using UnityEngine; using VisualPinball.Engine.VPT.Primitive; @@ -88,6 +89,36 @@ public static void MakePrimitive() var cc = go.AddComponent(); cc.enabled = true; + + var cte = go.AddComponent(); + cte.ConversionMode = ConvertToEntity.Mode.ConvertAndInjectGameObject; + } + } + + [MenuItem("GameObject/Visual Pinball/Make Collider", true, 21)] + public static bool MakeColliderValidation() + { + return Selection.gameObjects.All(gameObject => gameObject.GetComponent() == null && gameObject.GetComponent() != null); + } + + [MenuItem("GameObject/Visual Pinball/Make Collider", false, 21)] + public static void MakeCollider() + { + foreach (var go in Selection.gameObjects) { + var pc = go.AddComponent(); + pc.Position = go.transform.localPosition; + pc.Rotation = go.transform.localEulerAngles; + pc.Size = go.transform.localScale; + + var mc = go.AddComponent(); + mc.UseLegacyMesh = false; + mc.enabled = false; + + var cc = go.AddComponent(); + cc.enabled = true; + + var cte = go.AddComponent(); + cte.ConversionMode = ConvertToEntity.Mode.ConvertAndInjectGameObject; } } } From 91a9080ee82607a391cc84850af3c4eb96e04b2f Mon Sep 17 00:00:00 2001 From: freezy Date: Mon, 19 Sep 2022 22:29:14 +0200 Subject: [PATCH 04/84] asset-library: Add "replace selected" feature. --- VisualPinball.Engine/Math/DragPointData.cs | 16 ++++++ .../AssetBrowser/AssetDetailsElement.cs | 55 ++++++++++++++++++- .../AssetBrowser/AssetDetailsElement.uss | 15 +++++ .../AssetBrowser/AssetDetailsElement.uxml | 6 ++ .../VPT/Bumper/BumperComponent.cs | 22 ++++++++ .../VPT/Flipper/FlipperComponent.cs | 26 +++++++++ .../VPT/Gate/GateComponent.cs | 18 ++++++ .../VPT/HitTarget/TargetComponent.cs | 17 ++++++ .../VPT/IMainRenderableComponent.cs | 3 + .../VPT/Kicker/KickerComponent.cs | 18 ++++++ .../VPT/Light/LightComponent.cs | 17 ++++++ .../VPT/MainRenderableComponent.cs | 19 +++++++ .../MetalWireGuide/MetalWireGuideComponent.cs | 19 +++++++ .../VPT/Playfield/PlayfieldComponent.cs | 5 ++ .../VPT/Plunger/PlungerComponent.cs | 17 ++++++ .../VPT/Primitive/PrimitiveComponent.cs | 20 +++++++ .../VPT/Ramp/RampComponent.cs | 26 +++++++++ .../VPT/Rubber/RubberComponent.cs | 18 ++++++ .../VPT/Spinner/SpinnerComponent.cs | 21 +++++++ .../VPT/Surface/SlingshotComponent.cs | 6 ++ .../VPT/Surface/SurfaceComponent.cs | 17 ++++++ .../VPT/Table/TableComponent.cs | 6 ++ .../VPT/Trigger/TriggerComponent.cs | 22 ++++++++ 23 files changed, 408 insertions(+), 1 deletion(-) diff --git a/VisualPinball.Engine/Math/DragPointData.cs b/VisualPinball.Engine/Math/DragPointData.cs index 3259ac84a..93f68a019 100644 --- a/VisualPinball.Engine/Math/DragPointData.cs +++ b/VisualPinball.Engine/Math/DragPointData.cs @@ -87,6 +87,22 @@ public DragPointData Lerp(DragPointData dp, float pos) }; } + public DragPointData Clone() + { + return new DragPointData(Center) { + PosZ = PosZ, + IsSmooth = IsSmooth, + IsSlingshot = IsSlingshot, + HasAutoTexture = HasAutoTexture, + TextureCoord = TextureCoord, + IsLocked = IsLocked, + EditorLayer = EditorLayer, + EditorLayerName = EditorLayerName, + EditorLayerVisibility = EditorLayerVisibility, + CalcHeight = CalcHeight, + }; + } + #region BIFF static DragPointData() diff --git a/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetDetailsElement.cs b/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetDetailsElement.cs index aea81dd4f..41cdb10e5 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetDetailsElement.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetDetailsElement.cs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +using System.Collections.Generic; +using System.Linq; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; @@ -56,6 +58,8 @@ public AssetResult Asset { private AssetResult _asset; private UnityEditor.Editor _previewEditor; private Object _object; + private readonly Button _replaceSelectedButton; + private readonly Toggle _replaceSelectedKeepName; private readonly Label _categoryElement; private readonly TextField _descriptionEditElement; private readonly Label _descriptionViewElement; @@ -92,6 +96,8 @@ public AssetDetailsElement() _libraryLockElement = ui.Q("library-lock"); _categoryElement = ui.Q