Exemplo n.º 1
0
        public void Update()
        {
            if (Visible)
            {
                if (_scrolling)
                {
                    switch (Controller.GameOptions.TextSpeed)
                    {
                    case 0:
                        _scrollValue += Border.SCALE * 2;
                        break;

                    case 1:
                        _scrollValue += Border.SCALE * 1.5f;
                        break;

                    case 2:
                        _scrollValue += Border.SCALE;
                        break;
                    }
                    if (_scrollValue >= Border.UNIT * 2 * Border.SCALE)
                    {
                        _scrolling   = false;
                        _scrollValue = 0f;
                        _lineIndex++;
                        // reset char index so it only shows the now first line
                        var lines = _text[_textIndex];
                        var line1 = lines[_lineIndex];
                        _charIndex = line1.Length;
                    }
                }
                else
                {
                    var lines = _text[_textIndex];

                    if (_charDelay > 0)
                    {
                        _charDelay--;
                        if (_charDelay == 0)
                        {
                            _charDelay = 0;
                        }
                    }
                    else
                    {
                        if (GameboyInputs.ADown() || GameboyInputs.BDown())
                        {
                            _charDelay = 0;
                        }
                        else
                        {
                            switch (Controller.GameOptions.TextSpeed)
                            {
                            case 0:
                                _charDelay = CHARDELAY_FAST;
                                break;

                            case 1:
                                _charDelay = CHARDELAY_MID;
                                break;

                            case 2:
                                _charDelay = CHARDELAY_SLOW;
                                break;
                            }
                        }
                        var line1 = lines[_lineIndex];
                        if (_charIndex < line1.Length)
                        {
                            // skip escape char
                            if (_charIndex + 2 < line1.Length && line1[_charIndex] == PokemonFontRenderer.ESCAPE_CHAR)
                            {
                                _charIndex += 3;
                            }
                            else
                            {
                                _charIndex++;
                            }
                        }
                        else
                        {
                            if (lines.Length > _lineIndex + 1)
                            {
                                var line2      = lines[_lineIndex + 1];
                                var line2Index = _charIndex - line1.Length;
                                if (line2Index < line2.Length)
                                {
                                    // skip escape char
                                    if (line2Index + 2 < line2.Length && line2[line2Index] == PokemonFontRenderer.ESCAPE_CHAR)
                                    {
                                        _charIndex += 3;
                                    }
                                    else
                                    {
                                        _charIndex++;
                                    }
                                }
                            }
                        }
                    }

                    if (CanAdvance())
                    {
                        if (!_firedFinished && IsFinished)
                        {
                            Finished?.Invoke();
                            _firedFinished = true;
                        }

                        if (_arrowBlinkingDelay > 0)
                        {
                            _arrowBlinkingDelay--;
                            if (_arrowBlinkingDelay == 0)
                            {
                                _arrowBlinkingDelay = ARROW_BLINK_DELAY;
                                _arrowVisible       = !_arrowVisible;
                            }
                        }

                        if (GameboyInputs.APressed() || GameboyInputs.BPressed())
                        {
                            // scroll or show next text block
                            if (lines.Length > _lineIndex + 2)
                            {
                                _scrolling = true;
                            }
                            else
                            {
                                // close textbox when through all text
                                if (_textIndex == _text.Length - 1)
                                {
                                    Close();
                                }
                                else
                                {
                                    _textIndex++;
                                    _charIndex = 0;
                                    _lineIndex = 0;
                                    _charDelay = 4;
                                }
                            }
                        }
                    }
                }
            }
        }