Convert Virtualpads to IToolFormAutoConfig

This commit is contained in:
adelikat 2015-01-01 18:42:08 +00:00
parent 6ce93c0496
commit 1ee7cfc153
4 changed files with 77 additions and 219 deletions

View File

@ -332,24 +332,15 @@ namespace BizHawk.Client.Common
public Dictionary<string, ToolDialogSettings> CommonToolSettings = new Dictionary<string, ToolDialogSettings>();
public Dictionary<string, Dictionary<string, object>> CustomToolSettings = new Dictionary<string, Dictionary<string, object>>();
#region Cheats
// Cheats
public bool DisableCheatsOnLoad = false;
public bool LoadCheatFileByGame = true;
public bool CheatsAutoSaveOnClose = true;
public RecentFiles RecentCheats = new RecentFiles(8);
#endregion
// TAStudio
public TasStateManagerSettings DefaultTasProjSettings = new TasStateManagerSettings();
// VirtualPad Dialog
public ToolDialogSettings VirtualPadSettings = new ToolDialogSettings();
public bool AutoloadVirtualPad = false;
public bool VirtualPadSticky = true;
public bool VirtualPadClearClearsAnalog = false;
// NES Game Genie Encoder/Decoder
public ToolDialogSettings NesGGSettings = new ToolDialogSettings();
public bool NESGGAutoload = false;

View File

