Cheat Window - more fix ups

This commit is contained in:
andres.delikat 2011-03-17 17:00:06 +00:00
parent 446b049639
commit 986ff31f69
3 changed files with 128 additions and 18 deletions

View File

@ -11,6 +11,7 @@ namespace BizHawk.MultiClient
public int address { get; set; } public int address { get; set; }
public byte value { get; set; } public byte value { get; set; }
public bool enabled { get; set; } public bool enabled { get; set; }
public MemoryDomain domain { get; set; }
public Cheat() public Cheat()
{ {
@ -18,6 +19,7 @@ namespace BizHawk.MultiClient
address = 0; address = 0;
value = 0; value = 0;
enabled = false; enabled = false;
domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
} }
public Cheat(Cheat c) public Cheat(Cheat c)
@ -26,14 +28,16 @@ namespace BizHawk.MultiClient
address = c.address; address = c.address;
value = c.value; value = c.value;
enabled = c.enabled; enabled = c.enabled;
domain = c.domain;
} }
public Cheat(string cname, int addr, byte val, int comp, bool e) public Cheat(string cname, int addr, byte val, int comp, bool e, MemoryDomain d)
{ {
name = cname; name = cname;
address = addr; address = addr;
value = val; value = val;
enabled = e; enabled = e;
domain = d;
} }
} }

View File

