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 Content.Shared.Objectives;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Client.UserInterface;
namespace Content.Client.CharacterInfo; namespace Content.Client.CharacterInfo;
@@ -43,10 +44,16 @@ public sealed class CharacterInfoSystem : EntitySystem
private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args) private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args)
{ {
var data = new CharacterData(msg.EntityUid, msg.JobTitle, msg.Objectives, msg.Briefing, Name(msg.EntityUid)); var data = new CharacterData(msg.EntityUid, msg.JobTitle, msg.Objectives, msg.Briefing, Name(msg.EntityUid));
OnCharacterUpdate?.Invoke(data); 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( public readonly record struct CharacterData(
EntityUid Entity, EntityUid Entity,
string Job, string Job,
@@ -54,4 +61,15 @@ public sealed class CharacterInfoSystem : EntitySystem
string Briefing, string Briefing,
string EntityName 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.CharacterInfo;
using Content.Client.Gameplay; using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls; 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.Client.UserInterface.Systems.Objectives.Controls;
using Content.Shared.Input; using Content.Shared.Input;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers; using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Input.Binding; using Robust.Shared.Input.Binding;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using static Content.Client.CharacterInfo.CharacterInfoSystem; 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> public sealed class CharacterUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>, IOnSystemChanged<CharacterInfoSystem>
{ {
[UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!; [UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!;
[UISystemDependency] private readonly SpriteSystem _sprite = default!;
private CharacterWindow? _window; private CharacterWindow? _window;
private MenuButton? CharacterButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.CharacterButton; 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; var (entity, job, objectives, briefing, entityName) = data;
_window.SpriteView.SetEntity(entity);
_window.NameLabel.Text = entityName;
_window.SubText.Text = job; _window.SubText.Text = job;
_window.Objectives.RemoveAllChildren(); _window.Objectives.RemoveAllChildren();
@@ -123,7 +127,7 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
foreach (var condition in conditions) foreach (var condition in conditions)
{ {
var conditionControl = new ObjectiveConditionsControl(); var conditionControl = new ObjectiveConditionsControl();
conditionControl.ProgressTexture.Texture = condition.SpriteSpecifier.Frame0(); conditionControl.ProgressTexture.Texture = _sprite.Frame0(condition.SpriteSpecifier);
conditionControl.ProgressTexture.Progress = condition.Progress; conditionControl.ProgressTexture.Progress = condition.Progress;
var titleMessage = new FormattedMessage(); var titleMessage = new FormattedMessage();
var descriptionMessage = new FormattedMessage(); var descriptionMessage = new FormattedMessage();
@@ -143,8 +147,13 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
_window.Objectives.AddChild(objectiveControl); _window.Objectives.AddChild(objectiveControl);
} }
_window.SpriteView.SetEntity(entity); var controls = _characterInfo.GetCharacterInfoControls(entity);
_window.NameLabel.Text = entityName; foreach (var control in controls)
{
_window.Objectives.AddChild(control);
}
_window.RolePlaceholder.Visible = !controls.Any() && !objectives.Any();
} }
private void CharacterDetached() private void CharacterDetached()

View File

@@ -16,7 +16,7 @@
</BoxContainer> </BoxContainer>
<Label Text="{Loc 'character-info-objectives-label'}" HorizontalAlignment="Center"/> <Label Text="{Loc 'character-info-objectives-label'}" HorizontalAlignment="Center"/>
<BoxContainer Orientation="Vertical" Name="Objectives" Access="Public"/> <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> </BoxContainer>
</ScrollContainer> </ScrollContainer>
</windows:CharacterWindow> </windows:CharacterWindow>

View File

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