void LoadDialogue(string filename)
    {
        string line;
        StreamReader r = new StreamReader (filename);

        using (r) {
            do {
                line = r.ReadLine();
                if (line != null) {
                    string[] lineData = line.Split(';');
                    if (lineData[0] == "Player") {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], "", 0, "");
                        lineEntry.options = new string[lineData.Length-1];
                        for (int i = 1; i < lineData.Length; i++) {
                            Debug.Log(lineData[i]);
                            lineEntry.options[i-1] = lineData[i];
                        }
                        lines.Add(lineEntry);
                    } else {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], int.Parse(lineData[2]), lineData[3]);
                        lines.Add(lineEntry);
                    }
                }
            }
            while (line != null);
            r.Close();
        }
    }
	// Use this for initialization
	void Start () {
        string textStream = System.IO.File.ReadAllText(filePath);
        string[] lines = textStream.Split('\n');
        foreach(string line in lines)
        {
            if (line != null && !line.Equals("") && !line.Equals("\n"))
            {
                Debug.Log(line);
                string[] parts = line.Split(':');
                if (parts.Length == 2)
                {
                    DialogueLine dl = new DialogueLine(parts[0].Trim(), parts[1].Trim());
                    dialogueLines.Add(dl);
                }
                else
                {
                    Debug.Log("This line is not formatted properly: " + line);
                    //Proper formatting is:
                    //[speaker]: [quote]
                    //...or, for italicized narration:
                    //: [quote]
                }
            }
        }
        //Debug.Log(textStream.Length);
	}
        public override string Run(DialogueFile file, DialogueLine line)
        {
            if (target == null) {
                DialogueCompiler.Instance.Error(line, "No chapter specified");
                return null;
            }

            line.Options.SetSet(DialogueCompiler.ChapterVariable, target);
            return "";
        }
 public void BeginExecution()
 {
     clindex = 0;
     cline = dialogue.lines[clindex];
     cletter = 0;
     cpindex = 0;
     cphrase = System.Text.RegularExpressions.Regex.Unescape(cline.phrases[cpindex]);
     csubstr = "";
     done = false;
     waiting = false;
     delay = 0;
 }
Exemple #5
0
    GameObject ReadDialogueEvidence(XmlReader reader)
    {
        GameObject temp = new GameObject("dialogueEvidence");

        temp.AddComponent <DialogueEvidence>();
        temp.GetComponent <DialogueEvidence>().filepath = reader.GetAttribute("filepath");
        temp.GetComponent <DialogueEvidence>().opener   = reader.GetAttribute("opener");

        Read(reader);

        while (reader.Name == "dialogueLine")
        {
            DialogueLine line = new DialogueLine();
            line.id   = reader.GetAttribute("id");
            line.text = reader.GetAttribute("text");
            line.associatedEvidence = reader.GetAttribute("associatedEvidence");

            if (line.associatedEvidence != null)
            {
                objects[line.associatedEvidence].transform.parent = temp.transform;
            }


            //print(line.id);

            temp.GetComponent <DialogueEvidence>().lines.Add(line.id, line);

            DialogueResponse lastResp = null;
            while (Read(reader) && (reader.Name == "dialogueResponse" || reader.Name == "requirements"))
            {
                if (reader.Name == "dialogueResponse")
                {
                    DialogueResponse resp = new DialogueResponse();
                    resp.text     = reader.GetAttribute("text");
                    resp.directTo = reader.GetAttribute("directTo");

                    line.responses.Add(resp);
                    lastResp = resp;
                }
                else if (reader.Name == "requirements")
                {
                    lastResp.requirements = ReadRequirements(reader);
                }
            }
        }

        return(temp);
    }
