/// <summary>
    /// Checks is can drag any item or if can show UI
    /// </summary>
    /// <param name="ray"></param>
    private void CheckIfCanDrag(Ray ray)
    {
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, maxRayDistance, draggableLayerMask))
        {
            draggingObject = hit.transform.GetComponent <IDraggable>();
            if (draggingObject != null && draggingObject.CanDrag())
            {
                isMouseDragging = true;
                draggingObject.OnDragEvent(isMouseDragging);
                draggingTransform = hit.transform;
                originalPosition  = draggingTransform.position;
                positionOfScreen  = renderCamera.WorldToScreenPoint(originalPosition);
                offsetValue       = originalPosition - renderCamera.ScreenToWorldPoint(
                    new Vector3(Input.mousePosition.x, Input.mousePosition.y, positionOfScreen.z));
            }
        }
        if (Physics.Raycast(ray, out hit, maxRayDistance, inventoryLayerMask) && !isMouseDragging)
        {
            bagUI = hit.transform.GetComponent <IInventoryUICheckable>();
            if (bagUI != null)
            {
                bagUI.ShowUI();
                isCheckingUI = true;
            }
        }
    }
예제 #2
0
        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            CaptureMouse();

            var mousePixel = GetPixelPosition(e);

            plottableBeingDragged = plt.GetDraggableUnderMouse(mousePixel.X, mousePixel.Y);

            if (plottableBeingDragged is null)
            {
                // MouseDown event is to start a pan or zoom
                if (e.ChangedButton == MouseButton.Left && isAltPressed)
                {
                    mouseMiddleDownLocation = GetPixelPosition(e);
                }
                else if (e.ChangedButton == MouseButton.Left && enablePanning)
                {
                    mouseLeftDownLocation = GetPixelPosition(e);
                }
                else if (e.ChangedButton == MouseButton.Right && enableZooming)
                {
                    mouseRightDownLocation = GetPixelPosition(e);
                }
                else if (e.ChangedButton == MouseButton.Middle && enableScrollWheelZoom)
                {
                    mouseMiddleDownLocation = GetPixelPosition(e);
                }
                axisLimitsOnMouseDown = plt.Axis();
            }
            else
            {
                // mouse is being used to drag a plottable
            }
        }
    public void UpdateDragTarget()
    {
        PointerEventData pointerData = new PointerEventData(EventSystem.current)
        {
            pointerId = -1,
        };

        pointerData.position = Input.mousePosition;

        List <RaycastResult> results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(pointerData, results);

        for (int i = 0; i < results.Count; i++)
        {
            if (draggableMask == (draggableMask | (1 << results[i].gameObject.layer)))
            {
                target = results[i].gameObject.GetComponent <IDraggable>();
                if (target != null)
                {
                    targetTransform = results[i].gameObject.transform;
                    offset          = targetTransform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    break;
                }
            }
        }
    }
예제 #4
0
 private bool overlaps(int x, int y, IDraggable draggable)
 {
     return(x >= draggable.X &&
            x <= draggable.X + draggable.Width &&
            y >= draggable.Y &&
            y <= draggable.Y + draggable.Height);
 }
예제 #5
0
        public void MouseDrag(PointF mousePosition, MouseButtons button)
        {
            plottableBeingDragged = plt.GetDraggableUnderMouse(mousePosition.X, mousePosition.Y);

            if (plottableBeingDragged is null)
            {
                // MouseDown event is to start a pan or zoom
                if (button == MouseButtons.Left && isAltPressed)
                {
                    mouseMiddleDownLocation = mousePosition;
                }
                else if (button == MouseButtons.Left && enablePanning)
                {
                    mouseLeftDownLocation = mousePosition;
                }
                else if (button == MouseButtons.Right && enableZooming)
                {
                    mouseRightDownLocation = mousePosition;
                }
                else if (button == MouseButtons.Middle && enableScrollWheelZoom)
                {
                    mouseMiddleDownLocation = mousePosition;
                }
                rememberingAxisLimits = true;
                plt.GetSettings(false).RememberAxisLimits();
            }
            else
            {
                // mouse is being used to drag a plottable
            }
        }
        private void NodeDragMoved(IDraggable sender, DragEventArgs args, Event nativeEvent)
        {
            if (sender is BehaviorNodeControl)
            {
                BehaviorNodeControl node = sender as BehaviorNodeControl;

                switch (nativeEvent.button)
                {
                case 0:
                {
                    Vector2 newPos = node.Position + args.delta;

                    if (newPos.x >= 0.0f && newPos.y >= 0.0f)
                    {
                        node.SetPosition(newPos);
                    }
                }
                break;

                case 2:
                {
                    Vector2 newPos = node.Position + args.delta;

                    if (newPos.x >= 0.0f && newPos.y >= 0.0f)
                    {
                        DragHierarchy(node, args.delta);
                    }
                }
                break;
                }
            }
        }
