示例#1
0
        /// <summary>
        /// Initializes the button with the given element info.
        /// </summary>
        public void Initialize(int inElementIndex, DMElementInfo inInfo, Action <DMButtonUI> inOnClick, int inIndent)
        {
            ElementIndex = inElementIndex;
            m_OnClick    = inOnClick;
            m_Label.SetText(inInfo.Label);

            RectOffset padding = m_IndentGroup.padding;

            padding.left          = inIndent;
            m_IndentGroup.padding = padding;

            SetInteractive(DMInfo.EvaluateOptionalPredicate(inInfo.Predicate), true);

            switch (inInfo.Type)
            {
            case DMElementType.Button:
            case DMElementType.Submenu:
            {
                SetToggleState(false, true);
                break;
            }

            case DMElementType.Toggle:
            {
                SetToggleState(inInfo.Toggle.Getter(), true);
                break;
            }
            }
        }
示例#2
0
        private int IndexOfMenu(DMInfo inMenu)
        {
            for (int i = 0, len = m_MenuStack.Count; i < len; i++)
            {
                if (m_MenuStack[i].Menu == inMenu)
                {
                    return(i);
                }
            }

            return(-1);
        }
示例#3
0
 private void GetPageSettings(DMInfo inMenu, out int outMaxPages, out int outElementsPerPage)
 {
     if (m_MaxElementsPerPage <= 0 || inMenu.Elements.Count <= 0)
     {
         outMaxPages        = 1;
         outElementsPerPage = inMenu.Elements.Count;
     }
     else
     {
         outMaxPages        = (int)Math.Ceiling((float)inMenu.Elements.Count / m_MaxElementsPerPage);
         outElementsPerPage = m_MaxElementsPerPage;
     }
 }
示例#4
0
        /// <summary>
        /// Pushes a new menu onto the stack.
        /// </summary>
        public void PushMenu(DMInfo inMenu)
        {
            int existingIndex = IndexOfMenu(inMenu);

            if (existingIndex >= 0)
            {
                int removeCount = m_MenuStack.Count - 1 - existingIndex;
                if (removeCount > 0)
                {
                    m_MenuStack.RemoveFromBack(removeCount);
                }
            }
            else
            {
                m_MenuStack.PushBack(new MenuStackItem(inMenu, 0));
            }

            PopulateMenu(inMenu, 0);
        }
示例#5
0
        /// <summary>
        /// Updates all element's
        /// </summary>
        public void UpdateElements()
        {
            foreach (var button in m_ActiveButtons)
            {
                DMElementInfo info = m_CurrentMenu.Menu.Elements[button.ElementIndex];
                button.UpdateInteractive(DMInfo.EvaluateOptionalPredicate(info.Predicate));
                switch (info.Type)
                {
                case DMElementType.Toggle:
                {
                    button.UpdateToggleState(info.Toggle.Getter());
                    break;
                }
                }
            }

            foreach (var text in m_ActiveTexts)
            {
                DMTextInfo textInfo = m_CurrentMenu.Menu.Elements[text.ElementIndex].Text;
                text.UpdateValue(textInfo.Getter());
            }
        }
示例#6
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);
            }
        }
示例#7
0
 /// <summary>
 /// Clears the menu stack and goes to a new menu.
 /// </summary>
 public void GotoMenu(DMInfo inMenu)
 {
     m_MenuStack.Clear();
     PushMenu(inMenu);
 }
示例#8
0
 public MenuStackItem(DMInfo inMenu, int inPageIndex)
 {
     Menu      = inMenu;
     PageIndex = inPageIndex;
 }