diff options
| author | Emmanuel Hansen <emmausssss@gmail.com> | 2022-07-08 18:47:11 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-08 15:47:11 -0300 |
| commit | 3af42d6c7e9e71c504b87a7b0f7f960fe83418fb (patch) | |
| tree | 2b27f12ee0273d5316229d31383619d915c3210d /Ryujinx.Ava/Ui/Controls | |
| parent | bccf5e8b5a8f3870dbf03bedb0eb46b85b78d5f4 (diff) | |
UI - Avalonia Part 3 (#3441)
* Add all other windows
* addreesed review
* Prevent "No Update" option from being deleted
* Select no update is the current update is removed from the title update window
* fix amiibo crash
Diffstat (limited to 'Ryujinx.Ava/Ui/Controls')
| -rw-r--r-- | Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml | 35 | ||||
| -rw-r--r-- | Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml.cs | 105 |
2 files changed, 140 insertions, 0 deletions
diff --git a/Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml b/Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml new file mode 100644 index 00000000..c6f43f43 --- /dev/null +++ b/Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml @@ -0,0 +1,35 @@ +<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" + xmlns:Locale="clr-namespace:Ryujinx.Ava.Common.Locale" + x:Class="Ryujinx.Ava.Ui.Controls.ProfileImageSelectionDialog" + SizeToContent="WidthAndHeight" + WindowStartupLocation="CenterOwner" + Title="{Locale:Locale ProfileImageSelectionTitle}" + CanResize="false"> + <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="5,10,5, 5"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="70" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <TextBlock FontWeight="Bold" FontSize="18" HorizontalAlignment="Center" Grid.Row="1" + Text="{Locale:Locale ProfileImageSelectionHeader}" /> + <TextBlock FontWeight="Bold" Grid.Row="2" Margin="10" MaxWidth="400" TextWrapping="Wrap" + HorizontalAlignment="Center" TextAlignment="Center" Text="{Locale:Locale ProfileImageSelectionNote}" /> + <StackPanel Margin="5,0" Spacing="10" Grid.Row="4" HorizontalAlignment="Center" + Orientation="Horizontal"> + <Button Name="Import" Click="Import_OnClick" Width="200"> + <TextBlock Text="{Locale:Locale ProfileImageSelectionImportImage}" /> + </Button> + <Button Name="SelectFirmwareImage" IsEnabled="{Binding FirmwareFound}" Click="SelectFirmwareImage_OnClick" + Width="200"> + <TextBlock Text="{Locale:Locale ProfileImageSelectionSelectAvatar}" /> + </Button> + </StackPanel> + </Grid> +</Window>
\ No newline at end of file diff --git a/Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml.cs b/Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml.cs new file mode 100644 index 00000000..728b8906 --- /dev/null +++ b/Ryujinx.Ava/Ui/Controls/ProfileImageSelectionDialog.axaml.cs @@ -0,0 +1,105 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using Ryujinx.Ava.Common.Locale; +using Ryujinx.Ava.Ui.Windows; +using Ryujinx.HLE.FileSystem; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Processing; +using System.IO; +using Image = SixLabors.ImageSharp.Image; + +namespace Ryujinx.Ava.Ui.Controls +{ + public class ProfileImageSelectionDialog : StyleableWindow + { + private readonly ContentManager _contentManager; + + public bool FirmwareFound => _contentManager.GetCurrentFirmwareVersion() != null; + + public byte[] BufferImageProfile { get; set; } + + public ProfileImageSelectionDialog(ContentManager contentManager) + { + _contentManager = contentManager; + DataContext = this; + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); +#endif + } + + public ProfileImageSelectionDialog() + { + DataContext = this; + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); +#endif + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + + private async void Import_OnClick(object sender, RoutedEventArgs e) + { + OpenFileDialog dialog = new(); + dialog.Filters.Add(new FileDialogFilter + { + Name = LocaleManager.Instance["AllSupportedFormats"], + Extensions = { "jpg", "jpeg", "png", "bmp" } + }); + dialog.Filters.Add(new FileDialogFilter { Name = "JPEG", Extensions = { "jpg", "jpeg" } }); + dialog.Filters.Add(new FileDialogFilter { Name = "PNG", Extensions = { "png" } }); + dialog.Filters.Add(new FileDialogFilter { Name = "BMP", Extensions = { "bmp" } }); + + dialog.AllowMultiple = false; + + string[] image = await dialog.ShowAsync(this); + + if (image != null) + { + if (image.Length > 0) + { + string imageFile = image[0]; + + ProcessProfileImage(File.ReadAllBytes(imageFile)); + } + + Close(); + } + } + + private async void SelectFirmwareImage_OnClick(object sender, RoutedEventArgs e) + { + if (FirmwareFound) + { + AvatarWindow window = new(_contentManager); + + await window.ShowDialog(this); + + BufferImageProfile = window.SelectedImage; + + Close(); + } + } + + private void ProcessProfileImage(byte[] buffer) + { + using (Image image = Image.Load(buffer)) + { + image.Mutate(x => x.Resize(256, 256)); + + using (MemoryStream streamJpg = new()) + { + image.SaveAsJpeg(streamJpg); + + BufferImageProfile = streamJpg.ToArray(); + } + } + } + } +}
\ No newline at end of file |
