Example #1
0
    private IEnumerator showCooldown()
    {
        isSpellActive = true;

        var assignedSpell = SpellDefinition.FindByName(this.Spell);

        var sprite = GetComponent <dfControl>().Find("CoolDown") as dfSprite;

        sprite.IsVisible = true;

        var startTime = Time.realtimeSinceStartup;
        var endTime   = startTime + assignedSpell.Recharge;

        while (Time.realtimeSinceStartup < endTime)
        {
            var elapsed = Time.realtimeSinceStartup - startTime;
            var lerp    = 1f - elapsed / assignedSpell.Recharge;

            sprite.FillAmount = lerp;

            yield return(null);
        }

        sprite.FillAmount = 1f;
        sprite.IsVisible  = false;

        isSpellActive = false;
    }
    private void refresh()
    {
        var control   = gameObject.GetComponent <dfControl>();
        var container = control.Parent as dfScrollPanel;

        if (container != null)
        {
            control.Width = container.Width - container.ScrollPadding.horizontal;
        }

        var slot           = control.GetComponentInChildren <SpellSlot>();
        var lblCosts       = control.Find <dfLabel>("lblCosts");
        var lblName        = control.Find <dfLabel>("lblName");
        var lblDescription = control.Find <dfLabel>("lblDescription");

        if (lblCosts == null)
        {
            throw new Exception("Not found: lblCosts");
        }
        if (lblName == null)
        {
            throw new Exception("Not found: lblName");
        }
        if (lblDescription == null)
        {
            throw new Exception("Not found: lblDescription");
        }

        var assignedSpell = SpellDefinition.FindByName(this.Spell);

        if (assignedSpell == null)
        {
            slot.Spell          = "";
            lblCosts.Text       = "";
            lblName.Text        = "";
            lblDescription.Text = "";
            return;
        }
        else
        {
            slot.Spell          = this.spellName;
            lblName.Text        = assignedSpell.Name;
            lblCosts.Text       = string.Format("{0}/{1}/{2}", assignedSpell.Cost, assignedSpell.Recharge, assignedSpell.Delay);
            lblDescription.Text = assignedSpell.Description;
        }

        // Resize this control to match the size of the contents
        var descriptionHeight = lblDescription.RelativePosition.y + lblDescription.Size.y;
        var costsHeight       = lblCosts.RelativePosition.y + lblCosts.Size.y;

        control.Height = Mathf.Max(descriptionHeight, costsHeight) + 5;
    }
Example #3
0
    private void refresh()
    {
        var assignedSpell = SpellDefinition.FindByName(this.Spell);

        var sprite = GetComponent <dfControl>().Find <dfSprite>("Icon");

        sprite.SpriteName = assignedSpell != null ? assignedSpell.Icon : "";

        var label = GetComponentInChildren <dfButton>();

        label.IsVisible = this.IsActionSlot;
        label.Text      = this.slotNumber.ToString();
    }
    public void OnMouseHover(dfControl control, dfMouseEventArgs mouseEvent)
    {
        if (isTooltipVisible)
        {
            return;
        }

        var isSpellSlot = actionBar.Controls.Contains(mouseEvent.Source);

        if (isSpellSlot)
        {
            target = mouseEvent.Source;
            if (target == lastTarget)
            {
                return;
            }

            lastTarget = target;

            isTooltipVisible = true;

            var slot = target.GetComponentInChildren <SpellSlot>();
            if (string.IsNullOrEmpty(slot.Spell))
            {
                return;
            }

            var spell = SpellDefinition.FindByName(slot.Spell);
            if (spell == null)
            {
                return;
            }

            ActionbarsTooltip.Show(spell);
        }
        else
        {
            lastTarget = null;
        }
    }
    public void CastSpell(string spellName)
    {
        // Lookup a reference to the named spell
        var spell = SpellDefinition.FindByName(spellName);

        if (spell == null)
        {
            throw new InvalidCastException();             // lol
        }
        // Make sure that the spell is not already current
        if (activeSpells.Any(activeSpell => activeSpell.spell == spell))
        {
            return;
        }

        // Make sure there is enough Magic available
        if (Energy < spell.Cost)
        {
            return;
        }

        // Deduct the spell cost
        Energy -= spell.Cost;

        // Add the spell to the list of current spells
        activeSpells.Add(new SpellCastInfo()
        {
            spell = spell, whenCast = Time.realtimeSinceStartup
        });

        // Notify any observers that the spell was cast
        if (SpellActivated != null)
        {
            SpellActivated(spell);
        }
    }