Esempio n. 1
0
        public override void SetText(string text, float textScale, bool large)
        {
            string lastLine = text.Split('\n').Last();

            if (lastLine.Length > this._maxLineLength)
            {
                //text = text + "\n";
            }
            //if (text.ToString().Length > this._maxLength)
            //{
            //	text = text.ToString().Substring(0, this._maxLength);
            //}
            base.SetText(text, textScale, large);

            int lines = text.Split('\n').Length;

            this.MinHeight.Set(-4 + lines * 28 + this.PaddingTop + this.PaddingBottom, 0f);

            //this.MinWidth.Set(120, 0f);

            this._cursor = Math.Min(base.Text.Length, this._cursor);

            OnTextChanged?.Invoke();
        }
Esempio n. 2
0
 public object AddTextfield(string text, string defaultContent, OnTextChanged eventChangedCallback, OnTextSubmitted eventSubmittedCallback)
 {
     if (eventChangedCallback != null && !string.IsNullOrEmpty(text))
     {
         UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(kTextfieldTemplate)) as UIPanel;
         uIPanel.Find <UILabel>("Label").text = text;
         UITextField uITextField = uIPanel.Find <UITextField>("Text Field");
         uITextField.text              = defaultContent;
         uITextField.eventTextChanged += delegate(UIComponent c, string sel)
         {
             eventChangedCallback(sel);
         };
         uITextField.eventTextSubmitted += delegate(UIComponent c, string sel)
         {
             if (eventSubmittedCallback != null)
             {
                 eventSubmittedCallback(sel);
             }
         };
         return(uITextField);
     }
     DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create dropdown with no name or no event");
     return(null);
 }
Esempio n. 3
0
        public override void OnTextInput(string text)
        {
            base.OnTextInput(text);

            if (Focused)
            {
                char   c       = text[0];
                string tmpText = _realText;

                if (c == 8)
                {
                    if (_realText.Length > 0)
                    {
                        if (_text.IsAnyTextSelected)
                        {
                            RemoveSelectedText();
                        }
                        else if (_currentIndex > 0)
                        {
                            _realText = _realText.Remove(_currentIndex - 1, 1);
                            _currentIndex--;
                        }
                    }
                }
                else if (c == 13 && _text.Lines < MaxLines)
                {
                    _realText = _realText.Insert(_currentIndex, "\n");
                    _currentIndex++;
                }
                else if (!char.IsControl(c))
                {
                    RemoveSelectedText();

                    if ((char.IsDigit(c) && AllowNumbers == true) || (c == '-' && _currentIndex == 0 && _realText.Contains("-") == false))
                    {
                        _realText = _realText.Insert(_currentIndex, text);
                        _currentIndex++;
                    }
                    if (char.IsLetter(c) && AllowLetters == true)
                    {
                        _realText = _realText.Insert(_currentIndex, text);
                        _currentIndex++;
                    }
                    if ((char.IsSymbol(c) || char.IsPunctuation(c) || char.IsSeparator(c)) && char.IsWhiteSpace(c) == false && AllowSpecialCharacters == true)
                    {
                        _realText = _realText.Insert(_currentIndex, text);
                        _currentIndex++;
                    }
                    if (char.IsWhiteSpace(c))
                    {
                        _realText = _realText.Insert(_currentIndex, text);
                        _currentIndex++;
                    }
                }

                UpdateValue();

                if (_realText != tmpText)
                {
                    OnTextChanged?.Invoke(this, _realText);
                }
            }
        }
