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

Adds blinding + blindfolds #8688

Merged
merged 13 commits into from
Jul 12, 2022
2 changes: 2 additions & 0 deletions Content.Client/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Client.Chat.Managers;
using Content.Client.EscapeMenu;
using Content.Client.Eui;
using Content.Client.Eye.Blinding;
using Content.Client.Flash;
using Content.Client.GhostKick;
using Content.Client.HUD;
Expand Down Expand Up @@ -191,6 +192,7 @@ public override void PostInit()
overlayMgr.AddOverlay(new CircleMaskOverlay());
overlayMgr.AddOverlay(new FlashOverlay());
overlayMgr.AddOverlay(new RadiationPulseOverlay());
overlayMgr.AddOverlay(new BlindOverlay());

IoCManager.Resolve<IChatManager>().Initialize();
IoCManager.Resolve<IClientPreferencesManager>().Initialize();
Expand Down
69 changes: 69 additions & 0 deletions Content.Client/Eye/Blinding/BlindOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Content.Shared.Eye.Blinding;

namespace Content.Client.Eye.Blinding
{
public sealed class BlindOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] IEntityManager _entityManager = default!;
[Dependency] ILightManager _lightManager = default!;


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

private BlindableComponent _blindableComponent = default!;

public BlindOverlay()
{
IoCManager.InjectDependencies(this);
_greyscaleShader = _prototypeManager.Index<ShaderPrototype>("GreyscaleFullscreen").Instance().Duplicate();
_gradientCircleShader = _prototypeManager.Index<ShaderPrototype>("GradientCircleMask").Instance();
}
protected override bool BeforeDraw(in OverlayDrawArgs args)
{
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;

if (playerEntity == null)
return false;

if (!_entityManager.TryGetComponent<BlindableComponent>(playerEntity, out var blindComp))
return false;

_blindableComponent = blindComp;
return (blindComp.Sources > 0);
}

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

if (_blindableComponent.LightSetup) // Do we need to reset this?
{
_lightManager.Enabled = true;
_blindableComponent.LightSetup = false;
}

_blindableComponent.LightSetup = true; // Ok we touched the lights
_lightManager.Enabled = false;

_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);

var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;
worldHandle.SetTransform(Matrix3.Identity);
worldHandle.UseShader(_greyscaleShader);
worldHandle.DrawRect(viewport, Color.White);
worldHandle.UseShader(_gradientCircleShader);
worldHandle.DrawRect(viewport, Color.White);
}
}
}
3 changes: 2 additions & 1 deletion Content.Shared/Examine/ExamineSystemShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.DragDrop;
using Content.Shared.Interaction;
using Content.Shared.MobState.Components;
using Content.Shared.Eye.Blinding;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.Map;
Expand Down Expand Up @@ -96,7 +97,7 @@ public float GetExaminerRange(EntityUid examiner, MobStateComponent? mobState =
{
if (mobState.IsDead())
return DeadExamineRange;
else if (mobState.IsCritical())
else if (mobState.IsCritical() || (TryComp<BlindableComponent>(examiner, out var blind) && blind.Sources > 0))
return CritExamineRange;
}
return ExamineRange;
Expand Down
21 changes: 21 additions & 0 deletions Content.Shared/Eye/Blinding/BlindableComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Eye.Blinding
{
[RegisterComponent]
[NetworkedComponent]
public sealed class BlindableComponent : Component
{
/// <description>
/// How many sources of blindness are affecting us?
/// </description>
[DataField("sources")]
public int Sources = 0;

/// <description>
/// Used to ensure that this doesn't break with sandbox or admin tools.
/// This is not "enabled/disabled".
/// </description>
public bool LightSetup = false;
}
}
12 changes: 12 additions & 0 deletions Content.Shared/Eye/Blinding/BlindfoldComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Eye.Blinding
{
[RegisterComponent]
[NetworkedComponent]
public sealed class BlindfoldComponent : Component
{
[ViewVariables]
public bool IsActive = false;
}
}
40 changes: 40 additions & 0 deletions Content.Shared/Eye/Blinding/BlindingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Shared.Inventory.Events;
using Content.Shared.Inventory;
using Content.Shared.Item;

namespace Content.Shared.Eye.Blinding
{
public sealed class BlindingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlindfoldComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<BlindfoldComponent, GotUnequippedEvent>(OnUnequipped);
}

private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args)
{
if (!TryComp<SharedItemComponent>(uid, out var clothing) || clothing.SlotFlags == SlotFlags.PREVENTEQUIP) // we live in a society
return;
// Is the clothing in its actual slot?
if (!clothing.SlotFlags.HasFlag(args.SlotFlags))
return;

component.IsActive = true;
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
return;
blindComp.Sources++;
}

