Files
tbd-station-14/Content.Client/GameObjects/Components/Observer/GhostComponent.cs
ike709 055059ab5c Chairbender Chat (#3794)
* #272 restructure and restyle chat line edit section

* #272 no arrow, actually change id on channel changer

* #272 nice round chat channel picker

* #272 add chat channel selection logic, and auto-select
when a prefix is entered

* #272 consistent width of chat channel btn

* #272 only show admin channel filter if asay perms

* #272 add tutorial info on chat prefixes

* #272 added chat filter button

* #272 added chat filter button

* #272 WIP on filter popup

* #272 fix filter popup pressed / unpressed logic

* #272 fix filter popup positioning and layout

* #272 WIP channel filter logic

* #272 WIP channel filter logic

* #272 WIP refactoring how chatbox / manager manages available filters and channels to send on

* #272 WIP implementing filtering UI / logic
and refactoring how chat UI is managed

* #272 fix various bugs with new chat filter / selector logic

* #272 remove outdated todos

* #272 WIP working chat window resize

* #272 bounded chatbox resizing

* #272 alertUI moves with resized chat

* #272 WIP making alertUI not be too large when changing size / UIScale

* #272 WIP fixing window / uiscale adjustment

* #272 WIP hacky approach for resizing, will try another approach

* #272 implement hacky approach for bounded chat resize

* #272 no resizing of lobby chat

* #272 WIP adding unread marker to chat filters

* #272 basic working unread chat message indicators

* #272 WIP adding horizontal channel selector items

* #272 horizontal channel selector popup

* #272 workaround for chat selector staying highlighted when right clicking it while toggled

* #272 workaround for chat selector staying highlighted when right clicking it while toggled

* #272 wip trying to add tests for chatbox

* #272 remove test, not really possible with current system

* #272 merge latest

* #272 merge latest

* #272 fix csproj changes

* It works if you disable the lobby

* Fixes lobby chat

* Adds more channel focusses

* Channel cycler

* Address review

* Address nitpicks

* Address more of the review

* Fix chat post-viewport

* Finalize review stuff

Co-authored-by: chairbender <kwhipke1@gmail.com>
Co-authored-by: ike709 <sparebytes@protonmail.com>
2021-04-20 16:39:39 -07:00

145 lines
4.8 KiB
C#

using System.Collections.Generic;
using Content.Client.Interfaces.Chat;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Observer;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Observer
{
[RegisterComponent]
public class GhostComponent : SharedGhostComponent
{
[Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IComponentManager _componentManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
public List<string> WarpNames = new();
public Dictionary<EntityUid,string> PlayerNames = new();
private GhostGui? _gui ;
[ViewVariables(VVAccess.ReadOnly)] public bool CanReturnToBody { get; private set; } = true;
private bool _isAttached;
public override void OnRemove()
{
base.OnRemove();
_gui?.Dispose();
// PlayerDetachedMsg might not fire due to deletion order so...
if (_isAttached)
{
SetGhostVisibility(false);
}
}
private void SetGhostVisibility(bool visibility)
{
foreach (var ghost in _componentManager.GetAllComponents(typeof(GhostComponent), true))
{
if (ghost.Owner.TryGetComponent(out SpriteComponent? component))
{
component.Visible = visibility;
}
}
}
public override void Initialize()
{
base.Initialize();
if (Owner.TryGetComponent(out SpriteComponent? component))
{
component.Visible =
_playerManager.LocalPlayer?.ControlledEntity?.HasComponent<GhostComponent>() ?? false;
}
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PlayerAttachedMsg _:
if (_gui == null)
{
_gui = new GhostGui(this);
}
else
{
_gui.Orphan();
}
_gameHud.HandsContainer.AddChild(_gui);
SetGhostVisibility(true);
_isAttached = true;
break;
case PlayerDetachedMsg _:
_gui!.Parent?.RemoveChild(_gui);
SetGhostVisibility(false);
_isAttached = false;
break;
}
}
public void SendReturnToBodyMessage() => SendNetworkMessage(new ReturnToBodyComponentMessage());
public void SendGhostWarpRequestMessage(string warpName) => SendNetworkMessage(new GhostWarpToLocationRequestMessage(warpName));
public void SendGhostWarpRequestMessage(EntityUid target) => SendNetworkMessage(new GhostWarpToTargetRequestMessage(target));
public void GhostRequestWarpPoint() => SendNetworkMessage(new GhostRequestWarpPointData());
public void GhostRequestPlayerNames() => SendNetworkMessage(new GhostRequestPlayerNameData());
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not GhostComponentState state) return;
CanReturnToBody = state.CanReturnToBody;
if (Owner == _playerManager.LocalPlayer!.ControlledEntity)
{
_gui?.Update();
}
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
switch (message)
{
case GhostReplyWarpPointData data:
WarpNames = new List<string>();
foreach (var names in data.WarpName)
{
WarpNames.Add(names);
}
break;
case GhostReplyPlayerNameData data:
PlayerNames = new Dictionary<EntityUid, string>();
foreach (var (key, value) in data.PlayerNames)
{
PlayerNames.Add(key,value);
}
break;
}
}
}
}