コード例 #1
0
        protected override void OnDestroy()
        {
            foreach (var item in fields)
            {
                if (item.LineIn != null)
                {
                    item.LineIn.Remove();
                }

                for (int i = item.LinesOut.Count - 1; i >= 0; i--)
                {
                    item.LinesOut[i].Remove();
                }
            }

            if (LinesIn.Count > 0)
            {
                for (int i = LinesIn.Count - 1; i >= 0; i--)
                {
                    LinesIn[i].Remove();
                }
            }

            if (LineOut != null)
            {
                LineOut.Remove();
                LineOut = null;
            }
        }
コード例 #2
0
        public static AutomationLine HookLineIn(Automation auto)
        {
            if (Globals.TempFieldLine != null)
            {
                Globals.TempFieldLine.Remove();
                Globals.TempFieldLine = null;
            }

            if (Globals.TempAutomationLine == null)
            {
                var f = new AutomationLine();
                f.Right = auto;
                Globals.TempAutomationLine = f;
                return(f);
            }
            else
            {
                if (Globals.TempAutomationLine is ConditionalLine || Globals.TempAutomationLine is LoopableLine)
                {
                    if (Globals.TempAutomationLine.Right == null && Globals.TempAutomationLine.Left != auto)
                    {
                        AutomationLine line = null;
                        if (Globals.TempAutomationLine is ConditionalLine)
                        {
                            line = new ConditionalLine(((ConditionalLine)Globals.TempAutomationLine).Left, auto);
                        }
                        else
                        {
                            line = new LoopableLine(((LoopableLine)Globals.TempAutomationLine).Left, auto);
                        }

                        Globals.TempAutomationLine.Remove();
                        Globals.TempAutomationLine = null;
                        return(line);
                    }
                }

                if (Globals.TempAutomationLine.Right == null && Globals.TempAutomationLine.Left != auto)
                {
                    var line = new AutomationLine(Globals.TempAutomationLine.Left, auto);
                    Globals.TempAutomationLine.Remove();
                    Globals.TempAutomationLine = null;
                    return(line);
                }
                else
                {
                    Globals.TempAutomationLine.Remove();
                    Globals.TempAutomationLine = null;
                    return(HookLineIn(auto));
                }
            }
        }
コード例 #3
0
        private void RemoveOutgoingLines()
        {
            if (LineOut != null)
            {
                LineOut.Remove();
                LineOut = null;
            }

            foreach (var item in fields)
            {
                if (item.LinesOut.Count > 0)
                {
                    for (int i = item.LinesOut.Count - 1; i >= 0; i--)
                    {
                        item.LinesOut[i].Remove();
                    }
                }
            }
        }
コード例 #4
0
        public static AutomationLine HookLineOut(Automation auto)
        {
            if (Globals.TempFieldLine != null)
            {
                Globals.TempFieldLine.Remove();
                Globals.TempFieldLine = null;
            }

            if (Globals.TempAutomationLine == null)
            {
                var f = new AutomationLine();
                f.Left = auto;
                Globals.TempAutomationLine = f;
                return(f);
            }
            else
            {
                if (Globals.TempAutomationLine is ConditionalLine)
                {
                    Globals.TempAutomationLine.Remove();
                    Globals.TempAutomationLine = null;
                    return(HookLineOut(auto));
                }

                if (Globals.TempAutomationLine.Left == null && Globals.TempAutomationLine.Right != auto)
                {
                    var line = new AutomationLine(auto, Globals.TempAutomationLine.Right);
                    Globals.TempAutomationLine.Remove();
                    Globals.TempAutomationLine = null;
                    return(line);
                }
                else
                {
                    Globals.TempAutomationLine.Remove();
                    Globals.TempAutomationLine = null;
                    return(HookLineOut(auto));
                }
            }
        }
