diff --git a/ZuneModCore/ModViewModel.cs b/ZuneModCore/ModViewModel.cs index 38c5905..a20bd61 100644 --- a/ZuneModCore/ModViewModel.cs +++ b/ZuneModCore/ModViewModel.cs @@ -1,46 +1,39 @@ using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; -using OwlCore.AbstractUI.Models; using OwlCore.AbstractUI.ViewModels; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace ZuneModCore { public class ModViewModel : ObservableObject, IDisposable { - public ModViewModel(Mod mod) + public ModViewModel() { - Mod = mod; _loadCommand = new AsyncRelayCommand(LoadAsync); - _applyCommand = new AsyncRelayCommand(Mod.ApplyWithDependencies); - _resetCommand = new AsyncRelayCommand(Mod.Reset); + } - if (Mod.OptionsUI != null) - OptionsViewModel = new(Mod.OptionsUI); - - Mod.StatusChanged += OnStatusChanged; + public ModViewModel(Mod mod) : this() + { + UpdateMod(mod); } private Mod _mod; private AbstractUICollectionViewModel? _optionsVm; private IAsyncRelayCommand _loadCommand; private IAsyncRelayCommand? _actionCommand; - private bool _hasOptions; private bool _hasDependencies; private string _actionButtonText; - private readonly IAsyncRelayCommand _applyCommand; - private readonly IAsyncRelayCommand _resetCommand; + private IAsyncRelayCommand _applyCommand; + private IAsyncRelayCommand _resetCommand; public Mod Mod { get => _mod; set { - HasDependencies = _mod?.DependentMods != null && _mod.DependentMods.Count > 0; + UpdateMod(value); SetProperty(ref _mod, value); } } @@ -48,11 +41,7 @@ namespace ZuneModCore public AbstractUICollectionViewModel? OptionsViewModel { get => _optionsVm; - set - { - HasOptions = _optionsVm != null; - SetProperty(ref _optionsVm, value); - } + set => SetProperty(ref _optionsVm, value); } public IAsyncRelayCommand LoadCommand @@ -67,18 +56,19 @@ namespace ZuneModCore set => SetProperty(ref _actionCommand, value); } - public bool HasOptions - { - get => _hasOptions; - set => SetProperty(ref _hasOptions, value); - } - public bool HasDependencies { get => _hasDependencies; set => SetProperty(ref _hasDependencies, value); } + private IReadOnlyList? _Dependencies; + public IReadOnlyList? Dependencies + { + get => _Dependencies; + set => SetProperty(ref _Dependencies, value); + } + public string ActionButtonText { get => _actionButtonText; @@ -108,5 +98,22 @@ namespace ZuneModCore { Mod.StatusChanged -= OnStatusChanged; } + + private void UpdateMod(Mod mod) + { + if (mod == null) return; + + _mod = mod; + _applyCommand = new AsyncRelayCommand(Mod.ApplyWithDependencies); + _resetCommand = new AsyncRelayCommand(Mod.Reset); + + Dependencies = Mod.DependentMods; + HasDependencies = Dependencies != null && Dependencies.Count > 0; + + if (Mod.OptionsUI != null) + OptionsViewModel = new(Mod.OptionsUI); + + Mod.StatusChanged += OnStatusChanged; + } } } diff --git a/ZuneModdingHelper/OptionsUIDialog.xaml b/ZuneModdingHelper/OptionsUIDialog.xaml index b73c639..4ba0eba 100644 --- a/ZuneModdingHelper/OptionsUIDialog.xaml +++ b/ZuneModdingHelper/OptionsUIDialog.xaml @@ -23,6 +23,10 @@ + + + + @@ -31,9 +35,9 @@ - + - + @@ -50,9 +54,9 @@ Height="2" Margin="0,10,0,-7"/> - + Visibility="{Binding OptionsViewModel, Converter={StaticResource NullToVisibilityConverter}}"/> @@ -82,8 +86,8 @@