From 4f144c74d47021018bc3252393db8685d98d58c7 Mon Sep 17 00:00:00 2001 From: James Groom Date: Wed, 27 Mar 2024 17:17:53 +0000 Subject: [PATCH] Create constructors for `RollColumn` --- .../CustomControls/InputRoll/RollColumn.cs | 36 ++++++++++++------- src/BizHawk.Client.EmuHawk/tools/CDL.cs | 28 +++++++-------- .../tools/Cheats/Cheats.cs | 18 +++++----- .../tools/Debugger/GenericDebugger.cs | 19 ++-------- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 5 +-- .../tools/Lua/LuaConsole.cs | 6 ++-- .../tools/TAStudio/BookmarksBranchesBox.cs | 27 ++------------ .../tools/TAStudio/MarkerControl.cs | 19 ++-------- .../tools/TAStudio/TAStudio.cs | 29 ++++++--------- .../tools/TAStudio/UndoHistoryForm.cs | 7 ++-- .../tools/TraceLogger.cs | 16 ++------- .../tools/Watch/RamSearch.cs | 10 +++--- .../tools/Watch/RamWatch.cs | 16 ++++----- 13 files changed, 86 insertions(+), 150 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumn.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumn.cs index 24ea2276a2..fb1f50aaa8 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumn.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumn.cs @@ -5,11 +5,15 @@ public int Width { get; set; } public int Left { get; set; } public int Right { get; set; } - public string Name { get; set; } - public string Text { get; set; } - - // Is this the default we want? ColumnType.Text is the most common. - public ColumnType Type { get; set; } = ColumnType.Boolean; + + /// TODO rename to Key? + public string Name { get; private set; } + + /// TODO rename to Label? + public string Text { get; private set; } + + public ColumnType Type { get; private set; } + public bool Visible { get; set; } = true; /// @@ -22,14 +26,22 @@ /// public bool Rotatable { get; set; } - /// - /// Sets the desired width as appropriate for a display with no scaling. If display - /// scaling is enabled, the actual column width will be scaled accordingly. - /// - public int UnscaledWidth +// [JsonConstructor] + private RollColumn() { - get => UIHelper.UnscaleX(Width); - set => Width = UIHelper.ScaleX(value); + Name = default!; + Text = default!; } + + public RollColumn(string name, int widthUnscaled, ColumnType type, string text) + { + Name = name; + Text = text; + Type = type; + Width = UIHelper.ScaleX(widthUnscaled); + } + + public RollColumn(string name, int widthUnscaled, string text) + : this(name: name, widthUnscaled: widthUnscaled, type: ColumnType.Text, text: text) {} } } diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs index 49f1af4a16..798a9bbc3c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -87,21 +87,21 @@ namespace BizHawk.Client.EmuHawk tsbViewStyle.SelectedIndex = 0; lvCDL.AllColumns.Clear(); - lvCDL.AllColumns.AddRange(new[] + lvCDL.AllColumns.AddRange(new RollColumn[] { - new RollColumn { Name = "CDLFile", Text = "CDL File @", UnscaledWidth = 107, Type = ColumnType.Text }, - new RollColumn { Name = "Domain", Text = "Domain", UnscaledWidth = 126, Type = ColumnType.Text }, - new RollColumn { Name = "Percent", Text = "%", UnscaledWidth = 58, Type = ColumnType.Text }, - new RollColumn { Name = "Mapped", Text = "Mapped", UnscaledWidth = 64, Type = ColumnType.Text }, - new RollColumn { Name = "Size", Text = "Size", UnscaledWidth = 112, Type = ColumnType.Text }, - new RollColumn { Name = "0x01", Text = "0x01", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x02", Text = "0x02", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x04", Text = "0x04", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x08", Text = "0x08", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x10", Text = "0x10", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x20", Text = "0x20", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x40", Text = "0x40", UnscaledWidth = 56, Type = ColumnType.Text }, - new RollColumn { Name = "0x80", Text = "0x80", UnscaledWidth = 56, Type = ColumnType.Text } + new(name: "CDLFile", widthUnscaled: 107, text: "CDL File @"), + new(name: "Domain", widthUnscaled: 126, text: "Domain"), + new(name: "Percent", widthUnscaled: 58, text: "%"), + new(name: "Mapped", widthUnscaled: 64, text: "Mapped"), + new(name: "Size", widthUnscaled: 112, text: "Size"), + new(name: "0x01", widthUnscaled: 56, text: "0x01"), + new(name: "0x02", widthUnscaled: 56, text: "0x02"), + new(name: "0x04", widthUnscaled: 56, text: "0x04"), + new(name: "0x08", widthUnscaled: 56, text: "0x08"), + new(name: "0x10", widthUnscaled: 56, text: "0x10"), + new(name: "0x20", widthUnscaled: 56, text: "0x20"), + new(name: "0x40", widthUnscaled: 56, text: "0x40"), + new(name: "0x80", widthUnscaled: 56, text: "0x80"), }); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 2f25f0ba90..93377ddebb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -626,15 +626,15 @@ namespace BizHawk.Client.EmuHawk { Columns = new List { - new RollColumn { Text = "Names", Name = NameColumn, Visible = true, UnscaledWidth = 128, Type = ColumnType.Text }, - new RollColumn { Text = "Address", Name = AddressColumn, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text }, - new RollColumn { Text = "Value", Name = ValueColumn, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text }, - new RollColumn { Text = "Compare", Name = CompareColumn, Visible = true, UnscaledWidth = 63, Type = ColumnType.Text }, - new RollColumn { Text = "Compare Type", Name = ComparisonTypeColumn, Visible = true, UnscaledWidth = 98, Type = ColumnType.Text }, - new RollColumn { Text = "On", Name = OnColumn, Visible = false, UnscaledWidth = 28, Type = ColumnType.Text }, - new RollColumn { Text = "Size", Name = SizeColumn, Visible = true, UnscaledWidth = 55, Type = ColumnType.Text }, - new RollColumn { Text = "Endian", Name = EndianColumn, Visible = false, UnscaledWidth = 55, Type = ColumnType.Text }, - new RollColumn { Text = "Display Type", Name = TypeColumn, Visible = false, UnscaledWidth = 88, Type = ColumnType.Text } + new(name: NameColumn, widthUnscaled: 128, text: "Names"), + new(name: AddressColumn, widthUnscaled: 60, text: "Address"), + new(name: ValueColumn, widthUnscaled: 59, text: "Value"), + new(name: CompareColumn, widthUnscaled: 63, text: "Compare"), + new(name: ComparisonTypeColumn, widthUnscaled: 98, text: "Compare Type"), + new(name: OnColumn, widthUnscaled: 28, text: "On") { Visible = false }, + new(name: SizeColumn, widthUnscaled: 55, text: "Size"), + new(name: EndianColumn, widthUnscaled: 55, text: "Endian") { Visible = false }, + new(name: TypeColumn, widthUnscaled: 88, text: "Display Type") { Visible = false }, }; } diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index 65278a2721..2b4b3fba8e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -36,23 +36,8 @@ namespace BizHawk.Client.EmuHawk DisassemblerView.QueryItemText += DisassemblerView_QueryItemText; DisassemblerView.QueryItemBkColor += DisassemblerView_QueryItemBkColor; DisassemblerView.AllColumns.Clear(); - DisassemblerView.AllColumns.AddRange(new[] - { - new RollColumn - { - Name = AddressColumnName, - Text = AddressColumnName, - UnscaledWidth = 94, - Type = ColumnType.Text - }, - new RollColumn - { - Name = InstructionColumnName, - Text = InstructionColumnName, - UnscaledWidth = 291, - Type = ColumnType.Text - } - }); + DisassemblerView.AllColumns.Add(new(name: AddressColumnName, widthUnscaled: 94, text: AddressColumnName)); + DisassemblerView.AllColumns.Add(new(name: InstructionColumnName, widthUnscaled: 291, text: InstructionColumnName)); } private void EngageDebugger() diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index fce1eca24a..8eb9527cd1 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -363,10 +363,7 @@ namespace BizHawk.Client.EmuHawk [LuaMethod("addcolumn", "")] public void AddColumn(string name, string text, int width) { - if (Engaged()) - { - Tastudio.AddColumn(name, text, width, ColumnType.Text); - } + if (Engaged()) Tastudio.AddColumn(name: name, widthUnscaled: width, text: text); } [LuaMethodExample("tastudio.setbranchtext( \"Some text\", 1 );")] diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 90d85ed3b9..07eaf1fdeb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -56,9 +56,9 @@ namespace BizHawk.Client.EmuHawk { Columns = new List { - new() { Name = IconColumnName, Text = " ", Visible = true, UnscaledWidth = 22, Type = ColumnType.Image }, - new() { Name = ScriptColumnName, Text = "Script", Visible = true, UnscaledWidth = 92, Type = ColumnType.Text }, - new() { Name = PathColumnName, Text = "Path", Visible = true, UnscaledWidth = 300, Type = ColumnType.Text } + new(name: IconColumnName, widthUnscaled: 22, type: ColumnType.Image, text: " "), + new(name: ScriptColumnName, widthUnscaled: 92, text: "Script"), + new(name: PathColumnName, widthUnscaled: 300, text: "Path"), }; } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index cedd1669b7..3fad2a48cf 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -72,30 +72,9 @@ namespace BizHawk.Client.EmuHawk private void SetupColumns() { BranchView.AllColumns.Clear(); - BranchView.AllColumns.AddRange(new[] - { - new RollColumn - { - Name = BranchNumberColumnName, - Text = "#", - UnscaledWidth = 30, - Type = ColumnType.Text - }, - new RollColumn - { - Name = FrameColumnName, - Text = "Frame", - UnscaledWidth = 64, - Type = ColumnType.Text - }, - new RollColumn - { - Name = UserTextColumnName, - Text = "UserText", - UnscaledWidth = 90, - Type = ColumnType.Text - } - }); + BranchView.AllColumns.Add(new(name: BranchNumberColumnName, widthUnscaled: 30, text: "#")); + BranchView.AllColumns.Add(new(name: FrameColumnName, widthUnscaled: 64, text: "Frame")); + BranchView.AllColumns.Add(new(name: UserTextColumnName, widthUnscaled: 90, text: "UserText")); } private void QueryItemText(int index, RollColumn column, out string text, ref int offsetX, ref int offsetY) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index 5456e00e44..04ce5d603f 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -43,23 +43,8 @@ namespace BizHawk.Client.EmuHawk private void SetupColumns() { MarkerView.AllColumns.Clear(); - MarkerView.AllColumns.AddRange(new[] - { - new RollColumn - { - Name = "FrameColumn", - Text = "Frame", - UnscaledWidth = 52, - Type = ColumnType.Text - }, - new RollColumn - { - Name = "LabelColumn", - Text = "", - UnscaledWidth = 125, - Type = ColumnType.Text - } - }); + MarkerView.AllColumns.Add(new(name: "FrameColumn", widthUnscaled: 52, text: "Frame")); + MarkerView.AllColumns.Add(new(name: "LabelColumn", widthUnscaled: 125, text: string.Empty)); } public InputRoll MarkerInputRoll => MarkerView; diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 5912307fb9..6d92f56d58 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -345,14 +345,10 @@ namespace BizHawk.Client.EmuHawk private void SetUpColumns() { TasView.AllColumns.Clear(); - AddColumn(CursorColumnName, "", 18); - TasView.AllColumns.Add(new RollColumn + TasView.AllColumns.Add(new(name: CursorColumnName, widthUnscaled: 18, type: ColumnType.Boolean, text: string.Empty)); + TasView.AllColumns.Add(new(name: FrameColumnName, widthUnscaled: 68, text: "Frame#") { - Name = FrameColumnName, - Text = "Frame#", - UnscaledWidth = 68, - Type = ColumnType.Text, - Rotatable = true + Rotatable = true, }); var columnNames = MovieSession.Movie @@ -377,7 +373,11 @@ namespace BizHawk.Client.EmuHawk digits = mnemonic.Length; } - AddColumn(name, mnemonic, (digits * 6) + 14, type); // magic numbers reused in EditBranchTextPopUp() + TasView.AllColumns.Add(new( + name: name, + widthUnscaled: (digits * 6) + 14, // magic numbers reused in EditBranchTextPopUp() --feos // not since eb63fa5a9 (before 2.3.3) --yoshi + type: type, + text: mnemonic)); } var columnsToHide = TasView.AllColumns @@ -464,16 +464,9 @@ namespace BizHawk.Client.EmuHawk SetUpToolStripColumns(); } - public void AddColumn(string columnName, string columnText, int columnWidth, ColumnType columnType = ColumnType.Boolean) - { - TasView.AllColumns.Add(new RollColumn - { - Name = columnName, - Text = columnText, - UnscaledWidth = columnWidth, - Type = columnType - }); - } + /// for Lua + public void AddColumn(string name, string text, int widthUnscaled) + => TasView.AllColumns.Add(new(name: name, widthUnscaled: widthUnscaled, type: ColumnType.Text, text: text)); public void LoadBranchByIndex(int index) => BookMarkControl.LoadBranchExternal(index); public void ClearFramesExternal() => ClearFramesMenuItem_Click(null, null); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/UndoHistoryForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/UndoHistoryForm.cs index bf41f39b6b..7b7cc8b0e7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/UndoHistoryForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/UndoHistoryForm.cs @@ -23,11 +23,8 @@ namespace BizHawk.Client.EmuHawk HistoryView.QueryItemBkColor += HistoryView_QueryItemBkColor; HistoryView.AllColumns.Clear(); - HistoryView.AllColumns.AddRange(new[] - { - new RollColumn { Name = IdColumnName, Text = IdColumnName, UnscaledWidth = 40, Type = ColumnType.Text }, - new RollColumn { Name = UndoColumnName, Text = UndoColumnName, UnscaledWidth = 280, Type = ColumnType.Text } - }); + HistoryView.AllColumns.Add(new(name: IdColumnName, widthUnscaled: 40, text: IdColumnName)); + HistoryView.AllColumns.Add(new(name: UndoColumnName, widthUnscaled: 280, text: UndoColumnName)); MaxStepsNum.Value = Log.MaxSteps; } diff --git a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index bdb8edf4d5..f8eb6a11e9 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -94,20 +94,8 @@ namespace BizHawk.Client.EmuHawk _splitFile = FileSizeCap != 0; TraceView.AllColumns.Clear(); - TraceView.AllColumns.Add(new RollColumn - { - Name = DisasmColumnName, - Text = DisasmColumnName, - UnscaledWidth = 239, - Type = ColumnType.Text - }); - TraceView.AllColumns.Add(new RollColumn - { - Name = RegistersColumnName, - Text = RegistersColumnName, - UnscaledWidth = 357, - Type = ColumnType.Text - }); + TraceView.AllColumns.Add(new(name: DisasmColumnName, widthUnscaled: 239, text: DisasmColumnName)); + TraceView.AllColumns.Add(new(name: RegistersColumnName, widthUnscaled: 357, text: RegistersColumnName)); } private void SaveConfigSettings() diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 1fa0e95583..933cfee47d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -940,11 +940,11 @@ namespace BizHawk.Client.EmuHawk { Columns = new List { - new RollColumn { Text = "Address", Name = WatchList.Address, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text }, - new RollColumn { Text = "Value", Name = WatchList.Value, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text }, - new RollColumn { Text = "Prev", Name = WatchList.Prev, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text }, - new RollColumn { Text = "Changes", Name = WatchList.ChangesCol, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text }, - new RollColumn { Text = "Diff", Name = WatchList.Diff, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text } + new(name: WatchList.Address, widthUnscaled: 60, text: "Address"), + new(name: WatchList.Value, widthUnscaled: 59, text: "Value"), + new(name: WatchList.Prev, widthUnscaled: 59, text: "Prev"), + new(name: WatchList.ChangesCol, widthUnscaled: 60, text: "Changes"), + new(name: WatchList.Diff, widthUnscaled: 59, text: "Diff") { Visisble = false }, }; PreviewMode = true; diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 9d2eef96c2..e0c2e1e102 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -167,14 +167,14 @@ namespace BizHawk.Client.EmuHawk { Columns = new List { - new() { Text = "Address", Name = WatchList.Address, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text }, - new() { Text = "Value", Name = WatchList.Value, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text }, - new() { Text = "Prev", Name = WatchList.Prev, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text }, - new() { Text = "Changes", Name = WatchList.ChangesCol, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text }, - new() { Text = "Diff", Name = WatchList.Diff, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text }, - new() { Text = "Type", Name = WatchList.Type, Visible = false, UnscaledWidth = 55, Type = ColumnType.Text }, - new() { Text = "Domain", Name = WatchList.Domain, Visible = true, UnscaledWidth = 55, Type = ColumnType.Text }, - new() { Text = "Notes", Name = WatchList.Notes, Visible = true, UnscaledWidth = 128, Type = ColumnType.Text } + new(name: WatchList.Address, widthUnscaled: 60, text: "Address"), + new(name: WatchList.Value, widthUnscaled: 59, text: "Value"), + new(name: WatchList.Prev, widthUnscaled: 59, text: "Prev") { Visible = false }, + new(name: WatchList.ChangesCol, widthUnscaled: 60, text: "Changes"), + new(name: WatchList.Diff, widthUnscaled: 59, text: "Diff") { Visible = false }, + new(name: WatchList.Type, widthUnscaled: 55, text: "Type") { Visible = false }, + new(name: WatchList.Domain, widthUnscaled: 55, text: "Domain"), + new(name: WatchList.Notes, widthUnscaled: 128, text: "Notes"), }; }