Exemplo n.º 1
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"]);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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"]);
        }