Files
ss14-wl/Content.Client/Holopad/HolopadSystem.cs
lzk228 0af3e04fd8 Merge commit '3551eb04115854cdbbf1841f5960c3cdbc508583' into 02-19-upstream
# Conflicts:
#	Content.Server/Administration/Systems/AdminSystem.cs
#	Content.Server/Doors/Systems/AirlockSystem.cs
#	Content.Server/Holopad/HolopadSystem.cs
#	Content.Server/Humanoid/Systems/HumanoidAppearanceSystem.cs
#	Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
#	Resources/Prototypes/Catalog/VendingMachines/Inventories/curadrobe.yml
#	Resources/Prototypes/Datasets/Names/borg.yml
#	Resources/Prototypes/Datasets/ion_storm.yml
#	Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml
#	Resources/Prototypes/Entities/Clothing/Neck/mantles.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml
#	Resources/Prototypes/Entities/Stations/base.yml
#	Resources/Prototypes/Entities/Structures/Machines/lathe.yml
#	Resources/Prototypes/Maps/amber.yml
#	Resources/Prototypes/Maps/box.yml
#	Resources/Prototypes/Maps/convex.yml
#	Resources/Prototypes/Maps/fland.yml
#	Resources/Prototypes/Maps/meta.yml
#	Resources/Prototypes/Maps/plasma.yml
#	Resources/ServerInfo/Guidebook/Engineering/AME.xml
#	Resources/ServerInfo/Guidebook/Engineering/AirlockSecurity.xml
#	Resources/ServerInfo/Guidebook/Engineering/Atmospherics.xml
#	Resources/ServerInfo/Guidebook/Engineering/Construction.xml
#	Resources/ServerInfo/Guidebook/Engineering/Engineering.xml
#	Resources/ServerInfo/Guidebook/Engineering/Fires.xml
#	Resources/ServerInfo/Guidebook/Engineering/NetworkConfigurator.xml
#	Resources/ServerInfo/Guidebook/Engineering/Networking.xml
#	Resources/ServerInfo/Guidebook/Engineering/PortableGenerator.xml
#	Resources/ServerInfo/Guidebook/Engineering/Power.xml
#	Resources/ServerInfo/Guidebook/Engineering/RTG.xml
#	Resources/ServerInfo/Guidebook/Engineering/Shuttlecraft.xml
#	Resources/ServerInfo/Guidebook/Engineering/Singularity.xml
#	Resources/ServerInfo/Guidebook/Engineering/TEG.xml
#	Resources/ServerInfo/Guidebook/NewPlayer/Controls/Controls.xml
#	Resources/Textures/Clothing/Head/Helmets/paramedhelm.rsi/icon.png
#	Resources/Textures/Clothing/Head/Helmets/paramedhelm.rsi/inhand-left.png
#	Resources/Textures/Clothing/Head/Helmets/paramedhelm.rsi/inhand-right.png
#	Resources/Textures/Clothing/OuterClothing/Hardsuits/goliath.rsi/meta.json
#	Resources/Textures/Clothing/OuterClothing/Hardsuits/paramed.rsi/meta.json
#	Resources/Textures/Clothing/OuterClothing/Vests/hazard.rsi/equipped-OUTERCLOTHING.png
#	Resources/Textures/Clothing/OuterClothing/Vests/hazard.rsi/icon.png
#	Resources/Textures/Clothing/OuterClothing/Vests/hazard.rsi/meta.json
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/ancient.rsi/meta.json
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/security_trooper.rsi/inhand-right.png
#	Resources/Textures/Interface/Actions/actions_fakemindshield.rsi/icon-on.png
#	Resources/Textures/Objects/Storage/Briefcases/briefcase_brown.rsi/icon.png
#	Resources/Textures/Objects/Storage/Briefcases/briefcase_brown.rsi/meta.json
#	Resources/Textures/Objects/Storage/boxes.rsi/beaker.png
#	Resources/Textures/Objects/Storage/boxes.rsi/bodybags.png
#	Resources/Textures/Objects/Storage/boxes.rsi/bottle.png
#	Resources/Textures/Objects/Storage/boxes.rsi/box.png
#	Resources/Textures/Objects/Storage/boxes.rsi/box_hug.png
#	Resources/Textures/Objects/Storage/boxes.rsi/box_of_doom.png
#	Resources/Textures/Objects/Storage/boxes.rsi/box_of_doom_big.png
#	Resources/Textures/Objects/Storage/boxes.rsi/box_science.png
#	Resources/Textures/Objects/Storage/boxes.rsi/box_security.png
#	Resources/Textures/Objects/Storage/boxes.rsi/boxwide.png
#	Resources/Textures/Objects/Storage/boxes.rsi/boxwidetoy.png
#	Resources/Textures/Objects/Storage/boxes.rsi/candle.png
#	Resources/Textures/Objects/Storage/boxes.rsi/circuit.png
#	Resources/Textures/Objects/Storage/boxes.rsi/clown.png
#	Resources/Textures/Objects/Storage/boxes.rsi/darts.png
#	Resources/Textures/Objects/Storage/boxes.rsi/disk.png
#	Resources/Textures/Objects/Storage/boxes.rsi/emergencytank.png
#	Resources/Textures/Objects/Storage/boxes.rsi/encryptokey.png
#	Resources/Textures/Objects/Storage/boxes.rsi/evidence_markers.png
#	Resources/Textures/Objects/Storage/boxes.rsi/extendedtank.png
#	Resources/Textures/Objects/Storage/boxes.rsi/flare.png
#	Resources/Textures/Objects/Storage/boxes.rsi/flashbang.png
#	Resources/Textures/Objects/Storage/boxes.rsi/forensic.png
#	Resources/Textures/Objects/Storage/boxes.rsi/glasses.png
#	Resources/Textures/Objects/Storage/boxes.rsi/handcuff.png
#	Resources/Textures/Objects/Storage/boxes.rsi/headset.png
#	Resources/Textures/Objects/Storage/boxes.rsi/heart.png
#	Resources/Textures/Objects/Storage/boxes.rsi/holo.png
#	Resources/Textures/Objects/Storage/boxes.rsi/implant.png
#	Resources/Textures/Objects/Storage/boxes.rsi/inflatable.png
#	Resources/Textures/Objects/Storage/boxes.rsi/internals.png
#	Resources/Textures/Objects/Storage/boxes.rsi/latex.png
#	Resources/Textures/Objects/Storage/boxes.rsi/light.png
#	Resources/Textures/Objects/Storage/boxes.rsi/lightmixed.png
#	Resources/Textures/Objects/Storage/boxes.rsi/lighttube.png
#	Resources/Textures/Objects/Storage/boxes.rsi/magazine.png
#	Resources/Textures/Objects/Storage/boxes.rsi/meson.png
#	Resources/Textures/Objects/Storage/boxes.rsi/meta.json
#	Resources/Textures/Objects/Storage/boxes.rsi/mousetraps.png
#	Resources/Textures/Objects/Storage/boxes.rsi/nitrile.png
#	Resources/Textures/Objects/Storage/boxes.rsi/omegacart.png
#	Resources/Textures/Objects/Storage/boxes.rsi/pda.png
#	Resources/Textures/Objects/Storage/boxes.rsi/pillbox.png
#	Resources/Textures/Objects/Storage/boxes.rsi/sechud.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shellbeanbag.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shellflare.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shellflash.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shellincendiary.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shelllethal.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shellpractice.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shellslug.png
#	Resources/Textures/Objects/Storage/boxes.rsi/shelltoy.png
#	Resources/Textures/Objects/Storage/boxes.rsi/solution_trays.png
#	Resources/Textures/Objects/Storage/boxes.rsi/sterile.png
#	Resources/Textures/Objects/Storage/boxes.rsi/swab.png
#	Resources/Textures/Objects/Storage/boxes.rsi/syringe.png
#	Resources/Textures/Objects/Storage/boxes.rsi/trashbag.png
#	Resources/Textures/Objects/Storage/boxes.rsi/vials.png
#	Resources/Textures/Objects/Storage/boxes.rsi/writing.png
#	Resources/Textures/Objects/Storage/boxes.rsi/writing_of_doom.png
#	Resources/Textures/Objects/Storage/boxes.rsi/ziptie.png
#	Resources/Textures/Objects/Tiles/tile.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/icon.png
#	Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/primed.png
#	Resources/Textures/Objects/Weapons/Grenades/flashbang.rsi/icon.png
#	Resources/Textures/Objects/Weapons/Grenades/flashbang.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Grenades/flashbang.rsi/primed.png
#	Resources/Textures/Objects/Weapons/Grenades/stingergrenade.rsi/icon.png
#	Resources/Textures/Objects/Weapons/Grenades/stingergrenade.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Grenades/stingergrenade.rsi/primed.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/base.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/icon.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/mag-unshaded-1.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/mag-unshaded-2.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/mag-unshaded-3.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/mag-unshaded-4.png
#	Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Guns/Rifles/lecter.rsi/equipped-BACKPACK.png
#	Resources/Textures/Objects/Weapons/Guns/SMGs/vector.rsi/equipped-BACKPACK.png
#	Resources/Textures/Objects/Weapons/Guns/Shotguns/pump.rsi/equipped-BACKPACK.png
2025-02-19 03:00:13 +01:00

