Ejemplo n.º 1
0
        public static void Clip(Rect next, UnityLabel label, GUIStyle style, float xClip = 0, float yClip = 0)
        {
            Vector2 scroll = StateWindow.Get().scroll;
            float   x      = next.x - scroll.x;
            float   y      = next.y - scroll.y;

            if (xClip == -1)
            {
                next.x += scroll.x;
            }
            if (yClip == -1)
            {
                next.y += scroll.y;
            }
            if (xClip > 0)
            {
                style.overflow.left = (int)Mathf.Min(x - xClip, 0);
            }
            if (yClip > 0)
            {
                style.overflow.top = (int)Mathf.Min(y - yClip, 0);
            }
            bool xPass = xClip == -1 || (x + next.width > xClip);
            bool yPass = yClip == -1 || (y + next.height > yClip);

            label.value.text = style.overflow.left >= -(next.width / 4) ? label.value.text : "";
            label.value.text = style.overflow.top >= -(next.height / 4) ? label.value.text : "";
            if (xPass && yPass)
            {
                label.DrawLabel(next, style);
            }
        }
Ejemplo n.º 2
0
        public override void Clicked(int button)
        {
            var window = StateWindow.Get();

            if (button == 0)
            {
                var multiple = window.tableGUI.rows.Count(x => x.selected && !this.groupRows.Contains(x)) > 0;
                if (!multiple && !Event.current.control)
                {
                    window.DeselectAll();
                }
                this.SelectGroup(true);
                this.row.selected = this.groupRows.Count(x => x.selected) > 0;
            }
            if (button == 1)
            {
                var menu = new GenericMenu();
                menu.AddItem("Ungroup", false, this.Ungroup);
                if (this.row.table.rows.Count(x => x.selected) > 0)
                {
                    menu.AddItem("Selection/Invert", false, window.InvertSelection);
                    menu.AddItem("Selection/Deselect All", false, window.DeselectAll);
                }
                //menu.AddItem("Rename",false,this.row.target.As<StateRow>().PromptRename());
                menu.ShowAsContext();
            }
            window.Repaint();
        }
Ejemplo n.º 3
0
        public override void Draw()
        {
            Vector2 scroll = StateWindow.Get().scroll;

            this.DrawStyle();
            this.CheckClicked(scroll.x);
        }
Ejemplo n.º 4
0
 public override void Clicked(int button)
 {
     if (button == 0)
     {
         int mode = (EditorPref.Get <int>("StateWindow-Mode", 2) + 1) % 3;
         EditorPref.Set <int>("StateWindow-Mode", mode);
         this.row.table.ShowAll();
         StateWindow.Get().Repaint();
         return;
     }
 }
Ejemplo n.º 5
0
        public void RemoveAlternativeRow(object target)
        {
            var                 window   = StateWindow.Get();
            StateRow            row      = (StateRow)target;
            int                 rowIndex = window.rowIndex[row];
            List <StateRowData> data     = new List <StateRowData>(row.requirements);

            data.RemoveAt(rowIndex);
            row.requirements     = data.ToArray();
            window.rowIndex[row] = rowIndex - 1;
            window.BuildTable();
        }
Ejemplo n.º 6
0
        public void AddAlternativeRow(object target)
        {
            var                 window = StateWindow.Get();
            StateRow            row    = (StateRow)target;
            List <StateRowData> data   = new List <StateRowData>(row.requirements);

            data.Add(new StateRowData());
            row.requirements = data.ToArray();
            window.target.Refresh();
            window.rowIndex[row] = row.requirements.Length - 1;
            window.BuildTable();
        }
Ejemplo n.º 7
0
        public override void Draw()
        {
            var window = StateWindow.Get();

            this.DrawStyle();
            if (this.delayedContext)
            {
                this.Clicked(1);
                this.delayedContext = false;
            }
            this.CheckHovered(window.scroll.x);
            this.CheckClicked(window.scroll.x);
        }
