mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
Add dragdrop for donut file
Export dialog now shows localized donut name rather than "donut"
This commit is contained in:
parent
89fb9b0471
commit
9840120161
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<Control> 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<byte> 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<byte> 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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user