Esempio n. 1
0
    static public DialogueTextSettings Load(Dictionary <string, object> JSON, DialogueTextSettings defaults = null)
    {
        DialogueTextSettings newObject;

        if (defaults == null)
        {
            newObject = new DialogueTextSettings();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueTextSettings;
        }

        if (JSON.ContainsKey("textSpeed"))
        {
            newObject.textSpeed = float.Parse(JSON["textSpeed"].ToString());
        }
        if (JSON.ContainsKey("textPitch"))
        {
            newObject.textPitch = float.Parse(JSON["textPitch"].ToString());
        }

        if (JSON.ContainsKey("textPitchVariation"))
        {
            newObject.textPitchVariation = float.Parse(JSON["textPitchVariation"].ToString());
        }
        if (JSON.ContainsKey("textAudio"))
        {
            newObject.textAudio = JSON["textAudio"] as string;
        }

        return(newObject);
    }
Esempio n. 2
0
    public Sprite largePortrait; // TODO: Animation?

    public static DialogueNPCSettings Load(Dictionary <string, object> JSON, DialogueNPCSettings defaults = null)
    {
        DialogueNPCSettings newObject;

        if (defaults == null)
        {
            newObject = new DialogueNPCSettings();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueNPCSettings;
        }

        if (JSON.ContainsKey("id"))
        {
            newObject.id = JSON["id"] as string;
        }

        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, newObject.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, newObject.textSettings);
        }

        return(newObject);
    }
Esempio n. 3
0
    public void Merge(DialogueTextSettings _toMerge)
    {
        if (_toMerge.textSpeed != 0)
        {
            textSpeed = _toMerge.textSpeed;
        }
        if (_toMerge.textPitch != 0)
        {
            textPitch = _toMerge.textPitch;
        }
        if (_toMerge.textPitchVariation != 0)
        {
            textPitchVariation = _toMerge.textPitchVariation;
        }
        if (_toMerge.textAudio != null)
        {
            textAudio = _toMerge.textAudio;
        }
        if (_toMerge.textAudioMaxSpeed != 0)
        {
            textAudioMaxSpeed = _toMerge.textAudioMaxSpeed;
        }

        for (int i = 0; i < _toMerge.textSymbolTime.Count; ++i)
        {
            if (!textSymbolTime.Contains(_toMerge.textSymbolTime[i]))
            {
                textSymbolTime.Add(_toMerge.textSymbolTime[i]);
            }
        }
    }
Esempio n. 4
0
    public static DialogueSection Load(Dictionary <string, object> JSON, DialogueSection defaults = null)
    {
        DialogueSection newObject;

        if (defaults == null)
        {
            newObject = new DialogueSection();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueSection;
        }

        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, defaults.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, defaults.textSettings);
        }

        if (JSON.ContainsKey("triggerAnimation"))
        {
            newObject.triggerAnimation = JSON["triggerAnimation"] as string;
        }
        if (JSON.ContainsKey("triggerEffect"))
        {
            newObject.triggerEffect = JSON["triggerEffect"] as string;
        }
        if (JSON.ContainsKey("forceIdle"))
        {
            newObject.forceIdle = bool.Parse(JSON["forceIdle"] as string);
        }

        if (JSON.ContainsKey("text"))
        {
            newObject.text = new StringBuilder(JSON["text"] as string);
        }

        if (newObject.portraitSettings == null)
        {
            Debug.LogError("portraitSettings is null in DialogueSection");
        }
        if (newObject.textSettings == null)
        {
            Debug.LogError("textSettings is null in DialogueSection");
        }

        return(newObject);
    }
