Files
OldThink/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs

306 lines
9.4 KiB
C#
Raw Normal View History

#nullable enable
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Clothing;
using Content.Server.GameObjects.Components.Items.Storage;
Add changing the amount of hands on the GUI depending on your body parts (#1406) * Multiple hands in gui first pass * Remove IHandsComponent interface * Create hand class and more hand textures * Refactor ServerHandsComponent to use a single list of hands * Seal SharedHand * Fix picked up items not showing on top of the hand buttons * Remove HandsGui buttons and panels dictionaries * Fix items in hands rendering * Fix wrong hand container comparison * Fix not updating the location of duplicate hands * Change ClientHandsComponent to use a SortedList instead of a dictionary * More merge conflict fixes * Change SortedList to List * Fix hand button order * Add item tooltip for more than 2 hands and updating when removing hands * Add add hand and remove hand command * Merge conflict fixes * Remove nullable reference type from ContainerSlot * Fix texture errors * Fix error when reaching 0 hands * Fix error when swapping hands with no hands * Merged remove hand methods * Fix item panel texture errors * Merge conflict fixes * Fix addhand and removehand command descriptions * Add properly displaying tooltips for 2 hands * Make hand indexes and locations consistent across the client and server * Add dropping held entity if a hand is removed * Change hand location to be calculated by index * Made different hand gui updates more consistent * Remove human body yml testing changes * Sanitize addhand and removehand commands * Merge conflict fixes * Remove testing changes * Revert body system changes * Add missing imports * Remove obsolete hands parameter in yml files * Fix broken import * Fix startup error and adding and removing hands on the same tick * Make hand container id use an uint In case someone gets more than 2 billion hands * Rename hand component files * Make hands state use an array
2020-07-25 15:11:16 +02:00
using Content.Server.GameObjects.Components.Power;
using Content.Server.Interfaces.GameObjects.Components.Items;
2020-01-09 00:27:52 +01:00
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
Add changing the amount of hands on the GUI depending on your body parts (#1406) * Multiple hands in gui first pass * Remove IHandsComponent interface * Create hand class and more hand textures * Refactor ServerHandsComponent to use a single list of hands * Seal SharedHand * Fix picked up items not showing on top of the hand buttons * Remove HandsGui buttons and panels dictionaries * Fix items in hands rendering * Fix wrong hand container comparison * Fix not updating the location of duplicate hands * Change ClientHandsComponent to use a SortedList instead of a dictionary * More merge conflict fixes * Change SortedList to List * Fix hand button order * Add item tooltip for more than 2 hands and updating when removing hands * Add add hand and remove hand command * Merge conflict fixes * Remove nullable reference type from ContainerSlot * Fix texture errors * Fix error when reaching 0 hands * Fix error when swapping hands with no hands * Merged remove hand methods * Fix item panel texture errors * Merge conflict fixes * Fix addhand and removehand command descriptions * Add properly displaying tooltips for 2 hands * Make hand indexes and locations consistent across the client and server * Add dropping held entity if a hand is removed * Change hand location to be calculated by index * Made different hand gui updates more consistent * Remove human body yml testing changes * Sanitize addhand and removehand commands * Merge conflict fixes * Remove testing changes * Revert body system changes * Add missing imports * Remove obsolete hands parameter in yml files * Fix broken import * Fix startup error and adding and removing hands on the same tick * Make hand container id use an uint In case someone gets more than 2 billion hands * Rename hand component files * Make hands state use an array
2020-07-25 15:11:16 +02:00
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
namespace Content.Server.GameObjects.Components.Interactable
{
/// <summary>
2018-11-21 20:58:11 +01:00
/// Component that represents a handheld lightsource which can be toggled on and off.
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// </summary>
2019-07-31 15:02:36 +02:00
[RegisterComponent]
internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IInteractUsing,
IMapInit
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
{
[ViewVariables(VVAccess.ReadWrite)] public float Wattage { get; set; } = 10;
[ViewVariables] private ContainerSlot _cellContainer = default!;
2018-11-21 20:58:11 +01:00
[ViewVariables]
private BatteryComponent? Cell
{
get
{
2018-11-21 20:58:11 +01:00
if (_cellContainer.ContainedEntity == null) return null;
if (_cellContainer.ContainedEntity.TryGetComponent(out BatteryComponent? cell))
{
return cell;
}
return null;
}
}
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// <summary>
2018-11-21 20:58:11 +01:00
/// Status of light, whether or not it is emitting light.
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// </summary>
2018-09-09 15:34:43 +02:00
[ViewVariables]
2018-11-21 20:58:11 +01:00
public bool Activated { get; private set; }
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
[ViewVariables] protected override bool HasCell => Cell != null;
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
2018-11-21 20:58:11 +01:00
{
if (!eventArgs.Using.HasComponent<BatteryComponent>()) return false;
2018-11-21 20:58:11 +01:00
if (Cell != null) return false;
var handsComponent = eventArgs.User.GetComponent<IHandsComponent>();
2020-05-23 17:23:25 +02:00
if (!handsComponent.Drop(eventArgs.Using, _cellContainer))
{
return false;
}
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/pistol_magin.ogg", Owner);
Dirty();
return true;
2018-11-21 20:58:11 +01:00
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
2018-11-21 20:58:11 +01:00
{
if (Activated)
{
message.AddMarkup(Loc.GetString("The light is currently [color=darkgreen]on[/color]."));
}
2018-11-21 20:58:11 +01:00
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
2018-11-21 20:58:11 +01:00
{
return ToggleStatus(eventArgs.User);
2018-11-21 20:58:11 +01:00
}
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponent<PointLightComponent>();
_cellContainer =
ContainerManagerComponent.Ensure<ContainerSlot>("flashlight_cell_container", Owner, out _);
Dirty();
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
/// <summary>
2018-11-21 20:58:11 +01:00
/// Illuminates the light if it is not active, extinguishes it if it is active.
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// </summary>
/// <returns>True if the light's status was toggled, false otherwise.</returns>
private bool ToggleStatus(IEntity user)
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
{
var item = Owner.GetComponent<ItemComponent>();
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
// Update sprite and light states to match the activation.
if (Activated)
{
TurnOff();
item.EquippedPrefix = "off";
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
else
{
TurnOn(user);
item.EquippedPrefix = "on";
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
// Toggle always succeeds.
return true;
}
private void TurnOff(bool makeNoise = true)
{
if (!Activated)
{
return;
}
2019-07-30 13:31:46 +02:00
SetState(false);
Activated = false;
if (makeNoise)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/flashlight_toggle.ogg", Owner);
}
}
private void TurnOn(IEntity user)
{
if (Activated)
{
return;
}
var cell = Cell;
if (cell == null)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/button.ogg", Owner);
2020-01-09 00:27:52 +01:00
Owner.PopupMessage(user, Loc.GetString("Cell missing..."));
return;
}
// To prevent having to worry about frame time in here.
// Let's just say you need a whole second of charge before you can turn it on.
// Simple enough.
if (Wattage > cell.CurrentCharge)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/button.ogg", Owner);
Owner.PopupMessage(user, Loc.GetString("Dead cell..."));
return;
}
Activated = true;
2019-07-30 13:31:46 +02:00
SetState(true);
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/flashlight_toggle.ogg", Owner);
}
2019-07-30 13:31:46 +02:00
private void SetState(bool on)
{
if (Owner.TryGetComponent(out SpriteComponent? sprite))
{
sprite.LayerSetVisible(1, on);
}
if (Owner.TryGetComponent(out PointLightComponent? light))
{
light.Enabled = on;
}
if (Owner.TryGetComponent(out ClothingComponent? clothing))
{
clothing.ClothingEquippedPrefix = on ? "On" : "Off";
}
}
2018-11-21 20:58:11 +01:00
public void OnUpdate(float frameTime)
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
{
if (!Activated || Cell == null) return;
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
var appearanceComponent = Owner.GetComponent<AppearanceComponent>();
if (Cell.MaxCharge - Cell.CurrentCharge < Cell.MaxCharge * 0.70)
{
appearanceComponent.SetData(HandheldLightVisuals.Power, HandheldLightPowerStates.FullPower);
}
else if (Cell.MaxCharge - Cell.CurrentCharge < Cell.MaxCharge * 0.90)
{
appearanceComponent.SetData(HandheldLightVisuals.Power, HandheldLightPowerStates.LowPower);
}
else
{
appearanceComponent.SetData(HandheldLightVisuals.Power, HandheldLightPowerStates.Dying);
}
if (Cell == null || !Cell.TryUseCharge(Wattage * frameTime)) TurnOff();
2020-01-09 00:27:52 +01:00
Dirty();
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
2018-11-21 20:58:11 +01:00
private void EjectCell(IEntity user)
{
if (Cell == null)
{
return;
}
2018-11-21 20:58:11 +01:00
var cell = Cell;
if (!_cellContainer.Remove(cell.Owner))
{
return;
}
Dirty();
if (!user.TryGetComponent(out HandsComponent? hands))
{
return;
}
2018-11-21 20:58:11 +01:00
if (!hands.PutInHand(cell.Owner.GetComponent<ItemComponent>()))
{
cell.Owner.Transform.Coordinates = user.Transform.Coordinates;
}
// Assuming the battery has just been taken out of the flashlight, make sure it's getting disabled
TurnOff(false);
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/pistol_magout.ogg", Owner);
2018-11-21 20:58:11 +01:00
}
2020-01-09 00:27:52 +01:00
public override ComponentState GetComponentState()
{
if (Cell == null)
{
return new HandheldLightComponentState(null, false);
2020-01-09 00:27:52 +01:00
}
if (Wattage > Cell.CurrentCharge)
2020-01-09 00:27:52 +01:00
{
// Practically zero.
// This is so the item status works correctly.
return new HandheldLightComponentState(0, HasCell);
2020-01-09 00:27:52 +01:00
}
return new HandheldLightComponentState(Cell.CurrentCharge / Cell.MaxCharge, HasCell);
2020-01-09 00:27:52 +01:00
}
2018-11-21 20:58:11 +01:00
[Verb]
public sealed class EjectCellVerb : Verb<HandheldLightComponent>
{
protected override void GetData(IEntity user, HandheldLightComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
if (component.Cell == null)
{
data.Text = Loc.GetString("Eject cell (cell missing)");
data.Visibility = VerbVisibility.Disabled;
}
else
{
data.Text = Loc.GetString("Eject cell");
}
2018-11-21 20:58:11 +01:00
}
protected override void Activate(IEntity user, HandheldLightComponent component)
{
2018-11-21 20:58:11 +01:00
component.EjectCell(user);
}
}
void IMapInit.MapInit()
{
if (_cellContainer.ContainedEntity != null)
{
return;
}
2020-01-09 00:27:52 +01:00
var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallStandard", Owner.Transform.Coordinates);
_cellContainer.Insert(cell);
}
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
}