add gui functionality

This commit is contained in:
Li 2023-04-21 18:21:21 +12:00
parent 526f756b7b
commit cc838ff1b5
26 changed files with 771 additions and 176 deletions

View File

@ -57,15 +57,27 @@
</Style>
<!-- Button styles -->
<Style Selector="Button:disabled /template/ ContentPresenter">
<Setter Property="Background">
<Setter.Value>Black</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>DarkRed</Setter.Value>
</Setter>
<Setter Property="TextBlock.Foreground">
<Setter.Value>DarkRed</Setter.Value>
</Setter>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter">
<Setter Property="Background">
<Setter.Value>Red</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>Black</Setter.Value>
<Setter.Value>DarkRed</Setter.Value>
</Setter>
<Setter Property="TextBlock.Foreground">
<Setter.Value>White</Setter.Value>
<Setter.Value>Black</Setter.Value>
</Setter>
</Style>

View File

@ -9,12 +9,13 @@
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
<None Remove="DEFAULTICON.PNG" />
<None Remove="PS1CD.PNG" />
<None Remove="UMD.png" />
</ItemGroup>
<ItemGroup>
<AvaloniaResource Include="PS1CD.PNG" />
<AvaloniaResource Include="UMD.PNG">
<AvaloniaResource Include="Ps1\PS1CD.PNG" />
<AvaloniaResource Include="Psp\UMD.PNG">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AvaloniaResource>
</ItemGroup>
@ -30,4 +31,9 @@
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.18" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.5.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GameBuilder\GameBuilder.csproj" />
<ProjectReference Include="..\LibChovy\LibChovy.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,26 @@
<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="80"
x:Class="ChovySign_GUI.Global.BrowseButton"
Height="60">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Name="browseLabel" Content="File Path:" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox Name="filePath" HorizontalAlignment="Stretch" VerticalAlignment="Center" Watermark="(None)" Grid.Column="0"/>
<Button Name="browseButton" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Center" Click="browseClick" Grid.Column="1"/>
</Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,143 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace ChovySign_GUI.Global
{
public partial class BrowseButton : UserControl
{
private string fileTypeName;
private string extension;
public event EventHandler<EventArgs>? FileChanged;
protected virtual void OnFileChanged(EventArgs e)
{
if(FileChanged is not null)
FileChanged(this, e);
}
public string Extension
{
get
{
return extension.Replace(".", "");
}
set
{
extension = value;
}
}
public string FileTypeName
{
get
{
return fileTypeName;
}
set
{
fileTypeName = value;
}
}
public string Watermark
{
get
{
return this.filePath.Watermark;
}
set
{
this.filePath.Watermark = value;
}
}
public string Label
{
get
{
string? lbl = this.browseLabel.Content as String;
if (lbl is null) return "";
else return lbl;
}
set
{
this.browseLabel.Content = value;
}
}
public bool ContainsFile
{
get
{
return (File.Exists(this.filePath.Text) && Path.GetExtension(this.filePath.Text).Equals("." + Extension, StringComparison.InvariantCultureIgnoreCase));
}
}
public string FilePath
{
get
{
if (!ContainsFile) return "";
return this.filePath.Text;
}
set
{
this.filePath.Text = value;
}
}
private async void browseClick(object sender, RoutedEventArgs e)
{
Button? btn = sender as Button;
if (btn is Button)
{
btn.IsEnabled = false;
OpenFileDialog browseDialog = new OpenFileDialog();
if (extension != "")
{
browseDialog.Filters = new List<FileDialogFilter>();
FileDialogFilter filter = new FileDialogFilter();
filter.Extensions.Add(extension);
filter.Name = fileTypeName;
browseDialog.Filters.Add(filter);
browseDialog.Title = "Select a " + fileTypeName + " file.";
}
else
{
browseDialog.Title = "Select a file.";
}
Window? currentWindow = this.VisualRoot as Window;
if (currentWindow is not Window) throw new Exception("could not find current window");
string[]? selectedFiles = await browseDialog.ShowAsync(currentWindow);
if (selectedFiles is not null && selectedFiles.Length > 0)
this.FilePath = selectedFiles.First();
btn.IsEnabled = true;
OnFileChanged(new EventArgs());
}
}
public BrowseButton()
{
InitializeComponent();
this.filePath.KeyUp += onKeyPress;
this.extension = "";
this.fileTypeName = "All Files";
}
private void onKeyPress(object? sender, KeyEventArgs e)
{
OnFileChanged(new EventArgs());
}
}
}