Esempio n. 5
0
        // ********************************************************************
        private IEnumerator DisplaySection()
        {
            Debug.Log("Dispaying section " + m_sectionIndex + " out of " + m_currentFrame.sections.Count);

            // Initialize stuff for new section
            m_currentSection = m_currentFrame.sections[m_sectionIndex];
            m_displayIndex   = 0;

            LogManager.Log("DialoguePanel: DisplaySection " + m_currentSection.text,
                           LogCategory.UI,
                           LogSeverity.LOG,
                           "Dialogue",
                           gameObject);

            m_currentTextSettings = new DialogueTextSettings();
            m_currentTextSettings.Merge(m_currentFrame.character.textSettings);
            m_currentTextSettings.Merge(m_currentSection.textSettings);


            Dictionary <char, float> textSymbolTime = new Dictionary <char, float>();

            // Get settings from character
            for (int i = 0; i < m_currentTextSettings.textSymbolTime.Count; ++i)
            {
                textSymbolTime[m_currentTextSettings.textSymbolTime[i].symbol] = m_currentTextSettings.textSymbolTime[i].time;
            }

            // Print text until we're done
            if (m_currentSection.text != null)
            {
                float textSpeed     = m_defaultTextSpeed * m_currentTextSettings.textSpeed;
                float secondsToWait = 1.0f / textSpeed;

                int    side           = -1;
                string currentSpecial = "";

                if (m_currentFrame.character.portrait != null)
                {
                    side = (int)m_currentFrame.portraitSide;
                    // Set portrait emotion
                    m_characterAnimator[side].SetInteger("Emotion", (int)m_currentSection.emotion);
                    // Set special animation triggers
                    if (m_currentSection.triggerAnimation > 0)
                    {
                        currentSpecial = "Special-" + m_currentSection.triggerAnimation;
                        m_characterAnimator[side].SetTrigger("Special-" + m_currentSection.triggerAnimation);
                    }
                    else
                    {
                        // Set portrait to talking animation ONLY if no special animation is playing.
                        m_characterAnimator[side].SetBool("Talk", true);
                    }
                }

                while (m_displayIndex < m_currentSection.text.Length)
                {
                    char  currentChar          = m_currentSection.text[m_displayIndex];
                    float currentSecondsToWait = secondsToWait;
                    if (textSymbolTime.ContainsKey(currentChar))
                    {
                        currentSecondsToWait = textSymbolTime[currentChar];
                    }

                    // if we were playing a special animation, see if it is time to start the talk animation
                    if (!currentSpecial.NullOrEmpty())
                    {
                        if (!m_characterAnimator[side].GetCurrentAnimatorStateInfo(1).IsName(currentSpecial))
                        {
                            currentSpecial = "";
                            m_characterAnimator[side].SetBool("Talk", true);
                        }
                    }

                    PrintText();
                    if (!m_shouldSkip)
                    {
                        yield return(new WaitForSeconds(currentSecondsToWait));
                    }
                }

                // Set portrait to idle animation
                if (m_currentFrame.character.portrait != null)
                {
                    side = (int)m_currentFrame.portraitSide;
                    m_characterAnimator[side].SetBool("Talk", false);
                }
            }

            // TODO: Wait for animation to finish if we triggered a special animation.

            // TODO: Some kind of manual "wait" system? (for cutscenes)

            // Load next section
            m_previousSections += m_currentSection.text;
            ++m_sectionIndex;
            if (m_sectionIndex < m_currentFrame.sections.Count)
            {
                StartCoroutine(DisplaySection());
            }
            else
            {
                m_shouldSkip = false;

                if (m_currentFrame.displayChoices)
                {
                    m_waitingForChoiceInput = true;

                    List <int> validLinks = new List <int>();
                    for (int i = 0; i < m_currentFrame.links.Count; ++i)
                    {
                        if (m_currentFrame.links[i].MeetsConditions())
                        {
                            validLinks.Add(i);
                        }
                    }
                    //Debug.Log("Choices found for frame " + m_currentFrame.id + ": " + validLinks.Count);
                    for (int i = 0; i < validLinks.Count; ++i)
                    {
                        int          index = validLinks[i];
                        DialogueLink link  = m_currentFrame.links[index];
                        //Debug.Log("Creating button for " + index + " link frame: " + link.linkedFrame.name);
                        GameObject choiceButton = GameObject.Instantiate(m_choiceButtonPrototype) as GameObject;
                        choiceButton.transform.SetParent(m_choiceRoot.transform);
                        if (i == 0 && InputManager.controlScheme == ControlScheme.GAMEPAD)
                        {
                            firstSelected = choiceButton.GetComponentInChildren <Button>();
                            SelectButton(firstSelected);
                        }

                        // Setup button
                        ButtonSetup setup = choiceButton.GetComponent <ButtonSetup>();
                        setup.SetText(link.text);
                        setup.SetIcon(link.icon);
                        if (link.animation)
                        {
                            setup.SetAnimation(link.animation);
                        }
                        AddListenerForChoice(choiceButton.transform.GetComponentInChildren <Button>(), link);
                        m_choices.Add(choiceButton.GetComponent <Animator>());
                    }

                    StartCoroutine(ShowChoices(true));
                }
                else
                {
                    LogManager.Log("DialoguePanel: Setting m_waitingForNextFrame = true for " + m_currentFrame,
                                   LogCategory.UI,
                                   LogSeverity.LOG,
                                   "Dialogue",
                                   gameObject);
                    m_waitingForNextFrame = true;
                    m_waitingIcon.SetActive(true);
                }
            }

            yield return(null);
        }
