/// <summary>
 /// Adds a column (Either to the last line if it's not complete or to a new one).
 /// </summary>
 /// <param name="content">Content.</param>
 /// <param name="style">The line style.</param>
 public static void AddLineColumn(string content, UITooltipLines.LineStyle style)
 {
     if (mInstance != null)
     {
         mInstance.Internal_AddLineColumn(content, style);
     }
 }
 /// <summary>
 /// Adds a new single column line.
 /// </summary>
 /// <param name="content">Content.</param>
 /// <param name="padding">The line padding.</param>
 /// <param name="style">The line style.</param>
 public static void AddLine(string content, RectOffset padding, UITooltipLines.LineStyle style)
 {
     if (mInstance != null)
     {
         mInstance.Internal_AddLine(content, padding, style);
     }
 }
 public UITooltipLineContent()
 {
     this.LineStyle       = UITooltipLines.LineStyle.Default;
     this.CustomLineStyle = string.Empty;
     this.Content         = string.Empty;
     this.IsSpacer        = false;
 }
        /// <summary>
        /// Adds a column (Either to the last line if it's not complete or to a new one).
        /// </summary>
        /// <param name="a">Content.</param>
        /// <param name="style">The line style.</param>
        protected void Internal_AddLineColumn(string a, UITooltipLines.LineStyle style)
        {
            // Make sure we have a template initialized
            if (this.m_LinesTemplate == null)
            {
                this.m_LinesTemplate = new UITooltipLines();
            }

            // Add the column
            this.m_LinesTemplate.AddColumn(a, style);
        }
        /// <summary>
        /// Adds a new single column line.
        /// </summary>
        /// <param name="a">Content.</param>
        /// <param name="style">The line style.</param>
        protected void Internal_AddLine(string a, RectOffset padding, UITooltipLines.LineStyle style)
        {
            // Make sure we have a template initialized
            if (this.m_LinesTemplate == null)
            {
                this.m_LinesTemplate = new UITooltipLines();
            }

            // Add the line
            this.m_LinesTemplate.AddLine(a, padding, style);
        }
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool isSpacer = property.FindPropertyRelative("IsSpacer").boolValue;

            UITooltipLines.LineStyle style = (UITooltipLines.LineStyle)property.FindPropertyRelative("LineStyle").enumValueIndex;

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            EditorGUI.HelpBox(new Rect(position.x + 14f, position.y, position.width - 14f, position.height), "", MessageType.None);

            // Draw label
            //EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
            position = new Rect(position.x, position.y + 6f + Spacing, position.width - 8f, EditorGUIUtility.singleLineHeight);

            // Don't make child fields be indented
            EditorGUI.indentLevel += 1;

            // Draw fields - passs GUIContent.none to each so they are drawn without labels
            if (!isSpacer)
            {
                EditorGUI.PropertyField(position, property.FindPropertyRelative("LineStyle"), new GUIContent("Style"));
                position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + Spacing, position.width, EditorGUIUtility.singleLineHeight);

                if (style == UITooltipLines.LineStyle.Custom)
                {
                    if (UITooltipManager.Instance != null)
                    {
                        this.DrawCustomStyleField(position, property.FindPropertyRelative("CustomLineStyle"));
                        position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + Spacing, position.width, EditorGUIUtility.singleLineHeight);
                    }
                    else
                    {
                        EditorGUI.PropertyField(position, property.FindPropertyRelative("CustomLineStyle"), new GUIContent("Style Name"));
                        position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + Spacing, position.width, EditorGUIUtility.singleLineHeight);
                    }
                }

                EditorGUI.PropertyField(position, property.FindPropertyRelative("Content"), new GUIContent("Content"));
                position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + Spacing, position.width, EditorGUIUtility.singleLineHeight);
            }

            EditorGUI.PropertyField(position, property.FindPropertyRelative("IsSpacer"), new GUIContent("Is Spacer ?"));
            position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + Spacing, position.width, EditorGUIUtility.singleLineHeight);

            // Set indent back to what it was
            EditorGUI.indentLevel -= 1;

            EditorGUI.EndProperty();
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            bool isSpacer = property.FindPropertyRelative("IsSpacer").boolValue;

            UITooltipLines.LineStyle style = (UITooltipLines.LineStyle)property.FindPropertyRelative("LineStyle").enumValueIndex;

            if (isSpacer)
            {
                return(base.GetPropertyHeight(property, label) + EditorGUIUtility.singleLineHeight + Spacing);
            }

            if (style == UITooltipLines.LineStyle.Custom)
            {
                return(base.GetPropertyHeight(property, label) + (EditorGUIUtility.singleLineHeight * 4f) + (Spacing * 3f));
            }

            return(base.GetPropertyHeight(property, label) + (EditorGUIUtility.singleLineHeight * 3f) + (Spacing * 2f));
        }
        /// <summary>
        /// Creates new line column object.
        /// </summary>
        /// <param name="parent">Parent.</param>
        /// <param name="content">Content.</param>
        /// <param name="isLeft">If set to <c>true</c> is left.</param>
        /// <param name="style">The style.</param>
        /// <param name="customStyle">The custom style name.</param>
        private void CreateLineColumn(Transform parent, string content, bool isLeft, UITooltipLines.LineStyle style, string customStyle)
        {
            // Create the game object
            GameObject obj = new GameObject("Column", typeof(RectTransform), typeof(CanvasRenderer));

            obj.layer = this.gameObject.layer;
            obj.transform.SetParent(parent);

            // Set scale
            (obj.transform as RectTransform).localScale = new Vector3(1f, 1f, 1f);

            // Set the pivot to top left
            (obj.transform as RectTransform).pivot = new Vector2(0f, 1f);

            // Set a fixed size for attribute columns
            if (style == UITooltipLines.LineStyle.Attribute)
            {
                VerticalLayoutGroup   vlg  = this.gameObject.GetComponent <VerticalLayoutGroup>();
                HorizontalLayoutGroup phlg = parent.gameObject.GetComponent <HorizontalLayoutGroup>();
                LayoutElement         le   = obj.AddComponent <LayoutElement>();
                le.preferredWidth = (this.m_Rect.sizeDelta.x - vlg.padding.horizontal - phlg.padding.horizontal) / 2f;
            }

            // Prepare the text component
            Text text = obj.AddComponent <Text>();

            text.text            = content;
            text.supportRichText = true;
            text.alignment       = (isLeft) ? TextAnchor.LowerLeft : TextAnchor.LowerRight;

            // Get the line style
            UITooltipLineStyle lineStyle = UITooltipManager.Instance.defaultLineStyle;

            switch (style)
            {
            case UITooltipLines.LineStyle.Title:
                lineStyle = UITooltipManager.Instance.titleLineStyle;
                break;

            case UITooltipLines.LineStyle.Attribute:
                lineStyle = UITooltipManager.Instance.attributeLineStyle;
                break;

            case UITooltipLines.LineStyle.Description:
                lineStyle = UITooltipManager.Instance.descriptionLineStyle;
                break;

            case UITooltipLines.LineStyle.Custom:
                lineStyle = UITooltipManager.Instance.GetCustomStyle(customStyle);
                break;
            }

            // Apply the line style
            text.font        = lineStyle.TextFont;
            text.fontStyle   = lineStyle.TextFontStyle;
            text.fontSize    = lineStyle.TextFontSize;
            text.lineSpacing = lineStyle.TextFontLineSpacing;
            text.color       = lineStyle.TextFontColor;

            // Add text effect components
            if (lineStyle.TextEffects.Length > 0)
            {
                foreach (UITooltipTextEffect tte in lineStyle.TextEffects)
                {
                    if (tte.Effect == UITooltipTextEffectType.Shadow)
                    {
                        Shadow s = obj.AddComponent <Shadow>();
                        s.effectColor     = tte.EffectColor;
                        s.effectDistance  = tte.EffectDistance;
                        s.useGraphicAlpha = tte.UseGraphicAlpha;
                    }
                    else if (tte.Effect == UITooltipTextEffectType.Outline)
                    {
                        Outline o = obj.AddComponent <Outline>();
                        o.effectColor     = tte.EffectColor;
                        o.effectDistance  = tte.EffectDistance;
                        o.useGraphicAlpha = tte.UseGraphicAlpha;
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Creates new line column object.
        /// </summary>
        /// <param name="parent">Parent.</param>
        /// <param name="content">Content.</param>
        /// <param name="isLeft">If set to <c>true</c> is left.</param>
        /// <param name="style">The style.</param>
        private void CreateLineColumn(Transform parent, string content, bool isLeft, UITooltipLines.LineStyle style)
        {
            // Create the game object
            GameObject obj = new GameObject("Column", typeof(RectTransform), typeof(CanvasRenderer));

            obj.layer = this.gameObject.layer;
            obj.transform.SetParent(parent);

            // Set the pivot to top left
            (obj.transform as RectTransform).pivot = new Vector2(0f, 1f);

            // Set a fixed size for attribute columns
            if (style == UITooltipLines.LineStyle.Attribute)
            {
                VerticalLayoutGroup   vlg  = this.gameObject.GetComponent <VerticalLayoutGroup>();
                HorizontalLayoutGroup phlg = parent.gameObject.GetComponent <HorizontalLayoutGroup>();
                LayoutElement         le   = obj.AddComponent <LayoutElement>();
                le.preferredWidth = (this.m_Rect.sizeDelta.x - vlg.padding.horizontal - phlg.padding.horizontal) / 2f;
            }

            // Prepare the text component
            Text text = obj.AddComponent <Text>();

            text.text            = content;
            text.supportRichText = true;
            text.alignment       = (isLeft) ? TextAnchor.LowerLeft : TextAnchor.LowerRight;

            // Prepare some style properties
            TextEffectType effect         = TextEffectType.None;
            Color          effectColor    = Color.white;
            Vector2        effectDistance = new Vector2(1f, -1f);
            bool           effectUseAlpha = true;

            switch (style)
            {
            case UITooltipLines.LineStyle.Title:
                text.font        = this.m_TitleFont;
                text.fontStyle   = this.m_TitleFontStyle;
                text.fontSize    = this.m_TitleFontSize;
                text.lineSpacing = this.m_TitleFontLineSpacing;
                text.color       = this.m_TitleFontColor;
                effect           = this.m_TitleTextEffect;
                effectColor      = this.m_TitleTextEffectColor;
                effectDistance   = this.m_TitleTextEffectDistance;
                effectUseAlpha   = this.m_TitleTextEffectUseGraphicAlpha;
                break;

            case UITooltipLines.LineStyle.Attribute:
                text.font        = this.m_AttributeFont;
                text.fontStyle   = this.m_AttributeFontStyle;
                text.fontSize    = this.m_AttributeFontSize;
                text.lineSpacing = this.m_AttributeFontLineSpacing;
                text.color       = this.m_AttributeFontColor;
                effect           = this.m_AttributeTextEffect;
                effectColor      = this.m_AttributeTextEffectColor;
                effectDistance   = this.m_AttributeTextEffectDistance;
                effectUseAlpha   = this.m_AttributeTextEffectUseGraphicAlpha;
                break;

            case UITooltipLines.LineStyle.Description:
                text.font        = this.m_DescriptionFont;
                text.fontStyle   = this.m_DescriptionFontStyle;
                text.fontSize    = this.m_DescriptionFontSize;
                text.lineSpacing = this.m_DescriptionFontLineSpacing;
                text.color       = this.m_DescriptionFontColor;
                effect           = this.m_DescriptionTextEffect;
                effectColor      = this.m_DescriptionTextEffectColor;
                effectDistance   = this.m_DescriptionTextEffectDistance;
                effectUseAlpha   = this.m_DescriptionTextEffectUseGraphicAlpha;
                break;
            }

            // Add text effect component
            if (effect == TextEffectType.Shadow)
            {
                Shadow s = obj.AddComponent <Shadow>();
                s.effectColor     = effectColor;
                s.effectDistance  = effectDistance;
                s.useGraphicAlpha = effectUseAlpha;
            }
            else if (effect == TextEffectType.Outline)
            {
                Outline o = obj.AddComponent <Outline>();
                o.effectColor     = effectColor;
                o.effectDistance  = effectDistance;
                o.useGraphicAlpha = effectUseAlpha;
            }
        }