* ECS and damage Data * Comments and newlines * Added Comments * Make TryChangeDamageEvent immutable * Remove SetAllDamage event Use public SetAllDamage function instead * Undo destructible mistakes That was some shit code. * Rename DamageData to DamageSpecifier And misc small edits misc * Cache trigger prototypes. * Renaming destructible classes & functions * Revert "Cache trigger prototypes." This reverts commit 86bae15ba6616884dba75f552dfdfbe2d1fb6586. * Replace prototypes with prototype IDs. * Split damage.yml into individual files * move get/handle component state to system * Update HealthChange doc * Make godmode call Dirty() on damageable component * Add Initialize() to fix damage test * Make non-static * uncache resistance set prototype and trim DamageableComponentState * Remove unnecessary Dirty() calls during initialization * RemoveTryChangeDamageEvent * revert Dirty() * Fix MobState relying on DamageableComponent.Dirty() * Fix DisposalUnit Tests. These were previously failing, but because the async was not await-ed, this never raised the exception. After I fixed MobState component, this exception stopped happening and instead the assertions started being tested & failing * Disposal test 2: electric boogaloo * Fix typos/mistakes also add comments and fix spacing. * Use Uids instead of IEntity * fix merge * Comments, a merge issue, and making some damage ignore resistances * Extend DamageSpecifier and use it for DamageableComponent * fix master merge * Fix Disposal unit test. Again. Snapgrids were removed in master * Execute Exectute
187 lines
6.4 KiB
C#
187 lines
6.4 KiB
C#
using System.Linq;
|
|
using Content.Shared.Body.Components;
|
|
using Content.Shared.Body.Mechanism;
|
|
using Content.Shared.Body.Part;
|
|
using Content.Shared.Damage;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
|
using static Robust.Client.UserInterface.Controls.ItemList;
|
|
|
|
namespace Content.Client.Body.UI
|
|
{
|
|
public sealed class BodyScannerDisplay : SS14Window
|
|
{
|
|
private IEntity? _currentEntity;
|
|
private SharedBodyPartComponent? _currentBodyPart;
|
|
|
|
private SharedBodyComponent? CurrentBody => _currentEntity?.GetComponentOrNull<SharedBodyComponent>();
|
|
|
|
public BodyScannerDisplay(BodyScannerBoundUserInterface owner)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
Owner = owner;
|
|
Title = Loc.GetString("body-scanner-display-title");
|
|
|
|
var hSplit = new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
Children =
|
|
{
|
|
// Left half
|
|
new ScrollContainer
|
|
{
|
|
HorizontalExpand = true,
|
|
Children =
|
|
{
|
|
(BodyPartList = new ItemList())
|
|
}
|
|
},
|
|
// Right half
|
|
new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Vertical,
|
|
HorizontalExpand = true,
|
|
Children =
|
|
{
|
|
// Top half of the right half
|
|
new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Vertical,
|
|
VerticalExpand = true,
|
|
Children =
|
|
{
|
|
(BodyPartLabel = new Label()),
|
|
new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
Children =
|
|
{
|
|
new Label
|
|
{
|
|
Text = $"{Loc.GetString("body-scanner-display-health-label")} "
|
|
},
|
|
(BodyPartHealth = new Label())
|
|
}
|
|
},
|
|
new ScrollContainer
|
|
{
|
|
VerticalExpand = true,
|
|
Children =
|
|
{
|
|
(MechanismList = new ItemList())
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// Bottom half of the right half
|
|
(MechanismInfoLabel = new RichTextLabel
|
|
{
|
|
VerticalExpand = true
|
|
})
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
Contents.AddChild(hSplit);
|
|
|
|
BodyPartList.OnItemSelected += BodyPartOnItemSelected;
|
|
MechanismList.OnItemSelected += MechanismOnItemSelected;
|
|
MinSize = SetSize = (800, 600);
|
|
}
|
|
|
|
public BodyScannerBoundUserInterface Owner { get; }
|
|
|
|
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 (part, _) in body.Parts)
|
|
{
|
|
BodyPartList.AddItem(Loc.GetString(part.Name));
|
|
}
|
|
}
|
|
|
|
public void BodyPartOnItemSelected(ItemListSelectedEventArgs args)
|
|
{
|
|
var body = CurrentBody;
|
|
|
|
if (body == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var slot = body.SlotAt(args.ItemIndex);
|
|
_currentBodyPart = body.PartAt(args.ItemIndex).Key;
|
|
|
|
if (slot.Part != null)
|
|
{
|
|
UpdateBodyPartBox(slot.Part, slot.Id);
|
|
}
|
|
}
|
|
|
|
private void UpdateBodyPartBox(SharedBodyPartComponent part, string slotName)
|
|
{
|
|
BodyPartLabel.Text = $"{Loc.GetString(slotName)}: {Loc.GetString(part.Owner.Name)}";
|
|
|
|
// TODO BODY Part damage
|
|
if (part.Owner.TryGetComponent(out DamageableComponent? damageable))
|
|
{
|
|
BodyPartHealth.Text = Loc.GetString("body-scanner-display-body-part-damage-text",("damage", damageable.TotalDamage));
|
|
}
|
|
|
|
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(SharedMechanismComponent? mechanism)
|
|
{
|
|
// TODO BODY Improve UI
|
|
if (mechanism == null)
|
|
{
|
|
MechanismInfoLabel.SetMessage("");
|
|
return;
|
|
}
|
|
|
|
// TODO BODY Mechanism description
|
|
var message =
|
|
Loc.GetString(
|
|
$"{mechanism.Name}\nHealth: {mechanism.CurrentDurability}/{mechanism.MaxDurability}");
|
|
|
|
MechanismInfoLabel.SetMessage(message);
|
|
}
|
|
}
|
|
}
|