예제 #7
0
        public void DropIn(IDraggable view)
        {
            var knob = (view as MonoBehaviour).GetComponentInParent <InputKnob>();

            using (var comm = new StateCommand("Add connection"))
                knob.SetInputConnection(GetComponentInParent <OutputKnob>());
        }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hitInfo;
            target = ReturnClickedObject(out hitInfo);
            if (target != null)
            {
                isDragging = true;

                target.OnDragged(
                    Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)));
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            isDragging = false;

            //target?.OnDropped(
            //    Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)));
        }

        if (isDragging)
        {
            //target?.OnDragStay(
            //    Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)));
        }
    }
예제 #9
0
        /// <summary>
        /// Begins dragging the given <paramref name="draggable"/> so long as the <see cref="CurrentDraggable"/> is null. Uses the given <paramref name="offset"/> when keeping the draggable pinned to the mouse.
        /// Calls <see cref="IDraggable.OnDragBegin(Point)"/> with the given <paramref name="offset"/> and sets the <see cref="CurrentDraggable"/> to its return value.
        /// </summary>
        /// <param name="draggable"></param>
        /// <param name="offset"></param>
        public bool BeginDragging(IDraggable draggable, Point offset)
        {
            // Return false if the state is invalid.
            if (draggable == null || CurrentDraggable != null)
            {
                return(false);
            }

            // Begin dragging the given draggable.
            IDraggable newDraggable = draggable.OnDragBegin(offset, out Point newOffset);

            // If the given draggable returned a null value, return false.
            if (newDraggable == null)
            {
                return(false);
            }

            // Set the current draggable and offset.
            CurrentDraggable = newDraggable;
            DraggableOffset  = newOffset;
            DraggableOrigin  = CurrentDraggable.Bounds.AbsoluteTotalPosition;

            // Return true as the dragging was begun.
            return(true);
        }
예제 #10
0
 public void NotifyDragEnter(IDraggable obj, ScrumGestures.TouchPoint pt)
 {
     this.Invoke(() =>
     {
         this.Effect = Controls.Style.StyleHelper.GetOuterGlow(Controls.Style.Colors.ObjectGlowShared);
     });
 }
예제 #11
0
 public void OnDragCancelled()
 {
     _currentDraggable = null;
     foreach (IDragAndDropNode node in _nodes) {
         node.OnDragCancelled();
     }
 }
예제 #12
0
        private void PbPlot_MouseDown(object sender, MouseEventArgs e)
        {
            var mousePixel = e.Location;

            plottableBeingDragged = plt.GetDraggableUnderMouse(mousePixel.X, mousePixel.Y);

            if (plottableBeingDragged is null)
            {
                // MouseDown event is to start a pan or zoom
                if (e.Button == MouseButtons.Left && ModifierKeys.HasFlag(Keys.Shift))
                {
                    mouseMiddleDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Left && enablePanning)
                {
                    mouseLeftDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Right && enableZooming)
                {
                    mouseRightDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    mouseMiddleDownLocation = e.Location;
                }
                axisLimitsOnMouseDown = plt.Axis();
            }
            else
            {
                // mouse is being used to drag a plottable
                OnMouseDownOnPlottable(EventArgs.Empty);
            }
        }
예제 #13
0
 public void OnDropObject(GameObject dropped, IDraggable draggable)
 {
     draggable.Coffee = new BlackCoffee();
     Debug.Log(dropped.name + " dropped onto: " + gameObject.name + '\n' +
               "The " + dropped.name + " now contains " + draggable.Coffee.Name);
     StartCoroutine(brew(dropped));
 }
예제 #14
0
 public void AddDraggable(IDraggable draggable)
 {
     if (!activeDraggables.Contains(draggable))
     {
         activeDraggables.Add(draggable);
     }
 }
