Hud refactor (#7202)
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Jezithyr <jmaster9999@gmail.com> Co-authored-by: Jezithyr <Jezithyr@gmail.com> Co-authored-by: Visne <39844191+Visne@users.noreply.github.com> Co-authored-by: wrexbe <wrexbe@protonmail.com> Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
This commit is contained in:
58
Content.Client/CharacterInfo/CharacterInfoSystem.cs
Normal file
58
Content.Client/CharacterInfo/CharacterInfoSystem.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Content.Shared.CharacterInfo;
|
||||
using Content.Shared.Objectives;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Player;
|
||||
|
||||
namespace Content.Client.CharacterInfo;
|
||||
|
||||
public sealed class CharacterInfoSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _players = default!;
|
||||
|
||||
public event Action<CharacterData>? OnCharacterUpdate;
|
||||
public event Action? OnCharacterDetached;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PlayerAttachSysMessage>(OnPlayerAttached);
|
||||
|
||||
SubscribeNetworkEvent<CharacterInfoEvent>(OnCharacterInfoEvent);
|
||||
}
|
||||
|
||||
public void RequestCharacterInfo()
|
||||
{
|
||||
var entity = _players.LocalPlayer?.ControlledEntity;
|
||||
if (entity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RaiseNetworkEvent(new RequestCharacterInfoEvent(entity.Value));
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(PlayerAttachSysMessage msg)
|
||||
{
|
||||
if (msg.AttachedEntity == default)
|
||||
{
|
||||
OnCharacterDetached?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
var sprite = CompOrNull<ISpriteComponent>(msg.EntityUid);
|
||||
var data = new CharacterData(msg.JobTitle, msg.Objectives, msg.Briefing, sprite, Name(msg.EntityUid));
|
||||
|
||||
OnCharacterUpdate?.Invoke(data);
|
||||
}
|
||||
|
||||
public readonly record struct CharacterData(
|
||||
string Job,
|
||||
Dictionary<string, List<ConditionInfo>> Objectives,
|
||||
string Briefing,
|
||||
ISpriteComponent? Sprite,
|
||||
string EntityName
|
||||
);
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
using Content.Client.CharacterInterface;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
|
||||
namespace Content.Client.CharacterInfo.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class CharacterInfoComponent : Component, ICharacterUI
|
||||
{
|
||||
public CharacterInfoControl Control = default!;
|
||||
|
||||
public Control Scene { get; set; } = default!;
|
||||
public UIPriority Priority => UIPriority.Info;
|
||||
|
||||
public void Opened()
|
||||
{
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<CharacterInfoSystem>().RequestCharacterInfo(Owner);
|
||||
}
|
||||
|
||||
public sealed class CharacterInfoControl : BoxContainer
|
||||
{
|
||||
public SpriteView SpriteView { get; }
|
||||
public Label NameLabel { get; }
|
||||
public Label SubText { get; }
|
||||
|
||||
public BoxContainer ObjectivesContainer { get; }
|
||||
|
||||
public CharacterInfoControl()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
|
||||
AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
(SpriteView = new SpriteView { OverrideDirection = Direction.South, Scale = (2,2)}),
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
VerticalAlignment = VAlignment.Top,
|
||||
Children =
|
||||
{
|
||||
(NameLabel = new Label()),
|
||||
(SubText = new Label
|
||||
{
|
||||
VerticalAlignment = VAlignment.Top,
|
||||
StyleClasses = {StyleBase.StyleClassLabelSubText},
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddChild(new Label
|
||||
{
|
||||
Text = Loc.GetString("character-info-objectives-label"),
|
||||
HorizontalAlignment = HAlignment.Center
|
||||
});
|
||||
ObjectivesContainer = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical
|
||||
};
|
||||
AddChild(ObjectivesContainer);
|
||||
|
||||
AddChild(new Placeholder
|
||||
{
|
||||
PlaceholderText = Loc.GetString("character-info-roles-antagonist-text")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.CharacterInfo;
|
||||
using Content.Shared.Objectives;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.Utility;
|
||||
|
||||
namespace Content.Client.CharacterInfo.Components;
|
||||
|
||||
public sealed class CharacterInfoSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SpriteSystem _sprite = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<CharacterInfoEvent>(OnCharacterInfoEvent);
|
||||
SubscribeLocalEvent<CharacterInfoComponent, ComponentAdd>(OnComponentAdd);
|
||||
}
|
||||
|
||||
private void OnComponentAdd(EntityUid uid, CharacterInfoComponent component, ComponentAdd args)
|
||||
{
|
||||
component.Scene = component.Control = new CharacterInfoComponent.CharacterInfoControl();
|
||||
}
|
||||
|
||||
public void RequestCharacterInfo(EntityUid entityUid)
|
||||
{
|
||||
RaiseNetworkEvent(new RequestCharacterInfoEvent(entityUid));
|
||||
}
|
||||
|
||||
private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(msg.EntityUid, out CharacterInfoComponent? characterInfoComponent))
|
||||
return;
|
||||
|
||||
UpdateUI(characterInfoComponent, msg.JobTitle, msg.Objectives, msg.Briefing);
|
||||
if (EntityManager.TryGetComponent(msg.EntityUid, out ISpriteComponent? spriteComponent))
|
||||
{
|
||||
characterInfoComponent.Control.SpriteView.Sprite = spriteComponent;
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetComponent(msg.EntityUid, out MetaDataComponent? metadata))
|
||||
return;
|
||||
characterInfoComponent.Control.NameLabel.Text = metadata.EntityName;
|
||||
}
|
||||
|
||||
private void UpdateUI(CharacterInfoComponent comp, string jobTitle, Dictionary<string, List<ConditionInfo>> objectives, string briefing)
|
||||
{
|
||||
comp.Control.SubText.Text = jobTitle;
|
||||
|
||||
comp.Control.ObjectivesContainer.RemoveAllChildren();
|
||||
foreach (var (groupId, objectiveConditions) in objectives)
|
||||
{
|
||||
var vbox = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Modulate = Color.Gray
|
||||
};
|
||||
|
||||
vbox.AddChild(new Label
|
||||
{
|
||||
Text = groupId,
|
||||
Modulate = Color.LightSkyBlue
|
||||
});
|
||||
|
||||
foreach (var objectiveCondition in objectiveConditions)
|
||||
{
|
||||
var hbox = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
||||
};
|
||||
hbox.AddChild(new ProgressTextureRect
|
||||
{
|
||||
Texture = _sprite.Frame0(objectiveCondition.SpriteSpecifier),
|
||||
Progress = objectiveCondition.Progress,
|
||||
VerticalAlignment = Control.VAlignment.Center
|
||||
});
|
||||
hbox.AddChild(new Control
|
||||
{
|
||||
MinSize = (10,0)
|
||||
});
|
||||
hbox.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
new Label{Text = objectiveCondition.Title},
|
||||
new Label{Text = objectiveCondition.Description}
|
||||
}
|
||||
}
|
||||
);
|
||||
vbox.AddChild(hbox);
|
||||
}
|
||||
var briefinghBox = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
||||
};
|
||||
|
||||
briefinghBox.AddChild(new Label
|
||||
{
|
||||
Text = briefing,
|
||||
Modulate = Color.Yellow
|
||||
});
|
||||
|
||||
vbox.AddChild(briefinghBox);
|
||||
comp.Control.ObjectivesContainer.AddChild(vbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Content.Client.CharacterInterface;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.CharacterInfo.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface which is gathered to assemble the character window from multiple components
|
||||
/// </summary>
|
||||
public interface ICharacterUI
|
||||
{
|
||||
/// <summary>
|
||||
/// The control which holds the character user interface to be included in the window
|
||||
/// </summary>
|
||||
Control Scene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The order it will appear in the character UI, higher is lower
|
||||
/// </summary>
|
||||
UIPriority Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the CharacterUi was opened
|
||||
/// </summary>
|
||||
void Opened(){}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user