Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (Focused)
            {
                foreach (var _key in GInput.NewPressedKeys)
                {
                    switch (_key)
                    {
                    case Keys.Back:
                        if (Text.Length > 0)
                        {
                            Text = Text.Substring(0, Text.Length - 1);
                        }
                        break;

                    case Keys.Enter:
                        OnEnterPressed?.Invoke(this);
                        break;

                    default:
                        Text += GInput.KeyToString(_key, Filters);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void HandleInputStandalone()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         OnEscPressed?.Invoke(this, EventArgs.Empty);
     }
     else if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
     {
         OnEnterPressed?.Invoke(this, EventArgs.Empty);
     }
     else if (Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace))
     {
         OnDeletePressed?.Invoke(this, EventArgs.Empty);
     }
     // Left Button
     if (Input.GetMouseButtonDown(0))
     {
         TryToRaycast(Clickable.Click.MOUSE_LEFT_BUTTON);
     }
     // Right Button
     else if (Input.GetMouseButtonDown(1))
     {
         TryToRaycast(Clickable.Click.MOUSE_RIGHT_BUTTON);
     }
     // Middle Button
     else if (Input.GetMouseButtonDown(2))
     {
         TryToRaycast(Clickable.Click.MOUSE_MIDDLE_BUTTON);
     } /*else {
        * TryToRaycast(Clickable.Click.MOUSE_HOVER);
        * }*/
 }
 private void OnKeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         OnEnterPressed?.Invoke(this, e);
     }
 }
Ejemplo n.º 4
0
 public TextEntry(string pTextureName, string pDefaultText, Vector2 pPosition, bool pSecret, OnEnterPressed pOnEnterPressed)
     : base(pTextureName, pPosition)
 {
     _onEnterPressed = pOnEnterPressed;
     _secret = pSecret;
     _defaultText = pDefaultText;
     _skin = (GUISkin)Resources.Load("BasicSkin");
     if(_skin == null) { throw new Exception("Can't find BasicSkin"); }
     _name = "input_field_" + counter++;
 }
Ejemplo n.º 5
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Update();

            if (Focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();

                string newText = Main.GetInputText(Text);
                if (newText != Text)
                {
                    SetText(newText);
                }

                if (JustPressed(Keys.Tab))
                {
                    if (UnfocusOnTab)
                    {
                        Unfocus();
                    }
                    OnTabPressed?.Invoke();
                }

                if (JustPressed(Keys.Escape))
                {
                    if (UnfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }

                if (++BlinkerCount >= 20)
                {
                    BlinkerState = !BlinkerState;
                    BlinkerCount = 0;
                }

                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, Main.screenHeight - 36), 0f);
            }

            var display = Text;

            if (BlinkerState && Focused)
            {
                display += "|";
            }
            DrawWithText(spriteBatch, display);
        }
Ejemplo n.º 6
0
 private void HandleInputStandalone()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         OnEscPressed?.Invoke(this, EventArgs.Empty);
     }
     else if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
     {
         OnEnterPressed?.Invoke(this, EventArgs.Empty);
     }
     else if (Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace))
     {
         OnDeletePressed?.Invoke(this, EventArgs.Empty);
     }
     // Left Button
     if (Input.GetMouseButtonDown(0))
     {
         if (TransformGizmo.Instance.mainTargetRoot != null)
         {
             if (TransformGizmo.Instance.translatingAxis == Axis.None)
             {
                 TransformGizmo.Instance.ClearTargets();
                 TryToRaycast(Clickable.Click.MOUSE_LEFT_BUTTON);
             }
         }
         else
         {
             TryToRaycast(Clickable.Click.MOUSE_LEFT_BUTTON);
         }
     }
     // Right Button
     else if (Input.GetMouseButtonDown(1))
     {
         TryToRaycast(Clickable.Click.MOUSE_RIGHT_BUTTON);
     }
     // Middle Button
     else if (Input.GetMouseButtonDown(2))
     {
         TryToRaycast(Clickable.Click.MOUSE_MIDDLE_BUTTON);
     }
     else
     {
         TryToRaycast(Clickable.Click.MOUSE_HOVER);
     }
 }
