Exemplo n.º 1
0
        public void InvokeHover(Point screenPosition, float scale, ISymbolCache symbolCache)
        {
            if (Hover == null)
            {
                return;
            }
            if (HoverLayers.Count == 0)
            {
                return;
            }
            var mapInfo = InfoHelper.GetMapInfo(Viewport, screenPosition, scale, HoverLayers, symbolCache);

            if (mapInfo?.Feature != _previousHoverEventArgs?.MapInfo.Feature) // only notify when the feature changes
            {
                var mapInfoEventArgs = new MapInfoEventArgs
                {
                    MapInfo = mapInfo,
                    NumTaps = 0,
                    Handled = false
                };

                _previousHoverEventArgs = mapInfoEventArgs;
                Hover?.Invoke(this, mapInfoEventArgs);
            }
        }
Exemplo n.º 2
0
 public virtual bool OnHover(object sender, MouseEventArgs args)
 {
     hovering = true;
     if (Hover != null)
     {
         return(Hover.Invoke(sender, args));
     }
     return(true);
 }
Exemplo n.º 3
0
        private void _onHover(float p)
        {
            _pickList[this] = p;

            Hover?.Invoke(this);

            if (Mouse.Pressed(MouseButton.Left))
            {
                _isPicked = true;
            }
        }
Exemplo n.º 4
0
        public void InvokeHover(Point screenPosition, ISymbolCache symbolCache)
        {
            if (Hover == null)
            {
                return;
            }
            if (HoverLayers.Count == 0)
            {
                return;
            }
            var hoverEventArgs = InfoHelper.GetInfoEventArgs(Viewport, screenPosition, HoverLayers, symbolCache);

            if (hoverEventArgs?.Feature != _previousHoverEventArgs?.Feature) // only notify when the feature changes
            {
                _previousHoverEventArgs = hoverEventArgs;
                Hover?.Invoke(this, hoverEventArgs);
            }
        }
