From 154d0eadf2fe48911011b2f10fbc871a50c57ba8 Mon Sep 17 00:00:00 2001 From: Vonsant Date: Thu, 2 Jan 2025 08:04:25 +0300 Subject: [PATCH] Medals --- .../_CorvaxNext/CrewMedal/CrewMedalSystem.cs | 34 +++++ .../UI/CrewMedalBoundUserInterface.cs | 63 ++++++++ .../CrewMedal/UI/CrewMedalWindow.xaml | 13 ++ .../CrewMedal/UI/CrewMedalWindow.xaml.cs | 88 ++++++++++++ .../_CorvaxNext/CrewMedal/CrewMedalSystem.cs | 136 ++++++++++++++++++ .../CrewMedal/CrewMedalComponent.cs | 39 +++++ .../_CorvaxNext/CrewMedal/CrewMedalEvents.cs | 29 ++++ .../CrewMedal/SharedCrewMedalSystem.cs | 29 ++++ .../crew-medals/crew-medal-component.ftl | 17 +++ .../Entities/Clothing/Neck/medals.yml | 80 +++++++++++ 10 files changed, 528 insertions(+) create mode 100644 Content.Client/_CorvaxNext/CrewMedal/CrewMedalSystem.cs create mode 100644 Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalBoundUserInterface.cs create mode 100644 Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalWindow.xaml create mode 100644 Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalWindow.xaml.cs create mode 100644 Content.Server/_CorvaxNext/CrewMedal/CrewMedalSystem.cs create mode 100644 Content.Shared/_CorvaxNext/CrewMedal/CrewMedalComponent.cs create mode 100644 Content.Shared/_CorvaxNext/CrewMedal/CrewMedalEvents.cs create mode 100644 Content.Shared/_CorvaxNext/CrewMedal/SharedCrewMedalSystem.cs create mode 100644 Resources/Locale/ru-RU/_corvaxnext/crew-medals/crew-medal-component.ftl 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..17274d81f87 --- /dev/null +++ b/Content.Client/_CorvaxNext/CrewMedal/UI/CrewMedalBoundUserInterface.cs @@ -0,0 +1,63 @@ +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)) + { + 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 == 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 @@ + + +