-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from all commits
cd9a247
07f1d4f
5475dd3
f9a50b0
043dad7
74941fd
c82a740
2de7c55
9d9ce59
65fc8ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Скобочки можно убрать |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// 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); | ||||||||||||||
} | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
<ProjectReference Include="..\RobustToolbox\Lidgren.Network\Lidgren.Network.csproj"> | ||
<Private>false</Private> | ||
</ProjectReference> | ||
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -25,6 +26,7 @@ | |
</ItemGroup> | ||
<ItemGroup> | ||
<Folder Include="DeltaV\Abilities\" /> | ||
<Folder Include="_White\VisionLimit\" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" /> | ||
|
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(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,9 @@ | |||||||||||||
- type: Item | ||||||||||||||
storedRotation: 0 | ||||||||||||||
- type: IngestionBlocker | ||||||||||||||
- type: Mask | ||||||||||||||
- type: ClothingLimitVision | ||||||||||||||
radius: 6 | ||||||||||||||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Радиус слишком большой, 3 будет лучше, тк от 3х до 6 не должно быть видно нормально, в этом радиусе должно быть размытие какое-то или затемление |
||||||||||||||
- type: FlashImmunity | ||||||||||||||
- type: IdentityBlocker | ||||||||||||||
- type: EyeProtection | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это тут зачем?