[draft] examine tweaks (#161)

* deathgasps component, clothes examine system

* howered entities code w/o ui (#162)

Co-authored-by: Mona Hmiza <>

* lazy, mb later

* fuck

* wonderробукс bump

* trying to fix уамлики
This commit is contained in:
rhailrake
2023-06-13 19:33:50 +00:00
committed by Aviu00
parent 3fa30256ce
commit 518b730864
19 changed files with 1147 additions and 283 deletions

View File

@@ -387,7 +387,7 @@ namespace Content.Client.Examine
_lastExaminedEntity = entity;
}
private void CloseTooltip()
public void CloseTooltip()
{
if (_examineTooltipOpen != null)
{

View File

@@ -1,5 +1,12 @@
<Control Name="CFlavorText" xmlns="https://spacestation14.io">
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<TextEdit Name="CFlavorTextInput" Access="Public" MinSize="220 100" Margin="10" HorizontalExpand="True" VerticalExpand="True" />
</BoxContainer>
<Control Name="CFlavorText" xmlns="https://spacestation14.io"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
<PanelContainer>
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#242429" />
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<TextEdit Name="CFlavorTextInput" Access="Public" MinSize="220 100" HorizontalExpand="True" VerticalExpand="True" />
</BoxContainer>
</PanelContainer>
</Control>

View File

@@ -0,0 +1,151 @@
using System.Linq;
using Content.Client.Examine;
using Content.Client.Inventory;
using Content.Shared.Access.Components;
using Content.Shared.CCVar;
using Content.Shared.PDA;
using Content.Shared.Roles;
using Content.Shared.Verbs;
using Content.Shared.White.CharacterExamine;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client.White.CharacterExamine;
public sealed class CharacterInformationSystem : EntitySystem
{
[Dependency] private readonly ExamineSystem _examine = default!;
[Dependency] private readonly ClientInventorySystem _inventory = default!;
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IConfigurationManager _config = default!;
private CharacterInformationWindow? _window;
public override void Initialize()
{
base.Initialize();
_window = new CharacterInformationWindow();
SubscribeLocalEvent<CharacterInformationComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
}
private void OnGetExamineVerbs(EntityUid uid, CharacterInformationComponent component, GetVerbsEvent<ExamineVerb> args)
{
var verb = new ExamineVerb()
{
Act = () =>
{
// TODO: Better name?
Do(args.Target);
},
Text = Loc.GetString("character-information-verb-text"),
Message = Loc.GetString("character-information-verb-message"),
Category = VerbCategory.Examine,
Disabled = !_examine.IsInDetailsRange(args.User, uid),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/sentient.svg.192dpi.png")),
ClientExclusive = true,
};
args.Verbs.Add(verb);
}
private void Do(EntityUid uid)
{
if (_window == null)
return;
string? name = null;
string? job = null;
string? flavorText = null;
// Get ID from inventory, get name and job from ID
if (_inventory.TryGetSlotEntity(uid, "id", out var idUid))
{
var id = GetId(idUid);
if (id is not null)
{
var info = GetNameAndJob(id);
name = info.Item1;
job = info.Item2;
}
}
// Fancy job title
if (!string.IsNullOrEmpty(job))
{
var test = job.Replace(" ", "");
// Command will be last in the list
// TODO: Make this not revolve around this fact ^
var departments = _prototype.EnumeratePrototypes<DepartmentPrototype>().OrderBy(d => d.ID).Reverse();
var department = departments.FirstOrDefault(d => d.Roles.Contains(test));
if (department is not null)
{
// Department (ex: Command or Security)
var dept = string.Join(" ", Loc.GetString($"department-{department.ID}").Split(' ').Select(s => s[0].ToString().ToUpper() + s[1..].ToLower()));
// Redo the job title with the department color and department (ex: Captain (Command) or Security Officer (Security))
job = $"[color={department.Color.ToHex()}]{job} ({dept})[/color]";
}
}
// Get and set flavor text
if (!_config.GetCVar(CCVars.FlavorText))
{
flavorText = Loc.GetString("character-information-ui-flavor-text-disabled");
}
else if (_entity.TryGetComponent<DetailExaminableComponent>(uid, out var detail))
{
flavorText = detail.Content;
}
_window.OpenCentered();
_window.UpdateUi(uid, name, job, flavorText);
_examine.CloseTooltip();
}
/// <summary>
/// Gets the ID card component from either a PDA or an ID card if the entity has one
/// </summary>
/// <param name="idUid">Entity to check</param>
/// <returns>ID card component if they have one on the entity</returns>
private IdCardComponent? GetId(EntityUid? idUid)
{
// PDA
if (_entity.TryGetComponent(idUid, out PdaComponent? pda) &&
TryComp(pda.ContainedId, out IdCardComponent? idCard))
return idCard;
// ID Card
if (_entity.TryGetComponent(idUid, out IdCardComponent? id))
return id;
return null;
}
/// <summary>
/// Gets the name and job title from an ID card component
/// </summary>
/// <param name="id">The ID card to retrieve the information from</param>
/// <returns>Name, Job Title</returns>
private static (string, string) GetNameAndJob(IdCardComponent id)
{
var name = id.FullName;
if (string.IsNullOrEmpty(name))
name = "Unknown";
var jobTitle = id.JobTitle;
if (string.IsNullOrEmpty(jobTitle))
jobTitle = "Unknown";
jobTitle = string.Join(" ", jobTitle.Split(' ').Select(s => s[0].ToString().ToUpper() + s[1..].ToLower()));
return (name, jobTitle);
}
}

View File

@@ -0,0 +1,29 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:style="clr-namespace:Content.Client.Stylesheets"
Title="{Loc 'character-information-ui-title'}" MinSize="675 384" Resizable="True">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True" Margin="8">
<BoxContainer Orientation="Vertical">
<GridContainer Name="SpriteContainer" Columns="2">
</GridContainer>
<!-- Character name, job title and icon, etc goes here -->
<RichTextLabel Name="Name" HorizontalAlignment="Center" />
<RichTextLabel Name="Job" HorizontalAlignment="Center" VerticalAlignment="Center" />
</BoxContainer>
<PanelContainer MinSize="2 5" MaxWidth="2" Margin="8 0 8 0">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="{x:Static style:StyleNano.NanoGold}" ContentMarginTopOverride="2" />
</PanelContainer.PanelOverride>
</PanelContainer>
<ScrollContainer HScrollEnabled="False" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<!-- Character description goes here -->
<RichTextLabel Name="FlavorText" HorizontalExpand="True" />
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -0,0 +1,115 @@
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<IEntityManager>();
ResetUi();
}
/// <summary>
/// Placeholder entries
/// </summary>
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 => char.ToUpper(s[0]) + s[1..]));
_name.SetMarkup(unknown);
_job.SetMarkup(unknown);
_flavor.SetMarkup(Loc.GetString("character-information-ui-flavor-text-placeholder"));
}
/// <summary>
/// Updates the UI to show all relevant information about the entity
/// </summary>
/// <param name="examined">The entity to become informed about</param>
/// <param name="name">The name of the examined entity, taken from their ID</param>
/// <param name="job">The job of the examined entity, taken from their ID</param>
/// <param name="flavorText">The flavor text of the examined entity</param>
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);
}
/// <summary>
/// Fills the sprite views with the sprite from the sprite component
/// </summary>
/// <remarks>
/// Stupid, redefines the sprite view 4 times, can't find another way to do this
/// </remarks>
/// <param name="sprite">Sprite component to use</param>
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),
});
}
}