View File

@ -2,10 +2,10 @@
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="35"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="40"
x:Class="ChovySign_GUI.Global.KeySelector">
<!-- key selector -->
<Border Padding="4 4" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Border Padding="10 2" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />

View File

@ -0,0 +1,16 @@
<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="80"
x:Class="ChovySign_GUI.Global.LabeledTextBox"
Height="60">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Name="lblTxt" Content="Label:" VerticalAlignment="Bottom" Grid.Row="0"/>
<TextBox Name="txtBox" HorizontalAlignment="Stretch" VerticalAlignment="Center" MaxLength="128" Grid.Row="1"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,49 @@
using Avalonia.Controls;
namespace ChovySign_GUI.Global
{
public partial class LabeledTextBox : UserControl
{
public string Label
{
get
{
string? lbl = this.lblTxt.Content as string;
if (lbl is null) return "";
else return lbl;
}
set
{
this.lblTxt.Content = value;
}
}
public string Watermark
{
get
{
return this.txtBox.Watermark;
}
set
{
this.txtBox.Watermark = value;
}
}
public string Text
{
get
{
return this.txtBox.Text;
}
set
{
this.txtBox.Text = value;
}
}
public LabeledTextBox()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,18 @@
<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="ChovySign_GUI.Global.MessageBox" SizeToContent="WidthAndHeight" CanResize="False">
<StackPanel HorizontalAlignment="Center">
<TextBlock HorizontalAlignment="Center" Name="Text"/>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Name="Buttons">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Margin" Value="5"/>
</Style>
</StackPanel.Styles>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,77 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace ChovySign_GUI.Global
{
partial class MessageBox : Window
{
public enum MessageBoxButtons
{
Ok,
OkCancel,
YesNo,
YesNoCancel
}
public enum MessageBoxResult
{
Ok,
Cancel,
Yes,
No
}
public MessageBox()
{
AvaloniaXamlLoader.Load(this);
}
public static Task<MessageBoxResult> Show(Window parent, string text, string title, MessageBoxButtons buttons)
{
var msgbox = new MessageBox()
{
Title = title
};
msgbox.FindControl<TextBlock>("Text").Text = text;
var buttonPanel = msgbox.FindControl<StackPanel>("Buttons");
var res = MessageBoxResult.Ok;
void AddButton(string caption, MessageBoxResult r, bool def = false)
{
var btn = new Button { Content = caption };
btn.Click += (_, __) => {
res = r;
msgbox.Close();
};
buttonPanel.Children.Add(btn);
if (def)
res = r;
}
if (buttons == MessageBoxButtons.Ok || buttons == MessageBoxButtons.OkCancel)
AddButton("Ok", MessageBoxResult.Ok, true);
if (buttons == MessageBoxButtons.YesNo || buttons == MessageBoxButtons.YesNoCancel)
{
AddButton("Yes", MessageBoxResult.Yes);
AddButton("No", MessageBoxResult.No, true);
}
if (buttons == MessageBoxButtons.OkCancel || buttons == MessageBoxButtons.YesNoCancel)
AddButton("Cancel", MessageBoxResult.Cancel, true);
var tcs = new TaskCompletionSource<MessageBoxResult>();
msgbox.Closed += delegate { tcs.TrySetResult(res); };
if (parent != null)
msgbox.ShowDialog(parent);
else msgbox.Show();
return tcs.Task;
}
}
}

View File

@ -2,7 +2,7 @@
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="60"
x:Class="ChovySign_GUI.Global.ProgressStatus">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">

View File

@ -2,152 +2,21 @@
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"
xmlns:Global="clr-namespace:ChovySign_GUI.Global"
xmlns:Ps1="clr-namespace:ChovySign_GUI.Ps1"
xmlns:Psp="clr-namespace:ChovySign_GUI.Psp"
mc:Ignorable="d" d:DesignWidth="850" d:DesignHeight="850"
mc:Ignorable="d" d:DesignWidth="850" d:DesignHeight="950"
x:Class="ChovySign_GUI.MainWindow"
Title="Chovy Sign V2">
<Grid>
<TabControl>
<TabItem Header="PlayStation Portable">
<Psp:PspTab Name="pspTab"/>
</TabItem>
<TabItem Header="PlayStation 1">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="5*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Global:KeySelector Name="keySelector" Grid.Row="0" Grid.Column="1"/>
<!-- ISO Image selector -->
<Border Padding="4 4" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
<Image HorizontalAlignment="Stretch" VerticalAlignment="Center" Source="/PS1CD.PNG" Grid.Column="0"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="(Disc 1)" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox Name="cueText" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0"/>
<Button Name="browseButton" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="(Disc 2)" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox Name="cueText2" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0"/>
<Button Name="browseButton2" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</Grid>
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="(Disc 3)" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox Name="cueText3" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0"/>
<Button Name="browseButton3" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</Grid>
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="(Disc 4)" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox Name="cueText4" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0"/>
<Button Name="browseButton4" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</Grid>
<Grid Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="(Disc 5)" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox Name="cueText5" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0"/>
<Button Name="browseButton5" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</Grid>
</Grid>
</Grid>
</Border>
<Global:ProgressStatus Name="progressStatus" Grid.Row="2" Grid.Column="1"/>
</Grid>
<!-- Credits -->
<Label Content="SquallATF, Li, Motoharu, Davee, Dots TB, " VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
<Ps1:Ps1Tab Name="ps1Tab"/>
</TabItem>
</TabControl>
</TabControl>
</Grid>
</Window>

View File

@ -0,0 +1,35 @@
<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"
xmlns:Global="clr-namespace:ChovySign_GUI.Global"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="300"
x:Class="ChovySign_GUI.Ps1.CueSelector">
<!-- Bin/Cue Image selector -->
<Border Padding="5 5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Image HorizontalAlignment="Stretch" VerticalAlignment="Center" Source="/Ps1/PS1CD.PNG" Grid.Column="0"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
</Grid.RowDefinitions>
<Global:BrowseButton Name="discCue1" Extension="cue" FileTypeName="PS1 Cue Sheet" Label="Disc 1:" Grid.Row="0"/>
<Global:BrowseButton Name="discCue2" Extension="cue" FileTypeName="PS1 Cue Sheet" Label="Disc 2:" Grid.Row="1"/>
<Global:BrowseButton Name="discCue3" Extension="cue" FileTypeName="PS1 Cue Sheet" Label="Disc 3:" Grid.Row="2"/>
<Global:BrowseButton Name="discCue4" Extension="cue" FileTypeName="PS1 Cue Sheet" Label="Disc 4:" Grid.Row="3"/>
<Global:BrowseButton Name="discCue5" Extension="cue" FileTypeName="PS1 Cue Sheet" Label="Disc 5:" Grid.Row="4"/>
</Grid>
</Grid>
</Border>
</UserControl>

View File

@ -0,0 +1,88 @@
using Avalonia.Controls;
using System;
using System.Collections.Generic;
namespace ChovySign_GUI.Ps1
{
public partial class CueSelector : UserControl
{
public event EventHandler<EventArgs>? DiscsSelected;
protected virtual void OnDiscsSelected(EventArgs e)
{
if (DiscsSelected is not null)
DiscsSelected(this, e);
}
public string[] Discs
{
get
{
List<string> discList = new List<string>();
if (discCue1.ContainsFile) discList.Add(discCue1.FilePath);
else if (discCue2.ContainsFile) discList.Add(discCue2.FilePath);
else if (discCue3.ContainsFile) discList.Add(discCue3.FilePath);
else if (discCue4.ContainsFile) discList.Add(discCue4.FilePath);
else if (discCue5.ContainsFile) discList.Add(discCue5.FilePath);
return discList.ToArray();
}
}
public bool AnyDiscsSelected
{
get
{
return Discs.Length > 0;
}
}
private void clearAllAfter(int amt)
{
if (amt < 1) { discCue1.FilePath = ""; discCue1.IsEnabled = false; }
else discCue1.IsEnabled = true;
if (amt < 2) { discCue2.FilePath = ""; discCue2.IsEnabled = false; }
else discCue2.IsEnabled = true;
if (amt < 3) { discCue3.FilePath = ""; discCue3.IsEnabled = false; }
else discCue3.IsEnabled = true;
if (amt < 4) { discCue4.FilePath = ""; discCue4.IsEnabled = false; }
else discCue4.IsEnabled = true;
if (amt < 5) { discCue5.FilePath = ""; discCue5.IsEnabled = false; }
else discCue5.IsEnabled = true;
}
private void disableCueBoxes()
{
if (!discCue1.ContainsFile) clearAllAfter(1);
else if (!discCue2.ContainsFile) clearAllAfter(2);
else if (!discCue3.ContainsFile) clearAllAfter(3);
else if (!discCue4.ContainsFile) clearAllAfter(4);
else if (!discCue5.ContainsFile) clearAllAfter(5);
}
public CueSelector()
{
InitializeComponent();
disableCueBoxes();
discCue1.FileChanged += onFileChange;
discCue2.FileChanged += onFileChange;
discCue3.FileChanged += onFileChange;
discCue4.FileChanged += onFileChange;
discCue5.FileChanged += onFileChange;
}
private void onFileChange(object? sender, System.EventArgs e)
{
disableCueBoxes();
OnDiscsSelected(new EventArgs());
}
}
}

View File

@ -0,0 +1,29 @@
<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"
xmlns:Global="clr-namespace:ChovySign_GUI.Global"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="250"
x:Class="ChovySign_GUI.Ps1.GameInfoSelector">
<Border Padding="5 5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="7*" />
</Grid.ColumnDefinitions>
<Image Name="iconPreview" HorizontalAlignment="Center" VerticalAlignment="Center" Width="80" Height="80" Grid.Column="0"/>
<Grid HorizontalAlignment="Stretch" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
<RowDefinition Height="52"/>
</Grid.RowDefinitions>
<Global:LabeledTextBox HorizontalAlignment="Stretch" Name="gameTitle" Label="Title:" Watermark="The BEST PlayStation 1 Game" Grid.Row="0"/>
<Global:BrowseButton HorizontalAlignment="Stretch" Name="iconFile" Extension="png" FileTypeName="Portable Network Graphics" Watermark="(Default)" Label="icon0.png:" Grid.Row="1"/>
<Global:BrowseButton HorizontalAlignment="Stretch" Name="pic0File" Extension="png" FileTypeName="Portable Network Graphics" Watermark="(Default)" Label="pic0.png:" Grid.Row="2"/>
<Global:BrowseButton HorizontalAlignment="Stretch" Name="pic1File" Extension="png" FileTypeName="Portable Network Graphics" Watermark="(Default)" Label="pic1.png:" Grid.Row="3"/>
</Grid>
</Grid>
</Border>
</UserControl>

View File

@ -0,0 +1,149 @@
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using ChovySign_GUI.Global;
using GameBuilder.Pops;
using LibChovy.Art;
using System;
using System.IO;
using System.Threading.Tasks;
#pragma warning disable CS8601 // Possible null reference assignment.
// beacuse im checking if its null in the setter, but visual studio doesnt seem to understand :d
namespace ChovySign_GUI.Ps1
{
public partial class GameInfoSelector : UserControl
{
private byte[] iconCache;
private byte[] pic0Cache;
private byte[] pic1Cache;
public byte[] Icon0
{
get
{
return iconCache;
}
set
{
if(value is not null)
iconCache = value;
loadIcon(iconCache);
}
}
public byte[] Pic0
{
get
{
return pic0Cache;
}
set
{
if (value is not null)
pic0Cache = value;
}
}
public byte[] Pic1
{
get
{
return pic1Cache;
}
set
{
if (value is not null)
pic1Cache = value;
}
}
private void loadIcon(byte[] imageData)
{
using (MemoryStream imageStream = new MemoryStream(imageData))
this.iconPreview.Source = new Bitmap(imageStream);
}
public async Task GetGameInfo(string cueFile)
{
try
{
DiscInfo disc = new DiscInfo(cueFile);
this.gameTitle.Text = disc.DiscName;
byte[] newCover = await Downloader.DownloadCover(disc);
loadIcon(newCover);
iconCache = newCover;
}
catch (Exception) { }
}
private async Task<byte[]?> doLoad(BrowseButton imgFile, int width, int height)
{
imgFile.IsEnabled = false;
if (imgFile.FilePath != "")
{
try
{
byte[] imageData = await Resizer.LoadImage(imgFile.FilePath, width, height);
imgFile.IsEnabled = true;
return imageData;
}
catch (Exception)
{
Window? currentWindow = this.VisualRoot as Window;
if (currentWindow is not Window) throw new Exception("could not find current window");
await MessageBox.Show(currentWindow, "The image you selected is could not be loaded!", "Invalid image.", MessageBox.MessageBoxButtons.Ok);
imgFile.FilePath = "";
};
}
imgFile.IsEnabled = true;
return null;
}
private async void onIconChange(object? sender, EventArgs e)
{
BrowseButton? button = sender as BrowseButton;
if (button is null) return;
Icon0 = await doLoad(button, 80, 80);
}
private async void onPic0Change(object? sender, EventArgs e)
{
BrowseButton? button = sender as BrowseButton;
if (button is null) return;
Pic0 = await doLoad(button, 310, 180);
}
private async void onPic1Change(object? sender, EventArgs e)
{
BrowseButton? button = sender as BrowseButton;
if (button is null) return;
Pic1 = await doLoad(button, 480, 272);
}
public GameInfoSelector()
{
InitializeComponent();
iconCache = LibChovy.Resources.ICON0;
pic0Cache = LibChovy.Resources.PIC0;
pic1Cache = LibChovy.Resources.PIC1;
loadIcon(iconCache);
this.iconFile.FileChanged += onIconChange;
this.pic0File.FileChanged += onPic0Change;
this.pic1File.FileChanged += onPic1Change;
}
}
}
#pragma warning restore CS8601 // Possible null reference assignment.

View File

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 164 KiB

View File

@ -0,0 +1,34 @@
<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"
xmlns:Global="clr-namespace:ChovySign_GUI.Global"
xmlns:Ps1="clr-namespace:ChovySign_GUI.Ps1"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="900"
x:Class="ChovySign_GUI.Ps1.Ps1Tab">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.2*" />
<RowDefinition Height="1.5*" />
<RowDefinition Height="1.3*" />
<RowDefinition Height="0.6*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Global:KeySelector Name="keySelector" Grid.Row="0" Grid.Column="1"/>
<Ps1:CueSelector Name="discSelector" Grid.Row="1" Grid.Column="1"/>
<Ps1:GameInfoSelector Name="gameInfo" Grid.Row="2" Grid.Column="1"/>
<Global:ProgressStatus VerticalAlignment="Center" Name="progressStatus" Grid.Row="3" Grid.Column="1"/>
</Grid>
<!-- Credits -->
<Label Content="Li, Dots TB, SquallATF, Motoharu, Davee" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,27 @@
using Avalonia.Controls;
using System.Linq;
namespace ChovySign_GUI.Ps1
{
public partial class Ps1Tab : UserControl
{
public Ps1Tab()
{
InitializeComponent();
discSelector.DiscsSelected += onDiscSelected;
progressStatus.IsEnabled = false;
}
private void onDiscSelected(object? sender, System.EventArgs e)
{
CueSelector? cueSelector = sender as CueSelector;
if (cueSelector is null) return;
if (cueSelector.AnyDiscsSelected)
_ = this.gameInfo.GetGameInfo(cueSelector.Discs.First());
else
progressStatus.IsEnabled = false;
}
}
}

View File

@ -2,10 +2,11 @@
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="200"
xmlns:Global="clr-namespace:ChovySign_GUI.Global"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="145"
x:Class="ChovySign_GUI.Psp.IsoSelector">
<!-- ISO Image selector -->
<Border Padding="4 4" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<Border Padding="10 10" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
@ -16,25 +17,10 @@
<RowDefinition Height="5*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Image HorizontalAlignment="Stretch" VerticalAlignment="Center" Source="/UMD.PNG" Grid.Row="0"/>
<Image HorizontalAlignment="Center" VerticalAlignment="Center" Width="120" Source="/Psp/UMD.PNG" Grid.Row="0"/>
<CheckBox Content="Compress PBP" HorizontalAlignment="Center" Grid.Row="1"/>
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="ISO Image:" VerticalAlignment="Bottom" Grid.Row="0"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="0"/>
<Button Name="browseButton" Content="Browse" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="1"/>
</Grid>
</Grid>
<Global:BrowseButton Name="umdFile" Extension="iso" FileTypeName="Universal Media Disc 'UMD' Disc Image (ISO9660)" Label="UMD Image:" Grid.Column="1"/>
</Grid>
</Border>
</UserControl>

View File

@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Global="clr-namespace:ChovySign_GUI.Global"
xmlns:Psp="clr-namespace:ChovySign_GUI.Psp"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="900"
x:Class="ChovySign_GUI.Psp.PspTab">
<Grid>
<Grid>
@ -15,7 +15,7 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
@ -26,6 +26,6 @@
</Grid>
<!-- Credits -->
<Label Content="Li, Dots TB, Motoharu, SquallATF" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
<Label Content="Li, Dots TB, SquallATF, Motoharu, Davee" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
</UserControl>

View File

@ -7,6 +7,8 @@ namespace ChovySign_GUI.Psp
public PspTab()
{
InitializeComponent();
this.progressStatus.IsEnabled = false;
}
}
}

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -13,8 +13,8 @@ namespace GameBuilder.Pops
public class DiscInfo
{
private string cueFile;
private string? discName;
private string? discId;
private string discName;
private string discId;
public string CueFile
{
@ -89,7 +89,7 @@ namespace GameBuilder.Pops
discName = binUtil.ReadCDStr(0x20);
}
}
if (discName == "") discName = Path.GetFileNameWithoutExtension(cueFile);
if (discId is null) discId = "SLUS00001";
}

