New Cheat Search - implement various things

This commit is contained in:
adelikat 2013-10-04 16:06:08 +00:00
parent 1c4a479f23
commit 55cab352a1
8 changed files with 248 additions and 58 deletions

View File

@ -412,6 +412,27 @@ namespace BizHawk.MultiClient
public int CheatsCompareIndex = 3;
public int CheatsOnIndex = 4;
public int CheatsDomainIndex = 5;
public bool CheatsAlwaysOnTop = false;
public Dictionary<string, int> CheatsColumnWidths = new Dictionary<string, int>()
{
{ "NamesColumn", -1 },
{ "AddressColumn", -1 },
{ "ValueColumn", -1 },
{ "CompareColumn", -1 },
{ "OnColumn", -1 },
{ "DomainColumn", -1 },
};
public Dictionary<string, int> CheatsColumnIndexes = new Dictionary<string, int>()
{
{ "NamesColumn", 0 },
{ "AddressColumn", 1 },
{ "ValueColumn", 2 },
{ "CompareColumn", 3 },
{ "OnColumn", 4 },
{ "DomainColumn", 5 },
};
// TAStudio Dialog
public bool TAStudioSaveWindowPosition = true;

View File

@ -57,6 +57,12 @@ namespace BizHawk.MultiClient
_cheatList.Add(c);
}
public void Insert(int index, NewCheat c)
{
_changes = true;
_cheatList.Insert(index, c);
}
public void Remove(NewCheat c)
{
_changes = true;

View File

@ -20,7 +20,7 @@ namespace BizHawk.MultiClient
}
}
public static NewCheat SeparatorInstance
public static NewCheat Separator
{
get { return new NewCheat(SeparatorWatch.Instance, null, false); }
}
@ -71,6 +71,26 @@ namespace BizHawk.MultiClient
get { return _watch.Type; }
}
public string Name
{
get { if (IsSeparator) return String.Empty; else return _watch.Notes; }
}
public string AddressStr
{
get { return "TODO"; }
}
public string ValueStr
{
get { return "TODO"; }
}
public string CompareStr
{
get { return "TODO"; }
}
#endregion
#region Actions

View File

@ -67,6 +67,7 @@
this.ShowValuesAsHexMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AutoloadDialogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.RestoreWindowSizeMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ColumnsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
@ -293,12 +294,12 @@
//
// InsertSeparatorMenuItem
//
this.InsertSeparatorMenuItem.Enabled = false;
this.InsertSeparatorMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.InsertSeparator;
this.InsertSeparatorMenuItem.Name = "InsertSeparatorMenuItem";
this.InsertSeparatorMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.I)));
this.InsertSeparatorMenuItem.Size = new System.Drawing.Size(233, 22);
this.InsertSeparatorMenuItem.Text = "Insert Separator";
this.InsertSeparatorMenuItem.Click += new System.EventHandler(this.InsertSeparatorMenuItem_Click);
//
// toolStripSeparator3
//
@ -365,6 +366,7 @@
this.ShowValuesAsHexMenuItem,
this.AutoloadDialogMenuItem,
this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem,
this.toolStripSeparator5,
this.RestoreWindowSizeMenuItem});
this.OptionsSubMenu.Name = "OptionsSubMenu";
@ -409,10 +411,17 @@
//
// SaveWindowPositionMenuItem
//
this.SaveWindowPositionMenuItem.Enabled = false;
this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem";
this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(205, 22);
this.SaveWindowPositionMenuItem.Text = "Save Window Position";
this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click);
//
// AlwaysOnTopMenuItem
//
this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem";
this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(205, 22);
this.AlwaysOnTopMenuItem.Text = "Always on &Top";
this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
//
// toolStripSeparator5
//
@ -512,12 +521,12 @@
// toolStripButtonSeparator
//
this.toolStripButtonSeparator.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButtonSeparator.Enabled = false;
this.toolStripButtonSeparator.Image = global::BizHawk.MultiClient.Properties.Resources.InsertSeparator;
this.toolStripButtonSeparator.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButtonSeparator.Name = "toolStripButtonSeparator";
this.toolStripButtonSeparator.Size = new System.Drawing.Size(23, 22);
this.toolStripButtonSeparator.Text = "Insert Separator";
this.toolStripButtonSeparator.Click += new System.EventHandler(this.InsertSeparatorMenuItem_Click);
//
// toolStripSeparator2
//
@ -655,5 +664,6 @@
private System.Windows.Forms.Label TotalLabel;
private System.Windows.Forms.ToolStripMenuItem ColumnsSubMenu;
private System.Windows.Forms.Label MessageLabel;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
}
}

View File

