2022-07-28 22:41:34 +00:00
|
|
|
using Avalonia.Controls;
|
2023-03-14 16:04:38 +00:00
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Styling;
|
|
|
|
using FluentAvalonia.UI.Controls;
|
2022-07-28 22:41:34 +00:00
|
|
|
using Ryujinx.Ava.Common.Locale;
|
2022-12-29 14:24:05 +00:00
|
|
|
using Ryujinx.Ava.UI.Helpers;
|
|
|
|
using Ryujinx.Ava.UI.Models;
|
2023-03-14 16:04:38 +00:00
|
|
|
using Ryujinx.Ava.UI.ViewModels;
|
2022-07-28 22:41:34 +00:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2023-03-14 16:04:38 +00:00
|
|
|
using Ryujinx.Ui.Common.Helper;
|
2022-07-28 22:41:34 +00:00
|
|
|
using System.Threading.Tasks;
|
2023-03-14 16:04:38 +00:00
|
|
|
using Button = Avalonia.Controls.Button;
|
2022-07-28 22:41:34 +00:00
|
|
|
|
2022-12-29 14:24:05 +00:00
|
|
|
namespace Ryujinx.Ava.UI.Windows
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
public partial class DownloadableContentManagerWindow : UserControl
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
public DownloadableContentManagerViewModel ViewModel;
|
2022-07-28 22:41:34 +00:00
|
|
|
|
|
|
|
public DownloadableContentManagerWindow()
|
|
|
|
{
|
|
|
|
DataContext = this;
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public DownloadableContentManagerWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
|
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
DataContext = ViewModel = new DownloadableContentManagerViewModel(virtualFileSystem, titleId, titleName);
|
2022-07-28 22:41:34 +00:00
|
|
|
|
|
|
|
InitializeComponent();
|
2023-03-14 16:04:38 +00:00
|
|
|
}
|
2022-07-28 22:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
public static async Task Show(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
|
|
|
|
{
|
|
|
|
ContentDialog contentDialog = new()
|
|
|
|
{
|
|
|
|
PrimaryButtonText = "",
|
|
|
|
SecondaryButtonText = "",
|
|
|
|
CloseButtonText = "",
|
|
|
|
Content = new DownloadableContentManagerWindow(virtualFileSystem, titleId, titleName),
|
|
|
|
Title = string.Format(LocaleManager.Instance[LocaleKeys.DlcWindowTitle], titleName, titleId.ToString("X16"))
|
|
|
|
};
|
2022-11-25 11:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
|
|
|
|
bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
|
2022-11-25 11:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
contentDialog.Styles.Add(bottomBorder);
|
2022-07-28 22:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
await ContentDialogHelper.ShowAsync(contentDialog);
|
2022-11-25 11:41:34 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)
|
2022-11-25 11:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
ViewModel.Save();
|
|
|
|
((ContentDialog)Parent).Hide();
|
2022-11-25 11:41:34 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void Close(object sender, RoutedEventArgs e)
|
2022-11-25 11:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
((ContentDialog)Parent).Hide();
|
2022-07-28 22:41:34 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void RemoveDLC(object sender, RoutedEventArgs e)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (sender is Button button)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (button.DataContext is DownloadableContentModel model)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
ViewModel.Remove(model);
|
2022-07-28 22:41:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void OpenLocation(object sender, RoutedEventArgs e)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (sender is Button button)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (button.DataContext is DownloadableContentModel model)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
OpenHelper.LocateFile(model.ContainerPath);
|
|
|
|
}
|
2022-07-28 22:41:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
foreach (var content in e.AddedItems)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (content is DownloadableContentModel model)
|
2022-11-25 11:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
var index = ViewModel.DownloadableContents.IndexOf(model);
|
2022-07-28 22:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
if (index != -1)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
ViewModel.DownloadableContents[index].Enabled = true;
|
2022-07-28 22:41:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 11:41:34 +00:00
|
|
|
}
|
2022-07-28 22:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
foreach (var content in e.RemovedItems)
|
2022-11-25 11:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (content is DownloadableContentModel model)
|
2022-11-25 11:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
var index = ViewModel.DownloadableContents.IndexOf(model);
|
2022-11-25 11:41:34 +00:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
if (index != -1)
|
2022-07-28 22:41:34 +00:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
ViewModel.DownloadableContents[index].Enabled = false;
|
2022-07-28 22:41:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|