private void OnUnequipped(EntityUid uid, BlindfoldComponent component, GotUnequippedEvent args)
{
if (!component.IsActive)
return;
component.IsActive = false;
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
return;
blindComp.Sources--;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
ClothingUniformJumpsuitSecBlue: 3
ClothingHeadsetSecurity: 3
ClothingOuterWinterSec: 2
ClothingEyesBlindfold: 1
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
Gohei: 2
ClothingHeadPaperSack: 2
ClothingHeadPaperSackSmile: 2
ClothingEyesBlindfold: 1
emaggedInventory:
ClothingShoesBling: 1
15 changes: 15 additions & 0 deletions Resources/Prototypes/Entities/Clothing/Eyes/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@
sprite: Clothing/Eyes/Misc/eyepatch.rsi
- type: Clothing
sprite: Clothing/Eyes/Misc/eyepatch.rsi

- type: entity
parent: ClothingEyesBase
id: ClothingEyesBlindfold
name: blindfold
description: The bind leading the blind.
components:
- type: Sprite
sprite: Clothing/Eyes/Misc/blindfold.rsi
- type: Clothing
sprite: Clothing/Eyes/Misc/blindfold.rsi
- type: Blindfold
- type: Construction
graph: Blindfold
node: blindfold
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@
- WeaponFlareGun
- Spear
- LidSalami
- ClothingEyesBlindfold
chance: 0.6
offset: 0.0
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Species/human.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
- PressureImmunity
- Muted
- type: DiseaseCarrier
- type: Blindable
# Other
- type: Inventory
- type: Clickable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- type: constructionGraph
id: Blindfold
start: start
graph:
- node: start
edges:
- to: blindfold
steps:
- material: Cloth
amount: 3
doAfter: 10
- node: blindfold
entity: ClothingEyesBlindfold
13 changes: 13 additions & 0 deletions Resources/Prototypes/Recipes/Crafting/improvised.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@
icon:
sprite: Objects/Specific/Medical/medical.rsi
state: gauze

- type: construction
name: blindfold
id: blindfold
graph: Blindfold
startNode: start
targetNode: blindfold
category: Tools
objectType: Item
description: Better hope everyone turns a blind eye to you crafting this sussy item...
icon:
sprite: Clothing/Eyes/Misc/blindfold.rsi
state: icon
5 changes: 5 additions & 0 deletions Resources/Prototypes/Shaders/greyscale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
id: Greyscale
kind: source
path: "/Textures/Shaders/greyscale.swsl"

- type: shader
id: GreyscaleFullscreen
kind: source
path: "/Textures/Shaders/greyscale_fullscreen.swsl"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Resources/Textures/Clothing/Eyes/Misc/blindfold.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/40d89d11ea4a5cb81d61dc1018b46f4e7d32c62a",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
},
{
"name": "equipped-EYES",
"directions": 4
}
]
}
9 changes: 9 additions & 0 deletions Resources/Textures/Shaders/greyscale_fullscreen.swsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
uniform sampler2D SCREEN_TEXTURE;

void fragment() {
highp vec4 color = zTextureSpec(SCREEN_TEXTURE, UV);

highp float grey = dot(color.rgb, vec3(0.299, 0.587, 0.114));

COLOR = vec4(vec3(grey), color.a);
}