// ----------------------------------------------------------------------
        // OK
        public static void Iconize(iCS_EditorObject node)
        {
#if DEBUG
            Debug.Log("iCanScript: Iconize => " + node.DisplayName);
#endif
            if (!node.IsNode || node.DisplayOption == iCS_DisplayOptionEnum.Iconized)
            {
                return;
            }
            var iStorage = node.IStorage;
            OpenTransaction(iStorage);
            try {
                SendStartRelayoutOfTree(iStorage);
                iStorage.AnimateGraph(null,
                                      _ => {
                    node.Iconize();
                    node.SetAsHighestLayoutPriority();
                    iStorage.ForcedRelayoutOfTree();
                    node.ClearLayoutPriority();
                    var visualEditor = iCS_EditorController.FindVisualEditor();
                    if (visualEditor != null)
                    {
                        var focusNode = node.Parent;
                        if (focusNode == null)
                        {
                            focusNode = node;
                        }
                        visualEditor.SmartFocusOn(focusNode);
                    }
                }
                                      );
                SendEndRelayoutOfTree(iStorage);
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return;
            }
            CloseTransaction(iStorage, "Iconize " + node.DisplayName);
        }
        // ----------------------------------------------------------------------
        // OK
        public static iCS_EditorObject CreatePropertiesWizardElement(iCS_EditorObject parent, LibraryObject libraryObject)
        {
#if DEBUG
            Debug.Log("iCanScript: Create Instance Element => " + libraryObject.displayString);
#endif
            if (parent == null)
            {
                return(null);
            }
            var iStorage = parent.IStorage;

            iCS_EditorObject instance = null;
            OpenTransaction(iStorage);
            try {
                SendStartRelayoutOfTree(iStorage);
                iStorage.AnimateGraph(null,
                                      _ => {
                    instance = iStorage.PropertiesWizardCreate(parent, libraryObject);
                    instance.SetInitialPosition(parent.GlobalPosition);
                    instance.Iconize();
                    iStorage.ForcedRelayoutOfTree();
                }
                                      );
                SendEndRelayoutOfTree(iStorage);
            }
            catch (System.Exception) {
                instance = null;
            }
            if (instance == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Create " + libraryObject.nodeName);
            return(instance);
        }
Beispiel #3
0
        // ======================================================================
        public iCS_EditorObject PropertiesWizardCreate(iCS_EditorObject module, LibraryObject libraryObject)
        {
            if (PropertiesWizardFindFunction(module, libraryObject) != null)
            {
                return(null);
            }
            Rect             moduleRect = module.GlobalRect;
            iCS_EditorObject func       = CreateNode(module.InstanceId, libraryObject);

            func.SetInitialPosition(new Vector2(0.5f * (moduleRect.x + moduleRect.xMax), moduleRect.yMax));
            ForEachChildDataPort(func,
                                 port => {
                string modulePortName = port.DisplayName;
                if (!port.IsTargetOrSelfPort)
                {
                    modulePortName = libraryObject.nodeName;
                }
                if (port.IsInputPort)
                {
                    // Special case for "instance".
                    if (port.IsTargetPort)
                    {
                        iCS_EditorObject classPort = PropertiesWizardGetInputThisPort(module);
                        if (classPort != null)
                        {
                            SetSource(port, classPort);
                        }
                        else
                        {
                            Debug.LogWarning("iCanScript: Unable to find 'this' input port in class module: " + module.DisplayName);
                        }
                    }
                    else
                    {
                        iCS_EditorObject classPort = PropertiesWizardGetPort(module, modulePortName, VSObjectType.InDynamicDataPort);
                        if (classPort == null)
                        {
                            classPort = CreatePort(modulePortName, module.InstanceId, port.RuntimeType, VSObjectType.InDynamicDataPort);
                            SetSource(port, classPort);
                        }
                        else
                        {
                            SetSource(port, classPort);
                        }
                    }
                }
                else
                {
                    // Special case for "instance".
                    if (port.IsTargetOrSelfPort)
                    {
                    }
                    else
                    {
                        iCS_EditorObject classPort = PropertiesWizardGetPort(module, modulePortName, VSObjectType.OutDynamicDataPort);
                        if (classPort == null)
                        {
                            classPort = CreatePort(modulePortName, module.InstanceId, port.RuntimeType, VSObjectType.OutDynamicDataPort);
                            SetSource(classPort, port);
                        }
                        else
                        {
                            SetSource(classPort, port);
                        }
                    }
                }
            }
                                 );
            func.Iconize();
            return(func);
        }
Beispiel #4
0
        // ----------------------------------------------------------------------
        public static iCS_EditorObject CreateTransition(iCS_EditorObject fromStatePort, iCS_EditorObject toState, Vector2 toStatePortPos)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: Create Transition Package");
#endif
            if (fromStatePort == null || toState == null)
            {
                return(null);
            }
            if (!IsCreationAllowed())
            {
                return(null);
            }
            var iStorage = toState.IStorage;
            OpenTransaction(iStorage);
            iCS_EditorObject transitionPackage = null;
            try {
                // Create toStatePort
                iCS_EditorObject toStatePort = iStorage.CreatePort("", toState.InstanceId, typeof(void), VSObjectType.InStatePort);
                // Update port positions
                toStatePort.SetInitialPosition(toStatePortPos);
                toStatePort.UpdatePortEdge();
                fromStatePort.UpdatePortEdge();
                // Temporally connect state ports together.
                iStorage.SetSource(toStatePort, fromStatePort);
                // Create transition package
                transitionPackage = iStorage.CreateTransition(fromStatePort, toStatePort);
                // Try to position the transition in the middle
                var fromStatePortPos = fromStatePort.GlobalPosition;
                var globalPos        = 0.5f * (fromStatePortPos + toStatePortPos);
                transitionPackage.SetInitialPosition(globalPos);
                transitionPackage.Iconize();
                // Attempt to proper edge for transition ports.
                var outTransitionPort = toStatePort.ProducerPort;
                var inTransitionPort  = iStorage.GetInTransitionPort(transitionPackage);
                var diff = toStatePortPos - fromStatePortPos;
                if (Mathf.Abs(diff.x) > Mathf.Abs(diff.y))
                {
                    if (Vector2.Dot(diff, Vector2.right) > 0)
                    {
                        inTransitionPort.Edge  = NodeEdge.Left;
                        toStatePort.Edge       = NodeEdge.Left;
                        outTransitionPort.Edge = NodeEdge.Right;
                        fromStatePort.Edge     = NodeEdge.Right;
                    }
                    else
                    {
                        inTransitionPort.Edge  = NodeEdge.Right;
                        toStatePort.Edge       = NodeEdge.Right;
                        outTransitionPort.Edge = NodeEdge.Left;
                        fromStatePort.Edge     = NodeEdge.Left;
                    }
                }
                else
                {
                    if (Vector2.Dot(diff, Vector2.up) > 0)
                    {
                        inTransitionPort.Edge  = NodeEdge.Top;
                        toStatePort.Edge       = NodeEdge.Top;
                        outTransitionPort.Edge = NodeEdge.Bottom;
                        fromStatePort.Edge     = NodeEdge.Bottom;
                    }
                    else
                    {
                        inTransitionPort.Edge  = NodeEdge.Bottom;
                        toStatePort.Edge       = NodeEdge.Bottom;
                        outTransitionPort.Edge = NodeEdge.Top;
                        fromStatePort.Edge     = NodeEdge.Top;
                    }
                }
                inTransitionPort.PortPositionRatio  = 0.5f;
                outTransitionPort.PortPositionRatio = 0.5f;
                // Layout the graph
                iStorage.ForcedRelayoutOfTree();
                iStorage.ReduceCollisionOffset();
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(null);
            }
            if (transitionPackage == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Create Transition");
            SystemEvents.AnnounceVisualScriptElementAdded(transitionPackage);
            return(transitionPackage);
        }