Holopads (#32711)
* Initial resources commit * Initial code commit * Added additional resources * Continuing to build holopad and telephone systems * Added hologram shader * Added hologram system and entity * Holo calls now have a hologram of the user appear on them * Initial implementation of holopads transmitting nearby chatter * Added support for linking across multiple telephones/holopads/entities * Fixed a bunch of bugs * Tried simplifying holopad entity dependence, added support for mid-call user switching * Replaced PVS expansion with manually networked sprite states * Adjusted volume of ring tone * Added machine board * Minor features and tweaks * Resolving merge conflict * Recommit audio attributions * Telephone chat adjustments * Added support for AI interactions with holopads * Building the holopad UI * Holopad UI finished * Further UI tweaks * Station AI can hear local chatter when being projected from a holopad * Minor bug fixes * Added wire panels to holopads * Basic broadcasting * Start of emergency broadcasting code * Fixing issues with broadcasting * More work on emergency broadcasting * Updated holopad visuals * Added cooldown text to emergency broadcast and control lock out screen * Code clean up * Fixed issue with timing * Broadcasting now requires command access * Fixed some bugs * Added multiple holopad prototypes with different ranges * The AI no longer requires power to interact with holopads * Fixed some additional issues * Addressing more issues * Added emote support for holograms * Changed the broadcast lockout durations to their proper values * Added AI vision wire to holopads * Bug fixes * AI vision and interaction wires can be added to the same wire panel * Fixed error * More bug fixes * Fixed test fail * Embellished the emergency call lock out window * Holopads play borg sounds when speaking * Borg and AI names are listed as the caller ID on the holopad * Borg chassis can now be seen on holopad holograms * Holopad returns to a machine frame when badly damaged * Clarified some text * Fix merge conflict * Fixed merge conflict * Fixing merge conflict * Fixing merge conflict * Fixing merge conflict * Offset menu on open * AI can alt click on holopads to activate the projector * Bug fixes for intellicard interactions * Fixed speech issue with intellicards * The UI automatically opens for the AI when it alt-clicks on the holopad * Simplified shader math * Telephones will auto hang up 60 seconds after the last person on a call stops speaking * Added better support for AI requests when multiple AI cores are on the station * The call controls pop up for the AI when they accept a summons from a holopad * Compatibility mode fix for the hologram shader * Further shader fixes for compatibility mode * File clean up * More cleaning up * Removed access requirements from quantum holopads so they can used by nukies * The title of the holopad window now reflects the name of the device * Linked telephones will lose their connection if both move out of range of each other
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Numerics;
|
||||
using Content.Client.Chat.Managers;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Speech;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -141,7 +142,12 @@ namespace Content.Client.Chat.UI
|
||||
Modulate = Color.White;
|
||||
}
|
||||
|
||||
var offset = (-_eyeManager.CurrentEye.Rotation).ToWorldVec() * -EntityVerticalOffset;
|
||||
var baseOffset = 0f;
|
||||
|
||||
if (_entityManager.TryGetComponent<SpeechComponent>(_senderEntity, out var speech))
|
||||
baseOffset = speech.SpeechBubbleOffset;
|
||||
|
||||
var offset = (-_eyeManager.CurrentEye.Rotation).ToWorldVec() * -(EntityVerticalOffset + baseOffset);
|
||||
var worldPos = _transformSystem.GetWorldPosition(xform) + offset;
|
||||
|
||||
var lowerCenter = _eyeManager.WorldToScreen(worldPos) / UIScale;
|
||||
|
||||
101
Content.Client/Holopad/HolopadBoundUserInterface.cs
Normal file
101
Content.Client/Holopad/HolopadBoundUserInterface.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using Content.Shared.Holopad;
|
||||
using Content.Shared.Silicons.StationAi;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.Player;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Content.Client.Holopad;
|
||||
|
||||
public sealed class HolopadBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IClyde _displayManager = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private HolopadWindow? _window;
|
||||
|
||||
public HolopadBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = this.CreateWindow<HolopadWindow>();
|
||||
_window.Title = Loc.GetString("holopad-window-title", ("title", EntMan.GetComponent<MetaDataComponent>(Owner).EntityName));
|
||||
|
||||
if (this.UiKey is not HolopadUiKey)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var uiKey = (HolopadUiKey)this.UiKey;
|
||||
|
||||
// AIs will see a different holopad interface to crew when interacting with them in the world
|
||||
if (uiKey == HolopadUiKey.InteractionWindow && EntMan.HasComponent<StationAiHeldComponent>(_playerManager.LocalEntity))
|
||||
uiKey = HolopadUiKey.InteractionWindowForAi;
|
||||
|
||||
_window.SetState(Owner, uiKey);
|
||||
_window.UpdateState(new Dictionary<NetEntity, string>());
|
||||
|
||||
// Set message actions
|
||||
_window.SendHolopadStartNewCallMessageAction += SendHolopadStartNewCallMessage;
|
||||
_window.SendHolopadAnswerCallMessageAction += SendHolopadAnswerCallMessage;
|
||||
_window.SendHolopadEndCallMessageAction += SendHolopadEndCallMessage;
|
||||
_window.SendHolopadStartBroadcastMessageAction += SendHolopadStartBroadcastMessage;
|
||||
_window.SendHolopadActivateProjectorMessageAction += SendHolopadActivateProjectorMessage;
|
||||
_window.SendHolopadRequestStationAiMessageAction += SendHolopadRequestStationAiMessage;
|
||||
|
||||
// If this call is addressed to an AI, open the window in the bottom right hand corner of the screen
|
||||
if (uiKey == HolopadUiKey.AiRequestWindow)
|
||||
_window.OpenCenteredAt(new Vector2(1f, 1f));
|
||||
|
||||
// Otherwise offset to the left so the holopad can still be seen
|
||||
else
|
||||
_window.OpenCenteredAt(new Vector2(0.3333f, 0.50f));
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
var castState = (HolopadBoundInterfaceState)state;
|
||||
EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
|
||||
|
||||
_window?.UpdateState(castState.Holopads);
|
||||
}
|
||||
|
||||
public void SendHolopadStartNewCallMessage(NetEntity receiver)
|
||||
{
|
||||
SendMessage(new HolopadStartNewCallMessage(receiver));
|
||||
}
|
||||
|
||||
public void SendHolopadAnswerCallMessage()
|
||||
{
|
||||
SendMessage(new HolopadAnswerCallMessage());
|
||||
}
|
||||
|
||||
public void SendHolopadEndCallMessage()
|
||||
{
|
||||
SendMessage(new HolopadEndCallMessage());
|
||||
}
|
||||
|
||||
public void SendHolopadStartBroadcastMessage()
|
||||
{
|
||||
SendMessage(new HolopadStartBroadcastMessage());
|
||||
}
|
||||
|
||||
public void SendHolopadActivateProjectorMessage()
|
||||
{
|
||||
SendMessage(new HolopadActivateProjectorMessage());
|
||||
}
|
||||
|
||||
public void SendHolopadRequestStationAiMessage()
|
||||
{
|
||||
SendMessage(new HolopadStationAiRequestMessage());
|
||||
}
|
||||
}
|
||||
172
Content.Client/Holopad/HolopadSystem.cs
Normal file
172
Content.Client/Holopad/HolopadSystem.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using Content.Shared.Chat.TypingIndicator;
|
||||
using Content.Shared.Holopad;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Client.Holopad;
|
||||
|
||||
public sealed class HolopadSystem : SharedHolopadSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HolopadHologramComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<HolopadHologramComponent, BeforePostShaderRenderEvent>(OnShaderRender);
|
||||
SubscribeAllEvent<TypingChangedEvent>(OnTypingChanged);
|
||||
|
||||
SubscribeNetworkEvent<PlayerSpriteStateRequest>(OnPlayerSpriteStateRequest);
|
||||
SubscribeNetworkEvent<PlayerSpriteStateMessage>(OnPlayerSpriteStateMessage);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, HolopadHologramComponent component, ComponentInit ev)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
||||
return;
|
||||
|
||||
UpdateHologramSprite(uid);
|
||||
}
|
||||
|
||||
private void OnShaderRender(EntityUid uid, HolopadHologramComponent component, BeforePostShaderRenderEvent ev)
|
||||
{
|
||||
if (ev.Sprite.PostShader == null)
|
||||
return;
|
||||
|
||||
ev.Sprite.PostShader.SetParameter("t", (float)_timing.CurTime.TotalSeconds * component.ScrollRate);
|
||||
}
|
||||
|
||||
private void OnTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
var uid = args.SenderSession.AttachedEntity;
|
||||
|
||||
if (!Exists(uid))
|
||||
return;
|
||||
|
||||
if (!HasComp<HolopadUserComponent>(uid))
|
||||
return;
|
||||
|
||||
var netEv = new HolopadUserTypingChangedEvent(GetNetEntity(uid.Value), ev.IsTyping);
|
||||
RaiseNetworkEvent(netEv);
|
||||
}
|
||||
|
||||
private void OnPlayerSpriteStateRequest(PlayerSpriteStateRequest ev)
|
||||
{
|
||||
var targetPlayer = GetEntity(ev.TargetPlayer);
|
||||
var player = _playerManager.LocalSession?.AttachedEntity;
|
||||
|
||||
// Ignore the request if received by a player who isn't the target
|
||||
if (targetPlayer != player)
|
||||
return;
|
||||
|
||||
if (!TryComp<SpriteComponent>(player, out var playerSprite))
|
||||
return;
|
||||
|
||||
var spriteLayerData = new List<PrototypeLayerData>();
|
||||
|
||||
if (playerSprite.Visible)
|
||||
{
|
||||
// Record the RSI paths, state names and shader paramaters of all visible layers
|
||||
for (int i = 0; i < playerSprite.AllLayers.Count(); i++)
|
||||
{
|
||||
if (!playerSprite.TryGetLayer(i, out var layer))
|
||||
continue;
|
||||
|
||||
if (!layer.Visible ||
|
||||
string.IsNullOrEmpty(layer.ActualRsi?.Path.ToString()) ||
|
||||
string.IsNullOrEmpty(layer.State.Name))
|
||||
continue;
|
||||
|
||||
var layerDatum = new PrototypeLayerData();
|
||||
layerDatum.RsiPath = layer.ActualRsi.Path.ToString();
|
||||
layerDatum.State = layer.State.Name;
|
||||
|
||||
if (layer.CopyToShaderParameters != null)
|
||||
{
|
||||
var key = (string)layer.CopyToShaderParameters.LayerKey;
|
||||
|
||||
if (playerSprite.LayerMapTryGet(key, out var otherLayerIdx) &&
|
||||
playerSprite.TryGetLayer(otherLayerIdx, out var otherLayer) &&
|
||||
otherLayer.Visible)
|
||||
{
|
||||
layerDatum.MapKeys = new() { key };
|
||||
|
||||
layerDatum.CopyToShaderParameters = new PrototypeCopyToShaderParameters()
|
||||
{
|
||||
LayerKey = key,
|
||||
ParameterTexture = layer.CopyToShaderParameters.ParameterTexture,
|
||||
ParameterUV = layer.CopyToShaderParameters.ParameterUV
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
spriteLayerData.Add(layerDatum);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the recorded data to the server
|
||||
var evResponse = new PlayerSpriteStateMessage(ev.TargetPlayer, spriteLayerData.ToArray());
|
||||
RaiseNetworkEvent(evResponse);
|
||||
}
|
||||
|
||||
private void OnPlayerSpriteStateMessage(PlayerSpriteStateMessage ev)
|
||||
{
|
||||
UpdateHologramSprite(GetEntity(ev.SpriteEntity), ev.SpriteLayerData);
|
||||
}
|
||||
|
||||
private void UpdateHologramSprite(EntityUid uid, PrototypeLayerData[]? layerData = null)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(uid, out var hologramSprite))
|
||||
return;
|
||||
|
||||
if (!TryComp<HolopadHologramComponent>(uid, out var holopadhologram))
|
||||
return;
|
||||
|
||||
for (int i = hologramSprite.AllLayers.Count() - 1; i >= 0; i--)
|
||||
hologramSprite.RemoveLayer(i);
|
||||
|
||||
if (layerData == null || layerData.Length == 0)
|
||||
{
|
||||
layerData = new PrototypeLayerData[1];
|
||||
layerData[0] = new PrototypeLayerData()
|
||||
{
|
||||
RsiPath = holopadhologram.RsiPath,
|
||||
State = holopadhologram.RsiState
|
||||
};
|
||||
}
|
||||
|
||||
for (int i = 0; i < layerData.Length; i++)
|
||||
{
|
||||
var layer = layerData[i];
|
||||
layer.Shader = "unshaded";
|
||||
|
||||
hologramSprite.AddLayer(layerData[i], i);
|
||||
}
|
||||
|
||||
UpdateHologramShader(uid, hologramSprite, holopadhologram);
|
||||
}
|
||||
|
||||
private void UpdateHologramShader(EntityUid uid, SpriteComponent sprite, HolopadHologramComponent holopadHologram)
|
||||
{
|
||||
// Find the texture height of the largest layer
|
||||
float texHeight = sprite.AllLayers.Max(x => x.PixelSize.Y);
|
||||
|
||||
var instance = _prototypeManager.Index<ShaderPrototype>(holopadHologram.ShaderName).InstanceUnique();
|
||||
instance.SetParameter("color1", new Vector3(holopadHologram.Color1.R, holopadHologram.Color1.G, holopadHologram.Color1.B));
|
||||
instance.SetParameter("color2", new Vector3(holopadHologram.Color2.R, holopadHologram.Color2.G, holopadHologram.Color2.B));
|
||||
instance.SetParameter("alpha", holopadHologram.Alpha);
|
||||
instance.SetParameter("intensity", holopadHologram.Intensity);
|
||||
instance.SetParameter("texHeight", texHeight);
|
||||
instance.SetParameter("t", (float)_timing.CurTime.TotalSeconds * holopadHologram.ScrollRate);
|
||||
|
||||
sprite.PostShader = instance;
|
||||
sprite.RaiseShaderEvent = true;
|
||||
}
|
||||
}
|
||||
107
Content.Client/Holopad/HolopadWindow.xaml
Normal file
107
Content.Client/Holopad/HolopadWindow.xaml
Normal file
@@ -0,0 +1,107 @@
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
Resizable="False"
|
||||
MaxSize="400 800"
|
||||
MinSize="400 150">
|
||||
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
|
||||
|
||||
<BoxContainer Name="ControlsLockOutContainer" Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" ReservesSpace="False" Visible="False">
|
||||
<!-- Header text -->
|
||||
<controls:StripeBack>
|
||||
<PanelContainer>
|
||||
<RichTextLabel Name="EmergencyBroadcastText" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10 10 10 10" ReservesSpace="False"/>
|
||||
</PanelContainer>
|
||||
</controls:StripeBack>
|
||||
|
||||
<Label Text="{Loc 'holopad-window-controls-locked-out'}" HorizontalAlignment="Center" Margin="10 5 10 0" ReservesSpace="False"/>
|
||||
<RichTextLabel Name="LockOutIdText" HorizontalAlignment="Center" Margin="10 5 10 0" ReservesSpace="False"/>
|
||||
<Label Name="LockOutCountDownText" Text="{Loc 'holopad-window-controls-unlock-countdown'}" HorizontalAlignment="Center" Margin="10 15 10 10" ReservesSpace="False"/>
|
||||
</BoxContainer>
|
||||
|
||||
<BoxContainer Name="ControlsContainer" Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" ReservesSpace="False">
|
||||
|
||||
<!-- Active call controls (either this or the call placement controls will be active) -->
|
||||
<BoxContainer Name="ActiveCallControlsContainer" Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" ReservesSpace="False">
|
||||
|
||||
<!-- Header text -->
|
||||
<BoxContainer MinHeight="60" Orientation="Vertical" VerticalAlignment="Center">
|
||||
<Label Name="CallStatusText" Margin="10 5 10 0" ReservesSpace="False"/>
|
||||
<RichTextLabel Name="CallerIdText" HorizontalAlignment="Center" Margin="0 0 0 0" ReservesSpace="False"/>
|
||||
</BoxContainer>
|
||||
|
||||
<!-- Controls (the answer call button is absent when the phone is not ringing) -->
|
||||
<GridContainer Columns="2" ReservesSpace="False">
|
||||
<Control HorizontalExpand="True" Margin="10 0 2 5">
|
||||
<Button Name="AnswerCallButton" Text="{Loc 'holopad-window-answer-call'}" StyleClasses="OpenRight" Margin="0 0 0 5" Disabled="True"/>
|
||||
</Control>
|
||||
<Control HorizontalExpand="True" Margin="2 0 10 5">
|
||||
<Button Name="EndCallButton" Text="{Loc 'holopad-window-end-call'}" StyleClasses="OpenLeft" Margin="0 0 0 5" Disabled="True"/>
|
||||
</Control>
|
||||
</GridContainer>
|
||||
|
||||
</BoxContainer>
|
||||
|
||||
<!-- Call placement controls (either this or the active call controls will be active) -->
|
||||
<BoxContainer Name="CallPlacementControlsContainer" Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" ReservesSpace="False">
|
||||
|
||||
<controls:StripeBack>
|
||||
<PanelContainer>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<RichTextLabel Name="SubtitleText" HorizontalAlignment="Center" Margin="0 5 0 0"/>
|
||||
<RichTextLabel Name="OptionsText" HorizontalAlignment="Center" Margin="0 0 0 5"/>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</controls:StripeBack>
|
||||
|
||||
<!-- Request the station AI or activate the holopad projector (only one of these should be active at a time) -->
|
||||
<BoxContainer Name="RequestStationAiContainer" Orientation="Vertical" ReservesSpace="False" Visible="False">
|
||||
<Button Name="RequestStationAiButton" Text="{Loc 'holopad-window-request-station-ai'}" Margin="10 5 10 5" Disabled="False"/>
|
||||
</BoxContainer>
|
||||
|
||||
<BoxContainer Name="ActivateProjectorContainer" Orientation="Vertical" ReservesSpace="False" Visible="False">
|
||||
<Button Name="ActivateProjectorButton" Text="{Loc 'holopad-window-activate-projector'}" Margin="10 5 10 5" Disabled="False"/>
|
||||
</BoxContainer>
|
||||
|
||||
<!-- List of contactable holopads (the list is created in C#) -->
|
||||
<BoxContainer Name="HolopadContactListContainer" Orientation="Vertical" Margin="10 0 10 5" ReservesSpace="False" Visible="False">
|
||||
<PanelContainer Name="HolopadContactListHeaderPanel">
|
||||
<Label Text="{Loc 'holopad-window-select-contact-from-list'}" HorizontalAlignment="Center" Margin="0 3 0 3"/>
|
||||
</PanelContainer>
|
||||
|
||||
<PanelContainer Name="HolopadContactListPanel">
|
||||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True" Margin="8, 8, 8, 8" MinHeight="256">
|
||||
|
||||
<!-- If there is no data yet, this will be displayed -->
|
||||
<BoxContainer Name="FetchingAvailableHolopadsContainer" HorizontalAlignment="Center" HorizontalExpand="True" VerticalExpand="True" ReservesSpace="False">
|
||||
<Label Text="{Loc 'holopad-window-fetching-contacts-list'}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</BoxContainer>
|
||||
|
||||
<!-- Container for the contacts -->
|
||||
<BoxContainer Name="ContactsList" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="10 0 10 0"/>
|
||||
</ScrollContainer>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
|
||||
<!-- Button to start an emergency broadcast (the user requires a certain level of access to interact with it) -->
|
||||
<BoxContainer Name="StartBroadcastContainer" Orientation="Vertical" ReservesSpace="False" Visible="False">
|
||||
<Button Name="StartBroadcastButton" Text="{Loc 'holopad-window-emergency-broadcast'}" Margin="10 0 10 5" Disabled="False" ReservesSpace="False"/>
|
||||
</BoxContainer>
|
||||
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
|
||||
<!-- Footer -->
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<PanelContainer StyleClasses="LowDivider" />
|
||||
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
|
||||
<Label Text="{Loc 'holopad-window-flavor-left'}" StyleClasses="WindowFooterText" />
|
||||
<Label Text="{Loc 'holopad-window-flavor-right'}" StyleClasses="WindowFooterText"
|
||||
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0" />
|
||||
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
|
||||
</controls:FancyWindow>
|
||||
338
Content.Client/Holopad/HolopadWindow.xaml.cs
Normal file
338
Content.Client/Holopad/HolopadWindow.xaml.cs
Normal file
@@ -0,0 +1,338 @@
|
||||
using Content.Client.Popups;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.Holopad;
|
||||
using Content.Shared.Telephone;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Client.Holopad;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class HolopadWindow : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private readonly SharedHolopadSystem _holopadSystem = default!;
|
||||
private readonly SharedTelephoneSystem _telephoneSystem = default!;
|
||||
private readonly AccessReaderSystem _accessReaderSystem = default!;
|
||||
private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
private EntityUid? _owner = null;
|
||||
private HolopadUiKey _currentUiKey;
|
||||
private TelephoneState _currentState;
|
||||
private TelephoneState _previousState;
|
||||
private TimeSpan _buttonUnlockTime;
|
||||
private float _updateTimer = 0.25f;
|
||||
|
||||
private const float UpdateTime = 0.25f;
|
||||
private TimeSpan _buttonUnlockDelay = TimeSpan.FromSeconds(0.5f);
|
||||
|
||||
public event Action<NetEntity>? SendHolopadStartNewCallMessageAction;
|
||||
public event Action? SendHolopadAnswerCallMessageAction;
|
||||
public event Action? SendHolopadEndCallMessageAction;
|
||||
public event Action? SendHolopadStartBroadcastMessageAction;
|
||||
public event Action? SendHolopadActivateProjectorMessageAction;
|
||||
public event Action? SendHolopadRequestStationAiMessageAction;
|
||||
|
||||
public HolopadWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_holopadSystem = _entManager.System<SharedHolopadSystem>();
|
||||
_telephoneSystem = _entManager.System<SharedTelephoneSystem>();
|
||||
_accessReaderSystem = _entManager.System<AccessReaderSystem>();
|
||||
_popupSystem = _entManager.System<PopupSystem>();
|
||||
|
||||
_buttonUnlockTime = _timing.CurTime + _buttonUnlockDelay;
|
||||
|
||||
// Assign button actions
|
||||
AnswerCallButton.OnPressed += args => { OnHolopadAnswerCallMessage(); };
|
||||
EndCallButton.OnPressed += args => { OnHolopadEndCallMessage(); };
|
||||
StartBroadcastButton.OnPressed += args => { OnHolopadStartBroadcastMessage(); };
|
||||
ActivateProjectorButton.OnPressed += args => { OnHolopadActivateProjectorMessage(); };
|
||||
RequestStationAiButton.OnPressed += args => { OnHolopadRequestStationAiMessage(); };
|
||||
|
||||
// XML formatting
|
||||
AnswerCallButton.AddStyleClass("ButtonAccept");
|
||||
EndCallButton.AddStyleClass("Caution");
|
||||
StartBroadcastButton.AddStyleClass("Caution");
|
||||
|
||||
HolopadContactListPanel.PanelOverride = new StyleBoxFlat
|
||||
{
|
||||
BackgroundColor = new Color(47, 47, 59) * Color.DarkGray,
|
||||
BorderColor = new Color(82, 82, 82), //new Color(70, 73, 102),
|
||||
BorderThickness = new Thickness(2),
|
||||
};
|
||||
|
||||
HolopadContactListHeaderPanel.PanelOverride = new StyleBoxFlat
|
||||
{
|
||||
BackgroundColor = new Color(82, 82, 82),
|
||||
};
|
||||
|
||||
EmergencyBroadcastText.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("holopad-window-emergency-broadcast-in-progress")));
|
||||
SubtitleText.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("holopad-window-subtitle")));
|
||||
OptionsText.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("holopad-window-options")));
|
||||
}
|
||||
|
||||
#region: Button actions
|
||||
|
||||
private void OnSendHolopadStartNewCallMessage(NetEntity receiver)
|
||||
{
|
||||
SendHolopadStartNewCallMessageAction?.Invoke(receiver);
|
||||
}
|
||||
|
||||
private void OnHolopadAnswerCallMessage()
|
||||
{
|
||||
SendHolopadAnswerCallMessageAction?.Invoke();
|
||||
}
|
||||
|
||||
private void OnHolopadEndCallMessage()
|
||||
{
|
||||
SendHolopadEndCallMessageAction?.Invoke();
|
||||
|
||||
if (_currentUiKey == HolopadUiKey.AiRequestWindow)
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnHolopadStartBroadcastMessage()
|
||||
{
|
||||
if (_playerManager.LocalSession?.AttachedEntity == null || _owner == null)
|
||||
return;
|
||||
|
||||
var player = _playerManager.LocalSession.AttachedEntity;
|
||||
|
||||
if (!_accessReaderSystem.IsAllowed(player.Value, _owner.Value))
|
||||
{
|
||||
_popupSystem.PopupClient(Loc.GetString("holopad-window-access-denied"), _owner.Value, player.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
SendHolopadStartBroadcastMessageAction?.Invoke();
|
||||
}
|
||||
|
||||
private void OnHolopadActivateProjectorMessage()
|
||||
{
|
||||
SendHolopadActivateProjectorMessageAction?.Invoke();
|
||||
}
|
||||
|
||||
private void OnHolopadRequestStationAiMessage()
|
||||
{
|
||||
SendHolopadRequestStationAiMessageAction?.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void SetState(EntityUid owner, HolopadUiKey uiKey)
|
||||
{
|
||||
_owner = owner;
|
||||
_currentUiKey = uiKey;
|
||||
|
||||
// Determines what UI containers are available to the user.
|
||||
// Components of these will be toggled on and off when
|
||||
// UpdateAppearance() is called
|
||||
|
||||
switch (uiKey)
|
||||
{
|
||||
case HolopadUiKey.InteractionWindow:
|
||||
RequestStationAiContainer.Visible = true;
|
||||
HolopadContactListContainer.Visible = true;
|
||||
StartBroadcastContainer.Visible = true;
|
||||
break;
|
||||
|
||||
case HolopadUiKey.InteractionWindowForAi:
|
||||
ActivateProjectorContainer.Visible = true;
|
||||
StartBroadcastContainer.Visible = true;
|
||||
break;
|
||||
|
||||
case HolopadUiKey.AiActionWindow:
|
||||
HolopadContactListContainer.Visible = true;
|
||||
StartBroadcastContainer.Visible = true;
|
||||
break;
|
||||
|
||||
case HolopadUiKey.AiRequestWindow:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateState(Dictionary<NetEntity, string> holopads)
|
||||
{
|
||||
if (_owner == null || !_entManager.TryGetComponent<TelephoneComponent>(_owner.Value, out var telephone))
|
||||
return;
|
||||
|
||||
// Caller ID text
|
||||
var callerId = _telephoneSystem.GetFormattedCallerIdForEntity(telephone.LastCallerId.Item1, telephone.LastCallerId.Item2, Color.LightGray, "Default", 11);
|
||||
|
||||
CallerIdText.SetMessage(FormattedMessage.FromMarkupOrThrow(callerId));
|
||||
LockOutIdText.SetMessage(FormattedMessage.FromMarkupOrThrow(callerId));
|
||||
|
||||
// Sort holopads alphabetically
|
||||
var holopadArray = holopads.ToArray();
|
||||
Array.Sort(holopadArray, AlphabeticalSort);
|
||||
|
||||
// Clear excess children from the contact list
|
||||
while (ContactsList.ChildCount > holopadArray.Length)
|
||||
ContactsList.RemoveChild(ContactsList.GetChild(ContactsList.ChildCount - 1));
|
||||
|
||||
// Make / update required children
|
||||
for (int i = 0; i < holopadArray.Length; i++)
|
||||
{
|
||||
var (netEntity, label) = holopadArray[i];
|
||||
|
||||
if (i >= ContactsList.ChildCount)
|
||||
{
|
||||
var newContactButton = new HolopadContactButton();
|
||||
newContactButton.OnPressed += args => { OnSendHolopadStartNewCallMessage(newContactButton.NetEntity); };
|
||||
|
||||
ContactsList.AddChild(newContactButton);
|
||||
}
|
||||
|
||||
var child = ContactsList.GetChild(i);
|
||||
|
||||
if (child is not HolopadContactButton)
|
||||
continue;
|
||||
|
||||
var contactButton = (HolopadContactButton)child;
|
||||
contactButton.UpdateValues(netEntity, label);
|
||||
}
|
||||
|
||||
// Update buttons
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (_owner == null || !_entManager.TryGetComponent<TelephoneComponent>(_owner.Value, out var telephone))
|
||||
return;
|
||||
|
||||
if (_owner == null || !_entManager.TryGetComponent<HolopadComponent>(_owner.Value, out var holopad))
|
||||
return;
|
||||
|
||||
var hasBroadcastAccess = !_holopadSystem.IsHolopadBroadcastOnCoolDown((_owner.Value, holopad));
|
||||
var localPlayer = _playerManager.LocalSession?.AttachedEntity;
|
||||
|
||||
ControlsLockOutContainer.Visible = _holopadSystem.IsHolopadControlLocked((_owner.Value, holopad), localPlayer);
|
||||
ControlsContainer.Visible = !ControlsLockOutContainer.Visible;
|
||||
|
||||
// Temporarily disable the interface buttons when the call state changes to prevent any misclicks
|
||||
if (_currentState != telephone.CurrentState)
|
||||
{
|
||||
_previousState = _currentState;
|
||||
_currentState = telephone.CurrentState;
|
||||
_buttonUnlockTime = _timing.CurTime + _buttonUnlockDelay;
|
||||
}
|
||||
|
||||
var lockButtons = _timing.CurTime < _buttonUnlockTime;
|
||||
|
||||
// Make / update required children
|
||||
foreach (var child in ContactsList.Children)
|
||||
{
|
||||
if (child is not HolopadContactButton)
|
||||
continue;
|
||||
|
||||
var contactButton = (HolopadContactButton)child;
|
||||
contactButton.Disabled = (_currentState != TelephoneState.Idle || lockButtons);
|
||||
}
|
||||
|
||||
// Update control text
|
||||
var cooldown = _holopadSystem.GetHolopadBroadcastCoolDown((_owner.Value, holopad));
|
||||
var cooldownString = $"{cooldown.Minutes:00}:{cooldown.Seconds:00}";
|
||||
|
||||
StartBroadcastButton.Text = _holopadSystem.IsHolopadBroadcastOnCoolDown((_owner.Value, holopad)) ?
|
||||
Loc.GetString("holopad-window-emergency-broadcast-with-countdown", ("countdown", cooldownString)) :
|
||||
Loc.GetString("holopad-window-emergency-broadcast");
|
||||
|
||||
var lockout = _holopadSystem.GetHolopadControlLockedPeriod((_owner.Value, holopad));
|
||||
var lockoutString = $"{lockout.Minutes:00}:{lockout.Seconds:00}";
|
||||
|
||||
LockOutCountDownText.Text = Loc.GetString("holopad-window-controls-unlock-countdown", ("countdown", lockoutString));
|
||||
|
||||
switch (_currentState)
|
||||
{
|
||||
case TelephoneState.Idle:
|
||||
CallStatusText.Text = Loc.GetString("holopad-window-no-calls-in-progress"); break;
|
||||
|
||||
case TelephoneState.Calling:
|
||||
CallStatusText.Text = Loc.GetString("holopad-window-outgoing-call"); break;
|
||||
|
||||
case TelephoneState.Ringing:
|
||||
CallStatusText.Text = (_currentUiKey == HolopadUiKey.AiRequestWindow) ?
|
||||
Loc.GetString("holopad-window-ai-request") : Loc.GetString("holopad-window-incoming-call"); break;
|
||||
|
||||
case TelephoneState.InCall:
|
||||
CallStatusText.Text = Loc.GetString("holopad-window-call-in-progress"); break;
|
||||
|
||||
case TelephoneState.EndingCall:
|
||||
if (_previousState == TelephoneState.Calling || _previousState == TelephoneState.Idle)
|
||||
CallStatusText.Text = Loc.GetString("holopad-window-call-rejected");
|
||||
else
|
||||
CallStatusText.Text = Loc.GetString("holopad-window-call-ending");
|
||||
break;
|
||||
}
|
||||
|
||||
// Update control disability
|
||||
AnswerCallButton.Disabled = (_currentState != TelephoneState.Ringing || lockButtons);
|
||||
EndCallButton.Disabled = (_currentState == TelephoneState.Idle || _currentState == TelephoneState.EndingCall || lockButtons);
|
||||
StartBroadcastButton.Disabled = (_currentState != TelephoneState.Idle || !hasBroadcastAccess || lockButtons);
|
||||
RequestStationAiButton.Disabled = (_currentState != TelephoneState.Idle || lockButtons);
|
||||
ActivateProjectorButton.Disabled = (_currentState != TelephoneState.Idle || lockButtons);
|
||||
|
||||
// Update control visibility
|
||||
FetchingAvailableHolopadsContainer.Visible = (ContactsList.ChildCount == 0);
|
||||
ActiveCallControlsContainer.Visible = (_currentState != TelephoneState.Idle || _currentUiKey == HolopadUiKey.AiRequestWindow);
|
||||
CallPlacementControlsContainer.Visible = !ActiveCallControlsContainer.Visible;
|
||||
CallerIdText.Visible = (_currentState == TelephoneState.Ringing);
|
||||
AnswerCallButton.Visible = (_currentState == TelephoneState.Ringing);
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
_updateTimer += args.DeltaSeconds;
|
||||
|
||||
if (_updateTimer >= UpdateTime)
|
||||
{
|
||||
_updateTimer -= UpdateTime;
|
||||
UpdateAppearance();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class HolopadContactButton : Button
|
||||
{
|
||||
public NetEntity NetEntity;
|
||||
|
||||
public HolopadContactButton()
|
||||
{
|
||||
HorizontalExpand = true;
|
||||
SetHeight = 32;
|
||||
Margin = new Thickness(0f, 1f, 0f, 1f);
|
||||
}
|
||||
|
||||
public void UpdateValues(NetEntity netEntity, string label)
|
||||
{
|
||||
NetEntity = netEntity;
|
||||
Text = Loc.GetString("holopad-window-contact-label", ("label", label));
|
||||
}
|
||||
}
|
||||
|
||||
private int AlphabeticalSort(KeyValuePair<NetEntity, string> x, KeyValuePair<NetEntity, string> y)
|
||||
{
|
||||
if (string.IsNullOrEmpty(x.Value))
|
||||
return -1;
|
||||
|
||||
if (string.IsNullOrEmpty(y.Value))
|
||||
return 1;
|
||||
|
||||
return x.Value.CompareTo(y.Value);
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,7 @@ namespace Content.Client.Stylesheets
|
||||
|
||||
public static readonly Color ButtonColorGoodDefault = Color.FromHex("#3E6C45");
|
||||
public static readonly Color ButtonColorGoodHovered = Color.FromHex("#31843E");
|
||||
public static readonly Color ButtonColorGoodDisabled = Color.FromHex("#164420");
|
||||
|
||||
//NavMap
|
||||
public static readonly Color PointRed = Color.FromHex("#B02E26");
|
||||
@@ -1499,6 +1500,20 @@ namespace Content.Client.Stylesheets
|
||||
|
||||
Element<Button>().Class("ButtonColorGreen").Pseudo(ContainerButton.StylePseudoClassHover)
|
||||
.Prop(Control.StylePropertyModulateSelf, ButtonColorGoodHovered),
|
||||
|
||||
// Accept button (merge with green button?) ---
|
||||
Element<Button>().Class("ButtonAccept")
|
||||
.Prop(Control.StylePropertyModulateSelf, ButtonColorGoodDefault),
|
||||
|
||||
Element<Button>().Class("ButtonAccept").Pseudo(ContainerButton.StylePseudoClassNormal)
|
||||
.Prop(Control.StylePropertyModulateSelf, ButtonColorGoodDefault),
|
||||
|
||||
Element<Button>().Class("ButtonAccept").Pseudo(ContainerButton.StylePseudoClassHover)
|
||||
.Prop(Control.StylePropertyModulateSelf, ButtonColorGoodHovered),
|
||||
|
||||
Element<Button>().Class("ButtonAccept").Pseudo(ContainerButton.StylePseudoClassDisabled)
|
||||
.Prop(Control.StylePropertyModulateSelf, ButtonColorGoodDisabled),
|
||||
|
||||
// ---
|
||||
|
||||
// Small Button ---
|
||||
|
||||
8
Content.Client/Telephone/TelephoneSystem.cs
Normal file
8
Content.Client/Telephone/TelephoneSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Telephone;
|
||||
|
||||
namespace Content.Client.Telephone;
|
||||
|
||||
public sealed class TelephoneSystem : SharedTelephoneSystem
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user