Exemplo n.º 1
0
        public void PressSelectedOption()
        {
            if (m_state != eState.Idle)
            {
                return;
            }
            if (m_currentSelectedIndex < 0)
            {
                return;
            }
            if (m_currentSelectedIndex >= m_uiOptions.Count)
            {
                return;
            }
            if (m_uiOptions.Count == 0)
            {
                return;
            }

            UIConversationButton button = m_uiOptions[m_currentSelectedIndex];

            if (button.Speech != null)
            {
                ConversationManager.Instance.DoSpeech(button.Speech);
            }
            else
            {
                ConversationManager.Instance.OptionSelected(button.Option);
            }
        }
Exemplo n.º 2
0
        private UIConversationButton CreateButton()
        {
            UIConversationButton button = GameObject.Instantiate(ButtonPrefab, OptionsPanel);

            m_uiOptions.Add(button);
            return(button);
        }
Exemplo n.º 3
0
        private void CreateUIOptions()
        {
            // Display new options
            if (m_currentSpeech.ConnectionType == Connection.eConnectionType.Option)
            {
                for (int i = 0; i < m_currentSpeech.Connections.Count; i++)
                {
                    OptionConnection connection = m_currentSpeech.Connections[i] as OptionConnection;
                    if (ConditionsMet(connection))
                    {
                        UIConversationButton uiOption = CreateButton();
                        uiOption.SetupButton(UIConversationButton.eButtonType.Option, connection.OptionNode);
                    }
                }
            }
            // Display Continue/End options
            else
            {
                bool notAutoAdvance             = !m_currentSpeech.AutomaticallyAdvance;
                bool allowVisibleOptionWithAuto = (m_currentSpeech.AutomaticallyAdvance && m_currentSpeech.AutoAdvanceShouldDisplayOption);

                if (notAutoAdvance || allowVisibleOptionWithAuto)
                {
                    if (m_currentSpeech.ConnectionType == Connection.eConnectionType.Speech)
                    {
                        UIConversationButton uiOption = CreateButton();
                        SpeechNode           next     = GetValidSpeechOfNode(m_currentSpeech);

                        // If there was no valid speech node (due to no conditions being met) this becomes a None button type
                        if (next == null)
                        {
                            uiOption.SetupButton(UIConversationButton.eButtonType.End, null, endFont: m_conversation.EndConversationFont);
                        }
                        // Else, valid speech node found
                        else
                        {
                            uiOption.SetupButton(UIConversationButton.eButtonType.Speech, next, continueFont: m_conversation.ContinueFont);
                        }
                    }
                    else if (m_currentSpeech.ConnectionType == Connection.eConnectionType.None)
                    {
                        UIConversationButton uiOption = CreateButton();
                        uiOption.SetupButton(UIConversationButton.eButtonType.End, null, endFont: m_conversation.EndConversationFont);
                    }
                }
            }
            SetSelectedOption(0);

            // Set the button sprite and alpha
            for (int i = 0; i < m_uiOptions.Count; i++)
            {
                m_uiOptions[i].SetImage(OptionImage, OptionImageSliced);
                m_uiOptions[i].SetAlpha(0);
                m_uiOptions[i].gameObject.SetActive(false);
            }
        }
Exemplo n.º 4
0
        public void AlertHover(UIConversationButton button)
        {
            for (int i = 0; i < m_uiOptions.Count; i++)
            {
                if (m_uiOptions[i] == button && m_currentSelectedIndex != i)
                {
                    SetSelectedOption(i);
                    return;
                }
            }

            if (button == null)
            {
                UnselectOption();
            }
        }
Exemplo n.º 5
0
        public void PressSelectedOption()
        {
            if (m_state != eState.Idle)
            {
                return;
            }
            if (m_currentSelectedIndex < 0)
            {
                return;
            }
            if (m_currentSelectedIndex >= m_uiOptions.Count)
            {
                return;
            }
            if (m_uiOptions.Count == 0)
            {
                return;
            }

            UIConversationButton button = m_uiOptions[m_currentSelectedIndex];

            button.OnButtonPressed();
        }
