Ejemplo n.º 1
0
        internal void SetLayout(HudLayout layout)
        {
            using (var write = readerWriterLock.Write())
            {
                if (layout != null)
                {
                    if (TableType.HasValue && TableType != layout.TableType)
                    {
                        PanelOffsets.Clear();
                    }

                    this.layout = layout;
                    LayoutName  = layout.LayoutName;

                    if (!lastHands.Contains(layout.GameNumber))
                    {
                        lastHands.Add(layout.GameNumber);
                    }

                    if (layout.AvailableLayouts != null)
                    {
                        LayoutsCollection = new ObservableCollection <string>(layout.AvailableLayouts);
                        SelectedLayout    = LayoutsCollection.FirstOrDefault(x => x == layout.LayoutName);
                    }

                    RaisePropertyChanged(nameof(PreLoadMode));
                    RaisePropertyChanged(nameof(PreLoadText));
                }
            }
        }
Ejemplo n.º 2
0
        private async void DoTreatAs(object obj)
        {
            if (obj == null)
            {
                return;
            }

            await Task.Run(() =>
            {
                using (var readToken = readerWriterLock.Read())
                {
                    var tableType = (EnumTableType)obj;
                    TableType     = tableType;

                    PanelOffsets.Clear();

                    HudNamedPipeBindingService.TreatTableAs(WindowHandle, tableType);
                }
            });
        }
Ejemplo n.º 3
0
        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();
        }