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

Added ClothingLimitVision Component #16

Closed
wants to merge 10 commits into from
Closed
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
2 changes: 2 additions & 0 deletions Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Clothing\Components\" />
<Folder Include="Spawners\" />
<Folder Include="_White\VisionLimit\Overlays\System\" />
Comment on lines +27 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Folder Include="Clothing\Components\" />
<Folder Include="Spawners\" />
<Folder Include="_White\VisionLimit\Overlays\System\" />
<Folder Include="Spawners\" />

Это тут зачем?

</ItemGroup>
<ItemGroup>
<Compile Update="Lobby\UI\LobbyCharacterPanel.xaml.cs">
Expand Down
53 changes: 53 additions & 0 deletions Content.Client/_White/VisionLimit/Overlays/VisionLimitOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;

namespace Content.Client._White.VisionLimit.Overlays

{
public sealed class VisionLimitOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

public float VisionLimitRadius;

public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _circleMaskShader;

public VisionLimitOverlay()
{
IoCManager.InjectDependencies(this);
_circleMaskShader = _prototypeManager.Index<ShaderPrototype>("CircleMask").InstanceUnique();
}

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;

var playerEntity = _playerManager.LocalSession?.AttachedEntity;

if (playerEntity == null)
return;

if (_entityManager.TryGetComponent<EyeComponent>(playerEntity, out var content))
{
_circleMaskShader.SetParameter("Zoom", content.Zoom.X);

_circleMaskShader.SetParameter("CircleRadius", 6.5f); // It's relative, close enough to
_circleMaskShader.SetParameter("CircleMinDist", VisionLimitRadius * 10); // 1 unit = 1 tile
}

var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;

worldHandle.UseShader(_circleMaskShader);
worldHandle.DrawRect(viewport, Color.White);
worldHandle.UseShader(null);
}
}
}
126 changes: 126 additions & 0 deletions Content.Client/_White/VisionLimit/Systems/VisionLimitSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Content.Client._White.VisionLimit.Overlays;
using Content.Shared._White.VisionLimit.Components;
using Content.Shared.Clothing;
using Content.Shared.Inventory.Events;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;

namespace Content.Client._White.VisionLimit.Systems;

public sealed class VisionLimitSystem : EntitySystem
{
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly IPlayerManager _player = default!;

private VisionLimitOverlay _overlay = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<VisionLimitComponent, ComponentInit>(OnCompInit);
SubscribeLocalEvent<VisionLimitComponent, ComponentShutdown>(OnCompShutdown);

SubscribeLocalEvent<VisionLimitComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<VisionLimitComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);

SubscribeLocalEvent<ClothingLimitVisionComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingLimitVisionComponent, GotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<ClothingLimitVisionComponent, ItemMaskToggledEvent>(OnMaskToggled);

_overlay = new();
_overlay.ZIndex = -2; // Draw under damage overlay etc.
}

// Player entity interactions

private void OnPlayerAttached(EntityUid uid, VisionLimitComponent component, LocalPlayerAttachedEvent args)
{
UpdateOverlay(component);
}

private void OnPlayerDetached(EntityUid uid, VisionLimitComponent component, LocalPlayerDetachedEvent args)
{
_overlayMan.RemoveOverlay(_overlay);
}

private void OnCompInit(EntityUid uid, VisionLimitComponent component, ComponentInit args)
{
if (_player.LocalEntity == uid)
UpdateOverlay(component);
}

private void OnCompShutdown(EntityUid uid, VisionLimitComponent component, ComponentShutdown args)
{
if (_player.LocalEntity == uid)
{
_overlayMan.RemoveOverlay(_overlay);
}
Comment on lines +56 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (_player.LocalEntity == uid)
{
_overlayMan.RemoveOverlay(_overlay);
}
if (_player.LocalEntity == uid)
_overlayMan.RemoveOverlay(_overlay);

Скобочки можно убрать

}

// Equipment interactions

private void OnGotEquipped(EntityUid uid, ClothingLimitVisionComponent comp, GotEquippedEvent args)
{
AddLimit(args.Equipee, comp);
}

private void OnGotUnequipped(EntityUid uid, ClothingLimitVisionComponent comp, GotUnequippedEvent args)
{
RemoveLimit(args.Equipee, comp);
}

private void OnMaskToggled(EntityUid uid, ClothingLimitVisionComponent comp, ItemMaskToggledEvent args)
{
if (!args.IsToggled && !args.IsEquip)
AddLimit(args.Wearer, comp);
else
RemoveLimit(args.Wearer, comp);
}

// Overlay handling

private void AddLimit(EntityUid uid, ClothingLimitVisionComponent limiter)
{
if (limiter.Radius == 0) // Radius 0 = no limit
return;

EnsureComp<VisionLimitComponent>(uid, out var comp);
comp.VisionLimiters.Add(limiter, limiter.Radius);
UpdateOverlay(comp);
}

