Re-organize all projects (#4166)
This commit is contained in:
23
Content.Client/Suspicion/SuspicionEndTimerSystem.cs
Normal file
23
Content.Client/Suspicion/SuspicionEndTimerSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using Content.Shared.Suspicion;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Suspicion
|
||||
{
|
||||
public sealed class SuspicionEndTimerSystem : EntitySystem
|
||||
{
|
||||
public TimeSpan? EndTime { get; private set; }
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<SuspicionMessages.SetSuspicionEndTimerMessage>(RxTimerMessage);
|
||||
}
|
||||
|
||||
private void RxTimerMessage(SuspicionMessages.SetSuspicionEndTimerMessage ev)
|
||||
{
|
||||
EndTime = ev.EndTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Content.Client/Suspicion/SuspicionGui.xaml
Normal file
7
Content.Client/Suspicion/SuspicionGui.xaml
Normal file
@@ -0,0 +1,7 @@
|
||||
<Control xmlns="https://spacestation14.io">
|
||||
<VBoxContainer SeparationOverride="0">
|
||||
<Button Name="RoleButton">
|
||||
<Label Name="TimerLabel" SizeFlagsHorizontal="ShrinkEnd" SizeFlagsVertical="ShrinkEnd" />
|
||||
</Button>
|
||||
</VBoxContainer>
|
||||
</Control>
|
||||
124
Content.Client/Suspicion/SuspicionGui.xaml.cs
Normal file
124
Content.Client/Suspicion/SuspicionGui.xaml.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Content.Shared.Notification;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.Suspicion
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class SuspicionGui : Control
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private string? _previousRoleName;
|
||||
private bool _previousAntagonist;
|
||||
|
||||
public SuspicionGui()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
RoleButton.OnPressed += RoleButtonPressed;
|
||||
RoleButton.MinSize = (200, 60);
|
||||
}
|
||||
|
||||
private void RoleButtonPressed(ButtonEventArgs obj)
|
||||
{
|
||||
if (!TryGetComponent(out var role))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!role.Antagonist ?? false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var allies = string.Join(", ", role.Allies.Select(tuple => tuple.name));
|
||||
|
||||
role.Owner.PopupMessage(
|
||||
Loc.GetString(
|
||||
"suspicion-ally-count-display",
|
||||
("allyCount", role.Allies.Count),
|
||||
("allyNames", allies)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private bool TryGetComponent([NotNullWhen(true)] out SuspicionRoleComponent? suspicion)
|
||||
{
|
||||
suspicion = default;
|
||||
if (_playerManager.LocalPlayer?.ControlledEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out suspicion);
|
||||
}
|
||||
|
||||
public void UpdateLabel()
|
||||
{
|
||||
if (!TryGetComponent(out var suspicion))
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (suspicion.Role == null || suspicion.Antagonist == null)
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var endTime = EntitySystem.Get<SuspicionEndTimerSystem>().EndTime;
|
||||
if (endTime == null)
|
||||
{
|
||||
TimerLabel.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var diff = endTime.Value - _timing.CurTime;
|
||||
if (diff < TimeSpan.Zero)
|
||||
{
|
||||
diff = TimeSpan.Zero;
|
||||
}
|
||||
TimerLabel.Visible = true;
|
||||
TimerLabel.Text = $"{diff:mm\\:ss}";
|
||||
}
|
||||
|
||||
if (_previousRoleName == suspicion.Role && _previousAntagonist == suspicion.Antagonist)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_previousRoleName = suspicion.Role;
|
||||
_previousAntagonist = suspicion.Antagonist.Value;
|
||||
|
||||
var buttonText = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(_previousRoleName);
|
||||
buttonText = Loc.GetString(buttonText);
|
||||
|
||||
RoleButton.Text = buttonText;
|
||||
RoleButton.ModulateSelfOverride = _previousAntagonist ? Color.Red : Color.Green;
|
||||
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
UpdateLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
145
Content.Client/Suspicion/SuspicionRoleComponent.cs
Normal file
145
Content.Client/Suspicion/SuspicionRoleComponent.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.HUD;
|
||||
using Content.Shared.Suspicion;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Suspicion
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SuspicionRoleComponent : SharedSuspicionRoleComponent
|
||||
{
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
|
||||
private SuspicionGui? _gui;
|
||||
private string? _role;
|
||||
private bool? _antagonist;
|
||||
private bool _overlayActive;
|
||||
|
||||
public string? Role
|
||||
{
|
||||
get => _role;
|
||||
set
|
||||
{
|
||||
if (_role == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_role = value;
|
||||
_gui?.UpdateLabel();
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public bool? Antagonist
|
||||
{
|
||||
get => _antagonist;
|
||||
set
|
||||
{
|
||||
if (_antagonist == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_antagonist = value;
|
||||
_gui?.UpdateLabel();
|
||||
|
||||
if (value ?? false)
|
||||
{
|
||||
AddTraitorOverlay();
|
||||
}
|
||||
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public List<(string name, EntityUid uid)> Allies { get; } = new();
|
||||
|
||||
private void AddTraitorOverlay()
|
||||
{
|
||||
if (_overlayManager.HasOverlay<TraitorOverlay>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_overlayActive = true;
|
||||
var overlay = new TraitorOverlay(Owner.EntityManager, _resourceCache, _eyeManager);
|
||||
_overlayManager.AddOverlay(overlay);
|
||||
}
|
||||
|
||||
private void RemoveTraitorOverlay()
|
||||
{
|
||||
if (!_overlayActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_overlayManager.RemoveOverlay<TraitorOverlay>();
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not SuspicionRoleComponentState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Role = state.Role;
|
||||
Antagonist = state.Antagonist;
|
||||
Allies.Clear();
|
||||
Allies.AddRange(state.Allies);
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case PlayerAttachedMsg _:
|
||||
if (_gui == null)
|
||||
{
|
||||
_gui = new SuspicionGui();
|
||||
}
|
||||
else
|
||||
{
|
||||
_gui.Parent?.RemoveChild(_gui);
|
||||
}
|
||||
|
||||
_gameHud.SuspicionContainer.AddChild(_gui);
|
||||
_gui.UpdateLabel();
|
||||
|
||||
if (_antagonist ?? false)
|
||||
{
|
||||
AddTraitorOverlay();
|
||||
}
|
||||
|
||||
break;
|
||||
case PlayerDetachedMsg _:
|
||||
_gui?.Parent?.RemoveChild(_gui);
|
||||
RemoveTraitorOverlay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
_gui?.Dispose();
|
||||
RemoveTraitorOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
100
Content.Client/Suspicion/TraitorOverlay.cs
Normal file
100
Content.Client/Suspicion/TraitorOverlay.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Content.Shared.Examine;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Client.Suspicion
|
||||
{
|
||||
public class TraitorOverlay : Overlay
|
||||
{
|
||||
private readonly IEntityManager _entityManager;
|
||||
private readonly IEyeManager _eyeManager;
|
||||
private readonly IPlayerManager _playerManager;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
||||
private readonly Font _font;
|
||||
|
||||
private readonly string _traitorText = Loc.GetString("Traitor");
|
||||
|
||||
public TraitorOverlay(
|
||||
IEntityManager entityManager,
|
||||
IResourceCache resourceCache,
|
||||
IEyeManager eyeManager)
|
||||
{
|
||||
_playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
|
||||
_entityManager = entityManager;
|
||||
_eyeManager = eyeManager;
|
||||
|
||||
_font = new VectorFont(resourceCache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
var viewport = _eyeManager.GetWorldViewport();
|
||||
|
||||
var ent = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
if (ent == null || ent.TryGetComponent(out SuspicionRoleComponent? sus) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var (_, uid) in sus.Allies)
|
||||
{
|
||||
// Otherwise the entity can not exist yet
|
||||
if (!_entityManager.TryGetEntity(uid, out var ally))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ally.TryGetComponent(out IPhysBody? physics))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ExamineSystemShared.InRangeUnOccluded(ent.Transform.MapPosition, ally.Transform.MapPosition, 15,
|
||||
entity => entity == ent || entity == ally))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// all entities have a TransformComponent
|
||||
var transform = physics.Owner.Transform;
|
||||
|
||||
// if not on the same map, continue
|
||||
if (transform.MapID != _eyeManager.CurrentMap || !transform.IsMapTransform)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var worldBox = physics.GetWorldAABB();
|
||||
|
||||
// if not on screen, or too small, continue
|
||||
if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var screenCoordinates = args.ViewportControl!.WorldToScreen(physics.GetWorldAABB().TopLeft + (0, 0.5f));
|
||||
DrawString(args.ScreenHandle, _font, screenCoordinates, _traitorText, Color.OrangeRed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawString(DrawingHandleScreen handle, Font font, Vector2 pos, string str, Color color)
|
||||
{
|
||||
var baseLine = new Vector2(pos.X, font.GetAscent(1) + pos.Y);
|
||||
|
||||
foreach (var rune in str.EnumerateRunes())
|
||||
{
|
||||
var advance = font.DrawChar(handle, rune, baseLine, 1, color);
|
||||
baseLine += new Vector2(advance, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user