コード例 #1
0
ファイル: LinkItem.cs プロジェクト: dandelionn/Link
 private void richTextBoxDescription_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Tab)
     {
         e.SuppressKeyPress = true;
         if (e.Modifiers == Keys.Shift)
         {
             OnTabPressed?.Invoke(this, true);
         }
         else
         {
             richTextBoxLink.Focus();
         }
     }
     else
     {
         if (e.KeyCode == Keys.Delete)
         {
             if (richTextBoxDescription.SelectedText == String.Empty)
             {
                 OnDeleteKeyDown?.Invoke(this);
             }
         }
     }
 }
コード例 #2
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);
        }
コード例 #3
0
ファイル: TextBox.cs プロジェクト: ryancheung/InputFix
        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;
            }
        }
コード例 #4
0
ファイル: UITextBox.cs プロジェクト: GoodPro712/Desiccation
        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);
            }
        }
コード例 #5
0
ファイル: UIBetterTextBox.cs プロジェクト: direwolf420/TICMod
        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;
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        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);
        }
コード例 #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, (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);
        }
コード例 #9
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            counter++;
            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                SetText(Main.GetInputText(Text));
                //Main.keyCount = 0;
            }
            if (counter > 5 && WheresMyItems.RandomBuffHotKey.JustPressed)
            {
                Unfocus();
            }

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

            //if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))

            if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
            {
                Main.chatRelease       = false;
                Main.drawingPlayerChat = false;
                Main.inputTextEnter    = true;
            }
            if (Main.inputTextEnter || Main.inputTextEscape)
            {
                Main.chatRelease = false;
                Unfocus();
                Main.inputTextEscape = false;
                Main.playerInventory = false;
                Main.LocalPlayer.releaseInventory = false;
                Main.LocalPlayer.controlInv       = false;
            }
            //HandleSpecialKeys();
            this._cursor = base.Text.Length;
            //base.DrawSelf(spriteBatch);
            {
                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);
        }
コード例 #10
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);
        }