示例#1
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            Rectangle rectangle = GetDimensions().ToRectangle();

            if (IsMouseHovering)
            {
                OnMouseHover?.Invoke();
            }

            if (ContainsPoint(Main.MouseScreen) && !PlayerInput.IgnoreMouseInterface)
            {
                Main.LocalPlayer.mouseInterface = true;

                if (validItem == null || validItem(Main.mouseItem))
                {
                    bool?pre = PreItemChange?.Invoke(item);
                    if (pre == null || pre == true)
                    {
                        ItemSlot.Handle(ref item, context);                         //Handle handles all the click and hover actions based on the context.
                    }
                    PostItemChange?.Invoke(item);
                }
            }

            //Draw draws the slot itself and Item
            bool?preDraw = PreDrawItemSlot?.Invoke(item);

            if (preDraw == null || preDraw == true)
            {
                Draw(item, rectangle.TopLeft(), backgroundTexture, scale);
            }

            PostDrawItemSlot?.Invoke(item);
        }
示例#2
0
        private void RaycastFromCamera()
        {
            ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            Physics.Raycast(ray, out hit, distance, mask);

            OnMouseHover.Invoke(hit);
        }
示例#3
0
        AABB buttonBounds;         //it is easy to store button bounds as an AABB

        public Button(TextureName image, float width, float height, Vector2 position, float scale, Scene scene, OnMouseHover mouseHoverEvent = null, OnMouseEnter mouseEnterEvent = null, OnMouseLeave mouseLeaveEvent = null) : base(image, position, scale, 0, null, true)
        {
            buttonBounds = new AABB(new Vector2(width / 2, height / 2), width, height);
            if (scene != null)
            {
                scene.AddUIElement(this);
            }

            if (mouseHoverEvent == null)
            {
                mH += DefaultHoverEvent;
            }
            else
            {
                mH += mouseHoverEvent;
            }

            if (mouseLeaveEvent == null)
            {
                mL += DefaultExitEvent;
            }
            else
            {
                mL += mouseLeaveEvent;
            }

            if (mouseEnterEvent == null)
            {
                mE += DefaultEnterEvent;
            }
            else
            {
                mE += mouseEnterEvent;
            }
        }
示例#4
0
 internal void TriggerOnMouseHover(MouseState state)
 {
     OnMouseHover?.Invoke(state);
 }
示例#5
0
 private void OnMouseOver()
 {
     OnMouseHover?.Invoke(this);
 }
示例#6
0
 public void AddHoverEvent(OnMouseHover h)
 {
     mH += h;
 }