Exemple #6
0
 public void HandleDialogue()
 {
     if (currentLine.GetType() == typeof(DialogueLine))
     {
         DialogueLine line = (DialogueLine)currentLine;
         SetLine(line.Speaker, line.Text);
         return;
     }
     else if (currentLine.GetType() == typeof(DialogueIfBranch))
     {
         DialogueIfBranch ifLine = (DialogueIfBranch)currentLine;
         if (CheckConditions(ifLine.ConditionsToCheck, ifLine.CheckType))
         {
             if (ifLine.TrueLineId == 0)
             {
                 EndDialogue();
                 return;
             }
             currentLine = currentDialogue.FindLineById(ifLine.TrueLineId);
             HandleDialogue();
             return;
         }
         else if (ifLine.FalseLineId == 0)
         {
             EndDialogue();
             return;
         }
         else
         {
             currentLine = currentDialogue.FindLineById(ifLine.FalseLineId);
             ;
             HandleDialogue();
         }
         return;
     }
     else if (currentLine.GetType() == typeof(DialogueOption))
     {
         DialogueOption options = (DialogueOption)currentLine;
         SetLine(options.Speaker, options.Text);
         SetUpOptions(options);
         return;
     }
     else
     {
         EndDialogue();
     }
     return;
 }
    void LoadDialogue(string filename)
    {
        string       line;
        StreamReader r = new StreamReader(Application.streamingAssetsPath + filename);

        using (r)
        {
            do
            {
                line = r.ReadLine();
                if (line != null)
                {
                    string[] lineData = line.Split(';');
                    if (lineData[0] == "Player")
                    {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], "", 0, "", "", 0, 0);
                        lineEntry.options = new string[lineData.Length - 1];
                        for (int i = 1; i < lineData.Length; i++)
                        {
                            lineEntry.options[i - 1] = lineData[i];
                        }
                        lines.Add(lineEntry);
                    }
                    else if (lineData[0] == "Event")
                    {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], 0, "", "G", int.Parse(lineData[2]), int.Parse(lineData[3]));
                        lines.Add(lineEntry);
                    }
                    else if (lineData[0] == "Evidence")
                    {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], 0, "M", "Y", int.Parse(lineData[2]), int.Parse(lineData[3]));
                        lines.Add(lineEntry);
                    }
                    else if (lineData[0] == "Health")
                    {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], "You've lost 20 health...", 0, "M", "R", int.Parse(lineData[1]), int.Parse(lineData[2]));
                        lines.Add(lineEntry);
                    }
                    else
                    {
                        DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], int.Parse(lineData[2]), lineData[3], lineData[4], int.Parse(lineData[5]), int.Parse(lineData[6]));
                        lines.Add(lineEntry);
                    }
                }
            }while (line != null);
            r.Close();
        }
    }
    public void IntroOutroDialogue()
    {
        DialogueLine outDialogueLine = null;

        if (this.privGetNextLine(out outDialogueLine))
        {
            this._introOutroDiagDisplay.GetComponent <UnityEngine.UI.Text>().text = outDialogueLine.line;
        }
        else
        {
            this._introOutroDiagDisplay = null;
            // Terrible...
            AudioManager.Instance.StopSound("Menu", AudioType.Music);
            GameManager.Instance.GetComponent <BM_SceneManager>().LoadNextScene();
        }
    }
    public bool TryStartConversation(string conversationID)
    {
        ConversationGraph conversation;

        if (dialogue.TryGetConversation(conversationID, out conversation))
        {
            currentConversation = conversation;
            currentLine         = currentConversation.GetFirstMessage().Value;
            ShowLine(currentLine);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #10
0
 private void DialogoLoad()
 {
     if (Dialogo != null)
     {
         using (StringReader reader = new StringReader(Dialogo))
         {
             string line;
             while ((line = reader.ReadLine()) != null)
             {
                 string[]     lineData  = line.Split(':');
                 DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], int.Parse(lineData[2]), lineData[3]);
                 lines.Add(lineEntry);
             }
         }
     }
 }
    public string GetAnswer(int questionId, bool isRight)
    {
        DialogueLine currLine = GetLine(questionId);
        string       text     = "";

        if (isRight)
        {
            text += currLine.response_right;
        }
        else
        {
            text += currLine.response_wrong;
        }

        return(text + currLine.response_either);
    }
Exemple #12
0
    public IEnumerator DialogueLine(DialogueLine dialogueLine)
    {
        switch (dialogueLine.dialogueLineType)
        {
        case Dialogue.DialogueLineType.TRIGGER:
            yield return(StartCoroutine(DialogueTrigger(dialogueLine)));

            break;

        default:
        case Dialogue.DialogueLineType.TEXT:
            yield return(StartCoroutine(DialogueText(dialogueLine)));

            break;
        }
    }
    public string GetQuestion(int questionId, bool isRight)
    {
        DialogueLine currLine = GetLine(questionId);

        string text = currLine.question_base;

        if (isRight)
        {
            text += currLine.question_right;
        }
        else
        {
            text += currLine.question_wrong;
        }

        return(text);
    }
Exemple #14
0
    /* Starts the monologue of the next speaker in the allLines queue.
     * If allLines queue is empty, the dialogue has ended and it calls
     * the GenerateOptions() method. If there are still lines in the queue,
     * it names the speaker and makes a queue of the sentences to be displayed.
     * */
    public void NextSpeaker()
    {
        if (allLines.Count == 0)
        {
            GerenateOptions(options);
            return;
        }

        DialogueLine dialogueLine = allLines.Dequeue();

        nameText.text = dialogueLine.name;

        foreach (string sentence in dialogueLine.sentences)
        {
            sentences.Enqueue(sentence);
        }
        DisplayNextSentence();
    }