예제 #15
0
        protected override void MouseMove(MapDocument document, MapViewport viewport, OrthographicCamera camera, ViewportEvent e)
        {
            if (e.Dragging || e.Button == MouseButtons.Left)
            {
                return;
            }
            var point = camera.ScreenToWorld(e.X, e.Y);

            point = camera.Flatten(point);
            IDraggable drag = null;

            foreach (var state in States)
            {
                var drags = state.GetDraggables().ToList();
                drags.Add(state);
                foreach (var draggable in drags)
                {
                    if (draggable.CanDrag(document, viewport, camera, e, point))
                    {
                        drag = draggable;
                        break;
                    }
                }
                if (drag != null)
                {
                    break;
                }
            }
            if (drag != CurrentDraggable)
            {
                CurrentDraggable?.Unhighlight(document, viewport);
                CurrentDraggable = drag;
                CurrentDraggable?.Highlight(document, viewport);
            }
        }
예제 #16
0
 public DragSettings(bool left, IDraggable firstDragged, IDraggable draggable, float direction)
 {
     this.left         = left;
     this.firstDragged = firstDragged;
     this.draggable    = draggable;
     this.direction    = direction;
 }
예제 #17
0
 public void RemoveDraggable(IDraggable draggable)
 {
     if (activeDraggables.Contains(draggable))
     {
         activeDraggables.Remove(draggable);
     }
 }
예제 #18
0
        private static bool MoveDraggable([CanBeNull] FrameworkElement element, [CanBeNull] IDraggable draggable)
        {
            if (element == null || draggable == null)
            {
                return(false);
            }

            try {
                _dragging = true;

                var data = new DataObject();
                data.SetData(draggable.DraggableFormat, draggable);
                MarkDestinations(draggable.DraggableFormat);
                Events.RaiseDragStarted(draggable.DraggableFormat, draggable);

                var source = PrepareItem(element);
                if (source != null)
                {
                    data.SetData(SourceFormat, source);
                }

                using (new DragPreview(element)) {
                    DragDrop.DoDragDrop(element, data, DragDropEffects.Move);
                }
            } finally {
                _dragging = false;
                UnmarkDestinations();
                Events.RaiseDragEnded(draggable.DraggableFormat, draggable);
            }

            return(true);
        }
예제 #19
0
 public void NotifyDragExit(IDraggable obj, ScrumGestures.TouchPoint pt)
 {
     this.Invoke(() =>
     {
         this.Effect = null;
     });
 }
예제 #20
0
        public void DragComplete(IDraggable draggable)
        {
            if (draggable == null)
            {
                return;
            }

            if (draggable == dragConnection)
            {
                var target = getDraggableAt(dragConnection.X, dragConnection.Y);

                if (target is SignalSourceViewModel && draggedPort is SignalSinkViewModel)
                {
                    connect(target as SignalSourceViewModel, draggedPort as SignalSinkViewModel);
                }
                else if (target is SignalSinkViewModel && draggedPort is SignalSourceViewModel)
                {
                    connect(draggedPort as SignalSourceViewModel, target as SignalSinkViewModel);
                }

                dragConnection = null;
                draggedPort    = null;

                Refresh();
            }
        }
예제 #21
0
 public virtual void AddItem(IDraggable item)
 {
     if (item != null)
     {
         PlaceItem(item);
     }
 }
예제 #22
0
            public DragImplementor(IDraggable draggable, IDragOp.Create dragFactory)
            {
                this.draggable   = draggable;
                this.dragFactory = dragFactory;

                draggable.DetachedFromVisualTree +=
                    (s, e) => Cancel();
            }
 public void OnEndDrag(PointerEventData eventData)
 {
     draggableBuilding?.EndDrag();
     draggableBuilding     = null;
     buildingEntity        = null;
     isInteractable        = false;
     backgroundImage.color = Color.grey;
 }
예제 #24
0
 public MinDistanceDragOp(IDraggable draggable, Point point, int minDragDistance, IDragOp.Create dragFactory)
     : base(null)
 {
     this.draggable     = draggable;
     this.startingPoint = point;
     this.dragFactory   = dragFactory;
     minDistSquared     = minDragDistance * minDragDistance;
 }
예제 #25
0
 public virtual void SwapItems(ISlot slotA, ISlot slotB)
 {
     if (slotA != null && slotB != null)
     {
         IDraggable itemA = slotB.Item;
         IDraggable itemB = slotB.Item;
     }
 }
