Example #1
0
        /// <summary>
        /// Fills the menu based on the data's contents
        /// </summary>
        public virtual void FillMenu()
        {
            int tabCounter = 0;

            if (MMLogo != null)
            {
                MMLogo.color = Data.TextColor;
            }

            foreach (Transform child in Contents.transform)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (MMDebugMenuTabData tab in Data.Tabs)
            {
                if (!tab.Active)
                {
                    continue;
                }

                // create tab in the menu
                MMDebugMenuTab tabBarTab = Instantiate(Data.TabPrefab);
                tabBarTab.SelectedBackgroundColor   = Data.TextColor;
                tabBarTab.SelectedTextColor         = Data.BackgroundColor;
                tabBarTab.DeselectedBackgroundColor = Data.BackgroundColor;
                tabBarTab.DeselectedTextColor       = Data.TextColor;
                tabBarTab.TabText.text = tab.Name;
                tabBarTab.TabText.font = Data.RegularFont;
                tabBarTab.transform.SetParent(TabBar);
                tabBarTab.Index   = tabCounter;
                tabBarTab.Manager = TabManager;
                TabManager.Tabs.Add(tabBarTab);

                // create tab contents
                MMDebugMenuTabContents contents = Instantiate(Data.TabContentsPrefab);
                contents.transform.SetParent(TabContainer);
                RectTransform rectTransform = contents.GetComponent <RectTransform>();
                rectTransform.MMSetLeft(0f);
                rectTransform.MMSetRight(0f);
                rectTransform.MMSetTop(0f);
                rectTransform.MMSetBottom(0f);
                contents.Index = tabCounter;
                FillTab(contents, tabCounter);
                if (tabCounter == Data.InitialActiveTabIndex)
                {
                    contents.gameObject.SetActive(true);
                    tabBarTab.Select();
                }
                else
                {
                    contents.gameObject.SetActive(false);
                    tabBarTab.Deselect();
                }
                TabManager.TabsContents.Add(contents);

                tabCounter++;
            }

            // debug tab
            if (Data.DisplayDebugTab)
            {
                MMDebugMenuTab tabBarTab = Instantiate(Data.TabPrefab);
                tabBarTab.SelectedBackgroundColor   = Data.TextColor;
                tabBarTab.SelectedTextColor         = Data.BackgroundColor;
                tabBarTab.DeselectedBackgroundColor = Data.BackgroundColor;
                tabBarTab.DeselectedTextColor       = Data.TextColor;
                tabBarTab.TabText.text = Data.DebugTabName;
                tabBarTab.TabText.font = Data.RegularFont;
                tabBarTab.transform.SetParent(TabBar);
                tabBarTab.Index   = tabCounter;
                tabBarTab.Manager = TabManager;
                TabManager.Tabs.Add(tabBarTab);

                MMDebugMenuDebugTab debugTab = Instantiate(Data.DebugTabPrefab);
                debugTab.DebugText.color = Data.TextColor;
                debugTab.DebugText.font  = Data.RegularFont;
                debugTab.transform.SetParent(TabContainer);

                debugTab.CommandPrompt.textComponent.font  = Data.RegularFont;
                debugTab.CommandPrompt.textComponent.color = Data.TextColor;

                debugTab.CommandPromptCharacter.font  = Data.RegularFont;
                debugTab.CommandPromptCharacter.color = Data.TextColor;

                MMDebugMenuTabContents debugTabContents = debugTab.GetComponent <MMDebugMenuTabContents>();
                debugTabContents.Index = tabCounter;
                TabManager.TabsContents.Add(debugTabContents);
                RectTransform rectTransform = debugTabContents.GetComponent <RectTransform>();
                rectTransform.MMSetLeft(0f);
                rectTransform.MMSetRight(0f);
                rectTransform.MMSetTop(0f);
                rectTransform.MMSetBottom(0f);
                if (tabCounter == Data.InitialActiveTabIndex)
                {
                    debugTab.gameObject.SetActive(true);
                    TabManager.Tabs[tabCounter].Select();
                }
                else
                {
                    debugTab.gameObject.SetActive(false);
                    TabManager.Tabs[tabCounter].Deselect();
                }
                tabCounter++;
            }

            // fill with spacers
            int spacerCount = Data.MaxTabs - tabCounter;

            for (int i = 0; i < spacerCount; i++)
            {
                RectTransform spacer = Instantiate(Data.TabSpacerPrefab);
                spacer.transform.SetParent(TabBar);
            }
        }
