Example #1
0
        // ---------[ UTILITY ]---------
        /// <summary>Checks a TagContainer's template structure.</summary>
        public static bool HasValidTemplate(TagContainer container, out string helpMessage)
        {
            helpMessage = null;
            bool isValid = true;

            if (container.containerTemplate.gameObject == container.gameObject ||
                container.transform.IsChildOf(container.containerTemplate))
            {
                helpMessage = ("This Tag Container has an invalid template."
                               + "\nThe container template cannot share the same GameObject"
                               + " as this Tag Container component, and cannot be a parent of"
                               + " this object.");
                isValid = false;
            }

            TagContainerItem itemTemplate = container.containerTemplate.GetComponentInChildren <TagContainerItem>(true);

            if (itemTemplate == null ||
                container.containerTemplate.gameObject == itemTemplate.gameObject)
            {
                helpMessage = ("This Tag Container has an invalid template."
                               + "\nThe container template needs a child with the TagContainerItem"
                               + " component attached to use as the item template.");
                isValid = false;
            }

            return(isValid);
        }
        // ---------[ UTILITY ]---------
        /// <summary>Checks a ModContainer's template structure.</summary>
        public static bool HasValidTemplate(ExplorerFilterTagsDropdown selector, out string helpMessage)
        {
            helpMessage = null;

            // - null checks -
            if (selector.categoryDisplay == null ||
                !GameTagCategoryDisplay.HasValidTemplate(selector.categoryDisplay, out helpMessage))
            {
                helpMessage = ("The required GameTagCategoryDisplay is missing or"
                               + " has an invalid template.");
                return(false);
            }

            // - Validity checks -
            bool             isValid = true;
            TagContainerItem tagItem = selector.categoryDisplay.template.tagTemplate;

            // check for StateToggleDisplay
            if (tagItem.gameObject.GetComponentInChildren <StateToggleDisplay>(true) == null)
            {
                helpMessage = ("This ExplorerFilterTagsDropdown has an invalid template."
                               + "\nThe tag template of the GameTagCategoryDisplay must"
                               + " also have a StateToggleDisplay derived component as"
                               + " a child, or on the same GameObject."
                               + "\n(EG. GameObjectToggle, StateToggle, or SlideToggle.)");
                isValid = false;
            }

            return(isValid);
        }
 /// <summary>Helper function for removing a tag from the RequestFilter.</summary>
 public void RemoveTagFromExplorerFilter(TagContainerItem tagItem)
 {
     if (this.m_view != null && !this.m_isUpdating)
     {
         this.m_view.RemoveTagFromFilter(tagItem.tagName.text);
     }
 }
 /// <summary>Helper function for removing a tag from the RequestFilter.</summary>
 public void AddTagToExplorerFilter(TagContainerItem tagItem)
 {
     if (this.m_view != null && !this.m_isUpdating)
     {
         this.m_view.AddTagToFilter(tagItem.tagName.text);
     }
 }
        /// <summary>Helper function for toggling tags in the RequestFilter.</summary>
        public void ToggleTagInExplorerFilter(TagContainerItem tagItem)
        {
            if (this.m_view != null && !this.m_isUpdating)
            {
                string             tagName         = tagItem.tagName.text;
                StateToggleDisplay toggleComponent = tagItem.GetComponentInChildren <StateToggleDisplay>(true);

                if (toggleComponent.isOn)
                {
                    this.m_view.AddTagToFilter(tagName);
                }
                else
                {
                    this.m_view.RemoveTagFromFilter(tagName);
                }
            }
        }
Example #6
0
        // ---------[ INITIALIZATION ]---------
        /// <summary>Initialize template.</summary>
        protected virtual void Awake()
        {
            this.containerTemplate.gameObject.SetActive(false);

            // check template
            #if DEBUG
            string message;
            if (!TagContainer.HasValidTemplate(this, out message))
            {
                Debug.LogError("[mod.io] " + message, this);
                return;
            }
            #endif

            // get template vars
            Transform templateParent         = this.containerTemplate.parent;
            string    templateInstance_name  = this.containerTemplate.gameObject.name + " (Instance)";
            int       templateInstance_index = this.containerTemplate.GetSiblingIndex() + 1;
            this.m_itemTemplate = this.containerTemplate.GetComponentInChildren <TagContainerItem>(true);

            // check if instantiated
            bool isInstantiated = (templateParent.childCount > templateInstance_index &&
                                   templateParent.GetChild(templateInstance_index).gameObject.name == templateInstance_name);
            if (isInstantiated)
            {
                this.m_templateClone = templateParent.GetChild(templateInstance_index).gameObject;
                TagContainerItem[] itemInstances = this.m_templateClone.GetComponentsInChildren <TagContainerItem>(true);

                if (itemInstances == null || itemInstances.Length == 0)
                {
                    isInstantiated = false;
                    GameObject.Destroy(this.m_templateClone);
                }
                else
                {
                    this.m_container = (RectTransform)itemInstances[0].transform.parent;

                    foreach (TagContainerItem view in itemInstances)
                    {
                        GameObject.Destroy(view.gameObject);
                    }
                }
            }

            // instantiate
            if (!isInstantiated)
            {
                this.m_templateClone = GameObject.Instantiate(this.containerTemplate.gameObject, templateParent);
                this.m_templateClone.transform.SetSiblingIndex(templateInstance_index);
                this.m_templateClone.name = templateInstance_name;

                TagContainerItem itemInstance = this.m_templateClone.GetComponentInChildren <TagContainerItem>(true);
                this.m_container = (RectTransform)itemInstance.transform.parent;

                GameObject.Destroy(itemInstance.gameObject);

                this.m_templateClone.SetActive(true);
            }

            this.DisplayTags(this.m_tags);
        }