diff --git a/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml b/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml index 714d9e0fe7..427b3ff181 100644 --- a/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml +++ b/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml @@ -1,4 +1,4 @@ - @@ -13,6 +13,11 @@ diff --git a/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs b/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs index c48fcef619..47545f17e1 100644 --- a/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs +++ b/Content.Client/Silicons/Laws/Ui/LawDisplay.xaml.cs @@ -1,21 +1,86 @@ +using Content.Client.Chat.Managers; +using Content.Shared.Chat; +using Content.Shared.Radio; using Content.Shared.Silicons.Laws; +using Content.Shared.Speech; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Prototypes; namespace Content.Client.Silicons.Laws.Ui; [GenerateTypedNameReferences] public sealed partial class LawDisplay : Control { - public LawDisplay(SiliconLaw prototype) + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IChatManager _chatManager = default!; + [Dependency] private readonly EntityManager _entityManager = default!; + + public event Action? OnLawAnnouncementButtonPressed; + + public LawDisplay(EntityUid uid, SiliconLaw law, HashSet? radioChannels) { RobustXamlLoader.Load(this); + IoCManager.InjectDependencies(this); - var identifier = prototype.LawIdentifierOverride ?? $"{prototype.Order}"; + var identifier = law.LawIdentifierOverride ?? $"{law.Order}"; + var lawIdentifier = Loc.GetString("laws-ui-law-header", ("id", identifier)); + var lawDescription = Loc.GetString(law.LawString); - LawNumberLabel.Text = Loc.GetString("laws-ui-law-header", ("id", identifier)); - LawLabel.SetMessage(Loc.GetString(prototype.LawString)); + LawNumberLabel.Text = lawIdentifier; + LawLabel.SetMessage(lawDescription); + + // If you can't talk, you can't state your laws... + if (!_entityManager.TryGetComponent(uid, out var speech) || speech.SpeechSounds is null) + return; + + var localButton = new Button + { + Text = Loc.GetString("hud-chatbox-select-channel-Local"), + Modulate = Color.DarkGray, + StyleClasses = { "chatSelectorOptionButton" }, + MinHeight = 35, + MinWidth = 75, + }; + + localButton.OnPressed += _ => + { + _chatManager.SendMessage($"{lawIdentifier}: {lawDescription}", ChatSelectChannel.Local); + }; + + LawAnnouncementButtons.AddChild(localButton); + + if (radioChannels == null) + return; + + foreach (var radioChannel in radioChannels) + { + if (!_prototypeManager.TryIndex(radioChannel, out var radioChannelProto)) + continue; + + var radioChannelButton = new Button + { + Text = Loc.GetString(radioChannelProto.Name), + Modulate = radioChannelProto.Color, + StyleClasses = { "chatSelectorOptionButton" }, + MinHeight = 35, + MinWidth = 75, + }; + + radioChannelButton.OnPressed += _ => + { + switch (radioChannel) + { + case SharedChatSystem.CommonChannel: + _chatManager.SendMessage($"{SharedChatSystem.RadioCommonPrefix} {lawIdentifier}: {lawDescription}", ChatSelectChannel.Radio); break; + default: + _chatManager.SendMessage($"{SharedChatSystem.RadioChannelPrefix}{radioChannelProto.KeyCode} {lawIdentifier}: {lawDescription}", ChatSelectChannel.Radio); break; + } + }; + + LawAnnouncementButtons.AddChild(radioChannelButton); + } } } - diff --git a/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs b/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs index 78231c24df..2aee0a38c0 100644 --- a/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs +++ b/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs @@ -9,10 +9,11 @@ public sealed class SiliconLawBoundUserInterface : BoundUserInterface { [ViewVariables] private SiliconLawMenu? _menu; + private EntityUid _owner; public SiliconLawBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - + _owner = owner; } protected override void Open() @@ -40,6 +41,6 @@ public sealed class SiliconLawBoundUserInterface : BoundUserInterface if (state is not SiliconLawBuiState msg) return; - _menu?.Update(msg); + _menu?.Update(_owner, msg); } } diff --git a/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml b/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml index 1b6324dae6..97f6179e45 100644 --- a/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml +++ b/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml @@ -1,9 +1,9 @@ - + SetSize="450 515"> diff --git a/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml.cs b/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml.cs index 48adce87f8..a63494bc52 100644 --- a/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml.cs +++ b/Content.Client/Silicons/Laws/Ui/SiliconLawMenu.xaml.cs @@ -14,16 +14,16 @@ public sealed partial class SiliconLawMenu : FancyWindow IoCManager.InjectDependencies(this); } - public void Update(SiliconLawBuiState state) + public void Update(EntityUid uid, SiliconLawBuiState state) { state.Laws.Sort(); LawDisplayContainer.Children.Clear(); + foreach (var law in state.Laws) { - var control = new LawDisplay(law); + var control = new LawDisplay(uid, law, state.RadioChannels); LawDisplayContainer.AddChild(control); } } } - diff --git a/Content.Server/Silicons/Laws/SiliconLawSystem.cs b/Content.Server/Silicons/Laws/SiliconLawSystem.cs index 0413514e45..e10c1d95ca 100644 --- a/Content.Server/Silicons/Laws/SiliconLawSystem.cs +++ b/Content.Server/Silicons/Laws/SiliconLawSystem.cs @@ -1,9 +1,10 @@ -using System.Linq; +using System.Linq; using Content.Server.Administration; using Content.Server.Chat.Managers; using Content.Server.GameTicking; using Content.Server.Mind; using Content.Server.Mind.Components; +using Content.Server.Radio.Components; using Content.Server.Roles; using Content.Server.Station.Systems; using Content.Shared.Actions; @@ -35,6 +36,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem [Dependency] private readonly StationSystem _station = default!; [Dependency] private readonly UserInterfaceSystem _userInterface = default!; [Dependency] private readonly SharedStunSystem _stunSystem = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; /// public override void Initialize() @@ -58,7 +60,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem private void OnComponentStartup(EntityUid uid, SiliconLawBoundComponent component, ComponentStartup args) { - component.ProvidedAction = new (_prototype.Index(component.ViewLawsAction)); + component.ProvidedAction = new(_prototype.Index(component.ViewLawsAction)); _actions.AddAction(uid, component.ProvidedAction, null); } @@ -95,7 +97,10 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem private void OnBoundUIOpened(EntityUid uid, SiliconLawBoundComponent component, BoundUIOpenedEvent args) { - var state = new SiliconLawBuiState(GetLaws(uid)); + _entityManager.TryGetComponent(uid, out var intrinsicRadio); + HashSet? radioChannels = intrinsicRadio?.Channels; + + var state = new SiliconLawBuiState(GetLaws(uid), radioChannels); _userInterface.TrySetUiState(args.Entity, SiliconLawsUiKey.Key, state, (IPlayerSession) args.Session); } diff --git a/Content.Shared/Silicons/Laws/Components/SiliconLawBoundComponent.cs b/Content.Shared/Silicons/Laws/Components/SiliconLawBoundComponent.cs index 50a3c36efc..ab98a57feb 100644 --- a/Content.Shared/Silicons/Laws/Components/SiliconLawBoundComponent.cs +++ b/Content.Shared/Silicons/Laws/Components/SiliconLawBoundComponent.cs @@ -1,4 +1,4 @@ -using Content.Shared.Actions; +using Content.Shared.Actions; using Content.Shared.Actions.ActionTypes; using Robust.Shared.Serialization; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; @@ -63,9 +63,11 @@ public enum SiliconLawsUiKey : byte public sealed class SiliconLawBuiState : BoundUserInterfaceState { public List Laws; + public HashSet? RadioChannels; - public SiliconLawBuiState(List laws) + public SiliconLawBuiState(List laws, HashSet? radioChannels) { Laws = laws; + RadioChannels = radioChannels; } } diff --git a/Resources/Locale/en-US/station-laws/laws.ftl b/Resources/Locale/en-US/station-laws/laws.ftl index 1ba50e5443..04d4acabaa 100644 --- a/Resources/Locale/en-US/station-laws/laws.ftl +++ b/Resources/Locale/en-US/station-laws/laws.ftl @@ -26,8 +26,9 @@ law-emag-require-panel = The panel must be open to use the EMAG. laws-ui-menu-title = Laws laws-ui-law-header = Law {$id} +laws-ui-state-law = State law: laws-notify = You are bound to silicon laws, which you can view via the sidebar action. You are required to always follow your laws. laws-update-notify = Your laws have been updated. You can view the changes via the sidebar action. -laws-compromised-examine = The [color=red]law-governing[/color] internals seem damaged... +laws-compromised-examine = The [color=red]law-governing[/color] internals seem damaged... \ No newline at end of file