Exemple #15
0
    public override void OnInspectorGUI()
    {
        DialogueLine line = (DialogueLine)target;


        Texture sprite = line.Speaker.Sprites[line.Emotion].texture;

        float width = sprite.width * 400 / sprite.height;
        Rect  test  = new Rect(Screen.width / 2 - width / 2, 0, width, 400);

        GUI.DrawTexture(test, sprite);
        EditorGUILayout.Space(400);

        lang = (SystemLanguage)EditorGUILayout.EnumPopup(lang, GUILayout.Height(25));

        if (!line.FullText.ContainsKey(lang))
        {
            if (GUILayout.Button("Create translation"))
            {
                line.FullText.Add(lang, "");
            }
        }
        else
        {
            line.FullText[lang] = GUILayout.TextArea(line.FullText[lang], GUILayout.MinHeight(50));
            if (GUILayout.Button("Remove translation"))
            {
                line.FullText.Remove(lang);
            }
        }

        EditorGUILayout.Space(15);

        EditorGUILayout.PropertyField(speaker);
        EditorGUILayout.PropertyField(emotion);
        EditorGUILayout.PropertyField(anonymous);

        EditorGUILayout.Space(15);

        EditorList.Show(movement, "Character Movement");


        serializedObject.ApplyModifiedProperties();
    }
    public void SetNextDialogueLine()
    {
        if (_linesQueue.Count == 0)
        {
            EndDialogue();
            return;
        }

        DialogueLine line = _linesQueue.Dequeue();

        _characterNameField.SetText(line.CharacterName);

        if (_lastTypeRoutine != null)
        {
            StopCoroutine(_lastTypeRoutine);
        }

        _lastTypeRoutine = StartCoroutine(TypeLineRoutine(line.CharacterLine.ToCharArray()));
    }
    private List <DialogueLine> ConvertToDialogue(string filePath)
    {
        List <DialogueLine> lines = new List <DialogueLine>();

        string textFile = Resources.Load <TextAsset>(filePath).text;

        string[] fileLines = Regex.Split(textFile, "\n|\r|\r\n");

        foreach (string line in fileLines)
        {
            if (!line.Equals(""))
            {
                DialogueLine l = ConvertLine(line);
                lines.Add(l);
            }
        }

        return(lines);
    }
    /// <summary>
    /// Show dialogue with updated text from DialogueData
    /// </summary>
    public void ShowDialogueBox(DialogueLine dialogueLine)
    {
        _dialogueBox.Go.SetActive(true);

        if (dialogueLine.Actor != null)
        {
            _dialogueBox.Figure.gameObject.SetActive(true);
            _dialogueBox.Name.gameObject.SetActive(true);
            _dialogueBox.Figure.sprite = dialogueLine.Actor.Face;
            _dialogueBox.Name.text     = dialogueLine.Actor.name;
        }
        else
        {
            _dialogueBox.Figure.gameObject.SetActive(false);
            _dialogueBox.Name.gameObject.SetActive(false);
        }

        _dialogueBox.Message.text = dialogueLine.Sentence;
    }
    public void SetLine(DialogueLine line)
    {
        if (line == null)
        {
            GetComponent <UIDrawerBehaviour>().Hide();
            enabled = false;
            currentDialogue.DialogueEnd.Invoke();
            return;
        }

        dialogueField.text = string.Empty;

        portrait.sprite = portraits[line.characterID];
        currentLine     = line;
        string tmpText = line.line;

        if (CharacterStaticStorage.instance.fullCharacterList.Count != 0 && CharacterStaticStorage.instance.fullCharacterList[0] != null)
        {
            tmpText.Replace("[NAME]", CharacterStaticStorage.instance.fullCharacterList[0].name);
        }
        //tmpText = tmpText.Replace("[NAME]", CharacterStaticStorage.instance.fullCharacterList[0].name);
        currentText = tmpText;
        switch (line.portraitPosition)
        {
        case PortraitPositions.Left:
            portrait.rectTransform.anchoredPosition = centralPortraitPosition + Vector2.left * portraitOffsetFromCenter;
            break;

        case PortraitPositions.Right:
            portrait.rectTransform.anchoredPosition = centralPortraitPosition + Vector2.right * portraitOffsetFromCenter;
            break;

        case PortraitPositions.Center:
            portrait.rectTransform.anchoredPosition = centralPortraitPosition;
            break;
        }

        if (!showCharacterByCharacter)
        {
            dialogueField.text = line.line;
        }
    }
    /// <summary>
    /// Loads a dialogue scene file into dialogue line structs.
    /// </summary>
    /// <param name="scene">The scene file to be loaded</param>
    public void LoadDialogue(int scene)
    {
        lines = new List <DialogueLine>();
        string file = "Assets/Dialogue/Dialogue" + scene + ".txt";
        string line;

        using (StreamReader r = new StreamReader(file))
        {
            line = r.ReadLine();
            while (line != null)
            {
                {
                    string[]     lineData = line.Split(';');
                    DialogueLine lineEntry;
                    if (lineData[0] == "options")
                    {
                        lineEntry = new DialogueLine(
                            (UIManager.Character)Enum.Parse(typeof(UIManager.Character), lineData[0]), "", 0, "");
                        lineEntry.options = new string[lineData.Length - 1];
                        for (int i = 1; i < lineData.Length; i++)
                        {
                            lineEntry.options[i - 1] = lineData[i];
                        }
                    }
                    else if (lineData[0] == "end")
                    {
                        lineEntry = new DialogueLine(
                            (UIManager.Character)Enum.Parse(typeof(UIManager.Character), lineData[0]), "", 0, "");
                    }
                    else
                    {
                        lineEntry = new DialogueLine(
                            (UIManager.Character)Enum.Parse(typeof(UIManager.Character), lineData[0]), lineData[1],
                            (UIManager.Expression)Enum.Parse(typeof(UIManager.Expression), lineData[2]), lineData[3]);
                    }
                    lines.Add(lineEntry);
                    line = r.ReadLine();
                }
            }
            r.Close();
        }
    }