Ejemplo n.º 8
0
        public override void DrawStyle()
        {
            var      window       = StateWindow.Get();
            var      row          = this.row.target.As <StateRow>();
            var      script       = row.target;
            bool     darkSkin     = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false);
            string   name         = this.target is string?(string)this.target : script.alias;
            string   background   = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm";
            Color    textColor    = darkSkin? Colors.Get("Silver") : Colors.Get("Black");
            GUIStyle style        = new GUIStyle(GUI.skin.label);
            GUIStyle expand       = Style.Get("buttonExpand", true);
            bool     fieldHovered = window.row == this.row.order;

            if (fieldHovered)
            {
                textColor  = darkSkin ? Colors.Get("ZestyBlue") : Colors.Get("White");
                background = darkSkin ? "BoxBlackHighlightBlueAWarm" : "BoxBlackHighlightBlueDWarm";
            }
            if (this.row.selected)
            {
                textColor  = darkSkin ? Colors.Get("White") : Colors.Get("White");
                background = darkSkin ? "BoxBlackHighlightCyanA" : "BoxBlackHighlightCyanCWarm";
            }
            style.fixedWidth       -= 28;
            style.margin.left       = 0;
            style.normal.textColor  = textColor;
            style.normal.background = File.GetAsset <Texture2D>(background);
            if (this.row.selected)
            {
                expand.normal.background = style.normal.background;
                expand.normal.textColor  = textColor;
                expand.hover             = expand.normal;
                style.hover = style.normal;
            }
            bool   open   = EditorPref.Get <bool>("StateWindow-GroupRow-" + row.section, false);
            string symbol = open ? "-" : "+";

            StateWindow.Clip(symbol, expand, -1, window.headerSize);
            if (GUILayoutUtility.GetLastRect().AddX(window.scroll.x).Clicked())
            {
                EditorPref.Toggle("StateWindow-GroupRow-" + row.section);
                foreach (var groupRow in this.groupRows)
                {
                    groupRow.disabled = !groupRow.disabled;
                }
                Event.current.Use();
                window.tableGUI.ShowAll();
                window.Repaint();
            }
            StateWindow.Clip(name, style, -1, window.headerSize);
        }
Ejemplo n.º 9
0
        public virtual void DrawStyle(int state = 0)
        {
            var      window   = StateWindow.Get();
            string   value    = "";
            var      stateRow = (StateRow)this.row.target;
            var      row      = this.row.target.As <StateRow>();
            int      rowIndex = window.rowIndex[row];
            var      mode     = (HeaderMode)EditorPref.Get <int>("StateWindow-Mode", 3);
            GUIStyle style    = new GUIStyle(GUI.skin.button);

            value = stateRow.requirements.Length > 1 ? (rowIndex + 1).ToString() : "";
            if (this.row.selected)
            {
                style = Style.Get("buttonSelected", true);
            }
            else if (state == -1)
            {
                style = Style.Get("buttonDisabled", true);
            }
            else if (state == 1)
            {
                style = Style.Get("buttonOn", true);
            }
            else if (state == 2)
            {
                style = Style.Get("buttonOff", true);
            }
            else if (state == 3)
            {
                style = Style.Get("buttonUsed", true);
            }
            style.fixedWidth = window.cellSize;
            if (mode == HeaderMode.HorizontalFit)
            {
                bool lastEnabled = this.row.fields.Last(x => !x.disabled) == this;
                style.margin.right = lastEnabled ? 18 : 0;
                style.fixedWidth   = lastEnabled ? 0 : style.fixedWidth;
            }
            float headerSize = window.headerSize;

            StateWindow.Clip(value.ToLabel(), style, GUI.skin.label.fixedWidth + 7, headerSize);
            if (!Proxy.IsPlaying() && GUILayoutUtility.GetLastRect().Hovered())
            {
                window.row     = this.row.order;
                window.column  = this.order;
                window.hovered = true;
            }
        }