Ejemplo n.º 7
0
        public virtual void RecieveCommandInput(char command)//IME will handle key event first, so these method just for english input(if it is using IME, we need to notify TSF)
        {
            switch (command)
            {
            case '\b':
                if (acp.End == acp.Start && acp.Start > 0) //if not, means it alradey have something selected, we just delete it
                {
                    acp.Start--;                           //it selected nothing, reduce end to delete a char
                }
                if (acp.End != acp.Start)
                {
                    ReplaceSelection("");
#if TSF
                    if (Game1.keyboardDispatcher.Subscriber == this)
                    {
                        Game1.tsf.onTextChange();    //not changed by IME, should notify
                        Game1.tsf.onSelChange();
                    }
#endif
                    if (Game1.gameMode != 3)
                    {
                        Game1.playSound("tinyWhip");
                        return;
                    }
                }
                OnBackspacePressed?.Invoke(this);
                break;

            case '\r':
                OnEnterPressed?.Invoke(this);
                break;

            case '\t':
                OnTabPressed?.Invoke(this);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetInnerDimensions().ToRectangle();

            // Draw panel
            base.DrawSelf(spriteBatch);
            //	Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Yellow);

            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string newString = Main.GetInputText(currentString);
                if (!newString.Equals(currentString))
                {
                    currentString = newString;
                    OnTextChanged?.Invoke();
                }
                else
                {
                    currentString = newString;
                }

                if (JustPressed(Keys.Tab))
                {
                    if (unfocusOnTab)
                    {
                        Unfocus();
                    }
                    OnTabPressed?.Invoke();
                }
                if (JustPressed(Keys.Enter))
                {
                    Main.drawingPlayerChat = false;
                    if (unfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }
                if (++textBlinkerCount >= 20)
                {
                    textBlinkerState = (textBlinkerState + 1) % 2;
                    textBlinkerCount = 0;
                }
                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, Main.screenHeight - 36), 0f);
            }
            string displayString = currentString;

            if (textBlinkerState == 1 && focused)
            {
                displayString = displayString + "|";
            }
            CalculatedStyle space = base.GetDimensions();
            Color           color = Color.Black;

            if (currentString.Length == 0)
            {
            }
            Vector2 drawPos = space.Position() + new Vector2(4, 2);

            if (currentString.Length == 0 && !focused)
            {
                color *= 0.5f;
                //Utils.DrawBorderString(spriteBatch, hintText, new Vector2(space.X, space.Y), Color.Gray, 1f);
                spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color);
            }
            else
            {
                //Utils.DrawBorderString(spriteBatch, displayString, drawPos, Color.White, 1f);
                spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color);
            }
        }
Ejemplo n.º 9
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetInnerDimensions().ToRectangle();

            // Draw panel
            base.DrawSelf(spriteBatch);
            //	Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Yellow);

            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();

                string newString = Main.GetInputText("");
                if (newString != null && newString != "")
                {
                    history.Push(currentString);
                    currentString = currentString.Insert(cursorPos, newString);
                    cursorPos    += newString.Length;
                    OnTextChanged?.Invoke();
                }

                if (JustPressed(Keys.Tab))
                {
                    if (unfocusOnTab)
                    {
                        Unfocus();
                    }
                    OnTabPressed?.Invoke();
                }
                else if (JustPressed(Keys.Enter))
                {
                    Main.drawingPlayerChat = false;
                    if (unfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }
                else if (JustPressed(Keys.Left))
                {
                    cursorPos -= 1;
                    if (cursorPos < 0)
                    {
                        cursorPos = 0;
                    }
                }
                else if (JustPressed(Keys.Right))
                {
                    cursorPos += 1;
                    if (cursorPos > currentString.Length)
                    {
                        cursorPos = currentString.Length;
                    }
                }
                else if (JustPressed(Keys.End))
                {
                    cursorPos = currentString.Length;
                }
                else if (JustPressed(Keys.Home))
                {
                    cursorPos = 0;
                }
                else if (JustPressed(Keys.Back) && cursorPos != 0)
                {
                    history.Push(currentString);
                    currentString = currentString.Remove(cursorPos - 1, 1);
                    OnTextChanged?.Invoke();
                    cursorPos -= 1;
                }
                else if (JustPressed(Keys.Delete) && cursorPos != currentString.Length)
                {
                    history.Push(currentString);
                    currentString = currentString.Remove(cursorPos, 1);
                    OnTextChanged?.Invoke();
                }
                else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.C))
                {
                    ReLogic.OS.Platform.Current.Clipboard = currentString;
                }
                else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.X))
                {
                    history.Push(currentString);
                    ReLogic.OS.Platform.Current.Clipboard = currentString;
                    OnTextChanged?.Invoke();
                    currentString = "";
                    cursorPos     = 0;
                }
                else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.V))
                {
                    history.Push(currentString);
                    currentString = currentString.Insert(cursorPos, ReLogic.OS.Platform.Current.Clipboard);
                    cursorPos    += ReLogic.OS.Platform.Current.Clipboard.Length;
                    OnTextChanged?.Invoke();
                }
                else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.Z) && history.Count > 0)
                {
                    currentString = history.Pop();
                    cursorPos     = currentString.Length;
                }


                if (++textBlinkerCount >= 20)
                {
                    textBlinkerState = (textBlinkerState + 1) % 2;
                    textBlinkerCount = 0;
                }

                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
            }

            string displayString = currentString;
            string cursorChar    = " ";

            if (textBlinkerState == 1)
            {
                cursorChar = "|";
            }

            if (focused)
            {
                displayString = displayString.Insert(cursorPos, cursorChar);
            }

            CalculatedStyle space = base.GetDimensions();
            Color           color = textColor;

            if (currentString.Length == 0)
            {
            }

            Vector2 drawPos = space.Position() + new Vector2(4, 2);

            if (currentString.Length == 0 && !focused)
            {
                color *= 0.5f;
                //Utils.DrawBorderString(spriteBatch, hintText, new Vector2(space.X, space.Y), Color.Gray, 1f);
                spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color);
            }
            else
            {
                //Utils.DrawBorderString(spriteBatch, displayString, drawPos, Color.White, 1f);
                spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color);
            }

            if (IsMouseHovering)
            {
                Main.hoverItemName = hoverText;
            }
        }