private void RemoveLimit(EntityUid uid, ClothingLimitVisionComponent limiter)
{
if (TryComp<VisionLimitComponent>(uid, out var comp) && comp.VisionLimiters.ContainsKey(limiter))
{
comp.VisionLimiters.Remove(limiter);
UpdateOverlay(comp);

if (comp.VisionLimiters.Count == 0)
RemComp<VisionLimitComponent>(uid);
}

}

private void UpdateOverlay(VisionLimitComponent comp)
{
if (comp.VisionLimiters.Count > 0)
{
// Assign the smallest radius value from the VisionLimiters to the overlay
var min = 1337f;

foreach (var limiter in comp.VisionLimiters)
{
if (limiter.Value < min)
min = limiter.Value;
}
_overlay.VisionLimitRadius = min;

_overlayMan.AddOverlay(_overlay);
}
else
_overlayMan.RemoveOverlay(_overlay);
}
}
22 changes: 12 additions & 10 deletions Content.Shared/Clothing/EntitySystems/MaskSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,40 @@ private void OnGetActions(EntityUid uid, MaskComponent component, GetItemActions
private void OnToggleMask(Entity<MaskComponent> ent, ref ToggleMaskEvent args)
{
var (uid, mask) = ent;
if (mask.ToggleActionEntity == null || !_timing.IsFirstTimePredicted)
if (!_timing.IsFirstTimePredicted)
return;

if (!_inventorySystem.TryGetSlotEntity(args.Performer, "mask", out var existing) || !uid.Equals(existing))
return;

mask.IsToggled ^= true;
_actionSystem.SetToggled(mask.ToggleActionEntity, mask.IsToggled);

if (mask.IsToggled)
_popupSystem.PopupEntity(Loc.GetString("action-mask-pull-down-popup-message", ("mask", uid)), args.Performer, args.Performer);
else
_popupSystem.PopupEntity(Loc.GetString("action-mask-pull-up-popup-message", ("mask", uid)), args.Performer, args.Performer);
var dir = mask.IsToggled ? "down" : "up";
var msg = $"action-mask-pull-{dir}-popup-message";
_popupSystem.PopupClient(Loc.GetString(msg, ("mask", uid)), args.Performer, args.Performer);

ToggleMaskComponents(uid, mask, args.Performer, mask.EquippedPrefix);
}

// set to untoggled when unequipped, so it isn't left in a 'pulled down' state
private void OnGotUnequipped(EntityUid uid, MaskComponent mask, GotUnequippedEvent args)
{
if (mask.ToggleActionEntity == null)
if (!mask.IsToggled)
return;

mask.IsToggled = false;
Dirty(uid, mask);
_actionSystem.SetToggled(mask.ToggleActionEntity, mask.IsToggled);

ToggleMaskComponents(uid, mask, args.Equipee, mask.EquippedPrefix, true);
}

/// <summary>
/// Called after setting IsToggled, raises events and dirties.
/// <summary>
private void ToggleMaskComponents(EntityUid uid, MaskComponent mask, EntityUid wearer, string? equippedPrefix = null, bool isEquip = false)
{
Dirty(uid, mask);
if (mask.ToggleActionEntity is {} action)
_actionSystem.SetToggled(action, mask.IsToggled);

var maskEv = new ItemMaskToggledEvent(wearer, equippedPrefix, mask.IsToggled, isEquip);
RaiseLocalEvent(uid, ref maskEv);

Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Content.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ProjectReference Include="..\RobustToolbox\Lidgren.Network\Lidgren.Network.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этого тут тоже быть не должно

<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj">
<Private>false</Private>
</ProjectReference>
Expand All @@ -25,6 +26,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="DeltaV\Abilities\" />
<Folder Include="_White\VisionLimit\" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это тут лишние

</ItemGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<Import Project="..\RobustToolbox\MSBuild\Robust.CompNetworkGenerator.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Robust.Shared.GameStates;

namespace Content.Shared._White.VisionLimit.Components;

[NetworkedComponent, RegisterComponent, AutoGenerateComponentState]
public sealed partial class ClothingLimitVisionComponent: Component
{
/// <summary>
/// Limits wearer's vision to roughly Radius tiles
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Radius; // in tiles, 0 = no limit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Shared._White.VisionLimit.Components;

[RegisterComponent]
public sealed partial class VisionLimitComponent: Component
{
/// <summary>
/// Stores values of limits applied to an entity by any VisionLimiterComponent
/// </summary>

[DataField]
public Dictionary<ClothingLimitVisionComponent, float> VisionLimiters { get; set; } = new();

}
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Clothing/Head/welding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- type: Item
storedRotation: 0
- type: IngestionBlocker
- type: Mask
- type: ClothingLimitVision
radius: 6
Comment on lines +10 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- type: Mask
- type: ClothingLimitVision
radius: 6
- type: Mask # WD EDIT
- type: ClothingLimitVision # WD EDIT
radius: 6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Радиус слишком большой, 3 будет лучше, тк от 3х до 6 не должно быть видно нормально, в этом радиусе должно быть размытие какое-то или затемление

- type: FlashImmunity
- type: IdentityBlocker
- type: EyeProtection
Expand Down
Loading