Exemplo n.º 1
0
        public CalendarBadge(string day, Color c)
        {
            Padding = 0;

            _date = new Label();

            layout = new StackLayout();

            _date.Text                    = day;
            _date.TextColor               = Color.Black;
            _date.BackgroundColor         = Color.FromHex("cdcdcd");
            _date.HorizontalTextAlignment = TextAlignment.Center;

            layout.Children.Add(_date);
            //layout.Children.Add(new Label { Text = "X", TextColor = c, BackgroundColor=Color.Silver, HorizontalTextAlignment=TextAlignment.Center });
            _box = new RoundedBoxView.Forms.Plugin.Abstractions.RoundedBoxView();
            _box.BackgroundColor = c;
            _box.BorderThickness = 0;
            _box.WidthRequest    = 20;
            _box.HeightRequest   = 20;
            _box.CornerRadius    = 40;
            layout.Children.Add(_box);

            Content         = layout;
            HasShadow       = false;
            WidthRequest    = 30;
            HeightRequest   = 60;
            BackgroundColor = Color.Transparent;


            var tapped = new TapGestureRecognizer();

            tapped.Tapped += (s, e) =>
            {
                //OnTapped(s, e);
                Page p = new Page();
                p.DisplayAlert("ALERT", e.ToString(), "Close");
            };
            this.GestureRecognizers.Add(tapped);
        }
Exemplo n.º 2
0
        void addSnookerBreakControls(SnookerBreak snookerBreak, bool isOpponentsBreak)
        {
            StackLayout[] horizontalStack = new StackLayout[5];
            int           lineIdx;

            // Determine number of lines needed to display all balls in a break
            int numLines = (int)(snookerBreak.Balls.Count / maxNumberOfBallsPerLine) + 1;

            for (lineIdx = 0; lineIdx < numLines; lineIdx++)
            {
                horizontalStack[lineIdx] = new StackLayout()
                {
                    Orientation       = StackOrientation.Horizontal,
                    Padding           = new Thickness(1, 0, 1, 0),
                    BackgroundColor   = Config.ColorBackground,
                    Spacing           = 2,
                    HorizontalOptions = (!isOpponentsBreak || (lineIdx > 0)) ? LayoutOptions.Start : LayoutOptions.End
                };
            }

            // if more than one line, start adding opponent's balls from the left
            if (snookerBreak.Balls.Count >= maxNumberOfBallsPerLine)
            {
                horizontalStack[0].HorizontalOptions = LayoutOptions.Start;
            }

            double sizeOfPocketedBalls = Config.ExtraSmallBallSize;

            // Fill horizonal stack lines with the balls
            lineIdx = 0;
            if (snookerBreak.HasBalls)
            {
                int ballIdx = 0;
                foreach (var ballScore in snookerBreak.Balls)
                {
                    Color color       = Config.BallColors[ballScore];
                    Color borderColor = color;
                    if (ballScore == 7)
                    {
                        borderColor = Color.Gray;
                    }

                    RoundedBoxView.Forms.Plugin.Abstractions.RoundedBoxView ball = new RoundedBoxView.Forms.Plugin.Abstractions.RoundedBoxView {
                        WidthRequest         = sizeOfPocketedBalls,
                        HeightRequest        = sizeOfPocketedBalls,
                        MinimumWidthRequest  = sizeOfPocketedBalls,
                        MinimumHeightRequest = sizeOfPocketedBalls,
                        Color           = color,
                        BorderColor     = borderColor,
                        BackgroundColor = color,
                        BorderThickness = 1,
                        CornerRadius    = (int)(sizeOfPocketedBalls / 2),
                        VerticalOptions = LayoutOptions.Center
                    };

                    // if 8 balls in each line:
                    //   0/8 - 0, 7/8 - 0, 8/8 - 1, 9/8 - 1 ...
                    //
                    lineIdx = (int)(ballIdx / maxNumberOfBallsPerLine);
                    horizontalStack[lineIdx].Children.Insert(horizontalStack[lineIdx].Children.Count, ball);

                    ballIdx++;
                }
            }

            if (snookerBreak.IsFoul)
            {
                // add "foul":
                //   if on right side "foul xxx 15"
                //   if on left side  "xxx 15 foul"

                string foulLabelString = isOpponentsBreak ?
                                         "foul ": // if on right side "foul xxx 15"
                                         " foul"; // if on left side  "xxx 15 foul"

                BybLabel foulLabel = new BybLabel()
                {
                    Text         = foulLabelString,
                    TextColor    = Config.ColorRed,
                    WidthRequest = Config.IsTablet ? 35 : 27,
                    //VerticalTextAlignment = TextAlignment.Center,
                    HorizontalTextAlignment = TextAlignment.Start
                };

                if (isOpponentsBreak)
                {
                    horizontalStack[0].Children.Insert(0, foulLabel);                     // insert "foul " in the beginning "foul xxx 15"
                }
                else
                {
                    horizontalStack[0].Children.Add(foulLabel);                        // add " foul" to the end "15 xxx foul"
                }
            }

            // This grid hold all the break info
            BybBreakGrid breakGrid = new BybBreakGrid(isOpponentsBreak);

            // Add all the lines of balls to stack
            for (lineIdx = 0; lineIdx < numLines; lineIdx++)
            {
                breakGrid.ballsStack.Children.Add(horizontalStack[lineIdx]);
            }

            // Break score - 3 character string
            string   breakPointsString = String.Format("{0,3}", snookerBreak.Points.ToString());
            BybLabel breakPointsLabel  = new BybLabel()
            {
                Text                    = breakPointsString,
                BackgroundColor         = Config.ColorBackground,
                TextColor               = snookerBreak.IsFoul ? Config.ColorRed : Color.White,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = (isOpponentsBreak) ? TextAlignment.End : TextAlignment.Start
            };

            breakGrid.ballsStack.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() =>
                {
                    if (this.UserTappedOnBreak != null)
                    {
                        this.UserTappedOnBreak(this, snookerBreak);
                    }
                }),
                NumberOfTapsRequired = 1
            });
            breakPointsLabel.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() =>
                {
                    if (this.UserTappedOnBreak != null)
                    {
                        this.UserTappedOnBreak(this, snookerBreak);
                    }
                }),
                NumberOfTapsRequired = 1
            });

            // Add to the player who scored,
            // leave the other player's corresponding fields empty:
            //  - balls
            //  - break score field
            if (isOpponentsBreak)
            {
                breakGrid.Children.Add(breakGrid.ballsStack, 3, 0);
                breakGrid.Children.Add(breakPointsLabel, 4, 0);
            }
            else
            {
                breakGrid.Children.Add(breakPointsLabel, 0, 0);
                breakGrid.Children.Add(breakGrid.ballsStack, 1, 0);
            }
            int childIdx = breakGrid.Children.Count();

            // If running frame score is valid, add it in the middle
            if (frameScoreValid)
            {
                Grid frameScoreGrid = new CurrentBreakScoreGrid(frameScoreYou, frameScoreOpponent);
                breakGrid.Children.Add(frameScoreGrid, 2, 0);
            }

            // I think this might not be necessary
            breakGrid.RaiseChild(breakGrid.Children.ElementAt(childIdx - 1));
            breakGrid.RaiseChild(breakGrid.Children.ElementAt(childIdx - 2));

            // add the new break to the list of breaks
            this.Children.Add(breakGrid);
        } // addSnookerBreakControls()