Working Game Artworks (Front, Back, DVD)
This commit is contained in:
parent
2ee895494c
commit
0f8c65c61c
7 changed files with 224 additions and 17 deletions
|
@ -27,7 +27,8 @@
|
|||
</Grid>
|
||||
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto,*" Margin="20">
|
||||
<!-- PS2 Cover -->
|
||||
<Border Width="205" Height="292" Background="Black" CornerRadius="5" HorizontalAlignment="Left">
|
||||
<Border Width="205" Height="292" Background="Black" CornerRadius="5" HorizontalAlignment="Left"
|
||||
PointerPressed="CoverImage_OnPointerPressed">
|
||||
<Image Name="CoverImage" Source="Images/missing.png" Stretch="UniformToFill"/>
|
||||
</Border>
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ using Avalonia.Input;
|
|||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
using PS2_Manager.Core;
|
||||
|
||||
namespace PS2_Manager;
|
||||
|
@ -23,11 +24,16 @@ public partial class AddGameWindow : Window
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Control_OnLoaded(object? sender, RoutedEventArgs e)
|
||||
private void RefreshPreview()
|
||||
{
|
||||
IsoPathBox.Text = this.newGame.GamePath;
|
||||
SerialBox.Text = this.newGame.GameID;
|
||||
CoverImage.Source = this.newGame.Cover;
|
||||
CoverImage.Source = this.newGame.ArtworkFront;
|
||||
}
|
||||
|
||||
private void Control_OnLoaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
RefreshPreview();
|
||||
}
|
||||
|
||||
private void Control_OnSizeChanged(object? sender, SizeChangedEventArgs e)
|
||||
|
@ -92,4 +98,25 @@ public partial class AddGameWindow : Window
|
|||
{
|
||||
this.newGame.Name = GameNameBox.Text ?? "";
|
||||
}
|
||||
|
||||
private async void CoverImage_OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
|
||||
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = "Select a Cover for the PS2 Game",
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new []
|
||||
{
|
||||
Globals.FileDialogTypes.PS2Cover
|
||||
}
|
||||
});
|
||||
|
||||
if (files.Count >= 1)
|
||||
{
|
||||
this.newGame.ArtworkFront = new Bitmap(files[0].Path.LocalPath);
|
||||
RefreshPreview();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,9 @@ public class Game
|
|||
public string Name { get; set; }
|
||||
public string GameID { get; set; }
|
||||
public string GamePath { get; set; }
|
||||
public Bitmap Cover { get; set; }
|
||||
public Bitmap? ArtworkFront { get; set; }
|
||||
public Bitmap? ArtworkBack { get; set; }
|
||||
public Bitmap? ArtworkDVD { get; set; }
|
||||
public EventHandler? InstallationFinished { get; set; }
|
||||
public UpdateVar<double> InstallProgress { get; private set; }
|
||||
|
||||
|
@ -27,12 +29,14 @@ public class Game
|
|||
this.GameID = ISO.GetSerial(isoPath);
|
||||
if (!installed)
|
||||
{
|
||||
this.Cover = this.GetCover();
|
||||
this.ArtworkFront = this.GetCover();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Name = ParseFormattedFilename(Path.GetFileName(isoPath));
|
||||
this.Cover = new Bitmap(Path.Combine(Path.Combine(settings.library_path.GetValue<string>(), "ART"), this.GameID + "_COV.png"));
|
||||
this.ArtworkFront = this.LoadCover(Artwork.Type.Front);
|
||||
this.ArtworkBack = this.LoadCover(Artwork.Type.Back);
|
||||
this.ArtworkDVD = this.LoadCover(Artwork.Type.Disc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +128,7 @@ public class Game
|
|||
}
|
||||
}
|
||||
|
||||
this.InstallCover();
|
||||
//this.InstallCover();
|
||||
this.InstallationFinished?.Invoke(this, EventArgs.Empty);
|
||||
MainWindow.RefreshGamesListTrigger?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
|
@ -135,13 +139,78 @@ public class Game
|
|||
|
||||
|
||||
|
||||
public void InstallCover()
|
||||
public Bitmap? LoadCover(Artwork.Type artworkType)
|
||||
{
|
||||
string targetDirectory = settings.library_path.GetValue<string>();
|
||||
Util.CheckDir(Path.Combine(targetDirectory, "ART"));
|
||||
this.Cover.CreateScaledBitmap(
|
||||
try
|
||||
{
|
||||
switch (artworkType)
|
||||
{
|
||||
case Artwork.Type.Front:
|
||||
return new Bitmap(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_COV.png"));
|
||||
break;
|
||||
case Artwork.Type.Back:
|
||||
return new Bitmap(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_COV2.png"));
|
||||
break;
|
||||
case Artwork.Type.Disc:
|
||||
return new Bitmap(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_ICO.png"));
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void SaveCover(Artwork.Type artworkType)
|
||||
{
|
||||
string targetDirectory = settings.library_path.GetValue<string>();
|
||||
Util.CheckDir(Path.Combine(targetDirectory, "ART"));
|
||||
switch (artworkType)
|
||||
{
|
||||
case Artwork.Type.Front:
|
||||
this.ArtworkFront?.CreateScaledBitmap(
|
||||
new PixelSize(353, 500),
|
||||
BitmapInterpolationMode.HighQuality
|
||||
).Save(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_COV.png"));
|
||||
break;
|
||||
case Artwork.Type.Back:
|
||||
this.ArtworkBack?.CreateScaledBitmap(
|
||||
new PixelSize(353, 500),
|
||||
BitmapInterpolationMode.HighQuality
|
||||
).Save(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_COV2.png"));
|
||||
break;
|
||||
case Artwork.Type.Disc:
|
||||
this.ArtworkDVD?.CreateScaledBitmap(
|
||||
new PixelSize(353, 353),
|
||||
BitmapInterpolationMode.HighQuality
|
||||
).Save(Path.Combine(Path.Combine(targetDirectory, "ART"), this.GameID + "_ICO.png"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Artwork
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
Front,
|
||||
Back,
|
||||
Disc
|
||||
}
|
||||
|
||||
public static Type NextType(Type _type)
|
||||
{
|
||||
return (Type)(((int)_type + 1) % Enum.GetValues(typeof(Type)).Length);
|
||||
}
|
||||
|
||||
public static Type PrevType(Type _type)
|
||||
{
|
||||
return (Type)(((int)_type - 1 + Enum.GetValues(typeof(Type)).Length) % Enum.GetValues(typeof(Type)).Length);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,10 @@ public static class Globals
|
|||
{
|
||||
Patterns = new[] { "*.iso" }
|
||||
};
|
||||
public static FilePickerFileType PS2Cover { get; } = new("PS2 Cover")
|
||||
{
|
||||
Patterns = new[] { "*.png", "*.jpg" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,11 @@ public static class Util
|
|||
// Format to 1 decimal place
|
||||
return string.Format("{0:0.0} {1}", len, sizes[order]);
|
||||
}
|
||||
|
||||
public static bool IsBitmapEmpty(Bitmap? bitmap)
|
||||
{
|
||||
return bitmap == null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,4 +79,5 @@ public static class Checksum
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -5,9 +5,19 @@
|
|||
mc:Ignorable="d"
|
||||
x:Class="PS2_Manager.GameInfo">
|
||||
<Grid RowDefinitions="350, *, *, *, *">
|
||||
<Border Grid.Row="0" Width="205" Height="292" Background="Black" CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Grid Grid.Row="0" ColumnDefinitions="*, 205, *">
|
||||
|
||||
<Button Grid.Column="0" Content="←" HorizontalAlignment="Center" VerticalAlignment="Center" Click="PrevButton"/>
|
||||
<Button Grid.Column="2" Content="→" HorizontalAlignment="Center" VerticalAlignment="Center" Click="NextButton"/>
|
||||
|
||||
<Border Grid.Column="1" Width="205" Height="292" Background="Transparent" CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
PointerPressed="CoverImage_OnPointerPressed" Name="CoverContainer">
|
||||
<Grid>
|
||||
<Image Name="CoverImage" Source="Images/missing.png" Stretch="UniformToFill"/>
|
||||
<TextBlock Name="CoverTextHint" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="False"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1" Text="" HorizontalAlignment="Center"
|
||||
Name="GameNameTextBlock"/>
|
||||
<TextBlock Grid.Row="2" Text="" HorizontalAlignment="Center"
|
||||
|
|
|
@ -2,26 +2,116 @@ using System;
|
|||
using System.IO;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
using PS2_Manager.Core;
|
||||
|
||||
namespace PS2_Manager;
|
||||
|
||||
public partial class GameInfo : UserControl
|
||||
{
|
||||
public UpdateVar<Artwork.Type> ArtworkType { get; set; } = new UpdateVar<Artwork.Type>();
|
||||
public Game game { get; set; }
|
||||
public GameInfo(Game _game)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.game = _game;
|
||||
CoverImage.Source = game.Cover;
|
||||
ArtworkType.ValueChanged += UpdateArtworks;
|
||||
ArtworkType.Value = Artwork.Type.Front;
|
||||
|
||||
GameNameTextBlock.Text = game.Name;
|
||||
GameIdTextBlock.Text = game.GameID;
|
||||
|
||||
FileInfo fileInfo = new FileInfo(game.GamePath);
|
||||
IsoSizeTextBlock.Text = Util.FormatFileSize(fileInfo.Length);
|
||||
DateTime lastModified = fileInfo.LastWriteTime;
|
||||
string formattedDate = lastModified.ToString("dd.MM.yyyy HH:mm");
|
||||
GameDateTextBlock.Text = formattedDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UpdateArtworks()
|
||||
{
|
||||
Bitmap? tempBitmap = null;
|
||||
switch (ArtworkType.Value)
|
||||
{
|
||||
case Artwork.Type.Front:
|
||||
CoverContainer.Height = 292;
|
||||
tempBitmap = game.ArtworkFront;
|
||||
break;
|
||||
case Artwork.Type.Back:
|
||||
CoverContainer.Height = 292;
|
||||
tempBitmap = game.ArtworkBack;
|
||||
break;
|
||||
case Artwork.Type.Disc:
|
||||
CoverContainer.Height = CoverContainer.Width;
|
||||
tempBitmap = game.ArtworkDVD;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Util.IsBitmapEmpty(tempBitmap))
|
||||
{
|
||||
CoverContainer.Background = new SolidColorBrush(Color.Parse("#201c29"));
|
||||
CoverTextHint.IsVisible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CoverContainer.Background = Brushes.Transparent;
|
||||
CoverTextHint.IsVisible = false;
|
||||
}
|
||||
|
||||
|
||||
CoverTextHint.Text = ArtworkType.Value.ToString();
|
||||
|
||||
CoverImage.Source = tempBitmap;
|
||||
}
|
||||
|
||||
private async void CoverImage_OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
|
||||
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = "Select a Cover for the PS2 Game",
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new []
|
||||
{
|
||||
Globals.FileDialogTypes.PS2Cover
|
||||
}
|
||||
});
|
||||
|
||||
if (files.Count >= 1)
|
||||
{
|
||||
switch (ArtworkType.Value)
|
||||
{
|
||||
case Artwork.Type.Front:
|
||||
this.game.ArtworkFront = new Bitmap(files[0].Path.LocalPath);
|
||||
break;
|
||||
case Artwork.Type.Back:
|
||||
this.game.ArtworkBack = new Bitmap(files[0].Path.LocalPath);
|
||||
break;
|
||||
case Artwork.Type.Disc:
|
||||
this.game.ArtworkDVD = new Bitmap(files[0].Path.LocalPath);
|
||||
break;
|
||||
}
|
||||
this.game.SaveCover(ArtworkType.Value);
|
||||
UpdateArtworks();
|
||||
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private void NextButton(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
this.ArtworkType.Value = Artwork.NextType(this.ArtworkType.Value);
|
||||
}
|
||||
|
||||
private void PrevButton(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
this.ArtworkType.Value = Artwork.PrevType(this.ArtworkType.Value);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue