misc code cleanups in ram watch tool files

This commit is contained in:
adelikat 2017-04-19 07:50:25 -05:00
parent f108673449
commit 8f3d1613a0
5 changed files with 58 additions and 87 deletions

View File

@ -13,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: don't use textboxes as labels // TODO: don't use textboxes as labels
private List<Watch> _watchList = new List<Watch>(); private List<Watch> _watchList = new List<Watch>();
public Point InitialLocation = new Point(0, 0); public Point InitialLocation { get; set; } = new Point(0, 0);
public RamPoke() public RamPoke()
{ {
@ -104,10 +104,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var success = _watchList.All(watch => watch.Poke(ValueBox.Text)); var success = _watchList.All(watch => watch.Poke(ValueBox.Text));
if (ParentTool != null) ParentTool?.UpdateValues();
{
ParentTool.UpdateValues();
}
if (success) if (success)
{ {

View File

@ -27,7 +27,6 @@ namespace BizHawk.Client.EmuHawk
public partial class RamSearch : ToolFormBase, IToolForm public partial class RamSearch : ToolFormBase, IToolForm
{ {
// TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events // TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events
private string _currentFileName = string.Empty; private string _currentFileName = string.Empty;
private RamSearchEngine _searches; private RamSearchEngine _searches;
@ -42,8 +41,8 @@ namespace BizHawk.Client.EmuHawk
private bool _dropdownDontfire; // Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event! private bool _dropdownDontfire; // Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event!
public const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user private const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user
public const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size RAM Search will support (as it will crash beyond this) private const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size RAM Search will support (as it will crash beyond this)
#region Initialize, Load, and Save #region Initialize, Load, and Save
@ -81,10 +80,7 @@ namespace BizHawk.Client.EmuHawk
return true; return true;
} }
public bool UpdateBefore public bool UpdateBefore => false;
{
get { return false; }
}
private void HardSetDisplayTypeDropDown(BizHawk.Client.Common.DisplayType type) private void HardSetDisplayTypeDropDown(BizHawk.Client.Common.DisplayType type)
{ {
@ -261,10 +257,12 @@ namespace BizHawk.Client.EmuHawk
SetTotal(); SetTotal();
} }
public void NewUpdate(ToolFormUpdateType type) { } public void NewUpdate(ToolFormUpdateType type)
{
}
/// <summary> /// <summary>
/// This should only be called when the values of the list need an update such as after a poke or emulation occured /// This should only be called when the values of the list need an update such as after a poke or emulation occurred
/// </summary> /// </summary>
public void UpdateValues() public void UpdateValues()
{ {
@ -315,7 +313,7 @@ namespace BizHawk.Client.EmuHawk
HardSetDisplayTypeDropDown(_settings.Type); HardSetDisplayTypeDropDown(_settings.Type);
} }
public void SaveConfigSettings() private void SaveConfigSettings()
{ {
SaveColumnInfo(WatchListView, Settings.Columns); SaveColumnInfo(WatchListView, Settings.Columns);
@ -472,13 +470,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private int? DifferentByValue private int? DifferentByValue => DifferentByRadio.Checked ? DifferentByBox.ToRawInt() : null;
{
get
{
return DifferentByRadio.Checked ? DifferentByBox.ToRawInt() : null;
}
}
private RamSearchEngine.ComparisonOperator Operator private RamSearchEngine.ComparisonOperator Operator
{ {
@ -560,10 +552,7 @@ namespace BizHawk.Client.EmuHawk
_forcePreviewClear = true; _forcePreviewClear = true;
} }
private IEnumerable<int> SelectedIndices private IEnumerable<int> SelectedIndices => WatchListView.SelectedIndices.Cast<int>();
{
get { return WatchListView.SelectedIndices.Cast<int>(); }
}
private IEnumerable<Watch> SelectedItems private IEnumerable<Watch> SelectedItems
{ {
@ -582,7 +571,7 @@ namespace BizHawk.Client.EmuHawk
private void SetTotal() private void SetTotal()
{ {
TotalSearchLabel.Text = string.Format("{0:n0}", _searches.Count) + " addresses"; TotalSearchLabel.Text = $"{_searches.Count:n0}" + " addresses";
} }
private void SetDomainLabel() private void SetDomainLabel()
@ -628,11 +617,19 @@ namespace BizHawk.Client.EmuHawk
if (_settings.Type != type) if (_settings.Type != type)
{ {
if (!string.IsNullOrEmpty(SpecificValueBox.Text)) if (!string.IsNullOrEmpty(SpecificValueBox.Text))
{
SpecificValueBox.Text = "0"; SpecificValueBox.Text = "0";
}
if (!string.IsNullOrEmpty(DifferenceBox.Text)) if (!string.IsNullOrEmpty(DifferenceBox.Text))
{
DifferenceBox.Text = "0"; DifferenceBox.Text = "0";
}
if (!string.IsNullOrEmpty(DifferentByBox.Text)) if (!string.IsNullOrEmpty(DifferentByBox.Text))
{
DifferentByBox.Text = "0"; DifferentByBox.Text = "0";
}
} }
SpecificValueBox.Type = _settings.Type = type; SpecificValueBox.Type = _settings.Type = type;
@ -701,7 +698,7 @@ namespace BizHawk.Client.EmuHawk
private void PopulateTypeDropDown() private void PopulateTypeDropDown()
{ {
var previous = DisplayTypeDropdown.SelectedItem != null ? DisplayTypeDropdown.SelectedItem.ToString() : string.Empty; var previous = DisplayTypeDropdown.SelectedItem?.ToString() ?? string.Empty;
var next = string.Empty; var next = string.Empty;
DisplayTypeDropdown.Items.Clear(); DisplayTypeDropdown.Items.Clear();
@ -817,7 +814,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
public void LoadWatchFile(FileInfo file, bool append, bool truncate = false) private void LoadWatchFile(FileInfo file, bool append, bool truncate = false)
{ {
if (file != null) if (file != null)
{ {
@ -971,7 +968,7 @@ namespace BizHawk.Client.EmuHawk
AutoSearchTakeLagFramesIntoAccount = true; AutoSearchTakeLagFramesIntoAccount = true;
} }
public ColumnList Columns { get; set; } public ColumnList Columns { get; }
public bool PreviewMode { get; set; } public bool PreviewMode { get; set; }
public bool AlwaysExcludeRamWatch { get; set; } public bool AlwaysExcludeRamWatch { get; set; }
public bool AutoSearchTakeLagFramesIntoAccount { get; set; } public bool AutoSearchTakeLagFramesIntoAccount { get; set; }
@ -1000,8 +997,7 @@ namespace BizHawk.Client.EmuHawk
LoadWatchFile( LoadWatchFile(
GetWatchFileFromUser(string.Empty), GetWatchFileFromUser(string.Empty),
sender == AppendFileMenuItem, sender == AppendFileMenuItem,
sender == TruncateFromFileMenuItem sender == TruncateFromFileMenuItem);
);
} }
private void SaveMenuItem_Click(object sender, EventArgs e) private void SaveMenuItem_Click(object sender, EventArgs e)
@ -1250,7 +1246,7 @@ namespace BizHawk.Client.EmuHawk
ToggleSearchDependentToolBarItems(); ToggleSearchDependentToolBarItems();
_forcePreviewClear = true; _forcePreviewClear = true;
UpdateUndoToolBarButtons(); UpdateUndoToolBarButtons();
MessageLabel.Text = restoredCount.ToString() + " address" + (restoredCount != 1 ? "es" : "") + " restored"; MessageLabel.Text = restoredCount + " address" + (restoredCount != 1 ? "es" : string.Empty) + " restored";
} }
} }
@ -1263,7 +1259,7 @@ namespace BizHawk.Client.EmuHawk
ToggleSearchDependentToolBarItems(); ToggleSearchDependentToolBarItems();
_forcePreviewClear = true; _forcePreviewClear = true;
UpdateUndoToolBarButtons(); UpdateUndoToolBarButtons();
MessageLabel.Text = restoredCount.ToString() + " address" + (restoredCount != 1 ? "es" : "") + " removed"; MessageLabel.Text = restoredCount + " address" + (restoredCount != 1 ? "es" : string.Empty) + " removed";
} }
} }
@ -1393,17 +1389,14 @@ namespace BizHawk.Client.EmuHawk
{ {
var recentFiles = Settings.RecentSearches; // We don't want to wipe recent files when restoring var recentFiles = Settings.RecentSearches; // We don't want to wipe recent files when restoring
Settings = new RamSearchSettings(); Settings = new RamSearchSettings { RecentSearches = recentFiles };
Settings.RecentSearches = recentFiles;
Size = new Size(_defaultWidth, _defaultHeight); Size = new Size(_defaultWidth, _defaultHeight);
RamSearchMenu.Items.Remove( RamSearchMenu.Items.Remove(
RamSearchMenu.Items RamSearchMenu.Items
.OfType<ToolStripMenuItem>() .OfType<ToolStripMenuItem>()
.First(x => x.Name == "GeneratedColumnsSubMenu") .First(x => x.Name == "GeneratedColumnsSubMenu"));
);
RamSearchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback)); RamSearchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));