コード例 #5
0
        protected override void OnGUI()
        {
            var rect = Rectangle;

            GUI.Box(rect, "", ExtendedGUI.DefaultWindowStyle);
            if (Progress > 0 && ErrorType == ErrorType.None)
            {
                GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width * Progress, 15), Assets["progressBar"]);
            }

            Texture2D errorTex = null;

            switch (ErrorType)
            {
            case ErrorType.Execute:
                errorTex = Assets["genericException"];
                break;

            case ErrorType.Arugment:
                errorTex = Assets["argumentException"];
                break;

            case ErrorType.PreExecute:
                errorTex = Assets["genericException"];
                break;

            case ErrorType.PostExecute:
                errorTex = Assets["genericException"];
                break;
            }
            if (errorTex)
            {
                GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, 15), errorTex);
            }

            var topRect = new Rect(rect.x, rect.y, rect.width, 16);

            GUI.Label(topRect, name, headerStyle);

            if (Input.ButtonReleased(EMouseButton.Left) && topRect.Contains(Input.MousePosition))
            {
                var n = DateTime.Now.Ticks;
                var t = n - previousTicks;
                if (t <= 5000000)
                {
                    (Window as AutomatronEditor).LookAtAutomationSmooth(this);
                    n = 0;
                }
                previousTicks = n;
            }

            if (!Globals.IsError && Input.ButtonReleased(EMouseButton.Right) && topRect.Contains(Input.MousePosition))
            {
                var gm = GenericMenuBuilder.CreateMenu();
                gm.AddItem("Remove Incoming Lines", false, RemoveIncomingLines);
                gm.AddItem("Remove Outgoing Lines", false, RemoveOutgoingLines);
                gm.ShowAsContext();
            }

            if (showCloseButton && !Globals.IsExecuting)
            {
                var cRect = new Rect(rect.x + rect.width - 14, rect.y + 1, 13, 13);
                if (cRect.Contains(Input.MousePosition))
                {
                    GUI.DrawTexture(cRect, Assets["crossActive"]);

                    if (Input.ButtonReleased(EMouseButton.Left))
                    {
                        Remove();
                        Input.Use();
                    }
                }
                else
                {
                    GUI.DrawTexture(cRect, Assets["crossNormal"]);
                }
            }

            var lArrow = new Rect(rect.x - 15, rect.y, 15, 15);
            var rArrow = new Rect(rect.x + rect.width, rect.y, 15, 15);

            if (showInArrow)
            {
                GUI.DrawTexture(lArrow, Assets["arrowleft"]);

                if (!Globals.IsExecuting)
                {
                    if (Input.ButtonReleased(EMouseButton.Left))
                    {
                        if (lArrow.Contains(Input.MousePosition))
                        {
                            var line = AutomationLine.HookLineIn(this);
                            if (LinesIn.Contains(line))
                            {
                                LinesIn.Remove(line);
                            }

                            LinesIn.Add(line);
                            Window.AddControl(line);
                            Input.Use();
                        }
                    }
                    else if (Input.ButtonReleased(EMouseButton.Right))
                    {
                        if (lArrow.Contains(Input.MousePosition))
                        {
                            if (LinesIn.Count > 0)
                            {
                                for (int i = LinesIn.Count - 1; i >= 0; i--)
                                {
                                    LinesIn[i].Remove();
                                }
                            }

                            Input.Use();
                        }
                    }
                }
            }

            if (showOutArrow)
            {
                GUI.DrawTexture(rArrow, Assets["arrowright"]);

                if (!Globals.IsExecuting)
                {
                    if (Input.ButtonReleased(EMouseButton.Left))
                    {
                        if (rArrow.Contains(Input.MousePosition))
                        {
                            if (LineOut != null)
                            {
                                LineOut.Remove();
                                LineOut = null;
                            }

                            LineOut = AutomationLine.HookLineOut(this);
                            Window.AddControl(LineOut);
                            Input.Use();
                        }
                    }
                    else if (Input.ButtonReleased(EMouseButton.Right))
                    {
                        if (rArrow.Contains(Input.MousePosition))
                        {
                            if (LineOut != null)
                            {
                                LineOut.Remove();
                                LineOut = null;
                            }

                            Input.Use();
                        }
                    }
                }
            }

            if (!Globals.IsExecuting)
            {
                if (Input.ButtonPressed(EMouseButton.Left))
                {
                    dragger = null;

                    switch (SortingOrder)
                    {
                    case ESortingOrder.Automation:
                        if (rect.Contains(Input.MousePosition))
                        {
                            SortingOrder = ESortingOrder.AutomationSelected;
                        }
                        break;

                    case ESortingOrder.AutomationSelected:
                        if (!rect.Contains(Input.MousePosition))
                        {
                            SortingOrder = ESortingOrder.Automation;
                        }
                        break;
                    }
                }

                if (Input.ButtonDown(EMouseButton.Left))
                {
                    if (dragger == null)
                    {
                        var dragRect = new Rect(rect.x, rect.y, rect.width - 16, 16);
                        if (dragRect.Contains(Input.MousePosition))
                        {
                            dragger = this;
                            GUIUtility.keyboardControl = 0;
                        }
                    }
                }

                if (Input.ButtonReleased(EMouseButton.Left))
                {
                    dragger = null;
                }

                if (dragger == this)
                {
                    Position += Input.DragDelta;
                }
            }

            var fieldRect = new Rect(rect.x, rect.y + 18, rect.width, rect.height);

            foreach (var item in fields)
            {
                var height = item.GetHeight();
                fieldRect.height = height;
                item.OnGUI(fieldRect);
                fieldRect.y += height;
            }

            if (Input.ButtonReleased(EMouseButton.Right) && rect.Contains(Input.MousePosition))
            {
                Input.Use();
            }

            if (Input.ButtonDown(EMouseButton.Middle) && rect.Contains(Input.MousePosition))
            {
                Input.Use();
            }

            UpdateSize();
        }