예제 #26
0
 public void NotifyDragDrop(IDraggable obj, ScrumGestures.TouchPoint pt)
 {
     ((UserStoryControl)obj).UserStory.Effort.Value = this.Effort.Value;
     ((UserStoryControl)obj).UserInterface.UpdateData(((UserStoryControl)obj).UserStory);
     this.Invoke(() =>
     {
         this.Effect = null;
     });
 }
예제 #27
0
 public PlottableDragEvent(float x, float y, bool shiftDown, IDraggable plottable, Plot plt, Configuration config)
 {
     X                     = x;
     Y                     = y;
     ShiftDown             = shiftDown;
     Plot                  = plt;
     PlottableBeingDragged = plottable;
     Configuration         = config;
 }
예제 #28
0
        protected virtual void DestroyItem()
        {
            if (Item != null)
            {
                Destroy(Item.ThisGameObject);
            }

            Item = null;
        }
예제 #29
0
    public void OnReceiveObject(IDraggable draggable, GameObject gameObject)
    {
        if (CoffeeWishes.Count == 0)
        {
            Say("Uhm, I haven't ordered yet", stolenDialogueHandler, stolenDialogueObject);
            return;
        }
        if (draggable.Coffee == null)
        {
            Say("There's no coffee", stolenDialogueHandler, stolenDialogueObject);
            return;
        }

        if (draggable.Coffee?.GetType() == CoffeeWishes[currentCoffeeWishIndex].coffeeType)
        {
            GameManager.Instance.AddToCurrency(CoffeeWishes[currentCoffeeWishIndex].payment);
            gameObject.SetActive(false);
            Say("Wow, thanks, that's exactly what I DIDN'T order", stolenDialogueHandler, stolenDialogueObject);
            Speech speech = behaviour.speeches[1];
            if (speech != null)
            {
                foreach (Entry statement in speech.statements)
                {
                    if (System.Enum.TryParse(statement.moodChange?.ToLower().Trim(), out Pose poseks))
                    {
                        changePose(poseks);
                    }
                    else if (string.IsNullOrEmpty(statement.moodChange))
                    {
                        Debug.Log("Pose defined in XML but not recognized");
                    }

                    if (statement.choice.Count == 0)
                    {
                        Say(statement.text, stolenDialogueHandler, stolenDialogueObject);
                    }
                    else
                    {
                        string[] answerStrings = new string[4];
                        int?[]   answerValues  = new int?[4];
                        for (int i = 0; i < (statement.choice.Count > 4 ? 4 : statement.choice.Count); i++)
                        {
                            answerStrings[i] = statement.choice[i].value;
                            answerValues[i]  = statement.choice[i].result;
                        }
                        Say(statement.text, stolenDialogueHandler, stolenDialogueObject);
                        stolenDialogueHandler.SetQuestions(answerStrings, answerValues);
                    }
                }
            }
            if (System.Enum.TryParse("drinking".ToLower().Trim(), out Pose pose))
            {
                changePose(pose);
            }
        }
        //GameManager.Instance.SetTalking(false);
    }
예제 #30
0
        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ReleaseMouseCapture();
            var mouseLocation = GetPixelPosition(e);

            plottableBeingDragged = null;

            if (mouseMiddleDownLocation != null)
            {
                double x1 = Math.Min(mouseLocation.X, ((Point)mouseMiddleDownLocation).X);
                double x2 = Math.Max(mouseLocation.X, ((Point)mouseMiddleDownLocation).X);
                double y1 = Math.Min(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y);
                double y2 = Math.Max(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y);

                Point topLeft  = new Point(x1, y1);
                Size  size     = new Size(x2 - x1, y2 - y1);
                Point botRight = new Point(topLeft.X + size.Width, topLeft.Y + size.Height);

                if ((size.Width > 2) && (size.Height > 2))
                {
                    // only change axes if suffeciently large square was drawn
                    plt.Axis(
                        x1: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).X,
                        x2: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).X,
                        y1: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).Y,
                        y2: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).Y
                        );
                    AxisChanged?.Invoke(null, null);
                }
                else
                {
                    plt.AxisAuto();
                    AxisChanged?.Invoke(null, null);
                }
            }

            if (mouseRightDownLocation != null)
            {
                double deltaX          = Math.Abs(mouseLocation.X - mouseRightDownLocation.Value.X);
                double deltaY          = Math.Abs(mouseLocation.Y - mouseRightDownLocation.Value.Y);
                bool   mouseDraggedFar = (deltaX > 3 || deltaY > 3);
                ContextMenu.Visibility = (mouseDraggedFar) ? Visibility.Hidden : Visibility.Visible;
                ContextMenu.IsOpen     = (!mouseDraggedFar);
            }
            else
            {
                ContextMenu.IsOpen = false;
            }

            mouseLeftDownLocation    = null;
            mouseRightDownLocation   = null;
            mouseMiddleDownLocation  = null;
            axisLimitsOnMouseDown    = null;
            settings.mouseMiddleRect = null;
            Render(recalculateLayout: true);
        }
