Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port] Surgery Update V: The Phantom Gib #919

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions Content.Client/Backmen/Body/BodySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ private void ApplyMarkingToPart(MarkingPrototype markingPrototype,
var markingSprite = markingPrototype.Sprites[j];

if (markingSprite is not SpriteSpecifier.Rsi rsi)
{
continue;
}

var layerId = $"{markingPrototype.ID}-{rsi.RsiState}";

Expand All @@ -38,21 +36,14 @@ private void ApplyMarkingToPart(MarkingPrototype markingPrototype,
sprite.LayerSetVisible(layerId, visible);

if (!visible)
{
continue;
}

// Okay so if the marking prototype is modified but we load old marking data this may no longer be valid
// and we need to check the index is correct.
// So if that happens just default to white?
// and we need to check the index is correct. So if that happens just default to white?
if (colors != null && j < colors.Count)
{
sprite.LayerSetColor(layerId, colors[j]);
}
else
{
sprite.LayerSetColor(layerId, Color.White);
}
}
}

Expand All @@ -65,18 +56,16 @@ protected override void ApplyPartMarkings(EntityUid target, BodyPartAppearanceCo
sprite.Color = component.Color.Value;

foreach (var (visualLayer, markingList) in component.Markings)
{
foreach (var marking in markingList)
{
if (!_markingManager.TryGetMarking(marking, out var markingPrototype))
continue;

ApplyMarkingToPart(markingPrototype, marking.MarkingColors, marking.Visible, sprite);
}
}
}

protected override void RemovePartMarkings(EntityUid target, BodyPartAppearanceComponent partAppearance, HumanoidAppearanceComponent bodyAppearance)
protected override void RemoveBodyMarkings(EntityUid target, BodyPartAppearanceComponent partAppearance, HumanoidAppearanceComponent bodyAppearance)
{
return;
}
Expand Down
85 changes: 22 additions & 63 deletions Content.Client/Backmen/Surgery/SurgeryBui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
using Content.Shared.Backmen.Surgery;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Client.Hands.Systems;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Robust.Shared.Timing;
using Robust.Client.Timing;
using static Robust.Client.UserInterface.Control;
using OpenToolkit.GraphicsLibraryFramework;

namespace Content.Client.Backmen.Surgery;

Expand All @@ -22,37 +17,30 @@ public sealed class SurgeryBui : BoundUserInterface
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IPlayerManager _player = default!;

[Dependency] private readonly IClientGameTiming _gameTiming = default!;
[Dependency] private readonly IGameTiming _timing = default!;

private readonly SurgerySystem _system;
[ViewVariables]
private SurgeryWindow? _window;

private EntityUid? _part;
private bool _isBody = false;
private bool _isBody;
private (EntityUid Ent, EntProtoId Proto)? _surgery;
private readonly List<EntProtoId> _previousSurgeries = new();
private DateTime _lastRefresh = DateTime.UtcNow;
private (string handName, EntityUid item) _throttling = ("", new EntityUid());
public SurgeryBui(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_system = _entities.System<SurgerySystem>();
}
public SurgeryBui(EntityUid owner, Enum uiKey) : base(owner, uiKey) => _system = _entities.System<SurgerySystem>();

protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
if (_window == null)
if (_window is null
|| message is not SurgeryBuiRefreshMessage)
return;

if (message is SurgeryBuiRefreshMessage)
RefreshUI();
RefreshUI();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
if (state is SurgeryBuiState s)
Update(s);
if (state is not SurgeryBuiState s)
return;

Update(s);
}

protected override void Dispose(bool disposing)
Expand All @@ -64,8 +52,7 @@ protected override void Dispose(bool disposing)

