Ram Watch - fix ability to watch multiple domains at once, New/Edit/Duplicate watch dialog - allow pasting into address box, reformat address box on blur
This commit is contained in:
parent
62f2771a8e
commit
5adb7fcc91
|
@ -382,14 +382,17 @@ namespace BizHawk.MultiClient
|
|||
|
||||
RamWatchNewWatch r = new RamWatchNewWatch();
|
||||
r.location = GetPromptPoint();
|
||||
r.SetEndian(Domain.Endian);
|
||||
|
||||
Watch w = new Watch();
|
||||
w.Domain = Domain;
|
||||
r.SetWatch(w);
|
||||
Global.Sound.StopSound();
|
||||
r.ShowDialog();
|
||||
Global.Sound.StartSound();
|
||||
if (r.userSelected == true)
|
||||
if (r.SelectionWasMade == true)
|
||||
{
|
||||
InitializeAddress(r.watch);
|
||||
Watches.Add(r.watch);
|
||||
InitializeAddress(r.Watch);
|
||||
Watches.Add(r.Watch);
|
||||
Changes();
|
||||
UpdateWatchCount();
|
||||
DisplayWatchList();
|
||||
|
@ -417,15 +420,15 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
RamWatchNewWatch r = new RamWatchNewWatch();
|
||||
r.location = GetPromptPoint();
|
||||
r.SetToEditWatch(Watches[pos], "Edit Watch");
|
||||
r.SetWatch(Watches[pos], "Edit Watch");
|
||||
Global.Sound.StopSound();
|
||||
r.ShowDialog();
|
||||
Global.Sound.StartSound();
|
||||
|
||||
if (r.userSelected == true)
|
||||
if (r.SelectionWasMade == true)
|
||||
{
|
||||
Changes();
|
||||
Watches[pos] = r.watch;
|
||||
Watches[pos] = r.Watch;
|
||||
DisplayWatchList();
|
||||
}
|
||||
}
|
||||
|
@ -433,8 +436,12 @@ namespace BizHawk.MultiClient
|
|||
void EditWatch()
|
||||
{
|
||||
ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices;
|
||||
|
||||
if (indexes.Count > 0)
|
||||
{
|
||||
EditWatchObject(indexes[0]);
|
||||
}
|
||||
|
||||
UpdateValues();
|
||||
}
|
||||
|
||||
|
@ -462,18 +469,17 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
RamWatchNewWatch r = new RamWatchNewWatch();
|
||||
r.location = GetPromptPoint();
|
||||
int x = indexes[0];
|
||||
r.SetToEditWatch(Watches[x], "Duplicate Watch");
|
||||
r.SetWatch(Watches[indexes[0]], "Duplicate Watch");
|
||||
|
||||
Global.Sound.StopSound();
|
||||
r.ShowDialog();
|
||||
Global.Sound.StartSound();
|
||||
|
||||
if (r.userSelected == true)
|
||||
if (r.SelectionWasMade == true)
|
||||
{
|
||||
InitializeAddress(r.watch);
|
||||
InitializeAddress(r.Watch);
|
||||
Changes();
|
||||
Watches.Add(r.watch);
|
||||
Watches.Add(r.Watch);
|
||||
DisplayWatchList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,20 +12,165 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
public partial class RamWatchNewWatch : Form
|
||||
{
|
||||
public Watch watch = new Watch();
|
||||
public MemoryDomain domain = Global.Emulator.MainMemory;
|
||||
public bool userSelected = false;
|
||||
public bool customSetup = false;
|
||||
public Watch Watch = new Watch();
|
||||
public bool SelectionWasMade = false;
|
||||
public Point location = new Point();
|
||||
|
||||
private bool DoNotResetAddress = false;
|
||||
|
||||
public RamWatchNewWatch()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void SetTypeRadio(Watch.TYPE a)
|
||||
public void SetWatch(Watch watch, string message = "New Watch")
|
||||
{
|
||||
switch (a)
|
||||
DoNotResetAddress = true; //Hack for the drop down event changing when initializing the drop down
|
||||
Watch = new Watch(watch);
|
||||
this.Text = message;
|
||||
|
||||
NotesBox.Text = watch.Notes;
|
||||
setTypeRadio();
|
||||
setSignedRadio();
|
||||
setEndianBox();
|
||||
setDomainSelection();
|
||||
setAddressBox();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
private void RamWatchNewWatch_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (location.X > 0 && location.Y > 0)
|
||||
{
|
||||
this.Location = location;
|
||||
}
|
||||
|
||||
populateMemoryDomainComboBox();
|
||||
DoNotResetAddress = false;
|
||||
}
|
||||
|
||||
private void Cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectionWasMade = false;
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void OK_Click(object sender, EventArgs e)
|
||||
{
|
||||
//Put user settings in the watch file
|
||||
SelectionWasMade = true;
|
||||
if (InputValidate.IsValidHexNumber(AddressBox.Text))
|
||||
{
|
||||
Watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Not a valid address (enter a valid Hex number)", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
AddressBox.Focus();
|
||||
AddressBox.SelectAll();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (SignedRadio.Checked)
|
||||
{
|
||||
Watch.Signed = Watch.DISPTYPE.SIGNED;
|
||||
}
|
||||
else if (UnsignedRadio.Checked)
|
||||
{
|
||||
Watch.Signed = Watch.DISPTYPE.UNSIGNED;
|
||||
}
|
||||
else if (HexRadio.Checked)
|
||||
{
|
||||
Watch.Signed = Watch.DISPTYPE.HEX;
|
||||
}
|
||||
|
||||
if (Byte1Radio.Checked)
|
||||
{
|
||||
Watch.Type = Watch.TYPE.BYTE;
|
||||
}
|
||||
else if (Byte2Radio.Checked)
|
||||
{
|
||||
Watch.Type = Watch.TYPE.WORD;
|
||||
}
|
||||
else if (Byte4Radio.Checked)
|
||||
{
|
||||
Watch.Type = Watch.TYPE.DWORD;
|
||||
}
|
||||
|
||||
if (BigEndianRadio.Checked)
|
||||
{
|
||||
Watch.BigEndian = true;
|
||||
}
|
||||
else if (LittleEndianRadio.Checked)
|
||||
{
|
||||
Watch.BigEndian = false;
|
||||
}
|
||||
|
||||
Watch.Domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
|
||||
Watch.Notes = NotesBox.Text;
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void AddressBox_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
if (e.KeyChar == '\b' || e.KeyChar == 22)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!InputValidate.IsValidHexNumber(e.KeyChar))
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddressBox_Leave(object sender, EventArgs e)
|
||||
{
|
||||
AddressBox.Text = AddressBox.Text.Replace(" ", "");
|
||||
if (!InputValidate.IsValidHexNumber(AddressBox.Text))
|
||||
{
|
||||
AddressBox.Focus();
|
||||
AddressBox.SelectAll();
|
||||
ToolTip t = new ToolTip();
|
||||
t.Show("Must be a valid hexadecimal vaue", AddressBox, 5000);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
|
||||
AddressBox.Text = String.Format("{0:X" + getNumDigits(Watch.Domain.Size - 1) + "}", Watch.Address);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DomainComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!DoNotResetAddress)
|
||||
{
|
||||
Watch.Domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
|
||||
int x = getNumDigits(Watch.Domain.Size);
|
||||
Watch.Address = 0;
|
||||
Watch.Value = 0;
|
||||
setAddressBox();
|
||||
AddressBox.MaxLength = getNumDigits(Watch.Domain.Size);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
private void setTypeRadio()
|
||||
{
|
||||
switch (Watch.Type)
|
||||
{
|
||||
case Watch.TYPE.BYTE:
|
||||
Byte1Radio.Checked = true;
|
||||
|
@ -41,9 +186,62 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
private void SetSignedRadio(Watch.DISPTYPE a)
|
||||
private void setEndianBox()
|
||||
{
|
||||
switch (a)
|
||||
if (Watch.BigEndian == true)
|
||||
{
|
||||
BigEndianRadio.Checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LittleEndianRadio.Checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void setDomainSelection()
|
||||
{
|
||||
//Counts should always be the same, but just in case, let's check
|
||||
int max;
|
||||
if (Global.Emulator.MemoryDomains.Count < DomainComboBox.Items.Count)
|
||||
{
|
||||
max = Global.Emulator.MemoryDomains.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = DomainComboBox.Items.Count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
if (Watch.Domain.ToString() == DomainComboBox.Items[i].ToString())
|
||||
{
|
||||
DomainComboBox.SelectedIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void populateMemoryDomainComboBox()
|
||||
{
|
||||
DomainComboBox.Items.Clear();
|
||||
if (Global.Emulator.MemoryDomains.Count > 0)
|
||||
{
|
||||
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
|
||||
{
|
||||
string str = Global.Emulator.MemoryDomains[x].ToString();
|
||||
DomainComboBox.Items.Add(str);
|
||||
}
|
||||
}
|
||||
setDomainSelection();
|
||||
}
|
||||
|
||||
private void setAddressBox()
|
||||
{
|
||||
AddressBox.Text = String.Format("{0:X" + getNumDigits(Watch.Domain.Size - 1) + "}", Watch.Address);
|
||||
}
|
||||
|
||||
private void setSignedRadio()
|
||||
{
|
||||
switch (Watch.Signed)
|
||||
{
|
||||
case Watch.DISPTYPE.SIGNED:
|
||||
SignedRadio.Checked = true;
|
||||
|
@ -59,196 +257,14 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
public void SetToEditWatch(Watch w, string message)
|
||||
{
|
||||
//Sets this dialog to Edit Watch and receives default values
|
||||
this.Text = message;
|
||||
customSetup = true;
|
||||
|
||||
AddressBox.Text = string.Format("{0:X4}", w.Address);
|
||||
NotesBox.Text = w.Notes;
|
||||
|
||||
SetTypeRadio(w.Type);
|
||||
SetSignedRadio(w.Signed);
|
||||
|
||||
if (w.BigEndian == true)
|
||||
BigEndianRadio.Checked = true;
|
||||
else
|
||||
LittleEndianRadio.Checked = true;
|
||||
}
|
||||
|
||||
public void SetDomain(MemoryDomain domain)
|
||||
{
|
||||
watch.Domain = domain;
|
||||
}
|
||||
|
||||
public void SetEndian(Endian endian)
|
||||
{
|
||||
if (endian == Endian.Big)
|
||||
{
|
||||
BigEndianRadio.Checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LittleEndianRadio.Checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void RamWatchNewWatch_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!customSetup)
|
||||
{
|
||||
Watch w = new Watch();
|
||||
SetTypeRadio(w.Type);
|
||||
SetSignedRadio(w.Signed);
|
||||
AddressBox.Text = "0000";
|
||||
}
|
||||
|
||||
if (location.X > 0 && location.Y > 0)
|
||||
{
|
||||
this.Location = location;
|
||||
}
|
||||
|
||||
PopulateMemoryDomainComboBox();
|
||||
}
|
||||
|
||||
private void Cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
userSelected = false;
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void OK_Click(object sender, EventArgs e)
|
||||
{
|
||||
//Put user settings in the watch file
|
||||
userSelected = true;
|
||||
if (InputValidate.IsValidHexNumber(AddressBox.Text))
|
||||
{
|
||||
watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Not a valid address (enter a valid Hex number)", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
AddressBox.Focus();
|
||||
AddressBox.SelectAll();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (SignedRadio.Checked)
|
||||
{
|
||||
watch.Signed = Watch.DISPTYPE.SIGNED;
|
||||
}
|
||||
else if (UnsignedRadio.Checked)
|
||||
{
|
||||
watch.Signed = Watch.DISPTYPE.UNSIGNED;
|
||||
}
|
||||
else if (HexRadio.Checked)
|
||||
{
|
||||
watch.Signed = Watch.DISPTYPE.HEX;
|
||||
}
|
||||
|
||||
if (Byte1Radio.Checked)
|
||||
{
|
||||
watch.Type = Watch.TYPE.BYTE;
|
||||
}
|
||||
else if (Byte2Radio.Checked)
|
||||
{
|
||||
watch.Type = Watch.TYPE.WORD;
|
||||
}
|
||||
else if (Byte4Radio.Checked)
|
||||
{
|
||||
watch.Type = Watch.TYPE.DWORD;
|
||||
}
|
||||
|
||||
if (BigEndianRadio.Checked)
|
||||
{
|
||||
watch.BigEndian = true;
|
||||
}
|
||||
else if (LittleEndianRadio.Checked)
|
||||
{
|
||||
watch.BigEndian = false;
|
||||
}
|
||||
watch.Domain = domain;
|
||||
watch.Notes = NotesBox.Text;
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void AddressBox_Leave(object sender, EventArgs e)
|
||||
{
|
||||
AddressBox.Text = AddressBox.Text.Replace(" ", "");
|
||||
if (!InputValidate.IsValidHexNumber(AddressBox.Text))
|
||||
{
|
||||
AddressBox.Focus();
|
||||
AddressBox.SelectAll();
|
||||
ToolTip t = new ToolTip();
|
||||
t.Show("MUst be a valid hexadecimal vaue", AddressBox, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddressBox_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
if (e.KeyChar == '\b') return;
|
||||
|
||||
if (!InputValidate.IsValidHexNumber(e.KeyChar))
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void PopulateMemoryDomainComboBox()
|
||||
{
|
||||
DomainComboBox.Items.Clear();
|
||||
if (Global.Emulator.MemoryDomains.Count > 0)
|
||||
{
|
||||
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
|
||||
{
|
||||
string str = Global.Emulator.MemoryDomains[x].ToString();
|
||||
DomainComboBox.Items.Add(str);
|
||||
}
|
||||
}
|
||||
SetDomainSelection();
|
||||
}
|
||||
|
||||
private int GetNumDigits(Int32 i)
|
||||
private int getNumDigits(Int32 i)
|
||||
{
|
||||
if (i < 0x10000) return 4;
|
||||
if (i < 0x100000) return 5;
|
||||
if (i < 0x1000000) return 6;
|
||||
if (i < 0x10000000) return 7;
|
||||
else return 8;
|
||||
}
|
||||
|
||||
private void SetAddressBox()
|
||||
{
|
||||
AddressBox.Text = String.Format("{0:X" +
|
||||
GetNumDigits(watch.Address) + "}", watch.Address);
|
||||
}
|
||||
|
||||
private void SetDomainSelection()
|
||||
{
|
||||
//Counts should always be the same, but just in case, let's check
|
||||
int max;
|
||||
if (Global.Emulator.MemoryDomains.Count < DomainComboBox.Items.Count)
|
||||
max = Global.Emulator.MemoryDomains.Count;
|
||||
else
|
||||
max = DomainComboBox.Items.Count;
|
||||
|
||||
for (int x = 0; x < max; x++)
|
||||
{
|
||||
if (domain.ToString() == DomainComboBox.Items[x].ToString())
|
||||
DomainComboBox.SelectedIndex = x;
|
||||
}
|
||||
}
|
||||
|
||||
private void DomainComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
|
||||
int x = GetNumDigits(domain.Size);
|
||||
watch.Address = 0;
|
||||
watch.Value = 0;
|
||||
watch.Domain = domain;
|
||||
SetAddressBox();
|
||||
AddressBox.MaxLength = GetNumDigits(domain.Size);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ namespace BizHawk.MultiClient
|
|||
Original = w.Original;
|
||||
LastChange = w.LastChange;
|
||||
LastSearch = w.LastSearch;
|
||||
Domain = w.Domain;
|
||||
Deleted = w.Deleted;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue