ItemComponent.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Content.Shared.Hands.Components;
  2. using Robust.Shared.GameStates;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Serialization;
  5. using Robust.Shared.Utility;
  6. namespace Content.Shared.Item;
  7. /// <summary>
  8. /// Handles items which can be picked up to hands and placed in pockets, as well as storage containers
  9. /// like backpacks.
  10. /// </summary>
  11. [RegisterComponent]
  12. [NetworkedComponent]
  13. [Access(typeof(SharedItemSystem)), AutoGenerateComponentState(true)]
  14. public sealed partial class ItemComponent : Component
  15. {
  16. [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
  17. [Access(typeof(SharedItemSystem))]
  18. public ProtoId<ItemSizePrototype> Size = "Small";
  19. [Access(typeof(SharedItemSystem))]
  20. [DataField]
  21. public Dictionary<HandLocation, List<PrototypeLayerData>> InhandVisuals = new();
  22. [Access(typeof(SharedItemSystem))]
  23. [ViewVariables(VVAccess.ReadWrite)]
  24. [DataField, AutoNetworkedField]
  25. public string? HeldPrefix;
  26. /// <summary>
  27. /// Rsi of the sprite shown on the player when this item is in their hands. Used to generate a default entry for <see cref="InhandVisuals"/>
  28. /// </summary>
  29. [Access(typeof(SharedItemSystem))]
  30. [ViewVariables(VVAccess.ReadWrite)]
  31. [DataField("sprite")]
  32. public string? RsiPath;
  33. /// <summary>
  34. /// An optional override for the shape of the item within the grid storage.
  35. /// If null, a default shape will be used based on <see cref="Size"/>.
  36. /// </summary>
  37. [DataField, AutoNetworkedField]
  38. public List<Box2i>? Shape;
  39. /// <summary>
  40. /// A sprite used to depict this entity specifically when it is displayed in the storage UI.
  41. /// </summary>
  42. [DataField, AutoNetworkedField]
  43. public SpriteSpecifier? StoredSprite;
  44. /// <summary>
  45. /// An additional angle offset, in degrees, applied to the visual depiction of the item when displayed in the storage UI.
  46. /// </summary>
  47. [DataField, AutoNetworkedField]
  48. public float StoredRotation = 0;
  49. /// <summary>
  50. /// An additional offset, in pixels, applied to the visual depiction of the item when displayed in the storage UI.
  51. /// </summary>
  52. [DataField, AutoNetworkedField]
  53. public Vector2i StoredOffset;
  54. }
  55. /// <summary>
  56. /// Raised when an item's visual state is changed. The event is directed at the entity that contains this item, so
  57. /// that it can properly update its hands or inventory sprites and GUI.
  58. /// </summary>
  59. [Serializable, NetSerializable]
  60. public sealed class VisualsChangedEvent : EntityEventArgs
  61. {
  62. public readonly NetEntity Item;
  63. public readonly string ContainerId;
  64. public VisualsChangedEvent(NetEntity item, string containerId)
  65. {
  66. Item = item;
  67. ContainerId = containerId;
  68. }
  69. }