* Early commit * Early commit 2 * merging master broke my git * does anyone even read these * life is fleeting * it just works * this time passing integration tests * Remove hashset yaml serialization for now * You got a license for those nullables? * No examine, no context menu, part and mechanism parenting and visibility * Fix wrong brain sprite state * Removing layers was a mistake * just tear body system a new one and see if it still breathes * Remove redundant code * Add that comment back * Separate damage and body, component states, stomach rework * Add containers for body parts * Bring layers back pls * Fix parts magically changing color * Reimplement sprite layer visibility * Fix tests * Add leg test * Active legs is gone Crab rave * Merge fixes, rename DamageState to CurrentState * Remove IShowContextMenu and ICanExamine
185 lines
6.3 KiB
C#
185 lines
6.3 KiB
C#
#nullable enable
|
|
using System.Linq;
|
|
using Content.Shared.GameObjects.Components.Body;
|
|
using Content.Shared.GameObjects.Components.Body.Mechanism;
|
|
using Content.Shared.GameObjects.Components.Body.Part;
|
|
using Content.Shared.GameObjects.Components.Damage;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Maths;
|
|
using static Robust.Client.UserInterface.Controls.ItemList;
|
|
|
|
namespace Content.Client.GameObjects.Components.Body.Scanner
|
|
{
|
|
public sealed class BodyScannerDisplay : SS14Window
|
|
{
|
|
private IEntity? _currentEntity;
|
|
private IBodyPart? _currentBodyPart;
|
|
|
|
private IBody? CurrentBody => _currentEntity?.GetBody();
|
|
|
|
public BodyScannerDisplay(BodyScannerBoundUserInterface owner)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
Owner = owner;
|
|
Title = Loc.GetString("Body Scanner");
|
|
|
|
var hSplit = new HBoxContainer
|
|
{
|
|
Children =
|
|
{
|
|
// Left half
|
|
new ScrollContainer
|
|
{
|
|
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
|
Children =
|
|
{
|
|
(BodyPartList = new ItemList())
|
|
}
|
|
},
|
|
// Right half
|
|
new VBoxContainer
|
|
{
|
|
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
|
Children =
|
|
{
|
|
// Top half of the right half
|
|
new VBoxContainer
|
|
{
|
|
SizeFlagsVertical = SizeFlags.FillExpand,
|
|
Children =
|
|
{
|
|
(BodyPartLabel = new Label()),
|
|
new HBoxContainer
|
|
{
|
|
Children =
|
|
{
|
|
new Label
|
|
{
|
|
Text = "Health: "
|
|
},
|
|
(BodyPartHealth = new Label())
|
|
}
|
|
},
|
|
new ScrollContainer
|
|
{
|
|
SizeFlagsVertical = SizeFlags.FillExpand,
|
|
Children =
|
|
{
|
|
(MechanismList = new ItemList())
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// Bottom half of the right half
|
|
(MechanismInfoLabel = new RichTextLabel
|
|
{
|
|
SizeFlagsVertical = SizeFlags.FillExpand
|
|
})
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
Contents.AddChild(hSplit);
|
|
|
|
BodyPartList.OnItemSelected += BodyPartOnItemSelected;
|
|
MechanismList.OnItemSelected += MechanismOnItemSelected;
|
|
}
|
|
|
|
public BodyScannerBoundUserInterface Owner { get; }
|
|
|
|
protected override Vector2? CustomSize => (800, 600);
|
|
|
|
private ItemList BodyPartList { get; }
|
|
|
|
private Label BodyPartLabel { get; }
|
|
|
|
private Label BodyPartHealth { get; }
|
|
|
|
private ItemList MechanismList { get; }
|
|
|
|
private RichTextLabel MechanismInfoLabel { get; }
|
|
|
|
public void UpdateDisplay(IEntity entity)
|
|
{
|
|
_currentEntity = entity;
|
|
BodyPartList.Clear();
|
|
|
|
var body = CurrentBody;
|
|
|
|
if (body == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var slotName in body.Parts.Keys)
|
|
{
|
|
BodyPartList.AddItem(Loc.GetString(slotName));
|
|
}
|
|
}
|
|
|
|
public void BodyPartOnItemSelected(ItemListSelectedEventArgs args)
|
|
{
|
|
var body = CurrentBody;
|
|
|
|
if (body == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var slot = body.SlotAt(args.ItemIndex).Key;
|
|
_currentBodyPart = body.PartAt(args.ItemIndex).Value;
|
|
|
|
if (body.Parts.TryGetValue(slot, out var part))
|
|
{
|
|
UpdateBodyPartBox(part, slot);
|
|
}
|
|
}
|
|
|
|
private void UpdateBodyPartBox(IBodyPart part, string slotName)
|
|
{
|
|
BodyPartLabel.Text = $"{Loc.GetString(slotName)}: {Loc.GetString(part.Owner.Name)}";
|
|
|
|
// TODO BODY Make dead not be the destroy threshold for a body part
|
|
if (part.Owner.TryGetComponent(out IDamageableComponent? damageable) &&
|
|
damageable.TryHealth(DamageState.Critical, out var health))
|
|
{
|
|
BodyPartHealth.Text = $"{health.current} / {health.max}";
|
|
}
|
|
|
|
MechanismList.Clear();
|
|
|
|
foreach (var mechanism in part.Mechanisms)
|
|
{
|
|
MechanismList.AddItem(mechanism.Name);
|
|
}
|
|
}
|
|
|
|
// TODO BODY Guaranteed this is going to crash when a part's mechanisms change. This part is left as an exercise for the reader.
|
|
public void MechanismOnItemSelected(ItemListSelectedEventArgs args)
|
|
{
|
|
UpdateMechanismBox(_currentBodyPart?.Mechanisms.ElementAt(args.ItemIndex));
|
|
}
|
|
|
|
private void UpdateMechanismBox(IMechanism? mechanism)
|
|
{
|
|
// TODO BODY Improve UI
|
|
if (mechanism == null)
|
|
{
|
|
MechanismInfoLabel.SetMessage("");
|
|
return;
|
|
}
|
|
|
|
var message =
|
|
Loc.GetString(
|
|
$"{mechanism.Name}\nHealth: {mechanism.CurrentDurability}/{mechanism.MaxDurability}\n{mechanism.Description}");
|
|
|
|
MechanismInfoLabel.SetMessage(message);
|
|
}
|
|
}
|
|
}
|