pass InputManager to tools, remove other usages of GlobalWin in various tools
This commit is contained in:
parent
20a1a49851
commit
728a946470
|
@ -309,7 +309,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
GlobalWin.Game = GameInfo.NullInstance;
|
||||
_throttle = new Throttle();
|
||||
Emulator = new NullEmulator();
|
||||
GlobalWin.Tools = new ToolManager(this, Config, Emulator, MovieSession, Game);
|
||||
GlobalWin.Tools = new ToolManager(this, Config, InputManager, Emulator, MovieSession, Game);
|
||||
|
||||
UpdateStatusSlots();
|
||||
UpdateKeyPriorityIcon();
|
||||
|
|
|
@ -752,7 +752,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
foreach (var button in controller.Definition.BoolButtons)
|
||||
{
|
||||
// TODO: make an input adapter specifically for the bot?
|
||||
GlobalWin.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button));
|
||||
InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -890,7 +890,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
double probability = _cachedControlProbabilities[button];
|
||||
bool pressed = !(rand.Next(100) < probability);
|
||||
|
||||
GlobalWin.InputManager.ClickyVirtualPadController.SetBool(button, pressed);
|
||||
InputManager.ClickyVirtualPadController.SetBool(button, pressed);
|
||||
}
|
||||
|
||||
_currentBotAttempt.Log.Add(_logGenerator.GenerateLogEntry());
|
||||
|
@ -943,7 +943,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
UpdateBotStatusIcon();
|
||||
MessageLabel.Text = "Running...";
|
||||
_cachedControlProbabilities = ControlProbabilities;
|
||||
_logGenerator = MovieSession.Movie.LogGeneratorInstance(GlobalWin.InputManager.ClickyVirtualPadController);
|
||||
_logGenerator = MovieSession.Movie.LogGeneratorInstance(InputManager.ClickyVirtualPadController);
|
||||
}
|
||||
|
||||
private string CanStart()
|
||||
|
|
|
@ -267,12 +267,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
if ((SelectedButton != "Default float Auto-Fire") && (SelectedButton != "Default bool Auto-Fire"))
|
||||
{
|
||||
_tastudio.UpdateAutoFire(SelectedButton, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetPattern()
|
||||
{
|
||||
int index = GlobalWin.MovieSession.MovieController.Definition.BoolButtons.IndexOf(SelectedButton);
|
||||
int index = _tastudio.MovieSession.MovieController.Definition.BoolButtons.IndexOf(SelectedButton);
|
||||
|
||||
if (SelectedButton == "Default bool Auto-Fire")
|
||||
{
|
||||
|
|
|
@ -479,7 +479,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
AutoPatternBool p = BoolPatterns[index];
|
||||
GlobalWin.InputManager.AutofireStickyXorAdapter.SetSticky(button, isOn.Value, p);
|
||||
InputManager.AutofireStickyXorAdapter.SetSticky(button, isOn.Value, p);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -499,7 +499,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
AutoPatternAxis p = AxisPatterns[index];
|
||||
GlobalWin.InputManager.AutofireStickyXorAdapter.SetAxis(button, value, p);
|
||||
InputManager.AutofireStickyXorAdapter.SetAxis(button, value, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -470,7 +470,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
foreach (var column in TasView.VisibleColumns)
|
||||
{
|
||||
if (GlobalWin.InputManager.StickyXorAdapter.IsSticky(column.Name))
|
||||
if (InputManager.StickyXorAdapter.IsSticky(column.Name))
|
||||
{
|
||||
column.Emphasis = true;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void KeyClick(string name)
|
||||
{
|
||||
GlobalWin.InputManager.ClickyVirtualPadController.Click(name);
|
||||
InputManager.ClickyVirtualPadController.Click(name);
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public ToolManager Tools { get; set; }
|
||||
public Config Config { get; set; }
|
||||
public InputManager InputManager { get; set; }
|
||||
public IMainFormForTools MainForm { get; set; }
|
||||
|
||||
public IMovieSession MovieSession { get; set; }
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
private readonly MainForm _owner;
|
||||
private readonly Config _config;
|
||||
private readonly InputManager _inputManager;
|
||||
private IExternalApiProvider _apiProvider;
|
||||
private IEmulator _emulator;
|
||||
private IMovieSession _movieSession;
|
||||
|
@ -36,12 +37,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
public ToolManager(
|
||||
MainForm owner,
|
||||
Config config,
|
||||
InputManager inputManager,
|
||||
IEmulator emulator,
|
||||
IMovieSession movieSession,
|
||||
IGameInfo game)
|
||||
{
|
||||
_owner = owner;
|
||||
_config = config;
|
||||
_inputManager = inputManager;
|
||||
_emulator = emulator;
|
||||
_movieSession = movieSession;
|
||||
_game = game;
|
||||
|
@ -75,6 +78,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
tool.Tools = this;
|
||||
tool.Config = _config;
|
||||
tool.InputManager = _inputManager;
|
||||
tool.MainForm = _owner;
|
||||
tool.MovieSession = _movieSession;
|
||||
tool.Game = _game;
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
MaxValue = singleAxis.MaxValue,
|
||||
Orientation = singleAxis.Orientation
|
||||
},
|
||||
AnalogSchema analog => new VirtualPadAnalogStick
|
||||
AnalogSchema analog => new VirtualPadAnalogStick(GlobalWin.InputManager)
|
||||
{
|
||||
Name = analog.Name,
|
||||
SecondaryName = analog.SecondaryName,
|
||||
|
|
|
@ -145,14 +145,10 @@
|
|||
//
|
||||
this.AnalogStick.BackColor = System.Drawing.Color.Gray;
|
||||
this.AnalogStick.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.AnalogStick.ClearCallback = null;
|
||||
this.AnalogStick.Location = new System.Drawing.Point(3, 3);
|
||||
this.AnalogStick.Name = "AnalogStick";
|
||||
this.AnalogStick.ReadOnly = false;
|
||||
this.AnalogStick.Size = new System.Drawing.Size(164, 164);
|
||||
this.AnalogStick.TabIndex = 0;
|
||||
this.AnalogStick.X = 0;
|
||||
this.AnalogStick.Y = 0;
|
||||
this.AnalogStick.MouseDown += new System.Windows.Forms.MouseEventHandler(this.AnalogStick_MouseDown);
|
||||
this.AnalogStick.MouseMove += new System.Windows.Forms.MouseEventHandler(this.AnalogStick_MouseMove);
|
||||
//
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class VirtualPadAnalogStick : UserControl, IVirtualPadControl
|
||||
{
|
||||
private readonly InputManager _inputManager;
|
||||
private bool _readonly;
|
||||
|
||||
private bool _updatingFromAnalog;
|
||||
|
@ -19,8 +20,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private bool _updatingFromXY;
|
||||
|
||||
public VirtualPadAnalogStick()
|
||||
public VirtualPadAnalogStick(InputManager inputManager)
|
||||
{
|
||||
_inputManager = inputManager;
|
||||
InitializeComponent();
|
||||
AnalogStick.ClearCallback = ClearCallback;
|
||||
|
||||
|
@ -39,6 +41,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
|
||||
{
|
||||
AnalogStick.Init(
|
||||
_inputManager.StickyXorAdapter,
|
||||
Name,
|
||||
RangeX,
|
||||
!string.IsNullOrEmpty(SecondaryName) ? SecondaryName : Name.Replace("X", "Y"),
|
||||
|
@ -77,11 +80,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
ManualY.Value = 0;
|
||||
manualR.Value = 0;
|
||||
manualTheta.Value = 0;
|
||||
//see HOOMOO
|
||||
GlobalWin.InputManager.AutofireStickyXorAdapter.SetSticky(AnalogStick.XName, false);
|
||||
GlobalWin.InputManager.StickyXorAdapter.Unset(AnalogStick.XName);
|
||||
GlobalWin.InputManager.AutofireStickyXorAdapter.SetSticky(AnalogStick.YName, false);
|
||||
GlobalWin.InputManager.StickyXorAdapter.Unset(AnalogStick.YName);
|
||||
_inputManager.AutofireStickyXorAdapter.SetSticky(AnalogStick.XName, false);
|
||||
_inputManager.StickyXorAdapter.Unset(AnalogStick.XName);
|
||||
_inputManager.AutofireStickyXorAdapter.SetSticky(AnalogStick.YName, false);
|
||||
_inputManager.StickyXorAdapter.Unset(AnalogStick.YName);
|
||||
AnalogStick.HasValue = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -171,9 +171,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) => true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.NumberExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
@ -10,9 +11,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public sealed class AnalogStickPanel : Panel
|
||||
{
|
||||
private StickyXorAdapter _stickyXorAdapter;
|
||||
private int _x;
|
||||
private int _y;
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public int X
|
||||
{
|
||||
get => _x;
|
||||
|
@ -23,6 +26,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public int Y
|
||||
{
|
||||
get => _y;
|
||||
|
@ -33,7 +37,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public bool HasValue;
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public bool HasValue { get; set; }
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public bool ReadOnly { private get; set; }
|
||||
|
||||
public string XName { get; private set; } = string.Empty;
|
||||
|
@ -53,8 +60,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
Refresh();
|
||||
}
|
||||
|
||||
public void Init(string nameX, AxisSpec rangeX, string nameY, AxisSpec rangeY)
|
||||
public void Init(StickyXorAdapter stickyXorAdapter, string nameX, AxisSpec rangeX, string nameY, AxisSpec rangeY)
|
||||
{
|
||||
_stickyXorAdapter = stickyXorAdapter;
|
||||
Name = XName = nameX;
|
||||
_fullRangeX = rangeX;
|
||||
YName = nameY;
|
||||
|
@ -127,13 +135,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
private readonly Bitmap _dot = new Bitmap(7, 7);
|
||||
private readonly Bitmap _grayDot = new Bitmap(7, 7);
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public Action ClearCallback { private get; set; }
|
||||
|
||||
private void DoClearCallback()
|
||||
{
|
||||
ClearCallback?.Invoke();
|
||||
}
|
||||
|
||||
public AnalogStickPanel()
|
||||
{
|
||||
Size = new Size(PixelSizeX + 1, PixelSizeY + 1);
|
||||
|
@ -163,8 +167,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void SetAnalog()
|
||||
{
|
||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(XName, HasValue ? X : (int?)null);
|
||||
GlobalWin.InputManager.StickyXorAdapter.SetAxis(YName, HasValue ? Y : (int?)null);
|
||||
_stickyXorAdapter.SetAxis(XName, HasValue ? X : (int?)null);
|
||||
_stickyXorAdapter.SetAxis(YName, HasValue ? Y : (int?)null);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
@ -184,8 +188,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
// Previous frame
|
||||
if (_previous != null)
|
||||
{
|
||||
var pX = (int)_previous.AxisValue(XName);
|
||||
var pY = (int)_previous.AxisValue(YName);
|
||||
var pX = _previous.AxisValue(XName);
|
||||
var pY = _previous.AxisValue(YName);
|
||||
e.Graphics.DrawLine(_grayPen, PixelMidX, PixelMidY, RealToGfxX(pX), RealToGfxY(pY));
|
||||
e.Graphics.DrawImage(_grayDot, RealToGfxX(pX) - 3, RealToGfxY(_rangeY.EndInclusive) - RealToGfxY(pY) - 3);
|
||||
}
|
||||
|
@ -255,14 +259,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (!HasValue && X == 0 && Y == 0) return;
|
||||
X = Y = 0;
|
||||
HasValue = false;
|
||||
DoClearCallback();
|
||||
ClearCallback?.Invoke();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Set(IController controller)
|
||||
{
|
||||
var newX = (int) controller.AxisValue(XName);
|
||||
var newY = (int) controller.AxisValue(YName);
|
||||
var newX = controller.AxisValue(XName);
|
||||
var newY = controller.AxisValue(YName);
|
||||
if (newX != X || newY != Y) SetPosition(newX, newY);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue