using Content.Client._CorvaxNext.CrewMedal.UI;
using Content.Shared._CorvaxNext.CrewMedal;
namespace Content.Client._CorvaxNext.CrewMedal;
///
/// Handles the client-side logic for the Crew Medal system.
///
public sealed class CrewMedalSystem : SharedCrewMedalSystem
{
[Dependency] private readonly SharedUserInterfaceSystem _userInterfaceSystem = default!;
public override void Initialize()
{
base.Initialize();
// Subscribes to the event triggered after the state is automatically handled.
SubscribeLocalEvent(OnCrewMedalAfterState);
}
///
/// When an updated state is received on the client, refresh the UI to display the latest data.
///
private void OnCrewMedalAfterState(Entity entity, ref AfterAutoHandleStateEvent args)
{
// Checks if the Crew Medal UI is open for the given entity and reloads it with updated data.
if (_userInterfaceSystem.TryGetOpenUi(
entity.Owner,
CrewMedalUiKey.Key,
out var medalUi))
{
medalUi.Reload();
}
}
}