View File

@ -78,13 +78,10 @@ namespace BizHawk.Client.EmuHawk
}; };
} }
public ColumnList Columns { get; set; } public ColumnList Columns { get; }
} }
private IEnumerable<int> SelectedIndices private IEnumerable<int> SelectedIndices => WatchListView.SelectedIndices.Cast<int>();
{
get { return WatchListView.SelectedIndices.Cast<int>(); }
}
private IEnumerable<Watch> SelectedItems private IEnumerable<Watch> SelectedItems
{ {
@ -225,7 +222,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
public void NewUpdate(ToolFormUpdateType type) { } public void NewUpdate(ToolFormUpdateType type)
{
}
public void UpdateValues() public void UpdateValues()
{ {
@ -705,7 +704,7 @@ namespace BizHawk.Client.EmuHawk
PauseMenuItem.Text = _paused ? "Unpause" : "Pause"; PauseMenuItem.Text = _paused ? "Unpause" : "Pause";
} }
private MemoryDomain _currentDomain = null; private MemoryDomain _currentDomain;
private MemoryDomain CurrentDomain private MemoryDomain CurrentDomain
{ {
@ -770,7 +769,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (SelectedWatches.Any()) if (SelectedWatches.Any())
{ {
RamPoke poke = new RamPoke var poke = new RamPoke
{ {
InitialLocation = this.ChildPointToScreen(WatchListView) InitialLocation = this.ChildPointToScreen(WatchListView)
}; };

View File

@ -81,7 +81,7 @@ namespace BizHawk.Client.EmuHawk
if (_watchList.Count > 1) if (_watchList.Count > 1)
{ {
NotesBox.Enabled = false; NotesBox.Enabled = false;
NotesBox.Text = String.Empty; NotesBox.Text = string.Empty;
AddressBox.Enabled = false; AddressBox.Enabled = false;
AddressBox.Text = _watchList.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr)); AddressBox.Text = _watchList.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr));
@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk
Text = "New Watch"; Text = "New Watch";
break; break;
case Mode.Edit: case Mode.Edit:
Text = "Edit Watch" + (_watchList.Count > 1 ? "es" : ""); Text = "Edit Watch" + (_watchList.Count > 1 ? "es" : string.Empty);
break; break;
case Mode.Duplicate: case Mode.Duplicate:
Text = "Duplicate Watch"; Text = "Duplicate Watch";
@ -179,10 +179,9 @@ namespace BizHawk.Client.EmuHawk
break; break;
} }
if (DisplayTypeDropDown.Items.Contains(oldType)) DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items.Contains(oldType)
DisplayTypeDropDown.SelectedItem = oldType; ? oldType
else : DisplayTypeDropDown.Items[0];
DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[0];
} }
private void SetBigEndianCheckBox() private void SetBigEndianCheckBox()
@ -310,10 +309,9 @@ namespace BizHawk.Client.EmuHawk
_watchList[i].Domain, _watchList[i].Domain,
_watchList.Count == 1 ? AddressBox.ToRawInt() ?? 0 : _watchList[i].Address, _watchList.Count == 1 ? AddressBox.ToRawInt() ?? 0 : _watchList[i].Address,
size, size,
_watchList[i].Type, _watchList[i].Type,
_watchList[i].BigEndian, _watchList[i].BigEndian,
_watchList[i].Notes _watchList[i].Notes);
);
} }
} }