Esempio n. 4
0
 private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     OnTextChanged?.Invoke(sender, e);
 }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
        public bool AcceptInput(ConsoleKeyInfo keyPressed, GraphicsContext g)
        {
            g.SetCursorVisible(false);
            var map = InputMap.Compile();

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.MoveLeftWord))
            {
                // DOING
                // Move one word to the left, i.e. move to the left until you meet a space (or the beginning of the line)

                var i          = CaretPosition - 1;
                var skipSpaces = true;
                // this is so that we jump to the previous word if we are at the beginning of a
                // word when ctrl <- is invoked

                while (CaretPosition >= 0 && CaretPosition <= Text.Length)
                {
                    if (CaretPosition == 0)
                    {
                        UpdateCursorState(g);
                        return(true);
                    }

                    switch (Text[i])
                    {
                    case ' ':
                        if (!skipSpaces)
                        {
                            UpdateCursorState(g);
                            return(true);
                        }

                        goto default;     // Jump to case default

                    default:
                        CaretPosition--;
                        i--;
                        skipSpaces = false;
                        break;
                    }
                }

                UpdateCursorState(g);
                return(false);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.MoveRightWord))
            {
                var skipSpaces = true;

                while (CaretPosition <= Text.Length)
                {
                    if (CaretPosition == Text.Length)
                    {
                        UpdateCursorState(g);
                        return(true);
                    }

                    switch (Text[CaretPosition])
                    {
                    case ' ':
                        if (!skipSpaces)
                        {
                            UpdateCursorState(g);
                            return(true);
                        }

                        CaretPosition++;
                        break;

                    default:
                        CaretPosition++;
                        skipSpaces = false;
                        break;
                    }
                }

                UpdateCursorState(g);
                return(false);
            }


            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.BaseAction))
            {
                ActionOnComponent?.Invoke(this, new ActionEventArgs(this, keyPressed, g));
                UpdateCursorState(g);
                return(true);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.MoveLeft))
            {
                if (CaretPosition > 0)
                {
                    CaretPosition -= 1;
                    UpdateCursorState(g);
                    return(true);
                }

                UpdateCursorState(g);
                return(false);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.MoveRight))
            {
                if (CaretPosition < Text.Length)
                {
                    CaretPosition += 1;
                    UpdateCursorState(g);
                    return(true);
                }

                UpdateCursorState(g);
                return(false);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.DeleteToTheLeftAction))
            {
                if (CaretPosition > 0)
                {
                    Text           = Text.Remove(CaretPosition - 1, 1);
                    CaretPosition -= 1;
                    Print(1, g);
                    OnTextChanged?.Invoke(this, new ActionEventArgs(this, keyPressed, g));

                    UpdateCursorState(g);
                    return(true);
                }

                UpdateCursorState(g);
                return(false);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.DeleteToTheRightAction))
            {
                if (CaretPosition > 0 && CaretPosition < Text.Length)
                {
                    Text = Text.Remove(CaretPosition, 1);
                    Print(1, g);
                    OnTextChanged?.Invoke(this, new ActionEventArgs(this, keyPressed, g));

                    UpdateCursorState(g);
                    return(true);
                }


                UpdateCursorState(g);
                return(false);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.MoveLineStart))
            {
                // TODO
                // Move the caret to the beginning of the line
                if (CaretPosition > 0)
                {
                    CaretPosition = 0;

                    UpdateCursorState(g);
                    return(true);
                }

                UpdateCursorState(g);
                return(false);
            }

            if (Utils.KeyCorresponds(map, keyPressed, StandardActionNames.MoveLineEnd))
            {
                // TODO
                // Move the caret to the end of the line
                if (CaretPosition < Text.Length)
                {
                    CaretPosition = Text.Length;
                    UpdateCursorState(g);
                    return(true);
                }

                UpdateCursorState(g);
                return(false);
            }

            // Letters: add the letters to Text and write them with the following line. Also increase CaretPosition.
            //     g.Write(X + CaretPosition, Y, <the letter>);
            // Backspace: delete the letter, careposition - 1, make sure to rewrite the string correctly (or call Print
            // if you're lazy)

            if (keyPressed.KeyChar > (char)31 && keyPressed.Key != ConsoleKey.Enter &&
                keyPressed.Key != ConsoleKey.Tab && keyPressed.Key != ConsoleKey.Escape &&
                // NOT(control pressed XOR alt pressed)
                (keyPressed.Modifiers & ConsoleModifiers.Control) == 0 ==
                ((keyPressed.Modifiers & ConsoleModifiers.Alt) == 0))
            {
                Text           = Text.Insert(CaretPosition, "" + keyPressed.KeyChar);
                CaretPosition += 1;
                Print(PlaceholderText.Length - 1, g);
                OnTextChanged?.Invoke(this, new ActionEventArgs(this, keyPressed, g));
                UpdateCursorState(g);
                return(true);
            }


            // USE .KeyChar AND NOT .Key.ToString() !!!

            // If it matched one of the cases above, return true
            // Anything else: return false
            UpdateCursorState(g);
            return(false);
        }
Esempio n. 7
0
 public void TextChanged()
 {
     OnTextChanged?.Invoke();
 }