Exemple #21
0
    public void AdvanceDialogue()
    {
        if (currentLine.SetWhenDone != null)
        {
            SetFlag(currentLine.SetWhenDone, currentLine.SetType);
            currentLine.TriggerPassed = true;
        }
        DialogueLine line = (DialogueLine)currentLine;

        if (line.NextLineId == 0)
        {
            EndDialogue();
        }
        else
        {
            currentLine = currentDialogue.FindLineById(line.NextLineId);
            Debug.Log("next line");
            HandleDialogue();
        }
    }
Exemple #22
0
    void LoadDialogue(string filename)
    {
        string       file = "Assets/Resources/" + filename;
        string       line;
        StreamReader r = new StreamReader(file);

        using (r) {
            do
            {
                line = r.ReadLine();
                if (line != null)
                {
                    string[]     lineValues = SplitCsvLine(line);
                    DialogueLine line_entry = new DialogueLine(lineValues[0], lineValues[1], int.Parse(lineValues[2]));
                    lines.Add(line_entry);
                }
            }while (line != null);
            r.Close();
        }
    }
Exemple #23
0
    public void DisplayDialogueLine(DialogueLine dialogueLine)
    {
        switch (dialogueLine.Speaker)
        {
        case SpeakerType.Player:
            ShowTextCoroutine = ShowText("You: " + dialogueLine.Text, 5, dialogueLine.Time);
            StartCoroutine(ShowTextCoroutine);
            break;

        case SpeakerType.Professor:
            ShowTextCoroutine = ShowText("Doc: " + dialogueLine.Text, 4, dialogueLine.Time);
            StartCoroutine(ShowTextCoroutine);
            break;

        case SpeakerType.Sound:
            ShowTextCoroutine = ShowText(dialogueLine.Text, dialogueLine.Text.Length - 1, dialogueLine.Time);
            StartCoroutine(ShowTextCoroutine);
            break;
        }
    }
Exemple #24
0
        private void SetupInventoryCell(DialogueLine dialogueLine)
        {
            var model = dialogueLine.GetAssociatedQuestModel();

            if (model == null)
            {
                Logger.Error("Could not find associated quest model");
                return;
            }
            if (model is QuestEventModel qem)
            {
                var metadata = MetadataLoader.LootItemIdToMetadata[qem.ItemId];
                var item     = InventoryItem.FromMetadata(metadata);
                item.Amount = qem.Required;
                _inventoryCell.SetInventoryItem(item);
            }
            else
            {
                Logger.Error("Could not parse model as an event model " + model.Id);
            }
        }
    public override void bottomOption()
    {
        base.bottomOption();
        switch (optionNumber)
        {
        case 0:
            lines = new DialogueLine[] { new DialogueLine(gm.DialogueMan.getLine("mateo1_1_3"), () => { gm.EventMan.lerpToTarget.Invoke("shovel1", -45f, 1.0f); }, null, () => { gm.EventMan.lookAtPlayer.Invoke(); lines = new DialogueLine[] { new DialogueLine(gm.DialogueMan.getLine("mateo1_1_pretextbook")) }; }) };
            //options = new string[] { };
            lines[currentText].doLineStart();
            break;

        case 1:
            lines = new DialogueLine[] { new DialogueLine(gm.DialogueMan.getLine("mateo1_1_helped3"), () => { }, null, () => { }) };
            //options = new string[] { };
            lines[currentText].doLineStart();
            break;

        default:
            break;
        }
    }
	//Add character dialogue lines through here by characterName and the current dialogue line in that conversation
	public void AddLine(string characterName, DialogueLine dialogue){
		Handheld.Vibrate ();

		AudioSource.PlayClipAtPoint (messageSound, Vector3.zero);

		if (!m_conversationHistories.ContainsKey (characterName)) { //New conversation
				m_conversationHistories.Add (characterName, new List<DialogueLine> ());

				AddConversationDisplay (characterName, Color.white, dialogue);
		} else {
				UpdateConversationDisplay (characterName, Color.white, dialogue);
		}

		m_conversationHistories [characterName].Add (dialogue);

		//If ChatHandler is currently up, update it
		if (ChatHandler.Instance.IsCurrentCharacter (characterName)) {
				ChatHandler.Instance.UpdateList (dialogue);		
		}

	}
