예제 #1
0
    public ActionContainer Save()
    {
        GraphSaveUtility saveUtility = GraphSaveUtility.GetInstance(graphView);
        ActionContainer  saved       = null;

        if (graphView.IsCachedFile)
        {
            return(saveUtility.SaveGraph(DefaultCacheName));
        }

        if (graphView.IsDirty)
        {
            if (string.IsNullOrEmpty(graphView.LoadedFileName) || string.IsNullOrWhiteSpace(graphView.LoadedFileName))
            {
                return(SaveAs());
            }

            saved = saveUtility.SaveGraph(graphView.LoadedFileName);
            if (saved)
            {
                graphView.LoadedFileName = saved.ContainerName;
                graphView.SetDirty(false);
                graphView.IsCachedFile = false;
            }
        }
        return(saved);
    }
예제 #2
0
    private void RequestDataOperation(bool save)
    {
        if (string.IsNullOrEmpty(_fileName))
        {
            EditorUtility.DisplayDialog("Invalid file name!", "Please enter a vaild file name.", "OK");
        }

        var saveUtility = GraphSaveUtility.GetInstance(_graphView);

        if (save)
        {
            saveUtility.SaveGraph(_fileName);
        }
        else
        {
            saveUtility.LoadGraph(_fileName);
        }
    }
예제 #3
0
    private bool Load(string fileName)
    {
        if (string.IsNullOrEmpty(fileName))
        {
            EditorUtility.DisplayDialog("Invalid file name", "Please enter a valid file name.", "OK");
            return(false);
        }

        var saveUtility = GraphSaveUtility.GetInstance(graphView);

        // if loads cache file, shouldn't set the graphview to not dirty.
        if (saveUtility.LoadGraph(fileName) && !graphView.IsCachedFile)
        {
            graphView.SetDirty(false);
        }

        return(true);
    }
    private void RequestDataOperation(bool toSave)
    {
        if (string.IsNullOrEmpty(_fileName))
        {
            EditorUtility.DisplayDialog("Invalid file name", "Please enter a valid file name", "Sound Good");
            return;
        }

        GraphSaveUtility saveUtility = GraphSaveUtility.GetInstance(_graphView);

        if (toSave)
        {
            saveUtility.SaveGraph(_fileName);
        }
        else
        {
            saveUtility.LoadGraph(_fileName);
        }
    }
예제 #5
0
    public void DoSaveLoad(bool isSave)
    {
        if (string.IsNullOrEmpty(filename))
        {
            EditorUtility.DisplayDialog("Invalid filename", "Please enter a valid filename", "OK");
            return;
        }

        var saveUtility = GraphSaveUtility.GetInstance(graph);

        if (isSave)
        {
            saveUtility.SaveData(filename);
        }
        else
        {
            saveUtility.LoadData(filename);
        }
    }
    public void OnPasteElementsOption(string a, string b)
    {
        if (nodeCopyCache.Count == 0)
        {
            return;
        }

        var graphContainer = GraphSaveUtility.GetInstance(targetGraphView).GetNodesContainer();

        foreach (var node in nodeCopyCache)
        {
            var baseNode = (BaseNode)node;
            var nodeData = baseNode.CopyData(false);

            // Offset pasted node
            nodeData.position.y += baseNode.GetPosition().height + nodePasteOffset;

            switch (nodeData.nodeType)
            {
            case NodeType.DialogueNode:
                var dialogueNodeOriginal      = node as DialogueNode;
                DialogueNodeData dialogueData = dialogueNodeOriginal.CopyData();
                var dialogueNode = new DialogueNode(targetGraphView, nodeData, dialogueData);
                targetGraphView.AddElement(dialogueNode);
                break;

            case NodeType.ChoiceNode:
                var            choiceNodeOriginal = node as ChoiceNode;
                ChoiceNodeData choiceData         = choiceNodeOriginal.CopyData();
                var            choicePorts        = graphContainer.nodeLinks.ToList().Where(x => x.thisNodeGuid == nodeData.guid).ToList();
                var            choiceNode         = new ChoiceNode(targetGraphView, nodeData, choiceData, choicePorts);
                targetGraphView.AddElement(choiceNode);
                break;

            case NodeType.EndNode:
                var endNode = new BaseNode(nodeData.nodeType, targetGraphView, nodeData.position, nodeData.guid);
                targetGraphView.AddElement(endNode);
                break;
            }
        }
    }
예제 #7
0
    public ActionContainer SaveAs()
    {
        GraphSaveUtility saveUtility = GraphSaveUtility.GetInstance(graphView);
        ActionContainer  saved;

        string path = EditorUtility.SaveFilePanelInProject("Save As", "Module", "asset", "Please save file.");

        if (string.IsNullOrEmpty(path) || string.IsNullOrWhiteSpace(path))
        {
            return(null);
        }
        saved = saveUtility.SaveGraph(path, true);

        if (saved)
        {
            //Was able to save
            graphView.LoadedFileName = saved.ContainerName;
            graphView.SetDirty(false);
            graphView.IsCachedFile = false;
        }

        return(saved);
    }
