Files
crystall-punk-14/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs

70 lines
2.0 KiB
C#
Raw Normal View History

2017-09-30 16:56:19 +02:00
using Content.Client.Interfaces.GameObjects;
using Content.Client.UserInterface;
using Content.Shared.GameObjects;
2017-09-30 16:56:19 +02:00
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>();
2017-09-30 16:56:19 +02:00
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)
{
IEntity entity = null;
try
{
entity = Owner.EntityManager.GetEntity(hand.Value);
}
catch
{
// Nothing.
}
hands[hand.Key] = entity;
}
2017-09-30 16:56:19 +02:00
ActiveIndex = cast.ActiveIndex;
// Tell UI to update.
var uiMgr = IoCManager.Resolve<IUserInterfaceManager>();
if (!uiMgr.StateRoot.TryGetChild<HandsGui>("HandsGui", out var control))
2017-09-30 16:56:19 +02:00
{
control = new HandsGui();
uiMgr.StateRoot.AddChild(control);
2017-09-30 16:56:19 +02:00
}
control.UpdateHandIcons();
2017-09-30 16:56:19 +02:00
}
public void SendChangeHand(string index)
{
SendNetworkMessage(new ClientChangedHandMsg(index));
}
public void UseActiveHand()
{
if(GetEntity(ActiveIndex) != null)
{
SendNetworkMessage(new ActivateInhandMsg());
}
}
}
}