Skip to content

Commit

Permalink
added solidus's comments, pending removal of namespace thingies for t…
Browse files Browse the repository at this point in the history
…his repo, also fixed some healing thingies
  • Loading branch information
gluesniffler committed Nov 16, 2024
1 parent e58d88a commit 9c84e11
Show file tree
Hide file tree
Showing 34 changed files with 142 additions and 268 deletions.
12 changes: 3 additions & 9 deletions Content.Client/Body/Components/BrainComponent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using Robust.Shared.GameStates;

namespace Content.Client.Body.Components
{
[RegisterComponent]
public sealed partial class BrainComponent : Component
{
}
}
namespace Content.Client.Body.Components;
[RegisterComponent]
public sealed partial class BrainComponent : Component { }
12 changes: 3 additions & 9 deletions Content.Client/Body/Components/LungComponent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using Robust.Shared.GameStates;

namespace Content.Client.Body.Components
{
[RegisterComponent]
public sealed partial class LungComponent : Component
{
}
}
namespace Content.Client.Body.Components;
[RegisterComponent]
public sealed partial class LungComponent : Component { }
12 changes: 3 additions & 9 deletions Content.Client/Body/Components/StomachComponent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using Robust.Shared.GameStates;

namespace Content.Client.Body.Components
{
[RegisterComponent]
public sealed partial class StomachComponent : Component
{
}
}
namespace Content.Client.Body.Components;
[RegisterComponent]
public sealed partial class StomachComponent : Component { }
13 changes: 1 addition & 12 deletions Content.Client/Body/Systems/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,15 +56,13 @@ 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 RemoveBodyMarkings(EntityUid target, BodyPartAppearanceComponent partAppearance, HumanoidAppearanceComponent bodyAppearance)
Expand Down
12 changes: 2 additions & 10 deletions Content.Client/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,15 @@ private void HideLayers(EntityUid uid, HandsComponent component, Entity<BodyPart
if (component.RevealedLayers.TryGetValue(location, out var revealedLayers))
{
foreach (var key in revealedLayers)
{
sprite.RemoveLayer(key);
}

revealedLayers.Clear();
}
}

private void HandleBodyPartRemoved(EntityUid uid, HandsComponent component, ref BodyPartRemovedEvent args)
{
HideLayers(uid, component, args.Part);
}
private void HandleBodyPartRemoved(EntityUid uid, HandsComponent component, ref BodyPartRemovedEvent args) => HideLayers(uid, component, args.Part);

private void HandleBodyPartDisabled(EntityUid uid, HandsComponent component, ref BodyPartDisabledEvent args)
{
HideLayers(uid, component, args.Part);
}
private void HandleBodyPartDisabled(EntityUid uid, HandsComponent component, ref BodyPartDisabledEvent args) => HideLayers(uid, component, args.Part);

protected override void HandleEntityInserted(EntityUid uid, HandsComponent hands, EntInsertedIntoContainerMessage args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ protected override void ReceiveMessage(BoundUserInterfaceMessage message)
_window.Populate(cast);
}

private void SendBodyPartMessage(TargetBodyPart? part, EntityUid target)
{
if (part == null)
SendMessage(new HealthAnalyzerPartMessage(EntMan.GetNetEntity(target), null));
else
SendMessage(new HealthAnalyzerPartMessage(EntMan.GetNetEntity(target), part.Value));
}
private void SendBodyPartMessage(TargetBodyPart? part, EntityUid target) => SendMessage(new HealthAnalyzerPartMessage(EntMan.GetNetEntity(target), part ?? null));

protected override void Dispose(bool disposing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Numerics;
using Content.Client.Message;
using Content.Shared.Atmos;
using Content.Shared.Body.Part; // Shitmed
using Content.Client.UserInterface.Controls;
using Content.Shared.Alert;
using Content.Shared.Damage;
Expand Down Expand Up @@ -90,10 +89,7 @@ public void SetActiveBodyPart(TargetBodyPart part, TextureButton button)
return;

// Bit of the ole shitcode until we have Groins in the prototypes.
if (part == TargetBodyPart.Groin)
OnBodyPartSelected?.Invoke(TargetBodyPart.Torso, _target.Value);
else
OnBodyPartSelected?.Invoke(part, _target.Value);
OnBodyPartSelected?.Invoke(part == TargetBodyPart.Groin ? TargetBodyPart.Torso : part, _target.Value);
}

public void ResetBodyPart()
Expand Down Expand Up @@ -183,7 +179,6 @@ public void Populate(HealthAnalyzerScannedUserMessage msg)

// Total Damage


DamageLabel.Text = damageable.TotalDamage.ToString();

// Alerts
Expand Down
8 changes: 5 additions & 3 deletions Content.Client/Inventory/ClientInventorySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ public void UpdateSlot(EntityUid owner, InventorySlotsComponent component, strin

public void OnRefreshInventorySlots(EntityUid owner, InventorySlotsComponent component, RefreshInventorySlotsEvent args)
{
if (component.SlotData.TryGetValue(args.SlotName, out var slotData)
&& _playerManager.LocalEntity == owner)
OnSlotRemoved?.Invoke(slotData);
if (!component.SlotData.TryGetValue(args.SlotName, out var slotData)
|| _playerManager.LocalEntity != owner)
return;

OnSlotRemoved?.Invoke(slotData);
}

public bool TryAddSlotDef(EntityUid owner, InventorySlotsComponent component, SlotDefinition newSlotDef)
Expand Down
82 changes: 22 additions & 60 deletions Content.Client/Medical/Surgery/SurgeryBui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
using Content.Shared.Medical.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.Medical.Surgery;

Expand All @@ -22,35 +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();
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 @@ -62,7 +52,7 @@ protected override void Dispose(bool disposing)

private void Update(SurgeryBuiState state)
{
if (!_entities.TryGetComponent<SurgeryTargetComponent>(_player.LocalEntity, out var surgeryTargetComp)
if (!_entities.TryGetComponent(_player.LocalEntity, out SurgeryTargetComponent? surgeryTargetComp)
|| !surgeryTargetComp.CanOperate)
return;

Expand All @@ -86,32 +76,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 @@ -129,15 +113,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 @@ -192,11 +174,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 @@ -237,9 +218,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 @@ -295,11 +274,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 @@ -309,31 +287,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 @@ -367,17 +335,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
Loading

0 comments on commit 9c84e11

Please sign in to comment.