Cheat Window - more stuff implemented

This commit is contained in:
andres.delikat 2011-03-17 17:43:57 +00:00
parent 986ff31f69
commit fa29daab13
5 changed files with 118 additions and 11 deletions

View File

@ -98,6 +98,11 @@
public int CheatsWndy = -1;
public int CheatsWidth = -1;
public int CheatsHeight = -1;
public int CheatsNameWidth = -1;
public int CheatsAddressWidth = -1;
public int CheatsValueWidth = -1;
public int CheatsDomainWidth = -1;
public int CheatsOnWidth = -1;
//Movie Settings
public RecentFiles RecentMovies = new RecentFiles(8);

View File

@ -10,8 +10,8 @@ namespace BizHawk.MultiClient
public string name { get; set; }
public int address { get; set; }
public byte value { get; set; }
public bool enabled { get; set; }
public MemoryDomain domain { get; set; }
private bool enabled;
public Cheat()
{
@ -40,5 +40,22 @@ namespace BizHawk.MultiClient
domain = d;
}
public void Enable()
{
enabled = true;
//TODO: freeze
}
public void Disable()
{
enabled = false;
//TODO: freeze
}
public bool IsEnabled()
{
return enabled;
}
}
}

View File

@ -87,6 +87,7 @@
this.label1 = new System.Windows.Forms.Label();
this.NumCheatsLabel = new System.Windows.Forms.Label();
this.EditButton = new System.Windows.Forms.Button();
this.restoreWindowSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CheatsMenu.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.AddCheatGroup.SuspendLayout();
@ -119,6 +120,7 @@
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.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.CheatListView_AfterLabelEdit);
//
// CheatName
//
@ -324,7 +326,8 @@
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.saveWindowPositionToolStripMenuItem,
this.findAndLoadCheatFileByGameToolStripMenuItem,
this.autoTurnOnCheatsOnLoadToolStripMenuItem});
this.autoTurnOnCheatsOnLoadToolStripMenuItem,
this.restoreWindowSizeToolStripMenuItem});
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(56, 20);
this.optionsToolStripMenuItem.Text = "&Options";
@ -544,6 +547,7 @@
this.ValueBox.Size = new System.Drawing.Size(65, 20);
this.ValueBox.TabIndex = 5;
this.ValueBox.TextChanged += new System.EventHandler(this.ValueBox_TextChanged);
this.ValueBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ValueBox_KeyPress);
//
// AddressBox
//
@ -554,6 +558,7 @@
this.AddressBox.Size = new System.Drawing.Size(65, 20);
this.AddressBox.TabIndex = 4;
this.AddressBox.TextChanged += new System.EventHandler(this.AddressBox_TextChanged);
this.AddressBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.AddressBox_KeyPress);
//
// NameBox
//
@ -610,6 +615,13 @@
this.EditButton.UseVisualStyleBackColor = true;
this.EditButton.Click += new System.EventHandler(this.EditButton_Click);
//
// restoreWindowSizeToolStripMenuItem
//
this.restoreWindowSizeToolStripMenuItem.Name = "restoreWindowSizeToolStripMenuItem";
this.restoreWindowSizeToolStripMenuItem.Size = new System.Drawing.Size(248, 22);
this.restoreWindowSizeToolStripMenuItem.Text = "Restore Window Size";
this.restoreWindowSizeToolStripMenuItem.Click += new System.EventHandler(this.restoreWindowSizeToolStripMenuItem_Click);
//
// Cheats
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -696,5 +708,6 @@
private System.Windows.Forms.ComboBox DomainComboBox;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button EditButton;
private System.Windows.Forms.ToolStripMenuItem restoreWindowSizeToolStripMenuItem;
}
}

View File

