Esempio n. 1
0
 protected void DragEnded()
 {
     IsDragging = false;
     DragBuffer = Vector2.Zero;
     OnDragEnded?.Invoke();
     RemoveTouch();
 }
Esempio n. 2
0
 private void DraggableItem_OnRelease()
 {
     if (IsDragging)
     {
         IsDragging = false;
         OnDragEnded.Invoke();
     }
 }
    private async Task OnDroppedCanceled()
    {
        _dragOperationIsInProgress = false;

        await OnDragEnded.InvokeAsync(Item);

        StateHasChanged();
    }
 private async Task DragEnded(DragEventArgs e)
 {
     if (_dragOperationIsInProgress == true)
     {
         _dragOperationIsInProgress = false;
         await Container?.CancelTransaction();
     }
     else
     {
         await OnDragEnded.InvokeAsync(Item);
     }
 }
Esempio n. 5
0
    void Update()
    {
        //Mouse
        bool  isMouse    = Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0);
        Touch mouseTouch = new Touch();

        mouseTouch.position = Input.mousePosition;
        mouseTouch.phase    = Input.GetMouseButton(0) ? UnityEngine.TouchPhase.Moved : mouseTouch.phase;
        mouseTouch.phase    = Input.GetMouseButtonDown(0) ? UnityEngine.TouchPhase.Began : mouseTouch.phase;
        mouseTouch.phase    = Input.GetMouseButtonUp(0) ? UnityEngine.TouchPhase.Ended : mouseTouch.phase;

        if (Input.touchCount != 1 && !isMouse && !drag.isDragging)
        {
            drag.isDragging = false;
            return;
        }



        Touch touch = isMouse ? mouseTouch : Input.touches[0];

        if (touch.phase == TouchPhase.Began)
        {
            drag.isDragging = true;
            drag.localStart = drag.localEnd = touch.position;
            drag.timeStart  = Time.time;
            OnDragBegan?.Invoke(drag);
        }
        if (drag.isDragging && touch.phase == TouchPhase.Moved)
        {
            drag.isDragging = true;
            drag.localEnd   = touch.position;
            drag.timeEnd    = Time.time;

            drag.DrawDebug(Color.white);
            OnDrag?.Invoke(drag);
        }
        if (drag.isDragging && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled))
        {
            drag.localEnd   = touch.position;
            drag.isDragging = false;
            drag.timeEnd    = Time.time;

            drag.DrawDebug(Color.red);

            OnDragEnded?.Invoke(drag);
        }
    }
Esempio n. 6
0
        public void UpdateDrag()
        {
            //Mouse
            bool  isMouse    = Input.GetMouseButton(index) || Input.GetMouseButtonDown(index) || Input.GetMouseButtonUp(index);
            Touch mouseTouch = new Touch();

            mouseTouch.position = Input.mousePosition;
            mouseTouch.phase    = Input.GetMouseButton(index) ? UnityEngine.TouchPhase.Moved : mouseTouch.phase;
            mouseTouch.phase    = Input.GetMouseButtonDown(index) ? UnityEngine.TouchPhase.Began : mouseTouch.phase;
            mouseTouch.phase    = Input.GetMouseButtonUp(index) ? UnityEngine.TouchPhase.Ended : mouseTouch.phase;

            if (Input.touchCount != 1 && !isMouse && !isDragging)
            {
                isDragging = false;
                return;
            }

            Touch touch = isMouse ? mouseTouch : Input.touches[0];

            if (touch.phase == TouchPhase.Began)
            {
                isDragging = true;
                localStart = localEnd = touch.position;
                OnDragBegan?.Invoke(this);
            }
            if (isDragging && touch.phase == TouchPhase.Moved)
            {
                isDragging = true;
                localEnd   = touch.position;

                //drag.DrawDebug(Color.white);

                OnDrag?.Invoke(this);
            }
            if (isDragging && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled))
            {
                localEnd   = touch.position;
                isDragging = false;

                //drag.DrawDebug(Color.red);

                OnDragEnded?.Invoke(this);
            }
        }
Esempio n. 7
0
        public DraggableItem Drop()
        {
            MouseState mouseState = Mouse.GetState();

            if (CurrentItem != null)
            {
                Rectangle rect = CurrentItem.GlobalBounds;
                rect.X = mouseState.X - rect.Width / 2;
                rect.Y = mouseState.Y - rect.Height / 2;

                GUIComponent drop = GetIntersectingSlot(rect);


                if (drop != null)
                {
                    foreach (GUIComponent slotDropper in IllegalDrags.Keys)
                    {
                        if (CurrentItem.HasAnscestor(slotDropper))
                        {
                            foreach (GUIComponent illegals in IllegalDrags[slotDropper].Keys)
                            {
                                if (drop.HasAnscestor(illegals))
                                {
                                    CurrentItem.Item.CurrentAmount += CurrentDragAmount;
                                    OnDragEnded.Invoke(CurrentItem, null, 0);
                                    return(null);
                                }
                            }
                        }
                    }

                    DraggableItem toReturn = null;
                    bool          wasNew   = false;
                    bool          success  = Drag(CurrentItem, CurrentDragAmount, drop, out toReturn, out wasNew);

                    if (!success)
                    {
                        CurrentItem.Item.CurrentAmount += CurrentDragAmount;
                        OnDragEnded.Invoke(CurrentItem, null, 0);
                        return(null);
                    }
                    else if (wasNew)
                    {
                        OnDragEnded.Invoke(CurrentItem, toReturn, CurrentDragAmount);
                        return(toReturn);
                    }
                    else
                    {
                        OnDragEnded.Invoke(CurrentItem, null, CurrentDragAmount);
                        return(null);
                    }
                }
                else
                {
                    CurrentItem.Item.CurrentAmount += CurrentDragAmount;
                    OnDragEnded.Invoke(CurrentItem, null, 0);
                    return(null);
                }
            }


            CurrentItem       = null;
            CurrentDragAmount = 0;
            OnDragEnded.Invoke(CurrentItem, null, 0);
            return(null);
        }
Esempio n. 8
0
 protected override void OnThumbDragCompleted(DragCompletedEventArgs e)
 {
     base.OnThumbDragCompleted(e);
     OnDragEnded?.Invoke(this, e);
 }