Ejemplo n.º 10
0
        public override void Draw()
        {
            var window = StateWindow.Get();
            var title  = new GUIContent((string)this.target.As <StateTable>().gameObject.name);
            var style  = Style.Get("title");

            if (window.target.advanced)
            {
                title.text += window.tableIndex == 1 ? " <b>End</b>" : " <b>Start</b>";
            }
            style.fixedWidth = Screen.width - 24;
            Rect next = GUILayoutUtility.GetRect(title, style);

            title.ToLabel().DrawLabel(next.AddXY(window.scroll), style);
            this.CheckClicked();
        }
Ejemplo n.º 11
0
        public override void OnInspectorGUI()
        {
            EditorUI.Reset();
            this.SetupColors();
            this.DrawBreakdown();
            string message = "Click here to open the State Window.";

            message.DrawHelp();
            Rect area = GUILayoutUtility.GetLastRect();

            EditorGUIUtility.AddCursorRect(area, MouseCursor.Link);
            if (area.Clicked())
            {
                StateWindow.Begin();
            }
        }
Ejemplo n.º 12
0
 //===================================
 // Unity-Specific
 //===================================
 public void Update()
 {
     StateWindow.instance = this;
     this.wantsMouseMove  = true;
     this.CheckTarget();
     if (this.target.IsNull())
     {
         return;
     }
     Events.Add("On State Refreshed", this.BuildTable, this.target);
     if (Proxy.IsPlaying())
     {
         Events.Add("On State Updated", this.Repaint, this.target);
         this.row    = -1;
         this.column = -1;
     }
 }
Ejemplo n.º 13
0
        public override void Clicked(int button)
        {
            var window = StateWindow.Get();

            ProxyEditor.RecordObject(window.target, "State Window - Field Toggle");
            this.row.selected = false;
            int state       = 0;
            var requirement = (StateRequirement)this.target;

            if (requirement.requireOn)
            {
                state = 1;
            }
            if (requirement.requireOff)
            {
                state = 2;
            }
            if (requirement.requireUsed)
            {
                state = 3;
            }
            int amount = button == 0 ? 1 : -1;

            state += amount;
            state  = state.Modulus(4);
            requirement.requireOn   = false;
            requirement.requireOff  = false;
            requirement.requireUsed = false;
            if (state == 1)
            {
                requirement.requireOn = true;
            }
            if (state == 2)
            {
                requirement.requireOff = true;
            }
            if (state == 3)
            {
                requirement.requireUsed = true;
            }
            ProxyEditor.SetDirty(window.target);
            window.target.UpdateStates();
            window.Repaint();
        }
Ejemplo n.º 14
0
        public override void Draw()
        {
            int state       = 0;
            var window      = StateWindow.Get();
            var requirement = this.target.As <StateRequirement>();

            if (window.target.manual || requirement.name != "@External")
            {
                if (requirement.requireOn)
                {
                    state = 1;
                }
                if (requirement.requireOff)
                {
                    state = 2;
                }
                if (requirement.requireUsed)
                {
                    state = 3;
                }
                this.DrawStyle(state);
                this.CheckClicked();
            }
        }
Ejemplo n.º 15
0
        public override void Clicked(int button)
        {
            var window = StateWindow.Get();

            if (button == 0)
            {
                if (window.target.advanced)
                {
                    window.tableIndex = window.tableIndex == 0 ? 1 : 0;
                    window.BuildTable();
                }
            }
            if (button == 1)
            {
                var          menu           = new GenericMenu();
                MenuFunction markDirty      = () => ProxyEditor.SetDirty(window.target);
                MenuFunction toggleAdvanced = () => {
                    ProxyEditor.RecordObject(window.target, "State Window - Advanced Toggle");
                    window.target.advanced = !window.target.advanced;
                    window.tableIndex      = 0;
                    window.BuildTable();
                };
                MenuFunction toggleManual = () => {
                    ProxyEditor.RecordObject(window.target, "State Window - Manual Toggle");
                    window.target.manual = !window.target.manual;
                    window.BuildTable();
                };
                menu.AddItem("Advanced", window.target.advanced, toggleAdvanced + markDirty);
                if (window.target.controller != null)
                {
                    menu.AddItem("Manual", window.target.manual, toggleManual + markDirty);
                }
                menu.AddItem("Rebuild", false, window.BuildTable);
                menu.ShowAsContext();
            }
        }