Exemplo n.º 6
0
        //--------------------------------------
        // Do Speech
        //--------------------------------------

        public void DoSpeech(SpeechNode speech)
        {
            if (speech == null)
            {
                EndConversation();
                return;
            }

            m_currentSpeech = speech;

            // Clear current options
            ClearOptions();
            m_currentSelectedIndex = 0;

            // Set sprite
            if (speech.Icon == null)
            {
                NpcIcon.sprite = BlankSprite;
            }
            else
            {
                NpcIcon.sprite = speech.Icon;
            }

            // Set font
            if (speech.TMPFont != null)
            {
                DialogueText.font = speech.TMPFont;
            }
            else
            {
                DialogueText.font = null;
            }

            // Set name
            NameText.text = speech.Name;

            // Set text
            if (string.IsNullOrEmpty(speech.Text))
            {
                if (ScrollText)
                {
                    DialogueText.text                 = "";
                    m_targetScrollTextCount           = 0;
                    DialogueText.maxVisibleCharacters = 0;
                    m_elapsedScrollTime               = 0f;
                    m_scrollIndex = 0;
                }
                else
                {
                    DialogueText.text = "";
                    DialogueText.maxVisibleCharacters = 1;
                }
            }
            else
            {
                if (ScrollText)
                {
                    DialogueText.text                 = speech.Text;
                    m_targetScrollTextCount           = speech.Text.Length + 1;
                    DialogueText.maxVisibleCharacters = 0;
                    m_elapsedScrollTime               = 0f;
                    m_scrollIndex = 0;
                }
                else
                {
                    DialogueText.text = speech.Text;
                    DialogueText.maxVisibleCharacters = speech.Text.Length;
                }
            }


            // Call the event
            if (speech.Event != null)
            {
                speech.Event.Invoke();
            }

            // Play the audio
            if (speech.Audio != null)
            {
                AudioPlayer.clip   = speech.Audio;
                AudioPlayer.volume = speech.Volume;
                AudioPlayer.Play();
            }

            // Display new options
            if (speech.Options.Count > 0)
            {
                for (int i = 0; i < speech.Options.Count; i++)
                {
                    UIConversationButton option = GameObject.Instantiate(ButtonPrefab, OptionsPanel);
                    option.InitButton(speech.Options[i]);
                    option.SetOption(speech.Options[i]);
                    m_uiOptions.Add(option);
                }
            }
            else
            {
                // Display "Continue" / "End" if we should.
                bool notAutoAdvance = !speech.AutomaticallyAdvance;
                bool autoWithOption = (speech.AutomaticallyAdvance && speech.AutoAdvanceShouldDisplayOption);
                if (notAutoAdvance || autoWithOption)
                {
                    // Else display "continue" button to go to following dialogue
                    if (speech.Dialogue != null)
                    {
                        UIConversationButton option = GameObject.Instantiate(ButtonPrefab, OptionsPanel);
                        option.SetFollowingAction(speech.Dialogue);
                        m_uiOptions.Add(option);
                    }
                    // Else display "end" button
                    else
                    {
                        UIConversationButton option = GameObject.Instantiate(ButtonPrefab, OptionsPanel);
                        option.SetAsEndConversation();
                        m_uiOptions.Add(option);
                    }
                }
            }
            SetSelectedOption(0);

            // Set the button sprite and alpha
            for (int i = 0; i < m_uiOptions.Count; i++)
            {
                m_uiOptions[i].SetImage(OptionImage, OptionImageSliced);
                m_uiOptions[i].SetAlpha(0);
                m_uiOptions[i].gameObject.SetActive(false);
            }

            SetState(eState.ScrollingText);
        }