Esempio n. 8
0
        public void ReceiveCommandInput(char command)
        {
            if (Text == null)
            {
                Text = "";
            }

            switch (command)
            {
            case '\b' when !Readonly:     //backspace
                if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
                {
                    SetText(string.Empty, false);
                    CaretIndex = Text.Length;
                }
                else if (selectedCharacters > 0)
                {
                    RemoveSelectedText();
                }
                else if (Text.Length > 0 && CaretIndex > 0)
                {
                    CaretIndex--;
                    SetText(Text.Remove(CaretIndex, 1));
                    CalculateCaretPos();
                    ClearSelection();
                }
                OnTextChanged?.Invoke(this, Text);
                break;

            case (char)0x3:     // ctrl-c
                CopySelectedText();
                break;

            case (char)0x16 when !Readonly:     // ctrl-v
                string text = GetCopiedText();
                RemoveSelectedText();
                if (SetText(Text.Insert(CaretIndex, text)))
                {
                    CaretIndex = Math.Min(Text.Length, CaretIndex + text.Length);
                    OnTextChanged?.Invoke(this, Text);
                }
                break;

            case (char)0x18:     // ctrl-x
                CopySelectedText();
                if (!Readonly)
                {
                    RemoveSelectedText();
                }
                break;

            case (char)0x1:     // ctrl-a
                SelectAll();
                break;

            case (char)0x1A when !Readonly:     // ctrl-z
                text = memento.Undo();
                if (text != Text)
                {
                    ClearSelection();
                    SetText(text, false);
                    CaretIndex = Text.Length;
                    OnTextChanged?.Invoke(this, Text);
                }
                break;

            case (char)0x12 when !Readonly:     // ctrl-r
                text = memento.Redo();
                if (text != Text)
                {
                    ClearSelection();
                    SetText(text, false);
                    CaretIndex = Text.Length;
                    OnTextChanged?.Invoke(this, Text);
                }
                break;
            }
        }
Esempio 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;
            }
        }
Esempio n. 10
0
 private void Reparse()
 {
     Text = Parse();
     OnTextChanged?.Invoke(Text);
 }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public void ReceiveCommandInput(char command)
        {
            if (Text == null)
            {
                Text = "";
            }

            // Prevent alt gr from triggering any of these as that combination is often needed for special characters
            if (PlayerInput.IsAltDown())
            {
                return;
            }

            switch (command)
            {
            case '\b' when !Readonly:     //backspace
                if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
                {
                    SetText(string.Empty, false);
                    CaretIndex = Text.Length;
                }
                else if (selectedCharacters > 0)
                {
                    RemoveSelectedText();
                }
                else if (Text.Length > 0 && CaretIndex > 0)
                {
                    CaretIndex--;
                    SetText(Text.Remove(CaretIndex, 1));
                    CalculateCaretPos();
                    ClearSelection();
                }
                OnTextChanged?.Invoke(this, Text);
                break;

            case (char)0x3:     // ctrl-c
                CopySelectedText();
                break;

            case (char)0x16 when !Readonly:     // ctrl-v
                string text = GetCopiedText();
                RemoveSelectedText();
                if (SetText(Text.Insert(CaretIndex, text)))
                {
                    CaretIndex = Math.Min(Text.Length, CaretIndex + text.Length);
                    OnTextChanged?.Invoke(this, Text);
                }
                break;

            case (char)0x18:     // ctrl-x
                CopySelectedText();
                if (!Readonly)
                {
                    RemoveSelectedText();
                }
                break;

            case (char)0x1:     // ctrl-a
                if (PlayerInput.IsCtrlDown())
                {
                    SelectAll();
                }
                break;

            case (char)0x1A when !Readonly && !SubEditorScreen.IsSubEditor():     // ctrl-z
                text = memento.Undo();
                if (text != Text)
                {
                    ClearSelection();
                    SetText(text, false);
                    CaretIndex = Text.Length;
                    OnTextChanged?.Invoke(this, Text);
                }
                break;

            case (char)0x12 when !Readonly && !SubEditorScreen.IsSubEditor():     // ctrl-r
                text = memento.Redo();
                if (text != Text)
                {
                    ClearSelection();
                    SetText(text, false);
                    CaretIndex = Text.Length;
                    OnTextChanged?.Invoke(this, Text);
                }
                break;
            }
        }
Esempio n. 13
0
 private void DoTextChanged(object sender, EventArgs e)
 {
     OnTextChanged?.Invoke(sender, e);
 }
Esempio n. 14
0
 private void TextBox_TextChanged(object sender, EventArgs e)
 {
     OnTextChanged?.Invoke(this, EventArgs.Empty);
 }
        public static UITextField createTextField(UIHelperBase helper, string defaultContent, OnTextChanged onTextChanged, OnTextSubmitted onTextSubmitted)
        {
            var textfield = helper.AddTextfield("..", defaultContent, onTextChanged, onTextSubmitted) as UITextField;
            var parent    = textfield.parent;

            parent.RemoveUIComponent(textfield);
            var label = parent.Find <UILabel>("Label");

            parent.RemoveUIComponent(label);
            UnityEngine.Object.Destroy(label);
            parent.parent.RemoveUIComponent(parent);
            return(textfield);
        }
Esempio n. 16
0
 public void NoticeChanged(string value)
 {
     OnTextChanged?.Invoke(value);
 }
