public void DisplayDialogueLine(DialogueLine line)
        {
            if (!is_displaying)
            {
                is_displaying = true;
                speech_bubble_container.gameObject.SetActive(true);
            }

            text_container.text = "";

            if (line.contains_a_lie)
            {
                text_container.text = "<color=#DC143C>" + line.line_text + "</color>";
            }
            else
            {
                StopAllCoroutines();
                StartCoroutine(TypeLine(line.line_text));
            }
        }
Exemplo n.º 2
0
		public static void LoadFile(string CharacterName, SpeechHandler NewSpeech, List<string> MyLines) {
			List<string> SavedData = new List<string> ();//used to break up commands
			bool IsReadingID = false;
			bool IsReadingQuest = false;
			
			for (int i = 0; i < MyLines.Count; i++) {
				string line = MyLines[i];
				if (ContainsMainTag(line)) {
					if (IsReadingID) {
						//Debug.LogError("Adding new dialog! at line: " + line);
						DialogueLine NewDialogue = new DialogueLine(SavedData, NewSpeech.DialogueSize()+1, CharacterName);
						NewSpeech.AddDialogue (NewDialogue);
					} else if (IsReadingQuest) {
						Quest NewQuest = new Quest (SavedData);
						//Debug.LogError("Adding new quest: " + NewQuest.Name);
						if (NewSpeech.GetMainTalker())
							NewSpeech.GetMainTalker().AddQuest(NewQuest);
						else
							Debug.LogError("No main talker in conversation: " + NewSpeech.name);
					}
					SavedData.Clear();
					IsReadingID = (line.Contains ("/id"));
					IsReadingQuest =(line.Contains ("/quest"));
				}
				else {
					SavedData.Add (line);
				}
			}
			if (IsReadingID ) {
				DialogueLine NewDialogue = new DialogueLine(SavedData, NewSpeech.DialogueSize()+1, CharacterName);
				NewSpeech.AddDialogue (NewDialogue);
			}
			if (IsReadingQuest) {
				Quest NewQuest = new Quest (SavedData);
				NewSpeech.GetMainTalker().MyQuests.Add (NewQuest);
			}
		}
Exemplo n.º 3
0
 public void AddDialogue(DialogueLine NewDialogue)
 {
     MyDialogues.Add (NewDialogue);
 }
Exemplo n.º 4
0
        // handles the various setups for responses
        private void UpdateRespondType(DialogueLine NewDialogue)
        {
            float BubbleWidth = 100f*1.4f;
            float BubbleHeight = 100f*1.4f;
            RectTransform MyRect = MyDialogueText.GetComponent <RectTransform> ();

            DeactivateChildren ();

            if (NewDialogue.ReverseDialogueLines.Count <= 1)
            {
                MyDialogueText.gameObject.transform.FindChild("NextButton").gameObject.SetActive(true);
            }
            else
            {
                ToggleSpeechBubble2(true);
                MyCharacter2.GetSpeechHandler().MyDialogueText.GetComponent<SpeechAnimator> ().NewLine (NewDialogue.GetTotalReverseText());
                for (int i = 0; i < NewDialogue.ReverseDialogueLines.Count; i++)
                {
                    GameObject MyBlockThing = MyCharacter2.GetSpeechHandler().MyDialogueText.transform.FindChild("BlockThing" + i).gameObject;
                    MyBlockThing.SetActive(true);
                    //.MyBlockThing.GetComponent<RawImage>().color = Color.grey;
                    MyBlockThing.GetComponent<RawImage>().color = new Color32((byte)(Color.grey.r),
                                                                              (byte)(Color.grey.g),
                                                                              (byte)(Color.grey.b),
                                                                              80);

                    GameObject NewChild = new GameObject();
                    NewChild.name = "Option"+(i);

                    RawImage MyImage = NewChild.AddComponent<RawImage>();

                    Button MyButton = NewChild.AddComponent<Button>();
                    MyButton.targetGraphic = MyImage;
                    ColorBlock MyColors = MyButton.colors;
                    MyColors.normalColor = Color.grey;
                    MyColors.highlightedColor = Color.cyan;
                    MyColors.pressedColor = Color.green;
                    MyButton.colors = MyColors;
                    int Blarg = i;
                    MyButton.onClick.AddListener( () =>{
                        //Debug.LogError("......Gah.");
                        NextLine(Blarg);
                    });
                    NewChild.transform.position = MyDialogueText.transform.position;
                    NewChild.transform.rotation = Quaternion.identity;	//MyDialogueText.transform.rotation;
                    NewChild.transform.localScale = MyDialogueText.transform.localScale;
                    Vector3 OffsetPosition = new Vector3(-MyRect.GetSize().x/4f + i*BubbleWidth*2f, -MyRect.GetSize().y/2f-BubbleHeight/2f,0.3f);
                    NewChild.transform.position += OffsetPosition;
                    NewChild.transform.SetParent(MyDialogueText.transform, false);
                }
            }
            CanUpdateDialogue = true;
        }