Esempio n. 6
0
    public static DialogueFrame Load(Dictionary <string, object> JSON, DialogueFrame defaults = null)
    {
        DialogueFrame newObject;

        if (defaults == null)
        {
            newObject = new DialogueFrame();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueFrame;
        }

        if (JSON.ContainsKey("id"))
        {
            newObject.id = JSON["id"] as string;
        }

        // Links
        if (JSON.ContainsKey("endOnThisFrame"))
        {
            newObject.endOnThisFrame = bool.Parse(JSON["endOnThisFrame"].ToString());
        }
        if (JSON.ContainsKey("displayChoices"))
        {
            newObject.displayChoices = bool.Parse(JSON["displayChoices"].ToString());
        }
        if (JSON.ContainsKey("links"))
        {
            newObject.links = new List <DialogueLink>();
            List <object> lList = JSON["links"] as List <object>;
            foreach (object lEntry in lList)
            {
                DialogueLink newLink = DialogueLink.Load(lEntry as Dictionary <string, object>);
                newObject.links.Add(newLink);
            }
        }

        // Load NPC Settings
        if (JSON.ContainsKey("npcSettings"))
        {
            DialogueNPCSettings npcSettings = DialogueManager.FetchNPCSettings(JSON["npcSettings"] as string);

            if (npcSettings != null)
            {
                Debug.Log("NPC Settings fetched for: " + JSON["npcSettings"] + " - " + npcSettings);
                if (npcSettings.portraitSettings != null)
                {
                    newObject.portraitSettings = npcSettings.portraitSettings.ShallowCopy();
                }
                if (npcSettings.textSettings != null)
                {
                    newObject.textSettings = npcSettings.textSettings.ShallowCopy();
                }
            }
            else
            {
                Debug.LogError("NPC Settings NOT FOUND for: " + JSON["npcSettings"]);
            }
        }

        // Overrides
        if (JSON.ContainsKey("allowSkip"))
        {
            newObject.allowSkip = bool.Parse(JSON["allowSkip"] as string);
        }
        if (JSON.ContainsKey("waitForInput"))
        {
            newObject.waitForInput = bool.Parse(JSON["waitForInput"] as string);
        }
        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, newObject.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, newObject.textSettings);
        }

        // Sections
        if (JSON.ContainsKey("sections"))
        {
            newObject.sections = new List <DialogueSection>();
            DialogueSection defaultSection = new DialogueSection();
            defaultSection.portraitSettings = newObject.portraitSettings;
            defaultSection.textSettings     = newObject.textSettings;
            List <object> sList = JSON["sections"] as List <object>;
            foreach (object sEntry in sList)
            {
                DialogueSection newSection = DialogueSection.Load(sEntry as Dictionary <string, object>, defaultSection);
                newObject.sections.Add(newSection);
            }
            Debug.Log("Frame " + newObject.id + " loaded " + newObject.sections.Count + " sections");
        }

        if (newObject.portraitSettings == null)
        {
            Debug.LogError("portraitSettings is null in DialogueFrame");
        }
        if (newObject.textSettings == null)
        {
            Debug.LogError("textSettings is null in DialogueFrame");
        }

        return(newObject);
    }
Esempio n. 7
0
    // ********************************************************************
    // Function:	DisplaySection()
    // Purpose:		Performs actions described in a section
    // ********************************************************************
    private IEnumerator DisplaySection()
    {
        // Initialize stuff for new section
        m_currentSection = m_currentFrame.sections[m_sectionIndex];
        m_displayIndex   = 0;

        // Set text settings
        DialogueTextSettings textSettings = m_currentSection.textSettings;

        if (textSettings.textAudio != m_audioClipName)
        {
            m_audioClipName    = textSettings.textAudio;
            m_audioClip        = Resources.Load(m_audioClipPath + m_audioClipName) as AudioClip;
            m_audioSource.clip = m_audioClip;
        }

        // TODO: Set portrait settings

        PrintText();

        // Print text until we're done
        if (m_currentSection.text != null)
        {
            float textSpeed     = m_defaultTextSpeed * textSettings.textSpeed;
            float secondsToWait = 1.0f / textSpeed;
            while (m_displayIndex < m_currentSection.text.Length)
            {
                if (!m_shouldSkip)
                {
                    yield return(new WaitForSeconds(secondsToWait));
                }
                //yield return new WaitForSeconds(1.0f / (m_defaultTextSpeed*m_currentSection.textSettings.textSpeed));
                PrintText();
            }
        }

        // TODO: Trigger special animations and effects
        // TODO: Wait for animation to finish if we triggered a special animation.

        // TODO: Some kind of manual "wait" system? (for cutscenes)

        // Load next section
        ++m_sectionIndex;
        if (m_sectionIndex < m_currentFrame.sections.Count)
        {
            StartCoroutine(DisplaySection());
        }
        else
        {
            // TODO: Bring up choices if applicable
            m_shouldSkip = false;

            if (m_currentFrame.displayChoices)
            {
                m_waitingForChoiceInput = true;

                List <int> validLinks = new List <int>();
                for (int i = 0; i < m_currentFrame.links.Count; ++i)
                {
                    if (m_currentFrame.links[i].MeetsRequirements(ProfileManager.profile))
                    {
                        validLinks.Add(i);
                    }
                }
                Debug.Log("Choices found for frame " + m_currentFrame.id + ": " + validLinks.Count);
                for (int i = 0; i < validLinks.Count; ++i)
                {
                    int          index = validLinks[i];
                    DialogueLink link  = m_currentFrame.links[index];
                    Debug.Log("Creating button for " + index + " link conv: " + link.linkedConversation + " frame: " + link.linkedFrame);
                    GameObject choiceButton = GameObject.Instantiate(m_choiceButtonPrototype) as GameObject;
                    choiceButton.transform.SetParent(m_choiceRoot.transform);
                    choiceButton.GetComponentInChildren <Text>().text = link.text;
                    AddListenerForChoice(choiceButton.GetComponent <Button>(), index);
                    m_choices.Add(choiceButton.GetComponent <Animator>());
                }

                StartCoroutine(HideChoices(false));
            }
            else
            {
                m_waitingForNextFrame = true;
                m_waitingIcon.SetActive(true);
            }
        }

        yield return(null);
    }
