From a89b0dfdcde730ee3fa5120164fd667c6688a0d6 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 1 Sep 2020 09:01:18 +1000 Subject: [PATCH] Split TargetedPairSchema.MaxValue to MaxX/MaxY and cleanup * split TargetedPairSchema ctor and added docs to clarify its behaviour * renamed VirtualPadTargetScreen.RangeX/RangeY to MaxX/MaxY * left TODOs in the three places MaxValue was actually used --- .../tools/VirtualPads/VirtualPad.cs | 4 ++-- .../controls/VirtualPadTargetScreen.cs | 20 +++++++++---------- .../tools/VirtualPads/schema/GenSchema.cs | 2 +- .../VirtualPads/schema/PadSchemaControl.cs | 16 ++++++++++++--- .../tools/VirtualPads/schema/SaturnSchema.cs | 4 ++-- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs index bbc9c7aaa9..203dae8747 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs @@ -110,8 +110,8 @@ namespace BizHawk.Client.EmuHawk _inputManager.StickyXorAdapter, targetedPair.Name, targetedPair.SecondaryName, - targetedPair.MaxValue, - targetedPair.MaxValue // TODO split into MaxX and MaxY, and rename VirtualPadTargetScreen.RangeX/RangeY + targetedPair.MaxX, + targetedPair.MaxY ) { Location = UIHelper.Scale(targetedPair.Location), diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadTargetScreen.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadTargetScreen.cs index 30d31654d8..3d0e2b0635 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadTargetScreen.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadTargetScreen.cs @@ -25,14 +25,14 @@ namespace BizHawk.Client.EmuHawk StickyXorAdapter stickyXorAdapter, string nameX, string nameY, - int rangeX, - int rangeY) + int maxX, + int maxY) { _stickyXorAdapter = stickyXorAdapter; Name = XName = nameX; YName = nameY; - RangeX = rangeX; - RangeY = rangeY; + MaxX = maxX; + MaxY = maxY; InitializeComponent(); } @@ -122,16 +122,16 @@ namespace BizHawk.Client.EmuHawk } // These are the value that a maximum x or y actually represent, used to translate from control X,Y to values the core expects - private readonly int RangeX; - private readonly int RangeY; + private readonly int MaxX; + private readonly int MaxY; public float MultiplierX { get { - if (RangeX > 0) + if (MaxX > 0) { - return RangeX / (float)TargetPanel.Width; + return MaxX / (float)TargetPanel.Width; } return 1; @@ -142,9 +142,9 @@ namespace BizHawk.Client.EmuHawk { get { - if (RangeY > 0) + if (MaxY > 0) { - return RangeY / (float)TargetPanel.Height; + return MaxY / (float)TargetPanel.Height; } return 1; diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs index a0f6501e0f..d3e0d39a05 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs @@ -113,7 +113,7 @@ namespace BizHawk.Client.EmuHawk Size = new Size(356, 300), Buttons = new PadSchemaControl[] { - new TargetedPairSchema(14, 17, $"P{controller} Lightgun X", 10000) + new TargetedPairSchema(14, 17, $"P{controller} Lightgun X", 10000, 10000) //TODO (10000, 10000) matches previous behaviour - what was intended here? { TargetSize = new Size(320, 240) }, diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs index ba07ffb63f..6ffba58497 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs @@ -106,18 +106,28 @@ namespace BizHawk.Client.EmuHawk /// An (X, Y) pair intended to be a screen coordinate (for zappers, mouse, stylus, etc.) public sealed class TargetedPairSchema : PadSchemaControl { - public int MaxValue { get; } + public int MaxX { get; } + + public int MaxY { get; } public string SecondaryName { get; set; } public Size TargetSize { get; set; } - public TargetedPairSchema(int x, int y, string nameX, int maxValue = default) + /// Using this ctor, the valid ranges for the X and Y axes are taken to be (0..TargetSize.Width) and (0..TargetSize.Height). + public TargetedPairSchema(int x, int y, string nameX) : base(new Point(x, y), nameX) { - MaxValue = maxValue; SecondaryName = nameX.Replace("X", "Y"); } + + /// Using this ctor, the valid ranges for the X and Y axes are taken to be (0..maxX) and (0..maxY). + public TargetedPairSchema(int x, int y, string nameX, int maxX, int maxY) + : this(x, y, nameX) + { + MaxX = maxX; + MaxY = maxY; + } } public sealed class DiscManagerSchema : PadSchemaControl diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs index a6b231f3d8..89eedaab8e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs @@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk Size = new Size(375, 320), Buttons = new PadSchemaControl[] { - new TargetedPairSchema(14, 17, $"P{controller} Motion Left / Right", AxisRange.Max) + new TargetedPairSchema(14, 17, $"P{controller} Motion Left / Right", AxisRange.Max, AxisRange.Max) //TODO (0xFFFF, 0xFFFF) matches previous behaviour - what was intended here? { SecondaryName = $"P{controller} Motion Up / Down", TargetSize = new Size(256, 256) @@ -264,7 +264,7 @@ namespace BizHawk.Client.EmuHawk Size = new Size(375, 320), Buttons = new PadSchemaControl[] { - new TargetedPairSchema(14, 17, $"P{controller} X Axis", AxisRange.Max) + new TargetedPairSchema(14, 17, $"P{controller} X Axis", AxisRange.Max, AxisRange.Max) //TODO (0xFFFF, 0xFFFF) matches previous behaviour - what was intended here? { SecondaryName = $"P{controller} Y Axis", TargetSize = new Size(256, 256)