Hide slot change publisher's list, add/remove

This commit is contained in:
Kurt
2025-08-22 16:31:57 -05:00
parent 3f32ee5814
commit 5beabb2020
5 changed files with 22 additions and 10 deletions

View File

@@ -10,7 +10,7 @@ public sealed class SlotPublisher<T>
/// <summary>
/// All <see cref="ISlotViewer{T}"/> instances that provide a view on individual <see cref="ISlotInfo"/> content.
/// </summary>
public List<ISlotViewer<T>> Subscribers { get; } = [];
private List<ISlotViewer<T>> Subscribers { get; } = [];
public ISlotInfo? Previous { get; private set; }
public SlotTouchType PreviousType { get; private set; } = SlotTouchType.None;
@@ -46,4 +46,7 @@ public void ResetView(ISlotViewer<T> sub)
return;
ResetView(sub, Previous, PreviousType, PreviousEntity);
}
public void Subscribe(ISlotViewer<T> sub) => Subscribers.Add(sub);
public bool Unsubscribe(ISlotViewer<T> sub) => Subscribers.Remove(sub);
}

View File

@@ -14,7 +14,15 @@ public sealed class SlotViewInfo<T>(ISlotInfo Slot, ISlotViewer<T> View) : IEqua
public readonly ISlotViewer<T> View = View;
public PKM ReadCurrent() => Slot.Read(View.SAV);
/// <summary>
/// Indicates if the slot view can be written to.
/// </summary>
public bool CanWriteTo() => Slot.CanWriteTo(View.SAV);
/// <summary>
/// Indicates if the slot is empty (blank) data.
/// </summary>
public bool IsEmpty() => Slot.IsEmpty(View.SAV);
public WriteBlockedMessage CanWriteTo(PKM pk) => Slot.CanWriteTo(View.SAV, pk);

View File

@@ -23,10 +23,10 @@ public void SetEditEnvironment(SaveDataEditor<PictureBox> 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);
}
}

View File

@@ -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);
}
};
}

View File

@@ -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);
}
}