132 lines
4.9 KiB
C#

using Content.Shared.Chat.TypingIndicator;
using Content.Shared.Holopad;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using System.Linq;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.Holopad;
public sealed class HolopadSystem : SharedHolopadSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HolopadHologramComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<HolopadHologramComponent, BeforePostShaderRenderEvent>(OnShaderRender);
SubscribeAllEvent<TypingChangedEvent>(OnTypingChanged);
}
private void OnComponentStartup(Entity<HolopadHologramComponent> entity, ref ComponentStartup ev)
{
UpdateHologramSprite(entity, entity.Comp.LinkedEntity);
}
private void OnShaderRender(Entity<HolopadHologramComponent> entity, ref BeforePostShaderRenderEvent ev)
{
if (ev.Sprite.PostShader == null)
return;
UpdateHologramSprite(entity, entity.Comp.LinkedEntity);
}
private void OnTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs args)
{
var uid = args.SenderSession.AttachedEntity;
if (!Exists(uid))
return;
if (!HasComp<HolopadUserComponent>(uid))
return;
var netEv = new HolopadUserTypingChangedEvent(GetNetEntity(uid.Value), ev.State);
RaiseNetworkEvent(netEv);
}
private void UpdateHologramSprite(EntityUid hologram, EntityUid? target)
{
// Get required components
if (!TryComp<SpriteComponent>(hologram, out var hologramSprite) ||
!TryComp<HolopadHologramComponent>(hologram, out var holopadhologram))
return;
// Remove all sprite layers
for (int i = hologramSprite.AllLayers.Count() - 1; i >= 0; i--)
hologramSprite.RemoveLayer(i);
if (TryComp<SpriteComponent>(target, out var targetSprite))
{
// Use the target's holographic avatar (if available)
if (TryComp<HolographicAvatarComponent>(target, out var targetAvatar) &&
targetAvatar.LayerData != null)
{
for (int i = 0; i < targetAvatar.LayerData.Length; i++)
{
var layer = targetAvatar.LayerData[i];
hologramSprite.AddLayer(targetAvatar.LayerData[i], i);
}
}
// Otherwise copy the target's current physical appearance
else
{
hologramSprite.CopyFrom(targetSprite);
}
}
// There is no target, display a default sprite instead (if available)
else
{
if (string.IsNullOrEmpty(holopadhologram.RsiPath) || string.IsNullOrEmpty(holopadhologram.RsiState))
return;
var layer = new PrototypeLayerData();
layer.RsiPath = holopadhologram.RsiPath;
layer.State = holopadhologram.RsiState;
hologramSprite.AddLayer(layer);
}
// Override specific values
hologramSprite.Color = Color.White;
hologramSprite.Offset = holopadhologram.Offset;
hologramSprite.DrawDepth = (int)DrawDepth.Mobs;
hologramSprite.NoRotation = true;
hologramSprite.DirectionOverride = Direction.South;
hologramSprite.EnableDirectionOverride = true;
// Remove shading from all layers (except displacement maps)
for (int i = 0; i < hologramSprite.AllLayers.Count(); i++)
{
if (hologramSprite.TryGetLayer(i, out var layer) && layer.ShaderPrototype != "DisplacedStencilDraw")
hologramSprite.LayerSetShader(i, "unshaded");
}
UpdateHologramShader(hologram, hologramSprite, holopadhologram);
}
private void UpdateHologramShader(EntityUid uid, SpriteComponent sprite, HolopadHologramComponent holopadHologram)
{
// Find the texture height of the largest layer
float texHeight = sprite.AllLayers.Max(x => x.PixelSize.Y);
var instance = _prototypeManager.Index<ShaderPrototype>(holopadHologram.ShaderName).InstanceUnique();
instance.SetParameter("color1", new Vector3(holopadHologram.Color1.R, holopadHologram.Color1.G, holopadHologram.Color1.B));
instance.SetParameter("color2", new Vector3(holopadHologram.Color2.R, holopadHologram.Color2.G, holopadHologram.Color2.B));
instance.SetParameter("alpha", holopadHologram.Alpha);
instance.SetParameter("intensity", holopadHologram.Intensity);
instance.SetParameter("texHeight", texHeight);
instance.SetParameter("t", (float)_timing.CurTime.TotalSeconds * holopadHologram.ScrollRate);
sprite.PostShader = instance;
sprite.RaiseShaderEvent = true;
}
}