Skip to content

Commit

Permalink
Merge Shitmed
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisfiregamer1 committed Nov 9, 2024
2 parents 07eafcb + 1a0e84a commit 46a6c8a
Show file tree
Hide file tree
Showing 37 changed files with 620 additions and 130 deletions.
76 changes: 76 additions & 0 deletions Content.Client/Body/Systems/BodySystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,83 @@
using Content.Shared.Body.Systems;
using Content.Shared.Body.Part;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Robust.Client.GameObjects;
using Robust.Shared.Utility;
using Content.Shared.Body.Components;

namespace Content.Client.Body.Systems;

public sealed class BodySystem : SharedBodySystem
{
[Dependency] private readonly MarkingManager _markingManager = default!;

private void ApplyMarkingToPart(MarkingPrototype markingPrototype,
IReadOnlyList<Color>? colors,
bool visible,
SpriteComponent sprite)
{
for (var j = 0; j < markingPrototype.Sprites.Count; j++)
{
var markingSprite = markingPrototype.Sprites[j];

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

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

if (!sprite.LayerMapTryGet(layerId, out _))
{
var layer = sprite.AddLayer(markingSprite, j + 1);
sprite.LayerMapSet(layerId, layer);
sprite.LayerSetSprite(layerId, rsi);
}

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?
if (colors != null && j < colors.Count)
{
sprite.LayerSetColor(layerId, colors[j]);
}
else
{
sprite.LayerSetColor(layerId, Color.White);
}
}
}

protected override void ApplyPartMarkings(EntityUid target, BodyPartAppearanceComponent component)
{
if (!TryComp(target, out SpriteComponent? sprite))
return;

if (component.Color != null)
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)
{
return;
}
}
40 changes: 39 additions & 1 deletion Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Targeting;
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
Expand Down Expand Up @@ -36,6 +37,12 @@ public sealed partial class HealthAnalyzerWindow : FancyWindow
private readonly IPrototypeManager _prototypes;
private readonly IResourceCache _cache;

// Start-Shitmed
private EntityUid _spriteViewEntity;

[ValidatePrototypeId<EntityPrototype>]
private readonly EntProtoId _bodyView = "AlertSpriteView";
// End-Shitmed
public HealthAnalyzerWindow()
{
RobustXamlLoader.Load(this);
Expand Down Expand Up @@ -72,7 +79,7 @@ public void Populate(HealthAnalyzerScannedUserMessage msg)

// Patient Information

SpriteView.SetEntity(target.Value);
SpriteView.SetEntity(SetupIcon(msg.Body) ?? target.Value); // Shitmed
SpriteView.Visible = msg.ScanMode.HasValue && msg.ScanMode.Value;
NoDataTex.Visible = !SpriteView.Visible;

Expand Down Expand Up @@ -249,5 +256,36 @@ private BoxContainer CreateDiagnosticGroupTitle(string text, string id)

return rootContainer;
}

// Start-Shitmed
/// <summary>
/// Sets up the Body Doll using Alert Entity to use in Health Analyzer.
/// </summary>
private EntityUid? SetupIcon(Dictionary<TargetBodyPart, TargetIntegrity>? body)
{
if (body is null)
return null;
if (!_entityManager.Deleted(_spriteViewEntity))
_entityManager.QueueDeleteEntity(_spriteViewEntity);
_spriteViewEntity = _entityManager.Spawn(_bodyView);
if (!_entityManager.TryGetComponent<SpriteComponent>(_spriteViewEntity, out var sprite))
return null;
int layer = 0;
foreach (var (bodyPart, integrity) in body)
{
// TODO: Fix this way PartStatusUIController and make it use layers instead of TextureRects
string enumName = Enum.GetName(typeof(TargetBodyPart), bodyPart) ?? "Unknown";
int enumValue = (int) integrity;
var rsi = new SpriteSpecifier.Rsi(new ResPath($"/Textures/Interface/Targeting/Status/{enumName.ToLowerInvariant()}.rsi"), $"{enumName.ToLowerInvariant()}_{enumValue}");
// It's probably shitcode but im lazy to get into sprite stuff - It is shitcode :)
if (!sprite.TryGetLayer(layer, out _))
sprite.AddLayer(_spriteSystem.Frame0(rsi));
else
sprite.LayerSetTexture(layer, _spriteSystem.Frame0(rsi));
layer++;
}
return _spriteViewEntity;
}
// End-Shitmed
}
}
8 changes: 5 additions & 3 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ private void UpdateLayers(HumanoidAppearanceComponent component, SpriteComponent
foreach (var (key, info) in component.CustomBaseLayers)
{
oldLayers.Remove(key);
SetLayerData(component, sprite, key, info.Id, sexMorph: false, color: info.Color);
// Shitmed modification: For whatever reason these weren't actually ignoring the skin color as advertised.
SetLayerData(component, sprite, key, info.Id, sexMorph: false, color: info.Color, overrideSkin: true);
}

// hide old layers
Expand All @@ -83,7 +84,8 @@ private void SetLayerData(
HumanoidVisualLayers key,
string? protoId,
bool sexMorph = false,
Color? color = null)
Color? color = null,
bool overrideSkin = false)
{
var layerIndex = sprite.LayerMapReserveBlank(key);
var layer = sprite[layerIndex];
Expand All @@ -101,7 +103,7 @@ private void SetLayerData(
var proto = _prototypeManager.Index<HumanoidSpeciesSpriteLayer>(protoId);
component.BaseLayers[key] = proto;

if (proto.MatchSkin)
if (proto.MatchSkin && !overrideSkin)
layer.Color = component.SkinColor.WithAlpha(proto.LayerAlpha);

if (proto.BaseSprite != null)
Expand Down
79 changes: 12 additions & 67 deletions Content.Client/Medical/Surgery/SurgeryBui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
using Content.Shared.Medical.Surgery;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Rotation;
using Content.Shared.Standing;
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 @@ -21,33 +22,31 @@ 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 (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>();
}

protected override void Open()
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
_system.OnRefresh += () =>
{
UpdateDisabledPanel();
RefreshUI();
};
if (_window == null)
return;

if (State is SurgeryBuiState s)
Update(s);
if (message is SurgeryBuiRefreshMessage)
RefreshUI();
}

protected override void UpdateState(BoundUserInterfaceState state)
Expand All @@ -59,18 +58,16 @@ protected override void UpdateState(BoundUserInterfaceState state)
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
_window?.Dispose();

_system.OnRefresh -= RefreshUI;
}

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