Exemplo n.º 7
0
        //--------------------------------------
        // Do Speech
        //--------------------------------------

        public void DoSpeech(SpeechNode speech)
        {
            if (speech == null)
            {
                EndConversation();
                return;
            }

            m_currentSpeech = speech;

            // Clear current options
            ClearOptions();
            m_currentSelectedIndex = -1;

            // Set sprite
            if (speech.Icon == null)
            {
                NpcIcon.sprite = BlankSprite;
            }
            else
            {
                NpcIcon.sprite = speech.Icon;
            }

            // Set font
            if (speech.TMPFont != null)
            {
                DialogueText.font = speech.TMPFont;
            }
            else
            {
                DialogueText.font = null;
            }

            // Set name
            NameText.text = speech.Name;

            // Set text
            if (string.IsNullOrEmpty(speech.Text))
            {
                if (ScrollText)
                {
                    DialogueText.text                 = "";
                    m_targetScrollTextCount           = 0;
                    DialogueText.maxVisibleCharacters = 0;
                    m_elapsedScrollTime               = 0f;
                    m_scrollIndex = 0;
                }
                else
                {
                    DialogueText.text = "";
                    DialogueText.maxVisibleCharacters = 1;
                }
            }
            else
            {
                if (ScrollText)
                {
                    DialogueText.text                 = speech.Text;
                    m_targetScrollTextCount           = speech.Text.Length + 1;
                    DialogueText.maxVisibleCharacters = 0;
                    m_elapsedScrollTime               = 0f;
                    m_scrollIndex = 0;
                }
                else
                {
                    DialogueText.text = speech.Text;
                    DialogueText.maxVisibleCharacters = speech.Text.Length;
                }
                //if (Backlog != null)
                //{
                //    Backlog.text += speech.Name + ":\n" + speech.Text + "\n\n";
                //}
            }


            // Call the event
            //speech.Event?.Invoke();

            // Play the audio
            if (speech.Audio != null)
            {
                AudioPlayer.clip   = speech.Audio;
                AudioPlayer.volume = speech.Volume;
                AudioPlayer.Play();
            }

            // Display new options
            if (speech.Options.Count > 0)
            {
                //StartCoroutine(ShrinkDialogue());

                // Decrease spacing when many options are present to prevent options being too small
                var layout = OptionsPanel.GetComponent <VerticalLayoutGroup>();
                if (speech.Options.Count > 3)
                {
                    layout.spacing = 10;
                }
                else
                {
                    layout.spacing = 20;
                }

                for (int i = 0; i < speech.Options.Count; i++)
                {
                    UIConversationButton option = GameObject.Instantiate(ButtonPrefab, OptionsPanel);
                    option.InitButton(speech.Options[i]);
                    option.SetOption(speech.Options[i]);
                    m_uiOptions.Add(option);
                }
            }
            else
            {
                //StartCoroutine(ExpandDialogue());
                // Display "Continue" / "End" if we should.
                //bool notAutoAdvance = !speech.AutomaticallyAdvance;
                bool autoWithOption = (speech.AutomaticallyAdvance && speech.AutoAdvanceShouldDisplayOption);
                if (autoWithOption)
                {
                    // Else display "continue" button to go to following dialogue
                    if (speech.Dialogue != null)
                    {
                        UIConversationButton option = GameObject.Instantiate(ButtonPrefab, OptionsPanel);
                        option.SetFollowingAction(speech.Dialogue);
                        m_uiOptions.Add(option);
                    }
                    // Else display "end" button
                    else
                    {
                        UIConversationButton option = GameObject.Instantiate(ButtonPrefab, OptionsPanel);
                        option.SetAsEndConversation();
                        m_uiOptions.Add(option);
                    }
                }
            }
            // Auto select first option
            // SetSelectedOption(0);

            // Set the button sprite and alpha
            for (int i = 0; i < m_uiOptions.Count; i++)
            {
                m_uiOptions[i].SetImage(OptionImage, OptionImageSliced);
                m_uiOptions[i].SetAlpha(0);
                m_uiOptions[i].gameObject.SetActive(false);
            }

            SetState(eState.ScrollingText);
        }