Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            hoverSlot = -1;
            Vector2    origin   = InterfaceHelper.GetFullRectangle(this).TopLeft();
            MouseState curMouse = StorageGUI.curMouse;

            if (curMouse.X <= origin.X || curMouse.Y <= origin.Y)
            {
                return;
            }

            var inventoryBackTexture = TextureAssets.InventoryBack.Value;

            int slotWidth  = (int)(inventoryBackTexture.Width * inventoryScale * Main.UIScale);
            int slotHeight = (int)(inventoryBackTexture.Height * inventoryScale * Main.UIScale);
            int slotX      = (curMouse.X - (int)origin.X) / (slotWidth + padding);
            int slotY      = (curMouse.Y - (int)origin.Y) / (slotHeight + padding);

            if (slotX < 0 || slotX >= numColumns || slotY < 0 || slotY >= numRows)
            {
                return;
            }
            Vector2 slotPos = origin + new Vector2(slotX * (slotWidth + padding * Main.UIScale), slotY * (slotHeight + padding * Main.UIScale));

            if (curMouse.X > slotPos.X && curMouse.X < slotPos.X + slotWidth && curMouse.Y > slotPos.Y && curMouse.Y < slotPos.Y + slotHeight)
            {
                onHover(slotX + numColumns * slotY, ref hoverSlot);
            }
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            cursorTimer++;
            cursorTimer %= 60;

            if (StorageGUI.MouseClicked && Parent != null)
            {
                Rectangle  dim = InterfaceHelper.GetFullRectangle(this);
                MouseState mouse = StorageGUI.curMouse;
                bool       mouseOver = mouse.X > dim.X && mouse.X <dim.X + dim.Width && mouse.Y> dim.Y && mouse.Y < dim.Y + dim.Height;
                if (!hasFocus && mouseOver)
                {
                    hasFocus = true;
                    CheckBlockInput();
                }
                else if (hasFocus && !mouseOver)
                {
                    hasFocus = false;
                    CheckBlockInput();
                    cursorPosition = text.Length;
                }
            }
            else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && Parent != null && hasFocus)
            {
                Rectangle  dim = InterfaceHelper.GetFullRectangle(this);
                MouseState mouse = StorageGUI.curMouse;
                bool       mouseOver = mouse.X > dim.X && mouse.X <dim.X + dim.Width && mouse.Y> dim.Y && mouse.Y < dim.Y + dim.Height;
                if (!mouseOver)
                {
                    hasFocus       = false;
                    cursorPosition = text.Length;
                    CheckBlockInput();
                }
                else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && mouseOver)
                {
                    text           = string.Empty;
                    cursorPosition = 0;
                    StorageGUI.RefreshItems();
                }
            }

            if (hasFocus)
            {
                PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string newString = Main.GetInputText(text);
                if (!newString.Equals(text))
                {
                    text           = newString;
                    cursorPosition = text.Length;
                    StorageGUI.RefreshItems();
                }
                if (KeyTyped(Keys.Enter) || KeyTyped(Keys.Tab) || KeyTyped(Keys.Escape))
                {
                    hasFocus = false;
                    CheckBlockInput();
                }
            }
            base.Update(gameTime);
        }
Beispiel #3
0
        private bool MouseOverButton(int mouseX, int mouseY, int button)
        {
            Rectangle dim    = InterfaceHelper.GetFullRectangle(this);
            float     left   = dim.X + button * (buttonSize + buttonPadding) * Main.UIScale;
            float     right  = left + buttonSize * Main.UIScale;
            float     top    = dim.Y;
            float     bottom = top + buttonSize * Main.UIScale;

            return(mouseX > left && mouseX < right && mouseY > top && mouseY < bottom);
        }
Beispiel #4
0
        private static void UpdateDepositButton()
        {
            Rectangle dim = InterfaceHelper.GetFullRectangle(depositButton);

            if (curMouse.X > dim.X && curMouse.X < dim.X + dim.Width && curMouse.Y > dim.Y && curMouse.Y < dim.Y + dim.Height)
            {
                depositButton.BackgroundColor = new Color(73, 94, 171);
                if (MouseClicked)
                {
                    if (TryDepositAll())
                    {
                        RefreshItems();
                        Main.PlaySound(7, -1, -1, 1);
                    }
                }
            }
            else
            {
                depositButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
            }
        }
Beispiel #5
0
        public override void Update(GameTime gameTime)
        {
            cursorTimer++;
            cursorTimer %= 60;

            Rectangle  dim = InterfaceHelper.GetFullRectangle(this);
            MouseState mouse = StorageGUI.curMouse;
            bool       mouseOver = mouse.X > dim.X && mouse.X <dim.X + dim.Width && mouse.Y> dim.Y && mouse.Y < dim.Y + dim.Height;

            if (StorageGUI.MouseClicked && Parent != null)
            {
                if (!hasFocus && mouseOver)
                {
                    hasFocus = true;
                    CheckBlockInput();
                }
                else if (hasFocus && !mouseOver)
                {
                    hasFocus = false;
                    CheckBlockInput();
                    cursorPosition = text.Length;
                }
            }
            else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && Parent != null && hasFocus && !mouseOver)
            {
                hasFocus       = false;
                cursorPosition = text.Length;
                CheckBlockInput();
            }
            else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && mouseOver)
            {
                if (text.Length > 0)
                {
                    text           = string.Empty;
                    cursorPosition = 0;
                }
            }

            if (hasFocus)
            {
                PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string prev = text;

                if (cursorPosition < text.Length && text.Length > 0)
                {
                    prev = prev.Remove(cursorPosition);
                }

                string newString = Main.GetInputText(prev);
                bool   changed   = false;

                if (!newString.Equals(prev))
                {
                    int newStringLength = newString.Length;
                    if (prev != text)
                    {
                        newString += text.Substring(cursorPosition);
                    }
                    text           = newString;
                    cursorPosition = newStringLength;
                    changed        = true;
                }

                if (KeyTyped(Keys.Delete) && text.Length > 0 && cursorPosition <= text.Length - 1)
                {
                    text    = text.Remove(cursorPosition, 1);
                    changed = true;
                }
                if (KeyTyped(Keys.Left) && cursorPosition > 0)
                {
                    cursorPosition--;
                }
                if (KeyTyped(Keys.Right) && cursorPosition < text.Length)
                {
                    cursorPosition++;
                }
                if (KeyTyped(Keys.Home))
                {
                    cursorPosition = 0;
                }
                if (KeyTyped(Keys.End))
                {
                    cursorPosition = text.Length;
                }
                if ((Main.keyState.IsKeyDown(Keys.LeftControl) || Main.keyState.IsKeyDown(Keys.RightControl)) && KeyTyped(Keys.Back))
                {
                    text           = string.Empty;
                    cursorPosition = 0;
                    changed        = true;
                }

                if (changed)
                {
                    StorageGUI.RefreshItems();
                }

                if (KeyTyped(Keys.Enter) || KeyTyped(Keys.Tab) || KeyTyped(Keys.Escape))
                {
                    hasFocus = false;
                    CheckBlockInput();
                }
            }
            base.Update(gameTime);
        }