Add HUD button that displays your SSS role and allies (#1895)
* Add button that displays your SSS role and allies * Capitalize button name * Add cases for 0, 1 and invalid number of allies * Make the ally syncing system saner
This commit is contained in:
@@ -47,6 +47,7 @@ namespace Content.Client.UserInterface
|
||||
Action<bool> SandboxButtonToggled { get; set; }
|
||||
|
||||
Control HandsContainer { get; }
|
||||
Control SuspicionContainer { get; }
|
||||
Control InventoryQuickButtonContainer { get; }
|
||||
|
||||
bool CombatPanelVisible { get; set; }
|
||||
@@ -79,6 +80,7 @@ namespace Content.Client.UserInterface
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
|
||||
public Control HandsContainer { get; private set; }
|
||||
public Control SuspicionContainer { get; private set; }
|
||||
public Control InventoryQuickButtonContainer { get; private set; }
|
||||
|
||||
public bool CombatPanelVisible
|
||||
@@ -242,6 +244,17 @@ namespace Content.Client.UserInterface
|
||||
LayoutContainer.SetAnchorAndMarginPreset(HandsContainer, LayoutContainer.LayoutPreset.CenterBottom);
|
||||
LayoutContainer.SetGrowHorizontal(HandsContainer, LayoutContainer.GrowDirection.Both);
|
||||
LayoutContainer.SetGrowVertical(HandsContainer, LayoutContainer.GrowDirection.Begin);
|
||||
|
||||
SuspicionContainer = new MarginContainer
|
||||
{
|
||||
SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter
|
||||
};
|
||||
|
||||
RootControl.AddChild(SuspicionContainer);
|
||||
|
||||
LayoutContainer.SetAnchorAndMarginPreset(SuspicionContainer, LayoutContainer.LayoutPreset.BottomLeft, margin: 10);
|
||||
LayoutContainer.SetGrowHorizontal(SuspicionContainer, LayoutContainer.GrowDirection.End);
|
||||
LayoutContainer.SetGrowVertical(SuspicionContainer, LayoutContainer.GrowDirection.Begin);
|
||||
}
|
||||
|
||||
private void ButtonTutorialOnOnToggled()
|
||||
|
||||
116
Content.Client/UserInterface/Suspicion/SuspicionGui.cs
Normal file
116
Content.Client/UserInterface/Suspicion/SuspicionGui.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Content.Client.GameObjects.Components.Suspicion;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
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.UserInterface.Suspicion
|
||||
{
|
||||
public class SuspicionGui : Control
|
||||
{
|
||||
#pragma warning disable 0649
|
||||
[Dependency] private readonly IPlayerManager _playerManager;
|
||||
#pragma warning restore 0649
|
||||
|
||||
private readonly VBoxContainer _container;
|
||||
private readonly Button _roleButton;
|
||||
|
||||
private string _previousRoleName;
|
||||
private bool _previousAntagonist;
|
||||
|
||||
public SuspicionGui()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
AddChild(_container = new VBoxContainer
|
||||
{
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
(_roleButton = new Button
|
||||
{
|
||||
Name = "Suspicion Role Button"
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
_roleButton.CustomMinimumSize = (200, 60);
|
||||
_roleButton.OnPressed += RoleButtonPressed;
|
||||
}
|
||||
|
||||
private void RoleButtonPressed(ButtonEventArgs obj)
|
||||
{
|
||||
if (!TryGetComponent(out var role))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!role.Antagonist ?? false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var allies = string.Join(", ", role.Allies);
|
||||
var message = role.Allies.Count switch
|
||||
{
|
||||
0 => Loc.GetString("You have no allies"),
|
||||
1 => Loc.GetString("Your ally is {0}", allies),
|
||||
var n when n > 2 => Loc.GetString("Your allies are {0}", allies),
|
||||
_ => throw new ArgumentException($"Invalid number of allies: {role.Allies.Count}")
|
||||
};
|
||||
|
||||
role.Owner.PopupMessage(role.Owner, message);
|
||||
}
|
||||
|
||||
private bool TryGetComponent(out SuspicionRoleComponent suspicion)
|
||||
{
|
||||
suspicion = default;
|
||||
|
||||
return _playerManager?.LocalPlayer?.ControlledEntity?.TryGetComponent(out suspicion) == true;
|
||||
}
|
||||
|
||||
public void UpdateLabel()
|
||||
{
|
||||
if (!TryGetComponent(out var suspicion))
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (suspicion.Role == null || suspicion.Antagonist == null)
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user