Esempio n. 1
0
        private void OnButtonClicked(DMButtonUI inButton)
        {
            int           index = inButton.ElementIndex;
            DMElementInfo info  = m_CurrentMenu.Menu.Elements[index];

            switch (info.Type)
            {
            case DMElementType.Button:
            {
                info.Button.Callback();
                UpdateElements();
                break;
            }

            case DMElementType.Toggle:
            {
                bool bNewValue = !inButton.ToggleState();
                info.Toggle.Setter(bNewValue);
                inButton.UpdateToggleState(bNewValue);
                UpdateElements();
                break;
            }

            case DMElementType.Submenu:
            {
                PushMenu(info.Submenu.Submenu);
                break;
            }
            }
        }
Esempio n. 2
0
        private void PopulateMenu(DMInfo inMenu, int inPageIndex)
        {
            EnsureInitialized();

            if (m_CurrentMenu.Menu == inMenu && m_CurrentMenu.PageIndex == inPageIndex)
            {
                return;
            }

            m_CurrentMenu.Menu = inMenu;

            if (inMenu == null)
            {
                Clear();
                return;
            }

            int elementsPerPage, maxPages;

            GetPageSettings(inMenu, out maxPages, out elementsPerPage);

            m_CurrentMenu.PageIndex            = Mathf.Clamp(inPageIndex, 0, maxPages - 1);
            m_MenuStack[m_MenuStack.Count - 1] = m_CurrentMenu;
            m_CurrentPageCount = maxPages;

            m_Header.Init(inMenu.Header, m_MenuStack.Count > 1);

            int usedButtons  = 0;
            int usedTexts    = 0;
            int usedDividers = 0;
            int siblingIndex = m_SiblingIndexStart;

            int elementOffset = m_CurrentMenu.PageIndex * elementsPerPage;
            int elementCount  = Math.Min(elementsPerPage, inMenu.Elements.Count - elementOffset);
            int elementIndex;

            for (int i = 0; i < elementCount; i++)
            {
                elementIndex = i + elementOffset;

                DMElementInfo info = inMenu.Elements[elementIndex];
                switch (info.Type)
                {
                case DMElementType.Divider:
                {
                    RectTransform divider;
                    if (usedDividers >= m_ActiveDividers.Count)
                    {
                        divider = AllocDivider();
                    }
                    else
                    {
                        divider = m_ActiveDividers[usedDividers];
                    }
                    divider.SetSiblingIndex(siblingIndex++);
                    ++usedDividers;
                    break;
                }

                case DMElementType.Button:
                case DMElementType.Toggle:
                case DMElementType.Submenu:
                {
                    DMButtonUI button;
                    if (usedButtons >= m_ActiveButtons.Count)
                    {
                        button = AllocButton();
                    }
                    else
                    {
                        button = m_ActiveButtons[usedButtons];
                    }
                    button.Initialize(elementIndex, info, m_CachedButtonOnClick, m_IndentSpacing * info.Indent);
                    button.transform.SetSiblingIndex(siblingIndex++);
                    usedButtons++;
                    break;
                }

                case DMElementType.Text:
                {
                    DMTextUI text;
                    if (usedTexts >= m_ActiveTexts.Count)
                    {
                        text = AllocText();
                    }
                    else
                    {
                        text = m_ActiveTexts[usedTexts];
                    }
                    text.Initialize(elementIndex, info, m_IndentSpacing * info.Indent);
                    text.transform.SetSiblingIndex(siblingIndex++);
                    usedTexts++;
                    break;
                }
                }
            }

            int buttonsToRemove = m_ActiveButtons.Count - usedButtons;

            while (buttonsToRemove > 0)
            {
                DMButtonUI button = m_ActiveButtons.PopBack();
                button.transform.SetParent(m_ElementPool, false);
                m_InactiveButtons.PushBack(button);
                buttonsToRemove--;
            }

            int textsToRemove = m_ActiveTexts.Count - usedTexts;

            while (textsToRemove > 0)
            {
                DMTextUI text = m_ActiveTexts.PopBack();
                text.transform.SetParent(m_ElementPool, false);
                m_InactiveTexts.PushBack(text);
                textsToRemove--;
            }

            int dividersToRemove = m_ActiveDividers.Count - usedDividers;

            while (dividersToRemove > 0)
            {
                RectTransform divider = m_ActiveDividers.PopBack();
                divider.transform.SetParent(m_ElementPool, false);
                m_InactiveDividers.PushBack(divider);
                dividersToRemove--;
            }

            if (maxPages > 1)
            {
                m_Page.gameObject.SetActive(true);
                m_Page.transform.SetSiblingIndex(siblingIndex++);
                m_Page.UpdatePage(m_CurrentMenu.PageIndex, maxPages);
            }
            else
            {
                m_Page.gameObject.SetActive(false);
            }
        }