mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Use mod factories to lazy-load mods
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
x:Name="ModList" HorizontalContentAlignment="Stretch" BorderThickness="0"
|
x:Name="ModList" HorizontalContentAlignment="Stretch" BorderThickness="0"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" d:ItemsSource="{d:SampleData ItemCount=5}">
|
ScrollViewer.HorizontalScrollBarVisibility="Disabled" d:ItemsSource="{d:SampleData ItemCount=5}">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate DataType="{x:Type core:Mod}">
|
<DataTemplate DataType="{x:Type core:IModFactory`1}">
|
||||||
<Border x:Name="RootBorder" BorderThickness="0">
|
<Border x:Name="RootBorder" BorderThickness="0">
|
||||||
<Grid Margin="8">
|
<Grid Margin="8">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||||
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using OwlCore.AbstractUI.Models;
|
using OwlCore.AbstractUI.Models;
|
||||||
using OwlCore.ComponentModel;
|
using OwlCore.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -23,15 +24,15 @@ namespace ZuneModdingHelper.Pages
|
|||||||
_modConfig = modConfig;
|
_modConfig = modConfig;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ModList.ItemsSource = ModManager.GetAvailableMods();
|
ModList.ItemsSource = ModManager.ModFactories;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ApplyButton_Click(object sender, RoutedEventArgs e)
|
private async void ApplyButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!TryGetModFromControl(sender, out var mod))
|
if (!TryGetModFromControl(sender, out var modFactory))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var modTitle = mod.Metadata.Title;
|
var modTitle = modFactory.Metadata.Title;
|
||||||
ProgressDialogViewModel progDialog = new()
|
ProgressDialogViewModel progDialog = new()
|
||||||
{
|
{
|
||||||
Title = MOD_MANAGER_TITLE,
|
Title = MOD_MANAGER_TITLE,
|
||||||
@@ -42,9 +43,9 @@ namespace ZuneModdingHelper.Pages
|
|||||||
};
|
};
|
||||||
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(progDialog));
|
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(progDialog));
|
||||||
|
|
||||||
mod.ZuneInstallDir = _modConfig.ZuneInstallDir;
|
|
||||||
|
|
||||||
// Stage 0: Initialize mod
|
// Stage 0: Initialize mod
|
||||||
|
var mod = modFactory.Create(Ioc.Default);
|
||||||
|
mod.ZuneInstallDir = _modConfig.ZuneInstallDir;
|
||||||
if (mod is IAsyncInit initMod)
|
if (mod is IAsyncInit initMod)
|
||||||
await initMod.InitAsync();
|
await initMod.InitAsync();
|
||||||
++progDialog.Progress;
|
++progDialog.Progress;
|
||||||
@@ -93,10 +94,10 @@ namespace ZuneModdingHelper.Pages
|
|||||||
|
|
||||||
private async void ResetButton_Click(object sender, RoutedEventArgs e)
|
private async void ResetButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!TryGetModFromControl(sender, out var mod))
|
if (!TryGetModFromControl(sender, out var modFactory))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var modTitle = mod.Metadata.Title;
|
var modTitle = modFactory.Metadata.Title;
|
||||||
ProgressDialogViewModel progDialog = new()
|
ProgressDialogViewModel progDialog = new()
|
||||||
{
|
{
|
||||||
Title = MOD_MANAGER_TITLE,
|
Title = MOD_MANAGER_TITLE,
|
||||||
@@ -107,8 +108,8 @@ namespace ZuneModdingHelper.Pages
|
|||||||
};
|
};
|
||||||
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(progDialog));
|
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(progDialog));
|
||||||
|
|
||||||
|
var mod = modFactory.Create(Ioc.Default);
|
||||||
mod.ZuneInstallDir = _modConfig.ZuneInstallDir;
|
mod.ZuneInstallDir = _modConfig.ZuneInstallDir;
|
||||||
|
|
||||||
if (mod is IAsyncInit initMod)
|
if (mod is IAsyncInit initMod)
|
||||||
await initMod.InitAsync();
|
await initMod.InitAsync();
|
||||||
++progDialog.Progress;
|
++progDialog.Progress;
|
||||||
@@ -147,10 +148,10 @@ namespace ZuneModdingHelper.Pages
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryGetModFromControl(object sender, out Mod mod)
|
private static bool TryGetModFromControl(object sender, out IModFactory<Mod> modFactory)
|
||||||
{
|
{
|
||||||
mod = (sender as FrameworkElement)?.DataContext as Mod;
|
modFactory = (sender as FrameworkElement)?.DataContext as IModFactory<Mod>;
|
||||||
return mod is not null;
|
return modFactory is not null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user