2017-09-30 16:56:19 +02:00
|
|
|
|
using Content.Client.Interfaces.GameObjects;
|
|
|
|
|
|
using Content.Client.UserInterface;
|
2017-09-26 21:27:48 +02:00
|
|
|
|
using Content.Shared.GameObjects;
|
2017-09-30 16:56:19 +02:00
|
|
|
|
using SS14.Client.Interfaces.UserInterface;
|
2017-09-26 21:27:48 +02:00
|
|
|
|
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; }
|
2017-09-26 21:27:48 +02:00
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2018-04-07 15:31:38 +02:00
|
|
|
|
IEntity entity = null;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
entity = Owner.EntityManager.GetEntity(hand.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
// Nothing.
|
|
|
|
|
|
}
|
|
|
|
|
|
hands[hand.Key] = entity;
|
2017-09-26 21:27:48 +02:00
|
|
|
|
}
|
2017-09-30 16:56:19 +02:00
|
|
|
|
|
|
|
|
|
|
ActiveIndex = cast.ActiveIndex;
|
2017-11-09 18:04:37 +01:00
|
|
|
|
// Tell UI to update.
|
|
|
|
|
|
var uiMgr = IoCManager.Resolve<IUserInterfaceManager>();
|
2018-04-07 15:31:38 +02:00
|
|
|
|
if (!uiMgr.StateRoot.TryGetChild<HandsGui>("HandsGui", out var control))
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2018-04-07 15:31:38 +02:00
|
|
|
|
control = new HandsGui();
|
|
|
|
|
|
uiMgr.StateRoot.AddChild(control);
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
2018-04-07 15:31:38 +02:00
|
|
|
|
control.UpdateHandIcons();
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendChangeHand(string index)
|
|
|
|
|
|
{
|
2018-02-24 11:48:23 -08:00
|
|
|
|
SendNetworkMessage(new ClientChangedHandMsg(index));
|
2017-09-26 21:27:48 +02:00
|
|
|
|
}
|
2018-04-22 06:11:38 -05:00
|
|
|
|
|
|
|
|
|
|
public void UseActiveHand()
|
|
|
|
|
|
{
|
2018-04-25 06:42:35 -05:00
|
|
|
|
if(GetEntity(ActiveIndex) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendNetworkMessage(new ActivateInhandMsg());
|
|
|
|
|
|
}
|
2018-04-22 06:11:38 -05:00
|
|
|
|
}
|
2017-09-26 21:27:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|