Exemplo n.º 5
0
 private void UpdateDialogue(DialogueLine NewDialogue)
 {
     if (CanUpdateDialogue) {
         if (NewDialogue.IsReverseSpeech())
         {
             ToggleSpeech(false, true);
             MyCharacter2.GetSpeechHandler().MyDialogueText.GetComponent<SpeechAnimator> ().NewLine (NewDialogue.GetReverseSpeechDialogue(ChattedCount == 0));
             MyCharacter2.GetSpeechHandler().DeactivateChildren ();
             MyCharacter2.GetSpeechHandler().AddAnimationListener();
             MyCharacter2.GetSpeechHandler().CanUpdateDialogue = false;
         } else {
             ToggleSpeech(true, false);
             MyDialogueText.gameObject.GetComponent<SpeechAnimator> ().NewLine (NewDialogue.GetSpeechDialogue(ChattedCount == 0));
             DeactivateChildren ();
             // this way the handler knowns when the text has finished animation - stops skipping to next line
             AddAnimationListener();
             //MyDialogueText.gameObject.GetComponent<SpeechAnimator> ().OnFinishedAnimationFunction.AddListener(UpdateRespondType);
             CanUpdateDialogue = false;
         }
         if (NewDialogue.ReverseDialogueLines.Count > 1)
             MyCharacter2.GetSpeechHandler().IsOptions = true;
         else
             MyCharacter2.GetSpeechHandler().IsOptions = false;
     }
 }
Exemplo n.º 6
0
		// handles the various setups for responses
		private void UpdateRespondType(DialogueLine NewDialogue) {
			DeactivateChildren ();

			if (NewDialogue.ReverseDialogueLines.Count <= 1) 
			{
				MyDialogueText.gameObject.transform.FindChild("NextButton").gameObject.SetActive(true);
			}
			else
			{
				for (int i = 0; i < NewDialogue.ReverseDialogueLines.Count; i++) {
					Transform MyResponseTransform = MyDialogueText.gameObject.transform.FindChild("Option"+(i+1));
					if (MyResponseTransform) {
						MyResponseTransform.gameObject.SetActive(true);
						MyResponseTransform.gameObject.transform.GetChild(0).gameObject.GetComponent<Text>().text =
																				NewDialogue.ReverseDialogueLines[i];
					}
				}
			}
			CanUpdateDialogue = true;
		}
