Better inventory window, inventory buttons on game HUD.

Part of #272
This commit is contained in:
Pieter-Jan Briers
2019-07-23 23:24:47 +02:00
parent 4d202a7678
commit 1fbb5915aa
12 changed files with 431 additions and 252 deletions

View File

@@ -1,11 +1,12 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
namespace Content.Shared.GameObjects
{
public abstract class Inventory
{
public abstract int Columns { get; }
public abstract string InterfaceControllerTypeName { get; }
public abstract IReadOnlyList<Slots> SlotMasks { get; }
@@ -19,11 +20,13 @@ namespace Content.Shared.GameObjects
public abstract int SlotDrawingOrder(Slots slot);
}
// Dynamically created by SharedInventoryComponent.
[UsedImplicitly]
public class HumanInventory : Inventory
{
public override int Columns => 3;
public override string InterfaceControllerTypeName => "HumanInventoryInterfaceController";
private static Dictionary<Slots, int> _slotDrawingOrder = new Dictionary<Slots, int>
private static readonly Dictionary<Slots, int> _slotDrawingOrder = new Dictionary<Slots, int>
{
{Slots.HEAD, 10},
{Slots.MASK, 9},

View File

@@ -1,17 +1,53 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using System;
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
namespace Content.Shared.GameObjects
{
public abstract class SharedInventoryComponent : Component
{
// ReSharper disable UnassignedReadonlyField
[Dependency] protected readonly IReflectionManager ReflectionManager;
[Dependency] protected readonly IDynamicTypeFactory DynamicTypeFactory;
// ReSharper restore UnassignedReadonlyField
public sealed override string Name => "Inventory";
public sealed override uint? NetID => ContentNetIDs.STORAGE;
public sealed override Type StateType => typeof(InventoryComponentState);
[ViewVariables]
protected Inventory InventoryInstance { get; private set; }
[ViewVariables]
private string _templateName = "HumanInventory"; //stored for serialization purposes
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _templateName, "Template", "HumanInventory");
}
public override void Initialize()
{
base.Initialize();
CreateInventory();
}
private void CreateInventory()
{
var type = ReflectionManager.LooseGetType(_templateName);
DebugTools.Assert(type != null);
InventoryInstance = DynamicTypeFactory.CreateInstance<Inventory>(type);
}
[Serializable, NetSerializable]
protected class InventoryComponentState : ComponentState
{