ECS characterinfo (#5669)

This commit is contained in:
ShadowCommander
2021-12-11 15:12:55 -08:00
committed by GitHub
parent 237a90cd48
commit 703c23d8a5
9 changed files with 272 additions and 306 deletions

View File

@@ -1,67 +1,31 @@
using System;
using Content.Client.CharacterInterface;
using Content.Client.HUD.UI;
using Content.Client.Stylesheets;
using Content.Shared.CharacterInfo;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Players;
namespace Content.Client.CharacterInfo.Components
{
[RegisterComponent]
public sealed class CharacterInfoComponent : SharedCharacterInfoComponent, ICharacterUI
public sealed class CharacterInfoComponent : Component, ICharacterUI
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
public override string Name => "CharacterInfo";
private CharacterInfoControl _control = default!;
public CharacterInfoControl Control = default!;
public Control Scene { get; private set; } = default!;
public Control Scene { get; set; } = default!;
public UIPriority Priority => UIPriority.Info;
protected override void OnAdd()
{
base.OnAdd();
Scene = _control = new CharacterInfoControl(_resourceCache);
}
public void Opened()
{
#pragma warning disable 618
SendNetworkMessage(new RequestCharacterInfoMessage());
#pragma warning restore 618
EntitySystem.Get<CharacterInfoSystem>().RequestCharacterInfo(Owner);
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
switch (message)
{
case CharacterInfoMessage characterInfoMessage:
_control.UpdateUI(characterInfoMessage);
var entityManager = IoCManager.Resolve<IEntityManager>();
if (entityManager.TryGetComponent(Owner, out ISpriteComponent? spriteComponent))
{
_control.SpriteView.Sprite = spriteComponent;
}
_control.NameLabel.Text = entityManager.GetComponent<MetaDataComponent>(Owner).EntityName;
break;
}
}
private sealed class CharacterInfoControl : BoxContainer
public sealed class CharacterInfoControl : BoxContainer
{
public SpriteView SpriteView { get; }
public Label NameLabel { get; }
@@ -69,7 +33,7 @@ namespace Content.Client.CharacterInfo.Components
public BoxContainer ObjectivesContainer { get; }
public CharacterInfoControl(IResourceCache resourceCache)
public CharacterInfoControl()
{
IoCManager.InjectDependencies(this);
@@ -91,7 +55,7 @@ namespace Content.Client.CharacterInfo.Components
(SubText = new Label
{
VerticalAlignment = VAlignment.Top,
StyleClasses = {StyleNano.StyleClassLabelSubText},
StyleClasses = {StyleBase.StyleClassLabelSubText},
})
}
@@ -115,57 +79,6 @@ namespace Content.Client.CharacterInfo.Components
PlaceholderText = Loc.GetString("character-info-roles-antagonist-text")
});
}
public void UpdateUI(CharacterInfoMessage characterInfoMessage)
{
SubText.Text = characterInfoMessage.JobTitle;
ObjectivesContainer.RemoveAllChildren();
foreach (var (groupId, objectiveConditions) in characterInfoMessage.Objectives)
{
var vbox = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Modulate = Color.Gray
};
vbox.AddChild(new Label
{
Text = groupId,
Modulate = Color.LightSkyBlue
});
foreach (var objectiveCondition in objectiveConditions)
{
var hbox = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal
};
hbox.AddChild(new ProgressTextureRect
{
Texture = objectiveCondition.SpriteSpecifier.Frame0(),
Progress = objectiveCondition.Progress,
VerticalAlignment = VAlignment.Center
});
hbox.AddChild(new Control
{
MinSize = (10,0)
});
hbox.AddChild(new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Children =
{
new Label{Text = objectiveCondition.Title},
new Label{Text = objectiveCondition.Description}
}
}
);
vbox.AddChild(hbox);
}
ObjectivesContainer.AddChild(vbox);
}
}
}
}
}