public void DisplayNextSentence()
    {
        previousSpeaker.GetComponent <Animator>().SetBool("isTalking", false);
        clickTimer = 0.3f;
        if (sentences.Count == 0)
        {
            EndDialogue();
            return;
        }

        //string sentence = sentences.Dequeue();
        sent sentence = sentences.Dequeue();

        if (sentence.whosays != oldsays)
        {
            GameObject whospeaks = GameObject.Find(sentence.whosays);
            nameText.color  = whospeaks.GetComponent <NPC>().nameColor;
            previousSpeaker = whospeaks;
            //previousSpeaker.GetComponent<Animator>().SetBool("isTalking", true);

            FindObjectOfType <GlobalDialogueManager>().ChangeCharacter(whospeaks);
        }



        //Vector3 bubblePos = new Vector3(speaker.transform.position.x, speaker.transform.position.y + 6.5f, speaker.transform.position.z);
        //GameObject dcp = Instantiate(DialogueCanvasPrefab, bubblePos, speaker.transform.rotation);
        //dcp.GetComponent<DialogueManager>().StartDialogue(Sentences, speaker);

        oldsays = sentence.whosays;
        StopAllCoroutines();
        //StartCoroutine(TypeSentence(sentence));
        StartCoroutine(TypeSentence(sentence));
    }
