MacroInput - less global, cleanup
This commit is contained in:
parent
897bc0572e
commit
87cd264ed2
|
@ -18,88 +18,81 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
for (int i = 0; i < def.FloatControls.Count; i++)
|
||||
{
|
||||
CheckBox box = new CheckBox();
|
||||
box.Text = def.FloatControls[i];
|
||||
CheckBox box = new CheckBox {Text = def.FloatControls[i]};
|
||||
_buttonBoxes[i] = box;
|
||||
}
|
||||
for (int i = 0; i < def.BoolButtons.Count; i++)
|
||||
{
|
||||
CheckBox box = new CheckBox();
|
||||
box.Text = def.BoolButtons[i];
|
||||
CheckBox box = new CheckBox {Text = def.BoolButtons[i]};
|
||||
_buttonBoxes[i + def.FloatControls.Count] = box;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _buttonBoxes.Length; i++)
|
||||
foreach (var box in _buttonBoxes)
|
||||
{
|
||||
_buttonBoxes[i].Parent = this;
|
||||
_buttonBoxes[i].AutoSize = true;
|
||||
_buttonBoxes[i].Checked = true;
|
||||
_buttonBoxes[i].CheckedChanged += ButtonBox_CheckedChanged;
|
||||
box.Parent = this;
|
||||
box.AutoSize = true;
|
||||
box.Checked = true;
|
||||
box.CheckedChanged += ButtonBox_CheckedChanged;
|
||||
}
|
||||
|
||||
PositionBoxes();
|
||||
}
|
||||
|
||||
private bool _setting = false;
|
||||
private void ButtonBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null || _setting)
|
||||
if (SelectedZone == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CheckBox s = sender as CheckBox;
|
||||
CheckBox s = (CheckBox)sender;
|
||||
s.ForeColor = s.Checked ? SystemColors.ControlText : SystemColors.ButtonShadow;
|
||||
s.Refresh();
|
||||
|
||||
// Update the selected zone's key
|
||||
var lg = Global.MovieSession.LogGeneratorInstance() as Bk2LogEntryGenerator;
|
||||
var lg = (Bk2LogEntryGenerator)Global.MovieSession.LogGeneratorInstance();
|
||||
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
|
||||
string key = lg.GenerateLogKey();
|
||||
key = key.Replace("LogKey:", "").Replace("#", "");
|
||||
|
||||
for (int i = 0; i < _buttonBoxes.Length; i++)
|
||||
foreach (var box in _buttonBoxes)
|
||||
{
|
||||
if (!_buttonBoxes[i].Checked)
|
||||
key = key.Replace($"{_buttonBoxes[i].Text}|", "");
|
||||
if (!box.Checked)
|
||||
{
|
||||
key = key.Replace($"{box.Text}|", "");
|
||||
}
|
||||
}
|
||||
|
||||
key = key.Substring(0, key.Length - 1);
|
||||
|
||||
selectedZone.InputKey = key;
|
||||
}
|
||||
private void SetButtonBoxes()
|
||||
{
|
||||
if (selectedZone == null)
|
||||
return;
|
||||
|
||||
_setting = true;
|
||||
for (int i = 0; i < _buttonBoxes.Length; i++)
|
||||
_buttonBoxes[i].Checked = selectedZone.InputKey.Contains(_buttonBoxes[i].Text);
|
||||
_setting = false;
|
||||
SelectedZone.InputKey = key;
|
||||
}
|
||||
|
||||
private void PositionBoxes()
|
||||
{
|
||||
int X = this.ClientSize.Width - 3;
|
||||
int Y = this.ClientSize.Height - _buttonBoxes[0].Height - 3;
|
||||
int x = ClientSize.Width - 3;
|
||||
int y = ClientSize.Height - _buttonBoxes[0].Height - 3;
|
||||
|
||||
for (int i = _buttonBoxes.Length - 1; i >= 0; i--)
|
||||
{
|
||||
X -= _buttonBoxes[i].Width;
|
||||
if (X <= 3)
|
||||
x -= _buttonBoxes[i].Width;
|
||||
if (x <= 3)
|
||||
{
|
||||
X = this.ClientSize.Width - 3 - _buttonBoxes[i].Width;
|
||||
Y -= (_buttonBoxes[0].Height + 6);
|
||||
x = ClientSize.Width - 3 - _buttonBoxes[i].Width;
|
||||
y -= (_buttonBoxes[0].Height + 6);
|
||||
}
|
||||
|
||||
_buttonBoxes[i].Location = new Point(X, Y);
|
||||
_buttonBoxes[i].Location = new Point(x, y);
|
||||
}
|
||||
}
|
||||
private void MacroInputTool_Resize(object sender, EventArgs e)
|
||||
{
|
||||
if (_initializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PositionBoxes();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -82,14 +82,14 @@
|
|||
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
|
||||
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(170, 22);
|
||||
this.saveAsToolStripMenuItem.Text = "Save Selected As...";
|
||||
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
|
||||
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.SaveAsToolStripMenuItem_Click);
|
||||
//
|
||||
// loadMacroToolStripMenuItem
|
||||
//
|
||||
this.loadMacroToolStripMenuItem.Name = "loadMacroToolStripMenuItem";
|
||||
this.loadMacroToolStripMenuItem.Size = new System.Drawing.Size(170, 22);
|
||||
this.loadMacroToolStripMenuItem.Text = "Load Macro...";
|
||||
this.loadMacroToolStripMenuItem.Click += new System.EventHandler(this.loadMacroToolStripMenuItem_Click);
|
||||
this.loadMacroToolStripMenuItem.Click += new System.EventHandler(this.LoadMacroToolStripMenuItem_Click);
|
||||
//
|
||||
// RecentToolStripMenuItem
|
||||
//
|
||||
|
@ -127,7 +127,7 @@
|
|||
this.NameTextbox.Size = new System.Drawing.Size(99, 20);
|
||||
this.NameTextbox.TabIndex = 4;
|
||||
this.NameTextbox.Text = "Zone 0";
|
||||
this.NameTextbox.TextChanged += new System.EventHandler(this.NameTextbox_TextChanged);
|
||||
this.NameTextbox.TextChanged += new System.EventHandler(this.NameTextBox_TextChanged);
|
||||
//
|
||||
// ReplaceBox
|
||||
//
|
||||
|
|
|
@ -11,21 +11,21 @@ using BizHawk.Client.EmuHawk.ToolExtensions;
|
|||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[Tool(false, null)]
|
||||
public partial class MacroInputTool : Form, IToolFormAutoConfig
|
||||
public partial class MacroInputTool : ToolFormBase, IToolFormAutoConfig
|
||||
{
|
||||
[RequiredService]
|
||||
private IEmulator Emulator { get; set; }
|
||||
|
||||
private readonly List<MovieZone> _zones = new List<MovieZone>();
|
||||
private readonly List<int> _unsavedZones = new List<int>();
|
||||
private bool _selecting = false;
|
||||
private bool _selecting;
|
||||
|
||||
private IMovie CurrentMovie => Global.MovieSession.Movie;
|
||||
|
||||
// Still need to make sure the user can't load and use macros that
|
||||
// have options only available for TasMovie
|
||||
|
||||
private bool _initializing = false;
|
||||
private bool _initializing;
|
||||
public MacroInputTool()
|
||||
{
|
||||
_initializing = true;
|
||||
|
@ -36,7 +36,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
// Movie recording must be active (check TAStudio because opening a project re-loads the ROM,
|
||||
// which resets tools before the movie session becomes active)
|
||||
if (!Global.MovieSession.Movie.IsActive() && !GlobalWin.Tools.IsLoaded<TAStudio>())
|
||||
if (!CurrentMovie.IsActive() && !Tools.IsLoaded<TAStudio>())
|
||||
{
|
||||
MessageBox.Show("In order to use this tool you must be recording a movie.");
|
||||
Close();
|
||||
|
@ -101,10 +101,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
}
|
||||
|
||||
public bool UpdateBefore
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool UpdateBefore => true;
|
||||
|
||||
public bool AskSaveChanges()
|
||||
{
|
||||
|
@ -112,22 +109,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
DialogResult result = MessageBox.Show("You have unsaved macro(s). Do you wish to save them?", "Save?", MessageBoxButtons.YesNoCancel);
|
||||
if (result == DialogResult.Cancel)
|
||||
{
|
||||
DialogResult result = MessageBox.Show("You have unsaved macro(s). Do you wish to save them?", "Save?", MessageBoxButtons.YesNoCancel);
|
||||
if (result == DialogResult.Cancel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (result == DialogResult.No)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _unsavedZones.Count; i++)
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
SaveMacroAs(_zones[_unsavedZones[i]]);
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var zone in _unsavedZones)
|
||||
{
|
||||
SaveMacroAs(_zones[zone]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -146,81 +142,72 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
var newZone = new MovieZone(CurrentMovie, (int)StartNum.Value, (int)(EndNum.Value - StartNum.Value + 1));
|
||||
newZone.Name = $"Zone {_zones.Count}";
|
||||
var newZone = new MovieZone(CurrentMovie, (int) StartNum.Value, (int) (EndNum.Value - StartNum.Value + 1))
|
||||
{
|
||||
Name = $"Zone {_zones.Count}"
|
||||
};
|
||||
_zones.Add(newZone);
|
||||
ZonesList.Items.Add($"{newZone.Name} - length: {newZone.Length}");
|
||||
|
||||
_unsavedZones.Add(ZonesList.Items.Count - 1);
|
||||
}
|
||||
|
||||
private MovieZone selectedZone
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ZonesList.SelectedIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _zones[ZonesList.SelectedIndex];
|
||||
}
|
||||
}
|
||||
private MovieZone SelectedZone => ZonesList.SelectedIndex == -1 ? null : _zones[ZonesList.SelectedIndex];
|
||||
|
||||
private void ZonesList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null)
|
||||
if (SelectedZone == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_selecting = true;
|
||||
PlaceNum.Value = selectedZone.Start;
|
||||
ReplaceBox.Checked = selectedZone.Replace;
|
||||
NameTextbox.Text = selectedZone.Name;
|
||||
OverlayBox.Checked = selectedZone.Overlay;
|
||||
PlaceNum.Value = SelectedZone.Start;
|
||||
ReplaceBox.Checked = SelectedZone.Replace;
|
||||
NameTextbox.Text = SelectedZone.Name;
|
||||
OverlayBox.Checked = SelectedZone.Overlay;
|
||||
_selecting = false;
|
||||
}
|
||||
|
||||
private void NameTextbox_TextChanged(object sender, EventArgs e)
|
||||
private void NameTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null || _selecting)
|
||||
if (SelectedZone == null || _selecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
selectedZone.Name = NameTextbox.Text;
|
||||
ZonesList.Items[ZonesList.SelectedIndex] = $"{selectedZone.Name} - length: {selectedZone.Length}";
|
||||
SelectedZone.Name = NameTextbox.Text;
|
||||
ZonesList.Items[ZonesList.SelectedIndex] = $"{SelectedZone.Name} - length: {SelectedZone.Length}";
|
||||
}
|
||||
|
||||
private void PlaceNum_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null || _selecting)
|
||||
if (SelectedZone == null || _selecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
selectedZone.Start = (int)PlaceNum.Value;
|
||||
SelectedZone.Start = (int)PlaceNum.Value;
|
||||
}
|
||||
|
||||
private void ReplaceBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null || _selecting)
|
||||
if (SelectedZone == null || _selecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
selectedZone.Replace = ReplaceBox.Checked;
|
||||
SelectedZone.Replace = ReplaceBox.Checked;
|
||||
}
|
||||
|
||||
private void OverlayBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null || _selecting)
|
||||
if (SelectedZone == null || _selecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
selectedZone.Overlay = OverlayBox.Checked;
|
||||
SelectedZone.Overlay = OverlayBox.Checked;
|
||||
}
|
||||
|
||||
private void CurrentButton_Click(object sender, EventArgs e)
|
||||
|
@ -230,34 +217,34 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void PlaceZoneButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null)
|
||||
if (SelectedZone == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(CurrentMovie is TasMovie))
|
||||
{
|
||||
selectedZone.Start = Emulator.Frame;
|
||||
SelectedZone.Start = Emulator.Frame;
|
||||
}
|
||||
|
||||
selectedZone.PlaceZone(CurrentMovie);
|
||||
SelectedZone.PlaceZone(CurrentMovie);
|
||||
}
|
||||
|
||||
#region Menu Items
|
||||
|
||||
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedZone == null)
|
||||
if (SelectedZone == null)
|
||||
{
|
||||
MessageBox.Show("Please select a zone first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (SaveMacroAs(selectedZone))
|
||||
if (SaveMacroAs(SelectedZone))
|
||||
_unsavedZones.Remove(ZonesList.SelectedIndex);
|
||||
}
|
||||
|
||||
private void loadMacroToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void LoadMacroToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MovieZone loadZone = LoadMacro();
|
||||
if (loadZone != null)
|
||||
|
@ -278,7 +265,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentToolStripMenuItem.DropDownItems.Clear();
|
||||
RecentToolStripMenuItem.DropDownItems.AddRange(
|
||||
Global.Config.RecentMacros.RecentMenu(DummyLoadMacro, true));
|
||||
Config.RecentMacros.RecentMenu(DummyLoadMacro, true));
|
||||
}
|
||||
|
||||
private void DummyLoadMacro(string path)
|
||||
|
@ -288,16 +275,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
ZonesList.Items.Add($"{loadZone.Name} - length: {loadZone.Length}");
|
||||
}
|
||||
|
||||
private static string SuggestedFolder()
|
||||
private string SuggestedFolder()
|
||||
{
|
||||
return PathManager.MakeAbsolutePath(Path.Combine(
|
||||
Global.Config.PathEntries["Global", "Macros"].Path,
|
||||
Config.PathEntries["Global", "Macros"].Path,
|
||||
PathManager.FilesystemSafeName(Global.Game)), null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static bool SaveMacroAs(MovieZone macro)
|
||||
public bool SaveMacroAs(MovieZone macro)
|
||||
{
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
|
@ -326,12 +313,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
macro.Save(dialog.FileName);
|
||||
Global.Config.RecentMacros.Add(dialog.FileName);
|
||||
Config.RecentMacros.Add(dialog.FileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static MovieZone LoadMacro()
|
||||
public MovieZone LoadMacro()
|
||||
{
|
||||
using var dialog = new OpenFileDialog
|
||||
{
|
||||
|
@ -345,7 +332,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return null;
|
||||
}
|
||||
|
||||
Global.Config.RecentMacros.Add(dialog.FileName);
|
||||
Config.RecentMacros.Add(dialog.FileName);
|
||||
return new MovieZone(dialog.FileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -243,7 +243,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
TasView.FirstSelectedIndex ?? 0,
|
||||
TasView.LastSelectedIndex ?? 0 - TasView.FirstSelectedIndex ?? 0 + 1);
|
||||
|
||||
MacroInputTool.SaveMacroAs(macro);
|
||||
new MacroInputTool().SaveMacroAs(macro);
|
||||
}
|
||||
|
||||
private void PlaceMacroAtSelectionMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -253,7 +253,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
var macro = MacroInputTool.LoadMacro();
|
||||
var macro = new MacroInputTool().LoadMacro();
|
||||
if (macro != null)
|
||||
{
|
||||
macro.Start = TasView.FirstSelectedIndex ?? 0;
|
||||
|
|
Loading…
Reference in New Issue