/// <summary>
        /// Raises the draw link keyword collections entry event.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="index">Index.</param>
        /// <param name="hyperTextProcessor">
        /// A SerializedProperty representation of a <see cref="Candlelight.UI.HyperTextProcessor"/>.
        /// </param>
        /// <param name="getAllAssignedCollections">
        /// A method to get all <see cref="Candlelight.KeywordCollection"/> objects assigned to the
        /// <see cref="Candlelight.UI.HyperTextProcessor"/>.
        /// </param>
        public static void OnDrawLinkKeywordCollectionsEntry(
            Rect position,
            int index,
            SerializedProperty hyperTextProcessor,
            System.Func <IEnumerable <KeywordCollection> > getAllAssignedCollections
            )
        {
            HyperTextStyles styles =
                hyperTextProcessor.FindPropertyRelative("m_Styles").objectReferenceValue as HyperTextStyles;

            if (styles != null)
            {
                styles.GetCascadedLinkStyles(s_CascadedLinkStyles);
            }
            OnDrawKeywordCollectionClassEntry(
                position,
                hyperTextProcessor.FindPropertyRelative("m_LinkKeywordCollections").GetArrayElementAtIndex(index),
                s_LinkKeywordIdentifierGUIContent,
                styles == null ?
                s_EmptyIdentifierCollection : from style in s_CascadedLinkStyles select style.ClassName,
                ValidationStatus.Info,
                "link style with class name",
                styles,
                getAllAssignedCollections()
                );
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the validation statuses, labels, and tooltips for custom styles.
        /// </summary>
        private void UpdateCustomStyleGUIContents()
        {
            // rebuild inheritance
            m_InheritedLinks.Clear();
            m_InheritedQuads.Clear();
            m_InheritedTags.Clear();
            m_InheritTooltip  = "";
            m_OverrideTooltip = "";
            HyperTextStyles styles = this.target as HyperTextStyles;

            styles.GetInheritedStyles(s_InheritedStyles);
            m_ParentStyle = s_InheritedStyles.Where(s => s != null).LastOrDefault();
            if (m_ParentStyle != null)
            {
                m_InheritedLinks  = styles.GetInheritedLinkStyles();
                m_InheritedQuads  = styles.GetInheritedQuadStyles();
                m_InheritedTags   = styles.GetInheritedCustomTextStyles();
                m_InheritTooltip  = string.Format("will inherit from {0}", m_ParentStyle.name);
                m_OverrideTooltip = string.Format("overriding style inherited from {0}", m_ParentStyle.name);
            }
            // rebuild tooltips and icons
            m_LinkGUIContents.Clear();
            using (
                ListPool <HyperTextStyles.LinkSubclass> .Scope links = new ListPool <HyperTextStyles.LinkSubclass> .Scope()
                )
            {
                styles.GetLinkStyles(links.List);
                for (int i = 0; i < links.List.Count; ++i)
                {
                    m_LinkGUIContents[i]       = ValidateIdentifier(links.List[i].Identifier, links.List);
                    m_LinkGUIContents[i].Label = new GUIContent(
                        string.IsNullOrEmpty(links.List[i].Identifier) ?
                        string.Format("Link Style {0}", i) :
                        string.Format("<a class=\"{0}\">", links.List[i].Identifier)
                        );
                    UpdateValidatationStatusIfOverridingInheritedStyle(
                        m_LinkGUIContents[i], links.List[i].Identifier, m_InheritedLinks
                        );
                }
                m_QuadGUIContents.Clear();
                using (ListPool <HyperTextStyles.Quad> .Scope quads = new ListPool <HyperTextStyles.Quad> .Scope())
                {
                    styles.GetQuadStyles(quads.List);
                    styles.GetCascadedLinkStyles(links.List);
                    for (int i = 0; i < quads.List.Count; ++i)
                    {
                        m_QuadGUIContents[i]       = ValidateIdentifier(quads.List[i].Identifier, quads.List);
                        m_QuadGUIContents[i].Label = new GUIContent(
                            string.IsNullOrEmpty(quads.List[i].Identifier) ?
                            string.Format("Quad Style {0}", i) :
                            string.Format("<quad class=\"{0}\">", quads.List[i].Identifier)
                            );
                        if (
                            m_QuadGUIContents[i].Status == ValidationStatus.Okay &&
                            !string.IsNullOrEmpty(quads.List[i].LinkClassName) &&
                            !string.IsNullOrEmpty(quads.List[i].LinkId)
                            )
                        {
                            if (
                                links.List.Count(
                                    link => link.Identifier.ToLower() == quads.List[i].LinkClassName.ToLower()
                                    ) == 0
                                )
                            {
                                m_QuadGUIContents[i].Status        = ValidationStatus.Error;
                                m_QuadGUIContents[i].StatusTooltip = string.Format(
                                    "No link style with class name {0} exists.", quads.List[i].LinkClassName
                                    );
                            }
                        }
                        UpdateValidatationStatusIfOverridingInheritedStyle(
                            m_QuadGUIContents[i], quads.List[i].Identifier, m_InheritedQuads
                            );
                    }
                }
            }
            m_TagGUIContents.Clear();
            using (ListPool <HyperTextStyles.Text> .Scope tags = new ListPool <HyperTextStyles.Text> .Scope())
            {
                styles.GetCustomTextStyles(tags.List);
                for (int i = 0; i < tags.List.Count; ++i)
                {
                    m_TagGUIContents[i]       = ValidateIdentifier(tags.List[i].Identifier, tags.List, "Tag");
                    m_TagGUIContents[i].Label = new GUIContent(
                        string.IsNullOrEmpty(tags.List[i].Identifier) ?
                        string.Format("Text Style {0}", i) : string.Format("<{0}>", tags.List[i].Identifier)
                        );
                    UpdateValidatationStatusIfOverridingInheritedStyle(
                        m_TagGUIContents[i], tags.List[i].Identifier, m_InheritedTags
                        );
                }
            }
            // update list of inherited style names based on current tab
            m_CurrentTabInheritedStyleNames.Clear();
            switch (s_CustomStyleTabPreference.CurrentValue)
            {
            case CustomStyleTab.CustomTextStyles:
                m_CurrentTabInheritedStyleNames = (
                    from kv in m_InheritedTags
                    where kv.Value != this.target
                    select string.Format("{0} ({1})", kv.Key.Identifier, kv.Value.name)
                    ).ToList();
                break;

            case CustomStyleTab.LinkStyles:
                m_CurrentTabInheritedStyleNames = (
                    from kv in m_InheritedLinks
                    where kv.Value != this.target
                    select string.Format("{0} ({1})", kv.Key.Identifier, kv.Value.name)
                    ).ToList();
                break;

            case CustomStyleTab.QuadStyles:
                m_CurrentTabInheritedStyleNames = (
                    from kv in m_InheritedQuads
                    where kv.Value != this.target
                    select string.Format("{0} ({1})", kv.Key.Identifier, kv.Value.name)
                    ).ToList();
                break;
            }
        }