From 60011384ed7cb67a193a6ad0a34c851493db3f76 Mon Sep 17 00:00:00 2001 From: freezy Date: Mon, 23 Nov 2026 00:19:23 +0100 Subject: [PATCH 1/2] sound: input action sounds can play when the button is released InputActionSoundComponent gets a Start When option (pressed or released), reusing the StartWhen choice of switch and coil sounds. It is packed with the component. Items schema 6, case 2 (compatible both ways): older players ignore the new field and play the sound on the press, and older tables restore as before. --- .../Packaging/MechanicalSoundPackagingTests.cs | 2 ++ .../VisualPinball.Unity/Packaging/VpePackageManifest.cs | 3 ++- .../Sound/InputActionSoundComponent.cs | 9 +++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/VisualPinball.Unity/VisualPinball.Unity.Test/Packaging/MechanicalSoundPackagingTests.cs b/VisualPinball.Unity/VisualPinball.Unity.Test/Packaging/MechanicalSoundPackagingTests.cs index a4c48df4ee..9e735c0181 100644 --- a/VisualPinball.Unity/VisualPinball.Unity.Test/Packaging/MechanicalSoundPackagingTests.cs +++ b/VisualPinball.Unity/VisualPinball.Unity.Test/Packaging/MechanicalSoundPackagingTests.cs @@ -75,6 +75,7 @@ public IEnumerator RuntimePackagePreservesFourBanksAndSharedAndNullReferences() var input = child.AddComponent(); input.ActionName = "Start Game"; input.SoundAsset = second; + input.StartWhen = StartWhen.TurnedOff; new PackageWriter(source).WritePackageSync(package); var task = new RuntimePackageReader(package).ImportIntoScene(); while (!task.IsCompleted) @@ -97,6 +98,7 @@ public IEnumerator RuntimePackagePreservesFourBanksAndSharedAndNullReferences() var restoredInput = imported.GetComponentInChildren(true); Assert.That(restoredInput.ActionName, Is.EqualTo("Start Game")); Assert.That(restoredInput.SoundAsset, Is.SameAs(restored.Up)); + Assert.That(restoredInput.StartWhen, Is.EqualTo(StartWhen.TurnedOff)); } finally { if (imported) diff --git a/VisualPinball.Unity/VisualPinball.Unity/Packaging/VpePackageManifest.cs b/VisualPinball.Unity/VisualPinball.Unity/Packaging/VpePackageManifest.cs index a6b758b978..128d7672ff 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Packaging/VpePackageManifest.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Packaging/VpePackageManifest.cs @@ -71,7 +71,7 @@ public static class VpePackageSchemas /// The version of the items schema this build writes. It goes up by one with every change to the schema that /// a reader has to know about, with a line added to . /// - public const int ItemsVersion = 5; + public const int ItemsVersion = 6; /// /// The oldest items schema version a reader must implement to load what this build writes, stored in the manifest @@ -99,6 +99,7 @@ public static class VpePackageSchemas "the names in a table's files were made consistent, and tables from before would lose the settings stored under the old names", "the settings of a table's objects moved from thousands of small files into one, and tables from before have them where this build no longer looks", "the objects of a prefab instance say which of the prefab's objects they are, so the editor links them to the prefab again even when they were renamed", + "input action sounds can play when the button is released, which older players play on the press instead", }; /// diff --git a/VisualPinball.Unity/VisualPinball.Unity/Sound/InputActionSoundComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/Sound/InputActionSoundComponent.cs index d35f1a381d..2e3f332852 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Sound/InputActionSoundComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Sound/InputActionSoundComponent.cs @@ -24,6 +24,8 @@ namespace VisualPinball.Unity public class InputActionSoundComponent : SoundComponent, IPackable { public string ActionName; + [Tooltip("Whether the sound plays when the button is pressed or when it is released.")] + public StartWhen StartWhen = StartWhen.TurnedOn; private Player _player; private bool _pressed; public override bool SupportsLoopingSoundAssets() => false; @@ -38,7 +40,7 @@ private void OnInput(string action, bool pressed) { if (InputManager.GetCanonicalActionName(ActionName) != action || _pressed == pressed) return; _pressed = pressed; - if (pressed) + if (pressed == (StartWhen == StartWhen.TurnedOn)) StartSound(); } protected override void OnDisable() { @@ -51,17 +53,20 @@ protected override void OnDisable() { public new byte[] Pack() => PackageApi.Packer.Pack(new InputActionSoundPackable { Sound = base.Pack(), - ActionName = ActionName + ActionName = ActionName, + StartWhen = StartWhen }); public new void Unpack(byte[] bytes) { var p = PackageApi.Packer.Unpack(bytes); base.Unpack(p.Sound); ActionName = p.ActionName; + StartWhen = p.StartWhen; } } public struct InputActionSoundPackable { public byte[] Sound; public string ActionName; + public StartWhen StartWhen; } } From c33e9d339f1a0bb40cb94b7e1bc8b5b43d9c6025 Mon Sep 17 00:00:00 2001 From: freezy Date: Mon, 23 Nov 2026 12:20:59 +0100 Subject: [PATCH 2/2] display: expose a score reel's position and an output's rotation ScoreReelComponent.DigitPosition tells where a reel is in its turn, in digits, so the player can draw flat reels that move with the ones on the backglass. CabinetDisplayTarget carries the quarter turns the player applies to an output's content, with ContentWidth and ContentHeight for plugins that lay out their picture for the output. --- VisualPinball.Plugins.Test/CabinetDisplayTests.cs | 11 +++++++++++ VisualPinball.Plugins/Api/CabinetDisplays.cs | 14 ++++++++++++-- .../Display/ScoreReelComponent.cs | 8 ++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/VisualPinball.Plugins.Test/CabinetDisplayTests.cs b/VisualPinball.Plugins.Test/CabinetDisplayTests.cs index c52340515e..e7feb80f35 100644 --- a/VisualPinball.Plugins.Test/CabinetDisplayTests.cs +++ b/VisualPinball.Plugins.Test/CabinetDisplayTests.cs @@ -36,6 +36,17 @@ public void DuplicateAssignmentsAndInvalidAvailableDestinationsAreRejected() Assert.That(new CabinetDisplaySnapshot(1, 1, 1, new[] { target, second }, Array.Empty()).TargetsFor(CabinetOutputRole.Dmd).Count, Is.EqualTo(2)); } + [Test] + public void ContentOfADestinationTurnedByAQuarterIsAsWideAsTheDestinationIsHigh() + { + var upright = new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 300, height: 1200, rotation: 1); + Assert.That((upright.ContentWidth, upright.ContentHeight), Is.EqualTo((1200, 300))); + var turnedOver = new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 300, height: 1200, rotation: 2); + Assert.That((turnedOver.ContentWidth, turnedOver.ContentHeight), Is.EqualTo((300, 1200))); + Assert.That(new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 128, height: 32).Rotation, Is.EqualTo(0)); + Assert.Throws(() => new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 128, height: 32, rotation: 4)); + } + [Test] public void RankingFallsBackOnlyWhenIneligibleAndIsIndependentOfPublicationOrder() { diff --git a/VisualPinball.Plugins/Api/CabinetDisplays.cs b/VisualPinball.Plugins/Api/CabinetDisplays.cs index c8ea71d460..f1a1ae69e9 100644 --- a/VisualPinball.Plugins/Api/CabinetDisplays.cs +++ b/VisualPinball.Plugins/Api/CabinetDisplays.cs @@ -72,16 +72,26 @@ public sealed class CabinetDisplayTarget public int Y { get; } public int Width { get; } public int Height { get; } + /// + /// Clockwise quarter turns, 0 to 3, by which the Player turns what it shows here. A producer that lays out its + /// picture for this destination sizes it by and . + /// + public int Rotation { get; } + /// The width of a picture that fills this destination: its height when the content is turned by a quarter. + public int ContentWidth => (Rotation & 1) != 0 ? Height : Width; + /// The height of a picture that fills this destination: its width when the content is turned by a quarter. + public int ContentHeight => (Rotation & 1) != 0 ? Width : Height; public CabinetDisplayTarget(string endpointId, CabinetOutputRole role, CabinetEndpointState state, - int x = 0, int y = 0, int width = 0, int height = 0, string reason = "") + int x = 0, int y = 0, int width = 0, int height = 0, string reason = "", int rotation = 0) { if (string.IsNullOrWhiteSpace(endpointId)) throw new ArgumentException("An endpoint needs an ID.", nameof(endpointId)); if (!CabinetOutputRoles.IsDefined(role)) throw new ArgumentException("An output needs a role.", nameof(role)); if (!Enum.IsDefined(typeof(CabinetEndpointState), state)) throw new ArgumentOutOfRangeException(nameof(state)); if (state == CabinetEndpointState.Available && (width < 1 || height < 1)) throw new ArgumentOutOfRangeException(nameof(width)); + if (rotation < 0 || rotation > 3) throw new ArgumentOutOfRangeException(nameof(rotation)); EndpointId = endpointId; Role = role; State = state; - X = x; Y = y; Width = width; Height = height; Reason = reason ?? ""; + X = x; Y = y; Width = width; Height = height; Reason = reason ?? ""; Rotation = rotation; } } diff --git a/VisualPinball.Unity/VisualPinball.Unity/Display/ScoreReelComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/Display/ScoreReelComponent.cs index a34defb26e..44b0025893 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Display/ScoreReelComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Display/ScoreReelComponent.cs @@ -77,6 +77,14 @@ public void UnpackReferences(byte[] data, Transform root, PackagedRefs refs, Pac private bool _isRotatingDown => Direction == ScoreReelDirection.Down; + /// + /// Where the reel is now, in digits, from 0 up to but not including 10: 0 shows the zero, 9 the nine, and a + /// value in between means the reel is on its way to the next digit. After the nine it starts again at 0. It + /// counts up the same way for both values of , which only says whether the next digit + /// comes from above or from below. Follows the animation, so a flat drawing of the reel can move with it. + /// + public float DigitPosition => _currentRotation / 36f; + public void AnimateTo(int position) { var increasePositions = (position - _endPosition + 10) % 10;