if (_window == null)
{
_window = new SurgeryWindow();
Expand Down Expand Up @@ -125,7 +122,6 @@ State is not SurgeryBuiState s ||
_window.Surgeries.DisposeAllChildren();
_window.Steps.DisposeAllChildren();
_window.Parts.DisposeAllChildren();

View(ViewType.Parts);

var oldSurgery = _surgery;
Expand Down Expand Up @@ -194,11 +190,6 @@ int GetScore(BodyPartType? partType)

if (!_window.IsOpen)
_window.OpenCentered();
else
{
RefreshUI();
UpdateDisabledPanel();
}
}

private void AddStep(EntProtoId stepId, NetEntity netPart, EntProtoId surgeryId)
Expand Down Expand Up @@ -303,7 +294,6 @@ private void OnPartPressed(NetEntity netPart, List<EntProtoId> surgeryIds)
private void RefreshUI()
{
if (_window == null
|| !_timing.IsFirstTimePredicted
|| !_window.IsOpen
|| _part == null
|| !_entities.HasComponent<SurgeryComponent>(_surgery?.Ent)
Expand All @@ -312,7 +302,6 @@ private void RefreshUI()
{
return;
}

var next = _system.GetNextStep(Owner, _part.Value, _surgery.Value.Ent);
var i = 0;
foreach (var child in _window.Steps.Children)
Expand Down Expand Up @@ -350,60 +339,16 @@ private void RefreshUI()
else
{
stepButton.Button.Modulate = Color.White;
// GOD THIS NEEDS A REWRITE SO BADLY, IT UPDATES ON EVERY SINGLE TICK
// THEN RUNS CANPERFORMSTEP WHICH CALLS A SHITLOAD OF EVENTS
// DID THEY NOT FUCKING PLAYTEST THIS???
if (_player.LocalEntity is { } player
&& status == StepStatus.Next
&& !_system.CanPerformStep(player, Owner, _part.Value, stepButton.Step, false, out var popup, out var reason, out _))
{
stepButton.ToolTip = popup;
stepButton.Button.Disabled = true;

switch (reason)
{
case StepInvalidReason.MissingSkills:
stepName.AddMarkup($" [color=red]{Loc.GetString("surgery-ui-window-steps-error-skills")}[/color]");
break;
case StepInvalidReason.NeedsOperatingTable:
stepName.AddMarkup($" [color=red]{Loc.GetString("surgery-ui-window-steps-error-table")}[/color]");
break;
case StepInvalidReason.Armor:
stepName.AddMarkup($" [color=red]{Loc.GetString("surgery-ui-window-steps-error-armor")}[/color]");
break;
case StepInvalidReason.MissingTool:
stepName.AddMarkup($" [color=red]{Loc.GetString("surgery-ui-window-steps-error-tools")}[/color]");
break;
}
}
}

var texture = _entities.GetComponentOrNull<SpriteComponent>(stepButton.Step)?.Icon?.Default;
stepButton.Set(stepName, texture);
i++;
}

UpdateDisabledPanel();
}

private void UpdateDisabledPanel()
{
if (_window == null)
return;

if (_system.IsLyingDown(Owner))
{
_window.DisabledPanel.Visible = false;
_window.DisabledPanel.MouseFilter = MouseFilterMode.Ignore;
return;
}

_window.DisabledPanel.Visible = true;

var text = new FormattedMessage();
text.AddMarkup($"[color=red][font size=16]{Loc.GetString("surgery-ui-window-steps-error-laying")}[/font][/color]");
_window.DisabledLabel.SetMessage(text);
_window.DisabledPanel.MouseFilter = MouseFilterMode.Stop;
}

private void View(ViewType type)
Expand Down
8 changes: 3 additions & 5 deletions Content.Client/Medical/Surgery/SurgerySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ namespace Content.Client.Medical.Surgery;

public sealed class SurgerySystem : SharedSurgerySystem
{
public event Action? OnRefresh;

public override void Update(float frameTime)
public override void Initialize()
{
OnRefresh?.Invoke();
base.Initialize();
}
}
}
7 changes: 0 additions & 7 deletions Content.Client/Medical/Surgery/SurgeryWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,4 @@
<BoxContainer Name="Steps" Access="Public" Orientation="Vertical" Visible="False" />
</ScrollContainer>
</BoxContainer>
<PanelContainer Name="DisabledPanel" Access="Public" HorizontalExpand="True"
VerticalExpand="True" Visible="False">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#000000BF" />
</PanelContainer.PanelOverride>
<RichTextLabel Name="DisabledLabel" Access="Public" HorizontalAlignment="Center" />
</PanelContainer>
</controls:SurgeryWindow>
Loading

0 comments on commit 46a6c8a

Please sign in to comment.