@ -33,6 +33,7 @@
this.CheatName = new System.Windows.Forms.ColumnHeader(); this.CheatName = new System.Windows.Forms.ColumnHeader();
this.Address = new System.Windows.Forms.ColumnHeader(); this.Address = new System.Windows.Forms.ColumnHeader();
this.Value = new System.Windows.Forms.ColumnHeader(); this.Value = new System.Windows.Forms.ColumnHeader();
this.Domain = new System.Windows.Forms.ColumnHeader();
this.On = new System.Windows.Forms.ColumnHeader(); this.On = new System.Windows.Forms.ColumnHeader();
this.CheatsMenu = new System.Windows.Forms.MenuStrip(); this.CheatsMenu = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -73,6 +74,8 @@
this.toolStripButtonMoveDown = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonMoveDown = new System.Windows.Forms.ToolStripButton();
this.MessageLabel = new System.Windows.Forms.Label(); this.MessageLabel = new System.Windows.Forms.Label();
this.AddCheatGroup = new System.Windows.Forms.GroupBox(); this.AddCheatGroup = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.DomainComboBox = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.AddCheatButton = new System.Windows.Forms.Button(); this.AddCheatButton = new System.Windows.Forms.Button();
@ -83,6 +86,7 @@
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.NumCheatsLabel = new System.Windows.Forms.Label(); this.NumCheatsLabel = new System.Windows.Forms.Label();
this.EditButton = new System.Windows.Forms.Button();
this.CheatsMenu.SuspendLayout(); this.CheatsMenu.SuspendLayout();
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
this.AddCheatGroup.SuspendLayout(); this.AddCheatGroup.SuspendLayout();
@ -99,6 +103,7 @@
this.CheatName, this.CheatName,
this.Address, this.Address,
this.Value, this.Value,
this.Domain,
this.On}); this.On});
this.CheatListView.FullRowSelect = true; this.CheatListView.FullRowSelect = true;
this.CheatListView.GridLines = true; this.CheatListView.GridLines = true;
@ -107,29 +112,38 @@
this.CheatListView.Location = new System.Drawing.Point(12, 72); this.CheatListView.Location = new System.Drawing.Point(12, 72);
this.CheatListView.Name = "CheatListView"; this.CheatListView.Name = "CheatListView";
this.CheatListView.selectedItem = -1; this.CheatListView.selectedItem = -1;
this.CheatListView.Size = new System.Drawing.Size(294, 277); this.CheatListView.Size = new System.Drawing.Size(298, 277);
this.CheatListView.TabIndex = 0; this.CheatListView.TabIndex = 0;
this.CheatListView.UseCompatibleStateImageBehavior = false; this.CheatListView.UseCompatibleStateImageBehavior = false;
this.CheatListView.View = System.Windows.Forms.View.Details; this.CheatListView.View = System.Windows.Forms.View.Details;
this.CheatListView.Click += new System.EventHandler(this.CheatListView_Click); this.CheatListView.Click += new System.EventHandler(this.CheatListView_Click);
this.CheatListView.SelectedIndexChanged += new System.EventHandler(this.CheatListView_SelectedIndexChanged);
this.CheatListView.DoubleClick += new System.EventHandler(this.CheatListView_DoubleClick); this.CheatListView.DoubleClick += new System.EventHandler(this.CheatListView_DoubleClick);
// //
// CheatName // CheatName
// //
this.CheatName.Text = "Name"; this.CheatName.Text = "Name";
this.CheatName.Width = 110; this.CheatName.Width = 104;
// //
// Address // Address
// //
this.Address.Text = "Address"; this.Address.Text = "Address";
this.Address.Width = 52;
// //
// Value // Value
// //
this.Value.Text = "Value"; this.Value.Text = "Value";
this.Value.Width = 40;
//
// Domain
//
this.Domain.Text = "Domain";
this.Domain.Width = 58;
// //
// On // On
// //
this.On.Text = "On"; this.On.Text = "On";
this.On.Width = 40;
// //
// CheatsMenu // CheatsMenu
// //
@ -456,6 +470,9 @@
// AddCheatGroup // AddCheatGroup
// //
this.AddCheatGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.AddCheatGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.AddCheatGroup.Controls.Add(this.EditButton);
this.AddCheatGroup.Controls.Add(this.label6);
this.AddCheatGroup.Controls.Add(this.DomainComboBox);
this.AddCheatGroup.Controls.Add(this.label5); this.AddCheatGroup.Controls.Add(this.label5);
this.AddCheatGroup.Controls.Add(this.label4); this.AddCheatGroup.Controls.Add(this.label4);
this.AddCheatGroup.Controls.Add(this.AddCheatButton); this.AddCheatGroup.Controls.Add(this.AddCheatButton);
@ -467,15 +484,32 @@
this.AddCheatGroup.Controls.Add(this.label1); this.AddCheatGroup.Controls.Add(this.label1);
this.AddCheatGroup.Location = new System.Drawing.Point(327, 72); this.AddCheatGroup.Location = new System.Drawing.Point(327, 72);
this.AddCheatGroup.Name = "AddCheatGroup"; this.AddCheatGroup.Name = "AddCheatGroup";
this.AddCheatGroup.Size = new System.Drawing.Size(170, 150); this.AddCheatGroup.Size = new System.Drawing.Size(170, 225);
this.AddCheatGroup.TabIndex = 4; this.AddCheatGroup.TabIndex = 4;
this.AddCheatGroup.TabStop = false; this.AddCheatGroup.TabStop = false;
this.AddCheatGroup.Text = "Add Cheat"; this.AddCheatGroup.Text = "Add Cheat";
// //
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(7, 120);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(83, 13);
this.label6.TabIndex = 10;
this.label6.Text = "Memory Domain";
//
// DomainComboBox
//
this.DomainComboBox.FormattingEnabled = true;
this.DomainComboBox.Location = new System.Drawing.Point(10, 136);
this.DomainComboBox.Name = "DomainComboBox";
this.DomainComboBox.Size = new System.Drawing.Size(100, 21);
this.DomainComboBox.TabIndex = 9;
//
// label5 // label5
// //
this.label5.AutoSize = true; this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(80, 85); this.label5.Location = new System.Drawing.Point(80, 87);
this.label5.Name = "label5"; this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(18, 13); this.label5.Size = new System.Drawing.Size(18, 13);
this.label5.TabIndex = 8; this.label5.TabIndex = 8;
@ -484,7 +518,7 @@
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(80, 56); this.label4.Location = new System.Drawing.Point(80, 58);
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(18, 13); this.label4.Size = new System.Drawing.Size(18, 13);
this.label4.TabIndex = 7; this.label4.TabIndex = 7;
@ -492,7 +526,8 @@
// //
// AddCheatButton // AddCheatButton
// //
this.AddCheatButton.Location = new System.Drawing.Point(99, 115); this.AddCheatButton.Enabled = false;
this.AddCheatButton.Location = new System.Drawing.Point(10, 187);
this.AddCheatButton.Name = "AddCheatButton"; this.AddCheatButton.Name = "AddCheatButton";
this.AddCheatButton.Size = new System.Drawing.Size(65, 23); this.AddCheatButton.Size = new System.Drawing.Size(65, 23);
this.AddCheatButton.TabIndex = 6; this.AddCheatButton.TabIndex = 6;
@ -503,16 +538,17 @@
// ValueBox // ValueBox
// //
this.ValueBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; this.ValueBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
this.ValueBox.Location = new System.Drawing.Point(99, 79); this.ValueBox.Location = new System.Drawing.Point(99, 81);
this.ValueBox.MaxLength = 2; this.ValueBox.MaxLength = 2;
this.ValueBox.Name = "ValueBox"; this.ValueBox.Name = "ValueBox";
this.ValueBox.Size = new System.Drawing.Size(65, 20); this.ValueBox.Size = new System.Drawing.Size(65, 20);
this.ValueBox.TabIndex = 5; this.ValueBox.TabIndex = 5;
this.ValueBox.TextChanged += new System.EventHandler(this.ValueBox_TextChanged);
// //
// AddressBox // AddressBox
// //
this.AddressBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; this.AddressBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
this.AddressBox.Location = new System.Drawing.Point(99, 51); this.AddressBox.Location = new System.Drawing.Point(99, 53);
this.AddressBox.MaxLength = 8; this.AddressBox.MaxLength = 8;
this.AddressBox.Name = "AddressBox"; this.AddressBox.Name = "AddressBox";
this.AddressBox.Size = new System.Drawing.Size(65, 20); this.AddressBox.Size = new System.Drawing.Size(65, 20);
@ -525,11 +561,12 @@
this.NameBox.Name = "NameBox"; this.NameBox.Name = "NameBox";
this.NameBox.Size = new System.Drawing.Size(100, 20); this.NameBox.Size = new System.Drawing.Size(100, 20);
this.NameBox.TabIndex = 3; this.NameBox.TabIndex = 3;
this.NameBox.TextChanged += new System.EventHandler(this.NameBox_TextChanged);
// //
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(7, 82); this.label3.Location = new System.Drawing.Point(7, 84);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(34, 13); this.label3.Size = new System.Drawing.Size(34, 13);
this.label3.TabIndex = 2; this.label3.TabIndex = 2;
@ -538,7 +575,7 @@
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 54); this.label2.Location = new System.Drawing.Point(6, 56);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(45, 13); this.label2.Size = new System.Drawing.Size(45, 13);
this.label2.TabIndex = 1; this.label2.TabIndex = 1;
@ -562,6 +599,17 @@
this.NumCheatsLabel.TabIndex = 5; this.NumCheatsLabel.TabIndex = 5;
this.NumCheatsLabel.Text = "0 Cheats"; this.NumCheatsLabel.Text = "0 Cheats";
// //
// EditButton
//
this.EditButton.Enabled = false;
this.EditButton.Location = new System.Drawing.Point(99, 187);
this.EditButton.Name = "EditButton";
this.EditButton.Size = new System.Drawing.Size(65, 23);
this.EditButton.TabIndex = 11;
this.EditButton.Text = "&Edit";
this.EditButton.UseVisualStyleBackColor = true;
this.EditButton.Click += new System.EventHandler(this.EditButton_Click);
//
// Cheats // Cheats
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -608,6 +656,7 @@
private System.Windows.Forms.ColumnHeader CheatName; private System.Windows.Forms.ColumnHeader CheatName;
private System.Windows.Forms.ColumnHeader Address; private System.Windows.Forms.ColumnHeader Address;
private System.Windows.Forms.ColumnHeader Value; private System.Windows.Forms.ColumnHeader Value;
private System.Windows.Forms.ColumnHeader Domain;
private System.Windows.Forms.ColumnHeader On; private System.Windows.Forms.ColumnHeader On;
private System.Windows.Forms.ToolStripMenuItem duplicateToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem duplicateToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
@ -644,5 +693,8 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem autoLoadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem autoLoadToolStripMenuItem;
private System.Windows.Forms.ComboBox DomainComboBox;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button EditButton;
} }
} }

