public void OnPointerEnter(PointerEventData eventData)
    {
        //create tooltip
        tooltip = Instantiate(tooltipPrefab);
        RectTransform rect = tooltip.GetComponent <RectTransform>();

        rect.position = eventData.position;
        rect.SetParent(transform.parent, true);
        rect.SetAsLastSibling();
        ClearCircles();
        if (abilities.Count > 0 && abilities[0].GetRange() > 0)
        {
            foreach (var ability in abilities)
            {
                if (!ability.IsDestroyed())
                {
                    circles.Add(ability, Instantiate(rangeCirclePrefab, transform.parent.parent.Find("Circle Holder")).GetComponent <CircleGraphic>());
                    circles[ability].color = PlayerCore.GetPlayerFactionColor();
                }
            }
        }

        //rangeCircle.enabled = true;
        PollRangeCircle();
        Text text = tooltip.transform.Find("Text").GetComponent <Text>();

        text.text = abilityInfo;

        rect.sizeDelta = new Vector2(text.preferredWidth + 16f, text.preferredHeight + 16);
    }
    void PollRangeCircle()
    {
        foreach (var ability in abilities)
        {
            if (ability.GetRange() > 0 && circles.ContainsKey(ability))
            {
                if (ability.IsDestroyed())
                {
                    circles[ability].enabled = false;
                    continue;
                }
                else
                {
                    circles[ability].enabled = true;
                }

                circles[ability].color = ability.TimeUntilReady() > 0 ? Color.gray : PlayerCore.GetPlayerFactionColor();
                var range     = ability.GetRange();
                var cameraPos = CameraScript.instance.transform.position;
                cameraPos.z = 0;
                range       = Camera.main.WorldToScreenPoint(cameraPos + new Vector3(0, range)).y - Camera.main.WorldToScreenPoint(cameraPos).y;
                range      *= 2;

                circles[ability].rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(ability.transform.position);
                circles[ability].rectTransform.sizeDelta        = new Vector2(range, range);
                //Debug.Log(Camera.main.ScreenToWorldPoint((Vector3)rangeCircle.rectTransform.anchoredPosition +
                //    new Vector3(0,range / 2,CameraScript.zLevel) ) - abilities[0].transform.position);
            }
        }
    }
