From 523a39e5940503003b22d4e0d1078f4bb0804519 Mon Sep 17 00:00:00 2001 From: JelleInfinity <60387522+JelleInfinity@users.noreply.github.com> Date: Fri, 23 Sep 2022 04:10:24 +0200 Subject: [PATCH] Fix evo editor (#249) * Rename to Species * Use Graphics to resize image * Fix evo editor Not the best/fastest method, but at least its functional now --- .../Arceus/EvolutionTable8.cs | 2 +- pkNX.WinForms/Dumping/GameDumperPLA.cs | 2 +- pkNX.WinForms/Dumping/PersonalDumperPLA.cs | 2 +- pkNX.WinForms/MainEditor/EditorPLA.cs | 2 +- pkNX.WinForms/Subforms/PokeDataUI8a.cs | 27 ++++++++++--------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkNX.Structures.FlatBuffers/Arceus/EvolutionTable8.cs b/pkNX.Structures.FlatBuffers/Arceus/EvolutionTable8.cs index 875e217b..4a63a6fa 100644 --- a/pkNX.Structures.FlatBuffers/Arceus/EvolutionTable8.cs +++ b/pkNX.Structures.FlatBuffers/Arceus/EvolutionTable8.cs @@ -23,7 +23,7 @@ public class EvolutionTable8 : IFlatBufferArchive [FlatBufferTable, TypeConverter(typeof(ExpandableObjectConverter))] public class EvolutionSet8a { - [FlatBufferItem(0)] public ushort Index { get; set; } + [FlatBufferItem(0)] public ushort Species { get; set; } [FlatBufferItem(1)] public ushort Form { get; set; } [FlatBufferItem(2)] public EvolutionEntry8a[]? Table { get; set; } = Array.Empty(); diff --git a/pkNX.WinForms/Dumping/GameDumperPLA.cs b/pkNX.WinForms/Dumping/GameDumperPLA.cs index ab243fbf..53785874 100644 --- a/pkNX.WinForms/Dumping/GameDumperPLA.cs +++ b/pkNX.WinForms/Dumping/GameDumperPLA.cs @@ -325,7 +325,7 @@ public void DumpEvolutionBinary() var e = obj.Table[i]; if (e.Table?.Length is not > 0) continue; - var index = pt.GetFormIndex(e.Index, (byte)e.Form); + var index = pt.GetFormIndex(e.Species, (byte)e.Form); var entry = (IPersonalInfoPLA)pt[index]; if (!entry.IsPresentInGame) continue; diff --git a/pkNX.WinForms/Dumping/PersonalDumperPLA.cs b/pkNX.WinForms/Dumping/PersonalDumperPLA.cs index 10341ce2..984111d2 100644 --- a/pkNX.WinForms/Dumping/PersonalDumperPLA.cs +++ b/pkNX.WinForms/Dumping/PersonalDumperPLA.cs @@ -188,7 +188,7 @@ private void AddLearnsets(List lines, string specCode, int species, int private void AddEvolutions(List lines, int species, int form) { - var evo = Array.Find(Evos, z => z.Index == species && z.Form == form); + var evo = Array.Find(Evos, z => z.Species == species && z.Form == form); if (evo?.Table is null) return; var evo2 = evo.Table.Where(z => z.Species != 0).ToArray(); diff --git a/pkNX.WinForms/MainEditor/EditorPLA.cs b/pkNX.WinForms/MainEditor/EditorPLA.cs index 11c4bc9b..782ae3d1 100644 --- a/pkNX.WinForms/MainEditor/EditorPLA.cs +++ b/pkNX.WinForms/MainEditor/EditorPLA.cs @@ -426,7 +426,7 @@ public void EditEvolutions() { var names = ROM.GetStrings(TextName.SpeciesNames); PopFlat(GameFile.Evolutions, "Evolution Editor", - z => $"{names[z.Index]}{(z.Form != 0 ? $"-{z.Form}" : "")}"); + z => $"{names[z.Species]}{(z.Form != 0 ? $"-{z.Form}" : "")}"); } public void EditOutbreakDetail() diff --git a/pkNX.WinForms/Subforms/PokeDataUI8a.cs b/pkNX.WinForms/Subforms/PokeDataUI8a.cs index 619c6ac9..ef040c34 100644 --- a/pkNX.WinForms/Subforms/PokeDataUI8a.cs +++ b/pkNX.WinForms/Subforms/PokeDataUI8a.cs @@ -194,24 +194,25 @@ private void LoadIndex(int index) var form = formVal[index]; LoadPersonal((IPersonalInfoPLA)Data.PersonalData[index]); LoadLearnset(Editor.Learn[index]); - LoadEvolutions(Editor.Evolve[index]); + var evoTable = Editor.Evolve.Root.Table; + LoadEvolutions(evoTable.FirstOrDefault(x => x.Species == spec && x.Form == form)); Bitmap rawImg = (Bitmap)SpriteUtil.GetSprite(spec, form, 0, 0, false, false, false); - Bitmap bigImg = new(rawImg.Width * 2, rawImg.Height * 2); - for (int x = 0; x < rawImg.Width; x++) - { - for (int y = 0; y < rawImg.Height; y++) - { - Color c = rawImg.GetPixel(x, y); - bigImg.SetPixel(2 * x, 2 * y, c); - bigImg.SetPixel((2 * x) + 1, 2 * y, c); - bigImg.SetPixel(2 * x, (2 * y) + 1, c); - bigImg.SetPixel((2 * x) + 1, (2 * y) + 1, c); - } - } + Bitmap bigImg = ResizeBitmap(rawImg, rawImg.Width * 2, rawImg.Height * 2); PB_MonSprite.Image = bigImg; } + private Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height) + { + Bitmap result = new(width, height); + using (Graphics g = Graphics.FromImage(result)) + { + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + g.DrawImage(sourceBMP, 0, 0, width, height); + } + return result; + } + private void SaveCurrent() { SavePersonal();