mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-24 11:23:11 +00:00
f60926d200
future implementation
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Pushes slot update notifications out to all subscribers.
|
|
/// </summary>
|
|
public sealed class SlotPublisher
|
|
{
|
|
/// <summary>
|
|
/// All <see cref="ISlotViewer"/> instances that provide a view on individual <see cref="StorageSlotOffset"/> content.
|
|
/// </summary>
|
|
public List<ISlotViewer> Subscribers { get; } = new List<ISlotViewer>();
|
|
|
|
private SlotChange Previous;
|
|
private SlotTouchType PreviousType = SlotTouchType.None;
|
|
|
|
/// <summary>
|
|
/// Notifies all <see cref="Subscribers"/> with the latest slot change details.
|
|
/// </summary>
|
|
/// <param name="slot">Last interacted slot</param>
|
|
/// <param name="type">Last interacted slot interaction type</param>
|
|
public void NotifySlotChanged(SlotChange slot, SlotTouchType type)
|
|
{
|
|
foreach (var sub in Subscribers)
|
|
ResetView(sub, slot, type);
|
|
Previous = slot;
|
|
PreviousType = type;
|
|
}
|
|
|
|
private void ResetView(ISlotViewer sub, SlotChange slot, SlotTouchType type)
|
|
{
|
|
if (Previous != null)
|
|
sub.NotifySlotOld(Previous);
|
|
|
|
int index = sub.ViewIndex;
|
|
if (index == slot.Box)
|
|
sub.NotifySlotChanged(slot, type);
|
|
}
|
|
|
|
public void ResetView(ISlotViewer sub) => ResetView(sub, Previous, PreviousType);
|
|
}
|
|
}
|