View File

@ -6,9 +6,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibChovy
namespace LibChovy.Art
{
internal class ArtDownloader
public class Downloader
{
private const string coverApi = "https://raw.githubusercontent.com/xlenore/psx-covers/main/covers/";
private static HttpClient httpClient = new HttpClient();
@ -41,9 +41,9 @@ namespace LibChovy
}
}
}
}
catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); return Resources.ICON0; }
catch (Exception) { return Resources.ICON0; }
}
}

28
LibChovy/Art/Resizer.cs Normal file
View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibChovy.Art
{
public class Resizer
{
public static async Task<byte[]> LoadImage(string imagePath, int width=80, int height=80)
{
return await LoadImage(await File.ReadAllBytesAsync(imagePath), width, height);
}
public static async Task<byte[]> LoadImage(byte[] imageData, int width=80, int height=80)
{
using (Image img = Image.Load(imageData))
{
img.Mutate(x => x.Resize(width, height));
using (MemoryStream png = new MemoryStream())
{
await img.SaveAsPngAsync(png);
return png.ToArray();
}
}
}
}
}

View File

@ -1,5 +1,6 @@
using GameBuilder.Pops;
using GameBuilder.Psp;
using LibChovy.Art;
using System;
using System.Collections.Generic;
using System.Drawing;
@ -70,7 +71,7 @@ namespace LibChovy
{
if (icon0 is null)
{
byte[] coverImg = ArtDownloader.DownloadCover(FirstDisc).Result;
byte[] coverImg = Downloader.DownloadCover(FirstDisc).Result;
icon0 = coverImg;
return coverImg;
}