Ejemplo n.º 16
0
        public override void Clicked(int button)
        {
            var window   = StateWindow.Get();
            var stateRow = (StateRow)this.row.target;
            int rowIndex = window.rowIndex[stateRow];
            var selected = this.row.table.rows.Where(x => x.selected).ToArray();

            if (Event.current.alt && stateRow.requirements.Length > 1)
            {
                int length = stateRow.requirements.Length;
                rowIndex += button == 1 ? -1 : 1;
                if (rowIndex < 0)
                {
                    rowIndex = length - 1;
                }
                if (rowIndex >= length)
                {
                    rowIndex = 0;
                }
                window.rowIndex[stateRow] = rowIndex;
                window.BuildTable();
                return;
            }
            if (!this.row.selected && button == 1)
            {
                this.delayedContext = true;
            }
            if (button == 0 || !this.row.selected)
            {
                if (Event.current.shift)
                {
                    var allRows    = this.row.table.rows;
                    int firstIndex = selected.Length < 1 ? allRows.Count - 1 : allRows.FindIndex(x => x == selected.First());
                    int lastIndex  = selected.Length < 1 ? 0 : allRows.FindIndex(x => x == selected.Last());
                    int current    = allRows.FindIndex(x => x == this.row);
                    int closest    = current.Closest(firstIndex, lastIndex);
                    foreach (var row in allRows.Skip(current.Min(closest)).Take(current.Distance(closest) + 1))
                    {
                        row.selected = !row.disabled;
                    }
                }
                else
                {
                    bool state = !this.row.selected;
                    if (!Event.current.control)
                    {
                        window.DeselectAll();
                    }
                    this.row.selected = state;
                }
            }
            else if (button == 1)
            {
                var    menu = new GenericMenu();
                string term = selected.Any(x => x.target is StateRow && !x.target.As <StateRow>().section.IsEmpty()) ? "Regroup" : "Group";
                menu.AddItem(term + " Selected", false, window.GroupSelected);
                if (selected.Count(x => !x.target.As <StateRow>().section.IsEmpty()) > 0)
                {
                    menu.AddItem("Ungroup Selected", false, window.UngroupSelected);
                }
                menu.AddItem("Selection/Invert", false, window.InvertSelection);
                menu.AddItem("Selection/Deselect All", false, window.DeselectAll);
                if (selected.Length == 1)
                {
                    menu.AddItem("Add Alternate Row", false, this.AddAlternativeRow, stateRow);
                    if (rowIndex != 0)
                    {
                        menu.AddItem("Remove Alternative Row", false, this.RemoveAlternativeRow, stateRow);
                    }
                }
                menu.ShowAsContext();
            }
            window.Repaint();
        }
Ejemplo n.º 17
0
        //===================================
        // Utility
        //===================================
        public static void Clip(UnityLabel label, GUIStyle style, float xClip = 0, float yClip = 0)
        {
            Rect next = GUILayoutUtility.GetRect(label, style);

            StateWindow.Clip(next, label, style, xClip, yClip);
        }
