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