Exemplo n.º 5
0
        public override void Update(GameTime gameTime, Input input)
        {
            if (!HitBox.Contains(input.MousePos) || input.Hovered)
            {
                return;
            }

            if (input.LeftPress)
            {
                input.CaptureClick();
                Option?.Execute();
            }
            else if (input.MouseMovement != Point.Zero)
            {
                input.CaptureHover();
                Hover?.Invoke();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the button calling all the appropriate events.
        /// </summary>
        /// <param name="window">The render window the button is located in</param>
        public void Update(RenderWindow window)
        {
            Vector2i mousePosition = Mouse.GetPosition(window);

            bool hovered = false;

            if (GetGlobalBounds().Contains(mousePosition.X, mousePosition.Y))
            {
                if (!lastHover)
                {
                    MouseEntered?.Invoke(this, new EventArgs());
                }
                Hover?.Invoke(this, new EventArgs());
                hovered = lastHover = true;
            }
            else if (lastHover)
            {
                MouseLeave?.Invoke(this, new EventArgs());
                lastHover = false;
            }

            if (Mouse.IsButtonPressed(Mouse.Button.Left))
            {
                if (hovered)
                {
                    if (!lastMousePressed)
                    {
                        Clicked?.Invoke(this, new EventArgs());
                    }
                    Pressed?.Invoke(this, new EventArgs());
                }
                lastMousePressed = true;
            }
            else
            {
                lastMousePressed = false;
            }
        }
Exemplo n.º 7
0
 protected void onButtonHover()
 {
     Hover?.Invoke(this);
 }
Exemplo n.º 8
0
        public Button(IUiElement content)
        {
            On <HoverEvent>(_ => { IsHovered = true; Hover?.Invoke(); });
            On <BlurEvent>(_ => { IsHovered = false; Blur?.Invoke(); });
            On <UiLeftClickEvent>(e =>
            {
                if (!IsHovered)
                {
                    return;
                }

                if (!IsClicked)
                {
                    ButtonDown?.Invoke();
                }

                IsClicked = true;
                if (Typematic)
                {
                    Click?.Invoke();
                }

                e.Propagating = false;
            });

            On <UiLeftReleaseEvent>(e =>
            {
                if (!IsClicked)
                {
                    return;
                }
                IsClicked = false;

                if (Typematic)
                {
                    _typematicAccrual = 0;
                    return;
                }

                if (!IsHovered)
                {
                    return;
                }

                if (DoubleClick == null || !AllowDoubleClick || SuppressNextDoubleClick) // Simple single click only button
                {
                    Click?.Invoke();
                    SuppressNextDoubleClick = false;
                    return;
                }

                if (ClickTimerPending) // If they double-clicked...
                {
                    DoubleClick?.Invoke();
                    ClickTimerPending = false; // Ensure the single-click behaviour doesn't happen.
                }
                else // For the first click, just start the double-click timer.
                {
                    var config = Resolve <GameConfig>();
                    Raise(new StartTimerEvent(TimerName, config.UI.ButtonDoubleClickIntervalSeconds, this));
                    ClickTimerPending = true;
                }
            });

            On <UiRightClickEvent>(e =>
            {
                e.Propagating  = false;
                IsRightClicked = true;
            });

            On <UiRightReleaseEvent>(e =>
            {
                if (IsRightClicked && IsHovered)
                {
                    RightClick?.Invoke();
                }
                IsRightClicked = false;
            });

            On <TimerElapsedEvent>(e =>
            {
                if (e.Id != TimerName)
                {
                    return;
                }

                if (!ClickTimerPending) // They've already double-clicked
                {
                    return;
                }

                Click?.Invoke();
                ClickTimerPending = false;
            });

            On <EngineUpdateEvent>(e =>
            {
                if (!Typematic || !IsClicked)
                {
                    return;
                }

                var oldAccrual     = _typematicAccrual;
                _typematicAccrual += e.DeltaSeconds;
                var rate           = 8 * (int)(2 * oldAccrual);
                var oldAmount      = (int)(oldAccrual * rate);
                var newAmount      = (int)(_typematicAccrual * rate);
                var delta          = newAmount - oldAmount;
                for (int i = 0; i < delta; i++)
                {
                    Click?.Invoke();
                }
            });

            _id    = Interlocked.Increment(ref _nextId);
            _frame = AttachChild(new ButtonFrame(content));
        }
Exemplo n.º 9
0
 public void OnMouseEnter()
 {
     Hover?.Invoke(this, new EventArgs());
 }
Exemplo n.º 10
0
        public VisualInventorySlot(InventorySlotId slotId, IText amountSource, Func <IReadOnlyItemSlot> getSlot)
        {
            On <IdleClockEvent>(e => _frameNumber++);

            _slotId  = slotId;
            _getSlot = getSlot;
            _overlay = new UiSpriteElement(Base.CoreSprite.UiBroken)
            {
                IsActive = false
            };
            var text = new UiText(amountSource);

            if (!slotId.Slot.IsSpecial())
            {
                _size = slotId.Slot.IsBodyPart() ?
                        new Vector2(18, 18) : //16x16 surrounded by 1px borders
                        new Vector2(16, 20);
                _sprite = new UiSpriteElement(SpriteId.None);
                _button = AttachChild(new Button(new FixedPositionStack()
                                                 .Add(
                                                     new LayerStack(
                                                         _sprite,
                                                         _overlay),
                                                     1, 1, 16, 16) //16x16 surrounded by 1px borders
                                                 .Add(text, 0, 20 - 9, 16, 9))
                {
                    Padding = -1,
                    Margin  = 0,
                    Theme   = slotId.Slot.IsBodyPart()
                                ? (ButtonFrame.ThemeFunction)ButtonTheme.Default
                                : ButtonTheme.InventorySlot,

                    IsPressed = !slotId.Slot.IsBodyPart()
                }
                                      .OnHover(() => Hover?.Invoke())
                                      .OnBlur(() => Blur?.Invoke())
                                      .OnClick(() => Click?.Invoke())
                                      .OnRightClick(() => RightClick?.Invoke())
                                      .OnDoubleClick(() => DoubleClick?.Invoke())
                                      .OnButtonDown(() => ButtonDown?.Invoke()));
            }
            else
            {
                _sprite = new UiSpriteElement(
                    slotId.Slot == ItemSlotId.Gold
                        ? Base.CoreSprite.UiGold
                        : Base.CoreSprite.UiFood);

                _button = AttachChild(new Button(
                                          new VerticalStack(
                                              new Spacing(31, 0),
                                              _sprite,
                                              new UiText(amountSource)
                                              )
                {
                    Greedy = false
                })
                                      .OnHover(() => Hover?.Invoke())
                                      .OnBlur(() => Blur?.Invoke())
                                      .OnClick(() => Click?.Invoke())
                                      .OnRightClick(() => RightClick?.Invoke())
                                      .OnDoubleClick(() => DoubleClick?.Invoke())
                                      .OnButtonDown(() => ButtonDown?.Invoke()));
            }
        }
Exemplo n.º 11
0
 internal void RaiseHover(EventArgs args)
 {
     Hover.Invoke(this, args);
 }
Exemplo n.º 12
0
 protected virtual void OnHover(AbstractInteractable obj, Vector3 pos, bool isInRange)
 {
     Hover?.Invoke(obj, pos, isInRange);
 }
Exemplo n.º 13
0
 protected void onHover()
 {
     Hover?.Invoke(this, hoverIndex);
 }