Пример #1
0
        /// <summary>
        /// Update the UINumberBox.
        /// </summary>
        public override void Update()
        {
            if (textBox.Focused)
            {
                if (KeyboardUtils.JustPressed(Keys.Up) || KeyboardUtils.HeldDown(Keys.Up))
                {
                    if (up == 0)
                    {
                        Increase();
                        up = frameDelay;
                    }
                    up--;
                }
                else if (KeyboardUtils.JustPressed(Keys.Down) || KeyboardUtils.HeldDown(Keys.Down))
                {
                    if (down == 0)
                    {
                        Decrease();
                        down = frameDelay;
                    }
                    down--;
                }

                textBox.SelectionStart = textBox.Text.Length;
            }

            base.Update();
        }
        public override void RightClick(Item item, Player player)
        {
            if (!CanRightClick(item))
            {
                return;
            }

            WingSlotPlayer mp = player.GetModPlayer <WingSlotPlayer>();

            mp.EquipWings(KeyboardUtils.HeldDown(Keys.LeftShift), item);
        }
        public override void RightClick(Item item, Player player)
        {
            if (item.wingSlot > 0)
            {
                WingSlotPlayer mp = player.GetModPlayer <WingSlotPlayer>(mod);

                if (KeyboardUtils.HeldDown(Keys.LeftShift))
                {
                    mp.EquipWings(true, item);
                }
                else
                {
                    mp.EquipWings(false, item);
                }
            }
            else
            {
                base.RightClick(item, player);
            }
        }
Пример #4
0
        /// <summary>
        /// Update the object. Call during any Update() function.
        /// </summary>
        public override void Update()
        {
            if (Focused)
            {
                bool skip = false;

                if (Text.Length > 0)
                {
                    if (KeyboardUtils.JustPressed(Input.Keys.Left) || KeyboardUtils.HeldDown(Input.Keys.Left))
                    {
                        if (leftArrow == 0)
                        {
                            SelectionStart--;
                            leftArrow = frameDelay;
                        }
                        leftArrow--;
                        skip = true;
                    }
                    else if (KeyboardUtils.JustPressed(Input.Keys.Right) || KeyboardUtils.HeldDown(Input.Keys.Right))
                    {
                        if (rightArrow == 0)
                        {
                            SelectionStart++;
                            rightArrow = frameDelay;
                        }
                        rightArrow--;
                        skip = true;
                    }
                    else if (KeyboardUtils.JustPressed(Input.Keys.Delete) || KeyboardUtils.HeldDown(Input.Keys.Delete))
                    {
                        if (delete == 0)
                        {
                            if (SelectionStart < Text.Length)
                            {
                                Text = Text.Remove(SelectionStart, 1);
                            }
                            delete = frameDelay;
                        }
                        delete--;
                        skip = true;
                    }
                    else if (KeyboardUtils.JustPressed(Input.Keys.Enter))
                    {
                        Unfocus();
                    }
                    else
                    {
                        leftArrow  = 0;
                        rightArrow = 0;
                        delete     = 0;
                    }
                }

                if (!skip)
                {
                    int    oldLength = Text.Length;
                    string substring = Text.Substring(0, SelectionStart);

                    PlayerInput.WritingText = true;
                    string input = Regex.Replace(Main.GetInputText(substring), Strip, "");

                    // first, we check if the length of the string has changed, indicating
                    // text has been added or removed
                    if (input.Length != substring.Length)
                    {
                        // we remove the old text and replace it with the new, storing it
                        // in a temporary variable
                        string newText = Text.Remove(0, SelectionStart).Insert(0, input);

                        // now if the text is smaller than previously or, if not, the string is
                        // an appropriate size,
                        if (newText.Length < Text.Length || Font.MeasureString(newText).X < Size.X - 12)
                        {
                            // we set the old text to the new text
                            Text = newText;

                            // if the length of the text is now longer,
                            if (Text.Length > oldLength)
                            {
                                // adjust the selection start accordingly
                                SelectionStart += (Text.Length - oldLength);
                            }
                            // or if the length of the text is now shorter
                            else if (Text.Length < oldLength)
                            {
                                // adjust the selection start accordingly
                                SelectionStart -= (oldLength - Text.Length);
                            }
                        }
                    }
                }
            }

            base.Update();
        }