Set properties via ctors instead of obj init syntax and cleanup
This commit is contained in:
parent
bea796fb2d
commit
b204d65afe
|
@ -83,40 +83,49 @@ namespace BizHawk.Client.EmuHawk
|
||||||
PadBox.Controls.Add(controlSchema switch
|
PadBox.Controls.Add(controlSchema switch
|
||||||
{
|
{
|
||||||
ButtonSchema button => GenVirtualPadButton(button),
|
ButtonSchema button => GenVirtualPadButton(button),
|
||||||
SingleAxisSchema singleAxis => new VirtualPadAnalogButton(_inputManager.StickyXorAdapter)
|
SingleAxisSchema singleAxis => new VirtualPadAnalogButton(
|
||||||
|
_inputManager.StickyXorAdapter,
|
||||||
|
singleAxis.Name,
|
||||||
|
singleAxis.DisplayName,
|
||||||
|
singleAxis.MinValue,
|
||||||
|
singleAxis.MaxValue,
|
||||||
|
singleAxis.Orientation
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Name = singleAxis.Name,
|
|
||||||
DisplayName = singleAxis.DisplayName,
|
|
||||||
Location = UIHelper.Scale(singleAxis.Location),
|
Location = UIHelper.Scale(singleAxis.Location),
|
||||||
Size = UIHelper.Scale(singleAxis.TargetSize),
|
Size = UIHelper.Scale(singleAxis.TargetSize)
|
||||||
MinValue = singleAxis.MinValue,
|
|
||||||
MaxValue = singleAxis.MaxValue,
|
|
||||||
Orientation = singleAxis.Orientation
|
|
||||||
},
|
},
|
||||||
AnalogSchema analog => new VirtualPadAnalogStick(_inputManager)
|
AnalogSchema analog => new VirtualPadAnalogStick(
|
||||||
|
_inputManager,
|
||||||
|
analog.Name,
|
||||||
|
analog.SecondaryName,
|
||||||
|
analog.Spec,
|
||||||
|
analog.SecondarySpec
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Name = analog.Name,
|
|
||||||
SecondaryName = analog.SecondaryName,
|
|
||||||
Location = UIHelper.Scale(analog.Location),
|
Location = UIHelper.Scale(analog.Location),
|
||||||
Size = UIHelper.Scale(new Size(180 + 79, 200 + 9)),
|
Size = UIHelper.Scale(new Size(180 + 79, 200 + 9))
|
||||||
RangeX = analog.Spec,
|
|
||||||
RangeY = analog.SecondarySpec
|
|
||||||
},
|
},
|
||||||
TargetedPairSchema targetedPair => new VirtualPadTargetScreen(_inputManager.StickyXorAdapter)
|
TargetedPairSchema targetedPair => new VirtualPadTargetScreen(
|
||||||
|
_inputManager.StickyXorAdapter,
|
||||||
|
targetedPair.Name,
|
||||||
|
targetedPair.SecondaryName,
|
||||||
|
targetedPair.MaxValue,
|
||||||
|
targetedPair.MaxValue // TODO split into MaxX and MaxY, and rename VirtualPadTargetScreen.RangeX/RangeY
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Name = targetedPair.Name,
|
|
||||||
Location = UIHelper.Scale(targetedPair.Location),
|
Location = UIHelper.Scale(targetedPair.Location),
|
||||||
TargetSize = targetedPair.TargetSize,
|
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(_inputManager.StickyXorAdapter, discManager.SecondaryNames) {
|
DiscManagerSchema discManager => new VirtualPadDiscManager(
|
||||||
Name = discManager.Name,
|
_inputManager.StickyXorAdapter,
|
||||||
|
discManager.OwnerEmulator,
|
||||||
|
discManager.Name,
|
||||||
|
discManager.SecondaryNames
|
||||||
|
)
|
||||||
|
{
|
||||||
Location = UIHelper.Scale(discManager.Location),
|
Location = UIHelper.Scale(discManager.Location),
|
||||||
Size = UIHelper.Scale(discManager.TargetSize),
|
Size = UIHelper.Scale(discManager.TargetSize)
|
||||||
OwnerEmulator = discManager.OwnerEmulator
|
|
||||||
},
|
},
|
||||||
_ => throw new InvalidOperationException()
|
_ => throw new InvalidOperationException()
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,7 +67,6 @@
|
||||||
this.Controls.Add(this.AnalogTrackBar);
|
this.Controls.Add(this.AnalogTrackBar);
|
||||||
this.Name = "VirtualPadAnalogButton";
|
this.Name = "VirtualPadAnalogButton";
|
||||||
this.Size = new System.Drawing.Size(297, 74);
|
this.Size = new System.Drawing.Size(297, 74);
|
||||||
this.Load += new System.EventHandler(this.VirtualPadAnalogButton_Load);
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.AnalogTrackBar)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.AnalogTrackBar)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
|
@ -9,8 +9,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public partial class VirtualPadAnalogButton : UserControl, IVirtualPadControl
|
public partial class VirtualPadAnalogButton : UserControl, IVirtualPadControl
|
||||||
{
|
{
|
||||||
private readonly StickyXorAdapter _stickyXorAdapter;
|
private readonly StickyXorAdapter _stickyXorAdapter;
|
||||||
private string _displayName = "";
|
|
||||||
private int _maxValue, _minValue;
|
|
||||||
private bool _programmaticallyChangingValue;
|
private bool _programmaticallyChangingValue;
|
||||||
private bool _readonly;
|
private bool _readonly;
|
||||||
|
|
||||||
|
@ -25,10 +23,46 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualPadAnalogButton(StickyXorAdapter stickyXorAdapter)
|
public VirtualPadAnalogButton(
|
||||||
|
StickyXorAdapter stickyXorAdapter,
|
||||||
|
string name,
|
||||||
|
string displayName,
|
||||||
|
int minValue,
|
||||||
|
int maxValue,
|
||||||
|
Orientation orientation)
|
||||||
{
|
{
|
||||||
_stickyXorAdapter = stickyXorAdapter;
|
_stickyXorAdapter = stickyXorAdapter;
|
||||||
|
Name = name;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
// AnalogTrackBar, DisplayNameLabel, and ValueLabel are now assigned
|
||||||
|
|
||||||
|
var trackbarWidth = Size.Width - 15;
|
||||||
|
int trackbarHeight;
|
||||||
|
if ((AnalogTrackBar.Orientation = orientation) == Orientation.Vertical)
|
||||||
|
{
|
||||||
|
AnalogTrackBar.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
|
||||||
|
trackbarHeight = Size.Height - 30;
|
||||||
|
ValueLabel.Top = Size.Height / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AnalogTrackBar.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
||||||
|
trackbarHeight = Size.Height - 15;
|
||||||
|
}
|
||||||
|
AnalogTrackBar.Size = new Size(trackbarWidth, trackbarHeight);
|
||||||
|
|
||||||
|
AnalogTrackBar.Minimum = minValue;
|
||||||
|
AnalogTrackBar.Maximum = maxValue;
|
||||||
|
|
||||||
|
// try to base it on the width, lets make a tick every 10 pixels at the minimum
|
||||||
|
// yo none of this makes any sense --yoshi
|
||||||
|
var range = maxValue - minValue + 1;
|
||||||
|
var canDoTicks = Math.Min(Math.Max(2, trackbarWidth / 10), range);
|
||||||
|
AnalogTrackBar.TickFrequency = range / Math.Max(1, canDoTicks);
|
||||||
|
|
||||||
|
DisplayNameLabel.Text = displayName ?? string.Empty;
|
||||||
|
ValueLabel.Text = AnalogTrackBar.Value.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateValues()
|
public void UpdateValues()
|
||||||
|
@ -82,105 +116,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VirtualPadAnalogButton_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
DisplayNameLabel.Text = DisplayName;
|
|
||||||
ValueLabel.Text = AnalogTrackBar.Value.ToString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DisplayName
|
|
||||||
{
|
|
||||||
get => _displayName;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_displayName = value ?? "";
|
|
||||||
if (DisplayNameLabel != null)
|
|
||||||
{
|
|
||||||
DisplayNameLabel.Text = _displayName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int MaxValue
|
|
||||||
{
|
|
||||||
get => _maxValue;
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_maxValue = value;
|
|
||||||
if (AnalogTrackBar != null)
|
|
||||||
{
|
|
||||||
AnalogTrackBar.Maximum = _maxValue;
|
|
||||||
UpdateTickFrequency();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int MinValue
|
|
||||||
{
|
|
||||||
get => _minValue;
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_minValue = value;
|
|
||||||
if (AnalogTrackBar != null)
|
|
||||||
{
|
|
||||||
AnalogTrackBar.Minimum = _minValue;
|
|
||||||
UpdateTickFrequency();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Orientation Orientation
|
|
||||||
{
|
|
||||||
get => AnalogTrackBar.Orientation;
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
AnalogTrackBar.Orientation = value;
|
|
||||||
if (value == Orientation.Horizontal)
|
|
||||||
{
|
|
||||||
AnalogTrackBar.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
||||||
AnalogTrackBar.Size = new Size(Size.Width - 15, Size.Height - 15);
|
|
||||||
}
|
|
||||||
else if (value == Orientation.Vertical)
|
|
||||||
{
|
|
||||||
AnalogTrackBar.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
|
|
||||||
AnalogTrackBar.Size = new Size(Size.Width - 15, Size.Height - 30);
|
|
||||||
ValueLabel.Top = Size.Height / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTickFrequency()
|
|
||||||
{
|
|
||||||
if (AnalogTrackBar == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to base it on the width, lets make a tick every 10 pixels at the minimum
|
|
||||||
int canDoTicks = AnalogTrackBar.Width / 10;
|
|
||||||
if (canDoTicks < 2)
|
|
||||||
{
|
|
||||||
canDoTicks = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int range = _maxValue - _minValue + 1;
|
|
||||||
if (range < canDoTicks)
|
|
||||||
{
|
|
||||||
canDoTicks = range;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canDoTicks <= 0)
|
|
||||||
{
|
|
||||||
canDoTicks = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
AnalogTrackBar.TickFrequency = range / canDoTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int CurrentValue
|
public int CurrentValue
|
||||||
{
|
{
|
||||||
get => AnalogTrackBar.Value;
|
get => AnalogTrackBar.Value;
|
||||||
|
|
|
@ -170,7 +170,6 @@
|
||||||
this.Controls.Add(this.AnalogStick);
|
this.Controls.Add(this.AnalogStick);
|
||||||
this.Name = "VirtualPadAnalogStick";
|
this.Name = "VirtualPadAnalogStick";
|
||||||
this.Size = new System.Drawing.Size(253, 172);
|
this.Size = new System.Drawing.Size(253, 172);
|
||||||
this.Load += new System.EventHandler(this.VirtualPadAnalogStick_Load);
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.ManualX)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.ManualX)).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.ManualY)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.ManualY)).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.MaxXNumeric)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.MaxXNumeric)).EndInit();
|
||||||
|
|
|
@ -20,9 +20,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private bool _updatingFromXY;
|
private bool _updatingFromXY;
|
||||||
|
|
||||||
public VirtualPadAnalogStick(InputManager inputManager)
|
public VirtualPadAnalogStick(
|
||||||
|
InputManager inputManager,
|
||||||
|
string name,
|
||||||
|
string secondaryName,
|
||||||
|
AxisSpec rangeX,
|
||||||
|
AxisSpec rangeY)
|
||||||
{
|
{
|
||||||
_inputManager = inputManager;
|
_inputManager = inputManager;
|
||||||
|
Name = name;
|
||||||
|
RangeX = rangeX;
|
||||||
|
RangeY = rangeY;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
AnalogStick.ClearCallback = ClearCallback;
|
AnalogStick.ClearCallback = ClearCallback;
|
||||||
|
|
||||||
|
@ -30,21 +39,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
ManualY.ValueChanged += ManualXY_ValueChanged;
|
ManualY.ValueChanged += ManualXY_ValueChanged;
|
||||||
manualR.ValueChanged += PolarNumeric_Changed;
|
manualR.ValueChanged += PolarNumeric_Changed;
|
||||||
manualTheta.ValueChanged += PolarNumeric_Changed;
|
manualTheta.ValueChanged += PolarNumeric_Changed;
|
||||||
}
|
|
||||||
|
|
||||||
public AxisSpec RangeX { get; set; }
|
|
||||||
|
|
||||||
public AxisSpec RangeY { get; set; }
|
|
||||||
|
|
||||||
public string? SecondaryName { get; set; }
|
|
||||||
|
|
||||||
private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
AnalogStick.Init(
|
AnalogStick.Init(
|
||||||
_inputManager.StickyXorAdapter,
|
_inputManager.StickyXorAdapter,
|
||||||
Name,
|
Name,
|
||||||
RangeX,
|
RangeX,
|
||||||
!string.IsNullOrEmpty(SecondaryName) ? SecondaryName : Name.Replace("X", "Y"),
|
!string.IsNullOrEmpty(secondaryName) ? secondaryName : Name.Replace("X", "Y"),
|
||||||
RangeY
|
RangeY
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -62,6 +62,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
MaxYNumeric.Value = 100;
|
MaxYNumeric.Value = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly AxisSpec RangeX;
|
||||||
|
|
||||||
|
private readonly AxisSpec RangeY;
|
||||||
|
|
||||||
public void UpdateValues()
|
public void UpdateValues()
|
||||||
{
|
{
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
|
|
|
@ -11,15 +11,21 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
private readonly StickyXorAdapter _stickyXorAdapter;
|
private readonly StickyXorAdapter _stickyXorAdapter;
|
||||||
|
|
||||||
public VirtualPadDiscManager(StickyXorAdapter stickyXorAdapter, IReadOnlyList<string> buttonNames)
|
public VirtualPadDiscManager(
|
||||||
|
StickyXorAdapter stickyXorAdapter,
|
||||||
|
IEmulator ownerEmulator,
|
||||||
|
string name,
|
||||||
|
IReadOnlyList<string> buttonNames)
|
||||||
{
|
{
|
||||||
_stickyXorAdapter = stickyXorAdapter;
|
_stickyXorAdapter = stickyXorAdapter;
|
||||||
|
Name = name;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
btnOpen.Name = buttonNames[0];
|
btnOpen.Name = buttonNames[0];
|
||||||
btnClose.Name = buttonNames[1];
|
btnClose.Name = buttonNames[1];
|
||||||
_discSelectName = buttonNames[2];
|
_discSelectName = buttonNames[2];
|
||||||
|
|
||||||
UpdateCoreAssociation();
|
UpdateCoreAssociation();
|
||||||
|
OwnerEmulator = ownerEmulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly string _discSelectName;
|
private readonly string _discSelectName;
|
||||||
|
|
|
@ -21,9 +21,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private int? _overrideX;
|
private int? _overrideX;
|
||||||
private int? _overrideY;
|
private int? _overrideY;
|
||||||
|
|
||||||
public VirtualPadTargetScreen(StickyXorAdapter stickyXorAdapter)
|
public VirtualPadTargetScreen(
|
||||||
|
StickyXorAdapter stickyXorAdapter,
|
||||||
|
string nameX,
|
||||||
|
string nameY,
|
||||||
|
int rangeX,
|
||||||
|
int rangeY)
|
||||||
{
|
{
|
||||||
_stickyXorAdapter = stickyXorAdapter;
|
_stickyXorAdapter = stickyXorAdapter;
|
||||||
|
Name = XName = nameX;
|
||||||
|
YName = nameY;
|
||||||
|
RangeX = rangeX;
|
||||||
|
RangeY = rangeY;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +122,8 @@ 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
|
// These are the value that a maximum x or y actually represent, used to translate from control X,Y to values the core expects
|
||||||
public int RangeX { get; set; }
|
private readonly int RangeX;
|
||||||
public int RangeY { get; set; }
|
private readonly int RangeY;
|
||||||
|
|
||||||
public float MultiplierX
|
public float MultiplierX
|
||||||
{
|
{
|
||||||
|
@ -156,8 +166,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string XName { get; set; }
|
private readonly string XName;
|
||||||
public string YName { get; set; }
|
private readonly string YName;
|
||||||
|
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue