Skip to content

Commit

Permalink
Add hologram shader (#68)
Browse files Browse the repository at this point in the history
* Add holograms!

* Updated localization files
  • Loading branch information
DebugOk committed Oct 8, 2023
1 parent edc6d76 commit 50e9bfd
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Content.Client/DeltaV/Hologram/HologramSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Content.Shared.DeltaV.Hologram;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;

namespace Content.Client.DeltaV.Hologram;

public sealed class HologramSystem : SharedHologramSystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly OccluderSystem _occluder = default!;
[Dependency] private readonly EntityManager _entMan = default!;

private ShaderInstance _shader = default!;

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

_shader = _protoMan.Index<ShaderPrototype>("Hologram").InstanceUnique();
SubscribeLocalEvent<HologramComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<HologramComponent, ComponentStartup>(OnStartup);
}

private void SetShader(EntityUid uid, bool enabled, HologramComponent? component = null, SpriteComponent? sprite = null)
{
if (!Resolve(uid, ref component, ref sprite, false))
return;

sprite.PostShader = enabled ? _shader : null;
}

private void OnStartup(EntityUid uid, HologramComponent component, ComponentStartup args)
{
SetShader(uid, true, component);

component.Occludes = _entMan.TryGetComponent<OccluderComponent>(uid, out var occluder) && occluder.Enabled;
if (component.Occludes)
_occluder.SetEnabled(uid, false);
}

private void OnShutdown(EntityUid uid, HologramComponent component, ComponentShutdown args)
{
SetShader(uid, false, component);
if (component.Occludes)
_occluder.SetEnabled(uid, true);
}
}
43 changes: 43 additions & 0 deletions Content.Server/DeltaV/Hologram/HologramSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Content.Shared.Actions.Events;
using Content.Shared.DeltaV.Hologram;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Popups;
using Robust.Shared.Player;

namespace Content.Server.DeltaV.Hologram;

public sealed class HologramSystem : SharedHologramSystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<HologramComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<HologramComponent, DisarmAttemptEvent>(OnDisarmAttempt);
}

private void OnExamine(EntityUid uid, HologramComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("hologram-on-examine"));
}

private void OnDisarmAttempt(EntityUid uid, HologramComponent component, DisarmAttemptEvent args)
{
if (component.PreventDisarm)
{
args.Cancel();

var filterOther = Filter.PvsExcept(args.DisarmerUid, entityManager: EntityManager);
var messageUser = Loc.GetString("hologram-disarm-blocked",
("target", Identity.Entity(args.TargetUid, EntityManager)));
var messageOther = Loc.GetString("hologram-disarm-blocked-other",
("target", Identity.Entity(args.TargetUid, EntityManager)), ("performerName", args.DisarmerUid));

_popup.PopupEntity(messageOther, args.DisarmerUid, filterOther, true);
_popup.PopupEntity(messageUser, args.TargetUid, args.DisarmerUid);
}

}
}
21 changes: 21 additions & 0 deletions Content.Shared/DeltaV/Hologram/HologramComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Robust.Shared.GameStates;

namespace Content.Shared.DeltaV.Hologram;

[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedHologramSystem))]
public sealed partial class HologramComponent : Component
{
/// <summary>
/// To save the state of whatever the component was added to, in case it occludes when the component is added.
/// </summary>
[DataField("occludes")]
public bool Occludes = false;

/// <summary>
/// Do we stop disarms or not?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("preventDisarm")]
public bool PreventDisarm = false;
}
5 changes: 5 additions & 0 deletions Content.Shared/DeltaV/Hologram/SharedHologramSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Content.Shared.DeltaV.Hologram;

public abstract class SharedHologramSystem : EntitySystem
{
}
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/deltav/hologram/hologram.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hologram-on-examine = [color=lightblue]It is but a transient specter...[/color]
hologram-disarm-blocked = Your hand phases through {THE($target)}.
hologram-disarm-blocked-other = {THE($performerName)}'s hand phases through {THE($target)}.
8 changes: 8 additions & 0 deletions Resources/Prototypes/DeltaV/shaders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# hologram
- type: shader
id: Hologram
kind: source
path: "/Textures/DeltaV/Shaders/hologram.swsl"
params:
textureHeight: 32
hue: 0.64
Loading

0 comments on commit 50e9bfd

Please sign in to comment.