Ejemplo n.º 10
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetDimensions().ToRectangle();

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


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

                if (JustPressed(Keys.Tab))
                {
                    if (unfocusOnTab)
                    {
                        Unfocus();
                    }
                    OnTabPressed?.Invoke();
                }

                if (JustPressed(Keys.Enter))
                {
                    if (unfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }
                if (JustPressed(Keys.Up))
                {
                    OnUpPressed?.Invoke();
                }
            }
            CalculatedStyle innerDimensions2 = base.GetInnerDimensions();
            Vector2         pos2             = innerDimensions2.Position();

            if (IsLarge)
            {
                pos2.Y -= 10f * TextScale * TextScale;
            }
            else
            {
                pos2.Y -= 2f * TextScale;
            }
            if (IsLarge)
            {
                Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
                return;
            }
            Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);

            this._frameCount++;

            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 (base.IsLarge)
            {
                pos.Y -= 8f * base.TextScale;
            }
            else
            {
                pos.Y -= 1f * base.TextScale;
            }
            if (Text.Length == 0)
            {
                pos.X += 5;
                if (base.IsLarge)
                {
                    Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                    return;
                }
                Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                pos.X -= 5;
            }

            if (!focused)
            {
                return;
            }

            pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f;
            if ((this._frameCount %= 40) > 20)
            {
                return;
            }
            if (base.IsLarge)
            {
                Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
                return;
            }
            Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
        }
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetInnerDimensions().ToRectangle();

            Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.LightCyan * 0.6f);

            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                // This might work.....assuming chat isn't open
                var a = Main.GetInputText(Text);


                var    lines    = a.Split('\n');
                string lastLine = lines.Last();
                if (lastLine.Length > this._maxLineLength + 1)
                {
                    var  orig = a.ToCharArray();
                    char last = orig[orig.Length - 1];
                    orig[orig.Length - 1] = '\n';
                    a = new string(orig) + last;
                }

                WriteAll(a);

                if (JustPressed(Keys.Tab))
                {
                    if (unfocusOnTab)
                    {
                        Unfocus();
                    }
                    //	Main.NewText("Tab");
                    OnTabPressed?.Invoke();
                }

                if (JustPressed(Keys.Enter))
                {
                    //	Main.NewText("Enter");
                    if (unfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }
                if (JustPressed(Keys.Up))
                {
                    OnUpPressed?.Invoke();
                }
            }
            CalculatedStyle innerDimensions2 = base.GetInnerDimensions();
            Vector2         pos2             = innerDimensions2.Position();

            if (IsLarge)
            {
                pos2.Y -= 10f * TextScale * TextScale;
            }
            else
            {
                pos2.Y -= 2f * TextScale;
            }
            //pos2.X += (innerDimensions2.Width - TextSize.X) * 0.5f;
            if (IsLarge)
            {
                Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
                return;
            }
            Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);

            this._frameCount++;

            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 (base.IsLarge)
            {
                pos.Y -= 8f * base.TextScale;
            }
            else
            {
                pos.Y -= 1f * base.TextScale;
            }
            if (Text.Length == 0)
            {
                Vector2 hintTextSize = new Vector2(spriteFont.MeasureString(hintText.ToString()).X, IsLarge ? 32f : 16f) * TextScale;
                pos.X += 5;                //(hintTextSize.X);
                if (base.IsLarge)
                {
                    Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                    return;
                }
                Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                pos.X -= 5;
                //pos.X -= (innerDimensions.Width - hintTextSize.X) * 0.5f;
            }

            if (!focused)
            {
                return;
            }

            pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f;
            if ((this._frameCount %= 40) > 20)
            {
                return;
            }
            if (base.IsLarge)
            {
                Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
                return;
            }
            Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
        }
