* - Combine enum keys `ToggleableLightVisuals` and `ToggleVisuals` into `ToggleableVisuals` - Rename `ToggleableLightVisualsComponent` to `ToggleableVisualsComponent` and `ToggleableLightVisualsSystem` to `ToggleableVisualsSystem` - (The `SpriteLayer` field on the component is now required because the old default of `light` doesn't make sense anymore) - Make it so that `ToggleableVisualsComponent` works even when there's not a light attached to the entity - (Amazingly this seems to have only applied to Headphones, but I can only imagine there are many other things people would like to do with simple toggleable visuals) - Explicitly make `ItemTogglePointLightComponent`'s purpose to make `ToggleVisualsComponent` apply to `PointLightComponent`s on the same entity. - Add field `ToggleableVisualsColorModulatesLights`, which makes the `Color` appearance value of `ToggleableVisuals` modulate the color of lights on the same entity - Lots of prototype updates to uptake the above * fix bad merge * unbork robust * blindly letting rider reformat stuff * I guess I never cleaned up these imports at all
107 lines
3.7 KiB
C#
107 lines
3.7 KiB
C#
using Content.Shared.Actions;
|
|
using Content.Shared.Clothing.EntitySystems;
|
|
using Content.Shared.Item;
|
|
using Content.Shared.Light.Components;
|
|
using Content.Shared.Toggleable;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Light;
|
|
|
|
public abstract class SharedHandheldLightSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedItemSystem _itemSys = default!;
|
|
[Dependency] private readonly ClothingSystem _clothingSys = default!;
|
|
[Dependency] private readonly SharedActionsSystem _actionSystem = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<HandheldLightComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<HandheldLightComponent, ComponentHandleState>(OnHandleState);
|
|
|
|
SubscribeLocalEvent<HandheldLightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerb);
|
|
}
|
|
|
|
private void OnInit(EntityUid uid, HandheldLightComponent component, ComponentInit args)
|
|
{
|
|
UpdateVisuals(uid, component);
|
|
|
|
// Want to make sure client has latest data on level so battery displays properly.
|
|
Dirty(uid, component);
|
|
}
|
|
|
|
private void OnHandleState(EntityUid uid, HandheldLightComponent component, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not HandheldLightComponent.HandheldLightComponentState state)
|
|
return;
|
|
|
|
component.Level = state.Charge;
|
|
SetActivated(uid, state.Activated, component, false);
|
|
}
|
|
|
|
public void SetActivated(EntityUid uid, bool activated, HandheldLightComponent? component = null, bool makeNoise = true)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (component.Activated == activated)
|
|
return;
|
|
|
|
component.Activated = activated;
|
|
|
|
if (makeNoise)
|
|
{
|
|
var sound = component.Activated ? component.TurnOnSound : component.TurnOffSound;
|
|
_audio.PlayPvs(sound, uid);
|
|
}
|
|
|
|
Dirty(uid, component);
|
|
UpdateVisuals(uid, component);
|
|
}
|
|
|
|
public void UpdateVisuals(EntityUid uid, HandheldLightComponent? component = null, AppearanceComponent? appearance = null)
|
|
{
|
|
if (!Resolve(uid, ref component, ref appearance, false))
|
|
return;
|
|
|
|
if (component.AddPrefix)
|
|
{
|
|
var prefix = component.Activated ? "on" : "off";
|
|
_itemSys.SetHeldPrefix(uid, prefix);
|
|
_clothingSys.SetEquippedPrefix(uid, prefix);
|
|
}
|
|
|
|
if (component.ToggleActionEntity != null)
|
|
_actionSystem.SetToggled(component.ToggleActionEntity, component.Activated);
|
|
|
|
_appearance.SetData(uid, ToggleableVisuals.Enabled, component.Activated, appearance);
|
|
}
|
|
|
|
private void AddToggleLightVerb(Entity<HandheldLightComponent> ent, ref GetVerbsEvent<ActivationVerb> args)
|
|
{
|
|
if (!args.CanAccess || !args.CanInteract || !ent.Comp.ToggleOnInteract)
|
|
return;
|
|
|
|
var @event = args;
|
|
ActivationVerb verb = new()
|
|
{
|
|
Text = Loc.GetString("verb-common-toggle-light"),
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
|
|
Act = ent.Comp.Activated
|
|
? () => TurnOff(ent)
|
|
: () => TurnOn(@event.User, ent)
|
|
};
|
|
|
|
args.Verbs.Add(verb);
|
|
}
|
|
|
|
public abstract bool TurnOff(Entity<HandheldLightComponent> ent, bool makeNoise = true);
|
|
public abstract bool TurnOn(EntityUid user, Entity<HandheldLightComponent> uid);
|
|
}
|