diff --git a/BizHawk.MultiClient/tools/Cheats/CheatEdit.Designer.cs b/BizHawk.MultiClient/tools/Cheats/CheatEdit.Designer.cs index fbd64f9306..358df70ea2 100644 --- a/BizHawk.MultiClient/tools/Cheats/CheatEdit.Designer.cs +++ b/BizHawk.MultiClient/tools/Cheats/CheatEdit.Designer.cs @@ -214,6 +214,7 @@ this.DisplayTypeDropDown.Name = "DisplayTypeDropDown"; this.DisplayTypeDropDown.Size = new System.Drawing.Size(100, 21); this.DisplayTypeDropDown.TabIndex = 21; + this.DisplayTypeDropDown.SelectedIndexChanged += new System.EventHandler(this.DisplayTypeDropDown_SelectedIndexChanged); // // BigEndianCheckBox // @@ -235,6 +236,7 @@ this.AddButton.TabIndex = 23; this.AddButton.Text = "&Add"; this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); // // EditButton // @@ -246,6 +248,7 @@ this.EditButton.TabIndex = 24; this.EditButton.Text = "&Edit"; this.EditButton.UseVisualStyleBackColor = true; + this.EditButton.Click += new System.EventHandler(this.EditButton_Click); // // CheatEdit // diff --git a/BizHawk.MultiClient/tools/Cheats/CheatEdit.cs b/BizHawk.MultiClient/tools/Cheats/CheatEdit.cs index 0890109ab9..1d679d9ca7 100644 --- a/BizHawk.MultiClient/tools/Cheats/CheatEdit.cs +++ b/BizHawk.MultiClient/tools/Cheats/CheatEdit.cs @@ -12,20 +12,29 @@ namespace BizHawk.MultiClient { public partial class CheatEdit : UserControl { - //TODO: - private NewCheat _cheat; - private const string HexInd = "0x"; - - private bool _loading = false; - public CheatEdit() { InitializeComponent(); + AddressBox.Nullable = false; + ValueBox.Nullable = false; } + #region Privates + + private NewCheat _cheat; + private const string HexInd = "0x"; + private bool _loading = false; + private bool _editmode = false; + + private Action _addCallback = null; + private Action _editCallback = null; + private void CheatEdit_Load(object sender, EventArgs e) { - ToolHelpers.PopulateMemoryDomainDropdown(ref DomainDropDown, Global.Emulator.MainMemory); + if (Global.Emulator != null) + { + ToolHelpers.PopulateMemoryDomainDropdown(ref DomainDropDown, Global.Emulator.MainMemory); + } SetFormToDefault(); } @@ -69,7 +78,11 @@ namespace BizHawk.MultiClient PopulateTypeDropdown(); NameBox.Text = String.Empty; - AddressBox.SetHexProperties(Global.Emulator.MainMemory.Size); + + if (Global.Emulator != null) + { + AddressBox.SetHexProperties(Global.Emulator.MainMemory.Size); + } ValueBox.ByteSize = CompareBox.ByteSize = @@ -88,6 +101,8 @@ namespace BizHawk.MultiClient BigEndianCheckBox.Checked = false; + SetTypeSelected(Watch.DisplayType.Hex); + CheckFormState(); _loading = false; } @@ -154,9 +169,9 @@ namespace BizHawk.MultiClient private void CheckFormState() { - AddButton.Enabled = - EditButton.Enabled = - (!String.IsNullOrWhiteSpace(AddressBox.Text) && !String.IsNullOrWhiteSpace(ValueBox.Text)); + bool valid = (!String.IsNullOrWhiteSpace(AddressBox.Text) && !String.IsNullOrWhiteSpace(ValueBox.Text)); + AddButton.Enabled = valid; + EditButton.Enabled = _editmode && valid; } private void SizeDropDown_SelectedIndexChanged(object sender, EventArgs e) @@ -195,10 +210,36 @@ namespace BizHawk.MultiClient } } + private void DisplayTypeDropDown_SelectedIndexChanged(object sender, EventArgs e) + { + ValueBox.Type = + CompareBox.Type = + Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()); + } + + private void AddButton_Click(object sender, EventArgs e) + { + if (_addCallback != null) + { + _addCallback(); + } + } + + private void EditButton_Click(object sender, EventArgs e) + { + if (_editCallback != null) + { + _editCallback(); + } + } + + #endregion + #region API public void SetCheat(NewCheat cheat) { + _editmode = true; _cheat = cheat; if (cheat.IsSeparator) { @@ -211,11 +252,38 @@ namespace BizHawk.MultiClient } } - //Add Cheat Callback - //Edit Cheat Callback + public void ClearForm() + { + SetFormToDefault(); + _cheat = NewCheat.Separator; + } + + public NewCheat Cheat + { + get + { + Watch w = Watch.GenerateWatch( + ToolHelpers.DomainByName(DomainDropDown.SelectedItem.ToString()), + AddressBox.ToRawInt(), + GetCurrentSize(), + Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()), + NameBox.Text, + BigEndianCheckBox.Checked); + + return new NewCheat(w, CompareBox.ToRawInt(), enabled: true); + } + } + + public void SetAddEvent(Action AddCallback) + { + _addCallback = AddCallback; + } + + public void SetEditEvent(Action EditCallback) + { + _editCallback = EditCallback; + } #endregion - - } } diff --git a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs index 25599da8b2..383f1068dd 100644 --- a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs +++ b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.Designer.cs @@ -53,7 +53,6 @@ this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CheatsSubMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.AddCheatMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.RemoveCheatMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DuplicateMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.InsertSeparatorMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -134,6 +133,11 @@ this.CheatListView.TabIndex = 1; this.CheatListView.UseCompatibleStateImageBehavior = false; this.CheatListView.View = System.Windows.Forms.View.Details; + this.CheatListView.ColumnReordered += new System.Windows.Forms.ColumnReorderedEventHandler(this.CheatListView_ColumnReordered); + this.CheatListView.SelectedIndexChanged += new System.EventHandler(this.CheatListView_SelectedIndexChanged); + this.CheatListView.Click += new System.EventHandler(this.CheatListView_Click); + this.CheatListView.DoubleClick += new System.EventHandler(this.CheatListView_DoubleClick); + this.CheatListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CheatListView_KeyDown); // // CheatName // @@ -303,7 +307,6 @@ // CheatsSubMenu // this.CheatsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.AddCheatMenuItem, this.RemoveCheatMenuItem, this.DuplicateMenuItem, this.InsertSeparatorMenuItem, @@ -321,14 +324,6 @@ this.CheatsSubMenu.Text = "&Cheats"; this.CheatsSubMenu.DropDownOpened += new System.EventHandler(this.CheatsSubMenu_DropDownOpened); // - // AddCheatMenuItem - // - this.AddCheatMenuItem.Enabled = false; - this.AddCheatMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Freeze; - this.AddCheatMenuItem.Name = "AddCheatMenuItem"; - this.AddCheatMenuItem.Size = new System.Drawing.Size(233, 22); - this.AddCheatMenuItem.Text = "&Add Cheat"; - // // RemoveCheatMenuItem // this.RemoveCheatMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Delete; @@ -722,9 +717,9 @@ // this.CheatGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.CheatGroupBox.Controls.Add(this.CheatEditor); - this.CheatGroupBox.Location = new System.Drawing.Point(432, 72); + this.CheatGroupBox.Location = new System.Drawing.Point(432, 66); this.CheatGroupBox.Name = "CheatGroupBox"; - this.CheatGroupBox.Size = new System.Drawing.Size(202, 278); + this.CheatGroupBox.Size = new System.Drawing.Size(202, 284); this.CheatGroupBox.TabIndex = 8; this.CheatGroupBox.TabStop = false; this.CheatGroupBox.Text = "Cheat"; @@ -755,6 +750,8 @@ this.Name = "NewCheatForm"; this.Text = "New Cheat form"; this.Load += new System.EventHandler(this.NewCheatForm_Load); + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragDrop); + this.DragEnter += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragEnter); this.contextMenuStrip1.ResumeLayout(false); this.CheatsMenu.ResumeLayout(false); this.CheatsMenu.PerformLayout(); @@ -787,7 +784,6 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem ExitMenuItem; private System.Windows.Forms.ToolStripMenuItem CheatsSubMenu; - private System.Windows.Forms.ToolStripMenuItem AddCheatMenuItem; private System.Windows.Forms.ToolStripMenuItem RemoveCheatMenuItem; private System.Windows.Forms.ToolStripMenuItem DuplicateMenuItem; private System.Windows.Forms.ToolStripMenuItem InsertSeparatorMenuItem; diff --git a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs index 70c7257269..674f9b3205 100644 --- a/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs +++ b/BizHawk.MultiClient/tools/Cheats/NewCheatForm.cs @@ -168,11 +168,30 @@ namespace BizHawk.MultiClient || (Global.Emulator.SystemId == "GB") || (Global.Game.System == "GG") || (Global.Emulator is LibsnesCore)); + + CheatEditor.SetAddEvent(AddCheat); + CheatEditor.SetEditEvent(EditCheat); + } + + private void AddCheat() + { + Global.CheatList2.Add(CheatEditor.Cheat); + UpdateListView(); + UpdateMessageLabel(); + } + + private void EditCheat() + { + MessageBox.Show("Edit clicked"); } public void SaveConfigSettings() { - /*TODO*/ + SaveColumnInfo(); + Global.Config.CheatsWndx = Location.X; + Global.Config.CheatsWndy = Location.Y; + Global.Config.CheatsWidth = Right - Left; + Global.Config.CheatsHeight = Bottom - Top; } private void LoadConfigSettings() @@ -470,6 +489,18 @@ namespace BizHawk.MultiClient LoadColumnInfo(); } + private void DoSelectedIndexChange() + { + if (SelectedIndices.Any()) + { + CheatEditor.SetCheat(Global.CheatList2[SelectedIndices[0]]); + } + else + { + CheatEditor.ClearForm(); + } + } + #region Events #region File @@ -770,6 +801,67 @@ namespace BizHawk.MultiClient #endregion + #region ListView Events + + private void CheatListView_Click(object sender, EventArgs e) + { + DoSelectedIndexChange(); + } + + private void CheatListView_ColumnReordered(object sender, ColumnReorderedEventArgs e) + { + + Global.Config.CheatsColumnIndices[NAME] = CheatListView.Columns[NAME].DisplayIndex; + Global.Config.CheatsColumnIndices[ADDRESS] = CheatListView.Columns[ADDRESS].DisplayIndex; + Global.Config.CheatsColumnIndices[VALUE] = CheatListView.Columns[VALUE].DisplayIndex; + Global.Config.CheatsColumnIndices[COMPARE] = CheatListView.Columns[COMPARE].DisplayIndex; + Global.Config.CheatsColumnIndices[ON] = CheatListView.Columns[ON].DisplayIndex; + Global.Config.CheatsColumnIndices[DOMAIN] = CheatListView.Columns[DOMAIN].DisplayIndex; + Global.Config.CheatsColumnIndices[SIZE] = CheatListView.Columns[SIZE].DisplayIndex; + Global.Config.CheatsColumnIndices[ENDIAN] = CheatListView.Columns[ENDIAN].DisplayIndex; + Global.Config.CheatsColumnIndices[TYPE] = CheatListView.Columns[TYPE].DisplayIndex; + } + + private void CheatListView_DoubleClick(object sender, EventArgs e) + { + Toggle(); + } + + private void CheatListView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete && !e.Control && !e.Alt && !e.Shift) + { + Remove(); + } + else if (e.KeyCode == Keys.A && e.Control && !e.Alt && !e.Shift) //Select All + { + SelectAllMenuItem_Click(null, null); + } + } + + private void CheatListView_SelectedIndexChanged(object sender, EventArgs e) + { + DoSelectedIndexChange(); + } + + private void NewCheatForm_DragDrop(object sender, DragEventArgs e) + { + string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); + if (Path.GetExtension(filePaths[0]) == (".cht")) + { + LoadFile(new FileInfo(filePaths[0]), append: false); + UpdateListView(); + UpdateMessageLabel(); + } + } + + private void NewCheatForm_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; + } + + #endregion + #endregion } } diff --git a/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs b/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs index c22ba5f9a4..fdbb5f1750 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs +++ b/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs @@ -7,6 +7,9 @@ namespace BizHawk.MultiClient { private Watch.WatchSize _size = Watch.WatchSize.Byte; private Watch.DisplayType _type = Watch.DisplayType.Hex; + private bool _nullable = true; + + public bool Nullable { get { return _nullable; } set { _nullable = value; } } public WatchValueBox() { @@ -15,28 +18,33 @@ namespace BizHawk.MultiClient public override void ResetText() { - switch (Type) + if (_nullable) { - default: - case Watch.DisplayType.Signed: - case Watch.DisplayType.Unsigned: - Text = "0"; - break; - case Watch.DisplayType.Hex: - string formatstr = "{0:X" + MaxLength.ToString() + "}"; - Text = String.Format(formatstr, 0); - break; - case Watch.DisplayType.FixedPoint_12_4: - case Watch.DisplayType.FixedPoint_20_12: - case Watch.DisplayType.Float: - Text = "0.0"; - break; - case Watch.DisplayType.Binary: - Text = "0".PadLeft(((int)_size) * 8); - break; + Text = String.Empty; + } + else + { + switch (Type) + { + default: + case Watch.DisplayType.Signed: + case Watch.DisplayType.Unsigned: + Text = "0"; + break; + case Watch.DisplayType.Hex: + string formatstr = "{0:X" + MaxLength.ToString() + "}"; + Text = String.Format(formatstr, 0); + break; + case Watch.DisplayType.FixedPoint_12_4: + case Watch.DisplayType.FixedPoint_20_12: + case Watch.DisplayType.Float: + Text = "0.0"; + break; + case Watch.DisplayType.Binary: + Text = "0".PadLeft(((int)_size) * 8); + break; + } } - - } public Watch.WatchSize ByteSize @@ -44,14 +52,18 @@ namespace BizHawk.MultiClient get { return _size; } set { - if (_size != value) + bool changed = _size != value; + + _size = value; + if (changed) { + SetMaxLength(); if (!Watch.AvailableTypes(value).Contains(_type)) { Type = Watch.AvailableTypes(value)[0]; } + ResetText(); } - _size = value; } } @@ -60,79 +72,86 @@ namespace BizHawk.MultiClient get { return _type; } set { + int val = ToRawInt(); _type = value; - switch(_type) - { - default: - MaxLength = 8; - break; - case Watch.DisplayType.Binary: - switch (_size) - { - default: - case Watch.WatchSize.Byte: - MaxLength = 8; - break; - case Watch.WatchSize.Word: - MaxLength = 16; - break; - } - break; - case Watch.DisplayType.Hex: - switch (_size) - { - default: - case Watch.WatchSize.Byte: - MaxLength = 2; - break; - case Watch.WatchSize.Word: - MaxLength = 4; - break; - case Watch.WatchSize.DWord: - MaxLength = 8; - break; - } - break; - case Watch.DisplayType.Signed: - switch (_size) - { - default: - case Watch.WatchSize.Byte: - MaxLength = 4; - break; - case Watch.WatchSize.Word: - MaxLength = 6; - break; - case Watch.WatchSize.DWord: - MaxLength = 11; - break; - } - break; - case Watch.DisplayType.Unsigned: - switch (_size) - { - default: - case Watch.WatchSize.Byte: - MaxLength = 3; - break; - case Watch.WatchSize.Word: - MaxLength = 5; - break; - case Watch.WatchSize.DWord: - MaxLength = 10; - break; - } - break; - case Watch.DisplayType.FixedPoint_12_4: - MaxLength = 9; - break; - case Watch.DisplayType.Float: - MaxLength = 21; - break; - case Watch.DisplayType.FixedPoint_20_12: - MaxLength = 64; - break; - } + SetMaxLength(); + SetFromRawInt(val); + } + } + + private void SetMaxLength() + { + switch (_type) + { + default: + MaxLength = 8; + break; + case Watch.DisplayType.Binary: + switch (_size) + { + default: + case Watch.WatchSize.Byte: + MaxLength = 8; + break; + case Watch.WatchSize.Word: + MaxLength = 16; + break; + } + break; + case Watch.DisplayType.Hex: + switch (_size) + { + default: + case Watch.WatchSize.Byte: + MaxLength = 2; + break; + case Watch.WatchSize.Word: + MaxLength = 4; + break; + case Watch.WatchSize.DWord: + MaxLength = 8; + break; + } + break; + case Watch.DisplayType.Signed: + switch (_size) + { + default: + case Watch.WatchSize.Byte: + MaxLength = 4; + break; + case Watch.WatchSize.Word: + MaxLength = 6; + break; + case Watch.WatchSize.DWord: + MaxLength = 11; + break; + } + break; + case Watch.DisplayType.Unsigned: + switch (_size) + { + default: + case Watch.WatchSize.Byte: + MaxLength = 3; + break; + case Watch.WatchSize.Word: + MaxLength = 5; + break; + case Watch.WatchSize.DWord: + MaxLength = 10; + break; + } + break; + case Watch.DisplayType.FixedPoint_12_4: + MaxLength = 9; + break; + case Watch.DisplayType.Float: + MaxLength = 21; + break; + case Watch.DisplayType.FixedPoint_20_12: + MaxLength = 64; + break; } } @@ -397,7 +416,7 @@ namespace BizHawk.MultiClient } } - uint MaxUnsignedInt + private uint MaxUnsignedInt { get { @@ -414,7 +433,7 @@ namespace BizHawk.MultiClient } } - int MaxSignedInt + private int MaxSignedInt { get { @@ -431,7 +450,7 @@ namespace BizHawk.MultiClient } } - double Max12_4 + private double Max12_4 { get { @@ -439,7 +458,7 @@ namespace BizHawk.MultiClient } } - double Max20_12 + private double Max20_12 { get { @@ -447,15 +466,14 @@ namespace BizHawk.MultiClient } } - double _12_4_Unit { get { return 1 / 16.0; } } - double _20_12_Unit { get { return 1 / 4096.0; } } - + private double _12_4_Unit { get { return 1 / 16.0; } } + private double _20_12_Unit { get { return 1 / 4096.0; } } protected override void OnTextChanged(EventArgs e) { if (String.IsNullOrWhiteSpace(Text)) { - Text = "0"; + ResetText(); } } @@ -489,5 +507,41 @@ namespace BizHawk.MultiClient } } } + + public void SetFromRawInt(int val) + { + switch (_type) + { + default: + case Watch.DisplayType.Signed: + Text = val.ToString(); + break; + case Watch.DisplayType.Unsigned: + uint uval = (uint)val; + Text = uval.ToString(); + break; + case Watch.DisplayType.Binary: + uint bval = (uint)val; + int numBits = ((int)ByteSize) * 8; + Text = Convert.ToString(bval, 2).PadLeft(numBits, '0'); + break; + case Watch.DisplayType.Hex: + uint hexVal = (uint)val; + string formatstr = "{0:X" + MaxLength.ToString() + "}"; + Text = String.Format(formatstr, hexVal); + break; + case Watch.DisplayType.FixedPoint_12_4: + Text = String.Format("{0:F5}", (val / 16.0)); + break; + case Watch.DisplayType.FixedPoint_20_12: + Text = String.Format("{0:F5}", (val / 4096.0)); + break; + case Watch.DisplayType.Float: + byte[] bytes = BitConverter.GetBytes(val); + float _float = BitConverter.ToSingle(bytes, 0); + Text = String.Format("{0:F6}", _float); + break; + } + } } } diff --git a/BizHawk.Util/HexTextBox.cs b/BizHawk.Util/HexTextBox.cs index f725145816..73289e5637 100644 --- a/BizHawk.Util/HexTextBox.cs +++ b/BizHawk.Util/HexTextBox.cs @@ -7,22 +7,49 @@ namespace BizHawk public interface INumberBox { int ToRawInt(); + void SetFromRawInt(int rawint); + bool Nullable { get; } } public class HexTextBox : TextBox, INumberBox { private string _addressFormatStr = "{0:X4}"; + private int? _maxSize = null; + private bool _nullable = true; + + public bool Nullable { get { return _nullable; } set { _nullable = value; } } public void SetHexProperties(int domainSize) { - MaxLength = IntHelpers.GetNumDigits(domainSize - 1); + _maxSize = domainSize - 1; + MaxLength = IntHelpers.GetNumDigits(_maxSize.Value); _addressFormatStr = "{0:X" + MaxLength.ToString() + "}"; + ResetText(); } + private uint GetMax() + { + if (_maxSize.HasValue) + { + return (uint)_maxSize.Value; + } + else + { + return IntHelpers.MaxHexValueFromMaxDigits(MaxLength); + } + } + public override void ResetText() { - Text = String.Format(_addressFormatStr, 0); + if (_nullable) + { + Text = String.Empty; + } + else + { + Text = String.Format(_addressFormatStr, 0); + } } public HexTextBox() @@ -50,7 +77,7 @@ namespace BizHawk { uint val = (uint)ToRawInt(); - if (val == IntHelpers.MaxHexValueFromMaxDigits(MaxLength)) + if (val == GetMax()) { val = 0; } @@ -69,7 +96,7 @@ namespace BizHawk uint val = (uint)ToRawInt(); if (val == 0) { - val = IntHelpers.MaxHexValueFromMaxDigits(MaxLength); + val = GetMax(); } else { @@ -104,6 +131,11 @@ namespace BizHawk return int.Parse(Text, NumberStyles.HexNumber); } } + + public void SetFromRawInt(int val) + { + Text = String.Format(_addressFormatStr, val); + } } public class UnsignedIntegerBox : TextBox, INumberBox @@ -113,6 +145,10 @@ namespace BizHawk CharacterCasing = CharacterCasing.Upper; } + private bool _nullable = true; + + public bool Nullable { get { return _nullable; } set { _nullable = value; } } + protected override void OnKeyPress(KeyPressEventArgs e) { if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) @@ -127,7 +163,14 @@ namespace BizHawk public override void ResetText() { - Text = "0"; + if (_nullable) + { + Text = String.Empty; + } + else + { + Text = "0"; + } } protected override void OnKeyDown(KeyEventArgs e) @@ -191,5 +234,10 @@ namespace BizHawk return (int)uint.Parse(Text); } } + + public void SetFromRawInt(int val) + { + Text = val.ToString(); + } } } diff --git a/BizHawk.Util/StringHelpers.cs b/BizHawk.Util/StringHelpers.cs index e03bd26601..ef55c81fd9 100644 --- a/BizHawk.Util/StringHelpers.cs +++ b/BizHawk.Util/StringHelpers.cs @@ -29,19 +29,19 @@ namespace BizHawk } } - //TODO: put it in its own file - public static class IntHelpers //TODO: a less lame name - { - public static int GetNumDigits(Int32 i) - { - //if (i == 0) return 0; - //if (i < 0x10) return 1; - //if (i < 0x100) return 2; - //if (i < 0x1000) return 3; //adelikat: commenting these out because I decided that regardless of domain, 4 digits should be the minimum - if (i < 0x10000) return 4; - if (i < 0x1000000) return 6; - else return 8; - } + //TODO: put it in its own file + public static class IntHelpers //TODO: a less lame name + { + public static int GetNumDigits(Int32 i) + { + //if (i == 0) return 0; + //if (i < 0x10) return 1; + if (i < 0x100) return 2; + //if (i < 0x1000) return 3; //adelikat: let's only do even numbers + if (i < 0x10000) return 4; + if (i < 0x1000000) return 6; + else return 8; + } public static uint MaxHexValueFromMaxDigits(Int32 i) {