using System.Linq; using System.Numerics; using Content.Client.Message; using Content.Client.UserInterface.Controls; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; namespace Content.Client._White.CharacterExamine; [GenerateTypedNameReferences] public sealed partial class CharacterInformationWindow : FancyWindow { private readonly IEntityManager _entity; // ReSharper disable once InconsistentNaming private GridContainer _sprites => SpriteContainer; // ReSharper disable once InconsistentNaming private RichTextLabel _name => Name; // ReSharper disable once InconsistentNaming private RichTextLabel _job => Job; // ReSharper disable once InconsistentNaming private RichTextLabel _flavor => FlavorText; public CharacterInformationWindow() { RobustXamlLoader.Load(this); _entity = IoCManager.Resolve(); ResetUi(); } /// /// Placeholder entries /// public void ResetUi() { _sprites.RemoveAllChildren(); var unknown = Loc.GetString("generic-unknown"); // Capitalize the first letter of each word (Title Case) unknown = string.Join(" ", unknown.Split(' ').Select(s => OopsConcat(char.ToUpper(s[0]).ToString(), s[1..]))); _name.SetMarkup(unknown); _job.SetMarkup(unknown); _flavor.SetMarkup(Loc.GetString("character-information-ui-flavor-text-placeholder")); } /// /// Updates the UI to show all relevant information about the entity /// /// The entity to become informed about /// The name of the examined entity, taken from their ID /// The job of the examined entity, taken from their ID /// The flavor text of the examined entity public void UpdateUi(EntityUid examined, string? name = null, string? job = null, string? flavorText = null) { ResetUi(); // Fill in the omnidirectional sprite views FillSprites(examined); // Fill in the name and job if (!string.IsNullOrEmpty(name)) _name.SetMarkup(name); if (!string.IsNullOrEmpty(job)) _job.SetMarkup(job); // Fill in the flavor text if (!string.IsNullOrEmpty(flavorText)) _flavor.SetMessage(flavorText); } /// /// Fills the sprite views with the sprite from the sprite component /// /// /// Stupid, redefines the sprite view 4 times, can't find another way to do this /// /// Sprite component to use private void FillSprites(EntityUid uid) { _sprites.AddChild(new SpriteView(uid, _entity) { Scale = new Vector2(4, 4), OverrideDirection = Direction.South, Margin = new Thickness(0, 0, 8, 8), }); _sprites.AddChild(new SpriteView(uid, _entity) { Scale = new Vector2(4, 4), OverrideDirection = Direction.North, Margin = new Thickness(8, 0, 0, 8), }); _sprites.AddChild(new SpriteView(uid, _entity) { Scale = new Vector2(4, 4), OverrideDirection = Direction.West, Margin = new Thickness(0, 8, 8, 0), }); _sprites.AddChild(new SpriteView(uid, _entity) { Scale = new Vector2(4, 4), OverrideDirection = Direction.East, Margin = new Thickness(8, 8, 0, 0), }); } private static string OopsConcat(string a, string b) { // This exists to prevent Roslyn being clever and compiling something that fails sandbox checks. return a + b; } }