View File

@ -1,11 +1,11 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using System.Linq;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -13,14 +13,13 @@ namespace BizHawk.Client.EmuHawk
{ {
private WatchSize _size = WatchSize.Byte; private WatchSize _size = WatchSize.Byte;
private DisplayType _type = DisplayType.Hex; private DisplayType _type = DisplayType.Hex;
private bool _nullable = true;
public WatchValueBox() public WatchValueBox()
{ {
CharacterCasing = CharacterCasing.Upper; CharacterCasing = CharacterCasing.Upper;
} }
public bool Nullable { get { return _nullable; } set { _nullable = value; } } public bool Nullable { get; set; } = true;
public WatchSize ByteSize public WatchSize ByteSize
{ {
@ -42,15 +41,15 @@ namespace BizHawk.Client.EmuHawk
switch (value) switch (value)
{ {
case WatchSize.Byte: case WatchSize.Byte:
isTypeCompatible = ByteWatch.ValidTypes.Where(t => t == _type).Any(); isTypeCompatible = ByteWatch.ValidTypes.Any(t => t == _type);
break; break;
case WatchSize.Word: case WatchSize.Word:
isTypeCompatible = WordWatch.ValidTypes.Where(t => t == _type).Any(); isTypeCompatible = WordWatch.ValidTypes.Any(t => t == _type);
break; break;
case WatchSize.DWord: case WatchSize.DWord:
isTypeCompatible = DWordWatch.ValidTypes.Where(t => t == _type).Any(); isTypeCompatible = DWordWatch.ValidTypes.Any(t => t == _type);
break; break;
} }
@ -131,39 +130,21 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private double Max12_4 private double Max12_4 => MaxUnsignedInt / 16.0;
{
get { return MaxUnsignedInt / 16.0; }
}
private double Max20_12 private double Max20_12 => MaxUnsignedInt / 4096.0;
{
get { return MaxUnsignedInt / 4096.0; }
}
private double Max16_16 private double Max16_16 => MaxUnsignedInt / 65536.0;
{
get { return MaxUnsignedInt / 65536.0; }
}
private static double _12_4_Unit private static double _12_4_Unit => 1 / 16.0;
{
get { return 1 / 16.0; }
}
private static double _20_12_Unit private static double _20_12_Unit => 1 / 4096.0;
{
get { return 1 / 4096.0; }
}
private static double _16_16_Unit private static double _16_16_Unit => 1 / 65536.0;
{
get { return 1 / 65536.0; }
}
public override void ResetText() public override void ResetText()
{ {
if (_nullable) if (Nullable)
{ {
Text = string.Empty; Text = string.Empty;
} }
@ -689,7 +670,10 @@ namespace BizHawk.Client.EmuHawk
if (Text.IsFloat()) if (Text.IsFloat())
{ {
if (Text == "-" || Text == ".") if (Text == "-" || Text == ".")
{
return 0; return 0;
}
float val = float.Parse(Text); float val = float.Parse(Text);
var bytes = BitConverter.GetBytes(val); var bytes = BitConverter.GetBytes(val);
return BitConverter.ToInt32(bytes, 0); return BitConverter.ToInt32(bytes, 0);