private void SetDialog(Dialog dialog) { if (dialog == null) { Debug.LogWarning("No dialog found"); return; } m_dialog = new SerializedObject(dialog); if (dialog.StartingOptions.Count == 0) { dialog.StartingOptions.Add(new DialogNode(false)); } ResetEditor(); CheckLine = CurrentlyEdited.Startup; EditedLine = 0; CurrentlyEditedArray = dialog.StartingOptions; NPCOptionStyle = new GUIStyle(); NPCOptionStyle.normal.textColor = Color.red; NPCOptionStyle.fontSize = 13; PlayerOptionStyle = new GUIStyle(); PlayerOptionStyle.normal.textColor = Color.blue; PlayerOptionStyle.fontSize = 13; ActiveButtonStyle = new GUIStyle(); ActiveButtonStyle.normal.background = Resources.Load("selected_line") as Texture2D; ActiveButtonRect = new Rect(0, ActiveHeight, Screen.width, 25); }
void Remove(bool RemoveAllReferences = false) { if (!RemoveAllReferences) { if (CheckLine == CurrentlyEdited.Startup) { Remove(true); } else { int ToRemove = EditedLine; EditedLine = 0; ActiveHeight = 10; if (CheckLine == CurrentlyEdited.Player) { if (isCurrentParentOpeningLine) { for (int i = 0; i < dialog.StartingOptions[parentID].NextOptionID.Count; i++) { if (dialog.StartingOptions[parentID].NextOptionID[i] == ToRemove) { dialog.StartingOptions[parentID].NextOptionID.Remove(dialog.StartingOptions[parentID].NextOptionID[i]); } } Debug.Log(dialog.StartingOptions[parentID].Text); } else { for (int i = 0; i < dialog.SpeakerOptions[parentID].NextOptionID.Count; i++) { if (dialog.SpeakerOptions[parentID].NextOptionID[i] == ToRemove) { dialog.SpeakerOptions[parentID].NextOptionID.Remove(dialog.SpeakerOptions[parentID].NextOptionID[i]); } } Debug.Log(dialog.SpeakerOptions[parentID].Text); } } else if (CheckLine == CurrentlyEdited.NPC) { for (int i = 0; i < dialog.PlayerOptions[parentID].NextOptionID.Count; i++) { if (dialog.PlayerOptions[parentID].NextOptionID[i] == ToRemove) { dialog.PlayerOptions[parentID].NextOptionID.Remove(dialog.PlayerOptions[parentID].NextOptionID[i]); } } } } } else { int ToRemove = EditedLine; EditedLine = 0; ActiveHeight = 10; if (CheckLine == CurrentlyEdited.Startup) { // But first, see if it isn't the ONLY line in the dialog if (dialog.StartingOptions.Count == 1) { // remake a Conversation() with a single dialog node dialog.StartingOptions.Add(new DialogNode(false)); } } if (RemoveAllReferences) { if (CheckLine == CurrentlyEdited.NPC) { RemoveAllReplyReferences(dialog.PlayerOptions, ToRemove); } else { RemoveAllReplyReferences(dialog.SpeakerOptions, ToRemove); RemoveAllReplyReferences(dialog.StartingOptions, ToRemove); } EditArray().Remove(EditArray()[ToRemove]); CheckLine = CurrentlyEdited.Startup; } else { CheckLine = CurrentlyEdited.Startup; } } }
void DisplayDialogue(GUIStyle style, List <DialogNode> array, int editorwidth, int editorheight, int parentLine, bool isParentOpening, List <int> NextOptions, bool OpeningLine = false) { CurrentHeight = editorheight; // Red or blue text? Depending on who's talking // Should only be used for starting options if (OpeningLine) { for (int i = 0; i < array.Count; i++) { CurrentWidth = editorwidth; // Selecting a line if (GUI.Button(new Rect(CurrentWidth, CurrentHeight, array[i].Text.Length * 10, 25), array[i].Text, style)) { EditedLine = i; CheckLine = CurrentlyEdited.Startup; ActiveHeight = CurrentHeight; CurrentlyEditedArray = dialog.StartingOptions; } // +/- to toggle display for replies to a previous line if (!array[i].IsCopy) { array[i].EditorOpen = GUI.Toggle(new Rect(editorwidth - 15, CurrentHeight, 10, 10), array[i].EditorOpen, "+"); if (array[i].EditorOpen) { CurrentHeight += 25; DisplayDialogue(PlayerOptionStyle, dialog.PlayerOptions, CurrentWidth + 15, CurrentHeight, i, true, array[i].NextOptionID); } } if (i < array.Count - 1) { CurrentHeight += 25; } } // used for everything else } else { string HelperLine = ""; for (int i = 0; i < NextOptions.Count; i++) { if (array[NextOptions[i]].IsCopy) { HelperLine = " (Copy)"; } else { HelperLine = ""; } CurrentWidth = editorwidth; // Selecting a line if (GUI.Button(new Rect(CurrentWidth, CurrentHeight, Screen.width, 25), array[NextOptions[i]].Text + HelperLine, style)) { isCurrentParentOpeningLine = isParentOpening; parentID = parentLine; EditedLine = NextOptions[i]; ActiveHeight = CurrentHeight; CurrentlyEditedArray = array; if (NPCTalking(array)) { CheckLine = CurrentlyEdited.NPC; } else { CheckLine = CurrentlyEdited.Player; } } // +/- to toggle display for replies to a previous line if (!array[NextOptions[i]].IsCopy && array[NextOptions[i]].NextOptionID.Count > 0) { array[NextOptions[i]].IsCopy = true; array[NextOptions[i]].EditorOpen = GUI.Toggle(new Rect(CurrentWidth - 15, CurrentHeight, 10, 10), array[NextOptions[i]].EditorOpen, "+"); if (array[NextOptions[i]].EditorOpen) { CurrentHeight += 25; if (NPCTalking(array)) { DisplayDialogue(PlayerOptionStyle, dialog.PlayerOptions, CurrentWidth + 15, CurrentHeight, NextOptions[i], false, array[NextOptions[i]].NextOptionID); } else if (!NPCTalking(array)) { DisplayDialogue(NPCOptionStyle, dialog.SpeakerOptions, CurrentWidth + 15, CurrentHeight, NextOptions[i], false, array[NextOptions[i]].NextOptionID); } else { Debug.LogError("Something went horribly wrong. I don't know which array to display. Report a problem to a developer."); } } } if (i < NextOptions.Count - 1) { CurrentHeight += 25; } } } }