Files
tbd-station-14/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs
Acruid b005d661f8 Component Messaging Rework (#36)
* Remove DiscoBall.

* Changes `IEntity.AddComponent(IComponent)` to `IEntity.AddComponent<T>`.

* Pulled ComponentManager registration out of Component into Entity.

* Killed component message params.

* Updated engine submodule.
2018-02-24 11:48:23 -08:00

54 lines
1.6 KiB
C#

using Content.Client.Interfaces.GameObjects;
using Content.Client.UserInterface;
using Content.Shared.GameObjects;
using SS14.Client.Interfaces.UserInterface;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
using System.Collections.Generic;
namespace Content.Client.GameObjects
{
public class HandsComponent : SharedHandsComponent, IHandsComponent
{
private readonly Dictionary<string, IEntity> hands = new Dictionary<string, IEntity>();
public string ActiveIndex { get; private set; }
public IEntity GetEntity(string index)
{
if (hands.TryGetValue(index, out var entity))
{
return entity;
}
return null;
}
public override void HandleComponentState(ComponentState state)
{
var cast = (HandsComponentState)state;
hands.Clear();
foreach (var hand in cast.Hands)
{
hands[hand.Key] = Owner.EntityManager.GetEntity(hand.Value);
}
ActiveIndex = cast.ActiveIndex;
// Tell UI to update.
var uiMgr = IoCManager.Resolve<IUserInterfaceManager>();
if (!uiMgr.TryGetSingleComponent<HandsGui>(out var component))
{
component = new HandsGui();
uiMgr.AddComponent(component);
}
component.UpdateHandIcons();
}
public void SendChangeHand(string index)
{
SendNetworkMessage(new ClientChangedHandMsg(index));
}
}
}