예제 #31
0
 public void Remove(IDraggable obj)
 {
     ItemIcon ic = obj as ItemIcon;
     if (ic != null)
     {
         this.RemoveChild(ic);
         _player.Body.Unequip(ic.Item as Logic.Body.BodyPart, true);
     }
     Update();
 }
예제 #32
0
        void Awake()
        {
            caller = GetComponent <IDraggable>();
            if (caller == null)
            {
                DragManager.LogError("Couldn't find IDraggable in the gameObject with Draggable component.");
            }

            DragManager.Instance.AllDraggables.Add(this);
        }
예제 #33
0
 public void Remove(IDraggable item)
 {
     ItemIcon ii = item as ItemIcon;
     if (ii != null)
     {
         _inventory.Remove(ii.Item, true);
         RemoveChild(item as UIElement);
         UpdateContent();
     }
 }
예제 #34
0
 public bool OnDrop(IDraggable draggable)
 {
     var newValue = draggable as DragAndDropTestDraggable;
     if (newValue != null) {
         Text = newValue.Text;
         _displayableText = Text;
         return true;
     }
     return false;
 }
예제 #35
0
 public void StartDragging(IDragAndDropNode startNode)
 {
     _currentDraggable = startNode.GetDraggable();
     if (_currentDraggable != null) {
         _startNode = startNode;
         foreach (IDragAndDropNode node in _nodes) {
             if (!node.Equals(startNode))
                 node.OnDragStarted(_currentDraggable);
         }
     }
 }
예제 #36
0
    // Return bool that tells camera to stop or procced with moving
    public static bool DispatchDrag(IDraggable draggableComponent, Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);

        Plane hPlane = new Plane(Vector3.up, Vector3.zero);
        float distance = 0;
        if (hPlane.Raycast(ray, out distance)){
            Vector3 pointerPosition = ray.GetPoint(distance);

            return draggableComponent.OnDragMove(pointerPosition);
        }
        return false;
    }
예제 #37
0
파일: UIElement.cs 프로젝트: MyEyes/Igorr
 public bool TryDrop(UIElement caller, IDraggable obj)
 {
     IDroppable drop = this as IDroppable;
     if(drop!=null && obj.Rect.Intersects(new Rectangle((int)TotalOffset.X,(int)TotalOffset.Y,(int)_size.X,(int)_size.Y)))
     {
         if (drop.Drop(obj))
             return true;
     }
     for (int x = 0; x < _childs.Count; x++)
         if (_childs[x] != caller) if (_childs[x].TryDrop(this, obj)) return true;
     if (_parent!=null && _parent != caller)
         if (_parent.TryDrop(this, obj)) return true;
     return false;
 }
예제 #38
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="defaultItem">規定の描画オブジェクト</param>
        public DrawingManager(IDraggable defaultItem)
        {
            this.DefaultItem = defaultItem;
              this.Items = new List<IDraggable>();
              this.Disposables = new CompositeDisposable();
              this.Selectables = Enumerable.Empty<ISelectable>();
              this.SelectedItems = new CompositeDraggable(Enumerable.Empty<IDraggable>());
              DrawingManager.Selector.Dropped += (o, e) =>
              {
            var selectBounds = (o as Shape).Bounds.Abs();
            foreach (ISelectable shape in this.Items.OfType<ISelectable>())
              shape.SelectBy(selectBounds);

            SelectedItems = new CompositeDraggable(
              this.Selectables.Where(item => item.IsSelected).OfType<IDraggable>());
              };
        }
