Exemple #1
0
        // ----------------------------------------------------------------------
        public static bool DeleteMultiSelectedObjects(iCS_IStorage iStorage)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: Multi-Select Delete");
#endif
            if (iStorage == null)
            {
                return(false);
            }
            if (!IsDeletionAllowed())
            {
                return(false);
            }
            var selectedObjects = iStorage.GetMultiSelectedObjects();
            if (selectedObjects == null || selectedObjects.Length == 0)
            {
                return(false);
            }
            if (selectedObjects.Length == 1)
            {
                DeleteObject(selectedObjects[0]);
                return(true);
            }
            OpenTransaction(iStorage);
            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    foreach (var obj in selectedObjects)
                    {
                        if (!obj.CanBeDeleted())
                        {
                            ShowNotification("Fix port=> \"" + obj.DisplayName + "\" from node=> \"" + obj.ParentNode.FullName + "\" cannot be deleted.");
                            continue;
                        }
                        // Move the selection to the parent node
                        var parent = obj.ParentNode;
                        iStorage.SelectedObject = parent;

                        SystemEvents.AnnounceVisualScriptElementWillBeRemoved(obj);

                        if (obj.IsInstanceNodePort)
                        {
                            iStorage.PropertiesWizardDestroyAllObjectsAssociatedWithPort(obj);
                        }
                        else
                        {
                            iStorage.DestroyInstance(obj.InstanceId);
                        }
                        iStorage.ForcedRelayoutOfTree();
                    }
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(false);
            }
            CloseTransaction(iStorage, "Delete Selection");
            return(true);
        }
Exemple #2
0
        // =================================================================================
        // INITIALIZATION
        // ---------------------------------------------------------------------------------
        public static void Init(iCS_IStorage iStorage)
        {
            var editor = EditorWindow.CreateInstance <VisualScriptSettingsEditor>();

            editor.ShowUtility();
            editor.iStorage = iStorage;
        }
        // ----------------------------------------------------------------------
        // Returns the port name position in graph coordinate and GUI scale size.
        Rect GetPortNamePosition(iCS_EditorObject port, iCS_IStorage iStorage)
        {
            Vector2 labelSize = GetPortNameSize(port);
            Vector2 labelPos  = GetPortCenter(port);

            switch (port.Edge)
            {
            case iCS_EdgeEnum.Left:
                labelPos.x += iCS_EditorConfig.PortDiameter;
                labelPos.y -= 1 + 0.5f * labelSize.y / Scale;
                break;

            case iCS_EdgeEnum.Right:
                labelPos.x -= labelSize.x / Scale + iCS_EditorConfig.PortDiameter;
                labelPos.y -= 1 + 0.5f * labelSize.y / Scale;
                break;

            case iCS_EdgeEnum.Top:
                labelPos.x -= 1 + 0.5f * labelSize.x / Scale;
                labelPos.y -= iCS_EditorConfig.PortDiameter + 0.8f * (labelSize.y / Scale);
                break;

            case iCS_EdgeEnum.Bottom:
                labelPos.x -= 1 + 0.5f * labelSize.x / Scale;
                labelPos.y += iCS_EditorConfig.PortDiameter;
                break;
            }
            return(new Rect(labelPos.x, labelPos.y, labelSize.x, labelSize.y));
        }
 // ----------------------------------------------------------------------
 void FunctionMenu(iCS_EditorObject selectedObject, iCS_IStorage storage)
 {
     iCS_MenuContext[] menu;
     if (!selectedObject.IsIconizedInLayout)
     {
         // Base menu items
         menu = new iCS_MenuContext[0];
         int idx = 0;
         // -- Add Enable & Trigger --
         idx       = GrowMenuBy(ref menu, 1);
         menu[idx] = new iCS_MenuContext(EnablePortStr);
         idx       = GrowMenuBy(ref menu, 1);
         if (storage.HasTriggerPort(selectedObject))
         {
             menu[idx] = new iCS_MenuContext("#" + TriggerPortStr);
         }
         else
         {
             menu[idx] = new iCS_MenuContext(TriggerPortStr);
         }
         idx       = GrowMenuBy(ref menu, 1);
         menu[idx] = new iCS_MenuContext(SeparatorStr);
     }
     else
     {
         menu = new iCS_MenuContext[0];
     }
     AddWrapInPackageIfAppropriate(ref menu, selectedObject);
     AddShowInHierarchyMenuItem(ref menu);
     AddDeleteMenuItem(ref menu);
     ShowMenu(menu, selectedObject, storage);
 }