Exemple #27
0
    void LoadDialogue(string filename)
    {
        string       line;
        StreamReader r = new StreamReader(filename);

        using (r)
        {
            do
            {
                line = r.ReadLine();
                if (line != null)
                {
                    string[] lineData = line.Split(';');

                    DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], int.Parse(lineData[2]), lineData[3]);
                    lines.Add(lineEntry);
                }
            }while (line != null);
            r.Close();
        }
    }
Exemple #28
0
    //Called to add a brand new dialogue display
    private void AddConversationDisplay(string characterName, Color characterColor, DialogueLine dialogue)
    {
        GameObject conversationObj = Instantiate(conversationDisplayPrefab.gameObject) as GameObject;

        if (conversationObj != null)
        {
            ConversationDisplayUnit displayUnit = conversationObj.GetComponent <ConversationDisplayUnit>();

            displayUnit.SetUpDialogue(characterName, dialogue.LineOfDialogue, characterColor, Color.white);
            m_conversationDisplays.Add(displayUnit);

            if (m_conversationDisplays.Count > 1)
            {
                displayUnit.transform.position = m_conversationDisplays[m_conversationDisplays.Count - 2].transform.position - Vector3.up * DISTANCE_BETWEEN_CONVERSATIONS;
            }

            displayUnit.SetReadInConversation(TransferToChat);

            displayUnit.transform.parent = transform;
        }
    }
    public void LoadLine(DialogueLine line)
    {
        currentLine = line;

        // Load Speaker
        speaker.text = line.Speaker;
        if (speaker.text == "")
        {
            speakerPanel.SetActive(false);
        }
        else
        {
            speakerPanel.SetActive(true);
        }

        // Load Line
        // Sets responses at completion of coroutine
        StartCoroutine(LoadText(line.Line));

        // Apply Flag
    }
    // Dialogue is pulled from this method by providing actors name and set/line id
    public string getActorLineById(string actor, int setId, int lineId)
    {
        ActorDialogue actorDialogue;

        if (dialogue.TryGetValue(actor, out actorDialogue))
        {
            DialogueLine dialogueLine = actorDialogue.getDialogueLineById(setId, lineId);
            if (dialogueLine != null)
            {
                return(dialogueLine.getText());
            }
            else
            {
                return("FAIL");
            }
        }
        else
        {
            return("FAIL, NO VALUE");
        }
    }
    public int getBranchById(string actor, int setId, int lineId)
    {
        ActorDialogue actorDialogue;

        if (dialogue.TryGetValue(actor, out actorDialogue))
        {
            DialogueLine dialogueLine = actorDialogue.getDialogueLineById(setId, lineId);
            if (dialogueLine != null)
            {
                return(dialogueLine.getBranchSetId());
            }
            else
            {
                return(0);
            }
        }
        else
        {
            return(0);
        }
    }
Exemple #32
0
    public static void Show(SerializedProperty list, string name = "", bool showListSize = false)
    {
        if (name != "")
        {
            EditorGUILayout.LabelField(name);
        }

        EditorGUI.indentLevel += 1;

        if (list.isExpanded)
        {
            if (showListSize)
            {
                EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
            }

            for (int i = 0; i < list.arraySize; i++)
            {
                SerializedProperty element = list.GetArrayElementAtIndex(i);
                DialogueLine       line    = element.objectReferenceValue as DialogueLine;

                EditorGUILayout.BeginHorizontal();
                GUILayout.TextArea(line.Text, GUILayout.MaxWidth(200));

                EditorGUILayout.PropertyField(element, new GUIContent(""), GUILayout.MaxWidth(100));
                if (GUILayout.Button("Remove"))
                {
                    list.arraySize -= 1;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space(5);
            }
        }
        EditorGUI.indentLevel -= 1;

        if (GUILayout.Button("Add"))
        {
            list.arraySize += 1;
        }
    }
    void LoadDialogue(string filename)
    {
        string       line;
        StreamReader r = new StreamReader(filename);

        using (r){
            do
            {
                line = r.ReadLine();
                if (line != null)
                {
                    if (line != "")
                    {
                        string[] lineData = line.Split(';');
                        if (lineData[0] == "Player")
                        {
                            DialogueLine lineEntry = new DialogueLine(lineData[0], "", new Vector3(0, 0, 0));
                            lineEntry.choices = new string[lineData.Length - 1];
                            for (int i = 1; i < lineData.Length; i++)
                            {
                                lineEntry.choices[i - 1] = lineData[i];
                            }
                            lines.Add(lineEntry);
                        }
                        else
                        {
                            string[]     position  = lineData[2].Split(',');
                            DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], new Vector3(float.Parse(position[0]), float.Parse(position[1]), float.Parse(position[2])));
                            lines.Add(lineEntry);
                        }
                    }
                    else
                    {
                        lines.Add(new DialogueLine("", "", new Vector3(0, 0, 0)));
                    }
                }
            } while (line != null);
            r.Close();
        }
    }
