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

@@ -2,6 +2,7 @@
using Content.Shared.Objectives;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface;
namespace Content.Client.CharacterInfo;
@@ -43,10 +44,16 @@ public sealed class CharacterInfoSystem : EntitySystem
private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args)
{
var data = new CharacterData(msg.EntityUid, msg.JobTitle, msg.Objectives, msg.Briefing, Name(msg.EntityUid));
OnCharacterUpdate?.Invoke(data);
}
public List<Control> GetCharacterInfoControls(EntityUid uid)
{
var ev = new GetCharacterInfoControlsEvent(uid);
RaiseLocalEvent(uid, ref ev, true);
return ev.Controls;
}
public readonly record struct CharacterData(
EntityUid Entity,
string Job,
@@ -54,4 +61,15 @@ public sealed class CharacterInfoSystem : EntitySystem
string Briefing,
string EntityName
);
/// <summary>
/// Event raised to get additional controls to display in the character info menu.
/// </summary>
[ByRefEvent]
public readonly record struct GetCharacterInfoControlsEvent(EntityUid Entity)
{
public readonly List<Control> Controls = new();
public readonly EntityUid Entity = Entity;
}
}

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()

View File

@@ -16,7 +16,7 @@
</BoxContainer>
<Label Text="{Loc 'character-info-objectives-label'}" HorizontalAlignment="Center"/>
<BoxContainer Orientation="Vertical" Name="Objectives" Access="Public"/>
<cc:Placeholder PlaceholderText="{Loc 'character-info-roles-antagonist-text'}"/>
<cc:Placeholder Name="RolePlaceholder" Access="Public" PlaceholderText="{Loc 'character-info-roles-antagonist-text'}"/>
</BoxContainer>
</ScrollContainer>
</windows:CharacterWindow>

View File

@@ -2,7 +2,6 @@
using Content.Server.Roles;
using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
using Robust.Shared.Player;
namespace Content.Server.CharacterInfo;
@@ -25,8 +24,8 @@ public sealed class CharacterInfoSystem : EntitySystem
var conditions = new Dictionary<string, List<ConditionInfo>>();
var jobTitle = "No Profession";
var briefing = "!!ERROR: No Briefing!!"; //should never show on the UI unless there's a bug
if (EntityManager.TryGetComponent(entity, out MindContainerComponent? mindContainerComponent) && mindContainerComponent.Mind != null)
var briefing = "!!ERROR: No Briefing!!"; //should never show on the UI unless there's an issue
if (TryComp<MindContainerComponent>(entity, out var mindContainerComponent) && mindContainerComponent.Mind != null)
{
var mind = mindContainerComponent.Mind;