add generic sav block editor

This commit is contained in:
Kurt
2020-04-26 16:23:06 -07:00
parent 6cce57d505
commit 460062a07c
7 changed files with 227 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public class SaveBlockAccessor5B2W2 : ISaveBlock5BW, ISaveBlock5B2W2
public class SaveBlockAccessor5B2W2 : ISaveBlockAccessor<BlockInfoNDS>, ISaveBlock5BW, ISaveBlock5B2W2
{
public static readonly BlockInfoNDS[] BlocksB2W2 =
{

View File

@@ -2,7 +2,7 @@
namespace PKHeX.Core
{
public sealed class SaveBlockAccessor7USUM : ISaveBlock7USUM
public sealed class SaveBlockAccessor7USUM : ISaveBlockAccessor<BlockInfo7>, ISaveBlock7USUM
{
public const int boUU = SaveUtil.SIZE_G7USUM - 0x200;

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Linq;
using PKHeX.Core;
namespace PKHeX.WinForms
{
public class SaveBlockMetadata<T>
{
private readonly Dictionary<SaveBlock, string> BlockList;
public SaveBlockMetadata(ISaveBlockAccessor<T> accessor)
{
var aType = accessor.GetType();
BlockList = aType.GetAllPropertiesOfType<SaveBlock>(accessor);
}
public IEnumerable<string> GetSortedBlockList()
{
return BlockList.Select(z => z.Value).OrderBy(z => z);
}
public SaveBlock GetBlock(string name) => BlockList.First(z => z.Value == name).Key;
}
}

View File

@@ -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<SaveBlockAccessor5BW>(s.Blocks),
SAV5B2W2 s => new SAV_Accessor<SaveBlockAccessor5B2W2>(s.Blocks),
SAV6XY s => new SAV_Accessor<SaveBlockAccessor6XY>(s.Blocks),
SAV6AO s => new SAV_Accessor<SaveBlockAccessor6AO>(s.Blocks),
SAV6AODemo s => new SAV_Accessor<SaveBlockAccessor6AODemo>(s.Blocks),
SAV7SM s => new SAV_Accessor<SaveBlockAccessor7SM>(s.Blocks),
SAV7USUM s => new SAV_Accessor<SaveBlockAccessor7USUM>(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);

View File

@@ -70,6 +70,9 @@
<Compile Update="Subforms\PKM Editors\TechRecordEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Subforms\Save Editors\Misc\SAV_Accessor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Subforms\Save Editors\Gen8\SAV_BlockDump8.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -0,0 +1,122 @@
namespace PKHeX.WinForms
{
partial class SAV_Accessor<T>
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@@ -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<T> : Form where T : ISaveBlockAccessor<BlockInfo>
{
private readonly SaveBlockMetadata<BlockInfo> Metadata;
public SAV_Accessor(T accessor)
{
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
Metadata = new SaveBlockMetadata<BlockInfo>(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}");
}
}
}