public static void RaiseMoveCards(GameView gameView, List<CardView> cardViews, string targetSectorCode, CardPositionOffset offset, CardVisibility? visibility) { foreach(var cardsByOwner in cardViews.GroupBy(c => c.CardViewItem.OwnerPlayerKey)) { List<CardPosition> positions; PlayerStructure ownerPlayer = gameView.GameStructure.GetPlayer(cardsByOwner.Key); ISectorView targetSectorView = (ISectorView)gameView.Controls.Find(ownerPlayer.Sectors.Single(e => e.Item.Code == targetSectorCode).SectorKey, true).First(); if(GameViewHelper.TryGetSectorValidCardPositions(targetSectorView, offset, cardsByOwner.Count(), out positions)) gameView.Controller.MoveCards(cardsByOwner.Select(e => e.Name).ToList(), targetSectorCode, positions, visibility); } }
static bool TryGetSectorValidCardPositions(ISectorView sectorView, CardPositionOffset offset, int positionAmount, out List<CardPosition> cardPositions) { cardPositions = new List<CardPosition>(); bool valid = true; if(sectorView is StaticFreeSectorView) { Rectangle cardRect = CardMetricsService.CardRect(CardStyleBehaviorsService.BEHAVIORS_SMALL); StaticFreeSectorView staticFreeSectorView = (StaticFreeSectorView)sectorView; Point startPoint = new Point(); startPoint.X = (staticFreeSectorView.Width / 2) - (cardRect.Width / 2); startPoint.Y = (staticFreeSectorView.Height / 3) - (cardRect.Height / 2); List<PointF> normalizedPoints; valid = staticFreeSectorView.TryGetValidCardPositions(startPoint, positionAmount, new List<CardView>(), out normalizedPoints); if(valid) { for(int i = 0; i < positionAmount; i++) { int z = offset == CardPositionOffset.Top ? i : sectorView.CardViews.Count + i; cardPositions.Add(new CardPosition(normalizedPoints[i].X, normalizedPoints[i].Y, z)); } } } else { for(int i = 0; i < positionAmount; i++) cardPositions.Add(new CardPosition(0, 0, offset == CardPositionOffset.Top ? i : sectorView.CardViews.Count + i)); } return valid; }
public static void RaiseMoveCards(GameView gameView, List<CardView> cardViews, string targetSectorCode, CardPositionOffset offset) { RaiseMoveCards(gameView, cardViews, targetSectorCode, offset, null); }