From 11051091522301f89f1710bcc9093d1f4cf3fa64 Mon Sep 17 00:00:00 2001 From: Aviu00 <93730715+Aviu00@users.noreply.github.com> Date: Wed, 7 Feb 2024 00:40:41 +0900 Subject: [PATCH] - add: Toggleable night vision (#31) * - add: Toggleable night vision * - add: Add death squad huds & night vision --- .../_White/Overlays/NightVisionSystem.cs | 35 +++++---------- .../_Miracle/Systems/NightVisionSystem.cs | 7 +++ .../Systems/SharedNightVisionSystem.cs | 44 +++++++++++++++++++ .../_White/Overlays/NightVisionComponent.cs | 27 ++++++++++-- .../Locale/ru-RU/_miracle/night_vision.ftl | 2 + .../Entities/Clothing/Eyes/glasses.yml | 3 ++ .../Clothing/Head/hardsuit-helmets.yml | 7 +++ Resources/Prototypes/White/Actions/types.yml | 14 ++++++ .../_White/Entities/Cult/Items/tome_craft.yml | 2 + 9 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 Content.Server/_Miracle/Systems/NightVisionSystem.cs create mode 100644 Content.Shared/_Miracle/Systems/SharedNightVisionSystem.cs create mode 100644 Resources/Locale/ru-RU/_miracle/night_vision.ftl diff --git a/Content.Client/_White/Overlays/NightVisionSystem.cs b/Content.Client/_White/Overlays/NightVisionSystem.cs index d4ff8198ef..57fde51804 100644 --- a/Content.Client/_White/Overlays/NightVisionSystem.cs +++ b/Content.Client/_White/Overlays/NightVisionSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared._Miracle.Systems; using Content.Shared.GameTicking; using Content.Shared._White.Overlays; using Robust.Client.Graphics; @@ -6,7 +7,7 @@ using Robust.Shared.Player; namespace Content.Client._White.Overlays; -public sealed class NightVisionSystem : EntitySystem +public sealed class NightVisionSystem : SharedNightVisionSystem { [Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IOverlayManager _overlayMan = default!; @@ -18,9 +19,6 @@ public sealed class NightVisionSystem : EntitySystem { base.Initialize(); - SubscribeLocalEvent(OnInit); - SubscribeLocalEvent(OnRemove); - SubscribeLocalEvent(OnPlayerAttached); SubscribeLocalEvent(OnPlayerDetached); SubscribeLocalEvent(OnRestart); @@ -30,38 +28,25 @@ public sealed class NightVisionSystem : EntitySystem private void OnPlayerAttached(EntityUid uid, NightVisionComponent component, PlayerAttachedEvent args) { - if (_player.LocalSession != args.Player) - return; - - _overlayMan.AddOverlay(_overlay); - _lightManager.DrawLighting = false; + UpdateNightVision(uid, component.IsActive); } private void OnPlayerDetached(EntityUid uid, NightVisionComponent component, PlayerDetachedEvent args) { - if (_player.LocalSession != args.Player) - return; - - _overlayMan.RemoveOverlay(_overlay); - _lightManager.DrawLighting = true; + UpdateNightVision(uid, false); } - private void OnInit(EntityUid uid, NightVisionComponent component, ComponentInit args) + protected override void UpdateNightVision(EntityUid uid, bool active) { if (_player.LocalSession?.AttachedEntity != uid) return; - _overlayMan.AddOverlay(_overlay); - _lightManager.DrawLighting = false; - } + if (active) + _overlayMan.AddOverlay(_overlay); + else + _overlayMan.RemoveOverlay(_overlay); - private void OnRemove(EntityUid uid, NightVisionComponent component, ComponentRemove args) - { - if (_player.LocalSession?.AttachedEntity != uid) - return; - - _overlayMan.RemoveOverlay(_overlay); - _lightManager.DrawLighting = true; + _lightManager.DrawLighting = !active; } private void OnRestart(RoundRestartCleanupEvent ev) diff --git a/Content.Server/_Miracle/Systems/NightVisionSystem.cs b/Content.Server/_Miracle/Systems/NightVisionSystem.cs new file mode 100644 index 0000000000..7575cd518e --- /dev/null +++ b/Content.Server/_Miracle/Systems/NightVisionSystem.cs @@ -0,0 +1,7 @@ +using Content.Shared._Miracle.Systems; + +namespace Content.Server._Miracle.Systems; + +public sealed class NightVisionSystem : SharedNightVisionSystem +{ +} diff --git a/Content.Shared/_Miracle/Systems/SharedNightVisionSystem.cs b/Content.Shared/_Miracle/Systems/SharedNightVisionSystem.cs new file mode 100644 index 0000000000..860fe42c3a --- /dev/null +++ b/Content.Shared/_Miracle/Systems/SharedNightVisionSystem.cs @@ -0,0 +1,44 @@ +using Content.Shared._White.Overlays; +using Content.Shared.Actions; +using Robust.Shared.Audio.Systems; + +namespace Content.Shared._Miracle.Systems; + +public abstract class SharedNightVisionSystem : EntitySystem +{ + [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedActionsSystem _actions = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnToggle); + SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnRemove); + } + + private void OnRemove(EntityUid uid, NightVisionComponent component, ComponentRemove args) + { + _actions.RemoveAction(uid, component.ToggleActionEntity); + UpdateNightVision(uid, false); + } + + private void OnInit(EntityUid uid, NightVisionComponent component, ComponentInit args) + { + _actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction); + UpdateNightVision(uid, component.IsActive); + } + + protected virtual void UpdateNightVision(EntityUid uid, bool active) { } + + private void OnToggle(EntityUid uid, NightVisionComponent component, ToggleNightVisionEvent args) + { + component.IsActive = !component.IsActive; + _audio.PlayPredicted(component.ToggleSound, uid, uid); + UpdateNightVision(uid, component.IsActive); + Dirty(uid, component); + + args.Handled = true; + } +} diff --git a/Content.Shared/_White/Overlays/NightVisionComponent.cs b/Content.Shared/_White/Overlays/NightVisionComponent.cs index 0e1e385370..54f0baeea6 100644 --- a/Content.Shared/_White/Overlays/NightVisionComponent.cs +++ b/Content.Shared/_White/Overlays/NightVisionComponent.cs @@ -1,19 +1,38 @@ +using Content.Shared.Actions; +using Robust.Shared.Audio; using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; namespace Content.Shared._White.Overlays; [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class NightVisionComponent : Component { - [DataField("tint"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public Vector3 Tint = new(0.3f, 0.3f, 0.3f); - [DataField("strength"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public float Strength = 2f; - [DataField("noise"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public float Noise = 0.5f; - [DataField("color"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public Color Color = Color.FromHex("#98FB98"); + + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public bool IsActive = true; + + [DataField] + public SoundSpecifier? ToggleSound = new SoundPathSpecifier("/Audio/Items/flashlight_pda.ogg"); + + [DataField] + public EntProtoId? ToggleAction = "ToggleNightVision"; + + [ViewVariables] + public EntityUid? ToggleActionEntity; +} + +public sealed partial class ToggleNightVisionEvent : InstantActionEvent +{ } diff --git a/Resources/Locale/ru-RU/_miracle/night_vision.ftl b/Resources/Locale/ru-RU/_miracle/night_vision.ftl new file mode 100644 index 0000000000..7d06b922a6 --- /dev/null +++ b/Resources/Locale/ru-RU/_miracle/night_vision.ftl @@ -0,0 +1,2 @@ +ent-ToggleNightVision = Переключить ночное зрение + .desc = Переключает ночное зрение. diff --git a/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml b/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml index 40ed325a7a..0f74f8f67e 100644 --- a/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml +++ b/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml @@ -248,6 +248,9 @@ - type: Clothing sprite: Clothing/Eyes/Glasses/ninjavisor.rsi - type: FlashImmunity + - type: ClothingGrantComponent + component: + - type: NightVision - type: entity parent: ClothingEyesBase diff --git a/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml b/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml index 75594bc462..eadcc8d137 100644 --- a/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml +++ b/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml @@ -767,6 +767,13 @@ Caustic: 0.95 - type: FlashImmunity # WD edit - type: EyeProtection # WD edit + - type: ShowHealthIcons + damageContainers: + - Biological + - type: ClothingGrantComponent + component: + - type: NightVision + - type: ShowWhiteHealthBars #MISC. HARDSUITS #Clown Hardsuit diff --git a/Resources/Prototypes/White/Actions/types.yml b/Resources/Prototypes/White/Actions/types.yml index 25f9ce71b9..30dedb1017 100644 --- a/Resources/Prototypes/White/Actions/types.yml +++ b/Resources/Prototypes/White/Actions/types.yml @@ -27,3 +27,17 @@ sprite: White/Objects/Weapons/hardlight_spear.rsi state: spear event: !type:ActivateHardlightSpearImplantEvent + +- type: entity + id: ToggleNightVision + name: Toggle night vision. + description: Toggles night vision. + noSpawn: true + components: + - type: InstantAction + itemIconStyle: BigAction + priority: -20 + icon: + sprite: White/Clothing/Head/nightvision.rsi + state: icon + event: !type:ToggleNightVisionEvent diff --git a/Resources/Prototypes/_White/Entities/Cult/Items/tome_craft.yml b/Resources/Prototypes/_White/Entities/Cult/Items/tome_craft.yml index 9dfc5551b7..bd532120f0 100644 --- a/Resources/Prototypes/_White/Entities/Cult/Items/tome_craft.yml +++ b/Resources/Prototypes/_White/Entities/Cult/Items/tome_craft.yml @@ -40,6 +40,8 @@ - type: ClothingGrantComponent component: - type: NightVision + toggleAction: null + toggleSound: null color: White - type: ShowWhiteHealthBars damageContainers: