From 984012016180f6d44d3dc560df7f24234b566d51 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 15 Dec 2025 00:41:46 -0600 Subject: [PATCH] Add dragdrop for donut file Export dialog now shows localized donut name rather than "donut" --- .../Legality/Verifiers/LegendsZAVerifier.cs | 2 +- .../Save Editors/Gen9/DonutEditor9a.cs | 1 + .../Save Editors/Gen9/SAV_Donut9a.Designer.cs | 7 +++- .../Subforms/Save Editors/Gen9/SAV_Donut9a.cs | 38 +++++++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/PKHeX.Core/Legality/Verifiers/LegendsZAVerifier.cs b/PKHeX.Core/Legality/Verifiers/LegendsZAVerifier.cs index 63c131592..1c687a65f 100644 --- a/PKHeX.Core/Legality/Verifiers/LegendsZAVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LegendsZAVerifier.cs @@ -316,7 +316,7 @@ private static bool WasPossiblyObtainedBeforeDLC(PKM pk, IEncounterTemplate enc) Gallade when move is SacredSword => true, Espurr or Meowstic when move is Teleport => true, Meowstic when move is Moonblast => true, - Honedge when move is SacredSword => true, + Honedge or Doublade or Aegislash when move is SacredSword => true, Malamar when move is Octolock => true, Heliolisk when move is ShedTail => true, Aurorus when move is IceHammer => true, diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs index 08c297da2..33e0f1f4e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs @@ -252,4 +252,5 @@ public void Reset() // ReSharper disable NotAccessedPositionalProperty.Local private sealed record ComboText(string Text, string Value); // ReSharper enable NotAccessedPositionalProperty.Local + public string GetDonutName() => CB_Donut.Text; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.Designer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.Designer.cs index 687dfff7e..75fb7d217 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.Designer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.Designer.cs @@ -58,6 +58,7 @@ private void InitializeComponent() // // LB_Donut // + LB_Donut.AllowDrop = true; LB_Donut.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; LB_Donut.FormattingEnabled = true; LB_Donut.Location = new System.Drawing.Point(14, 15); @@ -133,12 +134,14 @@ private void InitializeComponent() // // donutEditor // + donutEditor.AllowDrop = true; donutEditor.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + donutEditor.AutoSize = true; donutEditor.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; donutEditor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; donutEditor.Location = new System.Drawing.Point(207, 15); donutEditor.Name = "donutEditor"; - donutEditor.Size = new System.Drawing.Size(672, 283); + donutEditor.Size = new System.Drawing.Size(646, 240); donutEditor.TabIndex = 27; // // B_Import @@ -167,6 +170,7 @@ private void InitializeComponent() // // SAV_Donut9a // + AllowDrop = true; AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; ClientSize = new System.Drawing.Size(894, 388); Controls.Add(B_Export); @@ -187,6 +191,7 @@ private void InitializeComponent() Text = "Donut Editor"; modifyMenu.ResumeLayout(false); ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.cs index e746c5a6f..905aa3624 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Donut9a.cs @@ -37,6 +37,17 @@ public SAV_Donut9a(SAV9ZA sav) // Not implemented. mnuRandomizeMax.Visible = false; mnuShinyAssortment.Visible = false; + + AddDrop(this, LB_Donut, donutEditor); + } + + private void AddDrop(params ReadOnlySpan objects) + { + foreach (var control in objects) + { + control.DragDrop += DragoutDrop; + control.DragEnter += Dragout_DragOver; + } } private void LoadDonutNames() @@ -196,19 +207,40 @@ private static bool TryLoadDonutOpenFile(Span data) if (ofd.ShowDialog() != DialogResult.OK) return false; + return ImportDonutFromPath(data, ofd.FileName); + } + + private void Dragout_DragOver(object? sender, DragEventArgs e) => e.Effect = DragDropEffects.Copy; + private void DragoutDrop(object? sender, DragEventArgs? e) + { + if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files) + return; + + var current = Donuts.GetDonut(lastIndex); + var data = current.Data; + ImportDonutFromPath(data, files[0]); + donutEditor.LoadDonut(current); + System.Media.SystemSounds.Asterisk.Play(); + e.Effect = DragDropEffects.Copy; + + Cursor = DefaultCursor; + } + + private static bool ImportDonutFromPath(Span data, string path) + { try { - var fileData = System.IO.File.ReadAllBytes(ofd.FileName); + var fileData = System.IO.File.ReadAllBytes(path); if (fileData.Length != data.Length) throw new Exception($"Invalid donut size: expected {data.Length} bytes, got {fileData.Length} bytes."); fileData.AsSpan().CopyTo(data); + return true; } catch (Exception ex) { WinFormsUtil.Error($"Failed to import donut from file:\n{ex.Message}"); return false; } - return true; } private void B_Export_Click(object sender, EventArgs e) @@ -231,7 +263,7 @@ private void B_Export_Click(object sender, EventArgs e) using var sfd = new SaveFileDialog(); sfd.Title = "Export Donut"; sfd.Filter = "Donut File (*.donut)|*.donut|All Files (*.*)|*.*"; - sfd.FileName = $"donut_{lastIndex + 1:000}.donut"; + sfd.FileName = $"{lastIndex + 1:000}_{donutEditor.GetDonutName()}.donut"; if (sfd.ShowDialog() != DialogResult.OK) return; System.IO.File.WriteAllBytes(sfd.FileName, data);