ui rework
Some checks failed
Java CI / test (push) Has been cancelled

This commit is contained in:
WeeXnes 2025-04-26 12:21:08 +02:00
parent 53b53a4e7c
commit b891f62d34
8 changed files with 272 additions and 306 deletions

View file

@ -1,30 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PS2_Manager.EditGame">
<Grid RowDefinitions="*, 40">
<ScrollViewer Grid.Row="0">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Text="Display Name:" HorizontalAlignment="Center" Padding="0,10"/>
<TextBox Name="DisplayNameBox"/>
<Separator/>
<Button Content="Calculate Checksums" Click="ChecksumButtonOnClick" HorizontalAlignment="Stretch"></Button>
<Border Background="#35313d" CornerRadius="5" Padding="10" Margin="0,5" IsVisible="False" Name="ChecksumArea">
<StackPanel>
<TextBlock FontSize="10" Name="MD5TextBlock"/>
<TextBlock FontSize="10" Name="SHATextBlock"/>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1" ColumnDefinitions="*,*">
<Button Content="Undo" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Edit_OnClick"/>
<Button Content="Save" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Save_OnClick"/>
</Grid>
</Grid>
</UserControl>

View file

@ -1,82 +0,0 @@
using System;
using System.ComponentModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using PS2_Manager.Core;
namespace PS2_Manager;
public partial class EditGame : UserControl
{
public Game game { get; set; }
public UpdateVar<string> MD5Hash { get; set; } = new UpdateVar<string>();
public UpdateVar<string> SHA1Hash { get; set; } = new UpdateVar<string>();
public EditGame(Game _game)
{
this.game = _game;
InitializeComponent();
DisplayNameBox.Text = this.game.Name;
MD5Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.Info("MD5 Hash calculated");
MD5TextBlock.Text = "MD5: " + MD5Hash.Value;
});
};
SHA1Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.Info("SHA1 Hash calculated");
SHATextBlock.Text = "SHA1: " + SHA1Hash.Value;
});
};
}
private void ChecksumButtonOnClick(object? sender, RoutedEventArgs e)
{
this.GetChecksum();
}
public void GetChecksum()
{
string filePath = this.game.GamePath;
MD5TextBlock.Text = "MD5: Loading...";
SHATextBlock.Text = "SHA1: Loading...";
ChecksumArea.IsVisible = true;
BackgroundWorker md5Worker = new BackgroundWorker();
BackgroundWorker sha1Worker = new BackgroundWorker();
md5Worker.DoWork += (s, e) =>
{
this.MD5Hash.Value = Checksum.GetMD5Hash(filePath);
};
sha1Worker.DoWork += (s, e) =>
{
this.SHA1Hash.Value = Checksum.GetSHA1Hash(filePath);
};
md5Worker.RunWorkerAsync();
Console.Info("MD5 Hashing started...");
sha1Worker.RunWorkerAsync();
Console.Info("SHA1 Hashing started...");
}
private void Save_OnClick(object? sender, RoutedEventArgs e)
{
this.game.ChangeName(DisplayNameBox.Text);
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
private void Edit_OnClick(object? sender, RoutedEventArgs e)
{
DisplayNameBox.Text = game.Name;
}
}

View file

@ -4,27 +4,5 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="PS2_Manager.GameInfo">
<Grid RowDefinitions="350, *, *, *, *">
<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"
Name="GameIdTextBlock"/>
<TextBlock Grid.Row="3" Text="" HorizontalAlignment="Center"
Name="IsoSizeTextBlock"/>
<TextBlock Grid.Row="4" Text="" HorizontalAlignment="Center"
Name="GameDateTextBlock"/>
</Grid>
</UserControl>

View file

@ -14,112 +14,16 @@ 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;
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()
{
Console.Info("Showing: " + ArtworkType.Value.ToString());
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;
}
Console.Info("Updating " + ArtworkType.Value + " Artwork for " + this.game.GameID);
this.game.SaveCover(ArtworkType.Value);
UpdateArtworks();
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
else
{
Console.Error("OpenFilePicker was called but Canceled or no Files selected");
}
}
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);
}
}

View file

