public void OnMouseMoveWithCard(MouseState mouse) { VisibleCardPack under = nearestCardPack(draggedPack.GetRectangle()); if (under != null && under.pack.CanAccept(draggedPack.pack)) { under.Light = true; } }
private VisibleCardPack nearestCardPack(Rectangle rect) { Rectangle line = new Rectangle(rect.X, rect.Y, rect.Width, 50); int centerX = line.Center.X; VisibleCardPack pack = visiblePacks .Where(i => i.GetRectangle().Intersects(line)) .OrderByDescending(i => Math.Abs(centerX - i.GetRectangle().Center.X)).FirstOrDefault(); return(pack); }
public void OnLeftPressedOverCard(MouseState mouse) { Point shift = startTargetingPoint - mouse.Position; if ((shift.X * shift.X + shift.Y * shift.Y) > DRAG_HOLD_POW_2) { int gap = mouseTarget.GapCount(startTargetingPoint); if (gap != -1) { draggedPack = new VisibleCardPack(mouseTarget.pack.LastCards(gap), startTargetingPoint); draggedOriginalPoint = mouseTarget.GapLeftTopPoint(mouse.Position); mouseTarget.InvisibleCards = gap; } } }
public void OnLeftMouseReleased(MouseState mouse) { if (draggedPack != null) { VisibleCardPack under = nearestCardPack(draggedPack.GetRectangle()); if (under != null && under.pack.CanAccept(draggedPack.pack)) { state.ConfirmMove(mouseTarget.pack, under.pack, draggedPack.pack.Count); } draggedPack = null; } else if (mouseTarget != null && draggedPack == null) { mouseTarget.Activate(); } if (mouseTarget != null) { mouseTarget.InvisibleCards = 0; } mouseTarget = null; }
public void OnLeftMousePressed(MouseState mouse) { mouseTarget = visiblePacks.FirstOrDefault(i => i.GetRectangle().Contains(mouse.Position)); startTargetingPoint = mouse.Position; }