Ejemplo n.º 12
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetInnerDimensions().ToRectangle();

            base.DrawSelf(spriteBatch);

            if (focused)
            {
                PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string newString = Main.GetInputText(currentString);
                if (!newString.Equals(currentString))
                {
                    currentString = newString;
                    OnTextChanged?.Invoke();
                }
                else
                {
                    currentString = newString;
                }

                if (JustPressed(Keys.Enter))
                {
                    Main.drawingPlayerChat = false;
                    Unfocus();
                    OnEnterPressed?.Invoke();
                }
                if (JustPressed(Keys.Escape))
                {
                    Unfocus();
                    OnEnterPressed?.Invoke();
                }
                if (JustPressed(Keys.Tab))
                {
                    Unfocus();
                    OnEnterPressed?.Invoke();
                }
                if (++textBlinkerCount >= 20)
                {
                    textBlinkerState = (textBlinkerState + 1) % 2;
                    textBlinkerCount = 0;
                }
                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
            }
            string displayString = currentString;

            if (this.textBlinkerState == 1 && focused)
            {
                displayString = displayString + "|";
            }
            CalculatedStyle space = base.GetDimensions();
            Color           color = Color.Black;

            if (currentString.Length == 0)
            {
            }
            Vector2 drawPos = space.Position() + new Vector2(4, 2);

            if (currentString.Length == 0 && !focused)
            {
                color *= 0.5f;
                spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color);
            }
            else
            {
                spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color);
            }
        }
Ejemplo n.º 13
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetInnerDimensions().ToRectangle();

            // Draw panel
            base.DrawSelf(spriteBatch);
            //	Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Yellow);

            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string newString = Main.GetInputText(currentString);
                if (!newString.Equals(currentString))
                {
                    currentString = newString;
                    OnTextChanged?.Invoke();
                }
                else
                {
                    currentString = newString;
                }

                if (JustPressed(Keys.Tab))
                {
                    if (unfocusOnTab)
                    {
                        Unfocus();
                    }
                    OnTabPressed?.Invoke();
                }
                if (JustPressed(Keys.Enter))
                {
                    Main.drawingPlayerChat = false;
                    if (unfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }
                if (++textBlinkerCount >= 20)
                {
                    textBlinkerState = (textBlinkerState + 1) % 2;
                    textBlinkerCount = 0;
                }
                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
            }
            string displayString = currentString;

            if (this.textBlinkerState == 1 && focused)
            {
                displayString = displayString + "|";
            }
            CalculatedStyle space = base.GetDimensions();
            Color           color = Color.Black;

            if (currentString.Length == 0)
            {
            }
            Vector2 drawPos = space.Position() + new Vector2(4, 2);

            if (currentString.Length == 0 && !focused)
            {
                color *= 0.5f;
                //Utils.DrawBorderString(spriteBatch, hintText, new Vector2(space.X, space.Y), Color.Gray, 1f);
                spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color);
            }
            else
            {
                //Utils.DrawBorderString(spriteBatch, displayString, drawPos, Color.White, 1f);
                spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color);
            }

            //			CalculatedStyle innerDimensions2 = base.GetInnerDimensions();
            //			Vector2 pos2 = innerDimensions2.Position();
            //			if (IsLarge)
            //			{
            //				pos2.Y -= 10f * TextScale * TextScale;
            //			}
            //			else
            //			{
            //				pos2.Y -= 2f * TextScale;
            //			}
            //			//pos2.X += (innerDimensions2.Width - TextSize.X) * 0.5f;
            //			if (IsLarge)
            //			{
            //				Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
            //				return;
            //			}
            //			Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
            //
            //			this._frameCount++;
            //
            //			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 (base.IsLarge)
            //			{
            //				pos.Y -= 8f * base.TextScale;
            //			}
            //			else
            //			{
            //				pos.Y -= 1f * base.TextScale;
            //			}
            //			if (Text.Length == 0)
            //			{
            //				Vector2 hintTextSize = new Vector2(spriteFont.MeasureString(hintText.ToString()).X, IsLarge ? 32f : 16f) * TextScale;
            //				pos.X += 5;//(hintTextSize.X);
            //				if (base.IsLarge)
            //				{
            //					Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
            //					return;
            //				}
            //				Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
            //				pos.X -= 5;
            //				//pos.X -= (innerDimensions.Width - hintTextSize.X) * 0.5f;
            //			}
            //
            //			if (!focused) return;
            //
            //			pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f;
            //			if ((this._frameCount %= 40) > 20)
            //			{
            //				return;
            //			}
            //			if (base.IsLarge)
            //			{
            //				Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
            //				return;
            //			}
            //			Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
        }
Ejemplo n.º 14
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle hitbox = GetDimensions().ToRectangle();

            //hitbox.Inflate(4, 4);
            Main.spriteBatch.Draw(REPLTool.magicPixel, hitbox, Color.White);

            // Draw panel -- Panel draws odd when too small
            // base.DrawSelf(spriteBatch);

            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                // This might work.....assuming chat isn't open
                WriteAll(Main.GetInputText(Text));

                if (JustPressed(Keys.Tab))
                {
                    if (unfocusOnTab)
                    {
                        Unfocus();
                    }
                    //	Main.NewText("Tab");
                    OnTabPressed?.Invoke();
                }

                if (JustPressed(Keys.Enter))
                {
                    //	Main.NewText("Enter");
                    if (unfocusOnEnter)
                    {
                        Unfocus();
                    }
                    OnEnterPressed?.Invoke();
                }
                if (JustPressed(Keys.Up))
                {
                    OnUpPressed?.Invoke();
                }
            }
            CalculatedStyle innerDimensions2 = base.GetInnerDimensions();
            Vector2         pos2             = innerDimensions2.Position();

            if (IsLarge)
            {
                pos2.Y -= 10f * TextScale * TextScale;
            }
            else
            {
                pos2.Y -= 2f * TextScale;
            }
            //pos2.X += (innerDimensions2.Width - TextSize.X) * 0.5f;
            if (IsLarge)
            {
                Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
                return;
            }
            Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);

            this._frameCount++;

            CalculatedStyle   innerDimensions = base.GetInnerDimensions();
            Vector2           pos             = innerDimensions.Position();
            DynamicSpriteFont spriteFont      = base.IsLarge ? Terraria.GameContent.FontAssets.DeathText.Value : GameContent.FontAssets.MouseText.Value;
            Vector2           vector          = new Vector2(spriteFont.MeasureString(base.Text.Substring(0, this._cursor)).X, base.IsLarge ? 32f : 16f) * base.TextScale;

            if (base.IsLarge)
            {
                pos.Y -= 8f * base.TextScale;
            }
            else
            {
                pos.Y -= 1f * base.TextScale;
            }
            if (Text.Length == 0)
            {
                Vector2 hintTextSize = new Vector2(spriteFont.MeasureString(hintText.ToString()).X, IsLarge ? 32f : 16f) * TextScale;
                pos.X += 5;                //(hintTextSize.X);
                if (base.IsLarge)
                {
                    Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                    return;
                }
                Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
                pos.X -= 5;
                //pos.X -= (innerDimensions.Width - hintTextSize.X) * 0.5f;
            }

            if (!focused)
            {
                return;
            }

            pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f;
            if ((this._frameCount %= 40) > 20)
            {
                return;
            }
            if (base.IsLarge)
            {
                Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
                return;
            }
            Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
        }
Ejemplo n.º 15
0
 public void EnterPressed()
 {
     OnEnterPressed?.Invoke(this, Parameter);
 }