mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2026-04-21 16:02:01 +00:00
Testing new stuff
This commit is contained in:
parent
746dc2cd22
commit
6619de59ab
4 changed files with 135 additions and 1 deletions
|
|
@ -10,6 +10,9 @@ namespace Ryujinx.Ava.UI.Models
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public partial byte[] Image { get; set; }
|
public partial byte[] Image { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial bool FirmwareFound { get; set; }
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public partial string Name { get; set; } = string.Empty;
|
public partial string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,37 @@
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
Source="{Binding Image, Converter={x:Static helpers:BitmapArrayValueConverter.Instance}}" />
|
Source="{Binding Image, Converter={x:Static helpers:BitmapArrayValueConverter.Instance}}" />
|
||||||
|
<Border
|
||||||
|
Margin="2"
|
||||||
|
Height="24"
|
||||||
|
Width="24"
|
||||||
|
CornerRadius="12"
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
Background="{DynamicResource ThemeContentBackgroundColor}">
|
||||||
|
<Button
|
||||||
|
MaxHeight="24"
|
||||||
|
Name="ProfileImageButton"
|
||||||
|
MaxWidth="24"
|
||||||
|
MinHeight="24"
|
||||||
|
MinWidth="24"
|
||||||
|
CornerRadius="12"
|
||||||
|
Padding="0">
|
||||||
|
<Button.Flyout>
|
||||||
|
<MenuFlyout Placement="Bottom">
|
||||||
|
<MenuItem
|
||||||
|
Header="{ext:Locale ProfileImageSelectionImportImage}"
|
||||||
|
Icon="{ext:Icon fa-solid fa-image}"
|
||||||
|
Click="Import_OnClick" />
|
||||||
|
<MenuItem
|
||||||
|
Header="{ext:Locale ProfileImageSelectionSelectAvatar}"
|
||||||
|
Icon="{ext:Icon fa-solid fa-floppy-disk}"
|
||||||
|
Click="SelectFirmwareImage_OnClick" />
|
||||||
|
</MenuFlyout>
|
||||||
|
</Button.Flyout>
|
||||||
|
<ui:SymbolIcon Symbol="Edit" />
|
||||||
|
</Button>
|
||||||
|
</Border>
|
||||||
</Panel>
|
</Panel>
|
||||||
</Border>
|
</Border>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,21 @@ using Ryujinx.Ava.UI.Helpers;
|
||||||
using Ryujinx.Ava.UI.Models;
|
using Ryujinx.Ava.UI.Models;
|
||||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||||
using UserProfile = Ryujinx.Ava.UI.Models.UserProfile;
|
using UserProfile = Ryujinx.Ava.UI.Models.UserProfile;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
using Ryujinx.HLE.FileSystem;
|
||||||
|
using SkiaSharp;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Avalonia.VisualTree;
|
||||||
|
|
||||||
namespace Ryujinx.Ava.UI.Views.User
|
namespace Ryujinx.Ava.UI.Views.User
|
||||||
{
|
{
|
||||||
public partial class UserEditorView : RyujinxControl<TempProfile>
|
public partial class UserEditorView : RyujinxControl<TempProfile>
|
||||||
{
|
{
|
||||||
private NavigationDialogHost _parent;
|
private NavigationDialogHost _parent;
|
||||||
|
private ContentManager _contentManager;
|
||||||
private UserProfile _profile;
|
private UserProfile _profile;
|
||||||
|
private TempProfile _tempProfile;
|
||||||
private bool _isNewUser;
|
private bool _isNewUser;
|
||||||
public static uint MaxProfileNameLength => 0x20;
|
public static uint MaxProfileNameLength => 0x20;
|
||||||
public bool IsDeletable => _profile.UserId != AccountManager.DefaultUserId;
|
public bool IsDeletable => _profile.UserId != AccountManager.DefaultUserId;
|
||||||
|
|
@ -40,8 +48,13 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
_isNewUser = isNewUser;
|
_isNewUser = isNewUser;
|
||||||
_profile = profile;
|
_profile = profile;
|
||||||
ViewModel = new TempProfile(_profile);
|
ViewModel = new TempProfile(_profile);
|
||||||
|
_tempProfile = ViewModel; // <-- this is critical
|
||||||
|
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|
||||||
|
_contentManager = _parent.ContentManager;
|
||||||
|
ViewModel.FirmwareFound = _contentManager.GetCurrentFirmwareVersion() != null;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,5 +169,85 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
SelectProfileImage();
|
SelectProfileImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void SelectFirmwareImage_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (ViewModel.FirmwareFound)
|
||||||
|
{
|
||||||
|
_parent.Navigate(typeof(UserFirmwareAvatarSelectorView), (_parent, _tempProfile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void Import_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var result = await ((Window)this.GetVisualRoot()!).StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||||
|
{
|
||||||
|
Title = LocaleManager.Instance[LocaleKeys.LoadSupportedImageFormatDialogTitle],
|
||||||
|
AllowMultiple = false,
|
||||||
|
FileTypeFilter = new List<FilePickerFileType>
|
||||||
|
{
|
||||||
|
new(LocaleManager.Instance[LocaleKeys.AllSupportedFormats])
|
||||||
|
{
|
||||||
|
Patterns = ["*.jpg", "*.jpeg", "*.png", "*.bmp"],
|
||||||
|
AppleUniformTypeIdentifiers = ["public.jpeg", "public.png", "com.microsoft.bmp"],
|
||||||
|
MimeTypes = ["image/jpeg", "image/png", "image/bmp"],
|
||||||
|
},
|
||||||
|
new("JPG")
|
||||||
|
{
|
||||||
|
Patterns = ["*.jpg"],
|
||||||
|
AppleUniformTypeIdentifiers = ["public.jpeg"],
|
||||||
|
MimeTypes = ["image/jpeg"],
|
||||||
|
},
|
||||||
|
new("JPEG")
|
||||||
|
{
|
||||||
|
Patterns = ["*.jpeg"],
|
||||||
|
AppleUniformTypeIdentifiers = ["public.jpeg"],
|
||||||
|
MimeTypes = ["image/jpeg"],
|
||||||
|
},
|
||||||
|
new("PNG")
|
||||||
|
{
|
||||||
|
Patterns = ["*.png"],
|
||||||
|
AppleUniformTypeIdentifiers = ["public.png"],
|
||||||
|
MimeTypes = ["image/png"],
|
||||||
|
},
|
||||||
|
new("BMP")
|
||||||
|
{
|
||||||
|
Patterns = ["*.bmp"],
|
||||||
|
AppleUniformTypeIdentifiers = ["com.microsoft.bmp"],
|
||||||
|
MimeTypes = ["image/bmp"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (DataContext is not TempProfile temp)
|
||||||
|
return;
|
||||||
|
|
||||||
|
temp.Image = ProcessProfileImage(File.ReadAllBytes(result[0].Path.LocalPath));
|
||||||
|
|
||||||
|
if (_profile != null)
|
||||||
|
_profile.Image = temp.Image;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] ProcessProfileImage(byte[] buffer)
|
||||||
|
{
|
||||||
|
using SKBitmap bitmap = SKBitmap.Decode(buffer);
|
||||||
|
|
||||||
|
SKBitmap resizedBitmap = bitmap.Resize(new SKImageInfo(256, 256), SKFilterQuality.High);
|
||||||
|
|
||||||
|
using MemoryStream streamJpg = new();
|
||||||
|
|
||||||
|
if (resizedBitmap != null)
|
||||||
|
{
|
||||||
|
using SKImage image = SKImage.FromBitmap(resizedBitmap);
|
||||||
|
using SKData dataJpeg = image.Encode(SKEncodedImageFormat.Jpeg, 100);
|
||||||
|
|
||||||
|
dataJpeg.SaveTo(streamJpg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return streamJpg.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ using FluentAvalonia.UI.Controls;
|
||||||
using FluentAvalonia.UI.Navigation;
|
using FluentAvalonia.UI.Navigation;
|
||||||
using Ryujinx.Ava.UI.Controls;
|
using Ryujinx.Ava.UI.Controls;
|
||||||
using Ryujinx.Ava.UI.Models;
|
using Ryujinx.Ava.UI.Models;
|
||||||
|
using Ryujinx.Ava.Common.Locale;
|
||||||
using Ryujinx.Ava.UI.ViewModels;
|
using Ryujinx.Ava.UI.ViewModels;
|
||||||
using Ryujinx.HLE.FileSystem;
|
using Ryujinx.HLE.FileSystem;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
@ -14,12 +15,14 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
{
|
{
|
||||||
private NavigationDialogHost _parent;
|
private NavigationDialogHost _parent;
|
||||||
private TempProfile _profile;
|
private TempProfile _profile;
|
||||||
|
private ContentManager _contentManager;
|
||||||
|
|
||||||
public UserFirmwareAvatarSelectorView(ContentManager contentManager)
|
public UserFirmwareAvatarSelectorView(ContentManager contentManager)
|
||||||
{
|
{
|
||||||
ContentManager = contentManager;
|
ContentManager = contentManager;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
AddHandler(Frame.NavigatedToEvent, (s, e) => NavigatedTo(e), RoutingStrategies.Direct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserFirmwareAvatarSelectorView()
|
public UserFirmwareAvatarSelectorView()
|
||||||
|
|
@ -40,9 +43,13 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
{
|
{
|
||||||
(_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter;
|
(_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter;
|
||||||
ContentManager = _parent.ContentManager;
|
ContentManager = _parent.ContentManager;
|
||||||
|
|
||||||
|
((ContentDialog)_parent.Parent).Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {LocaleManager.Instance[LocaleKeys.ProfileImageSelectionHeader]}";
|
||||||
|
|
||||||
if (Program.PreviewerDetached)
|
if (Program.PreviewerDetached)
|
||||||
{
|
{
|
||||||
ViewModel = new UserFirmwareAvatarSelectorViewModel();
|
ViewModel = new UserFirmwareAvatarSelectorViewModel();
|
||||||
|
ViewModel.FirmwareFound = ContentManager.GetCurrentFirmwareVersion() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue