pass InputManager dependencies to more virtualpad controls
This commit is contained in:
parent
2be1d04182
commit
ce0a529362
|
@ -5,12 +5,14 @@ using System.Windows.Forms;
|
|||
|
||||
using BizHawk.Emulation.Common;
|
||||
using System.Drawing;
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public partial class VirtualPad : UserControl
|
||||
{
|
||||
private readonly PadSchema _schema;
|
||||
private readonly InputManager _inputManager;
|
||||
private bool _readOnly;
|
||||
|
||||
public void UpdateValues()
|
||||
|
@ -36,7 +38,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public VirtualPad(PadSchema schema)
|
||||
public VirtualPad(PadSchema schema, InputManager inputManager)
|
||||
{
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
|
@ -44,6 +46,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
InitializeComponent();
|
||||
Dock = DockStyle.Top | DockStyle.Left;
|
||||
_schema = schema;
|
||||
_inputManager = inputManager;
|
||||
}
|
||||
|
||||
private void VirtualPadControl_Load(object sender, EventArgs e)
|
||||
|
@ -72,7 +75,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (_schema.IsConsole)
|
||||
{
|
||||
this.PadBox.ForeColor = SystemColors.HotTrack;
|
||||
PadBox.ForeColor = SystemColors.HotTrack;
|
||||
}
|
||||
|
||||
foreach (var controlSchema in _schema.Buttons)
|
||||
|
@ -80,7 +83,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
PadBox.Controls.Add(controlSchema switch
|
||||
{
|
||||
ButtonSchema button => GenVirtualPadButton(button),
|
||||
SingleAxisSchema singleAxis => new VirtualPadAnalogButton
|
||||
SingleAxisSchema singleAxis => new VirtualPadAnalogButton(_inputManager.StickyXorAdapter)
|
||||
{
|
||||
Name = singleAxis.Name,
|
||||
DisplayName = singleAxis.DisplayName,
|
||||
|
@ -90,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
MaxValue = singleAxis.MaxValue,
|
||||
Orientation = singleAxis.Orientation
|
||||
},
|
||||
AnalogSchema analog => new VirtualPadAnalogStick(GlobalWin.InputManager)
|
||||
AnalogSchema analog => new VirtualPadAnalogStick(_inputManager)
|
||||
{
|
||||
Name = analog.Name,
|
||||
SecondaryName = analog.SecondaryName,
|
||||
|
@ -99,7 +102,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
RangeX = analog.Spec,
|
||||
RangeY = analog.SecondarySpec
|
||||
},
|
||||
TargetedPairSchema targetedPair => new VirtualPadTargetScreen
|
||||
TargetedPairSchema targetedPair => new VirtualPadTargetScreen(_inputManager.StickyXorAdapter)
|
||||
{
|
||||
Name = targetedPair.Name,
|
||||
Location = UIHelper.Scale(targetedPair.Location),
|
||||
|
@ -107,9 +110,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
XName = targetedPair.Name,
|
||||
YName = targetedPair.SecondaryName,
|
||||
RangeX = targetedPair.MaxValue,
|
||||
RangeY = targetedPair.MaxValue //TODO split into MaxX and MaxY, and rename VirtualPadTargetScreen.RangeX/RangeY
|
||||
RangeY = targetedPair.MaxValue // TODO split into MaxX and MaxY, and rename VirtualPadTargetScreen.RangeX/RangeY
|
||||
},
|
||||
DiscManagerSchema discManager => new VirtualPadDiscManager(discManager.SecondaryNames) {
|
||||
DiscManagerSchema discManager => new VirtualPadDiscManager(_inputManager.StickyXorAdapter, discManager.SecondaryNames) {
|
||||
Name = discManager.Name,
|
||||
Location = UIHelper.Scale(discManager.Location),
|
||||
Size = UIHelper.Scale(discManager.TargetSize),
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
ControllerPanel.Controls.AddRange(padSchemata.Select(s => (Control) new VirtualPad(s)).Reverse().ToArray());
|
||||
ControllerPanel.Controls.AddRange(padSchemata.Select(s => (Control) new VirtualPad(s, InputManager)).Reverse().ToArray());
|
||||
}
|
||||
|
||||
public void ScrollToPadSchema(string padSchemaName)
|
||||
|
@ -181,7 +181,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return null;
|
||||
}
|
||||
|
||||
public IController PreviousFrame()
|
||||
private IController PreviousFrame()
|
||||
{
|
||||
if (MovieSession.Movie.IsPlayingOrRecording() && Emulator.Frame > 1)
|
||||
{
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public partial class VirtualPadAnalogButton : UserControl, IVirtualPadControl
|
||||
{
|
||||
private readonly StickyXorAdapter _stickyXorAdapter;
|
||||
private string _displayName = "";
|
||||
private int _maxValue, _minValue;
|
||||
private bool _programmaticallyChangingValue;
|
||||
|
@ -23,14 +25,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public VirtualPadAnalogButton()
|
||||
public VirtualPadAnalogButton(StickyXorAdapter stickyXorAdapter)
|
||||
{
|
||||
_stickyXorAdapter = stickyXorAdapter;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void UpdateValues()
|
||||
{
|
||||
if (AnalogTrackBar.Value != (int)GlobalWin.InputManager.StickyXorAdapter.AxisValue(Name))
|
||||
if (AnalogTrackBar.Value != _stickyXorAdapter.AxisValue(Name))
|
||||
{
|
||||
RefreshWidgets();
|
||||
}
|
||||
|
@ -38,13 +41,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void Clear()
|
||||
{
|
||||
GlobalWin.InputManager.StickyXorAdapter.Unset(Name);
|
||||
_stickyXorAdapter.Unset(Name);
|
||||
IsSet = false;
|
||||
}
|
||||
|
||||
public void Set(IController controller)
|
||||
{
|
||||
var newVal = (int)controller.AxisValue(Name);
|
||||
var newVal = controller.AxisValue(Name);
|
||||
var changed = AnalogTrackBar.Value != newVal;
|
||||
if (changed)
|
||||
{
|
||||
|
@ -211,7 +214,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (!_programmaticallyChangingValue)
|
||||
{
|
||||
CurrentValue = AnalogTrackBar.Value;
|
||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(Name, AnalogTrackBar.Value);
|
||||
_stickyXorAdapter.SetAxis(Name, AnalogTrackBar.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +223,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (!_isSet)
|
||||
{
|
||||
_programmaticallyChangingValue = true;
|
||||
AnalogTrackBar.Value = (int)GlobalWin.InputManager.StickyXorAdapter.AxisValue(Name);
|
||||
AnalogTrackBar.Value = _stickyXorAdapter.AxisValue(Name);
|
||||
ValueLabel.Text = AnalogTrackBar.Value.ToString();
|
||||
_programmaticallyChangingValue = false;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Sony.PSX;
|
||||
|
||||
|
@ -8,8 +9,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class VirtualPadDiscManager : UserControl, IVirtualPadControl
|
||||
{
|
||||
public VirtualPadDiscManager(IReadOnlyList<string> buttonNames)
|
||||
private readonly StickyXorAdapter _stickyXorAdapter;
|
||||
|
||||
public VirtualPadDiscManager(StickyXorAdapter stickyXorAdapter, IReadOnlyList<string> buttonNames)
|
||||
{
|
||||
_stickyXorAdapter = stickyXorAdapter;
|
||||
InitializeComponent();
|
||||
btnOpen.Name = buttonNames[0];
|
||||
btnClose.Name = buttonNames[1];
|
||||
|
@ -131,7 +135,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void lvDiscs_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
// emergency measure: if no selection, set no disc
|
||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(_discSelectName, lvDiscs.SelectedIndices.Count == 0 ? 0 : lvDiscs.SelectedIndices[0]);
|
||||
_stickyXorAdapter.SetAxis(_discSelectName, lvDiscs.SelectedIndices.Count == 0 ? 0 : lvDiscs.SelectedIndices[0]);
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public partial class VirtualPadTargetScreen : UserControl, IVirtualPadControl
|
||||
{
|
||||
private readonly StickyXorAdapter _stickyXorAdapter;
|
||||
private readonly Pen BlackPen = new Pen(Brushes.Black, 2);
|
||||
private readonly Pen GrayPen = new Pen(Brushes.Gray, 2);
|
||||
private readonly Pen RedPen = new Pen(Brushes.Red, 2);
|
||||
|
@ -19,8 +21,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
private int? _overrideX;
|
||||
private int? _overrideY;
|
||||
|
||||
public VirtualPadTargetScreen()
|
||||
public VirtualPadTargetScreen(StickyXorAdapter stickyXorAdapter)
|
||||
{
|
||||
_stickyXorAdapter = stickyXorAdapter;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
@ -37,8 +40,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void Clear()
|
||||
{
|
||||
GlobalWin.InputManager.StickyXorAdapter.Unset(XName);
|
||||
GlobalWin.InputManager.StickyXorAdapter.Unset(YName);
|
||||
_stickyXorAdapter.Unset(XName);
|
||||
_stickyXorAdapter.Unset(YName);
|
||||
_overrideX = null;
|
||||
_overrideY = null;
|
||||
_isSet = false;
|
||||
|
@ -158,7 +161,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public int X
|
||||
{
|
||||
get => _overrideX ?? (int)(GlobalWin.InputManager.StickyXorAdapter.AxisValue(XName) / MultiplierX);
|
||||
get => _overrideX ?? (int)(_stickyXorAdapter.AxisValue(XName) / MultiplierX);
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
|
@ -175,13 +178,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
XNumeric.Value = XNumeric.Maximum;
|
||||
}
|
||||
|
||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(XName, (int)((float)XNumeric.Value * MultiplierX));
|
||||
_stickyXorAdapter.SetAxis(XName, (int)((float)XNumeric.Value * MultiplierX));
|
||||
_isSet = true;
|
||||
}
|
||||
}
|
||||
public int Y
|
||||
{
|
||||
get => _overrideY ?? (int)(GlobalWin.InputManager.StickyXorAdapter.AxisValue(YName) / MultiplierY);
|
||||
get => _overrideY ?? (int)(_stickyXorAdapter.AxisValue(YName) / MultiplierY);
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
|
@ -197,7 +200,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
YNumeric.Value = YNumeric.Maximum;
|
||||
}
|
||||
|
||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(YName, (int)((float)YNumeric.Value * MultiplierY));
|
||||
_stickyXorAdapter.SetAxis(YName, (int)((float)YNumeric.Value * MultiplierY));
|
||||
_isSet = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue