diff --git a/Content.Client/_CorvaxNext/CrewMedal/CrewMedalSystem.cs b/Content.Client/_CorvaxNext/CrewMedal/CrewMedalSystem.cs new file mode 100644 index 00000000000..cb1b35c79bf --- /dev/null +++ b/Content.Client/_CorvaxNext/CrewMedal/CrewMedalSystem.cs @@ -0,0 +1,34 @@ +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(); + } + } +} diff --git a/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalBoundUserInterface.cs b/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalBoundUserInterface.cs new file mode 100644 index 00000000000..30ef2141bb2 --- /dev/null +++ b/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalBoundUserInterface.cs @@ -0,0 +1,65 @@ +using Content.Shared._CorvaxNext.CrewMedal; +using Robust.Client.UserInterface; + +namespace Content.Client._CorvaxNext.CrewMedal.UI; + +/// +/// A wrapper class for the Crew Medal user interface. +/// Initializes the and updates it when new data is received from the server. +/// +public sealed class CrewMedalBoundUserInterface : BoundUserInterface +{ + [Dependency] private readonly IEntityManager _entityManager = default!; + + /// + /// The main interface window. + /// + [ViewVariables] + private CrewMedalWindow? _window; + + public CrewMedalBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + IoCManager.InjectDependencies(this); + } + + protected override void Open() + { + base.Open(); + + _window = this.CreateWindow(); + _window.OnReasonChanged += HandleReasonChanged; + + Reload(); + } + + /// + /// Called when the reason is changed in the . + /// Sends a message to the server with the new reason if it differs from the current one. + /// + private void HandleReasonChanged(string newReason) + { + if (!_entityManager.TryGetComponent(Owner, out var component)) + return; + + if (!component.Reason.Equals(newReason)) + { + SendPredictedMessage(new CrewMedalReasonChangedMessage(newReason)); + } + } + + /// + /// Updates the data in the window to reflect the current state of the . + /// + public void Reload() + { + if (_window is null) + return; + + if (!_entityManager.TryGetComponent(Owner, out var component)) + return; + + _window.SetCurrentReason(component.Reason); + _window.SetAwarded(component.Awarded); + _window.SetMaxCharacters(component.MaxCharacters); + } +} diff --git a/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalWindow.xaml b/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalWindow.xaml new file mode 100644 index 00000000000..95304f08e6f --- /dev/null +++ b/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalWindow.xaml @@ -0,0 +1,13 @@ + + +