/// <summary>
        /// Method that adds player icons and scores to a stacklayout.
        /// </summary>
        /// <param name="players">Players that are added to the layout.</param>
        /// <param name="mainStack">Stacklayout where stuff is added.</param>
        private void AddPlayerScores(List <Player> players, StackLayout mainStack)
        {
            foreach (Player p in players)
            {
                // Players have been sorted so that player with the highest score appears first.
                // If a player's score is 0, then we know that that player and players after
                // haven't scored (are not part of the game).
                if (p.Score == 0)
                {
                    break;
                }

                var stack = new StackLayout
                {
                    Orientation   = StackOrientation.Horizontal,
                    HeightRequest = DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["KiviPlayerIconSizeX"]),
                    Children      =
                    {
                        new Image {
                            Source = p.Icon
                        },
                        new Label {
                            Text           = "= " + p.Score, VerticalOptions = LayoutOptions.Center,
                            FontFamily     = "Lobster_1.3.otf#Lobster_1.3",
                            FontSize       = DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["TitleFontX"]),
                            FontAttributes = FontAttributes.Bold,
                            TextColor      = (Color)Application.Current.Resources["PopupTextColor"]
                        }
                    },
                    HorizontalOptions = LayoutOptions.Center
                };
                mainStack.Children.Add(stack);
            }
        }