Ejemplo n.º 18
0
        public virtual void DrawStyle()
        {
            var      window      = StateWindow.Get();
            var      stateRow    = (StateRow)this.row.target;
            var      row         = this.row.target.As <StateRow>();
            var      script      = row.target;
            bool     darkSkin    = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false);
            string   name        = this.target is string?(string)this.target : this.target.As <StateRow>().name;
            string   background  = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm";
            Color    textColor   = darkSkin ? Colors.Get("Silver") : Colors.Get("Black");
            string   prefixColor = Colors.Get("DarkOrange").ToHex();
            GUIStyle style       = new GUIStyle(GUI.skin.label);

            style.margin.left = 5;
            bool fieldHovered = window.row == this.row.order || this.hovered;

            if (fieldHovered)
            {
                prefixColor = Colors.Get("ZestyOrange").ToHex();
                textColor   = darkSkin ? Colors.Get("ZestyBlue") : Colors.Get("White");
                background  = darkSkin ? "BoxBlackHighlightBlueAWarm" : "BoxBlackHighlightBlueDWarm";
            }
            if (this.row.selected)
            {
                prefixColor = Colors.Get("ZestyOrange").ToHex();
                textColor   = darkSkin ? Colors.Get("White") : Colors.Get("White");
                background  = darkSkin ? "BoxBlackHighlightCyanA" : "BoxBlackHighlightCyanCWarm";
            }
            if (Proxy.IsPlaying())
            {
                textColor  = Colors.Get("Gray");
                background = darkSkin ? "BoxBlackAWarm30" : "BoxWhiteBWarm50";
                bool usable = row.target is StateTable && row.target != window.target ? row.target.As <StateTable>().external : script.usable;
                if (usable)
                {
                    textColor  = darkSkin ? Colors.Get("Silver") : Colors.Get("Black");
                    background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm";
                }
                if (script.used)
                {
                    textColor  = darkSkin ? Colors.Get("White") : Colors.Get("White");
                    background = darkSkin ? "BoxBlackHighlightYellowAWarm" : "BoxBlackHighlightYellowDWarm";
                }
                if (script.active)
                {
                    textColor  = darkSkin ? Colors.Get("White") : Colors.Get("White");
                    background = darkSkin ? "BoxBlackHighlightPurpleAWarm" : "BoxBlackHighlightPurpleDWarm";
                }
            }
            if (!row.section.IsEmpty())
            {
                style.margin.left = 33;
                style.fixedWidth -= 28;
            }
            style.normal.textColor  = textColor;
            style.normal.background = File.GetAsset <Texture2D>(background);
            if (this.row.selected)
            {
                style.hover = style.normal;
            }
            int        currentRow = window.rowIndex[stateRow] + 1;
            int        totalRows  = stateRow.requirements.Length;
            var        prefix     = stateRow.requirements.Length > 1 ? "<color=" + prefixColor + "><i>[" + currentRow + "/" + totalRows + "]</i></color>  " : "";
            GUIContent content    = new GUIContent(prefix + name);

            StateWindow.Clip(content, style, -1, window.headerSize);
        }
Ejemplo n.º 19
0
 public void Ungroup()
 {
     this.SelectGroup();
     StateWindow.Get().UngroupSelected();
 }
