示例#1
0
        protected override void Draw(DrawingHandle handle)
        {
            if (!TryGetHands(out IHandsComponent hands))
            {
                return;
            }

            var leftActive = hands.ActiveIndex == "left";

            handle.DrawStyleBox(handBox, leftActive ? handL : handR);
            handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);

            if (LeftHand.Entity != null && LeftHand.HeldSprite != null)
            {
                var bounds = LeftHand.HeldSprite.Size;
                handle.DrawTextureRect(LeftHand.HeldSprite,
                                       Box2i.FromDimensions(handL.Left + (int)(handL.Width / 2f - bounds.X / 2f),
                                                            handL.Top + (int)(handL.Height / 2f - bounds.Y / 2f),
                                                            (int)bounds.X, (int)bounds.Y), tile: false);
            }

            if (RightHand.Entity != null && RightHand.HeldSprite != null)
            {
                var bounds = RightHand.HeldSprite.Size;
                handle.DrawTextureRect(RightHand.HeldSprite,
                                       Box2i.FromDimensions(handR.Left + (int)(handR.Width / 2f - bounds.Y / 2f),
                                                            handR.Top + (int)(handR.Height / 2f - bounds.Y / 2f),
                                                            (int)bounds.X, (int)bounds.Y), tile: false);
            }
        }
        protected override void Draw(DrawingHandle handle)
        {
            if (_playerManager?.LocalPlayer == null)
            {
                return;
            }

            IEntity entity = _playerManager.LocalPlayer.ControlledEntity;

            if (entity == null || !entity.TryGetComponent <IHandsComponent>(out var hands))
            {
                return;
            }

            var leftActive = hands.ActiveIndex == "left";

            handle.DrawStyleBox(handBox, leftActive ? handL : handR);
            handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);

            if (LeftHand.Entity != null && LeftHand.HeldSprite != null)
            {
                var bounds = LeftHand.HeldSprite.Size;
                handle.DrawTextureRect(LeftHand.HeldSprite,
                                       Box2i.FromDimensions(handL.Left + (int)(handL.Width / 2f - bounds.X / 2f),
                                                            handL.Top + (int)(handL.Height / 2f - bounds.Y / 2f),
                                                            (int)bounds.X, (int)bounds.Y), tile: false);
            }

            if (RightHand.Entity != null && RightHand.HeldSprite != null)
            {
                var bounds = RightHand.HeldSprite.Size;
                handle.DrawTextureRect(RightHand.HeldSprite,
                                       Box2i.FromDimensions(handR.Left + (int)(handR.Width / 2f - bounds.Y / 2f),
                                                            handR.Top + (int)(handR.Height / 2f - bounds.Y / 2f),
                                                            (int)bounds.X, (int)bounds.Y), tile: false);
            }
        }