Exemple #5
0
        // ----------------------------------------------------------------------
        // Assures proper initialization and returns true if editor is ready
        // to execute.
        bool IsInitialized()
        {
            // Nothing to do if we don't have a Graph to edit...
            UpdateMgr();
            if (IStorage == null)
            {
                myBookmark = null;
                DragType   = DragTypeEnum.None;
                CloseSubEditor();
                return(false);
            }
            if (IStorage != myPreviousIStorage)
            {
                // Avoid using a storage without a root node.
                if (StorageRoot == null)
                {
                    return(false);
                }
                myPreviousIStorage = IStorage;
                myBookmark         = null;
                DragType           = DragTypeEnum.None;
                CloseSubEditor();
                IStorage.ForceRelayout = true;
            }

            // Don't run if graphic sub-system did not initialise.
            if (iCS_Graphics.IsInitialized == false)
            {
                iCS_Graphics.Init(IStorage);
            }

            // Update visual script cache.
            UpdateVisualScriptCache();
            return(true);
        }
        // =================================================================================
        // Storage & Selected object Update.  This update is called by the Editors.
        // ---------------------------------------------------------------------------------
        public static void Update()
        {
            // -- Use previous game object if new selection does not include a visual script. --
            GameObject go            = Selection.activeGameObject;
            var        monoBehaviour = go != null?go.GetComponent <iCS_MonoBehaviourImp>() : null;

            // -- Verify if we should save visual script. --
            if (myIStorage != null && myIStorage.iCSMonoBehaviour != monoBehaviour)
            {
                var previousMonobehaviour = myIStorage.iCSMonoBehaviour;
                if (previousMonobehaviour != null)
                {
                    ImmediateSaveWithUndo();
                    SaveAndLoad.Save(myIStorage);
                }
            }
            if (monoBehaviour == null)
            {
                // Clear if previous game object is not valid.
                ImmediateSaveWithUndo();
                myIStorage  = null;
                myIsPlaying = Application.isPlaying;
                return;
            }
            // Verify for storage change.
            bool isPlaying = Application.isPlaying;

            if (myIStorage == null || myIStorage.iCSMonoBehaviour != monoBehaviour || myIsPlaying != isPlaying)
            {
                ImmediateSaveWithUndo();
                myIsPlaying = isPlaying;
                myIStorage  = new iCS_IStorage(monoBehaviour);
                return;
            }
        }
 public static void UndoIfUndoRedoId(int modificationId, iCS_IStorage iStorage)
 {
     if (IsCurrentUndoRedoId(modificationId, iStorage))
     {
         Undo.PerformUndo();
     }
 }
 public static void MakeVisible(iCS_EditorObject eObj, iCS_IStorage iStorage)
 {
     if (eObj == null || iStorage == null)
     {
         return;
     }
     if (eObj.IsNode)
     {
         for (var parent = eObj.Parent; parent != null && parent.InstanceId != 0; parent = parent.Parent)
         {
             parent.Unfold();
         }
         return;
     }
     if (eObj.IsPort)
     {
         var portParent = eObj.ParentNode;
         if (!portParent.IsVisibleInLayout || portParent.IsIconizedInLayout)
         {
             portParent.Fold();
         }
         MakeVisible(portParent, iStorage);
         return;
     }
 }
        // ----------------------------------------------------------------------
        public static iCS_EditorObject GetNextSibling(iCS_EditorObject node, iCS_IStorage storage)
        {
            if (node == null || node.Parent == null)
            {
                return(null);
            }
            iCS_EditorObject nextSibling = null;
            iCS_EditorObject firstChild  = null;
            bool             nodeFound   = false;

            storage.UntilMatchingChildNode(node.Parent,
                                           child => {
                if (firstChild == null)
                {
                    firstChild = child;
                }
                if (child == node)
                {
                    nodeFound = true;
                    return(false);
                }
                if (nodeFound)
                {
                    nextSibling = child;
                    return(true);
                }
                return(false);
            }
                                           );
            if (!nodeFound)
            {
                return(node);
            }
            return(nextSibling ?? firstChild);
        }
