Esempio n. 1
0
    public void Draw_RectLayout(string LabelText, Rect LabelAndFieldRect, Rect ButtonRect, Rect AreaRect, GUIStyle LabelStyle = null, GUIStyle InputFieldStyle = null, GUIStyle ButtonStyle = null, bool InputUnderline = false, bool ReadOnly = false)
    {
        if (LabelStyle == null)
        {
            LabelStyle = StaticLabelStyle;
        }
        if (InputFieldStyle == null)
        {
            InputFieldStyle = StaticFieldStyle;
        }
        if (ButtonStyle == null)
        {
            ButtonStyle = StaticButtonStyle;
        }

        if (!isEditing)
        {
            GUI.Label(LabelAndFieldRect, LabelText, LabelStyle);
            GUILayout.Space(4);
            if (!ReadOnly)
            {
                if (GUI.Button(ButtonRect, ButtonLabel_Edit, ButtonStyle))
                {
                    isEditing = true;
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }

            if (InputUnderline)
            {
                CustomEditorUtility.DrawSideBorder(CustomEditorUtility.Directions.Bottom, LabelAndFieldRect);
            }
        }
        else
        {
            bool temp = false;
            if (EditingCache == null)
            {
                EditingCache = LabelText;
                temp         = true;
                GUI.SetNextControlName("input");
            }

            EditingCache = EditorGUI.TextField(LabelAndFieldRect, EditingCache, InputFieldStyle);
            GUILayout.Space(4);

            if (temp)
            {
                GUI.FocusControl("input");
                temp = false;
            }

            if (GUI.Button(ButtonRect, ButtonLabel_Save, ButtonStyle) || Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
            {
                if (EditingCache != LabelText)
                {
                    Edited.Invoke(this.EditingCache);
                }
                EditingCache = null;
                isEditing    = false;
                GUI.FocusControl("0");
                if (EditorWindow.focusedWindow)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                if (!LabelAndFieldRect.Contains(Event.current.mousePosition))
                {
                    isEditing    = false;
                    EditingCache = null;
                    GUI.FocusControl("0");
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }
        }
    }
Esempio n. 2
0
    public void Draw(string labelText, bool inputUnderline = false, GUIStyle LabelStyle = null, GUIStyle InputFieldStyle = null, GUIStyle ButtonStyle = null, GUILayoutOption[] LabelAndFieldLayout = null, GUILayoutOption[] ButtonLayout = null, GUILayoutOption[] AreaLayout = null, bool ReadOnly = false)
    {
        if (LabelAndFieldLayout == null)
        {
            LabelAndFieldLayout = StaticLabelFieldLayout;
        }
        if (AreaLayout == null)
        {
            AreaLayout = StaticAreaLayout;
        }
        if (LabelStyle == null)
        {
            LabelStyle = StaticLabelStyle;
        }
        if (InputFieldStyle == null)
        {
            InputFieldStyle = StaticFieldStyle;
        }
        if (ButtonStyle == null)
        {
            ButtonStyle = StaticButtonStyle;
        }
        if (ButtonLayout == null)
        {
            ButtonLayout = StaticButtonLayout;
        }

        GUILayout.BeginHorizontal(AreaLayout);

        Rect labelAndFieldRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, LabelAndFieldLayout);
        Rect spacingRect       = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(4));
        Rect buttonRect        = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, ButtonLayout);

        if (!isEditing)
        {
            GUI.Label(labelAndFieldRect, labelText, LabelStyle);
            if (!ReadOnly)
            {
                if (GUI.Button(buttonRect, ButtonLabel_Edit, ButtonStyle))
                {
                    isEditing = true;
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }

            if (inputUnderline)
            {
                CustomEditorUtility.DrawSideBorder(CustomEditorUtility.Directions.Bottom, labelAndFieldRect);
            }
        }
        else
        {
            bool temp = false;
            if (EditingCache == null)
            {
                EditingCache = labelText;
                temp         = true;
                GUI.SetNextControlName("input");
            }

            EditingCache = EditorGUI.TextField(labelAndFieldRect, EditingCache, InputFieldStyle);

            if (temp)
            {
                GUI.FocusControl("input");
                temp = false;
            }

            if (GUI.Button(buttonRect, ButtonLabel_Save, ButtonStyle) || Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
            {
                if (EditingCache != labelText)
                {
                    Edited.Invoke(this.EditingCache);
                }
                EditingCache = null;
                isEditing    = false;
                GUI.FocusControl("0");
                if (EditorWindow.focusedWindow)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                if (!labelAndFieldRect.Contains(Event.current.mousePosition))
                {
                    isEditing    = false;
                    EditingCache = null;
                    GUI.FocusControl("0");
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }
        }
        GUILayout.EndHorizontal();
    }
Esempio n. 3
0
    public void DrawLayout(string labelText, bool inputUnderline = false, GUILayoutOption[] labelLayout = null, GUILayoutOption[] fieldLayout = null)
    {
        if (areaWidth > 0)
        {
            GUILayout.BeginHorizontal(GUILayout.Width(areaWidth));
        }
        else
        {
            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(areaExpandWidth));
        }

        if (!editing)
        {
            if (labelWidth > 0)
            {
                GUILayout.Label(labelText, LabelStyle, GUILayout.Width(labelWidth), GUILayout.Height(areaHeight));
            }
            else
            {
                GUILayout.Label(labelText, LabelStyle, GUILayout.ExpandWidth(labelExpandWidth), GUILayout.Height(areaHeight));
            }

            if (inputUnderline)
            {
                CustomEditorUtility.DrawSideBorder(CustomEditorUtility.Directions.Bottom, GUILayoutUtility.GetLastRect());
            }

            if (GUILayout.Button(editText, GUILayout.ExpandWidth(false), GUILayout.Height(areaHeight)))
            {
                editing = true;
            }
        }
        else
        {
            bool temp = false;
            if (editCache == null)
            {
                editCache = labelText;
                temp      = true;
                GUI.SetNextControlName("input");
            }
            if (labelWidth > 0)
            {
                editCache = EditorGUILayout.TextField(editCache, InputFieldStyle, GUILayout.Width(labelWidth + 60), GUILayout.MinWidth(80), GUILayout.Height(areaHeight));
            }
            else
            {
                editCache = EditorGUILayout.TextField(editCache, InputFieldStyle, GUILayout.ExpandWidth(labelExpandWidth), GUILayout.MinWidth(80), GUILayout.Height(areaHeight));
            }
            if (temp)
            {
                GUI.FocusControl("input");
                temp = false;
            }
            Rect inputRect = GUILayoutUtility.GetLastRect();

            if (GUILayout.Button(saveText, GUILayout.ExpandWidth(false), GUILayout.Height(areaHeight)) || Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
            {
                if (editCache != labelText)
                {
                    Edited.Invoke(this.editCache);
                }
                editCache = null;
                editing   = false;
                GUI.FocusControl("0");
                if (EditorWindow.focusedWindow)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            Rect buttonRect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.MouseUp)
            {
                if (!inputRect.Contains(Event.current.mousePosition) && !buttonRect.Contains(Event.current.mousePosition))
                {
                    editing   = false;
                    editCache = null;
                    GUI.FocusControl("0");
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }
        }
        GUILayout.EndHorizontal();

        if (Event.current.type == EventType.Repaint)
        {
            if (rect == null)
            {
                rect = GUILayoutUtility.GetLastRect();
            }
            topLeftPoint     = new Vector2(rect.xMin, rect.yMin);
            bottomRightPoint = new Vector2(rect.xMax, rect.yMax);
        }
    }
Esempio n. 4
0
    public void Draw(Rect position, string labelText, bool inputUnderline = false)
    {
        Rect labelRect;

        if (labelExpandWidth)
        {
            labelRect = new Rect(position.position, position.size - new Vector2(buttonWidth, 0));
        }
        else
        {
            labelRect = new Rect(position.position, new Vector2(labelWidth, position.height));
        }
        Rect inputRect = new Rect(labelRect.position, labelRect.size - new Vector2(buttonWidth + 8, 0));
        Rect buttonRect;

        buttonHeight = position.height;
        if (labelExpandWidth)
        {
            buttonRect = new Rect(position.x + position.width - buttonWidth, position.y, buttonWidth, buttonHeight);
        }
        else
        {
            buttonRect = new Rect(position.x + labelWidth + 8, position.y, buttonWidth, buttonHeight);
        }

        int cache;

        if (!editing)
        {
            cache = GUI.skin.label.fontSize;
            GUI.skin.label.fontSize = fontSize;
            if (labelWidth > 0)
            {
                GUI.Label(labelRect, labelText);
            }
            else
            {
                GUI.Label(labelRect, labelText);
            }
            GUI.skin.label.fontSize = cache;

            if (inputUnderline)
            {
                CustomEditorUtility.DrawSideBorder(CustomEditorUtility.Directions.Bottom, labelRect);
            }

            if (GUI.Button(buttonRect, editText))
            {
                editing = true;
            }
        }
        else
        {
            if (editCache == null)
            {
                editCache = labelText;
            }
            cache = GUI.skin.textField.fontSize;
            GUI.skin.textField.fontSize = fontSize;
            if (labelWidth > 0)
            {
                editCache = EditorGUI.TextField(inputRect, editCache);
            }
            else
            {
                editCache = EditorGUI.TextField(inputRect, editCache);
            }
            GUI.skin.textField.fontSize = cache;

            if (GUI.Button(buttonRect, saveText) || Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
            {
                if (editCache != labelText)
                {
                    Edited.Invoke(this.editCache);
                }
                editCache = null;
                editing   = false;
                GUI.FocusControl("0");
                if (EditorWindow.focusedWindow)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                if (!inputRect.Contains(Event.current.mousePosition) && !buttonRect.Contains(Event.current.mousePosition))
                {
                    editing   = false;
                    editCache = null;
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }
        }
    }
Esempio n. 5
0
    public string Draw_Advanced(string labelText, bool inputUnderline = false, GUIStyle labelStyle = null, GUIStyle inputFieldStyle = null, GUILayoutOption[] labelAndFieldLayout = null, GUILayoutOption[] areaLayout = null, bool ReadOnly = false)
    {
        if (labelAndFieldLayout == null)
        {
            labelAndFieldLayout = staticLabelFieldLayout;
        }
        if (areaLayout == null)
        {
            areaLayout = staticAreaLayout;
        }
        if (labelStyle == null)
        {
            labelStyle = staticLabelStyle;
        }
        if (inputFieldStyle == null)
        {
            inputFieldStyle = staticFieldStyle;
        }

        Rect labelAndFieldRect = GUILayoutUtility.GetRect(GUIContent.none, new GUIStyle(), labelAndFieldLayout);

        GUILayout.BeginHorizontal(areaLayout);

        if (!isEditing)
        {
            if (Event.current.type == EventType.MouseMove && !ReadOnly)
            {
                isHovering = (labelAndFieldRect.Contains(Event.current.mousePosition))? true : false;
                if (EditorWindow.focusedWindow)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            // if (isHovering) {
            //  GUI.Label(labelAndFieldRect, "<color=#4228FF>" + labelText + "</color>", labelStyle);
            // }
            GUI.Label(labelAndFieldRect, labelText, labelStyle);

            if (inputUnderline)
            {
                CustomEditorUtility.DrawSideBorder(CustomEditorUtility.Directions.Bottom, labelAndFieldRect);
            }

            if (!ReadOnly)
            {
                EditorGUIUtility.AddCursorRect(labelAndFieldRect, MouseCursor.Text);
            }

            if (!ReadOnly)
            {
                if (Event.current.type == EventType.MouseUp)
                {
                    if (labelAndFieldRect.Contains(Event.current.mousePosition))
                    {
                        isEditing = true;
                        if (EditorWindow.focusedWindow)
                        {
                            EditorWindow.focusedWindow.Repaint();
                        }
                    }
                }
            }
        }
        else
        {
            bool temp = false;
            if (EditingCache == null)
            {
                EditingCache = labelText;
                temp         = true;
                GUI.SetNextControlName("input");
            }

            EditingCache = EditorGUI.TextField(labelAndFieldRect, EditingCache, inputFieldStyle);

            if (showEnterTip)
            {
                GUI.Label(new Rect(labelAndFieldRect.xMax + 4, labelAndFieldRect.yMax - 14, 128, 14), "Press Enter to save.");
            }

            if (temp)
            {
                GUI.FocusControl("input");
                temp = false;
            }

            if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
            {
                if (EditingCache != labelText)
                {
                    Edited.Invoke(this.EditingCache);
                }
                EditingCache = null;
                isEditing    = false;
                GUI.FocusControl("0");
                if (EditorWindow.focusedWindow)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                if (!labelAndFieldRect.Contains(Event.current.mousePosition))
                {
                    isEditing    = false;
                    EditingCache = null;
                    GUI.FocusControl("0");
                    if (EditorWindow.focusedWindow)
                    {
                        EditorWindow.focusedWindow.Repaint();
                    }
                }
            }
        }
        GUILayout.EndHorizontal();
        return(EditingCache);
    }