Fixed bug where having no comparison type would throw exception

This commit is contained in:
Adam Sturge 2016-02-09 20:33:44 -08:00
parent 447d312a5c
commit c82f70763e
5 changed files with 42 additions and 14 deletions

View File

@ -8,7 +8,8 @@ namespace BizHawk.Client.Common
{
public enum COMPARISONTYPE
{
EQUAL,
NONE,
EQUAL,
GREATER_THAN,
GREATER_THAN_OR_EQUAL,
LESS_THAN,
@ -23,7 +24,7 @@ namespace BizHawk.Client.Common
private COMPARISONTYPE _comparisonType;
public Cheat(Watch watch, int value, int? compare = null, bool enabled = true, COMPARISONTYPE comparisonType = COMPARISONTYPE.EQUAL)
public Cheat(Watch watch, int value, int? compare = null, bool enabled = true, COMPARISONTYPE comparisonType = COMPARISONTYPE.NONE)
{
_enabled = enabled;
_watch = watch;
@ -237,6 +238,8 @@ namespace BizHawk.Client.Common
{
switch (_comparisonType)
{
case Cheat.COMPARISONTYPE.NONE: // This should never happen, but it's here just in case
break;
case Cheat.COMPARISONTYPE.EQUAL:
if (_compare.Value == _watch.ValueNoFreeze)
{
@ -274,10 +277,6 @@ namespace BizHawk.Client.Common
}
break;
default :
if (_compare.Value == _watch.ValueNoFreeze)
{
_watch.Poke(GetStringForPulse(_val));
}
break;
}
}

View File

@ -451,7 +451,7 @@ namespace BizHawk.Client.Common
var size = WatchSize.Byte;
var type = DisplayType.Hex;
var bigendian = false;
Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.EQUAL;
Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.NONE;
if (s.Length < 6)
{

View File

@ -265,6 +265,10 @@
this.CompareTypeDropDown.Name = "CompareTypeDropDown";
this.CompareTypeDropDown.Size = new System.Drawing.Size(65, 33);
this.CompareTypeDropDown.TabIndex = 26;
this.CompareTypeDropDown.Items.AddRange(new object[] {
""
});
this.CompareTypeDropDown.SelectedIndex = 0;
//
// CompareTypeLabel
//

View File

@ -87,7 +87,16 @@ namespace BizHawk.Client.EmuHawk
AddressBox.Text = _cheat.AddressStr;
ValueBox.Text = _cheat.ValueStr;
CompareBox.Text = _cheat.Compare.HasValue ? _cheat.CompareStr : String.Empty;
CompareTypeDropDown.SelectedIndex = (int)_cheat.ComparisonType;
if (_cheat.ComparisonType.Equals(Cheat.COMPARISONTYPE.NONE))
{
CompareTypeDropDown.SelectedIndex = 0;
}
else
{
CompareTypeDropDown.SelectedIndex = ((int)_cheat.ComparisonType - 1);
}
CheckFormState();
if (!_cheat.Compare.HasValue)
@ -304,7 +313,7 @@ namespace BizHawk.Client.EmuHawk
{
get
{
Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.EQUAL;
Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.NONE;
var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()];
var address = AddressBox.ToRawInt().Value;
if (address < domain.Size)
@ -320,13 +329,14 @@ namespace BizHawk.Client.EmuHawk
switch (CompareTypeDropDown.SelectedItem.ToString())
{
case "": comparisonType = Cheat.COMPARISONTYPE.NONE; break;
case "=": comparisonType = Cheat.COMPARISONTYPE.EQUAL; break;
case ">": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN; break;
case ">=": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN_OR_EQUAL; break;
case "<": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN; break;
case "<=": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN_OR_EQUAL; break;
case "!=": comparisonType = Cheat.COMPARISONTYPE.NOT_EQUAL; break;
default: comparisonType = Cheat.COMPARISONTYPE.EQUAL; break;
default: comparisonType = Cheat.COMPARISONTYPE.NONE; break;
}
int? c = CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value;
@ -376,14 +386,26 @@ namespace BizHawk.Client.EmuHawk
{
// Don't need to do anything in this case
if (!empty && this.CompareTypeDropDown.Items.Count > 0)
if(empty && this.CompareTypeDropDown.Items.Count == 1)
{
return;
}
// Don't need to do anything in this case
if (!empty && this.CompareTypeDropDown.Items.Count == 6)
{
return;
}
this.CompareTypeDropDown.Items.Clear();
if (!empty)
if (empty)
{
this.CompareTypeDropDown.Items.AddRange(new object[] {
""
});
}
else
{
this.CompareTypeDropDown.Items.AddRange(new object[] {
"=",
@ -394,7 +416,9 @@ namespace BizHawk.Client.EmuHawk
"!="
});
}
this.CompareTypeDropDown.SelectedIndex = 0;
}
}
}

View File

@ -267,13 +267,14 @@ namespace BizHawk.Client.EmuHawk
case COMPARISONTYPE:
switch (Global.CheatList[index].ComparisonType)
{
case Cheat.COMPARISONTYPE.NONE : text = ""; break;
case Cheat.COMPARISONTYPE.EQUAL : text = "="; break;
case Cheat.COMPARISONTYPE.GREATER_THAN : text = ">"; break;
case Cheat.COMPARISONTYPE.GREATER_THAN_OR_EQUAL : text = ">="; break;
case Cheat.COMPARISONTYPE.LESS_THAN : text = "<"; break;
case Cheat.COMPARISONTYPE.LESS_THAN_OR_EQUAL : text = "<="; break;
case Cheat.COMPARISONTYPE.NOT_EQUAL : text = "!="; break;
default : break;
default : text = ""; break;
}
break;