@ -372,11 +372,6 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Tools.LoadGameGenieEc();
}
if (Global.Config.AutoloadVirtualPad)
{
GlobalWin.Tools.Load<VirtualpadTool>();
}
if (Global.Config.DisplayStatusBar == false)
{
MainStatusBar.Visible = false;

View File

@ -36,20 +36,13 @@
this.StickyContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ControllerPanel = new System.Windows.Forms.Panel();
this.PadMenu = new MenuStripEx();
this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.ClearClearsAnalogInputMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.RestoreDefaultSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.PadsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.ClearAllMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.StickyMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SettingsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.ClearClearsAnalogInputMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ControllerBox.SuspendLayout();
this.PadBoxContextMenu.SuspendLayout();
this.PadMenu.SuspendLayout();
@ -75,21 +68,21 @@
this.clearAllToolStripMenuItem,
this.StickyContextMenuItem});
this.PadBoxContextMenu.Name = "PadBoxContextMenu";
this.PadBoxContextMenu.Size = new System.Drawing.Size(136, 48);
this.PadBoxContextMenu.Size = new System.Drawing.Size(143, 48);
this.PadBoxContextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.PadBoxContextMenu_Opening);
//
// clearAllToolStripMenuItem
//
this.clearAllToolStripMenuItem.Name = "clearAllToolStripMenuItem";
this.clearAllToolStripMenuItem.ShortcutKeyDisplayString = "Del";
this.clearAllToolStripMenuItem.Size = new System.Drawing.Size(135, 22);
this.clearAllToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
this.clearAllToolStripMenuItem.Text = "Clear All";
this.clearAllToolStripMenuItem.Click += new System.EventHandler(this.ClearAllMenuItem_Click);
//
// StickyContextMenuItem
//
this.StickyContextMenuItem.Name = "StickyContextMenuItem";
this.StickyContextMenuItem.Size = new System.Drawing.Size(135, 22);
this.StickyContextMenuItem.Size = new System.Drawing.Size(142, 22);
this.StickyContextMenuItem.Text = "Sticky";
this.StickyContextMenuItem.Click += new System.EventHandler(this.StickyMenuItem_Click);
//
@ -106,104 +99,23 @@
//
this.PadMenu.ClickThrough = true;
this.PadMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.OptionsSubMenu,
this.PadsSubMenu});
this.PadsSubMenu,
this.SettingsSubMenu});
this.PadMenu.Location = new System.Drawing.Point(0, 0);
this.PadMenu.Name = "PadMenu";
this.PadMenu.Size = new System.Drawing.Size(452, 24);
this.PadMenu.TabIndex = 7;
this.PadMenu.Text = "menuStrip1";
//
// OptionsSubMenu
//
this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ClearClearsAnalogInputMenuItem,
this.toolStripSeparator3,
this.AutoloadMenuItem,
this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem,
this.FloatingWindowMenuItem,
this.toolStripSeparator2,
this.RestoreDefaultSettingsMenuItem,
this.toolStripSeparator1,
this.ExitMenuItem});
this.OptionsSubMenu.Name = "OptionsSubMenu";
this.OptionsSubMenu.Size = new System.Drawing.Size(56, 20);
this.OptionsSubMenu.Text = "&Options";
this.OptionsSubMenu.DropDownOpened += new System.EventHandler(this.OptionsSubMenu_DropDownOpened);
//
// ClearClearsAnalogInputMenuItem
//
this.ClearClearsAnalogInputMenuItem.Name = "ClearClearsAnalogInputMenuItem";
this.ClearClearsAnalogInputMenuItem.Size = new System.Drawing.Size(195, 22);
this.ClearClearsAnalogInputMenuItem.Text = "&Clear clears Analog Input";
this.ClearClearsAnalogInputMenuItem.Click += new System.EventHandler(this.ClearClearsAnalogInputMenuItem_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(192, 6);
//
// AutoloadMenuItem
//
this.AutoloadMenuItem.Name = "AutoloadMenuItem";
this.AutoloadMenuItem.Size = new System.Drawing.Size(195, 22);
this.AutoloadMenuItem.Text = "&Autoload";
this.AutoloadMenuItem.Click += new System.EventHandler(this.AutoloadMenuItem_Click);
//
// SaveWindowPositionMenuItem
//
this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem";
this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(195, 22);
this.SaveWindowPositionMenuItem.Text = "&Save Window Position";
this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click);
//
// AlwaysOnTopMenuItem
//
this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem";
this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(195, 22);
this.AlwaysOnTopMenuItem.Text = "Always On Top";
this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
//
// FloatingWindowMenuItem
//
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(195, 22);
this.FloatingWindowMenuItem.Text = "Floating Window";
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(192, 6);
//
// RestoreDefaultSettingsMenuItem
//
this.RestoreDefaultSettingsMenuItem.Name = "RestoreDefaultSettingsMenuItem";
this.RestoreDefaultSettingsMenuItem.Size = new System.Drawing.Size(195, 22);
this.RestoreDefaultSettingsMenuItem.Text = "Restore Default Settings";
this.RestoreDefaultSettingsMenuItem.Click += new System.EventHandler(this.RestoreDefaultSettingsMenuItem_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(192, 6);
//
// ExitMenuItem
//
this.ExitMenuItem.Name = "ExitMenuItem";
this.ExitMenuItem.ShortcutKeyDisplayString = "Alt+F4";
this.ExitMenuItem.Size = new System.Drawing.Size(195, 22);
this.ExitMenuItem.Text = "E&xit";
this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click);
//
// PadsSubMenu
//
this.PadsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ClearAllMenuItem,
this.StickyMenuItem});
this.StickyMenuItem,
this.toolStripSeparator4,
this.ExitMenuItem});
this.PadsSubMenu.Name = "PadsSubMenu";
this.PadsSubMenu.Size = new System.Drawing.Size(42, 20);
this.PadsSubMenu.Size = new System.Drawing.Size(44, 20);
this.PadsSubMenu.Text = "&Pads";
this.PadsSubMenu.DropDownOpened += new System.EventHandler(this.PadsSubMenu_DropDownOpened);
//
@ -211,17 +123,46 @@
//
this.ClearAllMenuItem.Name = "ClearAllMenuItem";
this.ClearAllMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;
this.ClearAllMenuItem.Size = new System.Drawing.Size(135, 22);
this.ClearAllMenuItem.Size = new System.Drawing.Size(142, 22);
this.ClearAllMenuItem.Text = "&Clear All";
this.ClearAllMenuItem.Click += new System.EventHandler(this.ClearAllMenuItem_Click);
//
// StickyMenuItem
//
this.StickyMenuItem.Name = "StickyMenuItem";
this.StickyMenuItem.Size = new System.Drawing.Size(135, 22);
this.StickyMenuItem.Size = new System.Drawing.Size(142, 22);
this.StickyMenuItem.Text = "Sticky";
this.StickyMenuItem.Click += new System.EventHandler(this.StickyMenuItem_Click);
//
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(139, 6);
//
// ExitMenuItem
//
this.ExitMenuItem.Name = "ExitMenuItem";
this.ExitMenuItem.ShortcutKeyDisplayString = "Alt+F4";
this.ExitMenuItem.Size = new System.Drawing.Size(142, 22);
this.ExitMenuItem.Text = "E&xit";
this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click);
//
// SettingsSubMenu
//
this.SettingsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ClearClearsAnalogInputMenuItem});
this.SettingsSubMenu.Name = "SettingsSubMenu";
this.SettingsSubMenu.Size = new System.Drawing.Size(61, 20);
this.SettingsSubMenu.Text = "&Settings";
this.SettingsSubMenu.DropDownOpened += new System.EventHandler(this.OptionsSubMenu_DropDownOpened);
//
// ClearClearsAnalogInputMenuItem
//
this.ClearClearsAnalogInputMenuItem.Name = "ClearClearsAnalogInputMenuItem";
this.ClearClearsAnalogInputMenuItem.Size = new System.Drawing.Size(230, 22);
this.ClearClearsAnalogInputMenuItem.Text = "&Clear also clears Analog Input";
this.ClearClearsAnalogInputMenuItem.Click += new System.EventHandler(this.ClearClearsAnalogInputMenuItem_Click);
//
// VirtualpadTool
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -245,15 +186,7 @@
#endregion
private MenuStripEx PadMenu;
private System.Windows.Forms.ToolStripMenuItem OptionsSubMenu;
private System.Windows.Forms.ToolStripMenuItem AutoloadMenuItem;
private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem RestoreDefaultSettingsMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem ExitMenuItem;
private System.Windows.Forms.ToolStripMenuItem SettingsSubMenu;
private System.Windows.Forms.ToolStripMenuItem PadsSubMenu;
private System.Windows.Forms.ToolStripMenuItem ClearAllMenuItem;
private System.Windows.Forms.GroupBox ControllerBox;
@ -262,7 +195,8 @@
private System.Windows.Forms.ToolStripMenuItem clearAllToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem StickyContextMenuItem;
private System.Windows.Forms.ToolStripMenuItem ClearClearsAnalogInputMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.Panel ControllerPanel;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripMenuItem ExitMenuItem;
}
}