Esempio n. 8
0
    public static DialogueConversation Load(Dictionary <string, object> JSON, DialogueConversation defaults = null)
    {
        DialogueConversation newObject;

        if (defaults == null)
        {
            newObject = new DialogueConversation();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueConversation;
        }

        if (JSON.ContainsKey("id"))
        {
            newObject.id = JSON["id"] as string;
        }
        if (JSON.ContainsKey("autoload"))
        {
            newObject.autoload = bool.Parse(JSON["autoload"].ToString());
        }

        // Defaults
        if (JSON.ContainsKey("allowSkip"))
        {
            newObject.allowSkip = bool.Parse(JSON["allowSkip"].ToString());
        }
        if (JSON.ContainsKey("waitForInput"))
        {
            newObject.waitForInput = bool.Parse(JSON["waitForInput"].ToString());
        }
        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, newObject.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, newObject.textSettings);
        }

        // Requirements
        if (JSON.ContainsKey("requirements"))
        {
            newObject.requirements = new List <DialogueRequirement>();
            List <object> rList = JSON["requirements"] as List <object>;
            foreach (object rEntry in rList)
            {
                DialogueRequirement newRequirement = DialogueRequirement.Load(rEntry as Dictionary <string, object>);
                newObject.requirements.Add(newRequirement);
            }
        }

        // Frames
        if (JSON.ContainsKey("startingFrame"))
        {
            newObject.startingFrame = JSON["startingFrame"] as string;
        }
        if (JSON.ContainsKey("frames"))
        {
            newObject.frames = new Dictionary <string, DialogueFrame>();

            DialogueFrame defaultFrame = new DialogueFrame();
            defaultFrame.portraitSettings = newObject.portraitSettings;
            defaultFrame.textSettings     = newObject.textSettings;
            defaultFrame.allowSkip        = newObject.allowSkip;
            defaultFrame.waitForInput     = newObject.waitForInput;

            DialogueFrame lastFrame           = null;
            bool          lastFrameLinkNeeded = false;

            List <object> fList = JSON["frames"] as List <object>;
            foreach (object fEntry in fList)
            {
                DialogueFrame newFrame = DialogueFrame.Load(fEntry as Dictionary <string, object>, defaultFrame);
                newObject.frames[newFrame.id] = newFrame;

                if (lastFrameLinkNeeded)
                {
                    DialogueLink link = new DialogueLink();
                    link.linkedFrame = newFrame.id;
                    lastFrame.links  = new List <DialogueLink>();
                    lastFrame.links.Add(link);
                    Debug.Log("Frame " + lastFrame.id + " linked to frame " + newFrame.id);
                }

                lastFrameLinkNeeded = (!newFrame.endOnThisFrame && (newFrame.links == null || newFrame.links.Count == 0));
                lastFrame           = newFrame;

                if (newObject.startingFrame == null || newObject.startingFrame == "")
                {
                    newObject.startingFrame = newFrame.id;
                }
            }

            if (lastFrameLinkNeeded)
            {
                lastFrame.endOnThisFrame = true;
            }
            Debug.Log("Conversation " + newObject.id + " loaded " + newObject.frames.Count + " frames");
            Debug.Log("Starting frame: " + newObject.startingFrame);
        }

        if (newObject.portraitSettings == null)
        {
            Debug.LogError("portraitSettings is null in DialogueConversation");
        }
        if (newObject.textSettings == null)
        {
            Debug.LogError("textSettings is null in DialogueConversation");
        }

        return(newObject);
    }