Пример #1
0
 private void FavBtn_Click(object sender, RoutedEventArgs e)
 {
     if (GameInfo.IsFavorite)                                                          // If the game is a favorite
     {
         GameInfo.IsFavorite = false;                                                  // The game is no longer a favorite
         Definitions.HomePage.FavoriteBar.Children.Remove(FavoriteGameCard);           // Remove from favorite bar
         FavBtn.Content             = "\uF710";                                        // Change icon
         GameCardBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(102, 0, 255)); // Set the border color
     }
     else
     {
         GameInfo.IsFavorite = true;                                                    // Set the game to be a favorite
         FavoriteGameCard    = new FavoriteGameCard(GameInfo, this);
         Definitions.HomePage.FavoriteBar.Children.Add(FavoriteGameCard);               // Add to favorite bar
         FavBtn.Content             = "\uF71B";                                         // Change icon
         GameCardBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(55, 121, 238)); // Set the border color
     }
     GameSaver.Save(Definitions.Games);                                                 // Save the changes
 }
Пример #2
0
    /// <summary>
    /// Initialize the elements of the Interface.
    /// </summary>
    /// <param name="gameInfo"><see cref="Classes.GameInfo"/></param>
    /// <param name="isFromEdit"><see cref="true"/> if is called from the <see cref="EditGame"/> window.</param>
    internal void InitializeUI(GameInfo gameInfo, GavilyaPages gavilyaPages, bool isFromEdit = false, bool recommanded = false)
    {
        // Tooltip
        PlayToolTip.Content     = Properties.Resources.PlayLowerCase + " " + Properties.Resources.PlayTo + gameInfo.Name;
        GameToolTipName.Content = gameInfo.Name;

        // Border
        GameCardBorder.BorderThickness = new(0);                                                                                                                                                // Set the border thickness
        GameCardBorder.BorderBrush     = GameInfo.IsFavorite ? new SolidColorBrush(Color.FromRgb(55, 121, 238)) : GameCardBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(102, 0, 255)); // Set the border color


        // Location
        location = gameInfo.FileLocation;

        // Icon
        try
        {
            if (gameInfo.IconFileLocation != string.Empty && gameInfo.IconFileLocation != null)             // If a custom image is used
            {
                var bitmap = new BitmapImage();
                var stream = File.OpenRead(gameInfo.IconFileLocation);

                bitmap.BeginInit();
                bitmap.CacheOption      = BitmapCacheOption.OnLoad;
                bitmap.StreamSource     = stream;
                bitmap.DecodePixelWidth = 256;
                bitmap.EndInit();
                stream.Close();
                stream.Dispose();
                bitmap.Freeze();
                GameIcon.ImageSource = bitmap;
            }
            else
            {
                if (!gameInfo.IsUWP && !gameInfo.IsSteam)                 // If the game isn't UWP
                {
                    System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(gameInfo.FileLocation);
                    GameIcon.ImageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());                     // Show the image
                }
            }
        }
        catch
        {
            GameIcon.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Gavilya;component/Assets/PC.png"));             // Show the default image
        }

        // Favorite
        if (gameInfo.IsFavorite && !isFromEdit)         // If the game is a favorite
        {
            FavoriteGameCard = new FavoriteGameCard(gameInfo, this);
            Definitions.HomePage.FavoriteBar.Children.Add(FavoriteGameCard); // Add the game to the favorite bar
            FavBtn.Content = "\uF71B";                                       // Change icon
        }

        if (recommanded)
        {
            Definitions.HomePage.RecommandedBar.Children.Add(new FavoriteGameCard(gameInfo, this));             // Add the game to the recommanded bar
        }

        // Checkbox visibility
        if (Definitions.IsGamesCardsPagesCheckBoxesVisible)       // If the checkboxes are visibles
        {
            CheckBox.Visibility = Visibility.Visible;             // Visible
        }
        else
        {
            CheckBox.Visibility = Visibility.Hidden;             // Hiddent
        }

        // Page
        switch (gavilyaPages)
        {
        case GavilyaPages.Recent:                       // If the page is recent
            FavBtn.Visibility   = Visibility.Collapsed; // Hide the favorite button
            CheckBox.Visibility = Visibility.Hidden;    // Hide the checkbox
            MenuGroup.SetValue(Grid.ColumnProperty, 3);
            break;

        case GavilyaPages.Cards:                    // If the page is card
            FavBtn.Visibility = Visibility.Visible; // Show the favorite button
            break;
        }
    }