예제 #8
0
    private void GenerateToolBar()
    {
        var toolbar = new Toolbar();

        toolbar.styleSheets.Add(Resources.Load <StyleSheet>("MapGraph"));

        ////FileName TextField
        //var fileNameTextField = new TextField("File Name");
        //fileNameTextField.SetValueWithoutNotify(_filename);
        //fileNameTextField.MarkDirtyRepaint();
        //fileNameTextField.RegisterValueChangedCallback(evt => _filename = evt.newValue);
        //toolbar.Add(fileNameTextField);
        //////
        var textbox = new TextElement
        {
            text = _filename
        };

        textbox.style.color = Color.red;
        var objloader = new ObjectField("Data")
        {
            objectType        = typeof(MapContainer),
            allowSceneObjects = false
        };

        objloader.RegisterValueChangedCallback(evt =>
        {
            var saveUtility = GraphSaveUtility.GetInstance(_graphView);
            //saveUtility.SaveGraph(_filename);
            if (evt.newValue == null)
            {
                _filename    = "";
                textbox.text = _filename;
                return;
            }
            else
            {
                saveUtility.LoadGraph((MapContainer)evt.newValue);
                _filename    = evt.newValue.name;
                textbox.text = _filename;
            }
        });

        toolbar.Add(objloader);
        objloader.style.alignSelf = Align.FlexEnd;
        //toolbar.Add(textbox);
        ////////


        toolbar.Add(new Button(() => RequestDataOperation(true))
        {
            text = "Save Data"
        });

        toolbar.Add(new Button(() => RequestDataOperation(false))
        {
            text = "Load Data"
        });


        ////Create Node Button
        //var nodeCreateButton = new Button(clickEvent: () =>
        //{
        //    _graphView.CreateNode("Map Node");
        //});

        //nodeCreateButton.text = "Create Node";
        //toolbar.Add(nodeCreateButton);

        var roomloader = new ObjectField("RoomData")
        {
            objectType        = typeof(RoomData),
            allowSceneObjects = false
        };

        toolbar.Add(roomloader);



        //Create RoomNode Button
        var nodeCreateButton = new Button(clickEvent: () =>
        {
            _graphView.CreateRoomNode((RoomData)roomloader.value, Vector2.zero, true);
        })
        {
            text = "Create Node"
        };

        toolbar.Add(nodeCreateButton);



        rootVisualElement.Add(toolbar);
    }
예제 #9
0
    private void GenerateToolbar()
    {
        var toolbar = new Toolbar();

        ObjectField objectField  = new ObjectField();
        Toggle      gridCheckbox = new Toggle();
        ToolbarMenu fileMenu     = new ToolbarMenu {
            text = "File", style = { width = 50 }
        };

        #region File Menu
        //Should iterate through ActionModuleGroup
        fileMenu.menu.AppendAction("New Module", action =>
        {
            if (string.IsNullOrEmpty(graphView.LoadedFileName))
            {
                objectField.value = null;
                graphView.CreateEmptyNewGraph();
            }
        });

        fileMenu.menu.AppendSeparator();
        fileMenu.menu.AppendAction("Save", action =>
        {
            ActionContainer actionContainer;
            if (string.IsNullOrEmpty(graphView.LoadedFileName))
            {
                actionContainer = Save();
                if (actionContainer)
                {
                    objectField.SetValueWithoutNotify(actionContainer);
                }
                return;
            }
            actionContainer = Save();
            if (actionContainer)
            {
                objectField.SetValueWithoutNotify(actionContainer);
            }
        });
        fileMenu.menu.AppendAction("Save As", action =>
        {
            var actionContainer = SaveAs();
            if (actionContainer)
            {
                objectField.SetValueWithoutNotify(actionContainer);
            }
        });
        bool isGridActive = false;
        fileMenu.menu.AppendSeparator();
        fileMenu.menu.AppendAction("Activate Grid", action =>
        {
            isGridActive = !isGridActive;
            graphView.ToggleGrid(!isGridActive);
        }, action =>
        {
            if (isGridActive)
            {
                return(DropdownMenuAction.Status.Normal);
            }
            return(DropdownMenuAction.Status.Checked);
        });

        #endregion

        #region Object Loader
        objectField.objectType = typeof(ActionContainer);
        objectField.RegisterCallback <ChangeEvent <Object> >(evt =>
        {
            if (evt.newValue == null)
            {
                objectField.SetValueWithoutNotify(evt.previousValue);
                return;
            }
            var saveUtility = GraphSaveUtility.GetInstance(graphView);

            //if dirty
            if (!graphView.IsDirty)
            {
                //clears and loadGraph
                saveUtility.LoadGraph((ActionContainer)evt.newValue);
                string loadedName        = ((ActionContainer)evt.newValue).ContainerName;
                graphView.LoadedFileName = loadedName;
                graphView.SetName(loadedName);
                return;
            }
            //Graph is dirty
            int option = EditorUtility.DisplayDialogComplex("Unsaved Changes",
                                                            "Do you want to save the changes you made before?", "Save", "Cancel", "Don't Save");

            switch (option)
            {
            case 1:     //Cancel
                objectField.SetValueWithoutNotify(evt.previousValue);
                break;

            case 0:     // Save
                graphView.SetDirty(!(saveUtility.SaveGraph(graphView.LoadedFileName) != null &&
                                     saveUtility.LoadGraph((ActionContainer)evt.newValue)));
                break;

            case 2:     // Don't Save.
                graphView.SetDirty(!saveUtility.LoadGraph((ActionContainer)evt.newValue));
                break;
            }
        });
        #endregion

        toolbar.Add(fileMenu);
        toolbar.Add(objectField);

        //Adds toolbar to window
        rootVisualElement.Add(toolbar);
    }