Skip to content

Commit

Permalink
Merge pull request Simple-Station#21 from gluesniffler/SHITMED
Browse files Browse the repository at this point in the history
Mocho Shitmed Release 1
  • Loading branch information
Eagle-0 authored Oct 6, 2024
2 parents 929b4a7 + 9ba5958 commit e41af3c
Show file tree
Hide file tree
Showing 28 changed files with 487 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:hotbar="clr-namespace:Content.Client.UserInterface.Systems.Hotbar.Widgets"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets"
xmlns:targeting="clr-namespace:Content.Client.UserInterface.Systems.Targeting.Widgets"
Name="DefaultHud"
VerticalExpand="False"
VerticalAlignment="Bottom"
Expand All @@ -28,6 +29,7 @@
<widgets:GhostGui Name="Ghost" Access="Protected" />
<inventory:InventoryGui Name="Inventory" Access="Protected" />
<hotbar:HotbarGui Name="Hotbar" Access="Protected" />
<targeting:TargetingControl Name="Targeting" Access="Protected"/>
<chat:ResizableChatBox Name="Chat" Access="Protected" />
<alerts:AlertsUI Name="Alerts" Access="Protected" />
</screens:OverlayChatGameScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public OverlayChatGameScreen()
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
SetAnchorAndMarginPreset(Chat, LayoutPreset.TopRight, margin: 10);
SetAnchorAndMarginPreset(Alerts, LayoutPreset.TopRight, margin: 10);
SetAnchorAndMarginPreset(Targeting, LayoutPreset.BottomRight, margin: 10);

Chat.OnResized += ChatOnResized;
Chat.OnChatResizeFinish += ChatOnResizeFinish;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets"
xmlns:targeting="clr-namespace:Content.Client.UserInterface.Systems.Targeting.Widgets"
Name="SeparatedChatHud"
VerticalExpand="False"
VerticalAlignment="Bottom"
Expand All @@ -20,6 +21,7 @@
<widgets:GhostGui Name="Ghost" Access="Protected" />
<inventory:InventoryGui Name="Inventory" Access="Protected"/>
<hotbar:HotbarGui Name="Hotbar" Access="Protected"/>
<targeting:TargetingControl Name="Targeting" Access="Protected"/>
<BoxContainer Name="TopLeftContainer" Orientation="Vertical">
<actions:ActionsBar Name="Actions" Access="Protected" />
<BoxContainer Name="VoteMenu" Access="Public" Orientation="Vertical"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SeparatedChatGameScreen()
SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
SetAnchorAndMarginPreset(Alerts, LayoutPreset.CenterRight, margin: 10);

SetAnchorAndMarginPreset(Targeting, LayoutPreset.BottomRight, margin: 10);
ScreenContainer.OnSplitResizeFinished += () =>
OnChatResized?.Invoke(new Vector2(ScreenContainer.SplitFraction, 0));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.UserInterface.Systems.Targeting.Widgets;
using Content.Shared.Targeting;
using Content.Shared.Targeting.Events;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Utility;
using Robust.Client.Player;

namespace Content.Client.UserInterface.Systems.Targeting;

public sealed class TargetingUIController : UIController
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IEntityNetworkManager _net = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private SpriteSystem _spriteSystem = default!;
private TargetBodyPart _currentTarget = TargetBodyPart.Torso; // Default to torso

public override void Initialize()
{
base.Initialize();
var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
}

private void OnScreenLoad()
{
_spriteSystem = _entManager.System<SpriteSystem>();
}

public void CycleTarget(TargetingControl control)
{
if (_playerManager.LocalEntity is not { } user)
return;

var player = _entManager.GetNetEntity(user);
_currentTarget = (TargetBodyPart) (((int) _currentTarget + 1) % Enum.GetValues(typeof(TargetBodyPart)).Length);
var msg = new TargetChangeEvent(player, _currentTarget);
_net.SendSystemNetworkMessage(msg);
UpdateVisuals(control);
}

