Borg laws announcement (second attempt) (#19474)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<Control xmlns="https://spacestation14.io"
|
||||
<Control xmlns="https://spacestation14.io"
|
||||
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
Margin="0 0 0 10">
|
||||
@@ -13,6 +13,11 @@
|
||||
<Label Name="LawNumberLabel" StyleClasses="StatusFieldTitle"/>
|
||||
<customControls:HSeparator Margin="0 5 0 5"/>
|
||||
<RichTextLabel Name="LawLabel"/>
|
||||
<BoxContainer Name="LawAnnouncementButtons" Orientation="Horizontal" HorizontalExpand="True" Margin="0 5 0 0">
|
||||
<Label Text="{Loc laws-ui-state-law}" StyleClasses="StatusFieldTitle"/>
|
||||
<Control Margin="5 0 0 0" />
|
||||
<!-- Buttons are added via C# code-->
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</Control>
|
||||
|
||||
@@ -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<BaseButton.ButtonEventArgs>? OnLawAnnouncementButtonPressed;
|
||||
|
||||
public LawDisplay(EntityUid uid, SiliconLaw law, HashSet<string>? 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<SpeechComponent>(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<RadioChannelPrototype>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
Title="{Loc 'laws-ui-menu-title'}"
|
||||
MinSize="200 100"
|
||||
SetSize="450 385">
|
||||
SetSize="450 515">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
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<InstantActionPrototype>(component.ViewLawsAction));
|
||||
component.ProvidedAction = new(_prototype.Index<InstantActionPrototype>(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<IntrinsicRadioTransmitterComponent>(uid, out var intrinsicRadio);
|
||||
HashSet<string>? radioChannels = intrinsicRadio?.Channels;
|
||||
|
||||
var state = new SiliconLawBuiState(GetLaws(uid), radioChannels);
|
||||
_userInterface.TrySetUiState(args.Entity, SiliconLawsUiKey.Key, state, (IPlayerSession) args.Session);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<SiliconLaw> Laws;
|
||||
public HashSet<string>? RadioChannels;
|
||||
|
||||
public SiliconLawBuiState(List<SiliconLaw> laws)
|
||||
public SiliconLawBuiState(List<SiliconLaw> laws, HashSet<string>? radioChannels)
|
||||
{
|
||||
Laws = laws;
|
||||
RadioChannels = radioChannels;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ 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.
|
||||
|
||||
Reference in New Issue
Block a user