コード例 #1
0
    }                                              // Create a timer

    public GameCard(GameInfo gameInfo, GavilyaPages gavilyaPages, bool isFromEdit = false, bool recommanded = false)
    {
        InitializeComponent();

        GameInfo = gameInfo;                                           // Define the info
        InitializeUI(gameInfo, gavilyaPages, isFromEdit, recommanded); // Load the UI

        Timer = new DispatcherTimer {
            Interval = TimeSpan.FromSeconds(1)
        };                                // Define the timer
        Timer.Tick += Timer_Tick;         // Set the event
    }
コード例 #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;
        }
    }