@ -11,7 +11,8 @@
Width="990"
Height="520"
WindowStartupLocation="CenterScreen"
Loaded="Control_OnLoaded">
Loaded="Control_OnLoaded"
Foreground="White">
<Grid ColumnDefinitions="680, 10, 300" Background="Transparent">
<Grid Grid.Column="0" RowDefinitions="20, *">
<Grid Grid.Row="0">
@ -41,7 +42,7 @@
<MenuItem Header="Show Details"/>
</ContextMenu>
</Border.ContextMenu>
<TextBlock Text="{Binding Name}"/>
<TextBlock Foreground="White" Text="{Binding Name}"/>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
@ -68,7 +69,28 @@
</Border>
<Border Grid.Column="2">
<Border Margin="2,0,0,0" Name="GameEdit">
<Grid RowDefinitions="*, 40">
<ScrollViewer Grid.Row="0">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Foreground="White" Text="Display Name:" HorizontalAlignment="Center" Padding="0,10"/>
<TextBox Foreground="White" Name="NameTextBox_Edit"/>
<Separator/>
<Button Foreground="White" Content="Calculate Checksums" Click="ChecksumButtonOnClick" HorizontalAlignment="Stretch"></Button>
<Border Background="#35313d" CornerRadius="5" Padding="10" Margin="0,5" IsVisible="False" Name="ChecksumArea">
<StackPanel>
<TextBlock Foreground="White" FontSize="10" Name="MD5TextBlock"/>
<TextBlock Foreground="White" FontSize="10" Name="SHATextBlock"/>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1" ColumnDefinitions="*,*">
<Button Foreground="White" Content="Undo" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Undo_OnClick"/>
<Button Foreground="White" Content="Save" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Save_OnClick"/>
</Grid>
</Grid>
</Border>
</Border>
</Grid>
@ -76,9 +98,31 @@
</Grid>
</Grid>
<Grid Grid.Column="2" RowDefinitions="20, *" IsVisible="False" Name="GameShowcaseGrid">
<Grid Grid.Column="2" RowDefinitions="20, *" Name="GameShowcaseGrid">
<Border Grid.Row="1" Background="#35313d" CornerRadius="10" Name="InfoWindow" >
<Grid RowDefinitions="350, *, *, *, *">
<Grid Grid.Row="0" ColumnDefinitions="*, 205, *">
<Button Foreground="White" Grid.Column="0" Content="←" HorizontalAlignment="Center" VerticalAlignment="Center" Click="PrevButton"/>
<Button Foreground="White" 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 Foreground="White" Grid.Row="1" Text="" HorizontalAlignment="Center"
Name="GameNameTextBlock"/>
<TextBlock Foreground="White" Grid.Row="2" Text="" HorizontalAlignment="Center"
Name="GameIdTextBlock"/>
<TextBlock Foreground="White" Grid.Row="3" Text="" HorizontalAlignment="Center"
Name="IsoSizeTextBlock"/>
<TextBlock Foreground="White" Grid.Row="4" Text="" HorizontalAlignment="Center"
Name="GameDateTextBlock"/>
</Grid>
</Border>
</Grid>
</Grid>

View file

