Beispiel #1
0
        /// <summary>
        /// BT Canvas extra GUI States
        /// </summary>
        /// <param name="controller">MoonEditor Controller</param>
        /// <returns>Defined gui states</returns>
        public override Dictionary <int, System.Action> CanvasGUIStates(MoonEditorController controller)
        {
            Dictionary <int, System.Action> dic = new Dictionary <int, System.Action>();

            dic.Add(4, () =>
            {
                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);
                NewScriptName = MoonModal.InputPanel(new Vector2(200, 100), "Create " + ((NewScriptMode == 0) ? " Action" : "Decision"), "Ok", "Cancel", "Class Name", NewScriptName,
                                                     () =>
                {
                    if (MoonIO.ValidFileName(NewScriptName))
                    {
                        if (MoonIO.ValidClassName(NewScriptName))
                        {
                            string Savefolder = MoonSettings.ActionsSaveDirectory + "/BehaviorTrees";

                            if (NewScriptMode >= 1)
                            {
                                // create Decition
                                Savefolder += "/_Decisions";
                            }
                            CreateBTScript(Savefolder, NewScriptMode == 0, NewScriptName);
                            NewScriptName = string.Empty;
                            controller.CurrentGUIState = 0;
                        }
                    }
                }, () =>
                {
                    NewScriptName = string.Empty;
                    controller.CurrentGUIState = 0;
                });
            });

            return(dic);
        }
        /// <summary>
        /// Displays the editor depending on it's state
        /// </summary>
        /// <param name="e">User event</param>
        public void DoEditor(Event e)
        {
            GUIState st = (GUIState)CurrentGUIState;

            switch (st)
            {
            case GUIState.Normal:

                if (WorkingGraph != null)
                {
                    MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), WorkingGraph.Offset, WorkingGraph.Zoom);

                    canvas.DoNodeEditor(e);
                    WorkingGraph.OnCanvasGUI();
                }
                else
                {
                    MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);
                    MoonGUI.DrawCanvasLabel(new Rect(10, 15, 500, 300), new GUIContent("No Graph"), 26, true);
                }

                break;

            case GUIState.New:

                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);

                if (ModuleData != null)
                {
                    NewGraphName = MoonModal.InputPanel(new Vector2(200, 100), "New " + ModuleData.Name, "Ok", "Cancel", "Name",
                                                        NewGraphName,
                                                        () =>
                    {
                        if (MoonIO.ValidFileName(NewGraphName))
                        {
                            string foldername = (!string.IsNullOrEmpty(ModuleData.ExportFolderName)) ?
                                                ModuleData.ExportFolderName : ModuleData.Name;

                            NodeGraph newg = MoonIO.CreateGraphAsset(NewGraphName, foldername, ModuleData.GraphType,
                                                                     ModuleData.ModuleType);
                            if (newg != null)
                            {
                                WorkingGraph = newg;
                            }
                            NewGraphName    = string.Empty;
                            CurrentGUIState = (int)GUIState.Normal;
                        }
                    },
                                                        () =>
                    {
                        NewGraphName    = string.Empty;
                        CurrentGUIState = (int)GUIState.Normal;
                    });
                }
                else
                {
                    CurrentGUIState = (int)GUIState.Normal;
                }

                break;

            case GUIState.Open:

                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);

                MoonModal.OpenGraphPanel(ref OpenGraphOffset, ref OpenGraphSearch, FoundGraphs, (NodeGraph ng) =>
                {
                    WorkingGraph    = ng;
                    CurrentGUIState = (int)GUIState.Normal;
                }, () => CurrentGUIState = (int)GUIState.Normal, () => FoundGraphs = MoonIO.GetAllGraphs());

                if (!string.Equals(OpenGraphSearch, LastOpenGraphSearch))
                {
                    FoundGraphs         = MoonIO.GetAllGraphs(OpenGraphSearch);
                    LastOpenGraphSearch = OpenGraphSearch;
                }

                break;

            case GUIState.SaveAs:

                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);

                NewGraphName = MoonModal.InputPanel(new Vector2(200, 100), "Save as ", "Ok", "Cancel", "Name",
                                                    NewGraphName,
                                                    () =>
                {
                    if (MoonIO.ValidFileName(NewGraphName))
                    {
                        NodeGraph copy = MoonIO.CopyGraph(WorkingGraph, NewGraphName);

                        if (copy != null)
                        {
                            WorkingGraph = copy;
                        }

                        CurrentGUIState = (int)GUIState.Normal;
                    }
                },
                                                    () => CurrentGUIState = (int)GUIState.Normal);

                break;

            default:

                for (int i = 0; i < UserKeyStates.Length; i++)
                {
                    if (CurrentGUIState == UserKeyStates[i])
                    {
                        System.Action act;
                        if (UserStates.TryGetValue(UserKeyStates[i], out act))
                        {
                            act.Invoke();
                        }
                    }
                }

                break;
            }
        }