Esempio n. 17
0
 public UITextField AddTextField(string name, OnTextChanged eventCallback, string defaultValue = "", OnTextSubmitted eventSubmit = null)
 {
     return((UITextField)AddTextfield(name, defaultValue, eventCallback, eventSubmit));
 }
Esempio n. 18
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);
            }
        }
Esempio n. 19
0
 public object AddTextfield(string text, string defaultContent, OnTextChanged eventChangedCallback, OnTextSubmitted eventSubmittedCallback = null)
 {
     throw new NotImplementedException();
 }
Esempio n. 20
0
        public void ReceiveSpecialInput(Keys key)
        {
            switch (key)
            {
            case Keys.Left:
                if (isSelecting)
                {
                    InitSelectionStart();
                }
                CaretIndex = Math.Max(CaretIndex - 1, 0);
                caretTimer = 0;
                HandleSelection();
                break;

            case Keys.Right:
                if (isSelecting)
                {
                    InitSelectionStart();
                }
                CaretIndex = Math.Min(CaretIndex + 1, Text.Length);
                caretTimer = 0;
                HandleSelection();
                break;

            case Keys.Up:
                if (isSelecting)
                {
                    InitSelectionStart();
                }
                float lineHeight = Font.MeasureString("T").Y *TextBlock.TextScale;
                int   newIndex   = textBlock.GetCaretIndexFromLocalPos(new Vector2(caretPos.X, caretPos.Y - lineHeight));
                CaretIndex = newIndex;
                caretTimer = 0;
                HandleSelection();
                break;

            case Keys.Down:
                if (isSelecting)
                {
                    InitSelectionStart();
                }
                lineHeight = Font.MeasureString("T").Y *TextBlock.TextScale;
                newIndex   = textBlock.GetCaretIndexFromLocalPos(new Vector2(caretPos.X, caretPos.Y + lineHeight));
                CaretIndex = newIndex;
                caretTimer = 0;
                HandleSelection();
                break;

            case Keys.Delete when !Readonly:
                if (selectedCharacters > 0)
                {
                    RemoveSelectedText();
                }
                else if (Text.Length > 0 && CaretIndex < Text.Length)
                {
                    SetText(Text.Remove(CaretIndex, 1));
                    OnTextChanged?.Invoke(this, Text);
                    caretPosDirty = true;
                }
                break;

            case Keys.Tab:
                // Select the next text box.
                var editor = RectTransform.GetParents().Select(p => p.GUIComponent as SerializableEntityEditor).FirstOrDefault(e => e != null);
                if (editor == null)
                {
                    break;
                }
                var allTextBoxes = GetAndSortTextBoxes(editor).ToList();
                if (allTextBoxes.Any())
                {
                    int currentIndex = allTextBoxes.IndexOf(this);
                    int nextIndex    = Math.Min(allTextBoxes.Count - 1, currentIndex + 1);
                    var next         = allTextBoxes[nextIndex];
                    if (next != this)
                    {
                        next.Select();
                        next.Flash(Color.White * 0.5f, 0.5f);
                    }
                    else
                    {
                        // Select the first text box in the next editor that has text boxes.
                        var listBox = RectTransform.GetParents().Select(p => p.GUIComponent as GUIListBox).FirstOrDefault(lb => lb != null);
                        if (listBox == null)
                        {
                            break;
                        }
                        // TODO: The get's out of focus if the selection is out of view.
                        // Not sure how's that possible, but it seems to work when the auto scroll is disabled and you handle the scrolling manually.
                        listBox.SelectNext();
                        while (SelectNextTextBox(listBox) == null)
                        {
                            var previous = listBox.SelectedComponent;
                            listBox.SelectNext();
                            if (listBox.SelectedComponent == previous)
                            {
                                break;
                            }
                        }
                    }
                }
                IEnumerable <GUITextBox> GetAndSortTextBoxes(GUIComponent parent) => parent.GetAllChildren <GUITextBox>().OrderBy(t => t.Rect.Y).ThenBy(t => t.Rect.X);

                GUITextBox SelectNextTextBox(GUIListBox listBox)
                {
                    var textBoxes = GetAndSortTextBoxes(listBox.SelectedComponent);

                    if (textBoxes.Any())
                    {
                        var next = textBoxes.First();
                        next.Select();
                        next.Flash(Color.White * 0.5f, 0.5f);
                        return(next);
                    }
                    return(null);
                }

                break;
            }
            OnKeyHit?.Invoke(this, key);
            void HandleSelection()
            {
                if (isSelecting)
                {
                    InitSelectionStart();
                    CalculateSelection();
                }
                else
                {
                    ClearSelection();
                }
            }
        }
Esempio n. 21
0
 private void DispatchTextChangedEvent()
 {
     OnTextChanged?.Invoke(this);
 }