Exemplo n.º 1
0
    public void Refresh()
    {
        if (LevelToUnlock < 0 || LevelToUnlock >= 3)
        {
            return;
        }

        ChoicesValue s = GameManager.instance.Data.GetDataValue(stat).Choices[LevelToUnlock];

        if (s == null)
        {
            return;
        }

        if (s.IsUnlocked && s.Amount == 0 && !HasBoughtToday)
        {
            buttonText.text = "Buy " + Cost;
            this.GetComponentInChildren <Button>().interactable = true;
        }
    }
    public void SetChoices(Stat type)
    {
        StatHandler.instance.SetStat(type);

        float current = DataHandler.GetPercent(type);

        for (int i = 0; i < 3; i++)
        {
            ChoicesValue c = GameManager.instance.Data.GetDataValue(type).Choices[i];
            if (!c.IsUnlocked || c.Amount == 0)
            {
                Choices[i].SetActive(false);
                continue;
            }
            Choices[i].transform.GetChild(0).GetComponent <Text>().text = c.ChoiceText + " (Cost: " + c.APCost + ")";
            if (GameManager.instance.ActionPoints < c.APCost)
            {
                Choices[i].GetComponent <Button>().interactable = false;
                Choices[i].GetComponent <EventTrigger>().triggers.Clear();
                Choices[i].GetComponent <Button>().onClick.RemoveAllListeners();
                continue;
            }

            Choices[i].SetActive(true);
            Choices[i].GetComponent <Image>().color = Colors.Find(x => x.stat == type).color;
            float        toAdd = GameManager.instance.Data.GetDataValue(type).Choices[i].MeterFill;
            EventTrigger e     = Choices[i].GetComponent <EventTrigger>();
            e.triggers.Clear();

            EventTrigger.Entry entry = new EventTrigger.Entry
            {
                eventID  = EventTriggerType.PointerEnter,
                callback = new EventTrigger.TriggerEvent()
            };

            entry.callback.AddListener((data) =>
            {
                StatHandler.instance.ReturnAssistBar();
                StatHandler.instance.SetStat(type);
                StatHandler.instance.SetAssistBar(current + toAdd);
            });

            e.triggers.Add(entry);
            entry = new EventTrigger.Entry
            {
                eventID  = EventTriggerType.PointerExit,
                callback = new EventTrigger.TriggerEvent()
            };

            entry.callback.AddListener((data) => StatHandler.instance.ReturnAssistBar());

            e.triggers.Add(entry);

            Button b = Choices[i].GetComponent <Button>();
            int    d = i;
            b.interactable = true;
            b.onClick.RemoveAllListeners();
            b.onClick.AddListener(() => {
                StatHandler.instance.SetBar(current + toAdd);
                GameManager.instance.DecreaseActionPoints(c.APCost);
                ActionDone.instance.DoAction(type, d);

                if (type == Stat.Nourishment)
                {
                    GameManager.instance.UseItem(type, d);
                }
            });
        }
    }