View File

@ -9,10 +9,8 @@ using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class VirtualpadTool : Form, IToolForm
public partial class VirtualpadTool : Form, IToolFormAutoConfig
{
private int _defaultWidth;
private int _defaultHeight;
private bool _readOnly;
private List<VirtualPad> Pads
@ -39,34 +37,27 @@ namespace BizHawk.Client.EmuHawk
}
}
[ConfigPersist]
public bool StickyPads { get; set; }
[ConfigPersist]
public bool ClearAlsoClearsAnalog { get; set; }
public VirtualpadTool()
{
StickyPads = true;
InitializeComponent();
Closing += (o, e) => SaveConfigSettings();
TopMost = Global.Config.VirtualPadSettings.TopMost;
}
private void VirtualpadTool_Load(object sender, EventArgs e)
{
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Global.Config.VirtualPadSettings.UseWindowPosition)
{
Location = Global.Config.VirtualPadSettings.WindowPosition;
}
if (Global.Config.VirtualPadSettings.UseWindowPosition)
{
Size = Global.Config.VirtualPadSettings.WindowSize;
}
CreatePads();
}
public void ClearVirtualPadHolds()
{
if (Global.Config.VirtualPadClearClearsAnalog)
if (ClearAlsoClearsAnalog)
{
Pads.ForEach(pad => pad.Clear());
}
@ -159,19 +150,6 @@ namespace BizHawk.Client.EmuHawk
}
}
private void SaveConfigSettings()
{
Global.Config.VirtualPadSettings.Wndx = Location.X;
Global.Config.VirtualPadSettings.Wndy = Location.Y;
Global.Config.VirtualPadSettings.Width = Right - Left;
Global.Config.VirtualPadSettings.Height = Bottom - Top;
}
private void RefreshFloatingWindowControl()
{
Owner = Global.Config.VirtualPadSettings.FloatingWindow ? null : GlobalWin.MainForm;
}
#region IToolForm Implementation
public bool AskSaveChanges() { return true; }
@ -211,7 +189,7 @@ namespace BizHawk.Client.EmuHawk
Readonly = false;
}
if (!Readonly && !Global.Config.VirtualPadSticky)
if (!Readonly && !StickyPads)
{
Pads.ForEach(pad => pad.Clear());
}
@ -223,7 +201,7 @@ namespace BizHawk.Client.EmuHawk
{
// TODO: SetPrevious logic should go here too or that will get out of whack
if (!Readonly && !Global.Config.VirtualPadSticky)
if (!Readonly && !StickyPads)
{
Pads.ForEach(pad => pad.Clear());
}
@ -231,64 +209,11 @@ namespace BizHawk.Client.EmuHawk
#endregion
#region Events
#region Menu
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
{
AutoloadMenuItem.Checked = Global.Config.AutoloadVirtualPad;
SaveWindowPositionMenuItem.Checked = Global.Config.VirtualPadSettings.SaveWindowPosition;
AlwaysOnTopMenuItem.Checked = Global.Config.VirtualPadSettings.TopMost;
FloatingWindowMenuItem.Checked = Global.Config.VirtualPadSettings.FloatingWindow;
ClearClearsAnalogInputMenuItem.Checked = Global.Config.VirtualPadClearClearsAnalog;
}
private void ClearClearsAnalogInputMenuItem_Click(object sender, EventArgs e)
{
Global.Config.VirtualPadClearClearsAnalog ^= true;
}
private void AutoloadMenuItem_Click(object sender, EventArgs e)
{
Global.Config.AutoloadVirtualPad ^= true;
}
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.VirtualPadSettings.SaveWindowPosition ^= true;
}
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
{
Global.Config.VirtualPadSettings.TopMost ^= true;
TopMost = Global.Config.VirtualPadSettings.TopMost;
}
private void FloatingWindowMenuItem_Click(object sender, EventArgs e)
{
Global.Config.VirtualPadSettings.FloatingWindow ^= true;
RefreshFloatingWindowControl();
}
private void RestoreDefaultSettingsMenuItem_Click(object sender, EventArgs e)
{
Size = new Size(_defaultWidth, _defaultHeight);
Global.Config.VirtualPadSettings.SaveWindowPosition = true;
Global.Config.VirtualPadSettings.TopMost = TopMost = false;
Global.Config.VirtualPadSettings.FloatingWindow = false;
Global.Config.VirtualPadClearClearsAnalog = false;
}
private void ExitMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void PadsSubMenu_DropDownOpened(object sender, EventArgs e)
{
StickyMenuItem.Checked = Global.Config.VirtualPadSticky;
StickyMenuItem.Checked = StickyPads;
}
private void ClearAllMenuItem_Click(object sender, EventArgs e)
@ -298,15 +223,28 @@ namespace BizHawk.Client.EmuHawk
private void StickyMenuItem_Click(object sender, EventArgs e)
{
Global.Config.VirtualPadSticky ^= true;
StickyPads ^= true;
}
private void PadBoxContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
StickyContextMenuItem.Checked = Global.Config.VirtualPadSticky;
StickyContextMenuItem.Checked = StickyPads;
}
#endregion
private void ExitMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
{
ClearClearsAnalogInputMenuItem.Checked = ClearAlsoClearsAnalog;
}
private void ClearClearsAnalogInputMenuItem_Click(object sender, EventArgs e)
{
ClearAlsoClearsAnalog ^= true;
}
#endregion
}