void AddWindowBefore(object win) { Undo.RecordObject(CurrentDialogue, "Dialogue"); Dialogues.Window Curr = (Dialogues.Window)win; //If this is the first window if (Curr == CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow) { Dialogues.Window NewlyCreatedWindow = CreateNewWindow(Curr.Size.position - new Vector2(160, 0), -1); //The newly created window adds the first node as a connection NewlyCreatedWindow.Connections.Add(CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow.ID); //The first node is set to the new node CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow = NewlyCreatedWindow; CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Add(NewlyCreatedWindow); return; } Dialogues.Window PrevWindow = FindPreviousWindow(Curr); if (PrevWindow != null) { object[] Vals = { Curr.Size.position - new Vector2(160, 0), PrevWindow, Dialogues.WindowTypes.Text }; AddWindow(Vals).Connections.Add(Curr.ID); PrevWindow.Connections.Remove(Curr.ID); } }
Dialogues.Window AddWindow(object data) { Undo.RecordObject(CurrentDialogue, "Dialogue"); object[] Data = (object[])data; //Retrieving Data Vector2 Position = (Vector2)Data[0]; Dialogues.Window WindowClickedOn = (Dialogues.Window)Data[1]; Dialogues.WindowTypes Type = (Dialogues.WindowTypes)Data[2]; int ParentId = -1; if (WindowClickedOn != null) { ParentId = WindowClickedOn.ID; } //Creates the new window Dialogues.Window NewlyCreatedWindow = CreateNewWindow(Position, ParentId, Type); //Checks if this is the first node if (WindowClickedOn == null) { //It is the first node CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow = NewlyCreatedWindow; } else { //It is not the first node WindowClickedOn.Connections.Add(NewlyCreatedWindow.ID); } CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Add(NewlyCreatedWindow); return(NewlyCreatedWindow); }
void AddWindowBefore(Dialogues.Window curWin) { Undo.RecordObject(dialogue, "Dialogue"); if (curWin.ID == dialogue.Tree.FirstWindowID) { Dialogues.Window newWin = CreateNewWindow(curWin.Size.position - new Vector2(160, 0), -1); newWin.Connections.Add(dialogue.Tree.FirstWindowID); dialogue.Tree.FirstWindow.Parent = newWin.ID; dialogue.Tree.FirstWindowID = newWin.ID; dialogue.Tree.Windows.Add(newWin); return; } Dialogues.Window PrevWindow = FindPreviousWindow(curWin); if (PrevWindow != null) { object[] Vals = { curWin.Size.position - new Vector2(160, 0), PrevWindow, WindowTypes.Phrase }; var newWin = AddWindow(Vals); newWin.Connections.Add(curWin.ID); PrevWindow.Connections.Remove(curWin.ID); curWin.Parent = newWin.ID; } EditorUtility.SetDirty(dialogue); }
List <Dialogues.Window> FindPreviousWindows(Dialogues.Window winToFind) { if (CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow == winToFind) { return(null); } List <Dialogues.Window> TheList = new List <Dialogues.Window>(); //Checks all the connections for (int i = 0; i < CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Count; i++) { //If any of the connections is equal to the one we're trying to find, we return this Window for (int j = 0; j < CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i].Connections.Count; j++) { Dialogues.Window Curr = CurrentDialogue.Set[CurrentDialogue.CurrentSet].GetWindow(CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i].Connections[j]); if (Curr == winToFind) { TheList.Add(CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i]); } } } return(TheList); }
void CreateConnection(object win) { Dialogues.Window Curr = (Dialogues.Window)win; if (Find(Curr, ConnectingCurrent) || ConnectingCurrent.Connections.Contains(Curr.ID)) { if (!ConnectingCurrent.Connections.Contains(Curr.ID)) { ConnectingCurrent.Connections.Add(Curr.ID); } Connecting = false; if (Curr.Connections.Count > 1) { Curr.Type = WindowTypes.Decision; } EditorUtility.SetDirty(dialogue); return; } for (int i = 0; i < ConnectingCurrent.Connections.Count; i++) { if (ConnectingCurrent.Connections[i] == Curr.ID) { Connecting = false; return; } } ConnectingCurrent.Connections.Add(Curr.ID); Connecting = false; EditorUtility.SetDirty(dialogue); }
void RemoveConnection(object data) { object[] Data = (object[])data; Dialogues.Window Curr = (Dialogues.Window)Data[0]; int ToRemove = (int)Data[1]; //CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Remove(CurrentDialogue.Set[CurrentDialogue.CurrentSet].GetWindow(ToRemove)); bool Remove = true; for (int i = 0; i < CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Count; i++) { for (int j = 0; j < CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i].Connections.Count; j++) { if (CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i].Connections[j] == ToRemove && Curr.ID != CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i].Connections[j]) { Remove = false; } } } if (Remove) { CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Remove(CurrentDialogue.Set[CurrentDialogue.CurrentSet].GetWindow(ToRemove)); } Curr.Connections.Remove(ToRemove); }
void CreateConnection(object win) { Dialogues.Window Curr = (Dialogues.Window)win; if (Find(Curr, ConnectingCurrent) || ConnectingCurrent.Connections.Contains(Curr.ID)) { if (!ConnectingCurrent.Connections.Contains(Curr.ID))// && ConnectingCurrent.Type == WindowTypes.Choice) { ConnectingCurrent.Connections.Add(Curr.ID); } Connecting = false; if (Curr.Connections.Count > 1) { Curr.Type = Dialogues.WindowTypes.Choice; } return; } for (int i = 0; i < ConnectingCurrent.Connections.Count; i++) { if (ConnectingCurrent.Connections[i] == Curr.ID) { Connecting = false; return; } } ConnectingCurrent.Connections.Add(Curr.ID); Connecting = false; }
void RemoveConnection(object data) { Undo.RecordObject(dialogue, "Dialogue"); object[] Data = (object[])data; Dialogues.Window Curr = (Dialogues.Window)Data[0]; int ToRemove = (int)Data[1]; bool Remove = true; for (int i = 0; i < dialogue.Tree.Windows.Count; i++) { for (int j = 0; j < dialogue.Tree.Windows[i].Connections.Count; j++) { if (dialogue.Tree.Windows[i].Connections[j] == ToRemove && Curr.ID != dialogue.Tree.Windows[i].Connections[j]) { Remove = false; } } } if (Remove) { dialogue.Tree.Windows.Remove(dialogue.Tree.GetWindow(ToRemove)); } Curr.Connections.Remove(ToRemove); EditorUtility.SetDirty(dialogue); }
Dialogues.Window AddWindow(object data) { Undo.RecordObject(dialogue, "Dialogue"); object[] Data = (object[])data; Vector2 Position = (Vector2)Data[0]; Dialogues.Window curWin = (Dialogues.Window)Data[1]; WindowTypes Type = (WindowTypes)Data[2]; int ParentId = curWin != null? curWin.ID: -1; Dialogues.Window newWin = CreateNewWindow(Position, ParentId, Type); //Checks if this is the first node if (curWin == null) { dialogue.Tree.FirstWindowID = newWin.ID; } else { curWin.Connections.Add(newWin.ID); } dialogue.Tree.Windows.Add(newWin); EditorUtility.SetDirty(dialogue); return(newWin); }
void RemoveWindow(object win) { Undo.RecordObject(dialogue, "Dialogue"); Dialogues.Window Curr = (Dialogues.Window)win; ClearIds(); if (Curr.ID == dialogue.Tree.FirstWindowID) { dialogue.Tree.RemoveWindowByID(dialogue.Tree.FirstWindowID); if (Curr.Connections.Count == 0) { dialogue.Tree.CurrentId = 0; dialogue.Tree.FirstWindowID = -562; } if (Curr.Connections.Count == 1) { dialogue.Tree.FirstWindowID = Curr.Connections[0]; dialogue.Tree.FirstWindow.Parent = -1; dialogue.Tree.FirstWindow.NodeType = NodeType.Start; } return; } Dialogues.Window PrevWindow = FindPreviousWindow(Curr); if (Curr.Connections.Count != 0 && PrevWindow != null) { //We go through it's connections, and add them to the previous window for (int i = 0; i < Curr.Connections.Count; i++) { PrevWindow.Connections.Add(Curr.Connections[i]); } } if (PrevWindow != null) { if (Curr.Connections.Count > 1 && PrevWindow.Type == WindowTypes.Phrase) { PrevWindow.Type = WindowTypes.Decision; } PrevWindow.Connections.Remove(Curr.ID); for (int i = 0; i < Curr.Connections.Count; i++) { dialogue.Tree.GetWindow(Curr.Connections[i]).Parent = PrevWindow.ID; } } dialogue.Tree.Windows.Remove(Curr); ClearIds(); EditorUtility.SetDirty(dialogue); }
void WindowFunction(int windowID) { if (!Ids.ContainsKey(windowID)) { return; } Dialogues.Window Win = Ids[windowID]; int xSize = 150; int ySize = 84; if (Win.Type != WindowTypes.Decision) { if (GUI.Button(new Rect(0, 0, 15, 15), "-")) { AddWindowBefore(Win); } if (GUI.Button(new Rect(135, 0, 15, 15), "+")) { AddWindowAfter(Win); } } Win.Text = EditorGUI.TextArea(new Rect(0, 15, xSize, ySize), Win.Text); GUI.Label(new Rect(0, 100, 60, 20), "Speaker: "); Win.speaker = (Speaker)EditorGUI.EnumPopup( new Rect(60, 102, 85, 20), Win.speaker); if (Win.NodeType == NodeType.Start) { if (GUI.Button(new Rect(10, 125, 130, 20), "Tree conditions: " + dialogue.Tree.Importance)) { TreeShowCondition(); } } else if (Win.Type == WindowTypes.Option) { if (GUI.Button(new Rect(10, 125, 130, 20), "Show conditions: " + Win.showCondition.states.Count)) { ShowQuests(windowID, true); } } else { if (Win.NodeType == NodeType.End || FindPreviousWindow(Win).Type == WindowTypes.Option) { if (GUI.Button(new Rect(35, 125, 80, 20), "Quests: " + Win.activateQuests.Count)) { ShowQuests(windowID, false); } } } GUI.DragWindow(); }
bool Find(Dialogues.Window win, Dialogues.Window winToFind) { for (int i = 0; i < CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Count; i++) { if (CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[i] == winToFind) { return(true); } } return(false); }
Dialogues.Window CreateNewWindow(Vector2 Position, int ParentId, WindowTypes Type = WindowTypes.Phrase) { Dialogues.Window NewWindow = new Dialogues.Window( dialogue.Tree.CurrentId, ParentId, new Rect(Position, WindowSize), Type); dialogue.Tree.CurrentId++; EditorUtility.SetDirty(dialogue); return(NewWindow); }
bool Find(Dialogues.Window win, Dialogues.Window winToFind) { for (int i = 0; i < dialogue.Tree.Windows.Count; i++) { if (dialogue.Tree.Windows[i] == winToFind) { return(true); } } return(false); }
void Convert(object win) { Dialogues.Window Curr = (Dialogues.Window)win; if (Curr.Type == WindowTypes.Decision) { Curr.Type = WindowTypes.Phrase; } else { Curr.Type = WindowTypes.Decision; } }
void Convert(object win) { Dialogues.Window Curr = (Dialogues.Window)win; if (Curr.Type == Dialogues.WindowTypes.Choice) { Curr.Type = Dialogues.WindowTypes.Text; } else { Curr.Type = Dialogues.WindowTypes.Choice; } }
void DrawConnections(Color LineColor) { if (!CheckDialogueExists()) { return; } //Goes through the window's connections for (int j = 0; j < dialogue.Tree.Windows.Count; j++) { for (int i = 0; i < dialogue.Tree.Windows[j].Connections.Count; i++) { Dialogues.Window WindowList = dialogue.Tree.Windows[j]; Color Use = LineColor; if (WindowList.Type == WindowTypes.Decision) { Use = Color.green; } //Draws a line with the correct color between the current window and connection Handles.DrawBezier(WindowList.Size.center, dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center, new Vector2(WindowList.Size.center.x, WindowList.Size.center.y), new Vector2(dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.x, dialogue.Tree.GetWindow(WindowList.Connections[i]). Size.center.y), Use, null, 5f); Use = LineColor; //Finds the center between the points float xPos = (WindowList.Size.center.x) + ((dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.x - WindowList.Size.center.x) / 2); float yPos = (WindowList.Size.center.y) + ((dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.y - WindowList.Size.center.y) / 2); Vector2 Middle = new Vector2(xPos, yPos); //Draws arrows DrawConnectionArrow(WindowList.Size.center, Middle, true); DrawConnectionArrow(Middle, dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center, true); DrawConnectionArrow(WindowList.Size.center, dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center, true); } } if (Connecting) { Color ManualColor = Color.magenta; Handles.DrawBezier(ConnectingCurrent.Size.center, Event.current.mousePosition, new Vector2(ConnectingCurrent.Size.xMax + 50f, ConnectingCurrent.Size.center.y), new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y), ManualColor, null, 5f); } }
void AddWindowAfter(object win) { Undo.RecordObject(CurrentDialogue, "Dialogue"); Dialogues.Window Curr = (Dialogues.Window)win; Dialogues.Window NewlyCreatedWindow = CreateNewWindow(Curr.Size.position + new Vector2(160, 0), Curr.ID); for (int i = 0; i < Curr.Connections.Count; i++) { NewlyCreatedWindow.Connections.Add(Curr.Connections[i]); } Curr.Connections.Clear(); Curr.Connections.Add(NewlyCreatedWindow.ID); CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Add(NewlyCreatedWindow); }
void RemoveWindow(object win) { Dialogues.Window Curr = (Dialogues.Window)win; ClearIds(); //If the window we're removing is the start window, we have a custom check if (Curr == CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow) { //We don't allow the user to remove the first node if (Curr.Connections.Count == 0) { CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow = null; } return; } Dialogues.Window PrevWindow = FindPreviousWindow(Curr); //If the window to remove has connections if (Curr.Connections.Count != 0 && PrevWindow != null) { //We go through it's connections, and add them to the previous window for (int i = 0; i < Curr.Connections.Count; i++) { PrevWindow.Connections.Add(Curr.Connections[i]); } } if (PrevWindow != null) { if (Curr.Connections.Count > 1 && PrevWindow.Type == Dialogues.WindowTypes.Text) { PrevWindow.Type = Dialogues.WindowTypes.Choice; } if (PrevWindow == CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow) { AddWindowBefore(PrevWindow); } //Removes the window from existence PrevWindow.Connections.Remove(Curr.ID); Curr.Parent = -2; for (int i = 0; i < Curr.Connections.Count; i++) { CurrentDialogue.Set[CurrentDialogue.CurrentSet].GetWindow(Curr.Connections[i]).Parent = -2; } } CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Remove(Curr); ClearIds(); }
void RemoveWindowTree(object win) { Dialogues.Window Curr = (Dialogues.Window)win; //If this is the first node, removes everything if (Curr == CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow) { if (Curr.Connections.Count == 0) { CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow = null; } return; } //Simply removes the node, and lets everything connected die Dialogues.Window PrevWindow = FindPreviousWindow(Curr); Curr.Parent = -2; PrevWindow.Connections.Remove(Curr.ID); }
void AddWindowAfter(Dialogues.Window curWin) { Undo.RecordObject(dialogue, "Dialogue"); Dialogues.Window newWin = CreateNewWindow(curWin.Size.position + new Vector2(160, 0), curWin.ID); for (int i = 0; i < curWin.Connections.Count; i++) { newWin.Connections.Add(curWin.Connections[i]); dialogue.Tree.GetWindow(newWin.Connections[i]).Parent = newWin.ID; } curWin.Connections.Clear(); curWin.Connections.Add(newWin.ID); dialogue.Tree.Windows.Add(newWin); EditorUtility.SetDirty(dialogue); }
void RemoveWindowTree(object win) { Undo.RecordObject(dialogue, "Dialogue"); Dialogues.Window Curr = (Dialogues.Window)win; //If this is the first node, removes everything if (Curr.ID == dialogue.Tree.FirstWindowID) { dialogue.Tree.Windows.Clear(); dialogue.Tree.FirstWindowID = -562; dialogue.Tree.CurrentId = 0; return; } //Simply removes the node, and lets everything connected die Dialogues.Window PrevWindow = FindPreviousWindow(Curr); Curr.Parent = -2; PrevWindow.Connections.Remove(Curr.ID); EditorUtility.SetDirty(dialogue); }
void CheckPosition(Dialogues.Window win) { Vector2 newPos = win.Size.position; if (win.Size.center.x < 0) { win.Size.position = new Vector2(0, newPos.y); } if (win.Size.center.x > WorkSize.x) { win.Size.position = new Vector2(WorkSize.x - (win.Size.width), newPos.y); } if (win.Size.center.y < 0) { win.Size.position = new Vector2(newPos.x, 0); } if (win.Size.center.y > WorkSize.y) { win.Size.position = new Vector2(newPos.x, WorkSize.y - (win.Size.height)); } }
Dialogues.Window FindPreviousWindow(Dialogues.Window winToFind) { //If this is the first window, there is no previous if (dialogue.Tree.FirstWindowID == winToFind.ID) { return(null); } //Checks all the connections for (int i = 0; i < dialogue.Tree.Windows.Count; i++) { //If any of the connections is equal to the one we're trying to find, we return this Window for (int j = 0; j < dialogue.Tree.Windows[i].Connections.Count; j++) { Dialogues.Window Curr = dialogue.Tree.GetWindow(dialogue.Tree.Windows[i].Connections[j]); if (Curr == winToFind) { return(dialogue.Tree.Windows[i]); } } } return(null); }
void WindowFunction(int windowID) { if (!Ids.ContainsKey(windowID)) { return; } Dialogues.Window Win = (Dialogues.Window)Ids[windowID][0]; int xSize = 150; int ySize = 84; if (Win.Type != Dialogues.WindowTypes.Choice) { if (GUI.Button(new Rect(0, 0, 15, 15), "-")) { AddWindowBefore(Win); } if (GUI.Button(new Rect(135, 0, 15, 15), "+")) { AddWindowAfter(Win); } } Win.Trigger = GUI.Toggle(new Rect(10, 100, 60, 30), Win.Trigger, "Trigger"); if (Win.Trigger) { Win.TriggerText = GUI.TextField(new Rect(70, 100, 70, 20), Win.TriggerText); } else { Win.TriggerText = ""; } Win.Text = GUI.TextArea(new Rect(0, 15, xSize, ySize), Win.Text); GUI.DragWindow(); }
Dialogues.Window CreateNewWindow(Vector2 Position, int ParentId, Dialogues.WindowTypes Type = Dialogues.WindowTypes.Text) { Dialogues.Window NewWindow = new Dialogues.Window(CurrentDialogue.Set[CurrentDialogue.CurrentSet].CurrentId, ParentId, new Rect(Position, WindowSize), Type); CurrentDialogue.Set[CurrentDialogue.CurrentSet].CurrentId++; return(NewWindow); }
void BuildMenus(GenericMenu Menu) { Vector2 AdjustedMousePosition = Event.current.mousePosition + ScrollPosition - new Vector2(50, 50); Vector2 AdjustedMousePositionLine = Event.current.mousePosition + ScrollPosition; if (!CheckDialogueExists()) { object[] Vals = { AdjustedMousePosition, null, WindowTypes.Phrase }; Menu.AddItem(new GUIContent("Create First Window"), false, AddWindowWrapper, Vals); return; } for (int j = 0; j < dialogue.Tree.Windows.Count; j++) { Dialogues.Window WindowList = dialogue.Tree.Windows[j]; //Accounts for the area when the user has scrolled Rect AdjustedArea = new Rect(WindowList.Size.position - ScrollPosition, WindowList.Size.size); if (Connecting) { object[] CreateInfoDialogue = { AdjustedMousePosition, WindowTypes.Phrase }; object[] CreateInfoChoice = { AdjustedMousePosition, WindowTypes.Decision }; if (ConnectingCurrent.Type == WindowTypes.Phrase && ConnectingCurrent.Connections.Count == 0 || ConnectingCurrent.Type == WindowTypes.Option && ConnectingCurrent.Connections.Count == 0 || ConnectingCurrent.Type == WindowTypes.Decision) { Menu.AddItem(new GUIContent("Create Phrase"), false, EstablishNewWindowConnection, CreateInfoDialogue); Menu.AddItem(new GUIContent("Create Decision"), false, EstablishNewWindowConnection, CreateInfoChoice); } } //Checks if the mouse is close enough to a line for (int i = 0; i < WindowList.Connections.Count; i++) { float xPos = (WindowList.Size.center.x) + ((dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.x - WindowList.Size.center.x) / 2); float yPos = (WindowList.Size.center.y) + ((dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.y - WindowList.Size.center.y) / 2); Vector2 Middle = new Vector2(xPos, yPos); float xPosLower = (WindowList.Size.center.x) + ((Middle.x - WindowList.Size.center.x) / 2); float yPosLower = (WindowList.Size.center.y) + ((Middle.y - WindowList.Size.center.y) / 2); Vector2 Lower = new Vector2(xPosLower, yPosLower); float xPosHigher = (Middle.x) + ((dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.x - Middle.x) / 2); float yPosHigher = (Middle.y) + ((dialogue.Tree.GetWindow(WindowList.Connections[i]).Size.center.y - Middle.y) / 2); Vector2 Higher = new Vector2(xPosHigher, yPosHigher); if (Mathf.Abs((AdjustedMousePositionLine - Middle).magnitude) < 50 || Mathf.Abs((AdjustedMousePositionLine - Lower).magnitude) < 50 || Mathf.Abs((AdjustedMousePositionLine - Higher).magnitude) < 50) { object[] Vals = { WindowList, WindowList.Connections[i] }; Menu.AddItem(new GUIContent("Remove Connection"), false, RemoveConnection, Vals); } } //Checks if the mouse is on the current box if (AdjustedArea.Contains(Event.current.mousePosition)) { if (Connecting) { if (AdjustedArea.Contains(Event.current.mousePosition)) { if (ConnectingCurrent.Type == WindowTypes.Phrase && ConnectingCurrent.Connections.Count == 0 || ConnectingCurrent.Type == WindowTypes.Option && ConnectingCurrent.Connections.Count == 0 || ConnectingCurrent.Type == WindowTypes.Decision) { Menu.AddItem(new GUIContent("Establish Connection"), false, CreateConnection, WindowList); } } } else { if (WindowList.Type == WindowTypes.Phrase) { Menu.AddItem(new GUIContent("Convert To Decision"), false, Convert, WindowList); } else if (WindowList.Connections.Count <= 1 && WindowList.Type != WindowTypes.Option) { Menu.AddItem(new GUIContent("Convert To Phrase"), false, Convert, WindowList); } else if (WindowList.Type != WindowTypes.Option) { Menu.AddDisabledItem(new GUIContent("Convert To Phrase")); } if (WindowList.Type != WindowTypes.Option) { Menu.AddSeparator(""); } if (WindowList.Type == WindowTypes.Phrase && WindowList.Connections.Count == 0 || WindowList.Type == WindowTypes.Option && WindowList.Connections.Count == 0 || WindowList.Type == WindowTypes.Decision) { Menu.AddItem(new GUIContent("Create Connection"), false, StartConnection, WindowList); } Menu.AddItem(new GUIContent("Remove Window"), false, RemoveWindow, WindowList); Menu.AddItem(new GUIContent("Remove Window Tree"), false, RemoveWindowTree, WindowList); } } } if (Connecting) { Menu.AddItem(new GUIContent("Cancel"), false, CancelConnection); } EditorUtility.SetDirty(dialogue); }
void BuildWindows() { if (CheckDialogue() && !CheckDialogueExists()) { return; } for (int j = 0; j < CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows.Count; j++) { Dialogues.Window WindowList = CurrentDialogue.Set[CurrentDialogue.CurrentSet].Windows[j]; List <Dialogues.Window> PrevWindow = FindPreviousWindows(WindowList); if (PrevWindow != null) { for (int i = 0; i < PrevWindow.Count; i++) { if (PrevWindow[i].Type == Dialogues.WindowTypes.Choice) { WindowList.Type = Dialogues.WindowTypes.ChoiceAnswer; break; } if (PrevWindow[i].Type == Dialogues.WindowTypes.ChoiceAnswer && WindowList.Type == Dialogues.WindowTypes.ChoiceAnswer) { WindowList.Type = Dialogues.WindowTypes.Text; } if (PrevWindow[i].Type == Dialogues.WindowTypes.Text && WindowList.Type == Dialogues.WindowTypes.ChoiceAnswer) { WindowList.Type = Dialogues.WindowTypes.Text; } } } //Default naming string BoxName = ""; switch (WindowList.Type) { case Dialogues.WindowTypes.Text: BoxName = "Dialogue"; break; case Dialogues.WindowTypes.Choice: BoxName = "Decision"; break; case Dialogues.WindowTypes.ChoiceAnswer: BoxName = "Option"; break; } //Determines what type of node it is if (WindowList.Connections.Count == 0 && WindowList != CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow && WindowList.Type != Dialogues.WindowTypes.Choice) { WindowList.NodeType = Dialogues.NodeType.End; } else if (WindowList.ID == CurrentDialogue.Set[CurrentDialogue.CurrentSet].FirstWindow.ID) { WindowList.NodeType = Dialogues.NodeType.Start; } else { WindowList.NodeType = Dialogues.NodeType.Default; } //Changes the name accordingly if (WindowList.Type != Dialogues.WindowTypes.Choice) { switch (WindowList.NodeType) { case Dialogues.NodeType.Start: BoxName = "Start"; break; case Dialogues.NodeType.End: BoxName = "End"; if (WindowList.Type == Dialogues.WindowTypes.ChoiceAnswer) { BoxName = "End (Option)"; } break; default: break; } } //Sets up the ID for the window object[] Vals = { WindowList }; if (!Ids.ContainsKey(WindowList.ID)) { Ids.Add(WindowList.ID, Vals); } //Creates the actual window string Style = "flow node 0"; if (WindowList.Type == Dialogues.WindowTypes.Choice) { Style = "flow node 3"; } if (WindowList.NodeType == Dialogues.NodeType.Start) { Style = "flow node 1"; } if (WindowList.Type == Dialogues.WindowTypes.ChoiceAnswer) { Style = "flow node 2"; } if (WindowList.NodeType == Dialogues.NodeType.End) { Style = "flow node 6"; } if (WindowList.Type == Dialogues.WindowTypes.Choice && WindowList.Connections.Count == 0) { Style = "flow node 4"; } GUIStyle FinalStyle = new GUIStyle(Style); FinalStyle.fontSize = 14; FinalStyle.contentOffset = new Vector2(0, -30); CheckPosition(WindowList); WindowList.Size = GUI.Window(WindowList.ID, WindowList.Size, WindowFunction, BoxName, FinalStyle); } }
void BuildWindows() { if (CheckDialogue() && !CheckDialogueExists()) { return; } for (int j = 0; j < dialogue.Tree.Windows.Count; j++) { Dialogues.Window win = dialogue.Tree.Windows[j]; List <Dialogues.Window> prevWindows = FindPreviousWindows(win); if (prevWindows != null) { for (int i = 0; i < prevWindows.Count; i++) { if (prevWindows[i].Type == WindowTypes.Decision) { win.Type = WindowTypes.Option; break; } if (win.Type == WindowTypes.Option) { if (prevWindows[i].Type == WindowTypes.Option || prevWindows[i].Type == WindowTypes.Phrase) { win.Type = WindowTypes.Phrase; } } } } //Default naming string BoxName = win.Type.ToString(); //Determines what type of node it is if (win.Connections.Count == 0 && win.ID != dialogue.Tree.FirstWindowID && win.Type != WindowTypes.Decision) { win.NodeType = NodeType.End; } else if (win.ID == dialogue.Tree.FirstWindowID) { win.NodeType = NodeType.Start; } else { win.NodeType = NodeType.Default; } //Changes the name accordingly if (win.Type != WindowTypes.Decision) { switch (win.NodeType) { case NodeType.Start: BoxName = "Start"; break; case NodeType.End: BoxName = "End"; if (win.Type == WindowTypes.Option) { BoxName = "End (Option)"; } break; default: break; } } if (!Ids.ContainsKey(win.ID)) { Ids.Add(win.ID, win); } //Creates the actual window string Style = "flow node 0"; if (win.NodeType == NodeType.Start) { Style = "flow node 1"; } if (win.NodeType == NodeType.End) { Style = "flow node 1"; } if (win.Type == WindowTypes.Decision) { Style = "flow node 3"; } if (win.Type == WindowTypes.Option) { Style = "flow node 5"; } if (win.Type == WindowTypes.Decision && win.Connections.Count == 0) { Style = "flow node 6"; } GUIStyle FinalStyle = new GUIStyle(Style); FinalStyle.fontSize = 14; FinalStyle.contentOffset = new Vector2(0, -30); CheckPosition(win); win.Size.width = WindowSize.x; win.Size.height = WindowSize.y; BoxName = win.Parent + " " + BoxName + " " + win.ID; win.Size = GUI.Window(win.ID, win.Size, WindowFunction, BoxName, FinalStyle); } }
void StartConnection(object win) { Connecting = true; ConnectingCurrent = (Dialogues.Window)win; }