예제 #39
0
 public bool Drop(IDraggable item)
 {
     ItemIcon ii = item as ItemIcon;
     if (ii == null || ii.Item==null)
         return false;
     UIElement element = item as UIElement;
     Vector2 relPos = element.TotalOffset - this.TotalOffset + 0.5f * new Vector2(item.Rect.Width, item.Rect.Height);
     if (relPos.X < sideOffset || relPos.X > _size.X - sideOffset || relPos.Y < 0 || relPos.Y > _size.Y)
         return false;
     int rowLength = (int)((_size.X - 2 * sideOffset) / (partSize * iconSpread));
     int row = (int)((relPos.Y - 15) / (partSize * iconSpread));
     int column = (int)((relPos.X - sideOffset) / (partSize * iconSpread));
     column = column >= 0 ? column : 0;
     column = column < rowLength ? column : rowLength - 1;
     int index = column + row * rowLength;
     item.Drop(this);
     _inventory.Insert(ii.Item, index, true);
     UpdateContent();
     return true;
 }
 /// <summary>
 /// Constructor for WindowManipulationException
 /// </summary>
 /// <param name="window">The IWindow object related to the exception.  null if not specifically related to any registered windows.</param>
 /// <param name="message">Description of the error message.</param>
 public DraggableException(IDraggable window, string message)
 {
     _message = message;
     _win = window;
 }
예제 #41
0
 public void OnDragStarted(IDraggable draggable)
 {
     _displayableText = "Дропни в меня!";
 }
        /// <summary>
        /// registers an IDraggable to the class
        /// </summary>
        /// <param name="draggableToRegister"></param>
        protected void RegisterDraggable(IDraggable draggableToRegister)
        {
            //window element required.
            if (draggableToRegister.DragElement == null)
                throw new DraggableException(draggableToRegister, "Window Element is null or otherwise not defined.");

            //assign drag handle if exists, otherwise default to the entire DragElement as begin draggable.
            var handle = draggableToRegister.DragHandle ?? draggableToRegister.DragElement;

            if (ClickTargetLookup.ContainsKey(handle)) return;

            handle.MouseLeftButtonDown += DragMouseLeftButtonDown;
            ClickTargetLookup.Add(handle, draggableToRegister);
        }
        private void NodeDragMoved( IDraggable sender, DragEventArgs args, Event nativeEvent )
        {
            if ( sender is BehaviorNodeControl )
            {
                BehaviorNodeControl node = sender as BehaviorNodeControl;

                switch( nativeEvent.button )
                {
                    case 0:
                    {
                        Vector2 newPos = node.Position + args.delta;

                        if ( newPos.x >= 0.0f && newPos.y >= 0.0f )
                        {
                            node.SetPosition( newPos );
                        }
                    }
                    break;

                    case 2:
                    {
                        Vector2 newPos = node.Position + args.delta;

                        if ( newPos.x >= 0.0f && newPos.y >= 0.0f )
                        {
                            DragHierarchy( node, args.delta );
                        }
                    }
                    break;
                }
            }
        }
예제 #44
0
 private void AddItem(IDraggable item)
 {
     Items.Add(item);
       Selectables = Items.OfType<ISelectable>();
 }
예제 #45
0
        public static void MouseUp(Vector2 position)
        {
            //lastMouseDownPos = position;
            switch (Mousemode)
            {
                case MouseMode.Select:
                    CurrentObject = null;
                    CurrentObjectOffset = Vector2.Zero;
                    break;

                case MouseMode.DrawRectangle:
                    tempRectangle.BottomRight = position;
                    tempRectangle.Width = Math.Abs(tempRectangle.Width);
                    tempRectangle.Height = Math.Abs(tempRectangle.Height);
                    //CurrentLevel.Rectangles.Add(tempRectangle);
                    //tempRectangle = PhysicsRectangle.Empty;
                    Mousemode = MouseMode.DrawRectangleRotate;
                    rotatePoint = tempRectangle.Position;
                    break;
            }
        }
예제 #46
0
        public static void MouseDown(Vector2 position)
        {
            //lastMouseDownPos = position;
            switch (Mousemode)
            {
                case MouseMode.Select:
                    //if (GetCircleAABB(startPoint.Position, StartPoint.radius).Contains((int)position.X, (int)position.Y))
                    //startPoint.SetPosition(position);
                    if (GetCircleAABB(startPoint.Position, StartPoint.radius).ContainsVector(position))
                    //if (startPoint.ContainsPoint(position))
                    {
                        CurrentObject = startPoint;
                        CurrentObjectOffset =  CurrentObject.GetPosition() - position;
                    }
                    break;

                case MouseMode.DrawRectangle:
                    tempRectangle = new PhysicsRectangle(position, position *2, 0);
                    tempRectangle.TopLeft = position;
                    break;
                case MouseMode.DrawRectangleRotate:
                    //tempRectangle = new PhysicsRectangle(position, Vector2.Zero, 0);
                    tempRectangle.Rotation = (float)Math.Atan2(rotatePoint.Y - position.Y, rotatePoint.X - position.X);
                    CurrentLevel.Rectangles.Add(tempRectangle);
                    tempRectangle = PhysicsRectangle.Empty;
                    Mousemode = MouseMode.Select;
                    break;
            }
        }
 /// <summary>
 /// Called when drag operation starts
 /// </summary>
 /// <param name="draggable"></param>
 protected virtual void OnDragStarted(IDraggable draggable)
 {
     if (DragStarted != null) DragStarted(this, new DraggableEventArgs(draggable));
 }
