Exemplo n.º 1
0
        // Rebuilds the discard panel of the specified player.
        private void FillDiscardPanel(int pIndex)
        {
            for (int r = 1; r <= 3; r++)
            {
                this.FindPanel($"StpDiscard{r}P", pIndex).Children.Clear();
            }

            bool reversed = pIndex == 1 || pIndex == 2;

            int i = 0;

            foreach (TilePivot tile in _game.Round.GetDiscard(pIndex))
            {
                int        r     = i < 6 ? 1 : (i < 12 ? 2 : 3);
                Panel      panel = this.FindPanel($"StpDiscard{r}P", pIndex);
                AnglePivot angle = (AnglePivot)pIndex;
                if (_game.Round.IsRiichiRank(pIndex, i))
                {
                    angle = (AnglePivot)pIndex.RelativePlayerIndex(1);
                }
                if (reversed)
                {
                    panel.Children.Insert(0, tile.GenerateTileButton(angle: angle));
                }
                else
                {
                    panel.Children.Add(tile.GenerateTileButton(angle: angle));
                }
                i++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extension; generates a button which represents a tile.
        /// </summary>
        /// <param name="tile">The tile to display.</param>
        /// <param name="handler">Optionnal; event on click on the button; default value is <c>Null</c>.</param>
        /// <param name="angle">Optionnal; rotation angle; default is <c>0°</c>.</param>
        /// <param name="concealed">Optionnal; set <c>True</c> to display a concealed tile; default is <c>False</c>.</param>
        /// <returns>A button representing the tile.</returns>
        internal static Button GenerateTileButton(this TilePivot tile, RoutedEventHandler handler = null, AnglePivot angle = AnglePivot.A0, bool concealed = false)
        {
            string rscName = concealed ? CONCEALED_TILE_RSC_NAME : tile.ToString();

            Bitmap tileBitmap = Properties.Resources.ResourceManager.GetObject(rscName) as Bitmap;

            var button = new Button
            {
                Height  = angle == AnglePivot.A0 || angle == AnglePivot.A180 ? TILE_HEIGHT : TILE_WIDTH,
                Width   = angle == AnglePivot.A0 || angle == AnglePivot.A180 ? TILE_WIDTH : TILE_HEIGHT,
                Content = new System.Windows.Controls.Image
                {
                    Source          = tileBitmap.ToBitmapImage(),
                    LayoutTransform = new RotateTransform(Convert.ToDouble(angle.ToString().Replace("A", string.Empty)))
                },
                Tag = tile
            };

            if (handler != null)
            {
                button.Click += handler;
            }

            return(button);
        }