Example #3
0
    /// <summary>
    /// Initializes the Health Bar UI
    /// </summary>
    public void Initialize(PlayerCore player)
    {
        instance     = this;
        this.player  = player;
        barsArray    = new Image[3]; // initialize arrays
        oldBarsArray = new Image[3];
        gleamArray   = new Image[3];
        gleaming     = new bool[barsArray.Length];
        gleamed      = new bool[barsArray.Length];
        Color[] colors    = new Color[] { PlayerCore.GetPlayerFactionColor(), new Color(0.8F, 0.8F, 0.8F), new Color(0.4F, 0.8F, 1.0F) };
        Color[] oldColors = new Color[] { colors[0] / 2, new Color(0.3F, 0.3F, 0.3F), new Color(0.1F, 0.2F, 0.3F) };
        for (int i = 0; i < barsArray.Length; i++)
        {
            // iterate through array
            barsArray[i]            = Instantiate(inputBar).GetComponent <Image>();     // instantiate the image
            barsArray[i].fillAmount = 0;                                                // initialize fill to 0 for cool animation
            barsArray[i].color      = colors[i];
            oldBarsArray[i]         = Instantiate(barsArray[i]).GetComponent <Image>(); // instantiate the image
            for (int j = 0; j < oldBarsArray[i].transform.childCount; j++)
            {
                Destroy(oldBarsArray[i].transform.GetChild(j).gameObject);
            }

            oldBarsArray[i].fillAmount = 1;
            oldBarsArray[i].color      = oldColors[i];
            Vector3 tmp = barsArray[i].transform.position;
            tmp.y -= 24 * i;
            barsArray[i].transform.position = oldBarsArray[i].transform.position = tmp;
            oldBarsArray[i].transform.SetParent(transform, false);        // set as parent to the object this script is on
            barsArray[i].transform.SetParent(transform, false);           // set as parent to the object this script is on

            gleamArray[i] = Instantiate(inputBar).GetComponent <Image>(); // instantiate the image
            if (gleamArray[i].GetComponentInChildren <Text>())
            {
                foreach (Text text in gleamArray[i].GetComponentsInChildren <Text>())
                {
                    Destroy(text.gameObject);
                }
            }

            gleamArray[i].fillAmount = 0; // initialize fill to 0 for cool animation
            tmp    = gleamArray[i].transform.position;
            tmp.y -= 24 * i;
            gleamArray[i].transform.position = tmp;
            gleamArray[i].transform.SetParent(transform, false); // set as parent to the object this script is on
        }

        ChangeHudDamageIndicator(PlayerPrefs.GetFloat("HealthBarScript_hudDamageIndicator", 0.5F));
        initialized = true; // set to initialized
    }
    private void Update()
    {
        if (dragging)
        {
            var xPos = Input.mousePosition.x;
            AbilityHandler.RearrangeID(xPos, (AbilityID)abilities[0].GetID(), (AbilityID)abilities[0].GetID() == AbilityID.SpawnDrone ? (abilities[0] as SpawnDrone).spawnData.drone : null);
        }

        // update the number of off-CD abilities
        if (offCDCountText)
        {
            offCDCountText.text = abilities.FindAll(a => a && !a.IsDestroyed() &&
                                                    (a.TimeUntilReady() == 0 || a.GetAbilityType() == AbilityHandler.AbilityTypes.Passive)).Count + "";
        }

        if (tooltip)
        {
            tooltip.transform.position = Input.mousePosition;
        }

        if (!entity || visualMode)
        {
            return;
        }

        // there's no point in running Update if there is no ability
        if (!abilities.Exists(ab => ab && !ab.IsDestroyed()) || entity.GetIsDead())
        {
            if (offCDCountText)
            {
                offCDCountText.text = "";
            }

            if (image)
            {
                image.color = new Color(.1f, .1f, .1f); // make the background dark
            }

            if (gleam)
            {
                Destroy(gleam.gameObject); // remove other sprites; destroying makes them irrelevant
            }

            if (cooldown)
            {
                Destroy(cooldown.gameObject);
            }

            return;
        }

        abilities.Sort((a, b) =>
        {
            if (!a.IsDestroyed() && b.IsDestroyed())
            {
                return(-1);
            }
            else if (a.IsDestroyed() && !b.IsDestroyed())
            {
                return(1);
            }

            if (a.TimeUntilReady() > b.TimeUntilReady())
            {
                return(1);
            }
            else if (a.TimeUntilReady() < b.TimeUntilReady())
            {
                return(-1);
            }
            else if (a.GetTier() > b.GetTier())
            {
                return(-1);
            }
            else if (a.GetTier() < b.GetTier())
            {
                return(1);
            }
            else
            {
                return(0);
            }
        });

        ReflectDescription(abilities[0]);
        ReflectTier(abilities[0]);
        ReflectName(abilities[0]);

        if (entity.GetHealth()[2] < abilities[0].GetEnergyCost())
        {
            image.color = new Color(0, 0, 0.3F); // make the background dark blue
        }
        else if (abilities[0].GetAbilityType() != AbilityHandler.AbilityTypes.Passive && (abilities[0].State == Ability.AbilityState.Active ||
                                                                                          abilities[0].State == Ability.AbilityState.Charging ||
                                                                                          (abilities[0] is WeaponAbility && abilities[0].State == Ability.AbilityState.Ready)))
        {
            image.color = PlayerCore.GetPlayerFactionColor();
        }
        else
        {
            image.color = Color.white;
        }

        cooldown.fillAmount = abilities[0].TimeUntilReady() / abilities[0].GetCDDuration();

        if (!entity.GetIsDead())
        {
            bool hotkeyAccepted = (InputManager.GetKeyDown(keycode) && !InputManager.GetKey(KeyName.TurretQuickPurchase)) &&
                                  !PlayerViewScript.paused && !DialogueSystem.isInCutscene;
            if (abilities[0] is WeaponAbility)
            {
                foreach (var ab in abilities)
                {
                    if (hotkeyAccepted || (clicked && Input.mousePosition == oldInputMousePos))
                    {
                        ab.Activate();
                    }
                }
            }
            else if (hotkeyAccepted || (clicked && Input.mousePosition == oldInputMousePos))
            {
                abilities[0].Activate();
            }
        }

        clicked = false;

        // gleam (ability temporarily going white when cooldown refreshed) stuff
        if (gleaming)
        {
            Gleam();
        }

        if (abilities[0].TimeUntilReady() != 0)
        {
            gleamed = false;
        }
        else if (!gleamed && !gleaming)
        {
            gleamed     = true;
            gleaming    = true;
            gleam.color = Color.white;
        }
    }