Cheats - auto-generate the Columns submenu instead of boilerplate

This commit is contained in:
adelikat 2014-12-31 23:48:39 +00:00
parent ace8192c8a
commit dba923d8b9
3 changed files with 43 additions and 164 deletions

View File

@ -74,6 +74,43 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
}
}
public static ToolStripMenuItem GenerateColumnsMenu(this ToolDialogSettings.ColumnList list)
{
var menu = new ToolStripMenuItem
{
Name = "GeneratedColumnsSubMenu",
Text = "Columns"
};
var dummyList = list;
foreach (var column in dummyList)
{
var menuItem = new ToolStripMenuItem
{
Name = column.Name,
Text = column.Name.Replace("Column", string.Empty)
};
menuItem.Click += (o, ev) =>
{
dummyList[menuItem.Name].Visible ^= true;
};
menu.DropDownItems.Add(menuItem);
}
menu.DropDownOpened += (o, e) =>
{
foreach (var column in dummyList)
{
(menu.DropDownItems[column.Name] as ToolStripMenuItem).Checked = column.Visible;
}
};
return menu;
}
public static Point ChildPointToScreen(this Control control, Control child)
{
return control.PointToScreen(new Point(child.Location.X, child.Location.Y));

View File

@ -76,16 +76,6 @@
this.FloatingWindowMenuItem = 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();
this.ShowNameMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowAddressMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowValueMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowCompareMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowOnMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowDomainMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowSizeMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowEndianMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowDisplayTypeMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStrip1 = new ToolStripEx();
this.NewToolBarItem = new System.Windows.Forms.ToolStripButton();
this.OpenToolBarItem = new System.Windows.Forms.ToolStripButton();
@ -131,10 +121,12 @@
this.CheatListView.ItemCount = 0;
this.CheatListView.Location = new System.Drawing.Point(12, 72);
this.CheatListView.Name = "CheatListView";
this.CheatListView.SelectAllInProgress = false;
this.CheatListView.selectedItem = -1;
this.CheatListView.Size = new System.Drawing.Size(414, 278);
this.CheatListView.TabIndex = 1;
this.CheatListView.UseCompatibleStateImageBehavior = false;
this.CheatListView.UseCustomBackground = true;
this.CheatListView.View = System.Windows.Forms.View.Details;
this.CheatListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.CheatListView_ColumnClick);
this.CheatListView.SelectedIndexChanged += new System.EventHandler(this.CheatListView_SelectedIndexChanged);
@ -224,8 +216,7 @@
this.CheatsMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.FileSubMenu,
this.CheatsSubMenu,
this.OptionsSubMenu,
this.ColumnsSubMenu});
this.OptionsSubMenu});
this.CheatsMenu.Location = new System.Drawing.Point(0, 0);
this.CheatsMenu.Name = "CheatsMenu";
this.CheatsMenu.Size = new System.Drawing.Size(646, 24);
@ -504,86 +495,6 @@
this.RestoreWindowSizeMenuItem.Text = "Restore Default Settings";
this.RestoreWindowSizeMenuItem.Click += new System.EventHandler(this.RestoreWindowSizeMenuItem_Click);
//
// ColumnsSubMenu
//
this.ColumnsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ShowNameMenuItem,
this.ShowAddressMenuItem,
this.ShowValueMenuItem,
this.ShowCompareMenuItem,
this.ShowOnMenuItem,
this.ShowDomainMenuItem,
this.ShowSizeMenuItem,
this.ShowEndianMenuItem,
this.ShowDisplayTypeMenuItem});
this.ColumnsSubMenu.Name = "ColumnsSubMenu";
this.ColumnsSubMenu.Size = new System.Drawing.Size(67, 20);
this.ColumnsSubMenu.Text = "&Columns";
this.ColumnsSubMenu.DropDownOpened += new System.EventHandler(this.ColumnsSubMenu_DropDownOpened);
//
// ShowNameMenuItem
//
this.ShowNameMenuItem.Name = "ShowNameMenuItem";
this.ShowNameMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowNameMenuItem.Text = "&Name";
this.ShowNameMenuItem.Click += new System.EventHandler(this.ShowNameMenuItem_Click);
//
// ShowAddressMenuItem
//
this.ShowAddressMenuItem.Name = "ShowAddressMenuItem";
this.ShowAddressMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowAddressMenuItem.Text = "&Address";
this.ShowAddressMenuItem.Click += new System.EventHandler(this.ShowAddressMenuItem_Click);
//
// ShowValueMenuItem
//
this.ShowValueMenuItem.Name = "ShowValueMenuItem";
this.ShowValueMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowValueMenuItem.Text = "&Value";
this.ShowValueMenuItem.Click += new System.EventHandler(this.ShowValueMenuItem_Click);
//
// ShowCompareMenuItem
//
this.ShowCompareMenuItem.Name = "ShowCompareMenuItem";
this.ShowCompareMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowCompareMenuItem.Text = "&Compare";
this.ShowCompareMenuItem.Click += new System.EventHandler(this.ShowCompareMenuItem_Click);
//
// ShowOnMenuItem
//
this.ShowOnMenuItem.Name = "ShowOnMenuItem";
this.ShowOnMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowOnMenuItem.Text = "&On";
this.ShowOnMenuItem.Click += new System.EventHandler(this.ShowOnMenuItem_Click);
//
// ShowDomainMenuItem
//
this.ShowDomainMenuItem.Name = "ShowDomainMenuItem";
this.ShowDomainMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowDomainMenuItem.Text = "&Domain";
this.ShowDomainMenuItem.Click += new System.EventHandler(this.ShowDomainMenuItem_Click);
//
// ShowSizeMenuItem
//
this.ShowSizeMenuItem.Name = "ShowSizeMenuItem";
this.ShowSizeMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowSizeMenuItem.Text = "&Size";
this.ShowSizeMenuItem.Click += new System.EventHandler(this.ShowSizeMenuItem_Click);
//
// ShowEndianMenuItem
//
this.ShowEndianMenuItem.Name = "ShowEndianMenuItem";
this.ShowEndianMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowEndianMenuItem.Text = "&Endian";
this.ShowEndianMenuItem.Click += new System.EventHandler(this.ShowEndianMenuItem_Click);
//
// ShowDisplayTypeMenuItem
//
this.ShowDisplayTypeMenuItem.Name = "ShowDisplayTypeMenuItem";
this.ShowDisplayTypeMenuItem.Size = new System.Drawing.Size(141, 22);
this.ShowDisplayTypeMenuItem.Text = "&Display Type";
this.ShowDisplayTypeMenuItem.Click += new System.EventHandler(this.ShowDisplayTypeMenuItem_Click);
//
// toolStrip1
//
this.toolStrip1.ClickThrough = true;
@ -737,6 +648,7 @@
this.CheatEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CheatEditor.Core = null;
this.CheatEditor.Location = new System.Drawing.Point(6, 14);
this.CheatEditor.Name = "CheatEditor";
this.CheatEditor.Size = new System.Drawing.Size(190, 264);
@ -822,20 +734,10 @@
private System.Windows.Forms.ToolStripButton MoveDownToolbarItem;
private System.Windows.Forms.ToolStripButton LoadGameGenieToolbarItem;
private System.Windows.Forms.Label TotalLabel;
private System.Windows.Forms.ToolStripMenuItem ColumnsSubMenu;
private System.Windows.Forms.Label MessageLabel;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowNameMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowAddressMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowValueMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowCompareMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowOnMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowDomainMenuItem;
private System.Windows.Forms.ToolStripMenuItem ToggleMenuItem;
private System.Windows.Forms.ToolStripSeparator GameGenieToolbarSeparator;
private System.Windows.Forms.ToolStripMenuItem ShowSizeMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowEndianMenuItem;
private System.Windows.Forms.ToolStripMenuItem ShowDisplayTypeMenuItem;
private System.Windows.Forms.ContextMenuStrip CheatsContextMenu;
private System.Windows.Forms.ToolStripMenuItem ToggleContextMenuItem;
private System.Windows.Forms.ToolStripMenuItem RemoveContextMenuItem;

