Exemple #1
0
        protected override void OnUpdate(float dt)
        {
            base.OnUpdate(dt);
            if (IsOpen)
            {
                switch (m_state)
                {
                case State.Animating:
                {
                    if (CheckContinue())
                    {
                        // Skip animation
                        Title = m_characterName;
                        m_visibleCharacterName = m_characterName.Length;
                        if (m_modal)
                        {
                            m_visibleDialogueLines = Math.Min(m_dialogueLines.Length, m_firstLine + NUM_LINES);
                            m_visibleDialogueChars = 0;
                            if (m_visibleDialogueLines < m_dialogueLines.Length)
                            {
                                m_state = State.WaitingForMoreText;
                            }
                            else
                            {
                                m_state = State.WaitingForContinue;
                            }
                        }
                        else
                        {
                            m_visibleDialogueLines = m_dialogueLines.Length;
                            m_visibleDialogueChars = 0;
                            m_firstLine            = Math.Max(m_dialogueLines.Length - NUM_LINES, 0);
                            m_state = State.Finished;
                        }
                        RequestRebuild();
                        UpdatePrompt();
                    }
                    else
                    {
                        // Update animation
                        var charTime = 1.0f / TYPING_SPEED;
                        m_typeTimer -= dt;
                        while (m_typeTimer <= 0.0f)
                        {
                            if (m_visibleCharacterName < m_characterName.Length)
                            {
                                m_visibleCharacterName += Font.AdvanceGlyph(m_characterName, m_visibleCharacterName, true);
                                Title        = m_characterName.Substring(0, m_visibleCharacterName);
                                m_typeTimer += charTime;
                            }
                            else if (m_visibleDialogueLines < m_dialogueLines.Length)
                            {
                                var currentLine = m_dialogueLines[m_visibleDialogueLines];
                                m_visibleDialogueChars += Font.AdvanceGlyph(currentLine, m_visibleDialogueChars, true);
                                if (m_visibleDialogueChars >= currentLine.Length)
                                {
                                    m_visibleDialogueLines++;
                                    m_visibleDialogueChars = 0;
                                    if (m_visibleDialogueLines < m_dialogueLines.Length &&
                                        m_visibleDialogueLines >= m_firstLine + NUM_LINES)
                                    {
                                        if (m_modal)
                                        {
                                            m_state = State.WaitingForMoreText;
                                            UpdatePrompt();
                                        }
                                        else
                                        {
                                            m_firstLine++;
                                        }
                                    }
                                }
                                RequestRebuild();
                                m_typeTimer += charTime;
                            }
                            else
                            {
                                m_state = (m_modal ? State.WaitingForContinue : State.Finished);
                                UpdatePrompt();
                                break;
                            }
                        }
                    }
                    break;
                }

                case State.WaitingForMoreText:
                {
                    // Check for continue
                    if (CheckContinue())
                    {
                        TryContinue();
                    }
                    break;
                }

                case State.WaitingForContinue:
                {
                    // Check for continue
                    if (CheckContinue())
                    {
                        TryContinue();
                    }
                    break;
                }
                }
            }
        }