@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using PS2_Manager.Core;
namespace PS2_Manager;
@ -13,22 +17,68 @@ namespace PS2_Manager;
public partial class MainWindow : Window
{
public static EventHandler? RefreshGamesListTrigger { get; set; }
public UpdateVar<Artwork.Type> ArtworkType { get; set; } = new UpdateVar<Artwork.Type>();
public UpdateVar<string> MD5Hash { get; set; } = new UpdateVar<string>();
public UpdateVar<string> SHA1Hash { get; set; } = new UpdateVar<string>();
public MainWindow()
{
InitializeComponent();
RefreshGamesListTrigger += FetchGamesFromLibrary;
}
private void ShowcaseGame(Game game)
ArtworkType.ValueChanged += UpdateArtworks;
MD5Hash.ValueChanged += () =>
{
GameShowcaseGrid.IsVisible = true;
InfoWindow.Child = new GameInfo(game);
GameEdit.Child = new EditGame(game);
Console.Info(game + " set as Showcase");
Dispatcher.UIThread.Invoke(() =>
{
Console.Info("MD5 Hash calculated");
MD5TextBlock.Text = "MD5: " + MD5Hash.Value;
});
};
SHA1Hash.ValueChanged += () =>
{
Dispatcher.UIThread.Invoke(() =>
{
Console.Info("SHA1 Hash calculated");
SHATextBlock.Text = "SHA1: " + SHA1Hash.Value;
});
};
}
private void GamesList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
Console.Info("Selected " + selectedGame + " from ListView");
SetEditArea();
GameShowcaseGrid.IsVisible = true;
SetShowcaseArea();
}
}
private void SetShowcaseArea()
{
if (GamesList.SelectedItem is Game selectedGame)
{
ArtworkType.Value = Artwork.Type.Front;
GameNameTextBlock.Text = selectedGame.Name;
GameIdTextBlock.Text = selectedGame.GameID;
FileInfo fileInfo = new FileInfo(selectedGame.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 SetEditArea()
{
if (GamesList.SelectedItem is Game selectedGame)
{
NameTextBox_Edit.Text = selectedGame.Name;
}
}
private void WindowDrag(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
@ -71,7 +121,6 @@ public partial class MainWindow : Window
private async void Control_OnLoaded(object? sender, RoutedEventArgs e)
{
WindowTitle.Text = "PS2 Games Manager";
GameEdit.Child = new Welcome();
FetchGamesFromLibrary();
}
@ -92,14 +141,7 @@ public partial class MainWindow : Window
GamesList.ItemsSource = Games;
}
private void GamesList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
Console.Info("Selected " + selectedGame + " from ListView");
this.ShowcaseGame(selectedGame);
}
}
private void DeleteButton(object? sender, RoutedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
@ -115,4 +157,167 @@ public partial class MainWindow : Window
FetchGamesFromLibrary();
}
//Game Edit Area/////////////////////////////////////////////////////////////
private void Save_OnClick(object? sender, RoutedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
selectedGame.ChangeName(NameTextBox_Edit.Text ?? "Error");
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
}
private void Undo_OnClick(object? sender, RoutedEventArgs e)
{
if (GamesList.SelectedItem is Game selectedGame)
{
NameTextBox_Edit.Text = selectedGame.Name;
}
}
private void ChecksumButtonOnClick(object? sender, RoutedEventArgs e)
{
this.GetChecksum();
}
public void GetChecksum()
{
if (GamesList.SelectedItem is Game selectedGame)
{
string filePath = selectedGame.GamePath;
MD5TextBlock.Text = "MD5: Loading...";
SHATextBlock.Text = "SHA1: Loading...";
ChecksumArea.IsVisible = true;
BackgroundWorker md5Worker = new BackgroundWorker();
BackgroundWorker sha1Worker = new BackgroundWorker();
md5Worker.DoWork += (s, e) =>
{
this.MD5Hash.Value = Checksum.GetMD5Hash(filePath);
};
sha1Worker.DoWork += (s, e) =>
{
this.SHA1Hash.Value = Checksum.GetSHA1Hash(filePath);
};
md5Worker.RunWorkerAsync();
Console.Info("MD5 Hashing started...");
sha1Worker.RunWorkerAsync();
Console.Info("SHA1 Hashing started...");
}
}
//Game Showcase Area/////////////////////////////////////////////////////////////
private void UpdateArtworks()
{
if (GamesList.SelectedItem is Game selectedGame)
{
Console.Info("Showing: " + ArtworkType.Value.ToString());
Bitmap? tempBitmap = null;
switch (ArtworkType.Value)
{
case Artwork.Type.Front:
CoverContainer.Height = 292;
tempBitmap = selectedGame.ArtworkFront;
break;
case Artwork.Type.Back:
CoverContainer.Height = 292;
tempBitmap = selectedGame.ArtworkBack;
break;
case Artwork.Type.Disc:
CoverContainer.Height = CoverContainer.Width;
tempBitmap = selectedGame.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)
{
if (GamesList.SelectedItem is Game selectedGame)
{
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:
selectedGame.ArtworkFront = new Bitmap(files[0].Path.LocalPath);
break;
case Artwork.Type.Back:
selectedGame.ArtworkBack = new Bitmap(files[0].Path.LocalPath);
break;
case Artwork.Type.Disc:
selectedGame.ArtworkDVD = new Bitmap(files[0].Path.LocalPath);
break;
}
Console.Info("Updating " + ArtworkType.Value + " Artwork for " + selectedGame.GameID);
selectedGame.SaveCover(ArtworkType.Value);
UpdateArtworks();
MainWindow.RefreshGamesListTrigger?.Invoke(null, EventArgs.Empty);
}
else
{
Console.Error("OpenFilePicker was called but Canceled or no Files selected");
}
}
}
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);
}
}

View file

@ -1,31 +0,0 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PS2_Manager.MessageBox"
Title="MessageBox"
SystemDecorations="None">
<Grid RowDefinitions="20, *">
<Grid Grid.Row="0">
<Border Background="#35313d"
PointerPressed="WindowDrag">
<Grid ColumnDefinitions="*, 20">
<TextBlock Name="WindowTitle" FontSize="12" Text="Install Game" Padding="8,0,0,0" VerticalAlignment="Center"/>
<Border Grid.Column="1" Background="#4b4753">
<TextBlock FontSize="12" Text="×" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</Border>
</Grid>
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto,*" Margin="20">
<Border Margin="0,0,0,0">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Label Content="Oh no! an error has occurred" Foreground="White" HorizontalAlignment="Center" FontSize="25"/>
<Label Content="full exception log has been dumped into error__log.txt" Foreground="White" HorizontalAlignment="Center" FontSize="12"/>
<Label Content="" Name="ErrorDump" Foreground="Gray" HorizontalAlignment="Center" FontSize="12" Padding="0,15,0,0"/>
</StackPanel>
</Border>
</Grid>
</Grid>
</Window>

View file

@ -1,22 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
namespace PS2_Manager;
public partial class MessageBox : Window
{
public MessageBox(string messageContent)
{
InitializeComponent();
ErrorDump.Content = "Exception: " + messageContent;
}
private void WindowDrag(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
BeginMoveDrag(e);
}
}
}