Exemple #10
0
        // ----------------------------------------------------------------------
        public static iCS_EditorObject WrapMultiSelectionInPackage(iCS_IStorage iStorage)
        {
            if (iStorage == null)
            {
                return(null);
            }
            if (!IsCreationAllowed())
            {
                return(null);
            }
            var selectedObjects = iStorage.FilterMultiSelectionForWrapInPackage();

            if (selectedObjects == null || selectedObjects.Length == 0)
            {
                return(null);
            }

            iCS_EditorObject package = null;

            OpenTransaction(iStorage);
            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    var childrenRects = P.map(n => n.GlobalRect, selectedObjects);
                    package           = iStorage.WrapInPackage(selectedObjects);
                    if (package != null)
                    {
                        var r   = Math3D.Union(childrenRects);
                        var pos = Math3D.Middle(r);
                        package.SetInitialPosition(Math3D.Middle(r));
                        iStorage.ForcedRelayoutOfTree();
                        package.myAnimatedRect.StartValue = BuildRect(pos, Vector2.zero);
                        for (int i = 0; i < selectedObjects.Length; ++i)
                        {
                            selectedObjects[i].SetInitialPosition(iCS_EditorObject.PositionFrom(childrenRects[i]));
                            selectedObjects[i].LocalSize = iCS_EditorObject.SizeFrom(childrenRects[i]);
                        }
                        iStorage.ForcedRelayoutOfTree();
                        iStorage.ReduceCollisionOffset();
                    }
                    else
                    {
                        Debug.LogWarning("iCanScript: Unable to create a suitable package.");
                    }
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(null);
            }
            if (package == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Wrap Selection");
            SystemEvents.AnnounceVisualScriptElementAdded(package);
            return(package);
        }
 // ======================================================================
 // GUI helpers
 // ----------------------------------------------------------------------
 public static int SafeSelectAndMakeVisible(iCS_EditorObject selected, iCS_IStorage iStorage)
 {
     iCS_UserCommands.OpenTransaction(iStorage);
     iCS_UserCommands.Select(selected, iStorage);
     CenterOn(selected, iStorage);
     iCS_UserCommands.CloseTransaction(iStorage, "Focus on: " + selected.DisplayName);
     return(iStorage.UndoRedoId);
 }
Exemple #12
0
        // ----------------------------------------------------------------------
        static void SendEndRelayoutOfTree(iCS_IStorage iStorage)
        {
            var visualEditor = iCS_EditorController.FindVisualEditor();

            if (visualEditor != null && visualEditor.IStorage == iStorage)
            {
                visualEditor.OnEndRelayoutOfTree();
            }
        }
Exemple #13
0
        // ----------------------------------------------------------------------
        static void SendDisplayRootChange(iCS_IStorage iStorage)
        {
            var visualEditor = iCS_EditorController.FindVisualEditor();

            if (visualEditor != null && visualEditor.IStorage == iStorage)
            {
                visualEditor.OnDisplayRootChange();
            }
        }
        public static void CenterOn(iCS_EditorObject eObj, iCS_IStorage iStorage)
        {
            MakeVisible(eObj, iStorage);
            var graphEditor = iCS_EditorController.FindVisualEditor();

            if (graphEditor != null)
            {
                graphEditor.CenterAndScaleOn(eObj);
            }
        }
