//This will break the node connections public void breakConnection(int type, VIDE_EditorDB.Comment commID, VIDE_EditorDB.Answer ansID) { //Type 0 = VIDE_EditorDB.Comment -> VIDE_EditorDB.Answer //Type 1 = VIDE_EditorDB.Answer -> Set if (type == 0) { Undo.RecordObject(db, "Broke connection"); commID.outputAnswer = null; } if (type == 1) { Undo.RecordObject(db, "Broke connection"); if (ansID.outputNPC == null) { Undo.RecordObject(db, "Broke connection"); ansID.outputSet = null; } else { Undo.RecordObject(db, "Broke connection"); ansID.outputNPC = null; } } }
//Connect player node to NPC node //Create node if released on empty space public void TryConnectToAnswer(Vector2 mPos, VIDE_EditorDB.Comment commID) { if (commID == null) { return; } for (int i = 0; i < db.npcDiags.Count; i++) { if (db.npcDiags[i].rect.Contains(mPos)) { Undo.RecordObject(db, "Connected Node"); commID.outputAnswer = db.npcDiags[i]; Repaint(); return; } } for (int i = 0; i < db.playerDiags.Count; i++) { if (db.playerDiags[i].rect.Contains(mPos)) { return; } } int id = setUniqueID(); Undo.RecordObject(db, "Added Node"); db.npcDiags.Add(new VIDE_EditorDB.Answer(new Rect(mPos.x - 150, mPos.y - 200, 0, 0), id)); commID.outputAnswer = db.npcDiags[db.npcDiags.Count - 1]; repaintLines = true; Repaint(); GUIUtility.hotControl = 0; }
//The NPC node void DrawNPCWindow(int id) { GUI.enabled = editEnabled; bool dontDrag = false; if (Event.current.type == EventType.MouseUp) { draggingLine = false; dontDrag = true; } int ansID = id - (db.playerDiags.Count); if (ansID < 0) { ansID = 0; } GUILayout.BeginHorizontal(); GUI.color = colors[2]; string delText = "Delete Node"; if (areYouSureIndex == id) { if (areYouSure) { delText = "Sure?"; GUI.color = new Color32(176, 128, 54, 255); } } if (GUILayout.Button(delText, GUILayout.Width(80))) { if (areYouSureIndex != id) { areYouSure = false; } if (!areYouSure) { areYouSure = true; areYouSureIndex = id; } else { areYouSure = false; areYouSureIndex = 0; Undo.RecordObject(db, "removed node"); removeAnswer(db.npcDiags[ansID]); needSave = true; return; } } if (Event.current.type == EventType.MouseDown) { areYouSure = false; Repaint(); } GUI.color = defaultColor; if (db.npcDiags[ansID].endConversation) { GUI.color = Color.green; } else if (db.npcDiags[ansID].outputSet == null && db.npcDiags[ansID].outputNPC == null) { GUI.color = Color.red; } if (GUILayout.Button("End here: " + db.npcDiags[ansID].endConversation.ToString())) { areYouSure = false; Undo.RecordObject(db, "Changed End Point for id"); db.npcDiags[ansID].endConversation = !db.npcDiags[ansID].endConversation; db.npcDiags[ansID].outputSet = null; db.npcDiags[ansID].outputNPC = null; needSave = true; } GUI.color = defaultColor; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUIStyle stf = new GUIStyle(GUI.skin.textField); stf.wordWrap = true; GUI.SetNextControlName("nText_" + id.ToString()); Undo.RecordObject(db, "textCange"); db.npcDiags[ansID].text = EditorGUILayout.TextArea(db.npcDiags[ansID].text, stf, GUILayout.Width(260)); if (!db.npcDiags[ansID].endConversation) { if (db.npcDiags[ansID].outputSet == null && db.npcDiags[ansID].outputNPC == null) { Rect lr; if (GUILayout.RepeatButton("O", GUILayout.Width(30))) { areYouSure = false; lr = GUILayoutUtility.GetLastRect(); lr = new Rect(lr.x + db.npcDiags[ansID].rect.x + 30, lr.y + db.npcDiags[ansID].rect.y + 7, 0, 0); if (!draggingLine && !dontDrag) { draggedAns = db.npcDiags[ansID]; draggedCom = null; dragStart = new Vector2(lr.x, lr.y); draggingLine = true; } } } else { if (GUILayout.Button("x", GUILayout.Width(30))) { areYouSure = false; breakConnection(1, null, db.npcDiags[ansID]); needSave = true; } } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Tag: ", GUILayout.Width(30)); GUI.color = Color.cyan; Undo.RecordObject(db, "changed Tag"); db.npcDiags[ansID].tag = EditorGUILayout.TextField(db.npcDiags[ansID].tag, stf, GUILayout.Width(80)); GUI.color = defaultColor; GUILayout.Label("Extra data: ", GUILayout.Width(70)); GUI.color = Color.cyan; Undo.RecordObject(db, "changed extraData"); db.npcDiags[ansID].extraData = EditorGUILayout.TextField(db.npcDiags[ansID].extraData, stf); GUI.color = defaultColor; GUILayout.EndHorizontal(); if (Event.current.commandName == "UndoRedoPerformed") { Repaint(); } GUI.DragWindow(); }
//The player node void DrawPlayerWindow(int id) { GUI.enabled = editEnabled; bool dontDrag = false; if (Event.current.type == EventType.MouseUp) { draggingLine = false; dontDrag = true; } GUILayout.BeginHorizontal(); GUI.color = colors[1]; string delText = "Delete Node"; if (areYouSureIndex == id) { if (areYouSure) { delText = "Sure?"; GUI.color = new Color32(176, 128, 54, 255); } } if (GUILayout.Button(delText, GUILayout.Width(80))) { if (areYouSureIndex != id) { areYouSure = false; } if (!areYouSure) { areYouSure = true; areYouSureIndex = id; } else { areYouSure = false; areYouSureIndex = 0; Undo.RecordObject(db, "Removed Player Node"); removeSet(db.playerDiags[id]); needSave = true; return; } } if (Event.current.type == EventType.MouseDown) { areYouSure = false; Repaint(); } GUI.color = defaultColor; if (GUILayout.Button("Add comment")) { areYouSure = false; addComment(db.playerDiags[id]); needSave = true; } GUILayout.EndHorizontal(); for (int i = 0; i < db.playerDiags[id].comment.Count; i++) { if (db.playerDiags[id].comment.Count > 0) { GUILayout.BeginHorizontal(); GUILayout.Label((i + 1).ToString() + ". ", GUILayout.Width(20)); if (i == 0) { GUILayout.Space(24); } if (i != 0) { if (GUILayout.Button("X", GUILayout.Width(20))) { areYouSure = false; removeComment(db.playerDiags[id].comment[i]); needSave = true; return; } } GUIStyle stf = new GUIStyle(GUI.skin.textField); stf.wordWrap = true; GUI.SetNextControlName("pText_" + id.ToString() + i.ToString()); Undo.RecordObject(db, "Edited Player comment"); db.playerDiags[id].comment[i].text = EditorGUILayout.TextArea(db.playerDiags[id].comment[i].text, stf, GUILayout.Width(230)); if (db.playerDiags[id].comment[i].outputAnswer == null) { Rect lr; GUI.color = new Color32(176, 128, 54, 255);; if (GUILayout.RepeatButton("O", GUILayout.Width(30))) { areYouSure = false; lr = GUILayoutUtility.GetLastRect(); lr = new Rect(lr.x + db.playerDiags[id].rect.x + 30, lr.y + db.playerDiags[id].rect.y + 7, 0, 0); if (!draggingLine && !dontDrag) { draggedCom = db.playerDiags[id].comment[i]; draggedAns = null; dragStart = new Vector2(lr.x, lr.y); draggingLine = true; } } GUI.color = defaultColor; } else { GUI.color = defaultColor; if (GUILayout.Button("x", GUILayout.Width(30))) { areYouSure = false; breakConnection(0, db.playerDiags[id].comment[i], null); needSave = true; } if (Event.current.type == EventType.Repaint) { db.playerDiags[id].comment[i].outRect = GUILayoutUtility.GetLastRect(); } } GUILayout.EndHorizontal(); } } if (Event.current.button == 0 && Event.current.type == EventType.MouseDown) { areYouSure = false; Repaint(); } if (Event.current.commandName == "UndoRedoPerformed") { Repaint(); } GUI.DragWindow(); }
public void removeComment(VIDE_EditorDB.Comment idx) { Undo.RecordObject(db, "Removed Comment"); idx.inputSet.comment.Remove(idx); }