convert cheats dialog to use InputRoll

This commit is contained in:
adelikat 2019-10-18 21:43:34 -05:00
parent 5b5a238590
commit 5826d584cc
2 changed files with 66 additions and 116 deletions

View File

@ -30,14 +30,7 @@
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Cheats));
this.CheatListView = new BizHawk.Client.EmuHawk.VirtualListView();
this.CheatName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.Address = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.Value = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.Compare = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ComparisonType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.On = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.Domain = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.CheatListView = new InputRoll();
this.CheatsContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ToggleContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.RemoveContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -102,35 +95,22 @@
// CheatListView
//
this.CheatListView.AllowColumnReorder = true;
this.CheatListView.AllowColumnResize = true;
this.CheatListView.MultiSelect = true;
this.CheatListView.AllowDrop = true;
this.CheatListView.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.CheatListView.AutoArrange = false;
this.CheatListView.BlazingFast = false;
this.CheatListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.CheatName,
this.Address,
this.Value,
this.Compare,
this.ComparisonType,
this.On,
this.Domain});
this.CheatListView.ContextMenuStrip = this.CheatsContextMenu;
this.CheatListView.FullRowSelect = true;
this.CheatListView.GridLines = true;
this.CheatListView.HideSelection = false;
this.CheatListView.ItemCount = 0;
this.CheatListView.RowCount = 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, 321);
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.ColumnClick += new BizHawk.Client.EmuHawk.InputRoll.ColumnClickEventHandler(this.CheatListView_ColumnClick);
this.CheatListView.SelectedIndexChanged += new System.EventHandler(this.CheatListView_SelectedIndexChanged);
this.CheatListView.Click += new System.EventHandler(this.CheatListView_Click);
this.CheatListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragDrop);
@ -138,41 +118,6 @@
this.CheatListView.DoubleClick += new System.EventHandler(this.CheatListView_DoubleClick);
this.CheatListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CheatListView_KeyDown);
//
// CheatName
//
this.CheatName.Text = "Name";
this.CheatName.Width = 104;
//
// Address
//
this.Address.Text = "Address";
this.Address.Width = 52;
//
// Value
//
this.Value.Text = "Value";
this.Value.Width = 40;
//
// Compare
//
this.Compare.Text = "Compare";
//
// ComparisonType
//
this.ComparisonType.Text = "Comparison Type";
this.ComparisonType.Width = 194;
//
// On
//
this.On.Text = "On";
this.On.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.On.Width = 40;
//
// Domain
//
this.Domain.Text = "Domain";
this.Domain.Width = 75;
//
// CheatsContextMenu
//
this.CheatsContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -693,14 +638,7 @@
#endregion
private VirtualListView CheatListView;
private System.Windows.Forms.ColumnHeader CheatName;
private System.Windows.Forms.ColumnHeader Address;
private System.Windows.Forms.ColumnHeader Value;
private System.Windows.Forms.ColumnHeader ComparisonType;
private System.Windows.Forms.ColumnHeader Compare;
private System.Windows.Forms.ColumnHeader On;
private System.Windows.Forms.ColumnHeader Domain;
private InputRoll CheatListView;
private MenuStripEx CheatsMenu;
private System.Windows.Forms.ToolStripMenuItem FileSubMenu;
private System.Windows.Forms.ToolStripMenuItem NewMenuItem;

View File