@ -13,6 +13,28 @@ namespace BizHawk.MultiClient
{
public partial class NewCheatForm : Form
{
public const string NAME = "NamesColumn";
public const string ADDRESS = "AddressColumn";
public const string VALUE = "ValueColumn";
public const string COMPARE = "CompareColumn";
public const string ON = "OnColumn";
public const string DOMAIN = "DomainColumn";
private readonly Dictionary<string, int> DefaultColumnWidths = new Dictionary<string, int>
{
{ NAME, 128 },
{ ADDRESS, 60 },
{ VALUE, 59 },
{ COMPARE, 59 },
{ ON, 25 },
{ DOMAIN, 55 },
};
private int defaultWidth;
private int defaultHeight;
private string _sortedColumn = "";
private bool _sortReverse = false;
public NewCheatForm()
{
InitializeComponent();
@ -20,6 +42,10 @@ namespace BizHawk.MultiClient
CheatListView.QueryItemText += CheatListView_QueryItemText;
CheatListView.QueryItemBkColor += CheatListView_QueryItemBkColor;
CheatListView.VirtualMode = true;
_sortedColumn = "";
_sortReverse = false;
TopMost = Global.Config.CheatsAlwaysOnTop;
}
private void UpdateListView()
@ -104,7 +130,7 @@ namespace BizHawk.MultiClient
private void NewCheatForm_Load(object sender, EventArgs e)
{
LoadConfigSettings();
}
public void SaveConfigSettings()
@ -112,14 +138,78 @@ namespace BizHawk.MultiClient
/*TODO*/
}
private void LoadConfigSettings()
{
//Size and Positioning
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height;
if (Global.Config.CheatsSaveWindowPosition && Global.Config.CheatsWndx >= 0 && Global.Config.CheatsWndy >= 0)
{
Location = new Point(Global.Config.CheatsWndx, Global.Config.CheatsWndy);
}
if (Global.Config.CheatsWidth >= 0 && Global.Config.CheatsHeight >= 0)
{
Size = new Size(Global.Config.CheatsWidth, Global.Config.CheatsHeight);
}
LoadColumnInfo();
}
private void LoadColumnInfo()
{
CheatListView.Columns.Clear();
ToolHelpers.AddColumn(CheatListView, NAME, true, GetColumnWidth(NAME));
ToolHelpers.AddColumn(CheatListView, ADDRESS, true, GetColumnWidth(ADDRESS));
ToolHelpers.AddColumn(CheatListView, VALUE, true, GetColumnWidth(VALUE));
ToolHelpers.AddColumn(CheatListView, COMPARE, true, GetColumnWidth(COMPARE));
ToolHelpers.AddColumn(CheatListView, ON, true, GetColumnWidth(ON));
ToolHelpers.AddColumn(CheatListView, DOMAIN, true, GetColumnWidth(DOMAIN));
}
private int GetColumnWidth(string columnName)
{
var width = Global.Config.CheatsColumnWidths[columnName];
if (width == -1)
{
width = DefaultColumnWidths[columnName];
}
return width;
}
private void CheatListView_QueryItemText(int index, int column, out string text)
{
text = "";
if (Global.CheatList2[index].IsSeparator)
if (index >= Global.CheatList2.Count || Global.CheatList2[index].IsSeparator)
{
return;
}
/*TODO*/
string columnName = CheatListView.Columns[column].Name;
switch (columnName)
{
case NAME:
text = Global.CheatList2[index].Name;
break;
case ADDRESS:
text = Global.CheatList2[index].AddressStr;
break;
case VALUE:
text = Global.CheatList2[index].ValueStr;
break;
case COMPARE:
text = Global.CheatList2[index].CompareStr;
break;
case ON:
text = Global.CheatList2[index].Enabled ? "*" : "";
break;
case DOMAIN:
text = Global.CheatList2[index].Domain.Name;
break;
}
}
private void CheatListView_QueryItemBkColor(int index, int column, ref Color color)
@ -128,16 +218,52 @@ namespace BizHawk.MultiClient
{
if (Global.CheatList2[index].IsSeparator)
{
color = Color.DarkGray;
color = BackColor;
}
else if (Global.CheatList2[index].Enabled)
{
color = Color.LightCyan;
}
else
}
}
private List<int> SelectedIndices
{
get
{
var selected = new List<int>();
ListView.SelectedIndexCollection indices = CheatListView.SelectedIndices;
foreach (int index in indices)
{
color = BackColor;
selected.Add(index);
}
return selected;
}
}
private List<NewCheat> SelectedItems
{
get
{
var selected = new List<NewCheat>();
if (SelectedIndices.Any())
{
foreach (int index in SelectedIndices)
{
if (!Global.CheatList2[index].IsSeparator)
{
selected.Add(Global.CheatList2[index]);
}
}
}
return selected;
}
}
private List<NewCheat> SelectedCheats
{
get
{
return SelectedItems.Where(x => !x.IsSeparator).ToList();
}
}
@ -176,13 +302,38 @@ namespace BizHawk.MultiClient
}
private void InsertSeparatorMenuItem_Click(object sender, EventArgs e)
{
if (SelectedIndices.Any())
{
Global.CheatList2.Insert(SelectedIndices.Max(), NewCheat.Separator);
}
else
{
Global.CheatList2.Add(NewCheat.Separator);
}
UpdateListView();
}
#endregion
#region Options
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
{
AlwaysOnTopMenuItem.Checked = Global.Config.CheatsAlwaysOnTop;
SaveWindowPositionMenuItem.Checked = Global.Config.CheatsSaveWindowPosition;
}
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.CheatsSaveWindowPosition ^= true;
}
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
{
Global.Config.CheatsAlwaysOnTop ^= true;
}
#endregion