Exemple #34
0
 //also called by the NPC controller, there's some intermediary parsing that goes on here
 public void RenderDialogue(DialogueLine line)
 {
     //setting the player portrait for a reply
     if (line.image < 0)
     {
         SetPortrait(playerPortrait);
         SetName(pc.playerName);
     }
     else
     {
         if (currentNPC != null)
         {
             SetPortrait(currentNPC.portraits[line.image]);
         }
         else if (currentBoss != null)
         {
             SetPortrait(currentBoss.bossPortraits[line.image]);
         }
         SetName(line.name);
     }
     SetText(line.text);
 }
    public static DialogueEntry GetEntriesInChild(DialogueContainer a_dialogue, XmlNode a_node)
    {
        string        type = a_node.Name;
        DialogueEntry res  = null;

        switch (type)
        {
        case "window":
            res = new DialogueWindowMode(a_node);
            break;

        case "line":
            res = new DialogueLine(a_node);
            break;

        default:
            Debug.LogError("[Dialogue] Not a valid format " + type);
            break;
        }

        return(res);
    }
        public static string ExecuteCommands(DialogueFile file, DialogueLine line)
        {
            int startAt = 0;
            bool keep = true;
            var newLine = new StringBuilder(line.Content.Length);
            var match = commandPattern.Match(line.Content, startAt);
            while (match.Success) {
                newLine.Append(line.Content.Substring(startAt, match.Index - startAt));

                var commandName = match.Groups[1].Value;
                if (commands.ContainsKey(commandName)) {
                    var args = new string[match.Groups[2].Captures.Count];
                    for (int i = 0; i < match.Groups[2].Captures.Count; ++i) {
                        args[i] = match.Groups[2].Captures[i].Value;
                    }

                    var command = commands[commandName](commandName, args);

                    var replacement = command.Run(file, line);
                    if (replacement == null) {
                        keep = false;
                    } else {
                        newLine.Append(replacement);
                    }

                } else {
                    (new NoSuchCommand(commandName, null)).Run(file, line);
                }

                startAt = match.Index + match.Length;
                match = commandPattern.Match(line.Content, startAt);
            }

            newLine.Append(line.Content.Substring(startAt));

            return keep ? newLine.ToString() : null;
        }
Exemple #37
0
 public bool Wait()
 {
     waiting = true;
     if (Input.GetButtonDown("Select")) {
         if (clindex == dialogue.lines.Length - 1) {
             return true;
         }
         clindex++;
         cline = dialogue.lines[clindex];
         cpindex = 0;
         cphrase = System.Text.RegularExpressions.Regex.Unescape(cline.phrases[cpindex]);
         cletter = 0;
         csubstr = "";
         waiting = false;
     }
     return false;
 }
    public void DisplayLine(DialogueLine dl)
    {
        CurrentNode = dl;

        //show = true;
    }
    private DialogueLine ProcessNodeLine()
    {
        string line;
        DialogueLine LineNode = new DialogueLine();
        do
        {
            line = GetValidLine();

            if(line != null)
            {
                if(line[0] == '}')
                    break;
                else
                {
                    string[] elements = line.Split('=');
                    switch(elements[0].ToLower())
                    {
                    case "speaker_id":
                        LineNode.SetSpeakerId(int.Parse(elements[1]));
                        break;
                    case "text":
                        LineNode.SetText(elements[1]);
                        break;
                    default:
                        AttemptToAddJump(elements);
                        break;
                    }
                }
            }
        } while(line != null);
        return LineNode;
    }
 private void DisplayLine(DialogueLine line)
 {
     image.sprite = line.Portrait;
     StopCoroutine("TypeText");
     dialogueText.text = string.Empty;
     StartCoroutine("TypeText");
 }
	//Update dialogue display
	private void UpdateConversationDisplay(string characterName, Color characterColor, DialogueLine dialogue){
		for(int i = 0; i<m_conversationDisplays.Count; i++){
			if(m_conversationDisplays[i].IsSameConversation(characterName)){

				m_conversationDisplays[i].SetUpDialogue(characterName, dialogue.LineOfDialogue,characterColor,Color.white);
			}
		}
	}