@ -43,7 +43,6 @@ namespace BizHawk.Client.EmuHawk
CheatListView.QueryItemText += CheatListView_QueryItemText;
CheatListView.QueryItemBkColor += CheatListView_QueryItemBkColor;
CheatListView.VirtualMode = true;
_sortedColumn = "";
_sortReverse = false;
@ -80,7 +79,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
public void UpdateDialog()
{
CheatListView.ItemCount = Global.CheatList.Count;
CheatListView.RowCount = Global.CheatList.Count;
TotalLabel.Text = $"{Global.CheatList.CheatCount} {(Global.CheatList.CheatCount == 1 ? "cheat" : "cheats")} {Global.CheatList.ActiveCount} active";
}
@ -150,21 +149,36 @@ namespace BizHawk.Client.EmuHawk
private void Cheats_Load(object sender, EventArgs e)
{
// Hack for previous config settings
if (Settings.Columns.Any(c => string.IsNullOrWhiteSpace(c.Text)))
{
Settings = new CheatsSettings();
}
TopMost = Settings.TopMost;
CheatEditor.MemoryDomains = Core;
LoadConfigSettings();
CheatsMenu.Items.Add(CheatListView.ToColumnsMenu(ColumnToggleCallback));
ToggleGameGenieButton();
CheatEditor.SetAddEvent(AddCheat);
CheatEditor.SetEditEvent(EditCheat);
UpdateDialog();
}
CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
private void SetColumns()
{
foreach (var column in Settings.Columns)
{
if (CheatListView.AllColumns[column.Name] == null)
{
CheatListView.AllColumns.Add(column);
}
}
}
private void ColumnToggleCallback()
{
SaveColumnInfo(CheatListView, Settings.Columns);
LoadColumnInfo(CheatListView, Settings.Columns);
Settings.Columns = CheatListView.AllColumns;
}
private void ToggleGameGenieButton()
@ -195,7 +209,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveConfigSettings()
{
SaveColumnInfo(CheatListView, Settings.Columns);
Settings.Columns =CheatListView.AllColumns;
if (WindowState == FormWindowState.Normal)
{
@ -221,10 +235,11 @@ namespace BizHawk.Client.EmuHawk
Size = Settings.WindowSize;
}
LoadColumnInfo(CheatListView, Settings.Columns);
CheatListView.AllColumns.Clear();
SetColumns();
}
private void CheatListView_QueryItemText(int index, int column, out string text)
private void CheatListView_QueryItemText(int index, InputRoll.RollColumn column, out string text, ref int offsetX, ref int offsetY)
{
text = "";
if (index >= Global.CheatList.Count || Global.CheatList[index].IsSeparator)
@ -232,7 +247,7 @@ namespace BizHawk.Client.EmuHawk
return;
}
var columnName = CheatListView.Columns[column].Name;
var columnName = column.Name;
switch (columnName)
{
@ -296,7 +311,7 @@ namespace BizHawk.Client.EmuHawk
}
}
private void CheatListView_QueryItemBkColor(int index, int column, ref Color color)
private void CheatListView_QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color)
{
if (index < Global.CheatList.Count)
{
@ -311,7 +326,7 @@ namespace BizHawk.Client.EmuHawk
}
}
private IEnumerable<int> SelectedIndices => CheatListView.SelectedIndices.Cast<int>();
private IEnumerable<int> SelectedIndices => CheatListView.SelectedRows;
private IEnumerable<Cheat> SelectedItems
{
@ -325,19 +340,16 @@ namespace BizHawk.Client.EmuHawk
private void DoSelectedIndexChange()
{
if (!CheatListView.SelectAllInProgress)
if (SelectedCheats.Any())
{
if (SelectedCheats.Any())
{
var cheat = SelectedCheats.First();
CheatEditor.SetCheat(cheat);
CheatGroupBox.Text = $"Editing Cheat {cheat.Name} - {cheat.AddressStr}";
}
else
{
CheatEditor.ClearForm();
CheatGroupBox.Text = "New Cheat";
}
var cheat = SelectedCheats.First();
CheatEditor.SetCheat(cheat);
CheatGroupBox.Text = $"Editing Cheat {cheat.Name} - {cheat.AddressStr}";
}
else
{
CheatEditor.ClearForm();
CheatGroupBox.Text = "New Cheat";
}
}
@ -451,7 +463,7 @@ namespace BizHawk.Client.EmuHawk
Global.CheatList.Remove(item);
}
CheatListView.SelectedIndices.Clear();
CheatListView.DeselectAll();
UpdateDialog();
}
}
@ -486,12 +498,12 @@ namespace BizHawk.Client.EmuHawk
Global.CheatList.Insert(index - 1, cheat);
}
var newindices = indices.Select(t => t - 1);
var newIndices = indices.Select(t => t - 1);
CheatListView.SelectedIndices.Clear();
foreach (var newi in newindices)
CheatListView.DeselectAll();
foreach (var index in newIndices)
{
CheatListView.SelectItem(newi, true);
CheatListView.SelectRow(index, true);
}
UpdateMessageLabel();
@ -515,12 +527,12 @@ namespace BizHawk.Client.EmuHawk
UpdateMessageLabel();
var newindices = indices.Select(t => t + 1);
var newIndices = indices.Select(t => t + 1);
CheatListView.SelectedIndices.Clear();
foreach (var newi in newindices)
CheatListView.DeselectAll();
foreach (var index in newIndices)
{
CheatListView.SelectItem(newi, true);
CheatListView.SelectRow(index, true);
}
UpdateDialog();
@ -611,14 +623,15 @@ namespace BizHawk.Client.EmuHawk
.OfType<ToolStripMenuItem>()
.First(x => x.Name == "GeneratedColumnsSubMenu"));
CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
CheatsMenu.Items.Add(CheatListView.ToColumnsMenu(ColumnToggleCallback));
Global.Config.DisableCheatsOnLoad = false;
Global.Config.LoadCheatFileByGame = true;
Global.Config.CheatsAutoSaveOnClose = true;
RefreshFloatingWindowControl(Settings.FloatingWindow);
LoadColumnInfo(CheatListView, Settings.Columns);
CheatListView.AllColumns.Clear();
SetColumns();
}
#endregion
@ -651,9 +664,9 @@ namespace BizHawk.Client.EmuHawk
DoSelectedIndexChange();
}
private void CheatListView_ColumnClick(object sender, ColumnClickEventArgs e)
private void CheatListView_ColumnClick(object sender, InputRoll.ColumnClickEventArgs e)
{
var column = CheatListView.Columns[e.Column];
var column = e.Column;
if (column.Name != _sortedColumn)
{
_sortReverse = false;
@ -723,22 +736,21 @@ namespace BizHawk.Client.EmuHawk
{
public CheatsSettings()
{
Columns = new ColumnList
Columns = new List<InputRoll.RollColumn>
{
new Column { Name = NameColumn, Visible = true, Index = 0, Width = 128 },
new Column { Name = AddressColumn, Visible = true, Index = 1, Width = 60 },
new Column { Name = ValueColumn, Visible = true, Index = 2, Width = 59 },
new Column { Name = CompareColumn, Visible = true, Index = 3, Width = 59 },
new Column { Name = ComparisonTypeColumn, Visible = true, Index = 4, Width = 60 },
new Column { Name = OnColumn, Visible = false, Index = 5, Width = 28 },
new Column { Name = DomainColumn, Visible = true, Index = 6, Width = 55 },
new Column { Name = SizeColumn, Visible = true, Index = 7, Width = 55 },
new Column { Name = EndianColumn, Visible = false, Index = 8, Width = 55 },
new Column { Name = TypeColumn, Visible = false, Index = 9, Width = 55 }
new InputRoll.RollColumn { Text = "Names", Name = NameColumn, Visible = true, Width = 128, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Address", Name = AddressColumn, Visible = true, Width = 60, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Value", Name = ValueColumn, Visible = true, Width = 59, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Compare", Name = CompareColumn, Visible = true, Width = 63, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Compare Type", Name = ComparisonTypeColumn, Visible = true, Width = 98, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "On", Name = OnColumn, Visible = false, Width = 28, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Size", Name = SizeColumn, Visible = true, Width = 55, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Endian", Name = EndianColumn, Visible = false, Width = 55, Type = InputRoll.RollColumn.InputType.Text },
new InputRoll.RollColumn { Text = "Display Type", Name = TypeColumn, Visible = false, Width = 88, Type = InputRoll.RollColumn.InputType.Text }
};
}
public ColumnList Columns { get; set; }
public List<InputRoll.RollColumn> Columns { get; set; }
}
}
}