View File

@ -13,12 +13,11 @@ namespace BizHawk.MultiClient
{ {
public partial class Cheats : Form public partial class Cheats : Form
{ {
//Implement Edit button
//Input validation on address & value boxes //Input validation on address & value boxes
//Set address box text load based on memory domain size //Set address box text load based on memory domain size
//Memory domains
//File format - saving & loading //File format - saving & loading
//Shortcuts for Cheat menu items //Shortcuts for Cheat menu items
//Edit button enabled conditionally on highlighted listview item
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight; int defaultHeight;
@ -55,14 +54,17 @@ namespace BizHawk.MultiClient
private void CheatListView_QueryItemBkColor(int index, int column, ref Color color) private void CheatListView_QueryItemBkColor(int index, int column, ref Color color)
{ {
if (cheatList[index].address < 0) if (cheatList[index].address < 0)
color = Color.DarkGray;
else if (!cheatList[index].enabled)
color = this.BackColor; color = this.BackColor;
else if (cheatList[index].enabled)
color = Color.Pink;
} }
private void CheatListView_QueryItemText(int index, int column, out string text) private void CheatListView_QueryItemText(int index, int column, out string text)
{ {
text = ""; text = "";
if (cheatList[index].address == -1)
return;
if (column == 0) //Name if (column == 0) //Name
{ {
text = cheatList[index].name; text = cheatList[index].name;
@ -75,7 +77,11 @@ namespace BizHawk.MultiClient
{ {
text = String.Format("{0:X2}", cheatList[index].value); text = String.Format("{0:X2}", cheatList[index].value);
} }
if (column == 3) //Enabled if (column == 3) //Domain
{
text = cheatList[index].domain.Name;
}
if (column == 4) //Enabled
{ {
if (cheatList[index].enabled) if (cheatList[index].enabled)
text = "*"; text = "*";
@ -94,6 +100,20 @@ namespace BizHawk.MultiClient
private void Cheats_Load(object sender, EventArgs e) private void Cheats_Load(object sender, EventArgs e)
{ {
LoadConfigSettings(); LoadConfigSettings();
PopulateMemoryDomainComboBox();
}
private void PopulateMemoryDomainComboBox()
{
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);
}
DomainComboBox.SelectedIndex = 0;
}
} }
public void AddCheat(Cheat c) public void AddCheat(Cheat c)
@ -471,7 +491,6 @@ namespace BizHawk.MultiClient
{ {
Cheat c = new Cheat(); Cheat c = new Cheat();
c.address = -1; c.address = -1;
c.name = "Separator"; //TODO: remove me
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices; ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
int x; int x;
@ -503,6 +522,8 @@ namespace BizHawk.MultiClient
c.name = NameBox.Text; c.name = NameBox.Text;
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: validation c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: validation
c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber)); c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
c.domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
c.enabled = true;
return c; return c;
} }
@ -612,9 +633,42 @@ namespace BizHawk.MultiClient
return String.Format("{0:X" + GetNumDigits((Global.Emulator.MainMemory.Size - 1)).ToString() + "}", address); return String.Format("{0:X" + GetNumDigits((Global.Emulator.MainMemory.Size - 1)).ToString() + "}", address);
} }
private void EditButton_Click(object sender, EventArgs e)
{
//TODO Modify seletcted index 0 with cheat values
}
private void CheatListView_SelectedIndexChanged(object sender, EventArgs e)
{
if (CheatListView.SelectedIndices.Count > 0)
EditButton.Enabled = true;
else
EditButton.Enabled = false;
}
private void AddressBox_TextChanged(object sender, EventArgs e) private void AddressBox_TextChanged(object sender, EventArgs e)
{ {
if (AddressBox.Text.Length > 0 && ValueBox.Text.Length > 0)
AddCheatButton.Enabled = true;
else
AddCheatButton.Enabled = false;
} }
private void ValueBox_TextChanged(object sender, EventArgs e)
{
if (AddressBox.Text.Length > 0 && ValueBox.Text.Length > 0)
AddCheatButton.Enabled = true;
else
AddCheatButton.Enabled = false;
}
private void NameBox_TextChanged(object sender, EventArgs e)
{
if (AddressBox.Text.Length > 0 && ValueBox.Text.Length > 0)
AddCheatButton.Enabled = true;
else
AddCheatButton.Enabled = false;
}
} }
} }