Exemple #42
0
	//Adds the new line, then needs to update the display
	public void UpdateList(DialogueLine line){
		string toAdd="";

		int linesBetween =1;
		
		if(line.LineOfDialogue.Length<MAX_LINE_LENGTH){
			toAdd+=line.LineOfDialogue;

		}
		else{
			int charsOnThisLine = 0;
			for(int i = 0; i<line.LineOfDialogue.Length; i++){
				if(line.LineOfDialogue[i]==' '){
					int charsExtra = 0; 
					
					while(charsExtra+i<line.LineOfDialogue.Length && line.LineOfDialogue[charsExtra+i]!=' '){
						charsExtra++;
					}
					
					if(charsExtra+i>line.LineOfDialogue.Length){
						//Do nothing, we'll just get to the end of the line
						toAdd+=line.LineOfDialogue[i];
						charsOnThisLine++;
					}
					else{
						if(charsExtra+charsOnThisLine>MAX_LINE_LENGTH){
							toAdd+=line.LineOfDialogue[i]+"\n";
							charsOnThisLine=0;
							linesBetween++;

						}
						else{
							toAdd+=line.LineOfDialogue[i];
							charsOnThisLine++;
						}
					}
					
				}
				else{
					toAdd+=line.LineOfDialogue[i];
					charsOnThisLine++;
				}
				
				
			}
		}
	
		if(line.IsPlayerLine()){//The Player Said This
			playerText.text+=toAdd+"\n";

			//Add spaces where appropriate
			for(int i = 0; i<linesBetween; i++){
				otherText.text+="\n";
			}
		}
		else{//The other character said this
			otherText.text+=toAdd+"\n";

			//Add spaces where appropriate
			for(int i = 0; i<linesBetween; i++){
				playerText.text+="\n";
			}
		}
		
	}
 public override string Run(DialogueFile file, DialogueLine line)
 {
     return String.Format("*{0}*", DialogueCompiler.ChapterVariable);
 }
 public AtChapter(DialogueLine param)
 {
     line = param;
 }
    void LoadDialogue(string filename) {
        string file = "Assets/Err of the Divine/Resources/Dialogues/" + filename;
        string line;
        StreamReader r = new StreamReader(filename);

        using (r) {
            do {
                line = r.ReadLine();
                if (line != null) {
                    string[] line_values = SplitCsvLine(line);
                    DialogueLine line_entry = new DialogueLine(line_values[0],line_values[1],int.Parse(line_values[2]),line_values[3]);
                    lines.Add(line_entry);

                }
            }
            while (line != null);
            r.Close();
        }
    }
Exemple #46
0
 public AtLoad(DialogueLine param)
 {
     File = DialogueFile.Open(param.Content);
 }
 public AtDialogueName(DialogueLine param)
 {
     name = param;
 }
 public abstract string Run(DialogueFile file, DialogueLine line);
Exemple #49
0
 // Use this for initialization
 public void addLine(DialogueLine line)
 {
     lines.Add(line);
 }