public void UpdateVisuals(TargetingControl control)
{
var stateName = $"doll-{_currentTarget.ToString().ToLowerInvariant()}";
var spriteSpecifier = new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Targeting/bodydoll.rsi"), stateName);
control.SetTargetImage(_spriteSystem.Frame0(spriteSpecifier));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<widgets:TargetingControl
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Targeting.Widgets"
Name="TargetingButton"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
>
<Control>
<TextureButton
Name="TargetImage"
TexturePath="/Textures/Interface/Targeting/bodydoll.rsi/doll.png"
MouseFilter="Stop"
Scale="2.5 2.5"
/>
</Control>
</widgets:TargetingControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.UserInterface.Systems.Targeting.Widgets;

[GenerateTypedNameReferences]
public sealed partial class TargetingControl : UIWidget
{
private readonly TargetingUIController _controller;

public TargetingControl()
{
RobustXamlLoader.Load(this);
_controller = UserInterfaceManager.GetUIController<TargetingUIController>();
TargetImage.OnPressed += OnTargetImagePressed;
}
private void OnTargetImagePressed(BaseButton.ButtonEventArgs args)
{
_controller.CycleTarget(this);
}

public void SetTargetImage(Texture texture)
{
TargetImage.TextureNormal = texture;
}

}
3 changes: 3 additions & 0 deletions Content.Server/Body/Systems/BodySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Body.Systems;
using Content.Shared.Damage;
using Content.Shared.Humanoid;
using Content.Shared.Mind;
using Content.Shared.Mobs.Systems;
Expand All @@ -22,6 +23,7 @@ public sealed class BodySystem : SharedBodySystem
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
Expand Down Expand Up @@ -98,6 +100,7 @@ protected override void RemovePart(
var layers = HumanoidVisualLayersExtension.Sublayers(layer.Value);
_humanoidSystem.SetLayersVisibility(
bodyEnt, layers, visible: false, permanent: true, humanoid);
_appearance.SetData(bodyEnt, layer, true);
}

public override HashSet<EntityUid> GibBody(
Expand Down
27 changes: 27 additions & 0 deletions Content.Server/Targeting/TargetingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.Targeting;
using Content.Shared.Targeting.Events;
using Robust.Server.Audio;
using Robust.Shared.Audio;

namespace Content.Server.Targeting;
public sealed class TargetingSystem : SharedTargetingSystem
{
[Dependency] private readonly AudioSystem _audio = default!;

public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<TargetChangeEvent>(OnTargetChange);
}

private void OnTargetChange(TargetChangeEvent message, EntitySessionEventArgs args)
{
if (!TryComp<TargetingComponent>(GetEntity(message.Uid), out var target))
return;

// Todo, get a better sound for this shit.
//_audio.PlayGlobal(target.SwapSound, args.SenderSession, AudioParams.Default.WithVolume(-8f));
target.Target = message.BodyPart;
Dirty(GetEntity(message.Uid), target);
}
}
18 changes: 17 additions & 1 deletion Content.Shared/Body/Part/BodyPartComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public sealed partial class BodyPartComponent : Component
[DataField, AutoNetworkedField]
public EntityUid? Body;

[DataField, AutoNetworkedField]
public EntityUid? OriginalBody;

[DataField, AutoNetworkedField]
public BodyPartSlot? ParentSlot;

[DataField, AutoNetworkedField]
public BodyPartType PartType = BodyPartType.Other;

Expand All @@ -43,6 +49,12 @@ public sealed partial class BodyPartComponent : Component
[DataField, AutoNetworkedField]
public Dictionary<string, OrganSlot> Organs = new();

/// <summary>
/// How much health the body part has until it pops out.
/// </summary>
[DataField, AutoNetworkedField]
public float Integrity = 100f;

/// <summary>
/// These are only for VV/Debug do not use these for gameplay/systems
/// </summary>
Expand Down Expand Up @@ -90,11 +102,15 @@ public partial struct BodyPartSlot
{
public string Id;
public BodyPartType Type;
public NetEntity? Child;
public NetEntity? Parent;

public BodyPartSlot(string id, BodyPartType type)
public BodyPartSlot(string id, BodyPartType type, NetEntity? child = null, NetEntity? parent = null)
{
Id = id;
Type = type;
Child = child;
Parent = parent;
}
};

Expand Down
23 changes: 22 additions & 1 deletion Content.Shared/Body/Systems/SharedBodySystem.Body.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Shared.Body.Organ;
using Content.Shared.Body.Part;
using Content.Shared.Body.Prototypes;
using Content.Shared.Damage;
using Content.Shared.DragDrop;
using Content.Shared.Gibbing.Components;
using Content.Shared.Gibbing.Events;
Expand All @@ -14,6 +15,7 @@
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Utility;
using Robust.Shared.Timing;

namespace Content.Shared.Body.Systems;

Expand All @@ -29,7 +31,7 @@ public partial class SharedBodySystem
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly GibbingSystem _gibbingSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;

[Dependency] private readonly IGameTiming _gameTiming = default!;
private const float GibletLaunchImpulse = 8;
private const float GibletLaunchImpulseVariance = 3;

Expand All @@ -42,6 +44,7 @@ private void InitializeBody()
SubscribeLocalEvent<BodyComponent, ComponentInit>(OnBodyInit);
SubscribeLocalEvent<BodyComponent, MapInitEvent>(OnBodyMapInit);
SubscribeLocalEvent<BodyComponent, CanDragEvent>(OnBodyCanDrag);
SubscribeLocalEvent<BodyComponent, DamageChangedEvent>(OnDamageChanged);
}

private void OnBodyInserted(Entity<BodyComponent> ent, ref EntInsertedIntoContainerMessage args)
Expand Down Expand Up @@ -127,6 +130,23 @@ private void OnBodyCanDrag(Entity<BodyComponent> ent, ref CanDragEvent args)
args.Handled = true;
}

private void OnDamageChanged(Entity<BodyComponent> ent, ref DamageChangedEvent args)
{
if (ent.Comp is null
|| args.TargetPart is null
|| args.DamageDelta is null
|| !args.DamageIncreased)
return;

var (targetType, targetSymmetry) = ConvertTargetBodyPart(args.TargetPart.Value);
var targetPart = GetBodyChildrenOfType(ent, targetType, ent.Comp)
.FirstOrDefault(part => part.Component.Symmetry == targetSymmetry);
if (targetPart.Id != default && _gameTiming.IsFirstTimePredicted)
{
ApplyPartDamage(targetPart, args.DamageDelta, targetType);
}
}

/// <summary>
/// Sets up all of the relevant body parts for a particular body entity and root part.
/// </summary>
Expand Down Expand Up @@ -168,6 +188,7 @@ private void MapInitParts(EntityUid rootPartId, BodyPrototype prototype)

var childPartComponent = Comp<BodyPartComponent>(childPart);
var partSlot = CreatePartSlot(parentEntity, connection, childPartComponent.PartType, parentPartComponent);
childPartComponent.ParentSlot = partSlot;
var cont = Containers.GetContainer(parentEntity, GetPartSlotContainerId(connection));

if (partSlot is null || !Containers.Insert(childPart, cont))
Expand Down
Loading

0 comments on commit e41af3c

Please sign in to comment.