Пример #1
0
        public HandsGui()
        {
            IoCManager.InjectDependencies(this);

            var textureHandLeft   = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_l.png");
            var textureHandRight  = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_r.png");
            var textureHandActive = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_active.png");
            var storageTexture    = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/back.png");

            _rightStatusPanel = new ItemStatusPanel(true);
            _leftStatusPanel  = new ItemStatusPanel(false);

            _leftButton  = new ItemSlotButton(textureHandLeft, storageTexture);
            _rightButton = new ItemSlotButton(textureHandRight, storageTexture);
            var hBox = new HBoxContainer
            {
                SeparationOverride = 0,
                Children           = { _rightStatusPanel, _rightButton, _leftButton, _leftStatusPanel }
            };

            AddChild(hBox);

            _leftButton.OnPressed         += args => HandKeyBindDown(args, HandNameLeft);
            _leftButton.OnStoragePressed  += args => _OnStoragePressed(args, HandNameLeft);
            _rightButton.OnPressed        += args => HandKeyBindDown(args, HandNameRight);
            _rightButton.OnStoragePressed += args => _OnStoragePressed(args, HandNameRight);

            // Active hand
            _leftButton.AddChild(ActiveHandRect = new TextureRect
            {
                Texture      = textureHandActive,
                TextureScale = (2, 2)
            });
        public void UpdateCooldown(ItemSlotButton button, IEntity entity)
        {
            var cooldownDisplay = button.CooldownDisplay;

            if (entity != null &&
                entity.TryGetComponent(out ItemCooldownComponent cooldown) &&
                cooldown.CooldownStart.HasValue &&
                cooldown.CooldownEnd.HasValue)
            {
                var start = cooldown.CooldownStart.Value;
                var end   = cooldown.CooldownEnd.Value;

                var length   = (end - start).TotalSeconds;
                var progress = (_gameTiming.CurTime - start).TotalSeconds / length;
                var ratio    = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5);

                cooldownDisplay.Progress = MathHelper.Clamp((float)ratio, -1, 1);

                if (ratio > -1f)
                {
                    cooldownDisplay.Visible = true;
                }
                else
                {
                    cooldownDisplay.Visible = false;
                }
            }
Пример #3
0
        public void UpdateCooldown(ItemSlotButton button, IEntity entity)
        {
            var cooldownTexture = button.CooldownCircle;

            if (entity != null &&
                entity.TryGetComponent(out ItemCooldownComponent cooldown) &&
                cooldown.CooldownStart.HasValue &&
                cooldown.CooldownEnd.HasValue)
            {
                var start = cooldown.CooldownStart.Value;
                var end   = cooldown.CooldownEnd.Value;

                var length   = (end - start).TotalSeconds;
                var progress = (_gameTiming.CurTime - start).TotalSeconds;
                var ratio    = (float)(progress / length);

                var textureIndex = CalculateCooldownLevel(ratio);
                if (textureIndex == CooldownLevels)
                {
                    cooldownTexture.Visible = false;
                }
                else
                {
                    cooldownTexture.Visible = true;
                    cooldownTexture.Texture = _texturesCooldownOverlay[textureIndex];
                }
            }
        public void UpdateCooldown(ItemSlotButton button, IEntity entity)
        {
            var cooldownDisplay = button.CooldownDisplay;

            if (entity != null &&
                entity.TryGetComponent(out ItemCooldownComponent cooldown) &&
                cooldown.CooldownStart.HasValue &&
                cooldown.CooldownEnd.HasValue)
            {
                var start = cooldown.CooldownStart.Value;
                var end   = cooldown.CooldownEnd.Value;

                var length   = (end - start).TotalSeconds;
                var progress = (_gameTiming.CurTime - start).TotalSeconds;
                var ratio    = 1 - (float)(progress / length).Clamp(0, 1);

                cooldownDisplay.Fraction = ratio;

                if (ratio > 0)
                {
                    cooldownDisplay.Visible = true;
                }
                else
                {
                    cooldownDisplay.Visible = false;
                }
            }
Пример #5
0
#pragma warning restore 0649

        public bool SetItemSlot(ItemSlotButton button, IEntity entity)
        {
            if (entity == null)
            {
                button.SpriteView.Sprite     = null;
                button.StorageButton.Visible = false;
            }
            else
            {
                if (!entity.TryGetComponent(out ISpriteComponent sprite))
                {
                    return(false);
                }
                button.SpriteView.Sprite     = sprite;
                button.StorageButton.Visible = entity.HasComponent <ClientStorageComponent>();
            }
            return(true);
        }
Пример #6
0
        public void HoverInSlot(ItemSlotButton button, IEntity?entity, bool fits)
        {
            if (entity == null || !button.MouseIsHovering)
            {
                button.ClearHover();
                return;
            }

            if (!entity.HasComponent <SpriteComponent>())
            {
                return;
            }

            // Set green / red overlay at 50% transparency
            var hoverEntity = _entityManager.SpawnEntity("hoverentity", MapCoordinates.Nullspace);
            var hoverSprite = hoverEntity.GetComponent <SpriteComponent>();

            hoverSprite.CopyFrom(entity.GetComponent <SpriteComponent>());
            hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127);

            button.HoverSpriteView.Sprite = hoverSprite;
        }