/// <summary> /// Returns the current dialog based on the global variable "dialogHeadIndex" /// Returns null if there's none /// </summary> /// <returns></returns> private ListDialog GetCurrentHeadDialog() { if (dialogHeadIndex >= 0) { ListDialog currentDialog = dialogBucket.dialogs[dialogHeadIndex]; return(currentDialog); } return(null); }
/// <summary> /// Sets the dialog head to the one provided by the button action array /// </summary> /// <param name="index"></param> public void HandleButtonActions(int index) { ListDialog currentDialog = GetCurrentHeadDialog(); // Get current dialog dialogHeadIndex = buttonActionArray[index]; // Updates the dialog head index to a new dialog CheckIfMenu(); currentDialog.SetDialogActive(); // Reset the last dialog, could be useful later SetButtons(); // Set the buttons off ShowScript(); // Shows next line of dialog, pointed by the new index }
/// <summary> /// Equeues the .txt file with the dialog, sintax sensetive. /// Lines starting with '#' are comments, lines starting with '(' are button toggle commands /// </summary> private void EnqueueTextFile() { string theWholeFileAsOneLongString = textFile.text; // Gets text file as a one long string List <string> eachLine = new List <string>(); // Creates a list of string to store the lines of text eachLine.AddRange(theWholeFileAsOneLongString.Split('\n')); // Splits (at line break) then adds the lines to the list foreach (string line in eachLine) // Loops through each line of text { if (line.Length > 1) // Checks if theres any characters { if (line[0] != '#') // Checks if the line begins with '#' (a comment, should not do anything) { if (line[0] == '(') // Check if it is a action/toggle button command { ListDialog tmp = new ListDialog(); // If it is, its the end of the actual dialog tmp.action = line; // Creates a new tmp dialog, update the action as the last line int index = dialog.dialogueLines.Count; for (int i = 0; i < index; i++) // Dequeue everything inside this new tmp dialog { tmp.characterNames.Add(dialog.characterNames[i]); tmp.dialogueLines.Add(dialog.dialogueLines[i]); } dialog.CleanDialog(); dialogBucket.dialogs.Add(tmp); // Add it to the dialog bucket for future use } else if (line[0] == '/') // If it isn't then it's just a dialog line { var item = line.Split('('); dialog.characterNames.Add(item[0]); dialog.dialogueLines.Add(uiManager.CleanString(item[1])); } else { var item = line.Split('-'); // Splits at '-': "Character Name" - "Dialog line" dialog.characterNames.Add(uiManager.CleanString(item[0])); // Enqueue character name at the dialog dummy object dialog.dialogueLines.Add(uiManager.CleanString(item[1])); // Enqueue dialog line at the dialog dummy object } } } } }
/// <summary> /// Shows the actual line of dialog, name and portrait of the actual character talking /// It handles the dialog lines and names /// </summary> private void ShowScript() { ListDialog actualDialog = GetCurrentHeadDialog(); // If dialog is either: OFF, OVER or is not even there at all, don't show anything. if (actualDialog != null && !actualDialog.IsDialogOver() && !actualDialog.IsDialogOff()) { // Gets the next character name and line from the actual dialog string[] nameAndLine = actualDialog.GetNextNameAndLine(); if (nameAndLine[0][0] == '/') { HandleCommand(nameAndLine); } else { // Updates the portrait and text to the actual character in screen UpdateTextBox(nameAndLine); } } }
/// <summary> /// If there's no dialog lines left on the actual dialog, show the buttons (if any) /// </summary> private void HandlePrintCompleted() { ListDialog currentDialog = GetCurrentHeadDialog(); if (currentDialog.currentIndex >= currentDialog.dialogueLines.Count) { currentDialog.dialogIsOver = true; } if (!currentDialog.IsDialogOver()) { // If the next line is a certain command, just show script, dont wait for a mouse click string testIfCommand = currentDialog.characterNames[currentDialog.currentIndex].Substring(1); switch (testIfCommand) { case "wait": case "w": ShowScript(); break; case "playsound": case "playSound": case "ps": ShowScript(); break; case "playMusic": case "playmusic": case "pm": ShowScript(); break; } } else { //Debug.Log("PRINT COMPLETED"); SetButtons(dialogBucket.dialogs[dialogHeadIndex].action); } }
/// <summary> /// Show the buttons using a action string [sintax: "(option 1, option 2, option 3)"] /// Or hides if no string is sent /// </summary> /// <param name="rawOptions"></param> private void SetButtons(string rawOptions = "") { foreach (Button child in uiManager.buttonGrid) { child.gameObject.SetActive(false); } if (rawOptions != "") // If no string is sent, just leave everything off { string options = uiManager.CleanString(rawOptions); // Clean raw string if (options[0] == '[') { int num = int.Parse(options.Substring(1, options.Length - 2)); GetCurrentHeadDialog().SetDialogActive(); dialogHeadIndex = num; return; } ListDialog currentDialog = GetCurrentHeadDialog(); // Make a test to see if it's the narrator who is talking // If it is him, toogle button position to center option buttons box //uiManager.ToggleButtonPosition(currentDialog.characterNames[currentDialog.characterNames.Count-1] == uiManager.narratorName); // Then split on the ';' marker, option divided in the item[] var item = options.Split(';'); for (int i = 0; i < item.Length; i++) { var split = item[i].Split('['); uiManager.buttonGrid[i].GetComponentInChildren <TextMeshProUGUI>().text = split[0]; buttonActionArray[i] = int.Parse(uiManager.CleanString(split[1])); uiManager.buttonGrid[i].gameObject.SetActive(true); } /* * if (item.Length > 0) // If there's at least one button: * { * * var split = item[0].Split('['); * uiManager.buttonGrid[0].GetComponentInChildren<TextMeshProUGUI>().text = split[0]; * buttonActionArray[0] = int.Parse(uiManager.CleanString(split[1])); * uiManager.buttonGrid[0].gameObject.SetActive(true); * * } * * if (item.Length > 1) // If there's at least two buttons: * { * var split = item[1].Split('['); * uiManager.buttonGrid[1].GetComponentInChildren<TextMeshProUGUI>().text = split[0]; * buttonActionArray[1] = int.Parse(uiManager.CleanString(split[1])); * uiManager.buttonGrid[1].gameObject.SetActive(true); * } * * if (item.Length > 2) // If there's three buttons: * { * var split = item[2].Split('['); * uiManager.buttonGrid[2].GetComponentInChildren<TextMeshProUGUI>().text = split[0]; * buttonActionArray[2] = int.Parse(uiManager.CleanString(split[1])); * uiManager.buttonGrid[2].gameObject.SetActive(true); * }*/ } }