コード例 #6
0
        public void LoadAutomatron(string path)
        {
            var a = AutomatronSerializer.Load(path);

            if (a == null)
            {
                return;
            }

            Globals.Camera = a.Camera;
            Name           = a.Name;
            Path           = a.Path;

            foreach (var item in a.Automations)
            {
                var type = Globals.Types.Where(t => t.FullName == item.Type).FirstOrDefault();
                if (type == null)
                {
                    type = Type.GetType(item.Type);
                }
                if (type == null)
                {
                    continue;
                }

                var pos = item.Position;

                var instance = (Automation)Activator.CreateInstance(type);
                instance.Position = pos;

                AddControl(instance);
                instance.ID = item.ID;
                instance.LoadFields();

                foreach (var f in item.Fields)
                {
                    var fid = instance.GetField(f.ID);
                    if (fid != null)
                    {
                        fid.SetValue(f.Value);
                    }
                }

                if (item.ID == a.EntryID)
                {
                    entryPoint = (InternalQueueStart)instance;
                    EntryId    = entryPoint.ID;
                }
            }

            var automations = GetControls <Automation>();

            foreach (var item in a.Lines)
            {
                if (item.LineType == ELineType.FieldLine)
                {
                    var left  = automations.Where(auto => auto.HasField(item.IdLeft)).FirstOrDefault();
                    var right = automations.Where(auto => auto.HasField(item.IdRight)).FirstOrDefault();

                    if (left == null || right == null)
                    {
                        continue;
                    }

                    var line = new FieldLine(left.GetField(item.IdLeft), right.GetField(item.IdRight));
                    AddControl(line);
                }
                else
                {
                    var left  = automations.Where(auto => auto.ID == item.IdLeft).FirstOrDefault();
                    var right = automations.Where(auto => auto.ID == item.IdRight).FirstOrDefault();

                    if (left == null || right == null)
                    {
                        continue;
                    }

                    BezierLine line = null;

                    switch (item.LineType)
                    {
                    case ELineType.AutomationLine:
                        line = new AutomationLine(left, right);
                        break;

                    case ELineType.ConditionalLine:
                        line = new ConditionalLine((ConditionalAutomation)left, right);
                        break;

                    case ELineType.LoopableLine:
                        line = new LoopableLine((LoopableAutomation)left, right);
                        break;
                    }

                    if (line != null)
                    {
                        AddControl(line);
                        line.ID = item.ID;
                    }
                }
            }

            var id = GetControlID();

            if (id < a.ControlID)
            {
                var amount = a.ControlID - id;
                for (int i = 0; i < amount; i++)
                {
                    GetControlID();
                }
            }

            if (entryPoint == null)
            {
                entryPoint = new InternalQueueStart()
                {
                    Position = WindowRect.center
                };
                AddControl(entryPoint);

                EntryId = entryPoint.ID;
            }
        }