Equipment & inhands. (#110)
* Equipment WiP * Equipment's starting to work. * Equipment works properly 100% now. * Inhands work. Also more clothes.
This commit is contained in:
committed by
GitHub
parent
c612806ef1
commit
74541e23a4
@@ -6,46 +6,118 @@ using SS14.Client.Interfaces.Input;
|
||||
using SS14.Client.UserInterface;
|
||||
using SS14.Client.UserInterface.Controls;
|
||||
using SS14.Client.UserInterface.CustomControls;
|
||||
using SS14.Shared.ContentPack;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Input;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Network;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Serialization;
|
||||
using SS14.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.Components.Clothing;
|
||||
using SS14.Shared.Interfaces.Reflection;
|
||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||
using static Content.Shared.GameObjects.SharedInventoryComponent.ClientInventoryMessage;
|
||||
using static Content.Shared.GameObjects.SharedInventoryComponent.ServerInventoryMessage;
|
||||
|
||||
namespace Content.Client.GameObjects
|
||||
{
|
||||
public class ClientInventoryComponent : SharedInventoryComponent
|
||||
{
|
||||
private InventoryWindow Window;
|
||||
private string TemplateName = "HumanInventory"; //stored for serialization purposes
|
||||
private Dictionary<Slots, IEntity> _slots = new Dictionary<Slots, IEntity>();
|
||||
|
||||
private InventoryWindow _window;
|
||||
private string _templateName = "HumanInventory"; //stored for serialization purposes
|
||||
|
||||
private InputCmdHandler _openMenuCmdHandler;
|
||||
private Inventory _inventory;
|
||||
|
||||
private ISpriteComponent _sprite;
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
Window.Dispose();
|
||||
_window.Dispose();
|
||||
}
|
||||
|
||||
public override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
|
||||
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => { _window.AddToScreen(); _window.Open(); });
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
||||
var type = reflectionManager.LooseGetType(_templateName);
|
||||
DebugTools.Assert(type != null);
|
||||
_inventory = (Inventory)Activator.CreateInstance(type);
|
||||
|
||||
_window = new InventoryWindow(this);
|
||||
_window.CreateInventory(_inventory);
|
||||
|
||||
if (Owner.TryGetComponent(out _sprite))
|
||||
{
|
||||
foreach (var mask in _inventory.SlotMasks.OrderBy(s => _inventory.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 ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
Window = new InventoryWindow(this);
|
||||
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => { Window.AddToScreen(); Window.Open(); });
|
||||
serializer.DataField(ref TemplateName, "Template", "HumanInventory");
|
||||
Window.CreateInventory(TemplateName);
|
||||
serializer.DataField(ref _templateName, "Template", "HumanInventory");
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState state)
|
||||
{
|
||||
base.HandleComponentState(state);
|
||||
var cast = (InventoryComponentState) state;
|
||||
|
||||
var doneSlots = new HashSet<Slots>();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
foreach (var (slot, entityUid) in cast.Entities)
|
||||
{
|
||||
if (_slots.ContainsKey(slot))
|
||||
{
|
||||
_slots.Remove(slot);
|
||||
_clearSlot(slot);
|
||||
}
|
||||
|
||||
var entity = entityManager.GetEntity(entityUid);
|
||||
_slots[slot] = entity;
|
||||
_setSlot(slot, entity);
|
||||
doneSlots.Add(slot);
|
||||
}
|
||||
|
||||
foreach (var slot in _slots.Keys.ToList())
|
||||
{
|
||||
if (!doneSlots.Contains(slot))
|
||||
{
|
||||
_clearSlot(slot);
|
||||
_slots.Remove(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||
@@ -53,18 +125,6 @@ namespace Content.Client.GameObjects
|
||||
var inputMgr = IoCManager.Resolve<IInputManager>();
|
||||
switch (message)
|
||||
{
|
||||
//Updates what we are storing in UI slots
|
||||
case ServerInventoryMessage msg:
|
||||
if (msg.Updatetype == ServerInventoryUpdate.Addition)
|
||||
{
|
||||
Window.AddToSlot(msg);
|
||||
}
|
||||
else if (msg.Updatetype == ServerInventoryUpdate.Removal)
|
||||
{
|
||||
Window.RemoveFromSlot(msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case PlayerAttachedMsg _:
|
||||
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, _openMenuCmdHandler);
|
||||
break;
|
||||
@@ -75,6 +135,34 @@ namespace Content.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
private void _setSlot(Slots slot, IEntity entity)
|
||||
{
|
||||
if (_sprite != null && entity.TryGetComponent(out ClothingComponent clothing))
|
||||
{
|
||||
var flag = SlotMasks[slot];
|
||||
var data = clothing.GetEquippedStateInfo(flag);
|
||||
if (data == null)
|
||||
{
|
||||
_sprite.LayerSetVisible(slot, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var (rsi, state) = data.Value;
|
||||
_sprite.LayerSetVisible(slot, true);
|
||||
_sprite.LayerSetRSI(slot, rsi);
|
||||
_sprite.LayerSetState(slot, state);
|
||||
}
|
||||
}
|
||||
|
||||
_window?.AddToSlot(slot, entity);
|
||||
}
|
||||
|
||||
private void _clearSlot(Slots slot)
|
||||
{
|
||||
_window?.RemoveFromSlot(slot);
|
||||
_sprite?.LayerSetVisible(slot, false);
|
||||
}
|
||||
|
||||
public void SendUnequipMessage(Slots slot)
|
||||
{
|
||||
var unequipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Unequip);
|
||||
@@ -109,14 +197,10 @@ namespace Content.Client.GameObjects
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a grid container filled with slot buttons loaded from an inventory template
|
||||
/// Creates a grid container filled with slot buttons loaded from an inventory template
|
||||
/// </summary>
|
||||
/// <param name="TemplateName"></param>
|
||||
public void CreateInventory(string TemplateName)
|
||||
public void CreateInventory(Inventory inventory)
|
||||
{
|
||||
Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Shared").GetType("Content.Shared.GameObjects." + TemplateName);
|
||||
Inventory inventory = (Inventory)Activator.CreateInstance(type);
|
||||
|
||||
elements_x = inventory.Columns;
|
||||
|
||||
GridContainer = (GridContainer)Contents.GetChild("PanelContainer").GetChild("CenterContainer").GetChild("GridContainer");
|
||||
@@ -151,14 +235,11 @@ namespace Content.Client.GameObjects
|
||||
/// <summary>
|
||||
/// Adds the item we have equipped to the slot texture and prepares the slot button for removal
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public void AddToSlot(ServerInventoryMessage message)
|
||||
public void AddToSlot(Slots slot, IEntity entity)
|
||||
{
|
||||
InventoryButton button = InventorySlots[message.Inventoryslot];
|
||||
var entity = IoCManager.Resolve<IEntityManager>().GetEntity(message.EntityUid);
|
||||
var button = InventorySlots[slot];
|
||||
|
||||
button.EntityUid = message.EntityUid;
|
||||
var container = button.GetChild("CenterContainer");
|
||||
button.EntityUid = entity.Uid;
|
||||
button.GetChild<Button>("Button").OnPressed += RemoveFromInventory;
|
||||
button.GetChild<Button>("Button").OnPressed -= AddToInventory;
|
||||
|
||||
@@ -187,10 +268,9 @@ namespace Content.Client.GameObjects
|
||||
/// <summary>
|
||||
/// Remove element from the UI and update its button to blank texture and prepare for insertion again
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public void RemoveFromSlot(ServerInventoryMessage message)
|
||||
public void RemoveFromSlot(Slots slot)
|
||||
{
|
||||
InventoryButton button = InventorySlots[message.Inventoryslot];
|
||||
var button = InventorySlots[slot];
|
||||
button.GetChild<SpriteView>("SpriteView").Sprite = null;
|
||||
button.EntityUid = EntityUid.Invalid;
|
||||
button.GetChild<Button>("Button").OnPressed -= RemoveFromInventory;
|
||||
|
||||
Reference in New Issue
Block a user