Ejemplo n.º 20
0
        public override void Draw()
        {
            var window = StateWindow.Get();
            var hidden = !this.target.Equals("") && !window.target.manual && this.target.As <StateRequirement>().name == "@External";

            if (hidden)
            {
                return;
            }
            var target = this.target is StateRequirement?this.target.As <StateRequirement>() : null;

            var      script     = !target.IsNull() ? target.target.As <StateBehaviour>() : null;
            var      scroll     = window.scroll;
            var      label      = this.target is string?new GUIContent("") : new GUIContent(this.target.GetVariable <string>("name"));
            GUIStyle style      = new GUIStyle(GUI.skin.label);
            var      mode       = (HeaderMode)EditorPref.Get <int>("StateWindow-Mode", 2);
            bool     darkSkin   = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false);
            Color    textColor  = Colors.Get("Gray");
            string   background = darkSkin ? "BoxBlackAWarm30" : "BoxWhiteBWarm50";

            if (window.target.external)
            {
                textColor  = darkSkin ? Colors.Get("Silver") : Colors.Get("Black");
                background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm";
            }
            if (label.text == "")
            {
                this.disabled           = this.row.fields.Skip(1).Count(x => !x.disabled) < 1;
                window.headerSize       = 64;
                style.margin.left       = 5;
                style.hover             = style.normal;
                style.normal.background = File.GetAsset <Texture2D>(background);
                if (mode == HeaderMode.Vertical)
                {
                    window.headerSize = 35;
                    style.fixedHeight = style.fixedWidth;
                    StateWindow.Clip(label, style, 0, window.headerSize);
                }
                if (mode != HeaderMode.Vertical)
                {
                    StateWindow.Clip(label, style, -1, -1);
                }
                return;
            }
            bool fieldHovered = window.column == this.order;

            if (fieldHovered)
            {
                background = darkSkin ? "BoxBlackHighlightBlueAWarm" : "BoxBlackHighlightBlueDWarm";
                textColor  = darkSkin ? Colors.Get("ZestyBlue") : Colors.Get("White");
            }
            if (Proxy.IsPlaying() && !script.IsNull())
            {
                textColor  = Colors.Get("Gray");
                background = darkSkin ? "BoxBlackAWarm30" : "BoxWhiteBWarm50";
                bool usable = target.name == "@External" ? window.target.external : script.usable;
                bool active = target.name == "@External" ? window.target.external : script.active;
                if (usable)
                {
                    textColor  = darkSkin ? Colors.Get("Silver") : Colors.Get("Black");
                    background = darkSkin ? "BoxBlackA30" : "BoxWhiteBWarm";
                }
                if (script.used)
                {
                    textColor  = darkSkin ? Colors.Get("White") : Colors.Get("White");
                    background = darkSkin ? "BoxBlackHighlightYellowAWarm" : "BoxBlackHighlightYellowDWarm";
                }
                if (active)
                {
                    textColor  = darkSkin ? Colors.Get("White") : Colors.Get("White");
                    background = darkSkin ? "BoxBlackHighlightPurpleAWarm" : "BoxBlackHighlightPurpleDWarm";
                }
            }
            style.normal.textColor  = textColor;
            style.normal.background = File.GetAsset <Texture2D>(background);
            if (mode == HeaderMode.Vertical)
            {
                window.cellSize = style.fixedHeight;
                float    halfWidth  = style.fixedWidth / 2;
                float    halfHeight = style.fixedHeight / 2;
                GUIStyle rotated    = new GUIStyle(style).Rotate90();
                Rect     last       = GUILayoutUtility.GetRect(new GUIContent(""), rotated);
                GUIUtility.RotateAroundPivot(90, last.center);
                Rect position = new Rect(last.x, last.y, 0, 0);
                position.x         += halfHeight - halfWidth;
                position.y         += -halfHeight + halfWidth;
                style.overflow.left = (int)-scroll.y;
                label.text          = style.overflow.left >= -(position.width / 4) - 9 ? label.text : "";
                label.ToLabel().DrawLabel(position, style);
                GUI.matrix = Matrix4x4.identity;
            }
            else
            {
                style.fixedWidth -= 36;
                window.cellSize   = style.fixedWidth;
                if (mode == HeaderMode.HorizontalFit)
                {
                    var   visible = this.row.fields.Skip(1).Where(x => !x.disabled).ToList();
                    float area    = window.cellSize = (Screen.width - style.fixedWidth - 56) / visible.Count;
                    area = window.cellSize = Mathf.Floor(area - 2);
                    bool lastEnabled = visible.Last() == this;
                    style.margin.right = lastEnabled ? 18 : 0;
                    style.fixedWidth   = lastEnabled ? 0 : area;
                }
                style.alignment = TextAnchor.MiddleCenter;
                StateWindow.Clip(label, style, GUI.skin.label.fixedWidth + 7, -1);
            }
            this.CheckClicked(0, scroll.y);
        }