Example #1
0
        private void GeneratePopup(Item.Type type, int amount = 1)
        {
            PopupData data = new PopupData(sprites, type, amount);

            foreach (ItemPopupObject ipo in activePopups)
            {
                if (ipo.Data.ItemType == type)
                {
                    ipo.AddAmount(data.Amount);
                    return;
                }
            }

            for (int i = 0; i < popupsToShow.Count; i++)
            {
                PopupData pd = popupsToShow[i];
                if (pd.ItemType == type)
                {
                    pd.AddAmount(amount);
                    return;
                }
            }

            if (ViewingLimitReached)
            {
                popupsToShow.Add(data);
            }
            else
            {
                ItemPopupObject po = GetAnInactivePopup;
                po.Data = data;
            }
        }
Example #2
0
        protected override void RemovePopup(PopupObject po)
        {
            ItemPopupObject ipo = (ItemPopupObject)po;

            ipo.ActivateElements(false);
            base.RemovePopup(po);
        }
Example #3
0
        private ItemPopupObject CreatePopup()
        {
            RectTransform popup        = Instantiate(popupPrefab, transform, false);
            Image         UIImage      = popup.GetComponent <Image>();
            Material      materialCopy = Instantiate(UIImage.material);

            UIImage.material = materialCopy;
            ItemPopupObject po = new ItemPopupObject(popup,
                                                     materialCopy,
                                                     popup.GetChild(0).GetComponent <Image>(),
                                                     popup.GetChild(1).GetChild(0).GetComponent <Text>(),
                                                     popup.GetChild(1).GetChild(1).GetComponent <Text>());

            popup.anchoredPosition += Vector2.down * po.Height;
            inactivePopups.Add(po);
            po.ActivateElements(false);
            return(po);
        }
Example #4
0
        private void Update()
        {
            while (popupsToShow.Count > 0)
            {
                if (activePopups.Count == popupViewLimit)
                {
                    scrollDelayTimer += Time.unscaledDeltaTime;
                    if (scrollDelayTimer >= scrollDelay)
                    {
                        RemovePopupsWithID(activePopups.Count - 1);
                        foreach (ItemPopupObject ipo in activePopups)
                        {
                            ipo.SetTimer(Mathf.Max(0f, ipo.Timer - scrollDelayTimer));
                        }
                        scrollDelayTimer = 0f;
                    }
                    else
                    {
                        break;
                    }
                }

                if (activePopups.Count < popupViewLimit)
                {
                    PopupData       data = popupsToShow[0];
                    ItemPopupObject po   = GetAnInactivePopup;
                    po.Data = data;
                    popupsToShow.RemoveAt(0);
                }
            }

            foreach (ItemPopupObject ipo in activePopups)
            {
                int ID = ipo.ID;
                ipo.MaterialFlash = 1f;
                float delta        = ipo.MaterialRadius;
                float popupHeight  = ipo.Height;
                float targetHeight = GetTargetHeight(ipo);
                if (!Mathf.Approximately(delta, 1f) ||
                    !Mathf.Approximately(ipo.transform.anchoredPosition.y, targetHeight))
                {
                    delta = Mathf.MoveTowards(delta, 1f, Time.unscaledDeltaTime * popupEntrySpeed);
                    ipo.MaterialRadius             = delta;
                    ipo.transform.anchoredPosition = Vector2.Lerp(ipo.transform.anchoredPosition,
                                                                  new Vector2(XPos, targetHeight),
                                                                  Time.unscaledDeltaTime * popupMoveSpeed);
                    if (delta >= 0.833f)
                    {
                        ipo.ActivateElements(true);
                        Color colorDelta = Color.Lerp(
                            Color.white,
                            textColor,
                            (delta - 0.833f) / textFadeSpeed);
                        ipo.NameColour = ipo.DescriptionColour = colorDelta;
                    }
                }

                ipo.AddTimer(Time.unscaledDeltaTime);
            }

            RemovePopupsWithTimerGreaterThanOrEqualToTime(fullDelay);

            foreach (ItemPopupObject ipo in inactivePopups)
            {
                ipo.MaterialFlash = 0f;
                float delta = ipo.MaterialRadius;
                if (!Mathf.Approximately(delta, 0f))
                {
                    delta = Mathf.MoveTowards(delta, 0f, Time.unscaledDeltaTime * popupEntrySpeed);
                    ipo.MaterialRadius = delta;
                    Vector2 targetPos = new Vector2(
                        XPos,
                        ipo.transform.anchoredPosition.y);
                    ipo.transform.anchoredPosition =
                        Vector2.Lerp(ipo.transform.anchoredPosition,
                                     targetPos,
                                     Time.unscaledDeltaTime * popupMoveSpeed);
                    if (delta <= 0f)
                    {
                        ipo.transform.gameObject.SetActive(false);
                    }
                }
            }
        }