View File

@ -146,5 +146,23 @@ namespace BizHawk.MultiClient
return Global.Emulator.MainMemory;
}
public static void AddColumn(ListView listView, string columnName, bool enabled, int columnWidth)
{
if (enabled)
{
if (listView.Columns[columnName] == null)
{
ColumnHeader column = new ColumnHeader
{
Name = columnName,
Text = columnName.Replace("Column", ""),
Width = columnWidth,
};
listView.Columns.Add(column);
}
}
}
}
}

View File

@ -387,11 +387,11 @@ namespace BizHawk.MultiClient
private void LoadColumnInfo()
{
WatchListView.Columns.Clear();
AddColumn(ADDRESS, true);
AddColumn(VALUE, true);
AddColumn(PREV, Global.Config.RamSearchShowPrevColumn);
AddColumn(CHANGES, Global.Config.RamSearchShowChangeColumn);
AddColumn(DIFF, Global.Config.RamSearchShowDiffColumn);
ToolHelpers.AddColumn(WatchListView, ADDRESS, true, GetColumnWidth(ADDRESS));
ToolHelpers.AddColumn(WatchListView, VALUE, true, GetColumnWidth(VALUE));
ToolHelpers.AddColumn(WatchListView, PREV, Global.Config.RamSearchShowPrevColumn, GetColumnWidth(PREV));
ToolHelpers.AddColumn(WatchListView, CHANGES, Global.Config.RamSearchShowChangeColumn, GetColumnWidth(CHANGES));
ToolHelpers.AddColumn(WatchListView, DIFF, Global.Config.RamSearchShowDiffColumn, GetColumnWidth(DIFF));
ColumnPositions();
}
@ -456,24 +456,6 @@ namespace BizHawk.MultiClient
return width;
}
private void AddColumn(string columnName, bool enabled)
{
if (enabled)
{
if (WatchListView.Columns[columnName] == null)
{
ColumnHeader column = new ColumnHeader
{
Name = columnName,
Text = columnName.Replace("Column", ""),
Width = GetColumnWidth(columnName),
};
WatchListView.Columns.Add(column);
}
}
}
private void DoDisplayTypeClick(Watch.DisplayType type)
{
if (Settings.Type != type && !String.IsNullOrEmpty(SpecificValueBox.Text))

View File

@ -615,24 +615,6 @@ namespace BizHawk.MultiClient
}
}
private void AddColumn(string columnName, bool enabled)
{
if (enabled)
{
if (WatchListView.Columns[columnName] == null)
{
ColumnHeader column = new ColumnHeader
{
Name = columnName,
Text = columnName.Replace("Column", ""),
Width = GetColumnWidth(columnName),
};
WatchListView.Columns.Add(column);
}
}
}
private void ColumnPositions()
{
List<KeyValuePair<string, int>> Columns =
@ -671,13 +653,13 @@ namespace BizHawk.MultiClient
private void LoadColumnInfo()
{
WatchListView.Columns.Clear();
AddColumn(ADDRESS, true);
AddColumn(VALUE, true);
AddColumn(PREV, Global.Config.RamWatchShowPrevColumn);
AddColumn(CHANGES, Global.Config.RamWatchShowChangeColumn);
AddColumn(DIFF, Global.Config.RamWatchShowDiffColumn);
AddColumn(DOMAIN, Global.Config.RamWatchShowDomainColumn);
AddColumn(NOTES, true);
ToolHelpers.AddColumn(WatchListView, ADDRESS, true, GetColumnWidth(ADDRESS));
ToolHelpers.AddColumn(WatchListView, VALUE, true, GetColumnWidth(VALUE));
ToolHelpers.AddColumn(WatchListView, PREV, Global.Config.RamWatchShowPrevColumn, GetColumnWidth(PREV));
ToolHelpers.AddColumn(WatchListView, CHANGES, Global.Config.RamWatchShowChangeColumn, GetColumnWidth(CHANGES));
ToolHelpers.AddColumn(WatchListView, DIFF, Global.Config.RamWatchShowDiffColumn, GetColumnWidth(DIFF));
ToolHelpers.AddColumn(WatchListView, DOMAIN, Global.Config.RamWatchShowDomainColumn, GetColumnWidth(DOMAIN));
ToolHelpers.AddColumn(WatchListView, NOTES, true, GetColumnWidth(NOTES));
ColumnPositions();
}