From 08dfba17f16553e807bd8ed5b8fef8066e94f9c2 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Mon, 14 Aug 2023 09:50:00 -0400 Subject: [PATCH] add mods info colleciton, some cleanup --- .../Models/Launcher/ModInfoCollection.cs | 106 ++++++++++++++++++ .../ViewModels/ProfileViewModel.cs | 50 +-------- project/Aki.Launcher/Views/ProfileView.axaml | 12 +- 3 files changed, 114 insertions(+), 54 deletions(-) create mode 100644 project/Aki.Launcher.Base/Models/Launcher/ModInfoCollection.cs diff --git a/project/Aki.Launcher.Base/Models/Launcher/ModInfoCollection.cs b/project/Aki.Launcher.Base/Models/Launcher/ModInfoCollection.cs new file mode 100644 index 0000000..7a80a7f --- /dev/null +++ b/project/Aki.Launcher.Base/Models/Launcher/ModInfoCollection.cs @@ -0,0 +1,106 @@ +using Aki.Launcher.Models.Aki; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; + +namespace Aki.Launcher.Models.Launcher +{ + public class ModInfoCollection : INotifyPropertyChanged + { + private int _serverModsCount; + public int ServerModsCount + { + get => _serverModsCount; + set + { + if (_serverModsCount != value) + { + _serverModsCount = value; + RaisePropertyChanged(nameof(ServerModsCount)); + } + } + } + + private int _profileModsCount; + public int ProfileModsCount + { + get => _profileModsCount; + set + { + if (_profileModsCount != value) + { + _profileModsCount = value; + RaisePropertyChanged(nameof(ProfileModsCount)); + } + } + } + + private bool _hasProfileOnlyMods; + public bool HasProfileOnlyMods + { + get => _hasProfileOnlyMods; + set + { + if (_hasProfileOnlyMods != value) + { + _hasProfileOnlyMods = value; + RaisePropertyChanged(nameof(HasProfileOnlyMods)); + } + } + } + + private bool _hasMods; + public bool HasMods + { + get => _hasMods; + set + { + if (_hasMods != value) + { + _hasMods = value; + RaisePropertyChanged(nameof(HasMods)); + } + } + } + + public ObservableCollection Mods { get; private set; } = new ObservableCollection(); + + public ModInfoCollection() + { + var serverMods = ServerManager.GetLoadedServerMods().Values.ToList(); + var profileMods = ServerManager.GetProfileMods().ToList(); + + ServerModsCount = serverMods?.Count() ?? 0; + ProfileModsCount = profileMods?.Count() ?? 0; + + foreach (var serverMod in serverMods) + { + serverMod.InServer = true; + Mods.Add(serverMod); + } + + foreach (var profileMod in profileMods) + { + var existingMod = Mods.Where(x => x.Name == profileMod.Name && x.Version == profileMod.Version && x.Author == profileMod.Author).FirstOrDefault(); + + if (existingMod != null) + { + existingMod.InProfile = true; + continue; + } + + profileMod.InProfile = true; + Mods.Add(profileMod); + } + + HasMods = Mods.Count() > 0; + HasProfileOnlyMods = Mods.Where(x => x.InProfile && !x.InServer).Count() > 0; + } + + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void RaisePropertyChanged(string property) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property)); + } + } +} diff --git a/project/Aki.Launcher/ViewModels/ProfileViewModel.cs b/project/Aki.Launcher/ViewModels/ProfileViewModel.cs index 81e6ad7..5aa2f55 100644 --- a/project/Aki.Launcher/ViewModels/ProfileViewModel.cs +++ b/project/Aki.Launcher/ViewModels/ProfileViewModel.cs @@ -12,9 +12,6 @@ using System.Reactive.Disposables; using System.Diagnostics; using System.IO; using Aki.Launcher.Models.Aki; -using System.Collections.ObjectModel; -using System.Linq; -using Avalonia.Media; namespace Aki.Launcher.ViewModels { @@ -37,22 +34,13 @@ namespace Aki.Launcher.ViewModels set => this.RaiseAndSetIfChanged(ref _ModsListIsVisible, value); } - private PathGeometry _ModsListToggleButtonIcon; - public PathGeometry ModsListToggleButtonIcon - { - get => _ModsListToggleButtonIcon; - set => this.RaiseAndSetIfChanged(ref _ModsListToggleButtonIcon, value); - } - public string CurrentID { get; set; } public ProfileInfo ProfileInfo { get; set; } = AccountManager.SelectedProfileInfo; public ImageHelper SideImage { get; } = new ImageHelper(); - public ObservableCollection Mods { get; set; } = new ObservableCollection(); - public int ServerModsCount { get; set; } - public int ProfileModsCount { get; set; } + public ModInfoCollection ModInfoCollection { get; set; } = new ModInfoCollection(); private GameStarter gameStarter = new GameStarter(new GameStarterFrontend()); @@ -84,33 +72,7 @@ namespace Aki.Launcher.ViewModels CurrentID = AccountManager.SelectedAccount.id; - var serverMods = ServerManager.GetLoadedServerMods().Values.ToList(); - var profileMods = ServerManager.GetProfileMods().ToList(); - - ProfileModsCount = profileMods?.Count() ?? 0; - ServerModsCount = serverMods?.Count() ?? 0; - ModsListIsVisible = false; - - foreach (var serverMod in serverMods) - { - serverMod.InServer = true; - Mods.Add(serverMod); - } - - foreach (var profileMod in profileMods) - { - var existingMod = Mods.Where(x => x.Name == profileMod.Name && x.Version == profileMod.Version && x.Author == profileMod.Author).FirstOrDefault(); - - if (existingMod != null) - { - existingMod.InProfile = true; - continue; - } - - profileMod.InProfile = true; - Mods.Add(profileMod); - } } private async Task GameVersionCheck() @@ -137,15 +99,7 @@ namespace Aki.Launcher.ViewModels } } - public void ToggleModsListCommand() - { - - Dispatcher.UIThread.InvokeAsync(() => - { - ModsListIsVisible = !ModsListIsVisible; - //ModsListToggleButtonIcon = ModsListIsVisible ? "<" : ">"; - }); - } + public void ToggleModsListCommand() => ModsListIsVisible = !ModsListIsVisible; public void LogoutCommand() { diff --git a/project/Aki.Launcher/Views/ProfileView.axaml b/project/Aki.Launcher/Views/ProfileView.axaml index dd5b2b7..df67337 100644 --- a/project/Aki.Launcher/Views/ProfileView.axaml +++ b/project/Aki.Launcher/Views/ProfileView.axaml @@ -60,23 +60,23 @@