mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-03-14 20:00:17 +00:00
Fix SaveManager bug
This commit is contained in:
parent
f4af6c7375
commit
8eb3984981
3 changed files with 135 additions and 83 deletions
112
Ryujinx.Ava/UI/ViewModels/UserSaveManagerViewModel.cs
Normal file
112
Ryujinx.Ava/UI/ViewModels/UserSaveManagerViewModel.cs
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
using DynamicData;
|
||||||
|
using DynamicData.Binding;
|
||||||
|
using Ryujinx.Ava.UI.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace Ryujinx.Ava.UI.ViewModels;
|
||||||
|
|
||||||
|
public class UserSaveManagerViewModel : BaseModel
|
||||||
|
{
|
||||||
|
private int _sortIndex;
|
||||||
|
private int _orderIndex;
|
||||||
|
private string _search;
|
||||||
|
private ObservableCollection<SaveModel> _saves;
|
||||||
|
private ObservableCollection<SaveModel> _views;
|
||||||
|
|
||||||
|
public int SortIndex
|
||||||
|
{
|
||||||
|
get => _sortIndex;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_sortIndex = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
Sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int OrderIndex
|
||||||
|
{
|
||||||
|
get => _orderIndex;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_orderIndex = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
Sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Search
|
||||||
|
{
|
||||||
|
get => _search;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_search = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
Sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<SaveModel> Saves
|
||||||
|
{
|
||||||
|
get => _saves;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_saves = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
Sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<SaveModel> Views
|
||||||
|
{
|
||||||
|
get => _views;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserSaveManagerViewModel()
|
||||||
|
{
|
||||||
|
_saves = new ObservableCollection<SaveModel>();
|
||||||
|
_views = new ObservableCollection<SaveModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Sort()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Sorting");
|
||||||
|
Saves.AsObservableChangeSet()
|
||||||
|
.Filter(Filter)
|
||||||
|
.Sort(GetComparer())
|
||||||
|
.Bind(out var view).AsObservableList();
|
||||||
|
|
||||||
|
_views.Clear();
|
||||||
|
_views.AddRange(view);
|
||||||
|
OnPropertyChanged(nameof(Views));
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Filter(object arg)
|
||||||
|
{
|
||||||
|
if (arg is SaveModel save)
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(_search) || save.Title.ToLower().Contains(_search.ToLower());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IComparer<SaveModel> GetComparer()
|
||||||
|
{
|
||||||
|
switch (SortIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return OrderIndex == 0
|
||||||
|
? SortExpressionComparer<SaveModel>.Ascending(save => save.Title)
|
||||||
|
: SortExpressionComparer<SaveModel>.Descending(save => save.Title);
|
||||||
|
case 1:
|
||||||
|
return OrderIndex == 0
|
||||||
|
? SortExpressionComparer<SaveModel>.Ascending(save => save.Size)
|
||||||
|
: SortExpressionComparer<SaveModel>.Descending(save => save.Size);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,13 +7,19 @@
|
||||||
xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale"
|
xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale"
|
||||||
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
||||||
xmlns:models="clr-namespace:Ryujinx.Ava.UI.Models"
|
xmlns:models="clr-namespace:Ryujinx.Ava.UI.Models"
|
||||||
|
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
Height="400"
|
Height="400"
|
||||||
Width="550"
|
Width="550"
|
||||||
x:Class="Ryujinx.Ava.UI.Views.User.UserSaveManager"
|
x:Class="Ryujinx.Ava.UI.Views.User.UserSaveManager"
|
||||||
|
x:CompileBindings="True"
|
||||||
|
x:DataType="viewModels:UserSaveManagerViewModel"
|
||||||
Focusable="True">
|
Focusable="True">
|
||||||
|
<Design.DataContext>
|
||||||
|
<viewModels:UserSaveManagerViewModel />
|
||||||
|
</Design.DataContext>
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<helpers:BitmapArrayValueConverter x:Key="ByteImage" />
|
<helpers:BitmapArrayValueConverter x:Key="ByteImage" />
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
|
@ -96,7 +102,7 @@
|
||||||
VerticalAlignment="Stretch">
|
VerticalAlignment="Stretch">
|
||||||
<ListBox
|
<ListBox
|
||||||
Name="SaveList"
|
Name="SaveList"
|
||||||
Items="{Binding View}"
|
Items="{Binding Views}"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Stretch">
|
VerticalAlignment="Stretch">
|
||||||
<ListBox.Styles>
|
<ListBox.Styles>
|
||||||
|
@ -156,7 +162,7 @@
|
||||||
MinWidth="0"
|
MinWidth="0"
|
||||||
MinHeight="0"
|
MinHeight="0"
|
||||||
Name="OpenLocation"
|
Name="OpenLocation"
|
||||||
Command="{Binding OpenLocation}">
|
Click="OpenLocation">
|
||||||
<ui:SymbolIcon
|
<ui:SymbolIcon
|
||||||
Symbol="OpenFolder"
|
Symbol="OpenFolder"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
|
@ -169,7 +175,7 @@
|
||||||
MinWidth="0"
|
MinWidth="0"
|
||||||
MinHeight="0"
|
MinHeight="0"
|
||||||
Name="Delete"
|
Name="Delete"
|
||||||
Command="{Binding Delete}">
|
Click="Delete">
|
||||||
<ui:SymbolIcon
|
<ui:SymbolIcon
|
||||||
Symbol="Delete"
|
Symbol="Delete"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using DynamicData;
|
|
||||||
using DynamicData.Binding;
|
|
||||||
using FluentAvalonia.UI.Controls;
|
using FluentAvalonia.UI.Controls;
|
||||||
using FluentAvalonia.UI.Navigation;
|
using FluentAvalonia.UI.Navigation;
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
@ -10,11 +8,10 @@ using LibHac.Fs;
|
||||||
using LibHac.Fs.Shim;
|
using LibHac.Fs.Shim;
|
||||||
using Ryujinx.Ava.UI.Controls;
|
using Ryujinx.Ava.UI.Controls;
|
||||||
using Ryujinx.Ava.UI.Models;
|
using Ryujinx.Ava.UI.Models;
|
||||||
|
using Ryujinx.Ava.UI.ViewModels;
|
||||||
using Ryujinx.HLE.FileSystem;
|
using Ryujinx.HLE.FileSystem;
|
||||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UserId = LibHac.Fs.UserId;
|
using UserId = LibHac.Fs.UserId;
|
||||||
|
|
||||||
|
@ -22,54 +19,13 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
{
|
{
|
||||||
public partial class UserSaveManager : UserControl
|
public partial class UserSaveManager : UserControl
|
||||||
{
|
{
|
||||||
|
internal UserSaveManagerViewModel ViewModel { get; private set; }
|
||||||
|
|
||||||
private AccountManager _accountManager;
|
private AccountManager _accountManager;
|
||||||
private HorizonClient _horizonClient;
|
private HorizonClient _horizonClient;
|
||||||
private VirtualFileSystem _virtualFileSystem;
|
private VirtualFileSystem _virtualFileSystem;
|
||||||
private int _sortIndex;
|
|
||||||
private int _orderIndex;
|
|
||||||
private ObservableCollection<SaveModel> _view = new();
|
|
||||||
private string _search;
|
|
||||||
|
|
||||||
private NavigationDialogHost _parent;
|
private NavigationDialogHost _parent;
|
||||||
|
|
||||||
public ObservableCollection<SaveModel> Saves { get; set; } = new();
|
|
||||||
|
|
||||||
public ObservableCollection<SaveModel> View
|
|
||||||
{
|
|
||||||
get => _view;
|
|
||||||
set => _view = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int SortIndex
|
|
||||||
{
|
|
||||||
get => _sortIndex;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_sortIndex = value;
|
|
||||||
Sort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int OrderIndex
|
|
||||||
{
|
|
||||||
get => _orderIndex;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_orderIndex = value;
|
|
||||||
Sort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Search
|
|
||||||
{
|
|
||||||
get => _search;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_search = value;
|
|
||||||
Sort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserSaveManager()
|
public UserSaveManager()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -97,14 +53,14 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataContext = this;
|
DataContext = ViewModel = new UserSaveManagerViewModel();
|
||||||
Task.Run(LoadSaves);
|
Task.Run(LoadSaves);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadSaves()
|
public void LoadSaves()
|
||||||
{
|
{
|
||||||
Saves.Clear();
|
ViewModel.Saves.Clear();
|
||||||
var saveDataFilter = SaveDataFilter.Make(programId: default, saveType: SaveDataType.Account,
|
var saveDataFilter = SaveDataFilter.Make(programId: default, saveType: SaveDataType.Account,
|
||||||
new UserId((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low), saveDataId: default, index: default);
|
new UserId((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low), saveDataId: default, index: default);
|
||||||
|
|
||||||
|
@ -129,11 +85,11 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
if (save.ProgramId.Value != 0)
|
if (save.ProgramId.Value != 0)
|
||||||
{
|
{
|
||||||
var saveModel = new SaveModel(save, _horizonClient, _virtualFileSystem);
|
var saveModel = new SaveModel(save, _horizonClient, _virtualFileSystem);
|
||||||
Saves.Add(saveModel);
|
ViewModel.Saves.Add(saveModel);
|
||||||
saveModel.DeleteAction = () => { Saves.Remove(saveModel); };
|
saveModel.DeleteAction = () => { ViewModel.Saves.Remove(saveModel); };
|
||||||
}
|
}
|
||||||
|
|
||||||
Sort();
|
ViewModel.Sort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,42 +99,20 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||||
_parent?.GoBack();
|
_parent?.GoBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Sort()
|
private void OpenLocation(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Saves.AsObservableChangeSet()
|
if (sender is Avalonia.Controls.Button button)
|
||||||
.Filter(Filter)
|
|
||||||
.Sort(GetComparer())
|
|
||||||
.Bind(out var view).AsObservableList();
|
|
||||||
|
|
||||||
_view.Clear();
|
|
||||||
_view.AddRange(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IComparer<SaveModel> GetComparer()
|
|
||||||
{
|
{
|
||||||
switch (SortIndex)
|
(button.DataContext as SaveModel).OpenLocation();
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return OrderIndex == 0
|
|
||||||
? SortExpressionComparer<SaveModel>.Ascending(save => save.Title)
|
|
||||||
: SortExpressionComparer<SaveModel>.Descending(save => save.Title);
|
|
||||||
case 1:
|
|
||||||
return OrderIndex == 0
|
|
||||||
? SortExpressionComparer<SaveModel>.Ascending(save => save.Size)
|
|
||||||
: SortExpressionComparer<SaveModel>.Descending(save => save.Size);
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool Filter(object arg)
|
private void Delete(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (arg is SaveModel save)
|
if (sender is Avalonia.Controls.Button button)
|
||||||
{
|
{
|
||||||
return string.IsNullOrWhiteSpace(_search) || save.Title.ToLower().Contains(_search.ToLower());
|
(button.DataContext as SaveModel).Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue