diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs index 2c5d9791d5..1f93d59ba6 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs @@ -48,6 +48,28 @@ namespace BizHawk.Client.EmuHawk private void VirtualPadControl_Load(object sender, EventArgs e) { + static VirtualPadButton GenVirtualPadButton(ButtonSchema button) + { + var buttonControl = new VirtualPadButton + { + Name = button.Name, + Text = button.Icon != null + ? null + : string.IsNullOrWhiteSpace(button.DisplayName) + ? button.Name + : button.DisplayName, + Location = UIHelper.Scale(button.Location), + Image = button.Icon + }; + if (button.Icon != null && UIHelper.AutoScaleFactorX > 1F && UIHelper.AutoScaleFactorY > 1F) + { + // When scaling up, unfortunately the icon will look too small, but at least we can make the rest of the button bigger + buttonControl.AutoSize = false; + buttonControl.Size = UIHelper.Scale(button.Icon.Size) + new Size(6, 6); + } + return buttonControl; + } + Size = UIHelper.Scale(_schema.Size); MaximumSize = UIHelper.Scale(_schema.Size); PadBox.Text = _schema.DisplayName; @@ -57,75 +79,48 @@ namespace BizHawk.Client.EmuHawk this.PadBox.ForeColor = SystemColors.HotTrack; } - foreach (var button in _schema.Buttons) + foreach (var controlSchema in _schema.Buttons) { - switch (button.Type) + PadBox.Controls.Add(controlSchema switch { - case PadInputType.Boolean: - var buttonControl = new VirtualPadButton - { - Name = button.Name, - Text = button.Icon != null - ? null - : string.IsNullOrWhiteSpace(button.DisplayName) - ? button.Name - : button.DisplayName, - Location = UIHelper.Scale(button.Location), - Image = button.Icon - }; - if (button.Icon != null && UIHelper.AutoScaleFactorX > 1F && UIHelper.AutoScaleFactorY > 1F) - { - // When scaling up, unfortunately the icon will look too small, but at least we can make the rest of the button bigger - buttonControl.AutoSize = false; - buttonControl.Size = UIHelper.Scale(button.Icon.Size) + new Size(6, 6); - } - PadBox.Controls.Add(buttonControl); - break; - case PadInputType.AnalogStick: - PadBox.Controls.Add(new VirtualPadAnalogStick - { - Name = button.Name, - SecondaryName = (button.SecondaryNames != null && button.SecondaryNames.Any()) ? button.SecondaryNames[0] : "", - Location = UIHelper.Scale(button.Location), - Size = UIHelper.Scale(new Size(180 + 79, 200 + 9)), - RangeX = button.AxisRange ?? throw new Exception(), - RangeY = button.SecondaryAxisRange ?? throw new Exception() - }); - break; - case PadInputType.TargetedPair: - PadBox.Controls.Add(new VirtualPadTargetScreen - { - Name = button.Name, - Location = UIHelper.Scale(button.Location), - TargetSize = button.TargetSize, - XName = button.Name, - YName = button.SecondaryNames[0], - RangeX = button.MaxValue, - RangeY = button.MaxValue // TODO: ability to have a different Y than X - }); - break; - case PadInputType.SingleAxis: - PadBox.Controls.Add(new VirtualPadAnalogButton - { - Name = button.Name, - DisplayName = button.DisplayName, - Location = UIHelper.Scale(button.Location), - Size = UIHelper.Scale(button.TargetSize), - MinValue = button.MinValue, - MaxValue = button.MaxValue, - Orientation = button.Orientation - }); - break; - case PadInputType.DiscManager: - PadBox.Controls.Add(new VirtualPadDiscManager(button.SecondaryNames) - { - Name = button.Name, - Location = UIHelper.Scale(button.Location), - Size = UIHelper.Scale(button.TargetSize), - OwnerEmulator = button.OwnerEmulator - }); - break; - } + ButtonSchema button => GenVirtualPadButton(button), + SingleAxisSchema singleAxis => new VirtualPadAnalogButton + { + Name = singleAxis.Name, + DisplayName = singleAxis.DisplayName, + Location = UIHelper.Scale(singleAxis.Location), + Size = UIHelper.Scale(singleAxis.TargetSize), + MinValue = singleAxis.MinValue, + MaxValue = singleAxis.MaxValue, + Orientation = singleAxis.Orientation + }, + AnalogSchema analog => new VirtualPadAnalogStick + { + Name = analog.Name, + SecondaryName = analog.SecondaryName, + Location = UIHelper.Scale(analog.Location), + Size = UIHelper.Scale(new Size(180 + 79, 200 + 9)), + RangeX = analog.AxisRange, + RangeY = analog.SecondaryAxisRange + }, + TargetedPairSchema targetedPair => new VirtualPadTargetScreen + { + Name = targetedPair.Name, + Location = UIHelper.Scale(targetedPair.Location), + TargetSize = targetedPair.TargetSize, + XName = targetedPair.Name, + YName = targetedPair.SecondaryName, + RangeX = targetedPair.MaxValue, + RangeY = targetedPair.MaxValue //TODO split into MaxX and MaxY, and rename VirtualPadTargetScreen.RangeX/RangeY + }, + DiscManagerSchema discManager => new VirtualPadDiscManager(discManager.SecondaryNames) { + Name = discManager.Name, + Location = UIHelper.Scale(discManager.Location), + Size = UIHelper.Scale(discManager.TargetSize), + OwnerEmulator = discManager.OwnerEmulator + }, + _ => throw new InvalidOperationException() + }); } } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index e7231d72ed..4412ddfcd3 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -79,25 +79,35 @@ namespace BizHawk.Client.EmuHawk .FirstOrDefault(t => t.GetCustomAttributes(false) .OfType() .First().SystemId == Emulator.SystemId); - - if (schemaType != null) + + if (schemaType == null) return; + + var padSchemata = ((IVirtualPadSchema) Activator.CreateInstance(schemaType)) + .GetPadSchemas(Emulator) + .ToList(); + + if (VersionInfo.DeveloperBuild) { - var padSchemas = ((IVirtualPadSchema)Activator.CreateInstance(schemaType)) - .GetPadSchemas(Emulator) - .ToList(); - - if (VersionInfo.DeveloperBuild) + var buttonControls = Emulator.ControllerDefinition.BoolButtons; + var axisControls = Emulator.ControllerDefinition.AxisControls; + foreach (var schema in padSchemata) foreach (var controlSchema in schema.Buttons) { - CheckPads(padSchemas, Emulator.ControllerDefinition); - } - - var pads = padSchemas.Select(s => new VirtualPad(s)); - - if (pads.Any()) - { - ControllerPanel.Controls.AddRange(pads.Reverse().ToArray()); + Predicate searchSetContains = controlSchema switch + { + ButtonSchema _ => buttonControls.Contains, + DiscManagerSchema _ => s => buttonControls.Contains(s) || axisControls.Contains(s), + _ => axisControls.Contains + }; + if (!searchSetContains(controlSchema.Name)) + { + MessageBox.Show(this, + $"Schema warning: Schema entry '{schema.DisplayName}':'{controlSchema.Name}' will not correspond to any control in definition '{Emulator.ControllerDefinition.Name}'", + "Dev Warning"); + } } } + + ControllerPanel.Controls.AddRange(padSchemata.Select(s => (Control) new VirtualPad(s)).Reverse().ToArray()); } public void ScrollToPadSchema(string padSchemaName) @@ -117,42 +127,6 @@ namespace BizHawk.Client.EmuHawk } } - private void CheckPads(IEnumerable schemas, ControllerDefinition def) - { - var analogs = new HashSet(def.AxisControls); - var bools = new HashSet(def.BoolButtons); - - foreach (var schema in schemas) - { - foreach (var button in schema.Buttons) - { - var searchSet = new HashSet(); - switch (button.Type) - { - case PadInputType.AnalogStick: - case PadInputType.SingleAxis: - case PadInputType.TargetedPair: - // analog - searchSet = analogs; - break; - case PadInputType.Boolean: - searchSet = bools; - break; - case PadInputType.DiscManager: - searchSet = bools; - searchSet.UnionWith(analogs); - break; - } - if (!searchSet.Contains(button.Name)) - { - MessageBox.Show(this, - $"Schema warning: Schema entry '{schema.DisplayName}':'{button.Name}' will not correspond to any control in definition '{def.Name}'", - "Dev Warning"); - } - } - } - } - #region IToolForm Implementation public bool AskSaveChanges() => true; diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs index 2ef6330863..1977f78910 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadDiscManager.cs @@ -10,7 +10,7 @@ namespace BizHawk.Client.EmuHawk { public partial class VirtualPadDiscManager : UserControl, IVirtualPadControl { - public VirtualPadDiscManager(string[] buttonNames) + public VirtualPadDiscManager(IReadOnlyList buttonNames) { InitializeComponent(); btnOpen.Name = buttonNames[0]; diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs index 8ed052ec98..b409989dc5 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs @@ -66,7 +66,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = $"Player {controller}", Size = new Size(334, 94), - Buttons = new[] + Buttons = new PadSchemaControl[] { new ButtonSchema(5, 24, controller, "Button 1") { @@ -117,7 +117,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = $"Player {controller}", Size = new Size(334, 94), - Buttons = new[] + Buttons = new PadSchemaControl[] { new ButtonSchema(5, 24, controller, "Button") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A78Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A78Schema.cs index db1a010f50..74e2aa7e2c 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A78Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A78Schema.cs @@ -95,7 +95,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Light Gun", Size = new Size(356, 290), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} X") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ButtonSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ButtonSchema.cs deleted file mode 100644 index db856415dc..0000000000 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ButtonSchema.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System.Drawing; -using System.Windows.Forms; -using BizHawk.Client.EmuHawk.Properties; -using BizHawk.Emulation.Common; - -namespace BizHawk.Client.EmuHawk -{ - public enum PadInputType - { - Boolean, // A single on/off button - AnalogStick, // An analog stick X,Y Pair - SingleAxis, // A single analog control (pressure sensitive button for instance) - TargetedPair, // A X,Y pair intended to be a screen coordinate (for zappers, mouse, stylus, etc) - DiscManager - } - - public class ButtonSchema - { - public ButtonSchema(int x, int y, string name) - { - Location = new Point(x, y); - Name = name; - } - - public ButtonSchema(int x, int y, int controller, string name) - : this(x, y, $"P{controller} {name}") - { - DisplayName = name; - } - - public string Name { get; protected set; } - public string DisplayName { get; set; } - public PadInputType Type { get; protected set; } = PadInputType.Boolean; - public Point Location { get; protected set; } - public Bitmap Icon { get; set; } - public Size TargetSize { get; set; } // Specifically for TargetedPair, specifies the screen size - public string[] SecondaryNames { get; set; } // Any other buttons necessary to operate (such as the Y axis) - public int MaxValue { get; set; } // For non-boolean values, specifies the maximum value the button allows - public int MidValue { get; set; } // For non-boolean values, specifies the mid (zero) value for the button - public int MinValue { get; set; } // For non-boolean values, specifies the minimum value the button allows - public int MaxValueSec { get; set; } - public int MidValueSec { get; set; } - public int MinValueSec { get; set; } - public object OwnerEmulator { get; set; } - - public Orientation Orientation { get; set; } // For SingleAxis controls - - // for Analog Stick controls - public ControllerDefinition.AxisRange? AxisRange { get; set; } - public ControllerDefinition.AxisRange? SecondaryAxisRange { get; set; } - - public static ButtonSchema Up(int x, int y, string name = null) - => new ButtonSchema(x, y, name ?? "Up") - { - Icon = Resources.BlueUp - }; - - public static ButtonSchema Up(int x, int y, int controller) - => new ButtonSchema(x, y, controller, "Up") - { - Icon = Resources.BlueUp - }; - - - public static ButtonSchema Down(int x, int y, string name = null) - => new ButtonSchema(x, y, name ?? "Down") - { - Icon = Resources.BlueDown - }; - - public static ButtonSchema Down(int x, int y, int controller) - => new ButtonSchema(x, y, controller, "Down") - { - Icon = Resources.BlueDown - }; - - public static ButtonSchema Left(int x, int y, string name = null) - => new ButtonSchema(x, y, name ?? "Left") - { - Icon = Resources.Back - }; - - public static ButtonSchema Left(int x, int y, int controller) - => new ButtonSchema(x, y, controller, "Left") - { - Icon = Resources.Back - }; - - public static ButtonSchema Right(int x, int y, string name = null) - => new ButtonSchema(x, y, name ?? "Right") - { - Icon = Resources.Forward - }; - - public static ButtonSchema Right(int x, int y, int controller) - => new ButtonSchema(x, y, controller, "Right") - { - Icon = Resources.Forward - }; - } - - public class SingleAxisSchema : ButtonSchema - { - public SingleAxisSchema(int x, int y, string name) - : base(x, y, name) - { - Type = PadInputType.SingleAxis; - } - - public SingleAxisSchema(int x, int y, int controller, string name) - : base(x, y, controller, name) - { - Type = PadInputType.SingleAxis; - } - } - - public class TargetedPairSchema : ButtonSchema - { - public TargetedPairSchema(int x, int y, string nameX) - : base(x, y, nameX) - { - Type = PadInputType.TargetedPair; - SecondaryNames = new[] - { - nameX.Replace("X", "Y") - }; - } - } - - public class AnalogSchema : ButtonSchema - { - public AnalogSchema(int x, int y, string nameX) - : base(x, y, nameX) - { - Type = PadInputType.AnalogStick; - SecondaryNames = new[] - { - nameX.Replace("X", "Y") - }; - } - } - - public class DiscManagerSchema : ButtonSchema - { - public DiscManagerSchema(int x, int y) - : base(x, y, "Disc Select") - { - Type = PadInputType.DiscManager; - } - } -} diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs index 6a40c42e08..f32562b8b7 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs @@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk return new PadSchema { Size = new Size(275, 260), - Buttons = new[] + Buttons = new PadSchemaControl[] { new AnalogSchema(6, 14, $"P{controller} Disc X") { @@ -69,7 +69,7 @@ namespace BizHawk.Client.EmuHawk return new PadSchema { Size = new Size(195, 260), - Buttons = StandardButtons(controller).Concat(new[] + Buttons = StandardButtons(controller).Concat(new PadSchemaControl[] { new SingleAxisSchema(6, 200, controller, "Disc X") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GBASchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GBASchema.cs index e38a95a428..f5e54f345c 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GBASchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GBASchema.cs @@ -41,7 +41,7 @@ namespace BizHawk.Client.EmuHawk }; } - private static ButtonSchema Tilt(int x, int y, string direction) + private static SingleAxisSchema Tilt(int x, int y, string direction) => new SingleAxisSchema(x, y, "Tilt " + direction) { TargetSize = new Size(226, 69), diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs index 94e48bc8fe..53c48b01b3 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/GenSchema.cs @@ -111,11 +111,10 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Light Gun", Size = new Size(356, 300), - Buttons = new[] + Buttons = new PadSchemaControl[] { - new TargetedPairSchema(14, 17, $"P{controller} Lightgun X") + new TargetedPairSchema(14, 17, $"P{controller} Lightgun X", 10000) { - MaxValue = 10000, TargetSize = new Size(320, 240) }, new ButtonSchema(284, 17, controller, "Lightgun Trigger") @@ -136,12 +135,12 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Mouse", Size = new Size(418, 290), - Buttons = new[] + Buttons = new PadSchemaControl[] { new AnalogSchema(14, 17, $"P{controller} Mouse X") { - MaxValue = 255, - TargetSize = new Size(520, 570) +// MaxValue = 255, +// TargetSize = new Size(520, 570) }, new ButtonSchema(365, 17, controller, "Mouse Left") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs index 1ea7ba4969..ca01c11334 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs @@ -75,7 +75,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = $"Player {controller}", Size = new Size(280, 332), - Buttons = StandardButtons(controller).Concat(new[] + Buttons = StandardButtons(controller).Concat(new PadSchemaControl[] { new AnalogSchema(1, 121, $"P{controller} Disc X") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs index e781c4675d..67f69bed3a 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs @@ -28,7 +28,7 @@ namespace BizHawk.Client.EmuHawk return new PadSchema { Size = new Size(275, 316), - Buttons = new[] + Buttons = new PadSchemaControl[] { ButtonSchema.Up(24, 230, $"P{controller} DPad U"), ButtonSchema.Down(24, 251, $"P{controller} DPad D"), diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NdsSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NdsSchema.cs index 1732c19072..cb7cd43b72 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NdsSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NdsSchema.cs @@ -19,7 +19,7 @@ namespace BizHawk.Client.EmuHawk.tools.VirtualPads.schema return new PadSchema { Size = new Size(440, 260), - Buttons = new [] + Buttons = new PadSchemaControl[] { ButtonSchema.Up(14, 79), ButtonSchema.Down(14, 122), diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs index fad803990e..9f2d9759a2 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs @@ -252,7 +252,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Zapper", Size = new Size(356, 290), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} Zapper X") { @@ -269,7 +269,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Arkanoid Paddle", Size = new Size(380, 110), - Buttons = new[] + Buttons = new PadSchemaControl[] { new SingleAxisSchema(14, 17, controller, "Paddle") { @@ -320,7 +320,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Tablet", Size = new Size(356, 290), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} Pen X") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs index c1c403992d..330f181c23 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs @@ -51,7 +51,7 @@ namespace BizHawk.Client.EmuHawk { Size = new Size(500, 290), DisplayName = $"DualShock Player{controller}", - Buttons = new[] + Buttons = new PadSchemaControl[] { ButtonSchema.Up(32, 50, controller), ButtonSchema.Down(32, 71, controller), @@ -151,7 +151,7 @@ namespace BizHawk.Client.EmuHawk { Size = new Size(343, 195), DisplayName = $"NeGcon Player{controller}", - Buttons = new[] + Buttons = new PadSchemaControl[] { ButtonSchema.Up(36, 83, controller), ButtonSchema.Down(36, 104, controller), @@ -167,12 +167,11 @@ namespace BizHawk.Client.EmuHawk MinValue = 0, MaxValue = 255 }, - new SingleAxisSchema(125, 15, controller, "Twist") + new SingleAxisSchema(125, 15, controller, "Twist", isVertical: true) { TargetSize = new Size(64, 178), MinValue = 0, - MaxValue = 255, - Orientation = Orientation.Vertical + MaxValue = 255 }, new SingleAxisSchema(180, 60, controller, "2") { @@ -197,15 +196,10 @@ namespace BizHawk.Client.EmuHawk return new ConsoleSchema { Size = new Size(310, 400), - Buttons = new[] + Buttons = new PadSchemaControl[] { new ButtonSchema(10, 15, "Reset"), - new DiscManagerSchema(10, 54) - { - TargetSize = new Size(300, 300), - OwnerEmulator = psx, - SecondaryNames = new[] { "Open", "Close", "Disc Select" } - } + new DiscManagerSchema(10, 54, new Size(300, 300), psx, new[] { "Open", "Close", "Disc Select" }) } }; } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs index fd31b9fa7d..6743b569ff 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs @@ -7,7 +7,7 @@ namespace BizHawk.Client.EmuHawk { public Size Size { get; set; } public bool IsConsole { get; protected set; } - public IEnumerable Buttons { get; set; } = new List(); + public IEnumerable Buttons { get; set; } = new List(); public string DisplayName { get; set; } // The name of the pad itself, presumably will be displayed by the given pad time if supplied } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs new file mode 100644 index 0000000000..84af7ebb39 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchemaControl.cs @@ -0,0 +1,135 @@ +#nullable enable + +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +using BizHawk.Client.EmuHawk.Properties; +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.EmuHawk +{ + public abstract class PadSchemaControl + { + public readonly Point Location; + + public readonly string Name; + + protected PadSchemaControl(Point location, string name) + { + Location = location; + Name = name; + } + } + + /// A single on/off button + public class ButtonSchema : PadSchemaControl + { + public string? DisplayName { get; set; } + + public Bitmap? Icon { get; set; } + + public ButtonSchema(int x, int y, string name) + : base(new Point(x, y), name) + => DisplayName = name; + + public ButtonSchema(int x, int y, int controller, string name) + : this(x, y, $"P{controller} {name}") {} + + public static ButtonSchema Up(int x, int y, string? name = null) + => new ButtonSchema(x, y, name ?? "Up") { Icon = Resources.BlueUp }; + + public static ButtonSchema Up(int x, int y, int controller) + => new ButtonSchema(x, y, controller, "Up") { Icon = Resources.BlueUp }; + + public static ButtonSchema Down(int x, int y, string? name = null) + => new ButtonSchema(x, y, name ?? "Down") { Icon = Resources.BlueDown }; + + public static ButtonSchema Down(int x, int y, int controller) + => new ButtonSchema(x, y, controller, "Down") { Icon = Resources.BlueDown }; + + public static ButtonSchema Left(int x, int y, string? name = null) + => new ButtonSchema(x, y, name ?? "Left") { Icon = Resources.Back }; + + public static ButtonSchema Left(int x, int y, int controller) + => new ButtonSchema(x, y, controller, "Left") { Icon = Resources.Back }; + + public static ButtonSchema Right(int x, int y, string? name = null) + => new ButtonSchema(x, y, name ?? "Right") { Icon = Resources.Forward }; + + public static ButtonSchema Right(int x, int y, int controller) + => new ButtonSchema(x, y, controller, "Right") { Icon = Resources.Forward }; + } + + /// A single analog control (e.g. pressure sensitive button) + public class SingleAxisSchema : PadSchemaControl + { + public string DisplayName { get; set; } + + public int MaxValue { get; set; } + + public int MinValue { get; set; } + + public readonly Orientation Orientation; + + public Size TargetSize { get; set; } + + public SingleAxisSchema(int x, int y, string name, bool isVertical = false) + : base(new Point(x, y), name) + { + DisplayName = name; + Orientation = isVertical ? Orientation.Vertical : Orientation.Horizontal; + } + + public SingleAxisSchema(int x, int y, int controller, string name, bool isVertical = false) + : this(x, y, $"P{controller} {name}", isVertical) {} + } + + /// An analog stick (X, Y) pair + public class AnalogSchema : PadSchemaControl + { + public ControllerDefinition.AxisRange AxisRange { get; set; } + + public ControllerDefinition.AxisRange SecondaryAxisRange { get; set; } + + public string SecondaryName { get; set; } + + public AnalogSchema(int x, int y, string nameX) + : base(new Point(x, y), nameX) + => SecondaryName = nameX.Replace("X", "Y"); + } + + /// An (X, Y) pair intended to be a screen coordinate (for zappers, mouse, stylus, etc.) + public class TargetedPairSchema : PadSchemaControl + { + public readonly int MaxValue; + + public readonly string SecondaryName; + + public Size TargetSize { get; set; } + + public TargetedPairSchema(int x, int y, string nameX, int maxValue = default) + : base(new Point(x, y), nameX) + { + MaxValue = maxValue; + SecondaryName = nameX.Replace("X", "Y"); + } + } + + public class DiscManagerSchema : PadSchemaControl + { + public readonly IEmulator OwnerEmulator; + + public readonly IReadOnlyList SecondaryNames; + + public readonly Size TargetSize; + + public DiscManagerSchema(int x, int y, Size targetSize, IEmulator owner, IReadOnlyList secondaryNames) + : base(new Point(x, y), "Disc Select") + { + OwnerEmulator = owner; + SecondaryNames = secondaryNames; + TargetSize = targetSize; + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PcfxSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PcfxSchema.cs index bf5623bbb4..018ac44285 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PcfxSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PcfxSchema.cs @@ -72,7 +72,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Mouse", Size = new Size(375, 320), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} X") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs index 33e675c62d..bb1915e5ca 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs @@ -96,7 +96,7 @@ namespace BizHawk.Client.EmuHawk return new PadSchema { Size = new Size(458, 285), - Buttons = new[] + Buttons = new PadSchemaControl[] { ButtonSchema.Up(290, 77, controller), ButtonSchema.Down(290, 121, controller), @@ -111,7 +111,7 @@ namespace BizHawk.Client.EmuHawk new ButtonSchema(414, 80, controller, "Z"), new AnalogSchema(6, 74, $"P{controller} Stick Horizontal") { - SecondaryNames = new[] { $"P{controller} Stick Vertical" }, + SecondaryName = $"P{controller} Stick Vertical", AxisRange = axisRanges[0], SecondaryAxisRange = axisRanges[1] }, @@ -139,7 +139,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Mouse", Size = new Size(375, 320), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} X") { @@ -168,7 +168,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Wheel", Size = new Size(325, 100), - Buttons = new[] + Buttons = new PadSchemaControl[] { new SingleAxisSchema(8, 12, controller, "Wheel") { @@ -196,7 +196,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Mission", Size = new Size(445, 230), - Buttons = new[] + Buttons = new PadSchemaControl[] { new ButtonSchema(45, 15, controller, "Start"), new ButtonSchema(5, 58, controller, "L"), @@ -209,16 +209,15 @@ namespace BizHawk.Client.EmuHawk new ButtonSchema(80, 70, controller, "C"), new AnalogSchema(185, 13, $"P{controller} Stick Horizontal") { - SecondaryNames = new[] { $"P{controller} Stick Vertical" }, + SecondaryName = $"P{controller} Stick Vertical", AxisRange = axisRanges[0], SecondaryAxisRange = axisRanges[1] }, - new SingleAxisSchema(135, 13, controller, "Throttle") + new SingleAxisSchema(135, 13, controller, "Throttle", isVertical: true) { TargetSize = new Size(64, 178), MinValue = 0, - MaxValue = 255, - Orientation = Orientation.Vertical + MaxValue = 255 } } }; @@ -231,35 +230,33 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Dual Mission", Size = new Size(680, 230), - Buttons = new ButtonSchema[] + Buttons = new PadSchemaControl[] { new AnalogSchema(58, 13, $"P{controller} Left Stick Horizontal") { - SecondaryNames = new[] { $"P{controller} Left Stick Vertical" }, + SecondaryName = $"P{controller} Left Stick Vertical", AxisRange = axisRanges[3], SecondaryAxisRange = axisRanges[4] }, - new SingleAxisSchema(8, 13, controller, "Left Throttle") + new SingleAxisSchema(8, 13, controller, "Left Throttle", isVertical: true) { DisplayName = "Throttle", TargetSize = new Size(64, 178), MinValue = 0, - MaxValue = 255, - Orientation = Orientation.Vertical + MaxValue = 255 }, new AnalogSchema(400, 13, $"P{controller} Right Stick Horizontal") { - SecondaryNames = new[] { $"P{controller} Right Stick Vertical" }, + SecondaryName = $"P{controller} Right Stick Vertical", AxisRange = axisRanges[0], SecondaryAxisRange = axisRanges[1] }, - new SingleAxisSchema(350, 13, controller, "Right Throttle") + new SingleAxisSchema(350, 13, controller, "Right Throttle", isVertical: true) { DisplayName = "Throttle", TargetSize = new Size(64, 178), MinValue = 0, - MaxValue = 255, - Orientation = Orientation.Vertical + MaxValue = 255 } } }; diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs index 1a21bea47d..f149ee1909 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs @@ -137,7 +137,7 @@ namespace BizHawk.Client.EmuHawk return new PadSchema { Size = new Size(345, 225), - Buttons = new[] + Buttons = new PadSchemaControl[] { new AnalogSchema(6, 14, $"P{controller} Mouse X") { @@ -162,7 +162,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Super Scope", Size = new Size(356, 290), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} Scope X") { @@ -182,7 +182,7 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Justifier", Size = new Size(356, 290), - Buttons = new[] + Buttons = new PadSchemaControl[] { new TargetedPairSchema(14, 17, $"P{controller} Justifier X") { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs index b1eb4135b9..92522b6568 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs @@ -64,7 +64,7 @@ namespace BizHawk.Client.EmuHawk return new PadSchema { Size = new Size(280, 300), - Buttons = new[] + Buttons = new PadSchemaControl[] { Button(74, 34, controller, 1), Button(98, 34, controller, 2),