public override void _Ready()
    {
        _fillSprite = GetNode <Sprite>("PotionFill");
        _potionBar  = GetParent().GetNode <TextureProgress>("PotionProgress");

        FillState = FillStates.Empty;
    }
    private void FillStateUpdated(FillStates state)
    {
        switch (state)
        {
        case FillStates.Empty:
            _fillSprite.Scale = Vector2.Zero;
            _fillAmount       = 0f;
            break;

        case FillStates.Filling:
            _fillSprite.Scale = Vector2.Zero;
            _fillAmount       = 0f;
            break;

        case FillStates.Full:
            break;
        }
    }
    public override void _Process(float delta)
    {
        if (_fillState == FillStates.Filling)
        {
            if (_fillAmount >= _fillGoal)
            {
                _fillAmount = _fillGoal;
                FillState   = FillStates.Full;
            }
            _fillAmount = Mathf.Lerp(_fillAmount, _fillGoal, _FillSpeed * delta);

            float spriteScale = Mathf.Clamp(_fillAmount / _MaxPower, 0f, 1f);
            _fillSprite.Scale = new Vector2(spriteScale, spriteScale);
        }

        if (_potionBarAdd > 0)
        {
            var barProgress = _potionBarAdd * delta;
            _potionBarAdd         -= barProgress;
            _potionBarFillCurrent += barProgress;

            _potionBar.Value = ((double)_potionBarFillCurrent / (double)_potionBarFillMax) * 120.0;
        }
    }
 public void InitiateCircleFill(float fillGoal)
 {
     FillState      = FillStates.Filling;
     _fillGoal      = fillGoal;
     _potionBarAdd += fillGoal;
 }
Exemple #5
0
        /**
         * Display values to the statistics UI fields given a statistic
         * component target, a respective value to set, and whether the formatted
         * value should be interpreted as a timestamp or not.
         *
         * @param statistic   the Statistic UI component to target in the Scene.
         * @param value       the value to set for the respective statistic UI component.
         * @param isTimestamp whether the value should be interpreted as a timestamp.
         * @param fillState   determines how the statistic should be displayed if a default value is assigned.
         * @param precision   determines how many decimal places to show for floating point statistics.
         */
        private void DisplayStatistic(Statistic statistic, string value, bool isTimestamp, FillStates fillState = FillStates.FILL_NA_ON_ZERO, int precision = 0)
        {
            string formatted = value.Equals("0") && fillState.Equals(FillStates.FILL_NA_ON_ZERO) ? "N/A" : value;

            if (isTimestamp)
            {
                if (value.Equals("0") && fillState.Equals(FillStates.FILL_NA_ON_ZERO))
                {
                    formatted = "N/A";
                }
                else
                {
                    formatted = Utils.GetTimestamp(float.Parse(value));
                }
            }
            else if (fillState.Equals(FillStates.NO_FILL))
            {
                // Format to show only 2 decimal places
                formatted = float.Parse(value).ToString("F" + precision);
            }

            statistic.SetText(formatted);
        }