Example #2
0
 public static IEnumerable<sent> sentFromGroup(LMGroupSound snd) {
   //transformovana lmdata - zjisti lmdata XML s sentences
   Dictionary<string, XElement> sentsXml;
   if (transformedXml != null) {
     var xml = XElement.Parse(transformedXml);
     xml.Descendants().Select(el => el.Name = el.Name.LocalName).ToArray(); //odstran namespace
     sentsXml = xml.Descendants("sound_sentence").ToDictionary(s => s.AttributeValue("id"), s => s);
   } else
     sentsXml = new Dictionary<string, XElement>();
   //transformedXml = null;
   bool? isDialog = null; int sentOrder = 0;
   foreach (var interval in snd.Cast<LMGroupSound>()) {
     if (isDialog == true) throw new Exception("OLD NEW DATA ERROR: by hand operation needed for sound: more than 2 intervals in dialog");
     var oldEndPos = -1;
     string sid, gid, u; sent lastSent = null;
     interval.markers.getObjId(out sid, out gid, out u);
     yield return new sent() { url = "/" + u, sentOrder = sentOrder++, self = null, sentXml = new XElement("phrase", new XAttribute("beg-pos", "0"), new XAttribute("end-pos", "0")) };
     foreach (sound_sentence sent in interval) {
       LMScormLib.Marker mark = interval.markers[sent.markIdx];
       var res = new sent() { url = "/" + u, sentOrder = sentOrder++, self = sent };
       XElement xml = null;
       if (!string.IsNullOrEmpty(sent.id) && sentsXml.TryGetValue(sent.id, out xml)) {
         var desc = xml.DescendantNodes().ToArray();
         if (desc.Length == 0) xml = null;
         else if (desc.Length == 1 && desc[0] is XText && string.IsNullOrEmpty(((XText)desc[0]).Value.Trim(new char[] { '\r', '\n', '\t', ' ' }))) xml = null;
         if (xml != null) { //http://bt.langmaster.cz/com/edit_bug.aspx?id=2139: Obrázek uvnitř lm:sound_sentence má chybnou url aritmetiku
           foreach (var src in xml.Descendants("img").SelectMany(n => n.Attributes("src"))) {
             if (src.Value.StartsWith("~")) src.Value = src.Value.Substring(2).ToLower();
           }
         }
       }
       //dialog?
       res.replica = sent.myReplica();
       if (isDialog == null) isDialog = res.replica != null; else if (isDialog != (res.replica != null)) throw new Exception("OLD NEW DATA ERROR: by hand operation needed for sound: isDialog != (myRole!=null)");
       //ignoreSound
       //res.ignoreSound = getIgnoreSound(sent);
       //if (ignoreSound == null) ignoreSound = res.ignoreSound; else if (ignoreSound != res.ignoreSound) throw new Exception("ignoreSound != res.ignoreSound");
       var oldb = (int)(mark.Beg / 10000);
       if (lastSent != null) {
         oldb = (int)((oldEndPos + oldb) / 2);
         lastSent.sentXml.SetAttributeValue("end-pos", oldb.ToString());
       }
       oldEndPos = (int)(mark.End / 10000);
       res.sentXml = new XElement("phrase", new XAttribute("beg-pos", oldb.ToString()), new XAttribute("end-pos", oldEndPos.ToString()), xml == null ? (Object)mark.Title : xml.Nodes());
       lastSent = res;
       yield return res;
     }
   }
 } public static string transformedXml;
    //IEnumerator TypeSentence (string sentence)
    IEnumerator TypeSentence(sent sentence)
    {
        if (sentence.whatsays == "Not me! Hey, little kid, you do it.")
        {
            GameObject.Find("Baby").GetComponent <Animator>().Play("into");
            GameObject.Find("BarsBeginning").GetComponent <Animator>().Play("slide");
        }
        //previousSpeaker.GetComponent<Animator>().SetBool("isTalking", true);
        nameText.text     = sentence.whosays;
        dialogueText.text = "";
        int count = previousSpeaker.GetComponent <NPC>().voiceCount - 1;
        //foreach (char letter in sentence.ToCharArray())

        bool precommand = false;
        bool startc     = false;

        foreach (char letter in sentence.whatsays)
        {
            startc = false;
            if (letter == '{')
            {
                precommand = true;
            }
            if (letter == '@')
            {
                if (precommand == false)
                {
                    precommand = true;
                    startc     = true;
                }
            }
            if (!precommand)
            {
                dialogueText.text += letter;
            }
            if (letter == '@')
            {
                if (precommand == true && !startc)
                {
                    precommand = false;
                }
            }
            if (letter == '}')
            {
                precommand = false;
            }
        }
        int totalVisibleCharacters = dialogueText.textInfo.characterCount;
        int visibleCount           = 0;

        dialogueText.maxVisibleCharacters = 0;
        char[] letterArr = dialogueText.text.ToCharArray();

        //Checking how many lines
        dialogueText.ForceMeshUpdate();
        float lineCount = dialogueText.textInfo.lineCount - 3;

        if (lineCount < 0)
        {
            lineCount = 0;
        }

        //Resetting
        dialogueText.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(dialogueText.gameObject.GetComponent <RectTransform>().anchoredPosition.x, 5.699997f);
        upperBox.GetComponent <RectTransform>().anchoredPosition            = new Vector2(upperBox.GetComponent <RectTransform>().anchoredPosition.x, 39.1f);
        nameText.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(nameText.gameObject.GetComponent <RectTransform>().anchoredPosition.x, 110.2f);

        //Resizing
        dialogueText.gameObject.GetComponent <RectTransform>().anchoredPosition += new Vector2(0, 57.3f * lineCount);
        upperBox.GetComponent <RectTransform>().anchoredPosition            += new Vector2(0, 57.3f * lineCount);
        nameText.gameObject.GetComponent <RectTransform>().anchoredPosition += new Vector2(0, 57.3f * lineCount);

        foreach (char letter in sentence.whatsays)
        {
            if (letter == '+')
            {
                previousSpeaker.GetComponent <Animator>().SetBool("isTalking", false);
                DisplayNextSentence();
                break;
            }

            if (letter == '*')
            {
                command = !command;
                if (command == false)
                {
                    previousSpeaker.GetComponent <Animator>().Play(commandtext);
                    commandtext = "";
                }
            }

            if (letter == '{')
            {
                command = true;
            }

            if (letter == '}')
            {
                command = false;
                if (commandtext == "shake")
                {
                    //FindObjectOfType<CameraShake>().ShakeDefault();
                }
                if (commandtext.Length > 3)
                {
                    if (commandtext.Substring(0, 2) == "tp")
                    {
                        string coords = commandtext.Substring(3);
                        print(coords);
                        string x  = "";
                        string y  = "";
                        bool   yb = false;
                        foreach (char c in coords)
                        {
                            if (c == ',')
                            {
                                yb = true;
                            }
                            else
                            {
                                if (!yb)
                                {
                                    x += c;
                                }
                                if (yb)
                                {
                                    y += c;
                                }
                            }
                        }
                        previousSpeaker.transform.position = new Vector2(float.Parse(x), float.Parse(y));
                    }
                }

                if (commandtext.Length > 6)
                {
                    if (commandtext.Substring(0, 4) == "anim")
                    {
                        previousSpeaker.GetComponent <Animator>().Play(commandtext.Substring(5));
                    }
                }

                commandtext = "";
            }

            if (letter == '<')
            {
                tag = true;
            }

            if (letter == '@')
            {
                command = !command;
                if (command == false)
                {
                    yield return(new WaitForSeconds(float.Parse(commandtext)));

                    commandtext = "";
                }
            }

            if (letter == '#')
            {
                command = !command;
                if (command == false)
                {
                    previousSpeaker.GetComponent <NPC>().moveToX = float.Parse(commandtext);
                    previousSpeaker.GetComponent <Animator>().SetFloat("speed", 1);
                    commandtext = "";
                }
            }

            if (command == false)
            {
                if (letter != '*' && letter != '#' && letter != '@' && letter != '[' && letter != ']' && letter != '{' && letter != '}')
                {
                    if (!tag)
                    {
                        //if (tagtext != "")
                        //{
                        //    //dialogueText.text += tagtext;
                        //    tagtext = "";
                        //}

                        //New system thingy
                        visibleCount += 1;

                        dialogueText.maxVisibleCharacters = visibleCount;

                        count += 1;


                        //dialogueText.text += letter;
                        previousSpeaker.GetComponent <Animator>().SetBool("isTalking", true);
                        FindObjectOfType <GlobalDialogueManager>().dcp.GetComponentInChildren <Animator>().Play("DialogueBox_Open");
                    }
                }
            }
            if (command == true)
            {
                if (letter != '*' && letter != '#' && letter != '@' && letter != '{' && letter != '}')
                {
                    commandtext += letter;
                }
            }
            if (tag == true)
            {
                //tagtext += letter;
            }


            if (count == previousSpeaker.GetComponent <NPC>().voiceCount)
            {
                if (!command)
                {
                    try
                    {
                        audioManager.Play(previousSpeaker.name);
                    }
                    catch { }
                }
                count = 0;
            }

            if (!command && !tag)
            {
                yield return(new WaitForSeconds(0.02f));

                //wait more if punctuation
                if (letter == '.' || letter == '!')
                {
                    yield return(new WaitForSeconds(0.15f));
                }
            }
            if (letter == '>')
            {
                tag = false;
            }
        }
        previousSpeaker.GetComponent <Animator>().SetBool("isTalking", false);
    }
Example #4
0
 private static void say(string con, string who, string what)
 {
     sent b = new sent(); b.addsent(con, who, what); sayList.Add(b);
 }