Fix suspicion round end timer, actually show it.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Client.GameObjects.EntitySystems
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Content.Client/UserInterface/Suspicion/SuspicionGui.xaml
Normal file
8
Content.Client/UserInterface/Suspicion/SuspicionGui.xaml
Normal file
@@ -0,0 +1,8 @@
|
||||
<ui:Control xmlns:uic="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client"
|
||||
xmlns:ui="clr-namespace:Robust.Client.UserInterface;assembly=Robust.Client">
|
||||
<uic:VBoxContainer SeparationOverride="0">
|
||||
<uic:Button Name="RoleButton">
|
||||
<uic:Label Name="TimerLabel" SizeFlagsHorizontal="ShrinkEnd" SizeFlagsVertical="ShrinkEnd" />
|
||||
</uic:Button>
|
||||
</uic:VBoxContainer>
|
||||
</ui:Control>
|
||||
@@ -1,48 +1,41 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.Components.Suspicion;
|
||||
using Content.Client.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Client.UserInterface.Suspicion
|
||||
{
|
||||
public class SuspicionGui : Control
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class SuspicionGui : Control
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private readonly VBoxContainer _container;
|
||||
private readonly Button _roleButton;
|
||||
|
||||
private string _previousRoleName;
|
||||
private string? _previousRoleName;
|
||||
private bool _previousAntagonist;
|
||||
|
||||
public SuspicionGui()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
AddChild(_container = new VBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
(_roleButton = new Button
|
||||
{
|
||||
Name = "Suspicion Role Button"
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
_roleButton.CustomMinimumSize = (200, 60);
|
||||
_roleButton.OnPressed += RoleButtonPressed;
|
||||
RoleButton.OnPressed += RoleButtonPressed;
|
||||
RoleButton.CustomMinimumSize = (200, 60);
|
||||
}
|
||||
|
||||
private void RoleButtonPressed(ButtonEventArgs obj)
|
||||
@@ -67,11 +60,15 @@ namespace Content.Client.UserInterface.Suspicion
|
||||
role.Owner.PopupMessage(message);
|
||||
}
|
||||
|
||||
private bool TryGetComponent(out SuspicionRoleComponent suspicion)
|
||||
private bool TryGetComponent([NotNullWhen(true)] out SuspicionRoleComponent? suspicion)
|
||||
{
|
||||
suspicion = default;
|
||||
if (_playerManager.LocalPlayer?.ControlledEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _playerManager?.LocalPlayer?.ControlledEntity?.TryGetComponent(out suspicion) == true;
|
||||
return _playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out suspicion);
|
||||
}
|
||||
|
||||
public void UpdateLabel()
|
||||
@@ -88,6 +85,18 @@ namespace Content.Client.UserInterface.Suspicion
|
||||
return;
|
||||
}
|
||||
|
||||
var endTime = EntitySystem.Get<SuspicionEndTimerSystem>().EndTime;
|
||||
if (endTime == null)
|
||||
{
|
||||
TimerLabel.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var diff = _timing.CurTime - endTime.Value;
|
||||
TimerLabel.Visible = true;
|
||||
TimerLabel.Text = $"{diff:mm\\:ss}";
|
||||
}
|
||||
|
||||
if (_previousRoleName == suspicion.Role && _previousAntagonist == suspicion.Antagonist)
|
||||
{
|
||||
return;
|
||||
@@ -99,8 +108,8 @@ namespace Content.Client.UserInterface.Suspicion
|
||||
var buttonText = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(_previousRoleName);
|
||||
buttonText = Loc.GetString(buttonText);
|
||||
|
||||
_roleButton.Text = buttonText;
|
||||
_roleButton.ModulateSelfOverride = _previousAntagonist ? Color.Red : Color.Green;
|
||||
RoleButton.Text = buttonText;
|
||||
RoleButton.ModulateSelfOverride = _previousAntagonist ? Color.Red : Color.Green;
|
||||
|
||||
Visible = true;
|
||||
}
|
||||
Reference in New Issue
Block a user