예제 #48
0
        public IDraggable BeginDragAt(int x, int y)
        {
            var draggable = getDraggableAt(x, y);

            if (draggable is SignalSinkViewModel)
            {
                var sink = draggable as SignalSinkViewModel;
                if (sink.Sink.Source != null)
                {
                    draggedPort = getSourceModelForSink(sink);

                    disconnect(sink);

                    dragConnection = new DragConnection
                    {
                        X = sink.X,
                        Y = sink.Y,
                        Width = sink.Width,
                        Height = sink.Height
                    };
                    return dragConnection;
                }
            }

            if (draggable is SignalSinkViewModel
                || draggable is SignalSourceViewModel)
            {

                draggedPort = draggable;
                dragConnection = new DragConnection
                {
                    X = draggable.X,
                    Y = draggable.Y,
                    Width = draggable.Width,
                    Height = draggable.Height
                };
                return dragConnection;
            }

            return draggable;
        }
예제 #49
0
	void selectAndDrag (bool userFingerUp, bool userFingerDown, bool userFingerPressed)
	{
		RaycastHit hit;
		Ray ray = Camera.main.ScreenPointToRay (pointerPosition);
		int layerMask =~(1 << 10);
		if (Physics.Raycast (ray, out hit, Mathf.Infinity, layerMask))
		{
			if (userFingerDown)
			{
				latestFingerDownPosition = pointerPosition;
				withinDeadZone = true;
								
				draggableComponent = DragGameObject.GetDraggable (hit.transform.gameObject);
				if (draggableComponent != null && SelectGameObject.GetObjectByIndex (0) == draggableComponent && draggableComponent.IsPlaceholder)
				{
					lockCameraMovement = true;
				}
				else
				{
					lockCameraMovement = false;
				}
			}

			// Once we leave the deadzone, we don't check this anymore until the next touch/mouse down.
			if(userFingerPressed && withinDeadZone)
			{
				float draggedDistance = Vector3.Distance(latestFingerDownPosition, pointerPosition);
				if(draggedDistance > deadZoneThreshold)
				{
					withinDeadZone = false;
				}
			}

			if (userFingerUp)
			{
				GameObject hitObject = hit.collider.transform.gameObject;
				// If we have not move a screen
				if (withinDeadZone)
				{
					if (hitObject.name == "Terrain")
					{
						if(commandableComponent != null)
						{
							// A commandable unit is selected, and we hit the terrain. Move that unit to this position.
							CommandGameObject.DispatchMoveCommand(commandableComponent, hit.point);
						}
						
						//Deselect all objects, whether we are commanding or not.
						SelectGameObject.DeselectAll ();
					}
					else if (hitObject.name == "OkButton" || hitObject.name == "CancelButton")
					{
						// hitObject is the button--> its parent is the button container --> and its parent is the building.
						GameObject parentGameObject = hitObject.transform.parent.transform.parent.gameObject;
						if(hitObject.name == "OkButton")
						{
							if(draggableComponent.CurrentPositionValid)
							{
								JSTrigger.StartBuildingConstruction (parentGameObject);
							}
							else
							{
								print ("Invalid construction site!! derp");
							}
						}
						else
						{
							Destroy(parentGameObject);
						}
					}
					else
					{
						SelectGameObject.Dispatch (hitObject);
						commandableComponent = CommandGameObject.GetCommandable(hitObject);
					}
				}

				if (draggableComponent != null && draggingOccured)
				{
					DragGameObject.DispatchDragStop (draggableComponent);
					draggingOccured = false;
				}
				draggableComponent = null;
				withinDeadZone = true;
			}
		}

		if (draggableComponent != null)
		{
			if (!withinDeadZone && draggableComponent.IsPlaceholder)
			{
				lockCameraMovement = DragGameObject.DispatchDrag (draggableComponent, pointerPosition);
				draggingOccured = lockCameraMovement;
			}
		}
		else
		{
			lockCameraMovement = false;
		}
	}
