Working flashlight for hard hats (#2599)

* Add verb to toggle flashlight

* Playing with hand-held light for hard hat

* ClothingEquippedPrefix will update players sprite when changed

* Make abstract prototype for hardhat and fixed hardhat orange sprites

* Fixed all other hard hats

* Fixed requested changes

* Restore prototype and sprites changes

* Nullables

* That's actually nullable

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
Alex Evgrashin
2020-11-23 06:17:38 +03:00
committed by GitHub
parent e97763afd2
commit fb6dd4a490
44 changed files with 202 additions and 31 deletions

View File

@@ -1,9 +1,13 @@
using Content.Client.GameObjects.Components.Items;
#nullable enable
using Content.Client.GameObjects.Components.HUD.Inventory;
using Content.Client.GameObjects.Components.Items;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.Items;
using Robust.Client.Graphics;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -18,8 +22,29 @@ namespace Content.Client.GameObjects.Components.Clothing
public override string Name => "Clothing";
public override uint? NetID => ContentNetIDs.CLOTHING;
private string? _clothingEquippedPrefix;
[ViewVariables(VVAccess.ReadWrite)]
public string ClothingEquippedPrefix { get; set; }
public string? ClothingEquippedPrefix
{
get => _clothingEquippedPrefix;
set
{
if (_clothingEquippedPrefix == value)
return;
_clothingEquippedPrefix = value;
if (!Owner.TryGetContainer(out IContainer? container))
return;
if (!container.Owner.TryGetComponent(out ClientInventoryComponent? inventory))
return;
if (!inventory.TryFindItemSlots(Owner, out EquipmentSlotDefines.Slots? slots))
return;
inventory.SetSlotVisuals(slots.Value, Owner);
}
}
[ViewVariables(VVAccess.ReadWrite)]
public FemaleClothingMask FemaleMask
@@ -54,7 +79,7 @@ namespace Content.Client.GameObjects.Components.Clothing
return null;
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState == null)
return;

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Client.GameObjects.Components.Clothing;
using Content.Shared.GameObjects.Components.Inventory;
@@ -22,10 +24,9 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
{
private readonly Dictionary<Slots, IEntity> _slots = new Dictionary<Slots, IEntity>();
[ViewVariables]
public InventoryInterfaceController InterfaceController { get; private set; }
[ViewVariables] public InventoryInterfaceController InterfaceController { get; private set; } = default!;
private ISpriteComponent _sprite;
private ISpriteComponent? _sprite;
private bool _playerAttached = false;
@@ -69,7 +70,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
}
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
@@ -126,7 +127,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
return;
}
if (entity != null && entity.TryGetComponent(out ClothingComponent clothing))
if (entity.TryGetComponent(out ClothingComponent? clothing))
{
var flag = SlotMasks[slot];
var data = clothing.GetEquippedStateInfo(flag);
@@ -155,6 +156,9 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
internal void ClearAllSlotVisuals()
{
if (_sprite == null)
return;
foreach (var slot in InventoryInstance.SlotMasks)
{
if (slot != Slots.NONE)
@@ -192,7 +196,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));
}
public override void HandleMessage(ComponentMessage message, IComponent component)
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
@@ -210,9 +214,25 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
}
}
public bool TryGetSlot(Slots slot, out IEntity item)
public bool TryGetSlot(Slots slot, out IEntity? item)
{
return _slots.TryGetValue(slot, out item);
}
public bool TryFindItemSlots(IEntity item, [NotNullWhen(true)] out Slots? slots)
{
slots = null;
foreach (var (slot, entity) in _slots)
{
if (entity == item)
{
slots = slot;
return true;
}
}
return false;
}
}
}