Exemplo n.º 1
0
        private void HandleComponentState(EntityUid uid, HandsComponent component, ref ComponentHandleState args)
        {
            if (args.Current is not HandsComponentState state)
            {
                return;
            }

            // Do we have a NEW hand?
            var handsModified = component.Hands.Count != state.Hands.Count;

            if (!handsModified)
            {
                for (var i = 0; i < state.Hands.Count; i++)
                {
                    if (component.Hands[i].Name != state.Hands[i].Name ||
                        component.Hands[i].Location != state.Hands[i].Location)
                    {
                        handsModified = true;
                        break;
                    }
                }
            }

            if (handsModified)
            {
                // we have new hands, get the new containers.
                component.Hands = state.Hands;
                UpdateHandContainers(uid, component);
            }

            TrySetActiveHand(uid, state.ActiveHand, component);
        }
Exemplo n.º 2
0
 private void HandlePlayerAttached(EntityUid uid, HandsComponent component, PlayerAttachedEvent args)
 {
     component.Gui = new HandsGui(component, this);
     _gameHud.HandsContainer.AddChild(component.Gui);
     component.Gui.SetPositionFirst();
     UpdateGui(component);
 }
Exemplo n.º 3
0
 private void OnVisualsChanged(EntityUid uid, HandsComponent component, VisualsChangedEvent args)
 {
     // update hands visuals if this item is in a hand (rather then inventory or other container).
     if (component.TryGetHand(args.ContainerId, out var hand))
     {
         UpdateHandVisuals(uid, args.Item, hand, component);
     }
 }
        public HandsGui(HandsComponent hands, HandsSystem handsSystem)
        {
            _handsComponent = hands;
            _handsSystem    = handsSystem;

            RobustXamlLoader.Load(this);
            IoCManager.InjectDependencies(this);

            StatusPanel = ItemStatusPanel.FromSide(HandLocation.Middle);
            StatusContainer.AddChild(StatusPanel);
            StatusPanel.SetPositionFirst();
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Called when a user clicked on their hands GUI
        /// </summary>
        public void UIHandClick(HandsComponent hands, string handName)
        {
            if (!hands.TryGetHand(handName, out var pressedHand))
            {
                return;
            }

            if (!hands.TryGetActiveHand(out var activeHand))
            {
                return;
            }

            var pressedEntity = pressedHand.HeldEntity;
            var activeEntity  = activeHand.HeldEntity;

            if (pressedHand == activeHand && activeEntity != null)
            {
                // use item in hand
                // it will always be attack_self() in my heart.
                RaiseNetworkEvent(new UseInHandMsg());
                return;
            }

            if (pressedHand != activeHand && pressedEntity == null)
            {
                // change active hand
                EntityManager.RaisePredictiveEvent(new RequestSetHandEvent(handName));
                return;
            }

            if (pressedHand != activeHand && pressedEntity != null && activeEntity != null)
            {
                // use active item on held item
                RaiseNetworkEvent(new ClientInteractUsingInHandMsg(pressedHand.Name));
                return;
            }

            if (pressedHand != activeHand && pressedEntity != default && activeEntity == default)
            {
                // use active item on held item
                RaiseNetworkEvent(new MoveItemFromHandMsg(pressedHand.Name));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Called when a user clicked on their hands GUI
        /// </summary>
        public void UIHandClick(HandsComponent hands, string handName)
        {
            if (!hands.Hands.TryGetValue(handName, out var pressedHand))
            {
                return;
            }

            if (hands.ActiveHand == null)
            {
                return;
            }

            var pressedEntity = pressedHand.HeldEntity;
            var activeEntity  = hands.ActiveHand.HeldEntity;

            if (pressedHand == hands.ActiveHand && activeEntity != null)
            {
                // use item in hand
                // it will always be attack_self() in my heart.
                EntityManager.RaisePredictiveEvent(new RequestUseInHandEvent());
                return;
            }

            if (pressedHand != hands.ActiveHand && pressedEntity == null)
            {
                // change active hand
                EntityManager.RaisePredictiveEvent(new RequestSetHandEvent(handName));
                return;
            }

            if (pressedHand != hands.ActiveHand && pressedEntity != null && activeEntity != null)
            {
                // use active item on held item
                EntityManager.RaisePredictiveEvent(new RequestHandInteractUsingEvent(pressedHand.Name));
                return;
            }

            if (pressedHand != hands.ActiveHand && pressedEntity != null && activeEntity == null)
            {
                // move the item to the active hand
                EntityManager.RaisePredictiveEvent(new RequestMoveHandItemEvent(pressedHand.Name));
            }
        }
Exemplo n.º 7
0
        private void HandleComponentState(EntityUid uid, HandsComponent component, ref ComponentHandleState args)
        {
            if (args.Current is not HandsComponentState state)
            {
                return;
            }

            var handsModified = component.Hands.Count != state.Hands.Count;
            var manager       = EnsureComp <ContainerManagerComponent>(uid);

            foreach (var hand in state.Hands)
            {
                if (component.Hands.TryAdd(hand.Name, hand))
                {
                    hand.Container = _containerSystem.EnsureContainer <ContainerSlot>(uid, hand.Name, manager);
                    handsModified  = true;
                }
            }

            if (handsModified)
            {
                foreach (var name in component.Hands.Keys)
                {
                    if (!state.HandNames.Contains(name))
                    {
                        component.Hands.Remove(name);
                    }
                }

                component.SortedHands = new(state.HandNames);
            }

            TrySetActiveHand(uid, state.ActiveHand, component);

            if (uid == _playerManager.LocalPlayer?.ControlledEntity)
            {
                UpdateGui();
            }
        }
Exemplo n.º 8
0
 private static void ClearGui(HandsComponent comp)
 {
     comp.Gui?.Orphan();
     comp.Gui = null;
 }
Exemplo n.º 9
0
 private static void HandleCompRemove(EntityUid uid, HandsComponent component, ComponentRemove args)
 {
     ClearGui(component);
 }
Exemplo n.º 10
0
 private static void HandlePlayerDetached(EntityUid uid, HandsComponent component, PlayerDetachedEvent args)
 {
     ClearGui(component);
 }