diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor5B2W2.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor5B2W2.cs index d6d11d823..9d750447b 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor5B2W2.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor5B2W2.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core { - public class SaveBlockAccessor5B2W2 : ISaveBlock5BW, ISaveBlock5B2W2 + public class SaveBlockAccessor5B2W2 : ISaveBlockAccessor, ISaveBlock5BW, ISaveBlock5B2W2 { public static readonly BlockInfoNDS[] BlocksB2W2 = { diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor7USUM.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor7USUM.cs index a7d94f627..1504b217c 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor7USUM.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor7USUM.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core { - public sealed class SaveBlockAccessor7USUM : ISaveBlock7USUM + public sealed class SaveBlockAccessor7USUM : ISaveBlockAccessor, ISaveBlock7USUM { public const int boUU = SaveUtil.SIZE_G7USUM - 0x200; diff --git a/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs b/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs new file mode 100644 index 000000000..f9dd0916d --- /dev/null +++ b/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Linq; +using PKHeX.Core; + +namespace PKHeX.WinForms +{ + public class SaveBlockMetadata + { + private readonly Dictionary BlockList; + + public SaveBlockMetadata(ISaveBlockAccessor accessor) + { + var aType = accessor.GetType(); + BlockList = aType.GetAllPropertiesOfType(accessor); + } + + public IEnumerable GetSortedBlockList() + { + return BlockList.Select(z => z.Value).OrderBy(z => z); + } + + public SaveBlock GetBlock(string name) => BlockList.First(z => z.Value == name).Key; + } +} diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 6d42c3344..16668b3b9 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -620,10 +620,41 @@ private void B_OpenRaids_Click(object sender, EventArgs e) private void B_Blocks_Click(object sender, EventArgs e) { - if (!(SAV is SAV8SWSH swsh)) + var form = GetAccessorForm(SAV); + if (form == null) return; - using var form = new SAV_BlockDump8(swsh); form.ShowDialog(); + form.Dispose(); + } + + private static Form GetAccessorForm(SaveFile sav) + { + return sav switch + { + SAV5BW s => new SAV_Accessor(s.Blocks), + SAV5B2W2 s => new SAV_Accessor(s.Blocks), + SAV6XY s => new SAV_Accessor(s.Blocks), + SAV6AO s => new SAV_Accessor(s.Blocks), + SAV6AODemo s => new SAV_Accessor(s.Blocks), + SAV7SM s => new SAV_Accessor(s.Blocks), + SAV7USUM s => new SAV_Accessor(s.Blocks), + SAV8SWSH s => new SAV_BlockDump8(s), + _ => GetPropertyForm(sav), + }; + } + + private static Form GetPropertyForm(SaveFile sav) + { + var form = new Form + { + Text = "Simple Editor", + MinimumSize = new Size(350, 380), + MinimizeBox = false, + MaximizeBox = false + }; + var pg = new PropertyGrid {SelectedObject = sav, Dock = DockStyle.Fill}; + form.Controls.Add(pg); + return form; } private void B_OpenOPowers_Click(object sender, EventArgs e) @@ -1105,7 +1136,8 @@ private void ToggleViewSubEditors(SaveFile sav) B_OpenRTCEditor.Enabled = sav.Generation == 2 || (sav is SAV3 s3 && (s3.RS || s3.E)); B_MailBox.Enabled = sav is SAV2 || sav is SAV3 || sav is SAV4 || sav is SAV5; - B_Raids.Enabled = B_Blocks.Enabled = sav is SAV8SWSH; + B_Raids.Enabled = sav is SAV8SWSH; + B_Blocks.Enabled = true; SL_Extra.SAV = sav; SL_Extra.Initialize(sav.GetExtraSlots(HaX), InitializeDragDrop); diff --git a/PKHeX.WinForms/PKHeX.WinForms.csproj b/PKHeX.WinForms/PKHeX.WinForms.csproj index e19a0d62c..c6a152d71 100644 --- a/PKHeX.WinForms/PKHeX.WinForms.csproj +++ b/PKHeX.WinForms/PKHeX.WinForms.csproj @@ -70,6 +70,9 @@ Form + + Form + Form diff --git a/PKHeX.WinForms/Subforms/Save Editors/Misc/SAV_Accessor.Designer.cs b/PKHeX.WinForms/Subforms/Save Editors/Misc/SAV_Accessor.Designer.cs new file mode 100644 index 000000000..ac6e27121 --- /dev/null +++ b/PKHeX.WinForms/Subforms/Save Editors/Misc/SAV_Accessor.Designer.cs @@ -0,0 +1,122 @@ +namespace PKHeX.WinForms +{ + partial class SAV_Accessor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.CB_Key = new System.Windows.Forms.ComboBox(); + this.L_Key = new System.Windows.Forms.Label(); + this.TC_Tabs = new System.Windows.Forms.TabControl(); + this.Tab_Blocks = new System.Windows.Forms.TabPage(); + this.PG_BlockView = new System.Windows.Forms.PropertyGrid(); + this.TC_Tabs.SuspendLayout(); + this.Tab_Blocks.SuspendLayout(); + this.SuspendLayout(); + // + // CB_Key + // + this.CB_Key.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; + this.CB_Key.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; + this.CB_Key.DropDownWidth = 270; + this.CB_Key.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.CB_Key.FormattingEnabled = true; + this.CB_Key.Location = new System.Drawing.Point(83, 9); + this.CB_Key.Name = "CB_Key"; + this.CB_Key.Size = new System.Drawing.Size(183, 22); + this.CB_Key.TabIndex = 0; + this.CB_Key.SelectedIndexChanged += new System.EventHandler(this.CB_Key_SelectedIndexChanged); + // + // L_Key + // + this.L_Key.AutoSize = true; + this.L_Key.Location = new System.Drawing.Point(6, 12); + this.L_Key.Name = "L_Key"; + this.L_Key.Size = new System.Drawing.Size(37, 13); + this.L_Key.TabIndex = 1; + this.L_Key.Text = "Block:"; + // + // TC_Tabs + // + this.TC_Tabs.Controls.Add(this.Tab_Blocks); + this.TC_Tabs.Dock = System.Windows.Forms.DockStyle.Fill; + this.TC_Tabs.Location = new System.Drawing.Point(0, 0); + this.TC_Tabs.Name = "TC_Tabs"; + this.TC_Tabs.SelectedIndex = 0; + this.TC_Tabs.Size = new System.Drawing.Size(334, 341); + this.TC_Tabs.TabIndex = 12; + // + // Tab_Blocks + // + this.Tab_Blocks.Controls.Add(this.PG_BlockView); + this.Tab_Blocks.Controls.Add(this.L_Key); + this.Tab_Blocks.Controls.Add(this.CB_Key); + this.Tab_Blocks.Location = new System.Drawing.Point(4, 22); + this.Tab_Blocks.Name = "Tab_Blocks"; + this.Tab_Blocks.Padding = new System.Windows.Forms.Padding(3); + this.Tab_Blocks.Size = new System.Drawing.Size(326, 315); + this.Tab_Blocks.TabIndex = 0; + this.Tab_Blocks.Text = "Blocks"; + this.Tab_Blocks.UseVisualStyleBackColor = true; + // + // PG_BlockView + // + this.PG_BlockView.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.PG_BlockView.Location = new System.Drawing.Point(3, 37); + this.PG_BlockView.Name = "PG_BlockView"; + this.PG_BlockView.Size = new System.Drawing.Size(320, 275); + this.PG_BlockView.TabIndex = 14; + this.PG_BlockView.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.PG_BlockView_PropertyValueChanged); + // + // SAV_Accessor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(334, 341); + this.Controls.Add(this.TC_Tabs); + this.Icon = global::PKHeX.WinForms.Properties.Resources.Icon; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SAV_Accessor"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "SaveBlock Editor"; + this.TC_Tabs.ResumeLayout(false); + this.Tab_Blocks.ResumeLayout(false); + this.Tab_Blocks.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.ComboBox CB_Key; + private System.Windows.Forms.Label L_Key; + private System.Windows.Forms.TabControl TC_Tabs; + private System.Windows.Forms.TabPage Tab_Blocks; + private System.Windows.Forms.PropertyGrid PG_BlockView; + } +} \ No newline at end of file diff --git a/PKHeX.WinForms/Subforms/Save Editors/Misc/SAV_Accessor.cs b/PKHeX.WinForms/Subforms/Save Editors/Misc/SAV_Accessor.cs new file mode 100644 index 000000000..122e3a1c6 --- /dev/null +++ b/PKHeX.WinForms/Subforms/Save Editors/Misc/SAV_Accessor.cs @@ -0,0 +1,41 @@ +using System; +using System.Diagnostics; +using System.Linq; +using System.Windows.Forms; +using PKHeX.Core; + +namespace PKHeX.WinForms +{ + public partial class SAV_Accessor : Form where T : ISaveBlockAccessor + { + private readonly SaveBlockMetadata Metadata; + + public SAV_Accessor(T accessor) + { + InitializeComponent(); + WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); + + Metadata = new SaveBlockMetadata(accessor); + + CB_Key.Items.AddRange(Metadata.GetSortedBlockList().ToArray()); + CB_Key.SelectedIndex = 0; + } + + private void CB_Key_SelectedIndexChanged(object sender, EventArgs e) + { + var name = CB_Key.Text; + var block = Metadata.GetBlock(name); + UpdateBlockSummaryControls(block); + } + + private void UpdateBlockSummaryControls(SaveBlock obj) + { + PG_BlockView.SelectedObject = obj; + } + + private void PG_BlockView_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) + { + Debug.WriteLine($"ChangedItem = {e.ChangedItem.Label}, OldValue = {e.OldValue}, NewValue = {e.ChangedItem.Value}"); + } + } +}