예제 #50
0
 private void StopDragging()
 {
     IDragAndDropNode dropNode = FindNode(_lastTouchPosition);
     if (dropNode != null)
         OnDrop(dropNode);
     else
         CancelDrag();
     _currentDraggable = null;
 }
예제 #51
0
 public static void DispatchDragStop(IDraggable draggableComponent)
 {
     draggableComponent.OnDragStop();
 }
예제 #52
0
 private bool overlaps(int x, int y, IDraggable draggable)
 {
     return x >= draggable.X
             && x <= draggable.X + draggable.Width
             && y >= draggable.Y
             && y <= draggable.Y + draggable.Height;
 }
        /// <summary>
        /// Unregisters a IDraggable object from the class
        /// </summary>
        /// <param name="draggableToUnRegister"></param>
        protected void UnRegisterDraggable(IDraggable draggableToUnRegister)
        {
            var handle = draggableToUnRegister.DragHandle ?? draggableToUnRegister.DragElement;

            if (!ClickTargetLookup.ContainsKey(handle)) return;

            handle.MouseLeftButtonDown -= DragMouseLeftButtonDown;
            ClickTargetLookup.Remove(handle);
        }
예제 #54
0
        public void DragComplete(IDraggable draggable)
        {
            if (draggable == null) return;

            if (draggable == dragConnection)
            {
                var target = getDraggableAt(dragConnection.X, dragConnection.Y);

                if (target is SignalSourceViewModel && draggedPort is SignalSinkViewModel)
                {
                    connect(target as SignalSourceViewModel, draggedPort as SignalSinkViewModel);
                }
                else if (target is SignalSinkViewModel && draggedPort is SignalSourceViewModel)
                {
                    connect(draggedPort as SignalSourceViewModel, target as SignalSinkViewModel);
                }

                dragConnection = null;
                draggedPort = null;

                Refresh();
            }
        }
 /// <summary>
 /// Constructor requiring IWindow object on which the event is occurrirng
 /// </summary>
 /// <param name="draggable"></param>
 public DraggableEventArgs(IDraggable draggable)
 {
     Source = draggable;
 }
예제 #56
0
    void selectAndDrag(Vector3 pointerPosition, bool userFingerUp, bool userFingerDown, bool userFingerPressed)
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay (pointerPosition);

        if (Physics.Raycast (ray, out hit))
        {
            if (userFingerDown)
            {
                latestFingerDownPosition = pointerPosition;
                withinDeadZone = true;

                if (hit.transform.gameObject.name == "Terrain")
                {
                    terrainPointed = pointerPosition;
                }

                draggableComponent = DragGameObject.GetDraggable (hit.transform.gameObject);
                if (draggableComponent != null && SelectGameObject.GetObjectByIndex (0) == draggableComponent)
                {
                    lockCameraMovement = true;
                }
                else
                {
                    lockCameraMovement = false;
                }
            }

            // Once we leave the deadzone, we don't check this anymore until the next touch/mouse down.
            if(userFingerPressed && withinDeadZone)
            {
                float draggedDistance = Vector3.Distance(latestFingerDownPosition, pointerPosition);
                if(draggedDistance > deadZoneThreshold)
                {
                    withinDeadZone = false;
                    deadZoneLeavePosition = pointerPosition;
                }
            }

            if (userFingerUp)
            {
                // Deselect all objects
                if (hit.transform.gameObject.name == "Terrain")
                {
                    if (withinDeadZone)
                    {
                        SelectGameObject.DeselectAll ();
                    }
                }
                // If we have not move a screen
                if (withinDeadZone)
                {
                    SelectGameObject.Dispatch (hit.transform.gameObject);
                }

                if (draggableComponent != null && draggingOccured)
                {
                    DragGameObject.DispatchDragStop (draggableComponent);
                    draggingOccured = false;
                }

                draggableComponent = null;
                withinDeadZone = true;
            }
        }

        if (draggableComponent != null)
        {
            if (!withinDeadZone)
            {
                lockCameraMovement = DragGameObject.DispatchDrag (draggableComponent, pointerPosition);
                draggingOccured = lockCameraMovement;
            }
        }
        else
        {
            lockCameraMovement = false;
        }
        latestDragCameraPosition = pointerPosition;
    }