Pass box-to-show to ResetBoxNames

Previous commit changed the behavior to not check SaveFile's CurrentBox, only keep current index. If we want a specific index (like a new SaveFile's latest box), we must pass it.
This commit is contained in:
Kurt 2023-05-06 19:42:48 -07:00
parent 8e177708b7
commit f9ac5eae15
6 changed files with 30 additions and 26 deletions

View File

@ -151,7 +151,7 @@ public bool HideSecretValues
public bool HaX { get => _hax; set => _hax = Stats.HaX = value; }
private byte[] LastData = Array.Empty<byte>();
public PKM Data { get => Entity; set => Entity = value; }
public PKM Data => Entity;
public PKM Entity { get; private set; } = null!;
public bool FieldsLoaded { get; private set; }
public bool ChangingFields { get; set; }

View File

@ -145,12 +145,19 @@ public void Setup(SlotChangeManager m)
FlagIllegal = M.SE.FlagIllegal;
}
/// <summary>
/// Updates the list of Box Names to select from, and selects the box index specified. If no box is specified, the previous index is used.
/// </summary>
/// <param name="box">Box to display after reload.</param>
public void ResetBoxNames(int box = -1)
{
if (!SAV.HasBox)
return;
var currentIndex = CurrentBox;
if (box < 0)
box = currentIndex;
var update = BoxUtil.GetBoxNames(SAV);
var current = CB_BoxSelect.Items;
if (!GetIsSame(update, current))
@ -168,8 +175,6 @@ public void ResetBoxNames(int box = -1)
}
}
if (box < 0)
box = currentIndex;
box = Math.Clamp(box, 0, current.Count - 1);
if (box != CurrentBox)
CurrentBox = box;
@ -281,8 +286,10 @@ public bool InitializeFromSAV(SaveFile sav)
int box = sav.CurrentBox;
if ((uint)box >= sav.BoxCount)
box = 0;
// Display the Box Names
ResetBoxNames(box);
Editor.LoadBox(box);
ResetBoxNames(); // Display the Box Names
return result;
}
}

View File

@ -409,7 +409,7 @@ private void ClickBoxDouble(object sender, MouseEventArgs e)
z.BringToFront();
return;
}
new SAV_BoxViewer(this, M).Show();
new SAV_BoxViewer(this, M, Box.CurrentBox).Show();
}
private void ClickClone(object sender, EventArgs e)

View File

@ -420,7 +420,6 @@ public void InitializeComponent()
PKME_Tabs.AccessibleDescription = "Pokémon Editor Pane";
PKME_Tabs.AccessibleName = "Pokémon Editor Pane";
PKME_Tabs.ChangingFields = false;
PKME_Tabs.Data = null;
PKME_Tabs.Dock = System.Windows.Forms.DockStyle.Fill;
PKME_Tabs.HaX = false;
PKME_Tabs.Location = new System.Drawing.Point(0, 0);

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@ -68,13 +68,11 @@ private static IEnumerable<Assembly> GetAssemblies(IEnumerable<string> dllFileNa
private static IEnumerable<Type> GetPluginsOfType<T>(IEnumerable<Assembly> assemblies)
{
var interfaceTypeName = typeof(T).FullName;
if (interfaceTypeName is null)
return Array.Empty<Type>();
return assemblies.SelectMany(z => GetPluginTypes(z, interfaceTypeName));
var pluginType = typeof(T);
return assemblies.SelectMany(z => GetPluginTypes(z, pluginType));
}
private static IEnumerable<Type> GetPluginTypes(Assembly z, string interfaceTypeName)
private static IEnumerable<Type> GetPluginTypes(Assembly z, Type plugin)
{
try
{
@ -83,13 +81,13 @@ private static IEnumerable<Type> GetPluginTypes(Assembly z, string interfaceType
var attachMethod = assemblyLoaderType?.GetMethod("Attach", BindingFlags.Static | BindingFlags.Public);
attachMethod?.Invoke(null, Array.Empty<object>());
var types = z.GetTypes();
return types.Where(type => IsTypePlugin(type, interfaceTypeName));
var types = z.GetExportedTypes();
return types.Where(type => IsTypePlugin(type, plugin));
}
// User plugins can be out of date, with mismatching API surfaces.
catch (Exception ex)
{
Debug.WriteLine($"Unable to load plugin [{interfaceTypeName}]: {z.FullName}");
Debug.WriteLine($"Unable to load plugin [{plugin.FullName}]: {z.FullName}");
Debug.WriteLine(ex.Message);
if (ex is not ReflectionTypeLoadException rtle)
return Array.Empty<Type>();
@ -103,12 +101,10 @@ private static IEnumerable<Type> GetPluginTypes(Assembly z, string interfaceType
}
}
private static bool IsTypePlugin(Type type, string interfaceTypeName)
private static bool IsTypePlugin(Type type, Type plugin)
{
if (type.IsInterface || type.IsAbstract)
return false;
if (type.GetInterface(interfaceTypeName) == null)
return false;
return true;
return plugin.IsAssignableFrom(type);
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Windows.Forms;
using PKHeX.Core;
using PKHeX.WinForms.Controls;
@ -9,10 +9,11 @@ public sealed partial class SAV_BoxViewer : Form
{
private readonly SAVEditor parent;
public SAV_BoxViewer(SAVEditor p, SlotChangeManager m)
public SAV_BoxViewer(SAVEditor p, SlotChangeManager m, int box)
{
parent = p;
InitializeComponent();
parent = p;
int deltaW = Width - Box.BoxPokeGrid.Width;
int deltaH = Height - Box.BoxPokeGrid.Height;
Box.Editor = new BoxEdit(m.SE.SAV);
@ -44,14 +45,15 @@ public SAV_BoxViewer(SAVEditor p, SlotChangeManager m)
Box.CurrentBox = e.Delta > 1 ? Box.Editor.MoveLeft() : Box.Editor.MoveRight();
};
foreach (PictureBox pb in Box.SlotPictureBoxes)
pb.ContextMenuStrip = parent.SlotPictureBoxes[0].ContextMenuStrip;
Box.ResetBoxNames(); // fix box names
var mnu = parent.SlotPictureBoxes[0].ContextMenuStrip;
foreach (var pb in Box.SlotPictureBoxes)
pb.ContextMenuStrip = mnu;
Box.ResetBoxNames(box); // fix box names
Box.ResetSlots(); // refresh box background
p.EditEnv.Slots.Publisher.Subscribers.Add(Box);
}
public int CurrentBox => Box.CurrentBox;
private void PB_BoxSwap_Click(object sender, EventArgs e) => Box.CurrentBox = parent.SwapBoxesViewer(Box.CurrentBox);
private static void Main_DragEnter(object? sender, DragEventArgs? e)