View File

@ -204,6 +204,8 @@ namespace BizHawk.Client.EmuHawk
CheatEditor.SetAddEvent(AddCheat);
CheatEditor.SetEditEvent(EditCheat);
UpdateDialog();
CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu());
}
private void ToggleGameGenieButton()
@ -667,68 +669,6 @@ namespace BizHawk.Client.EmuHawk
#endregion
#region Columns
private void ColumnsSubMenu_DropDownOpened(object sender, EventArgs e)
{
ShowNameMenuItem.Checked = Settings.Columns[NAME].Visible;
ShowAddressMenuItem.Checked = Settings.Columns[ADDRESS].Visible;
ShowValueMenuItem.Checked = Settings.Columns[VALUE].Visible;
ShowCompareMenuItem.Checked = Settings.Columns[COMPARE].Visible;
ShowOnMenuItem.Checked = Settings.Columns[ON].Visible;
ShowDomainMenuItem.Checked = Settings.Columns[DOMAIN].Visible;
ShowSizeMenuItem.Checked = Settings.Columns[SIZE].Visible;
ShowEndianMenuItem.Checked = Settings.Columns[ENDIAN].Visible;
ShowDisplayTypeMenuItem.Checked = Settings.Columns[TYPE].Visible;
}
private void ShowNameMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(NAME);
}
private void ShowAddressMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(ADDRESS);
}
private void ShowValueMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(VALUE);
}
private void ShowCompareMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(COMPARE);
}
private void ShowOnMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(ON);
}
private void ShowDomainMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(DOMAIN);
}
private void ShowSizeMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(SIZE);
}
private void ShowEndianMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(ENDIAN);
}
private void ShowDisplayTypeMenuItem_Click(object sender, EventArgs e)
{
DoColumnToggle(TYPE);
}
#endregion
#region ListView and Dialog Events
private void CheatListView_Click(object sender, EventArgs e)