Exemple #15
0
 // ----------------------------------------------------------------------
 private static void RebuildChildrenLists(iCS_IStorage iStorage)
 {
     iStorage.ForEach(
         obj => {
         if (obj.IsParentValid)
         {
             obj.Parent.AddChild(obj);
         }
     }
         );
 }
 // ----------------------------------------------------------------------
 void SelectedPortMenu(iCS_EditorObject port, iCS_IStorage storage)
 {
     iCS_MenuContext[] menu = new iCS_MenuContext[1];
     menu[0] = new iCS_MenuContext(ShowHierarchyStr);
     // Allow to delete a port if its parent is a module.
     if (port.CanBeDeleted())
     {
         AddDeleteMenuItem(ref menu);
     }
     ShowMenu(menu, port, storage);
 }
        // ----------------------------------------------------------------------
        static string GetPortPath(iCS_EditorObject port, iCS_IStorage iStorage)
        {
            iCS_EditorObject parent = port.Parent;
            string           path   = parent.DisplayName;

            for (parent = parent.Parent; parent != null && parent != iStorage[0]; parent = parent.Parent)
            {
                path += "." + parent.DisplayName;
            }
            return(path);
        }
Exemple #18
0
        // ======================================================================
        // Rebuild from engine database.
        // ----------------------------------------------------------------------
        public iCS_EditorObject(int id, iCS_IStorage iStorage)
        {
            myIStorage = iStorage;
            myId       = id;
            var parent = Parent;

            if (parent != null)
            {
                parent.AddChild(this);
            }
        }
 public static void SaveWithUndo(iCS_IStorage iStorage, string undoMessage, TransactionType transactionType)
 {
     if (mySaveIStorage != null && mySaveIStorage != iStorage)
     {
         ImmediateSaveWithUndo();
     }
     mySaveIStorage        = iStorage;
     mySaveUndoMessage     = undoMessage;
     mySaveTransactionType = transactionType;
     mySaveTimer.Restart();
 }
        static void PerformSaveWithUndo()
        {
            if (mySaveIStorage == null)
            {
                return;
            }
            var iStorageToSave = mySaveIStorage;

            mySaveIStorage = null;
            iStorageToSave.SaveWithUndo(mySaveUndoMessage, mySaveTransactionType);
        }
 // ----------------------------------------------------------------------
 // Change the display root to the parent of the selected object.
 public static void ResetDisplayRoot(iCS_IStorage iStorage)
 {
     if (iStorage == null)
     {
         return;
     }
     OpenTransaction(iStorage);
     iStorage.ClearNavigationHistory();
     SendDisplayRootChange(iStorage);
     CloseTransaction(iStorage, "Reset Display Root");
 }
        public static void StartMultiSelectionNodeRelocation(iCS_IStorage iStorage)
        {
            OpenTransaction(iStorage);
            // Keep a copy of the original position.
            var selectedNodes = iStorage.FilterMultiSelectionForMove();

            foreach (var node in selectedNodes)
            {
                node.AnimationTargetRect = node.GlobalRect;
            }
        }
 public static void CancelMultiSelectionNodeRelocation(iCS_IStorage iStorage)
 {
     // Animate node back to its original position.
     iStorage.AnimateGraph(null,
                           _ => {
         iStorage.CancelMultiSelectionNodeRelocation();
         iStorage.ForcedRelayoutOfTree();
     }
                           );
     CancelTransaction(iStorage);
 }
        // ======================================================================
        // Initialization
        // ----------------------------------------------------------------------
        public iCS_PropertyController(iCS_EditorObject target, iCS_IStorage iStorage)
        {
            // Update main state variables.
            myTarget  = target;
            myStorage = iStorage;
            if (!IsValid)
            {
                return;
            }

            BuildViews();
        }
        // ---------------------------------------------------------------------------------
        /// Creates a visual script node from the given library object.
        ///
        /// @param libraryObject The library object from which to create a visual node.
        /// @param iStorage The storage in which to put the created node.
        /// @return _true_ if instance was created. _false_ otherwise.
        ///
        bool CreateInstance(LibraryObject libraryObject, iCS_IStorage iStorage)
        {
            if (libraryObject is LibraryType)
            {
                var libraryType = libraryObject as LibraryType;
                iStorage.CreatePropertyWizardNode(-1, libraryType.type);
                return(true);
            }
            var node = iStorage.CreateNode(-1, libraryObject);

            return(node != null);
        }
 // ---------------------------------------------------------------------------------
 public static bool IsSameVisualScript(iCS_MonoBehaviourImp monoBehaviour, iCS_IStorage iStorage)
 {
     if (monoBehaviour == null || iStorage == null)
     {
         return(false);
     }
     if (iStorage.iCSMonoBehaviour == monoBehaviour)
     {
         return(true);
     }
     return(false);
 }
 // ---------------------------------------------------------------------------------
 public static bool IsSameVisualScript(iCS_IStorage iStorage, iCS_VisualScriptData storage)
 {
     if (iStorage == null || storage == null)
     {
         return(false);
     }
     if (iStorage.Storage == storage)
     {
         return(true);
     }
     return(false);
 }
        public static void MenuSanityCheck()
        {
            iCS_IStorage storage = iCS_VisualScriptDataController.IStorage;

            if (storage == null)
            {
                return;
            }
            Debug.Log("iCanScript: Start Sanity Check on: " + storage.iCSMonoBehaviour.name);
            storage.SanityCheck();
            Debug.Log("iCanScript: Completed Sanity Check on: " + storage.iCSMonoBehaviour.name);
        }
        // ======================================================================
        // Undo/Redo is a condition detected by the storage.  It simulates
        // a User Command.
        static void ReloadEditorData(iCS_IStorage iStorage, Action reloadAction)
        {
            var animationStarts = new Rect[iStorage.EditorObjects.Count];

            iStorage.ForEach(obj => { animationStarts[obj.InstanceId] = obj.AnimationTargetRect; });
            var previousScrollPosition = iStorage.ScrollPosition;
            var previousScale          = iStorage.GuiScale;

            iStorage.AnimateGraph(null,
                                  _ => {
                // Keep a copy of the animation start Rect.
                // Rebuild editor data.
                try {
                    reloadAction();
                }
                catch (System.Exception e) {
                    Debug.LogWarning("iCanScript: Problem found regenerating data: " + e.Message);
                }
                // Rebuild layout
                iStorage.ForcedRelayoutOfTree();
                // Put back the animation start Rect.
                int len = animationStarts.Length;
                for (int id = 0; id < len; ++id)
                {
                    if (iStorage.IsValid(id))
                    {
                        var obj = iStorage.EditorObjects[id];
                        obj.ResetAnimationRect(animationStarts[id]);
                    }
                }
                var visualEditor = iCS_EditorController.FindVisualEditor();
                if (visualEditor != null)
                {
                    var animationTime = PreferencesController.AnimationTime;
                    visualEditor.AnimateScrollPosition(previousScrollPosition,
                                                       iStorage.ScrollPosition,
                                                       animationTime);
                    visualEditor.AnimateScale(previousScale,
                                              iStorage.GuiScale,
                                              animationTime);
                }
            }
                                  );
            // Update central visual script data
            iCS_VisualScriptDataController.Update();
            // Repaint all windows that could have changed.
            iCS_EditorController.RepaintAllEditors();
            // Force redraw of Inspector Window.
            EditorUtility.SetDirty(iStorage.iCSMonoBehaviour);
            // Annouce that an undo occured.
            SystemEvents.AnnouceVisualScriptUndo(iStorage);
        }
        // ----------------------------------------------------------------------
        void PortMenu(MenuType menuType, iCS_EditorObject port, iCS_IStorage storage, bool reverseInOut)
        {
            switch (menuType)
            {
            case MenuType.SelectedObject:
                SelectedPortMenu(port, storage);
                break;

            case MenuType.ReleaseAfterDrag:
                ReleaseAfterDragPortMenu(port, storage, reverseInOut);
                break;
            }
        }