Exemplo n.º 7
0
        private IEnumerator DialogueSequence()
        {
            Scene currentScene = SceneManager.GetActiveScene();

            for (int i = 0; i < transform.childCount; i++)
            {
                //Checks if there is a current dialogue line
                if (currentLine != null)
                {
                    previousLine = currentLine;
                    if (transform.GetChild(i).GetComponent <DialogueLine>())
                    {
                        currentLine = transform.GetChild(i).GetComponent <DialogueLine>();
                    }
                }
                else
                {
                    if (transform.GetChild(i).GetComponent <DialogueLine>())
                    {
                        currentLine = transform.GetChild(i).GetComponent <DialogueLine>();
                    }
                }

                //Checks if there is a saved dialogue line
                if (savedLine != null)
                {
                    //Checks if the saved dialogue line is in the same textbox as the current dialogue line
                    if (savedLine.textBox1 && currentLine.textBox1 || savedLine.textBox2 && currentLine.textBox2)
                    {
                        savedLine.gameObject.SetActive(false);
                        transform.GetChild(i).gameObject.SetActive(true);
                    }
                }

                //Checks if there is a previous dialogue line
                if (previousLine != null)
                {
                    //Checks if the previous dialogue line is in the textbox opposite of the current dialogue line
                    if (previousLine.textBox1 && currentLine.textBox2 || previousLine.textBox2 && currentLine.textBox1)
                    {
                        transform.GetChild(i).gameObject.SetActive(true);
                        savedLine = previousLine;
                    }
                    else
                    {
                        Deactivate();
                        transform.GetChild(i).gameObject.SetActive(true);
                    }
                }
                else
                {
                    Deactivate();
                    transform.GetChild(i).gameObject.SetActive(true);
                }

                //Checks if it's a transition line, which changes the scene
                if (transform.GetChild(i).GetComponent <TransitionLine>() == true)
                {
                    transform.GetChild(i).GetComponent <TransitionLine>().ChangeScene();
                    break;
                }

                //Checks if it's an ImageLine, which displays an image on the screen
                if (transform.GetChild(i).GetComponent <ImageLine>() == true)
                {
                    transform.GetChild(i).GetComponent <ImageLine>().DisplayImage();
                }

                //Checks which Dialogue Box to place the dialogue in
                else if (transform.GetChild(i).GetComponent <DialogueLine>().textBox1 == true)
                {
                    transform.GetChild(i).GetComponent <RectTransform>().anchoredPosition = box1;
                }
                else if (transform.GetChild(i).GetComponent <DialogueLine>().textBox2 == true)
                {
                    transform.GetChild(i).GetComponent <RectTransform>().anchoredPosition = box2;
                }

                if (transform.GetChild(i).GetComponent <DialogueLine>())
                {
                    yield return(new WaitUntil(() => transform.GetChild(i).GetComponent <DialogueLine>().finished));
                }

                if (currentLine.GetComponent <DialogueLine>().textBox1)
                {
                    dialogueCursorTop.SetActive(true);
                }
                else if (currentLine.GetComponent <DialogueLine>().textBox2)
                {
                    dialogueCursorBot.SetActive(true);
                }

                buttonPressed = false;
                yield return(new WaitUntil(() => buttonPressed == true));

                //Hides any images that may be currently active
                if (transform.GetChild(i).GetComponent <ImageLine>())
                {
                    transform.GetChild(i).gameObject.SetActive(false);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Shows the dialogue text, aligns text according the speaker if needed and changes color.
        /// </summary>
        /// <param name="dl">Dialogue line to be shown.</param>
        private void SetDialogueWindow(DialogueLine dl)
        {
            dialogueText.text = dl.dialogueText;

            if (!alignTextToSpeakerSide)
            {
                dialogueText.alignment = TextAnchor.UpperLeft;
            }

            if (applySpeakerColorToDialogueLine)
            {
                dialogueText.color = dl.speaker.dialogueColor;
            }
            else
            {
                dialogueText.color = Color.white;
            }

            //we want to make sure the text size container will be calculated for our text
            LayoutRebuilder.ForceRebuildLayoutImmediate(dialogueText.rectTransform);

            //shows or hides speakers in the dialogue, changes their color and text anchor
            if (currentDialogue.actorsOnTheLeft.Contains(dl.speaker))
            {
                if (alignTextToSpeakerSide)
                {
                    dialogueText.alignment = TextAnchor.UpperLeft;
                }

                leftSpeakerImage.sprite = dl.speaker.image;
                leftSpeakerName.text    = dl.speaker.actorName;
                leftSpeakerName.color   = dl.speaker.dialogueColor;

                if (!showBothSpeakersAllTheTime)
                {
                    leftSpeakerImage.gameObject.SetActive(true);
                    leftSpeakerName.gameObject.SetActive(true);

                    rightSpeakerImage.gameObject.SetActive(false);
                    rightSpeakerName.gameObject.SetActive(false);
                }
            }
            else if (currentDialogue.actorsOnTheRight.Contains(dl.speaker))
            {
                if (alignTextToSpeakerSide)
                {
                    dialogueText.alignment = TextAnchor.UpperRight;
                }

                rightSpeakerImage.sprite = dl.speaker.image;
                rightSpeakerName.text    = dl.speaker.actorName;
                rightSpeakerName.color   = dl.speaker.dialogueColor;

                if (!showBothSpeakersAllTheTime)
                {
                    leftSpeakerImage.gameObject.SetActive(false);
                    leftSpeakerName.gameObject.SetActive(false);
                    rightSpeakerImage.gameObject.SetActive(true);
                    rightSpeakerName.gameObject.SetActive(true);
                }
            }
            else
            {
                if (alignNonSideSpeakerToCenter)
                {
                    dialogueText.alignment = TextAnchor.UpperCenter;
                }

                if (!showBothSpeakersAllTheTime)
                {
                    leftSpeakerImage.gameObject.SetActive(false);
                    leftSpeakerName.gameObject.SetActive(false);
                    rightSpeakerImage.gameObject.SetActive(false);
                    rightSpeakerName.gameObject.SetActive(false);
                }
            }

            //stop audio sound if there is any
            if (_dialogueAudioSource.isPlaying)
            {
                _dialogueAudioSource.Stop();
            }

            //play audio if there is any
            if (dl.audio != null)
            {
                _dialogueAudioSource.clip = dl.audio;
                _dialogueAudioSource.Play();
            }
        }