private void Update(SurgeryBuiState state)
{
//Logger.Debug($"Attempting to update surgerybuistate with {state}, {_player.LocalEntity}, first predicted? {_timing.IsFirstTimePredicted}, surgeryTargetComp? {_entities.TryGetComponent<SurgeryTargetComponent>(_player.LocalEntity, out var surgeryTargetComp2)} {surgeryTargetComp2?.CanOperate}");
if (!_entities.TryGetComponent<SurgeryTargetComponent>(_player.LocalEntity, out var surgeryTargetComp)
if (!_entities.TryGetComponent(_player.LocalEntity, out SurgeryTargetComponent? surgeryTargetComp)
|| !surgeryTargetComp.CanOperate)
return;
if (_window == null)
Expand All @@ -88,32 +75,26 @@ private void Update(SurgeryBuiState state)
_surgery = null;
_previousSurgeries.Clear();

if (!_entities.TryGetNetEntity(_part, out var netPart) ||
State is not SurgeryBuiState s ||
!s.Choices.TryGetValue(netPart.Value, out var surgeries))
{
if (!_entities.TryGetNetEntity(_part, out var netPart)
|| State is not SurgeryBuiState s
|| !s.Choices.TryGetValue(netPart.Value, out var surgeries))
return;
}

OnPartPressed(netPart.Value, surgeries);
};

_window.StepsButton.OnPressed += _ =>
{
if (!_entities.TryGetNetEntity(_part, out var netPart) ||
_previousSurgeries.Count == 0)
{
if (!_entities.TryGetNetEntity(_part, out var netPart)
|| _previousSurgeries.Count == 0)
return;
}

var last = _previousSurgeries[^1];
_previousSurgeries.RemoveAt(_previousSurgeries.Count - 1);

if (_system.GetSingleton(last) is not { } previousId ||
!_entities.TryGetComponent(previousId, out SurgeryComponent? previous))
{
if (_system.GetSingleton(last) is not { } previousId
|| !_entities.TryGetComponent(previousId, out SurgeryComponent? previous))
return;
}

OnSurgeryPressed((previousId, previous), netPart.Value, last);
};
Expand All @@ -131,15 +112,13 @@ State is not SurgeryBuiState s ||

var options = new List<(NetEntity netEntity, EntityUid entity, string Name, BodyPartType? PartType)>();
foreach (var choice in state.Choices.Keys)
{
if (_entities.TryGetEntity(choice, out var ent))
{
if (_entities.TryGetComponent(ent, out BodyPartComponent? part))
options.Add((choice, ent.Value, _entities.GetComponent<MetaDataComponent>(ent.Value).EntityName, part.PartType));
else if (_entities.TryGetComponent(ent, out BodyComponent? body))
options.Add((choice, ent.Value, _entities.GetComponent<MetaDataComponent>(ent.Value).EntityName, null));
}
}

options.Sort((a, b) =>
{
Expand Down Expand Up @@ -197,11 +176,10 @@ int GetScore(BodyPartType? partType)

private void AddStep(EntProtoId stepId, NetEntity netPart, EntProtoId surgeryId)
{
if (_window == null ||
_system.GetSingleton(stepId) is not { } step)
{
if (_window == null
|| _system.GetSingleton(stepId) is not { } step)
return;
}

var stepName = new FormattedMessage();
stepName.AddText(_entities.GetComponent<MetaDataComponent>(step).EntityName);
var stepButton = new SurgeryStepButton { Step = step };
Expand Down Expand Up @@ -242,9 +220,7 @@ private void OnSurgeryPressed(Entity<SurgeryComponent> surgery, NetEntity netPar
_window.Steps.AddChild(new HSeparator { Margin = new Thickness(0, 0, 0, 1) });
}
foreach (var stepId in surgery.Comp.Steps)
{
AddStep(stepId, netPart, surgeryId);
}

View(ViewType.Steps);
RefreshUI();
Expand Down Expand Up @@ -300,11 +276,10 @@ private void RefreshUI()
|| !_window.IsOpen
|| _part == null
|| !_entities.HasComponent<SurgeryComponent>(_surgery?.Ent)
|| !_entities.TryGetComponent<SurgeryTargetComponent>(_player.LocalEntity ?? EntityUid.Invalid, out var surgeryComp)
|| !_entities.TryGetComponent(_player.LocalEntity ?? EntityUid.Invalid, out SurgeryTargetComponent? surgeryComp)
|| !surgeryComp.CanOperate)
{
return;
}

var next = _system.GetNextStep(Owner, _part.Value, _surgery.Value.Ent);
var i = 0;
foreach (var child in _window.Steps.Children)
Expand All @@ -314,31 +289,21 @@ private void RefreshUI()

var status = StepStatus.Incomplete;
if (next == null)
{
status = StepStatus.Complete;
}
else if (next.Value.Surgery.Owner != _surgery.Value.Ent)
{
status = StepStatus.Incomplete;
}
else if (next.Value.Step == i)
{
status = StepStatus.Next;
}
else if (i < next.Value.Step)
{
status = StepStatus.Complete;
}

stepButton.Button.Disabled = status != StepStatus.Next;

var stepName = new FormattedMessage();
stepName.AddText(_entities.GetComponent<MetaDataComponent>(stepButton.Step).EntityName);

if (status == StepStatus.Complete)
{
stepButton.Button.Modulate = Color.Green;
}
else
{
stepButton.Button.Modulate = Color.White;
Expand Down Expand Up @@ -372,17 +337,11 @@ private void View(ViewType type)

if (_entities.TryGetComponent(_part, out MetaDataComponent? partMeta) &&
_entities.TryGetComponent(_surgery?.Ent, out MetaDataComponent? surgeryMeta))
{
_window.Title = $"Surgery - {partMeta.EntityName}, {surgeryMeta.EntityName}";
}
else if (partMeta != null)
{
_window.Title = $"Surgery - {partMeta.EntityName}";
}
else
{
_window.Title = "Surgery";
}
}

private enum ViewType
Expand Down
34 changes: 21 additions & 13 deletions Content.Client/Backmen/Targeting/TargetingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ public override void Initialize()
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.Torso)))
.Bind(ContentKeyFunctions.TargetLeftArm,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.LeftArm)))
/* .Bind(ContentKeyFunctions.TargetLeftHand,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.LeftHand))) SOON :TM: */
.Bind(ContentKeyFunctions.TargetRightArm,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.RightArm)))
/* .Bind(ContentKeyFunctions.TargetRightHand,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.RightHand)))*/
.Bind(ContentKeyFunctions.TargetLeftLeg,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.LeftLeg)))
/* .Bind(ContentKeyFunctions.TargetLeftFoot,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.LeftFoot)))*/
.Bind(ContentKeyFunctions.TargetRightLeg,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.RightLeg)))
/* .Bind(ContentKeyFunctions.TargetRightFoot,
InputCmdHandler.FromDelegate((session) => HandleTargetChange(session, TargetBodyPart.RightFoot)))*/
.Register<SharedTargetingSystem>();
}

