* basic radiation generator * might need this * thonk * big thonk * oop * e * werks * sprite * oopsy woopsy * radiation * clean up file * makes it work, probably * minor fixes * resources * progress on component * this will no longer be necessary * radiation go brrrr * finally fix container issues * out var Co-authored-by: Remie Richards <remierichards@gmail.com> * second out fix * another out fix Co-authored-by: Remie Richards <remierichards@gmail.com> * switch case * fix switch * sound and improvements * nullable * basic containment field system * ensure alignment * fix beam placement logic * field generation fully working * fix potential crash * working containment functionality * extremely basic emitter functionality * fix radiation panel naming * emitter stuff * oopsies * fixes * some fixes * cleanup * small fix and move emitter file * add sprite resources for PA * slight rework of the singulo adds rads * pushing for smugleaf :) * added radiationpanels * some fixes for the singulo * containmentfield * pa wip * progress * pa working * emitter fix * works :) * ui works * some work on ui & pa * progress * ui work & misc fixes * GREYSCALE * pa ui polish containmentfieldgen rework * singulo rework added snapgrid * getcomponent get out * singulo rework added collisiongroups underplating & passable * yaml work: - collision boxes - singulo now unshaded * no unlit * misc changes * pa wires * add usability check * nullable enable * minor fix * power need added * reenables containment field energy drain menu close button singularity collider fix * sprite replacement * finished singulo pulling * pjb fixes * fixing sprites & minor adjustments * decrease containmentfield power * some yml adjustments * unlit layers singulogenerator * singulogen * everything works just not the powergetting on the pa i wanna die * Adds PA construction graphs, PA construction works * Snap to grid parts when completing construction * updated to newest master * inb4 i work on power * fixes upstream merge adds power need to particleaccelerator * properly implements power & apc power * Emitters are now fancy. * I have actually no idea how this happened. * Give PA a wiring LayoutId * PA is an acronym * indicators fixes hacking * Singulo is a word you blasphemous IDE. * Rewrite the PA. * Fancy names for PA parts. * Wiring fixes, strength wire cutting. * fixes projectile & ignores components * nullability errors * fixes integration tests Co-authored-by: unusualcrow <unusualcrow@protonmail.com> Co-authored-by: L.E.D <10257081+unusualcrow@users.noreply.github.com> Co-authored-by: Remie Richards <remierichards@gmail.com> Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
219 lines
7.0 KiB
C#
219 lines
7.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Content.Client.GameObjects.Components.Clothing;
|
|
using Content.Shared.GameObjects.Components.Inventory;
|
|
using Content.Shared.Preferences.Appearance;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Interfaces.GameObjects.Components;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.ViewVariables;
|
|
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
|
using static Content.Shared.GameObjects.Components.Inventory.SharedInventoryComponent.ClientInventoryMessage;
|
|
|
|
namespace Content.Client.GameObjects.Components.HUD.Inventory
|
|
{
|
|
/// <summary>
|
|
/// A character UI which shows items the user has equipped within his inventory
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public class ClientInventoryComponent : SharedInventoryComponent
|
|
{
|
|
private readonly Dictionary<Slots, IEntity> _slots = new Dictionary<Slots, IEntity>();
|
|
|
|
[ViewVariables]
|
|
public InventoryInterfaceController InterfaceController { get; private set; }
|
|
|
|
private ISpriteComponent _sprite;
|
|
|
|
private bool _playerAttached = false;
|
|
|
|
public override void OnRemove()
|
|
{
|
|
base.OnRemove();
|
|
|
|
if (_playerAttached)
|
|
{
|
|
InterfaceController?.PlayerDetached();
|
|
}
|
|
InterfaceController?.Dispose();
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
var controllerType = ReflectionManager.LooseGetType(InventoryInstance.InterfaceControllerTypeName);
|
|
var args = new object[] {this};
|
|
InterfaceController = DynamicTypeFactory.CreateInstance<InventoryInterfaceController>(controllerType, args);
|
|
InterfaceController.Initialize();
|
|
|
|
if (Owner.TryGetComponent(out _sprite))
|
|
{
|
|
foreach (var mask in InventoryInstance.SlotMasks.OrderBy(s => InventoryInstance.SlotDrawingOrder(s)))
|
|
{
|
|
if (mask == Slots.NONE)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
_sprite.LayerMapReserveBlank(mask);
|
|
}
|
|
}
|
|
|
|
// Component state already came in but we couldn't set anything visually because, well, we didn't initialize yet.
|
|
foreach (var (slot, entity) in _slots)
|
|
{
|
|
_setSlot(slot, entity);
|
|
}
|
|
}
|
|
|
|
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
|
{
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
if (curState == null)
|
|
return;
|
|
|
|
var cast = (InventoryComponentState) curState;
|
|
|
|
var doneSlots = new HashSet<Slots>();
|
|
|
|
foreach (var (slot, entityUid) in cast.Entities)
|
|
{
|
|
if (!Owner.EntityManager.TryGetEntity(entityUid, out var entity))
|
|
{
|
|
continue;
|
|
}
|
|
if (!_slots.ContainsKey(slot) || _slots[slot] != entity)
|
|
{
|
|
_slots[slot] = entity;
|
|
_setSlot(slot, entity);
|
|
}
|
|
doneSlots.Add(slot);
|
|
}
|
|
|
|
if (cast.HoverEntity != null)
|
|
{
|
|
var (slot, (entityUid, fits)) = cast.HoverEntity.Value;
|
|
var entity = Owner.EntityManager.GetEntity(entityUid);
|
|
|
|
InterfaceController?.HoverInSlot(slot, entity, fits);
|
|
}
|
|
|
|
foreach (var slot in _slots.Keys.ToList())
|
|
{
|
|
if (!doneSlots.Contains(slot))
|
|
{
|
|
_clearSlot(slot);
|
|
_slots.Remove(slot);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void _setSlot(Slots slot, IEntity entity)
|
|
{
|
|
SetSlotVisuals(slot, entity);
|
|
|
|
InterfaceController?.AddToSlot(slot, entity);
|
|
}
|
|
|
|
internal void SetSlotVisuals(Slots slot, IEntity entity)
|
|
{
|
|
if (_sprite == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (entity != null && entity.TryGetComponent(out ClothingComponent clothing))
|
|
{
|
|
var flag = SlotMasks[slot];
|
|
var data = clothing.GetEquippedStateInfo(flag);
|
|
if (data != null)
|
|
{
|
|
var (rsi, state) = data.Value;
|
|
_sprite.LayerSetVisible(slot, true);
|
|
_sprite.LayerSetState(slot, state, rsi);
|
|
|
|
if (slot == Slots.INNERCLOTHING)
|
|
{
|
|
_sprite.LayerSetState(HumanoidVisualLayers.StencilMask, clothing.FemaleMask switch
|
|
{
|
|
FemaleClothingMask.NoMask => "female_none",
|
|
FemaleClothingMask.UniformTop => "female_top",
|
|
_ => "female_full",
|
|
});
|
|
}
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
_sprite.LayerSetVisible(slot, false);
|
|
}
|
|
|
|
internal void ClearAllSlotVisuals()
|
|
{
|
|
foreach (var slot in InventoryInstance.SlotMasks)
|
|
{
|
|
if (slot != Slots.NONE)
|
|
{
|
|
_sprite.LayerSetVisible(slot, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void _clearSlot(Slots slot)
|
|
{
|
|
InterfaceController?.RemoveFromSlot(slot);
|
|
_sprite?.LayerSetVisible(slot, false);
|
|
}
|
|
|
|
public void SendEquipMessage(Slots slot)
|
|
{
|
|
var equipMessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Equip);
|
|
SendNetworkMessage(equipMessage);
|
|
}
|
|
|
|
public void SendUseMessage(Slots slot)
|
|
{
|
|
var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Use);
|
|
SendNetworkMessage(equipmessage);
|
|
}
|
|
|
|
public void SendHoverMessage(Slots slot)
|
|
{
|
|
SendNetworkMessage(new ClientInventoryMessage(slot, ClientInventoryUpdate.Hover));
|
|
}
|
|
|
|
public void SendOpenStorageUIMessage(Slots slot)
|
|
{
|
|
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));
|
|
}
|
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent component)
|
|
{
|
|
base.HandleMessage(message, component);
|
|
|
|
switch (message)
|
|
{
|
|
case PlayerAttachedMsg _:
|
|
InterfaceController.PlayerAttached();
|
|
_playerAttached = true;
|
|
break;
|
|
|
|
case PlayerDetachedMsg _:
|
|
InterfaceController.PlayerDetached();
|
|
_playerAttached = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public bool TryGetSlot(Slots slot, out IEntity item)
|
|
{
|
|
return _slots.TryGetValue(slot, out item);
|
|
}
|
|
}
|
|
}
|