GlobalWin.Cheatlist begone

This commit is contained in:
adelikat 2020-06-12 13:39:20 -05:00
parent eb811b7d79
commit ac54318cfb
7 changed files with 26 additions and 50 deletions

View File

@ -234,19 +234,6 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions
GlobalWin.Sound.StartSound();
}
public static void FreezeAll(this IEnumerable<Watch> watches)
{
GlobalWin.CheatList.AddRange(
watches
.Where(w => !w.IsSeparator)
.Select(w => new Cheat(w, w.Value)));
}
public static void UnfreezeAll(this IEnumerable<Watch> watches)
{
GlobalWin.CheatList.RemoveRange(watches.Where(watch => !watch.IsSeparator));
}
public static IEnumerable<ToolStripItem> MenuItems(this IMemoryDomains domains, Action<string> setCallback, string selected = "", int? maxSize = null)
{
foreach (var domain in domains)

View File

@ -13,8 +13,6 @@ namespace BizHawk.Client.EmuHawk
public static IEmulator Emulator { get; set; }
public static CheatCollection CheatList { get; set; }
/// <summary>
/// the IGL to be used for rendering
/// </summary>

View File

@ -432,7 +432,7 @@ namespace BizHawk.Client.EmuHawk
Sound.StartSound();
InputManager.SyncControls(Emulator, MovieSession, Config);
GlobalWin.CheatList = new CheatCollection(Config.Cheats);
CheatList = new CheatCollection(Config.Cheats);
CheatList.Changed += Tools.UpdateCheatRelatedTools;
RewireSound();
@ -874,7 +874,7 @@ namespace BizHawk.Client.EmuHawk
}
private Sound Sound => GlobalWin.Sound;
public CheatCollection CheatList => GlobalWin.CheatList;
public CheatCollection CheatList { get; }
public IRewinder Rewinder { get; private set; }

View File

@ -1654,12 +1654,6 @@ namespace BizHawk.Client.EmuHawk
if (addresses.Any())
{
using var poke = new RamPoke
{
InitialLocation = this.ChildPointToScreen(AddressLabel),
ParentTool = this
};
var watches = addresses.Select(
address => Watch.GenerateWatch(
_domain,
@ -1668,7 +1662,12 @@ namespace BizHawk.Client.EmuHawk
Common.DisplayType.Hex,
BigEndian));
poke.SetWatch(watches);
using var poke = new RamPoke(watches, MainForm.CheatList)
{
InitialLocation = this.ChildPointToScreen(AddressLabel),
ParentTool = this
};
poke.ShowHawkDialog();
GeneralUpdate();
}

View File

@ -8,25 +8,24 @@ using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
// TODO: don't use textboxes as labels
public partial class RamPoke : Form
{
// TODO: don't use textboxes as labels
private List<Watch> _watchList = new List<Watch>();
private readonly List<Watch> _watchList;
private readonly CheatCollection _cheats;
public Point InitialLocation { get; set; } = new Point(0, 0);
public RamPoke()
public RamPoke(IEnumerable<Watch> watches, CheatCollection cheats)
{
_watchList = watches
.Where(w => !w.IsSeparator) // Weed out separators just in case
.ToList();
_cheats = cheats;
InitializeComponent();
}
public IToolForm ParentTool { get; set; }
public void SetWatch(IEnumerable<Watch> watches)
{
_watchList = watches.ToList();
}
private void UnSupportedConfiguration()
{
MessageBox.Show("RAM Poke does not support mixed types", "Unsupported Options", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -35,8 +34,6 @@ namespace BizHawk.Client.EmuHawk
private void RamPoke_Load(object sender, EventArgs e)
{
_watchList = _watchList.Where(x => !x.IsSeparator).ToList(); // Weed out separators just in case
if (_watchList.Count == 0)
{
ValueBox.Enabled = false;
@ -97,11 +94,8 @@ namespace BizHawk.Client.EmuHawk
var result = watch.Poke(ValueBox.Text);
if (result)
{
var cheat = GlobalWin.CheatList.FirstOrDefault(c => c.Address == watch.Address && c.Domain == watch.Domain);
if (!(cheat is null))
{
cheat.PokeValue(watch.Value);
}
var cheat = _cheats.FirstOrDefault(c => c.Address == watch.Address && c.Domain == watch.Domain);
cheat?.PokeValue(watch.Value);
}
else
{

View File

@ -860,14 +860,12 @@ namespace BizHawk.Client.EmuHawk
{
if (SelectedIndices.Any())
{
var poke = new RamPoke
var poke = new RamPoke(SelectedIndices.Select(t => _searches[t]), MainForm.CheatList)
{
InitialLocation = this.ChildPointToScreen(WatchListView)
};
poke.SetWatch(SelectedIndices.Select(t => _searches[t]));
poke.ShowHawkDialog();
UpdateList();
}
}
@ -1256,11 +1254,12 @@ namespace BizHawk.Client.EmuHawk
var allCheats = SelectedWatches.All(x => MainForm.CheatList.IsActive(x.Domain, x.Address));
if (allCheats)
{
SelectedWatches.UnfreezeAll();
MainForm.CheatList.RemoveRange(SelectedWatches);
}
else
{
SelectedWatches.FreezeAll();
MainForm.CheatList.AddRange(
SelectedWatches.Select(w => new Cheat(w, w.Value)));
}
}

View File

@ -763,13 +763,11 @@ namespace BizHawk.Client.EmuHawk
{
if (SelectedWatches.Any())
{
var poke = new RamPoke
var poke = new RamPoke(SelectedWatches, MainForm.CheatList)
{
InitialLocation = this.ChildPointToScreen(WatchListView)
};
poke.SetWatch(SelectedWatches);
if (poke.ShowHawkDialog(this).IsOk())
{
GeneralUpdate();
@ -782,11 +780,12 @@ namespace BizHawk.Client.EmuHawk
var allCheats = SelectedWatches.All(x => MainForm.CheatList.IsActive(x.Domain, x.Address));
if (allCheats)
{
SelectedWatches.UnfreezeAll();
MainForm.CheatList.RemoveRange(SelectedWatches);
}
else
{
SelectedWatches.FreezeAll();
MainForm.CheatList.AddRange(
SelectedWatches.Select(w => new Cheat(w, w.Value)));
}
}