Exemplo n.º 1
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetDimensions().ToRectangle();

            Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.White);

            if (focused)
            {
                PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                WriteAll(Main.GetInputText(Text));

                if (JustPressed(Keys.Escape))
                {
                    UnfocusTextBox();
                }

                if (JustPressed(Keys.Enter))
                {
                    ModState.SerializeModPack(Text);
                    SetText("");
                    Recalculate();
                    UnfocusTextBox();
                }

                if (JustPressed(Keys.Up))
                {
                    _cursor = 0;
                }

                if (JustPressed(Keys.Down))
                {
                    _cursor = Text.Length;
                }

                if (JustPressed(Keys.Left))
                {
                    CursorLeft();
                }

                if (JustPressed(Keys.Right))
                {
                    CursorRight();
                }

                if (JustPressed(Keys.Back))
                {
                    BackSpace();
                }

                if (!hitbox.Contains(Main.MouseScreen.ToPoint()) && Main.mouseLeft)
                {
                    UnfocusTextBox();
                }
            }



            CalculatedStyle   innerDimensions = base.GetInnerDimensions();
            Vector2           pos             = innerDimensions.Position();
            DynamicSpriteFont spriteFont      = base.IsLarge ? Main.fontDeathText : Main.fontMouseText;
            Vector2           vector          = new Vector2(spriteFont.MeasureString(base.Text.Substring(0, this._cursor)).X, base.IsLarge ? 32f : 16f) * base.TextScale;

            if (Text.Length == 0)
            {
                Vector2 hintTextSize = new Vector2(spriteFont.MeasureString(_hintText).X, IsLarge ? 32f : 16f) * TextScale;
                pos.X += 5;                //(hintTextSize.X);
                Utils.DrawBorderString(spriteBatch, _hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                pos.X -= 5;
                //pos.X -= (innerDimensions.Width - hintTextSize.X) * 0.5f;
            }
            else
            {
                spriteBatch.DrawString(Main.fontMouseText, Text, pos, Color.Black);
            }

            _frameCount++;

            if (!focused)
            {
                return;
            }

            if (hitbox.Contains(Main.MouseScreen.ToPoint()))
            {
                ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, _hoverText, new Vector2(Main.MouseScreen.X + 24, Main.MouseScreen.Y), Color.White, 0f, Vector2.Zero, Vector2.One);
            }

            pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f;
            if ((_frameCount %= 40) > 20)
            {
                return;
            }
            Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
        }