From 728a946470c11aa68ddb8950f91776b03ec88cd0 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 3 Jul 2020 14:26:08 -0500 Subject: [PATCH] pass InputManager to tools, remove other usages of GlobalWin in various tools --- src/BizHawk.Client.EmuHawk/MainForm.cs | 2 +- .../tools/BasicBot/BasicBot.cs | 6 ++-- .../tools/TAStudio/PatternsForm.cs | 4 +-- .../tools/TAStudio/TAStudio.ListView.cs | 4 +-- .../tools/TAStudio/TAStudio.cs | 2 +- .../tools/TI83/TI83KeyPad.cs | 2 +- .../tools/ToolFormBase.cs | 1 + .../tools/ToolManager.cs | 4 +++ .../tools/VirtualPads/VirtualPad.cs | 2 +- .../VirtualPadAnalogStick.Designer.cs | 4 --- .../controls/VirtualPadAnalogStick.cs | 14 ++++---- .../VirtualPads/controls/VirtualPadButton.cs | 5 +-- .../controls/components/AnalogStickPanel.cs | 34 +++++++++++-------- 13 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 1529e2cfe1..8fbf8a67e0 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -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(); diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 278167b034..709b922330 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -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() diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs index 7489f2b2f2..8a88802be2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs @@ -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") { diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index ebccdd8157..38468f0f34 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -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); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index df6afcda83..04e3670fdc 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -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; } diff --git a/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs b/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs index d658c3a147..5ff0eb22a0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs @@ -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() diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs index 072b21081a..5e66a22448 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs @@ -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; } diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 1c83a5db7e..0d76dc938a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -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; diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs index e215de69b6..54c4143da5 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs @@ -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, diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.Designer.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.Designer.cs index b5ac44cf6c..9d1c6b2015 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.Designer.cs @@ -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); // diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs index dfcbf5e54e..cd6438c57d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs @@ -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; } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadButton.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadButton.cs index f5a8d8b196..8a36d5a23c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadButton.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadButton.cs @@ -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; } } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs index 3a76bffd84..949ed4d211 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs @@ -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); }