Example #2
0
        protected virtual void FillTab(MMDebugMenuTabContents tab, int index)
        {
            Transform parent = tab.Parent;

            foreach (MMDebugMenuItem item in Data.Tabs[index].MenuItems)
            {
                if (!item.Active)
                {
                    continue;
                }

                switch (item.Type)
                {
                case MMDebugMenuItem.MMDebugMenuItemTypes.Button:
                    MMDebugMenuItemButton button;
                    button                 = (item.ButtonType == MMDebugMenuItem.MMDebugMenuItemButtonTypes.Border) ? Instantiate(Data.ButtonBorderPrefab) : Instantiate(Data.ButtonPrefab);
                    button.name            = "MMDebugMenuItemButton_" + item.Name;
                    button.ButtonText.text = item.ButtonText;
                    button.ButtonEventName = item.ButtonEventName;
                    if (item.ButtonType == MMDebugMenuItem.MMDebugMenuItemButtonTypes.Border)
                    {
                        button.ButtonText.color = Data.AccentColor;
                        button.ButtonBg.color   = Data.TextColor;
                    }
                    else
                    {
                        button.ButtonText.color = Data.BackgroundColor;
                        button.ButtonBg.color   = Data.AccentColor;
                    }
                    button.ButtonText.font = Data.RegularFont;
                    button.transform.SetParent(parent);
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Checkbox:
                    MMDebugMenuItemCheckbox checkbox = Instantiate(Data.CheckboxPrefab);
                    checkbox.name            = "MMDebugMenuItemCheckbox_" + item.Name;
                    checkbox.SwitchText.text = item.CheckboxText;
                    if (item.CheckboxInitialState)
                    {
                        checkbox.Switch.SetTrue();
                    }
                    else
                    {
                        checkbox.Switch.SetFalse();
                    }
                    checkbox.CheckboxEventName = item.CheckboxEventName;
                    checkbox.transform.SetParent(parent);
                    checkbox.Switch.GetComponent <Image>().color = Data.AccentColor;
                    checkbox.SwitchText.color = Data.TextColor;
                    checkbox.SwitchText.font  = Data.RegularFont;
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Slider:
                    MMDebugMenuItemSlider slider = Instantiate(Data.SliderPrefab);
                    slider.name               = "MMDebugMenuItemSlider_" + item.Name;
                    slider.Mode               = item.SliderMode;
                    slider.RemapZero          = item.SliderRemapZero;
                    slider.RemapOne           = item.SliderRemapOne;
                    slider.TargetSlider.value = MMMaths.Remap(item.SliderInitialValue, item.SliderRemapZero, item.SliderRemapOne, 0f, 1f);
                    slider.transform.SetParent(parent);

                    slider.SliderText.text  = item.SliderText;
                    slider.SliderText.color = Data.TextColor;
                    slider.SliderText.font  = Data.RegularFont;

                    slider.SliderValueText.text  = (item.SliderMode == MMDebugMenuItemSlider.Modes.Int) ? item.SliderInitialValue.ToString() : item.SliderInitialValue.ToString("F3");
                    slider.SliderValueText.color = Data.AccentColor;
                    slider.SliderValueText.font  = Data.BoldFont;

                    slider.SliderKnob.color = Data.AccentColor;
                    slider.SliderLine.color = Data.TextColor;

                    slider.SliderEventName = item.SliderEventName;
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Spacer:
                    GameObject spacerPrefab = (item.SpacerType == MMDebugMenuItem.MMDebugMenuItemSpacerTypes.Small) ? Data.SpacerSmallPrefab : Data.SpacerBigPrefab;
                    GameObject spacer       = Instantiate(spacerPrefab);
                    spacer.name = "MMDebugMenuItemSpacer_" + item.Name;
                    spacer.transform.SetParent(parent);
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Title:
                    MMDebugMenuItemTitle title = Instantiate(Data.TitlePrefab);
                    title.name            = "MMDebugMenuItemSlider_" + item.Name;
                    title.TitleText.text  = item.TitleText;
                    title.TitleText.color = Data.TextColor;
                    title.TitleText.font  = Data.BoldFont;
                    title.TitleLine.color = Data.AccentColor;
                    title.transform.SetParent(parent);
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Choices:
                    MMDebugMenuItemChoices choicesPrefab;
                    if (item.ChoicesType == MMDebugMenuItem.MMDebugMenuItemChoicesTypes.TwoChoices)
                    {
                        choicesPrefab = Data.TwoChoicesPrefab;
                    }
                    else
                    {
                        choicesPrefab = Data.ThreeChoicesPrefab;
                    }

                    MMDebugMenuItemChoices choices = Instantiate(choicesPrefab);
                    choices.name = "MMDebugMenuItemChoices_" + item.Name;

                    choices.Choices[0].ButtonText.text = item.ChoiceOneText;
                    choices.Choices[1].ButtonText.text = item.ChoiceTwoText;

                    choices.Choices[0].ButtonEventName = item.ChoiceOneEventName;
                    choices.Choices[1].ButtonEventName = item.ChoiceTwoEventName;

                    if (item.ChoicesType == MMDebugMenuItem.MMDebugMenuItemChoicesTypes.ThreeChoices)
                    {
                        choices.Choices[2].ButtonEventName = item.ChoiceThreeEventName;
                        choices.Choices[2].ButtonText.text = item.ChoiceThreeText;
                    }

                    choices.OffColor    = Data.BackgroundColor;
                    choices.OnColor     = Data.TextColor;
                    choices.AccentColor = Data.AccentColor;

                    foreach (MMDebugMenuChoiceEntry entry in choices.Choices)
                    {
                        if (entry != null)
                        {
                            entry.ButtonText.font = Data.RegularFont;
                        }
                    }

                    choices.Select(item.SelectedChoice);
                    choices.transform.SetParent(parent);
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Value:
                    MMDebugMenuItemValue value = Instantiate(Data.ValuePrefab);
                    value.name                  = "MMDebugMenuItemValue_" + item.Name;
                    value.LabelText.text        = item.ValueLabel;
                    value.LabelText.color       = Data.TextColor;
                    value.LabelText.font        = Data.RegularFont;
                    value.ValueText.text        = item.ValueInitialValue;
                    value.ValueText.color       = Data.AccentColor;
                    value.ValueText.font        = Data.BoldFont;
                    value.RadioReceiver.Channel = item.ValueMMRadioReceiverChannel;
                    value.transform.SetParent(parent);
                    break;

                case MMDebugMenuItem.MMDebugMenuItemTypes.Text:

                    MMDebugMenuItemText textPrefab;
                    switch (item.TextType)
                    {
                    case MMDebugMenuItem.MMDebugMenuItemTextTypes.Tiny:
                        textPrefab = Data.TextTinyPrefab;
                        break;

                    case MMDebugMenuItem.MMDebugMenuItemTextTypes.Small:
                        textPrefab = Data.TextSmallPrefab;
                        break;

                    case MMDebugMenuItem.MMDebugMenuItemTextTypes.Long:
                        textPrefab = Data.TextLongPrefab;
                        break;

                    default:
                        textPrefab = Data.TextTinyPrefab;
                        break;
                    }
                    MMDebugMenuItemText text = Instantiate(textPrefab);
                    text.name              = "MMDebugMenuItemText_" + item.Name;
                    text.ContentText.text  = item.TextContents;
                    text.ContentText.color = Data.TextColor;
                    text.ContentText.font  = Data.RegularFont;
                    text.transform.SetParent(parent);
                    break;
                }
            }

            // we always add a spacer at the end because scrollviews are terrible
            GameObject finalSpacer = Instantiate(Data.SpacerBigPrefab);

            finalSpacer.name = "MMDebugMenuItemSpacer_FinalSpacer";
            finalSpacer.transform.SetParent(parent);
        }