@ -13,14 +13,19 @@ namespace BizHawk.MultiClient
{
public partial class Cheats : Form
{
//Implement Edit button
//Input validation on address & value boxes
//Set address box text load based on memory domain size
//File format - saving & loading
//Shortcuts for Cheat menu items
//Implement Options menu settings
//Save column widths
//Implement Freeze/Unfreeze on enabled changed in Cheat object
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
int defaultNameWidth;
int defaultAddressWidth;
int defaultValueWidth;
int defaultDomainWidth;
int defaultOnWidth;
List<Cheat> cheatList = new List<Cheat>();
string currentCheatFile = "";
@ -55,7 +60,7 @@ namespace BizHawk.MultiClient
{
if (cheatList[index].address < 0)
color = Color.DarkGray;
else if (!cheatList[index].enabled)
else if (!cheatList[index].IsEnabled())
color = this.BackColor;
}
@ -83,7 +88,7 @@ namespace BizHawk.MultiClient
}
if (column == 4) //Enabled
{
if (cheatList[index].enabled)
if (cheatList[index].IsEnabled())
text = "*";
else
text = "";
@ -101,6 +106,7 @@ namespace BizHawk.MultiClient
{
LoadConfigSettings();
PopulateMemoryDomainComboBox();
AddressBox.MaxLength = GetNumDigits(Global.Emulator.MainMemory.Size - 1);
}
private void PopulateMemoryDomainComboBox()
@ -191,6 +197,11 @@ namespace BizHawk.MultiClient
{
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height;
defaultNameWidth = CheatListView.Columns[0].Width;
defaultAddressWidth = CheatListView.Columns[1].Width;
defaultValueWidth = CheatListView.Columns[2].Width;
defaultDomainWidth = CheatListView.Columns[3].Width;
defaultOnWidth = CheatListView.Columns[4].Width;
if (Global.Config.CheatsWndx >= 0 && Global.Config.CheatsWndy >= 0)
Location = new Point(Global.Config.CheatsWndx, Global.Config.CheatsWndy);
@ -199,6 +210,17 @@ namespace BizHawk.MultiClient
{
Size = new System.Drawing.Size(Global.Config.CheatsWidth, Global.Config.CheatsHeight);
}
if (Global.Config.CheatsNameWidth > 0)
CheatListView.Columns[0].Width = Global.Config.CheatsNameWidth;
if (Global.Config.CheatsAddressWidth > 0)
CheatListView.Columns[1].Width = Global.Config.CheatsAddressWidth;
if (Global.Config.CheatsValueWidth > 0)
CheatListView.Columns[2].Width = Global.Config.CheatsValueWidth;
if (Global.Config.CheatsDomainWidth > 0)
CheatListView.Columns[3].Width = Global.Config.CheatsDomainWidth;
if (Global.Config.CheatsOnWidth > 0)
CheatListView.Columns[4].Width = Global.Config.CheatsOnWidth;
}
public void SaveConfigSettings()
@ -207,6 +229,12 @@ namespace BizHawk.MultiClient
Global.Config.CheatsWndy = this.Location.Y;
Global.Config.CheatsWidth = this.Right - this.Left;
Global.Config.CheatsHeight = this.Bottom - this.Top;
Global.Config.CheatsNameWidth = CheatListView.Columns[0].Width;
Global.Config.CheatsAddressWidth = CheatListView.Columns[1].Width;
Global.Config.CheatsValueWidth = CheatListView.Columns[2].Width;
Global.Config.CheatsDomainWidth = CheatListView.Columns[3].Width;
Global.Config.CheatsOnWidth = CheatListView.Columns[4].Width;
}
private void DisplayCheatsList()
@ -523,7 +551,7 @@ namespace BizHawk.MultiClient
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: validation
c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
c.domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
c.enabled = true;
c.Enable();
return c;
}
@ -611,7 +639,10 @@ namespace BizHawk.MultiClient
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
if (indexes.Count > 0)
{
cheatList[indexes[0]].enabled ^= true;
if (cheatList[indexes[0]].IsEnabled())
cheatList[indexes[0]].Enable();
else
cheatList[indexes[0]].Disable();
CheatListView.Refresh();
}
}
@ -635,7 +666,14 @@ namespace BizHawk.MultiClient
private void EditButton_Click(object sender, EventArgs e)
{
//TODO Modify seletcted index 0 with cheat values
//TODO: this fails because selected index must go away to edit values, either prevent that or keep track of the last selected index
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
if (indexes.Count > 0)
{
if (AddressBox.Text.Length > 0 && ValueBox.Text.Length > 0)
cheatList[indexes[0]] = MakeCheat();
CheatListView.Refresh();
}
}
private void CheatListView_SelectedIndexChanged(object sender, EventArgs e)
@ -670,5 +708,38 @@ namespace BizHawk.MultiClient
AddCheatButton.Enabled = false;
}
private void AddressBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidHexNumber(e.KeyChar))
e.Handled = true;
}
private void ValueBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidHexNumber(e.KeyChar))
e.Handled = true;
}
private void CheatListView_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
if (e.Label == null) //If no change
return;
string Str = e.Label;
int index = e.Item;
cheatList[e.Item].name = Str;
}
private void restoreWindowSizeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(defaultWidth, defaultHeight);
CheatListView.Columns[0].Width = defaultNameWidth;
CheatListView.Columns[1].Width = defaultAddressWidth;
CheatListView.Columns[2].Width = defaultValueWidth;
CheatListView.Columns[3].Width = defaultDomainWidth;
CheatListView.Columns[4].Width = defaultOnWidth;
}
}
}

View File

@ -20,7 +20,8 @@ namespace BizHawk.MultiClient
//Ability to watch in different memory domains
//.wch format includes platform and domain type
//address num digits based on domain size
//Refactor column width settings like Cheats, default valeu = -1, and check for negative values
//Refactor restore window size by saving widths in constructor and use them to restore
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
List<Watch> watchList = new List<Watch>();