Exemple #50
0
        public DialogueLine ScaleDialogue(DialogueLine dl)
        {
            //No need to scale 1:1
            if (scalefactorx==1.0 && scalefactory==1.0) return dl;

            sb = new StringBuilder(1024);
            linetok = dl.text;

            lastindex = 0;
            mc = rscale.Matches(linetok);
            for (int mindex = 0; mindex != mc.Count; mindex+=1) {
                m = mc[mindex];
                if (m.Index > lastindex)
                    sb.Append(linetok.Substring(lastindex, m.Index - lastindex));

                gc = m.Groups; //gc[1] is the command with parenthesis, gc[2] is all the params
                sb.Append(gc[1]);

                switch (gc[1].Value) {
                    case "\\pos(":
                        split = gc[2].Value.Split(",".ToCharArray());
                        sb.Append(String.Format("{0},{1}",
                            Math.Round((double.Parse(split[0], Util.nfi) * scalefactorx), 0),
                            Math.Round((double.Parse(split[1], Util.nfi) * scalefactory), 0)));
                        break;

                    case "\\org(":
                        split = gc[2].Value.Split(",".ToCharArray());
                        sb.Append(String.Format("{0},{1}",
                            Math.Round((double.Parse(split[0], Util.nfi) * scalefactorx), 0),
                            Math.Round((double.Parse(split[1], Util.nfi) * scalefactory), 0)));
                        break;

                    case "\\clip(":
                        split = gc[2].Value.Split(",".ToCharArray());

                        // if it doesn't have 4 tokens, it's either malformed or a drawing type clip
                        //  and if it's a drawing type clip, the drawing itself will be caught later
                        if (split.Length == 4) {
                            try {
                                String.Format("{0},{1},{2},{3}",
                                    Math.Round((double.Parse(split[0], Util.cfi) * scalefactorx), 0),
                                    Math.Round((double.Parse(split[1], Util.cfi) * scalefactory), 0),
                                    Math.Round((double.Parse(split[2], Util.cfi) * scalefactorx), 0),
                                    Math.Round((double.Parse(split[3], Util.cfi) * scalefactory), 0));
                            } catch { }
                        }
                        break;

                    case "\\move(":
                        split = gc[2].Value.Split(",".ToCharArray());

                        tokindex = 0;
                        for (tokindex = 0; tokindex != split.Length; tokindex+=1) {
                            if (tokindex != 1) sb.Append(",");
                            if (tokindex < 5)
                                //Tokens will alternate x and y, so tokindex&1==0 should mean x, otherwise y
                                sb.Append(Math.Round((double.Parse(split[tokindex], Util.cfi) * (((tokindex&1) == 0) ? scalefactorx : scalefactory)), 0));
                            else //5 and 6 are times, don't scale them
                                sb.Append(split[tokindex]);
                        }
                        break;

                    case "\\bord":
                        sb.Append(Math.Round((double.Parse(gc[2].Value, Util.cfi) * scalefactory), 0));
                        break;

                    case "\\shad":
                        sb.Append(Math.Round((double.Parse(gc[2].Value, Util.cfi) * scalefactory), 0));
                        break;

                    case "\\fs":
                        sb.Append(Math.Round((double.Parse(gc[2].Value, Util.cfi) * scalefactory), 0));
                        break;

                    case "\\fsp":
                        sb.Append(Math.Round((double.Parse(gc[2].Value, Util.cfi) * scalefactorx), 0));
                        break;

                    case "\\pbo":
                        sb.Append(Math.Round((double.Parse(gc[2].Value, Util.cfi) * scalefactory), 0));
                        break;

                    default:
                        sb.Append(gc[2]); // don't know what it is, don't touch the params
                        break;
                }

                lastindex = m.Index + m.Length;
            }

            if (linetok.Length > lastindex)
                sb.Append(linetok.Substring(lastindex, linetok.Length - lastindex));

            if (rscaledrawing.IsMatch(linetok)) { // linetok isn't current yet but it's enough to just find a match
                linetok = sb.ToString();
                x = true; // x first
                sb = new StringBuilder(1024);
                lastindex = 0;
                mc = rscaledrawing.Matches(linetok);
                for (int mindex = 0; mindex != mc.Count; mindex+=1) {
                    m = mc[mindex];
                    pscale = int.Parse(m.Groups["scale"].Value);
                    foreach (Capture c in m.Groups["num"].Captures) {
                        if (c.Index > lastindex)
                            sb.Append(linetok.Substring(lastindex, c.Index - lastindex));
                        sb.Append((pscale > 0) ? Math.Round(double.Parse(c.Value) * (x ? scalefactorx : scalefactory), 0).ToString(Util.cfi) : c.Value);
                        x = !x; // Alternate X and Y
                        lastindex = c.Index + c.Length;
                    }
                }

                if (linetok.Length > lastindex)
                    sb.Append(linetok.Substring(lastindex, linetok.Length - lastindex));
            }

            dl.text = sb.ToString();
            return dl;
        }
	//Called to add a brand new dialogue display
	private void AddConversationDisplay(string characterName, Color characterColor, DialogueLine dialogue){
		GameObject conversationObj = Instantiate (conversationDisplayPrefab.gameObject) as GameObject;

		if (conversationObj != null) {
			ConversationDisplayUnit displayUnit = conversationObj.GetComponent<ConversationDisplayUnit>();

			displayUnit.SetUpDialogue(characterName,dialogue.LineOfDialogue,characterColor, Color.white);
			m_conversationDisplays.Add (displayUnit);

			if(m_conversationDisplays.Count>1){
				displayUnit.transform.position=m_conversationDisplays[m_conversationDisplays.Count-2].transform.position- Vector3.up*DISTANCE_BETWEEN_CONVERSATIONS;
			}

			displayUnit.SetReadInConversation(TransferToChat);

			displayUnit.transform.parent=transform;
		}
	}
 public override string Run(DialogueFile file, DialogueLine line)
 {
     DialogueCompiler.Instance.Error(line, "No such command ({0})", command);
     return null;
 }
Exemple #53
0
 public override string Run(DialogueFile file, DialogueLine line)
 {
     return "%22";
 }