Add support for custom controls in the character menu (#19567)

This commit is contained in:
Nemanja
2023-08-27 04:24:24 -04:00
committed by GitHub
parent 70e0520a2c
commit 3e93e963b5
4 changed files with 35 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Client.CharacterInfo;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
@@ -6,10 +7,10 @@ using Content.Client.UserInterface.Systems.Character.Windows;
using Content.Client.UserInterface.Systems.Objectives.Controls;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Input.Binding;
using Robust.Shared.Utility;
using static Content.Client.CharacterInfo.CharacterInfoSystem;
@@ -21,6 +22,7 @@ namespace Content.Client.UserInterface.Systems.Character;
public sealed class CharacterUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>, IOnSystemChanged<CharacterInfoSystem>
{
[UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!;
[UISystemDependency] private readonly SpriteSystem _sprite = default!;
private CharacterWindow? _window;
private MenuButton? CharacterButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.CharacterButton;
@@ -103,6 +105,8 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
var (entity, job, objectives, briefing, entityName) = data;
_window.SpriteView.SetEntity(entity);
_window.NameLabel.Text = entityName;
_window.SubText.Text = job;
_window.Objectives.RemoveAllChildren();
@@ -123,7 +127,7 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
foreach (var condition in conditions)
{
var conditionControl = new ObjectiveConditionsControl();
conditionControl.ProgressTexture.Texture = condition.SpriteSpecifier.Frame0();
conditionControl.ProgressTexture.Texture = _sprite.Frame0(condition.SpriteSpecifier);
conditionControl.ProgressTexture.Progress = condition.Progress;
var titleMessage = new FormattedMessage();
var descriptionMessage = new FormattedMessage();
@@ -143,8 +147,13 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
_window.Objectives.AddChild(objectiveControl);
}
_window.SpriteView.SetEntity(entity);
_window.NameLabel.Text = entityName;
var controls = _characterInfo.GetCharacterInfoControls(entity);
foreach (var control in controls)
{
_window.Objectives.AddChild(control);
}
_window.RolePlaceholder.Visible = !controls.Any() && !objectives.Any();
}
private void CharacterDetached()