private void RotateHud(bool clockwise) { if (!TableType.HasValue) { return; } try { var tableSize = (int)TableType; var toolsBySeats = layout.ListHUDPlayer .SelectMany(x => x.HudElement.Tools) .OfType <IHudNonPopupToolViewModel>() .Concat(layout.EmptySeatsViewModels .SelectMany(x => x.Tools) .OfType <IHudNonPopupToolViewModel>()) .GroupBy(x => x.Parent.Seat) .ToDictionary(x => x.Key, x => x.ToArray()); var toolsById = toolsBySeats.Values .SelectMany(x => x) .GroupBy(x => x.Id, x => new { OffsetX = x.OffsetX ?? x.Position.X, OffsetY = x.OffsetY ?? x.Position.Y, x.Parent.Seat }) .ToDictionary(x => x.Key, x => x.GroupBy(p => p.Seat).ToDictionary(p => p.Key, p => p.FirstOrDefault())); // need to rotate all positions even if there is no player on position for (var seat = 1; seat <= tableSize; seat++) { var newSeat = clockwise ? seat + 1 : seat - 1; if (newSeat > tableSize) { newSeat = 1; } else if (newSeat < 1) { newSeat = tableSize; } var nonPopupTools = toolsBySeats[seat]; foreach (var nonPopupTool in nonPopupTools) { if (!toolsById.ContainsKey(nonPopupTool.Id) || !toolsById[nonPopupTool.Id].ContainsKey(newSeat)) { continue; } var newOffsets = toolsById[nonPopupTool.Id][newSeat]; if (newOffsets == null) { continue; } nonPopupTool.OffsetX = newOffsets.OffsetX; nonPopupTool.OffsetY = newOffsets.OffsetY; var toolKey = new HudToolKey { Id = nonPopupTool.Id, Seat = seat }; if (!PanelOffsets.ContainsKey(toolKey)) { PanelOffsets.Add(toolKey, new Point(newOffsets.OffsetX, newOffsets.OffsetY)); } else { PanelOffsets[toolKey] = new Point(newOffsets.OffsetX, newOffsets.OffsetY); } } } } catch (Exception e) { LogProvider.Log.Error(this, $"Failed to rotate hud for table. [{WindowHandle}]", e); } RefreshHud?.Invoke(); }
private void ApplyPositions(object obj) { var sourceSeat = obj as int?; if (!sourceSeat.HasValue || layout == null) { return; } var positionProvider = ServiceLocator.Current.GetInstance <IPositionProvider>(layout.PokerSite.ToString()); if (!positionProvider.Positions.ContainsKey((int)TableType)) { return; } var seatsPositions = positionProvider.Positions[(int)TableType]; var baseHUDPlayer = layout.ListHUDPlayer.FirstOrDefault(x => x.SeatNumber == sourceSeat.Value); if (baseHUDPlayer == null) { return; } var baseSeatPosition = new Point(seatsPositions[sourceSeat.Value - 1, 0], seatsPositions[sourceSeat.Value - 1, 1]); var nonPopupToolViewModels = baseHUDPlayer.HudElement.Tools.OfType <IHudNonPopupToolViewModel>(); var toolOffsetsDictionary = (from nonPopupToolViewModel in nonPopupToolViewModels let toolOffsetX = nonPopupToolViewModel.OffsetX ?? nonPopupToolViewModel.Position.X let toolOffsetY = nonPopupToolViewModel.OffsetY ?? nonPopupToolViewModel.Position.Y let shiftX = toolOffsetX - baseSeatPosition.X let shiftY = toolOffsetY - baseSeatPosition.Y select new { ToolId = nonPopupToolViewModel.Id, ShiftX = shiftX, ShiftY = shiftY }).ToDictionary(x => x.ToolId); for (var seat = 1; seat <= (int)TableType; seat++) { if (seat == sourceSeat.Value) { continue; } foreach (var tool in toolOffsetsDictionary.Values) { var toolKey = new HudToolKey { Id = tool.ToolId, Seat = seat }; var seatPosition = new Point(seatsPositions[seat - 1, 0], seatsPositions[seat - 1, 1]); var offsetX = seatPosition.X + tool.ShiftX; var offsetY = seatPosition.Y + tool.ShiftY; PanelOffsets[toolKey] = new Point(offsetX, offsetY); } } var elementsToUpdate = layout.ListHUDPlayer.Where(x => x.SeatNumber != sourceSeat.Value).Select(x => x.HudElement).ToArray(); elementsToUpdate.ForEach(element => { element.Tools.OfType <IHudNonPopupToolViewModel>().ForEach(tool => { if (toolOffsetsDictionary.ContainsKey(tool.Id)) { var seatPosition = new Point(seatsPositions[element.Seat - 1, 0], seatsPositions[element.Seat - 1, 1]); tool.OffsetX = seatPosition.X + toolOffsetsDictionary[tool.Id].ShiftX; tool.OffsetY = seatPosition.Y + toolOffsetsDictionary[tool.Id].ShiftY; } }); }); RefreshHud?.Invoke(); }