diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs b/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs index bfdbef572..4db659b3c 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs @@ -10,7 +10,7 @@ public sealed class SlotPublisher /// /// All instances that provide a view on individual content. /// - public List> Subscribers { get; } = []; + private List> Subscribers { get; } = []; public ISlotInfo? Previous { get; private set; } public SlotTouchType PreviousType { get; private set; } = SlotTouchType.None; @@ -46,4 +46,7 @@ public void ResetView(ISlotViewer sub) return; ResetView(sub, Previous, PreviousType, PreviousEntity); } + + public void Subscribe(ISlotViewer sub) => Subscribers.Add(sub); + public bool Unsubscribe(ISlotViewer sub) => Subscribers.Remove(sub); } diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs b/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs index 0c443a4cf..8ebfa02c4 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs @@ -14,7 +14,15 @@ public sealed class SlotViewInfo(ISlotInfo Slot, ISlotViewer View) : IEqua public readonly ISlotViewer View = View; public PKM ReadCurrent() => Slot.Read(View.SAV); + + /// + /// Indicates if the slot view can be written to. + /// public bool CanWriteTo() => Slot.CanWriteTo(View.SAV); + + /// + /// Indicates if the slot is empty (blank) data. + /// public bool IsEmpty() => Slot.IsEmpty(View.SAV); public WriteBlockedMessage CanWriteTo(PKM pk) => Slot.CanWriteTo(View.SAV, pk); diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 9e7a19cc2..693df6eb6 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -23,10 +23,10 @@ public void SetEditEnvironment(SaveDataEditor value) M.Env = value; menu.Editor = value; SAV = value.SAV; - value.Slots.Publisher.Subscribers.Add(this); - value.Slots.Publisher.Subscribers.Add(SL_Party); - value.Slots.Publisher.Subscribers.Add(Box); - value.Slots.Publisher.Subscribers.Add(SL_Extra); + value.Slots.Publisher.Subscribe(this); + value.Slots.Publisher.Subscribe(SL_Party); + value.Slots.Publisher.Subscribe(Box); + value.Slots.Publisher.Subscribe(SL_Extra); } public SaveFile SAV { get; private set; } = FakeSaveFile.Default; @@ -234,7 +234,8 @@ private void ResetMiscSlots() { var info = SL_Extra.GetSlotData(i); var pb = slots[i]; - SlotUtil.UpdateSlot(pb, info, info.Read(SAV), SAV, Box.FlagIllegal); + var showLegality = info is not SlotInfoMisc { HideLegality: true }; + SlotUtil.UpdateSlot(pb, info, info.Read(SAV), SAV, Box.FlagIllegal && showLegality); } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs index 527c74fb7..d82be4c49 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs @@ -28,13 +28,13 @@ public SAV_BoxList(SAVEditor p, SlotChangeManager m) CenterToParent(); Owner = p.ParentForm; foreach (var b in Boxes) - m.Env.Slots.Publisher.Subscribers.Add(b); + m.Env.Slots.Publisher.Subscribe(b); FormClosing += (_, _) => { foreach (var b in Boxes) { b.M?.Boxes.Remove(b); - m.Env.Slots.Publisher.Subscribers.Remove(b); + m.Env.Slots.Publisher.Unsubscribe(b); } }; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs index 01756e0be..e80a8e848 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs @@ -51,7 +51,7 @@ public SAV_BoxViewer(SAVEditor p, SlotChangeManager m, int box) Box.ResetBoxNames(box); // fix box names Box.ResetSlots(); // refresh box background - p.EditEnv.Slots.Publisher.Subscribers.Add(Box); + p.EditEnv.Slots.Publisher.Subscribe(Box); } private void PB_BoxSwap_Click(object sender, EventArgs e) => Box.CurrentBox = parent.SwapBoxesViewer(Box.CurrentBox); @@ -70,6 +70,6 @@ private void SAV_BoxViewer_FormClosing(object sender, FormClosingEventArgs e) { // Remove viewer from manager list Box.M?.Boxes.Remove(Box); - parent.EditEnv.Slots.Publisher.Subscribers.Remove(Box); + parent.EditEnv.Slots.Publisher.Unsubscribe(Box); } }