Expand All @@ -54,28 +62,28 @@ private void HandlePlayerDetached(EntityUid uid, TargetingComponent component, L

private void OnTargetingStartup(EntityUid uid, TargetingComponent component, ComponentStartup args)
{
if (_playerManager.LocalEntity == uid)
{
TargetingStartup?.Invoke(component);
PartStatusStartup?.Invoke(component);
}
if (_playerManager.LocalEntity != uid)
return;

TargetingStartup?.Invoke(component);
PartStatusStartup?.Invoke(component);
}

private void OnTargetingShutdown(EntityUid uid, TargetingComponent component, ComponentShutdown args)
{
if (_playerManager.LocalEntity == uid)
{
TargetingShutdown?.Invoke();
PartStatusShutdown?.Invoke();
}
if (_playerManager.LocalEntity != uid)
return;

TargetingShutdown?.Invoke();
PartStatusShutdown?.Invoke();
}

private void OnTargetIntegrityChange(TargetIntegrityChangeEvent args)
{
if (!TryGetEntity(args.Uid, out var uid)
|| !_playerManager.LocalEntity.Equals(uid)
|| !TryComp(uid, out TargetingComponent? component)
|| !args.RefreshUi)
|| !_playerManager.LocalEntity.Equals(uid)
|| !TryComp(uid, out TargetingComponent? component)
|| !args.RefreshUi)
return;

PartStatusUpdate?.Invoke(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,46 @@
Name="DollHead"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollTorso"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollGroin"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollLeftArm"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollTorso"
Name="DollLeftHand"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollRightArm"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollRightHand"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollLeftLeg"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollLeftFoot"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollRightLeg"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
<TextureRect
Name="DollRightFoot"
Stretch="KeepAspectCentered"
SetSize="64 64"/>
</PanelContainer>
</Control>
</widgets:PartStatusControl>
Loading
Loading