/// <summary> /// Drop event to call the respective classes to handle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AssociatedObject_Drop(object sender, DragEventArgs e) { if (dataType != null) { //if the data type can be dropped if (e.Data.GetDataPresent(dataType)) { //drop the data IDropable target = AssociatedObject.DataContext as IDropable; if (target.CanDrop) { target.Drop(e.Data.GetData(dataType)); //remove the data from the source IDragable source = e.Data.GetData(dataType) as IDragable; source.Remove(e.Data.GetData(dataType)); } } } if (adorner != null) { adorner.Remove(); } e.Handled = true; return; }
public void DoDrop(UnityEngine.GameObject go) { if (go == null) { return; } IDragable dragObj = go.GetComponent <DragItem>(); if (dragObj == null) { return; } string type = dragObj.DragType; if (type.Equals(DRAG_TYPE)) { } else if (type.Equals(BagItem.DRAG_TYPE)) { if (DragItem.mDraggedItem != null) { EquipInfo equipVo = DragItem.mDraggedItem as EquipInfo; if (equipVo.PutWhere == PutWhere) { BagLogic.GetInstance().LoadEquip(equipVo.Position, equipVo.PutWhere); } } } else { return; } }
public SimulationModeItemManager(ContextMenuStrip contextMenuStrip, CarModelGraphicControl graphicControl) { model = new CarModel(new CarModelState(new PointD(ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X), ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)), new PointD(0, 1))); finish = new FinishModel(new PointD(ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X), ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)), 0); obstacles = new List<ObstacleModel>(); dragables = new List<IDragable>(); sampledCarState = model.state; dragables.Add(model); dragables.Add(finish); dragged = null; state = State.NONE; this.contextMenuStrip = contextMenuStrip; this.graphicControl = graphicControl; contextMenuStrip.Items[0].Click += new EventHandler(newObstacle); contextMenuStrip.Items[1].Click += new EventHandler(deleteObstacle); }
public void DoDrop(UnityEngine.GameObject go) { if (go == null) { return; } IDragable dragObj = go.GetComponent <DragItem>(); string type = dragObj.DragType; if (type.Equals(DRAG_TYPE)) { if (DragItem.mDraggedItem != null) { BagLogic.GetInstance().ExChangeItem((DragItem.mDraggedItem as ItemInfo).Position, slot); } } else if (type.Equals(EquipItem.DRAG_TYPE)) { if (DragItem.mDraggedItem != null) { //int target = BagManager.GetInstance().GetNullPosition(); int target = BagLogic.GetInstance().GetNullPosition(); if (target != -1) { BagLogic.GetInstance().UnLoadEquip((DragItem.mDraggedItem as EquipInfo).PutWhere, slot); } else { Debug.Log("背包已满"); } } } }
void AssociatedObject_Drop(object sender, DragEventArgs e) { if (_dataType != null) { //if the data type can be dropped if (e.Data.GetDataPresent(_dataType)) { //drop the data IDropable target = AssociatedObject.DataContext as IDropable; //var point = e.GetPosition(this.AssociatedObject.DataContext as IInputElement); if (target != null) { target.Drop(e.Data.GetData(_dataType), e); } //remove the data from the source IDragable source = e.Data.GetData(_dataType) as IDragable; if (source != null) { source.Remove(e.Data.GetData(_dataType)); } } } //if (this.adorner != null) // this.adorner.Remove(); e.Handled = true; }
/// <summary> /// Tries to set new content to this socket. /// If <paramref name="content"/>'s key matches one of keys in this socket, /// returns true and set content. If not, returns false. /// If <paramref name="force"/> is true, set this content no matter what key it has. /// </summary> /// <returns><c>true</c>, if content was set, <c>false</c> otherwise.</returns> /// <param name="content">Content.</param> /// <param name="force">If set to <c>true</c> force.</param> public bool SetContent(IDragable content, bool force = false) { bool passed = MatchKey(content); if (passed || force) { DragSocket otherSocket = content.GetSocket(); if (otherSocket != null) { otherSocket.ResetContent(); // If this socket already have content, exchange content with given content's socket. if (this.content != null) { if (!otherSocket.SetContent((IDragable)this.content)) { otherSocket.SetContent(content, true); return(false); // If setting socket is failed, return false. } components.Clear(); } } if (components.Count > 0) { return(false); } components.Add((GUIComponent)content); content.ChangeSocket(this); return(true); } return(false); }
public SimulationModeItemManager(ContextMenuStrip contextMenuStrip, CarModelGraphicControl graphicControl) { model = new CarModel(new CarModelState(new PointD(ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X), ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)), new PointD(0, 1))); finish = new FinishModel(new PointD(ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X), ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)), 0); obstacles = new List <ObstacleModel>(); dragables = new List <IDragable>(); sampledCarState = model.state; dragables.Add(model); dragables.Add(finish); dragged = null; state = State.NONE; this.contextMenuStrip = contextMenuStrip; this.graphicControl = graphicControl; contextMenuStrip.Items[0].Click += new EventHandler(newObstacle); contextMenuStrip.Items[1].Click += new EventHandler(deleteObstacle); }
/// <summary> /// Handle touch on object /// </summary> /// <param name="position"></param> /// <param name="fingerId"></param> private void BeginTouch(Vector3 position, int fingerId) { var worldPosition = Camera.main.ScreenToWorldPoint(position); var hitInfo = Physics2D.Raycast(worldPosition, Vector2.zero); if (hitInfo) { var touchable = hitInfo.transform.GetComponent <ITouchable>(); if (touchable != null) { touchable.OnTouch(); } if (_dragObject == null) { var dragable = hitInfo.transform.GetComponent <IDragable>(); if (dragable != null) { _dragObject = dragable; _touchId = fingerId; _dragObject.OnDrag(worldPosition); } } } }
void EndDrag() { if (_currentDragable != null) { _currentDragable.OnDragEnd(FindDropReceiver(), _pointerDataProvider); } _currentDragable = null; }
void RegisterDrag(IDragable dragged) { if (draggedObjects.Contains(dragged)) { return; } draggedObjects.Add(dragged); }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (_dragged != null) { _dragged.EndDrag(); } _dragged = null; Invalidate(); }
/// <summary> /// Clear drag object /// </summary> private void ClearDrag() { if (_dragObject != null) { _dragObject.OnDragEnded(); } _dragObject = null; _touchId = -1; }
private void OnClickItem(GameObject go) { IDragable item = go.GetComponent <DragItem>(); ItemInfo itemVO = item.DragItemVO as ItemInfo; if (itemVO != null) { EventDispatcher.GameWorld.Dispath(ControllerCommand.OPEN_BAGITEMCLICK_PANEL, new object[] { itemVO.Position, go.transform }); } }
public bool MatchKey(IDragable content) { foreach (string key in keys) { if (content.GetKey() == key) { return(true); } } return(false); }
protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { _mouseDown = e.Location; var p = ToClient(e.Location); var hitted = _nodes.FirstOrDefault(n => n.Hit(p)); if (hitted != null) { _dragged = hitted.StartDrag(p); } } }
public bool SetContent(int index, IDragable content, bool force = false) { if (index >= size || index < 0) { return(false); } if (components[index] is NullGUIComponent) { return(false); } return(((DragSocket)components[index]).SetContent(content, force)); }
public bool Begin(IDragable dragable) { if (null == dragable) { return(false); } mDragable = dragable; mDragable.OnDragOut(); return(true); }
protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { mouseDown = e.Location; var p = ToClient(e.Location); //ищем объект под мышкой var hitted = model.OfType <IDragable>().FirstOrDefault(n => n.Hit(p)); if (hitted != null) { dragged = hitted.StartDrag(p);//начинаем тащить } } }
void AssociatedObject_Drop(object sender, DragEventArgs e) { if (dataType != null) { if (e.Data.GetDataPresent(dataType)) { IDropable target = this.AssociatedObject.DataContext as IDropable; target.Drop(e); IDragable source = e.Data.GetData(dataType) as IDragable; source.Remove(); } } }
private void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (_isMouseClicked) { IDragable dragObject = this.AssociatedObject.DataContext as IDragable; if (dragObject != null) { DataObject data = new DataObject(); data.SetData(dragObject.DataType, this.AssociatedObject.DataContext); System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Move); } } }
public bool MouseDown(MouseEventArgs e, Matrix transform) { Point[] pp = new Point[] { e.Location }; transform.TransformPoints(pp); Point location = pp[0]; if (e.Button == MouseButtons.Left) { if (state == State.NONE) { IDragable inside = getInsideDragabe(location); IDragable outside = getOutsideDragabe(location); if (inside != null) { dragged = inside; state = State.DRAGGEDINSIDE; inselected.SetSelectedState(2, 0); return(true); } else if (outside != null) { dragged = outside; state = State.DRAGGEDOUTSIDE; outselected.SetSelectedState(0, 2); return(true); } return(false); } } if (e.Button == MouseButtons.Right) { dragged = getInsideDragabe(location); if (dragged == null) { dragged = getOutsideDragabe(location); } if ((dragged != null) && (dragged.GetType() == typeof(ObstacleModel))) { contextMenuStrip.Items[1].Enabled = true; } else { contextMenuStrip.Items[1].Enabled = false; } contextMenuLocation = location; return(true); } return(false); }
void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (_isMouseClicked) { //set the item's DataContext as the data to be transferred IDragable dragObject = AssociatedObject.DataContext as IDragable; if (dragObject != null && dragObject.IsDragable && !dragObject.HasBeenDragged) { DataObject data = new DataObject(); data.SetData(dragObject.DataType, AssociatedObject.DataContext); DragDrop.DoDragDrop(AssociatedObject, data, DragDropEffects.Move); } } _isMouseClicked = false; }
void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (isMouseClicked) { //set the item's DataContext as the data to be transferred IDragable dragObject = this.AssociatedObject.DataContext as IDragable; if (dragObject != null) { DataObject data = new DataObject(); data.SetData(dragObject.DataType, this.AssociatedObject.DataContext); System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Move); } } isMouseClicked = false; }
Transform GetDraggableTransformUnderMouse() { GameObject clickedObject = GetObjectUnderMouse(); IDragable iDrag = clickedObject.GetComponent <IDragable>(); if (iDrag != null) { if (!iDrag.startDrag()) { return(null); } return(clickedObject.transform); } return(null); }
void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (_isMouseClicked) { //set the item's DataContext as the data to be transferred IDragable dragObject = AssociatedObject.DataContext as IDragable; if (dragObject != null && dragObject.IsDragable) { DataObject data = new DataObject(); data.SetData(dragObject.DataType, AssociatedObject.DataContext); DragDrop.DoDragDrop(AssociatedObject, data, DragDropEffects.Move); Mediator.NotifyColleagues(Constants.ACTION_DRAG_DROP_STARTED, data); } } _isMouseClicked = false; }
IDragable FindDragable() { UiElement ui = _pointerDataProvider.UnderCursorUiElement; IDragable result = ui as IDragable; if (result != null) { return(result); } TileObject to = _pointerDataProvider.UnderCursorTileObject; result = to as IDragable; return(result); }
void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (isMouseClicked) { // Set item's data context as the data to be transfered IDragable dragObject = this.AssociatedObject.DataContext as IDragable; if (dragObject != null) { DataObject data = new DataObject(); data.SetData(dragObject.DataType, dragObject); // Start drag and drop operation System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Copy); } } isMouseClicked = false; }
/// <summary> /// The associated object_ mouse leave. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (this.isMouseClicked) { // set the item's DataContext as the data to be transferred IDragable dragObject = this.AssociatedObject.DataContext as IDragable; if (dragObject != null) { DataObject data = new DataObject(); data.SetData(dragObject.DataType, this.AssociatedObject.DataContext); System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Move); //Messenger.Default.Send<string>("Обновить активные задачи!"); } } this.isMouseClicked = false; }
private void OnDoubleClickItem(GameObject go) { IDragable item = go.GetComponent <DragItem>(); ItemInfo itemVO = item.DragItemVO as ItemInfo; if (itemVO != null) { if (itemVO.Genre == (int)KItemGenre.igEquip) { EquipInfo equipVo = itemVO as EquipInfo; BagLogic.GetInstance().LoadEquip(equipVo.Position, equipVo.PutWhere); } else if (itemVO.Genre == (int)KItemGenre.igCommon) { //BagLogic.GetInstance().SendUseItem(KPackageType.ePlayerPackage, KPlayerPackageIndex.eppiPlayerItemBox, itemVO.Position); } item.DragIcon.enabled = false; } }
private void AssociatedObjectOnMouseMove(object sender, MouseEventArgs mouseEventArgs) { Point currentPosition = mouseEventArgs.GetPosition(RelativeElement); pos = mouseEventArgs.GetPosition(this.AssociatedObject); //Point currentPosition = mouseEventArgs.GetPosition(Window.GetWindow(this.AssociatedObject)); if (!_isMousePressed || !this.AssociatedObject.IsMouseOver) { return; } if (Math.Abs(_originalPosition.X - currentPosition.X) < SystemParameters.MinimumHorizontalDragDistance && Math.Abs(_originalPosition.Y - currentPosition.Y) < SystemParameters.MinimumVerticalDragDistance) { return; } IDragable context = this.AssociatedObject.DataContext as IDragable; if (context == null) { return; } Debug.WriteLine("Mouse leave"); _adorner = new DefaultAdorner(this.AssociatedObject, mouseEventArgs.GetPosition(null), RelativeElement); DataObject data = new DataObject(); data.SetData(context.DataType, context); System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Move); if (_adorner != null) { _adorner.Destroy(); _adorner = null; } _isMousePressed = false; }
/// <summary> /// The associated object_ drop. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void AssociatedObject_Drop(object sender, DragEventArgs e) { // if the data type can be dropped if (this.dataType != null) { if (e.Data.GetDataPresent(this.dataType)) { // first find the UIElement that it was dropped over, then we determine if it's // dropped above or under the UIElement, then insert at the correct index. ItemsControl dropContainer = sender as ItemsControl; // get the UIElement that was dropped over UIElement droppedOverItem = UIHelper.GetUIElement(dropContainer, e.GetPosition(dropContainer)); int dropIndex = -1; // the location where the item will be dropped dropIndex = dropContainer.ItemContainerGenerator.IndexFromContainer(droppedOverItem) + 1; // find if it was dropped above or below the index item so that we can insert // the item in the correct place if (UIHelper.IsPositionAboveElement(droppedOverItem, e.GetPosition(droppedOverItem))) { // if above dropIndex = dropIndex - 1; // we insert at the index above it } // remove the data from the source IDragable source = e.Data.GetData(this.dataType) as IDragable; source.Remove(e.Data.GetData(this.dataType)); // drop the data IDropable target = this.AssociatedObject.DataContext as IDropable; target.Drop(e.Data.GetData(this.dataType), dropIndex); } } if (this.insertAdornerManager != null) { this.insertAdornerManager.Clear(); } e.Handled = true; return; }
public bool MouseDown(MouseEventArgs e, Matrix transform) { Point[] pp = new Point[] { e.Location }; transform.TransformPoints(pp); Point location = pp[0]; if (e.Button == MouseButtons.Left) { if (state == State.NONE) { IDragable inside = getInsideDragabe(location); IDragable outside = getOutsideDragabe(location); if (inside != null) { dragged = inside; state = State.DRAGGEDINSIDE; inselected.SetSelectedState(2, 0); return true; } else if (outside != null) { dragged = outside; state = State.DRAGGEDOUTSIDE; outselected.SetSelectedState(0, 2); return true; } return false; } } if (e.Button == MouseButtons.Right) { dragged = getInsideDragabe(location); if (dragged == null) dragged = getOutsideDragabe(location); if ((dragged != null) && (dragged.GetType() == typeof(ObstacleModel))) contextMenuStrip.Items[1].Enabled = true; else contextMenuStrip.Items[1].Enabled = false; contextMenuLocation = location; return true; } return false; }