Exemple #2
0
        /// <summary>
        /// Method that is executed when app starts.
        /// Scales all objects on the screen using DisplayCalculator.
        /// </summary>
        private void SetScreenMetrics()
        {
            // Setting gameboard's height to be the same as device's width.
            MainGrid.RowDefinitions[1].Height = DisplayCalculator.DisplayWidth;

            // Using DisplayCalculator to calculate next values.
            // Resources are found from MainPage.xaml.
            AppTitle.FontSize             = DisplayCalculator.CalculateByWidth((double)Resources["AppTitleX"]);
            CalculateButton.FontSize      = DisplayCalculator.CalculateByWidth((double)Resources["ButtonFontSizeX"]);
            CalculateButton.Margin        = new Thickness(DisplayCalculator.CalculateByWidth((double)Resources["ButtonMarginX"]), 10);
            CalculateButton.HeightRequest = DisplayCalculator.CalculateByHeight((double)Resources["ButtonHeightRequestX"]);
            CalculateButton.CornerRadius  = (int)Math.Ceiling(CalculateButton.HeightRequest);
            SettingsIcon.HeightRequest    = DisplayCalculator.CalculateByWidth((double)Resources["SettingsIconX"]);
        }
        /// <summary>
        /// Creates a custom button that closes a popup.
        /// </summary>
        /// <param name="message">Message that is being shown on the button.</param>
        /// <param name="fontSize">Text font size.</param>
        /// <param name="margin">Button's margin.</param>
        /// <returns>A custom button used in popups.</returns>
        public static Button CreateButton(string message, double fontSize, Thickness margin)
        {
            var button = new Button
            {
                Text          = message,
                FontSize      = fontSize,
                Margin        = margin,
                HeightRequest = DisplayCalculator.CalculateByHeight(
                    (double)Application.Current.Resources["SettingsButtonHeightRequestX"]),
                WidthRequest = DisplayCalculator.CalculateByWidth(
                    (double)Application.Current.Resources["SettingsButtonWidthRequestX"]),
            };

            button.CornerRadius = (int)Math.Ceiling(button.HeightRequest);
            button.Clicked     += async(sender, args) => await PopupNavigation.Instance.PopAsync(true);

            return(button);
        }
        /// <summary>
        /// Creates a popup that shows players scores after calculation is done.
        /// </summary>
        /// <param name="players">List of players with scores that are shown.</param>
        public KiviPopupWindow(List <Player> players)
        {
            // Creating main stack layout.
            var mainStack = ScreenManager.CreateStackLayout(StackOrientation.Vertical, new Thickness(20, 0),
                                                            10, (Color)Application.Current.Resources["PopupWindowColor"]);

            // Adding player icons and scores to the stack.
            AddPlayerScores(players, mainStack);

            // Creating an Ok button that closes the popup.
            var button = ScreenManager.CreateButton(AppResources.Ok,
                                                    DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]),
                                                    new Thickness(DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["KiviButtonMarginX"]),
                                                                  DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["KiviButtonTopMarginX"])));

            // Changing button to be smaller horizontally and adding it to main stack.
            button.WidthRequest = DisplayCalculator.DisplayWidth / 3;
            mainStack.Children.Add(button);

            // Creating a frame and adding main stack into it.
            Content = ScreenManager.CreateFrame(mainStack, 50, new Thickness(20),
                                                (Color)Application.Current.Resources["PopupWindowColor"]);
        }
        /// <summary>
        /// Constructor of settings popup.
        /// </summary>
        public Settings()
        {
            // Creating main stacklayout.
            var stack = ScreenManager.CreateStackLayout(StackOrientation.Vertical,
                                                        new Thickness(0), 10, (Color)Application.Current.Resources["PopupWindowColor"]);

            // Adding title to stacklayout.
            stack.Children.Add(ScreenManager.CreateTitle(AppResources.Settings,
                                                         DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["TitleFontX"]),
                                                         (Color)Application.Current.Resources["PopupTextColor"]));

            // Creating label and switch for the option to change gameboard icons.
            Label iconsSwitchLabel = ScreenManager.CreateLabel(AppResources.IconsChange,
                                                               DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                               (Color)Application.Current.Resources["PopupTextColor"], FontAttributes.None);

            var iconsSwitch = new Switch
            {
                OnColor           = (Color)Application.Current.Resources["GreenColor"],
                ThumbColor        = (Color)Application.Current.Resources["ButtonBackgroundColor"],
                IsToggled         = MainPage.AlternativeIcons,
                Scale             = DisplayCalculator.CalculateSwitchScale((double)Application.Current.Resources["SettingsSwitchScaleX"]),
                HorizontalOptions = LayoutOptions.Center
            };

            iconsSwitch.Toggled += (sender, e) =>
            {
                MainPage.ChangeIcons();
            };

            // Creating label and switch for the option to skip application intro animations.
            Label introSwitchLabel = ScreenManager.CreateLabel(AppResources.IntroChange,
                                                               DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                               (Color)Application.Current.Resources["PopupTextColor"], FontAttributes.None);

            var introSwitch = new Switch
            {
                OnColor           = (Color)Application.Current.Resources["GreenColor"],
                ThumbColor        = (Color)Application.Current.Resources["ButtonBackgroundColor"],
                IsToggled         = App.SkipStartingAnimations,
                Scale             = DisplayCalculator.CalculateSwitchScale((double)Application.Current.Resources["SettingsSwitchScaleX"]),
                HorizontalOptions = LayoutOptions.Center
            };

            introSwitch.Toggled += (sender, e) =>
            {
                App.SkipStartingAnimations = introSwitch.IsToggled;
            };

            // Creating a grid and adding earlier created labels and switches into it.
            Grid grid = new Grid();

            grid.RowSpacing = DisplayCalculator.CalculateByHeight((double)Application.Current.Resources["SettingsGridSpacingScaleX"]);
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(4, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            grid.Children.Add(iconsSwitchLabel, 0, 0);
            grid.Children.Add(iconsSwitch, 1, 0);
            grid.Children.Add(introSwitchLabel, 0, 1);
            grid.Children.Add(introSwitch, 1, 1);

            stack.Children.Add(grid);

            // Creating a button that opens new popup that informs app user about score calculation.
            var infoButton = ScreenManager.CreateButton(AppResources.InfoButtonText,
                                                        DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]),
                                                        new Thickness(DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["SettingsButtonWidthMarginX"]),
                                                                      DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["SettingsButtonHeightMarginX"])));

            infoButton.Clicked += async(sender, args) => await ShowInformation();

            // Creating a button that closes this popup.
            var closeButton = ScreenManager.CreateButton(AppResources.Close,
                                                         DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]),
                                                         new Thickness(DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["SettingsButtonWidthMarginX"]),
                                                                       DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["SettingsButtonHeightMarginX"])));

            closeButton.Clicked += async(sender, args) =>
            {
                await PopupNavigation.Instance.PopAsync(true);
            };

            // Creating a button for gameboard clearing.
            var clearBoardButton = ScreenManager.CreateButton(AppResources.ClearGameBoard,
                                                              DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]),
                                                              new Thickness(DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["SettingsButtonWidthMarginX"]),
                                                                            DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["SettingsButtonHeightMarginX"])));

            clearBoardButton.Clicked += async(sender, args) =>
            {
                await MainPage.ClearGameBoard();

                await PopupNavigation.Instance.PopAsync(true);
            };

            // Adding buttons to stacklayout.
            stack.Children.Add(infoButton);
            stack.Children.Add(clearBoardButton);
            stack.Children.Add(closeButton);

            // Creates a frame with rounded corners and adds stacklayout into it.
            Content = ScreenManager.CreateFrame(stack, 50, new Thickness(20),
                                                (Color)Application.Current.Resources["PopupWindowColor"]);
        }
        /// <summary>
        /// Creates a popup that shows information about score calculation.
        /// </summary>
        public KiviPopupWindow()
        {
            // Creating main stacklayout.
            var mainStack = ScreenManager.CreateStackLayout(StackOrientation.Vertical,
                                                            new Thickness(0), 10, (Color)Application.Current.Resources["PopupWindowColor"]);

            // Adding title for the popup.
            mainStack.Children.Add(ScreenManager.CreateTitle(AppResources.InfoTitle,
                                                             DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["TitleFontX"]),
                                                             (Color)Application.Current.Resources["PopupTextColor"]));

            // Creating a stacklayout that will later be put into a scrollview.
            var scrollStack = ScreenManager.CreateStackLayout(StackOrientation.Vertical,
                                                              new Thickness(0), 10, (Color)Application.Current.Resources["LightBackground"]);

            scrollStack.Padding = new Thickness(DisplayCalculator.CalculateByWidth(
                                                    (double)Application.Current.Resources["KiviStackPaddingX"]));

            // Adding instructions part 1 to the layout.
            scrollStack.Children.Add(ScreenManager.CreateLabel(AppResources.InstructionsPart1,
                                                               DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                               (Color)Application.Current.Resources["PopupTextColor"], FontAttributes.None));

            // Adding an example title to the layout.
            scrollStack.Children.Add(ScreenManager.CreateLabel(AppResources.ExampleTitle,
                                                               DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                               (Color)Application.Current.Resources["PopupTextColor"], FontAttributes.Bold));

            // Adding instructions part 2 to the layout.
            scrollStack.Children.Add(ScreenManager.CreateLabel(AppResources.InstructionsPart2,
                                                               DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                               (Color)Application.Current.Resources["PopupTextColor"], FontAttributes.None));

            // Adding an info grid that has information about calculation. Has instruction parts 3-7 in it.
            scrollStack.Children.Add(new InfoGrid(DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                  DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["InfoIconX"])));

            // Adding instructions part 8 to the layout.
            scrollStack.Children.Add(ScreenManager.CreateLabel(AppResources.InstructionsPart8,
                                                               DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["NormalFontX"]),
                                                               (Color)Application.Current.Resources["PopupTextColor"], FontAttributes.None));

            // Adding an example image of a gameboard.
            scrollStack.Children.Add(new Image {
                Source            = "example_gameboard.png",
                HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(0, 0)
            });

            // Creating scrollview and adding stack in it.
            ScrollView scrollview = new ScrollView
            {
                Content = scrollStack
            };

            // Adding scroll view to the main stack.
            mainStack.Children.Add(scrollview);

            // Creating a close button.
            mainStack.Children.Add(ScreenManager.CreateButton(AppResources.Close,
                                                              DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]),
                                                              new Thickness(DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]),
                                                                            DisplayCalculator.CalculateByWidth((double)Application.Current.Resources["BoldFontX"]))));

            // Creating a frame and adding main stack into it.
            Content = ScreenManager.CreateFrame(mainStack, 50, new Thickness(20),
                                                (Color)Application.Current.Resources["PopupWindowColor"]);
        }