From a2a0900f7df765c8a7d79f6493d0393740fde446 Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Thu, 23 Apr 2020 17:25:50 -0500 Subject: [PATCH] Mods are now "loaded" mods page has stuff in it now --- ZenovaLauncher/App.xaml.cs | 2 + ZenovaLauncher/Mods/Mod.cs | 37 ++++ ZenovaLauncher/Mods/ModManager.cs | 54 ++++++ ZenovaLauncher/Pages/ModsPage.xaml | 175 +++++++++++++++++- ZenovaLauncher/Pages/ModsPage.xaml.cs | 54 +++++- ZenovaLauncher/Pages/ProfilesPage.xaml | 6 +- ZenovaLauncher/Pages/ProfilesPage.xaml.cs | 2 +- ZenovaLauncher/Profiles/Profile.cs | 27 ++- ZenovaLauncher/Profiles/ProfileLauncher.cs | 17 +- ZenovaLauncher/Profiles/ProfileManager.cs | 71 +++---- ZenovaLauncher/Utils/Preferences.cs | 16 +- ZenovaLauncher/Utils/Utils.cs | 1 - .../MinecraftVersion.cs | 0 .../VersionDownloader.cs | 0 .../{Profiles => Versions}/VersionManager.cs | 1 - ZenovaLauncher/ZenovaLauncher.csproj | 9 +- 16 files changed, 407 insertions(+), 65 deletions(-) create mode 100644 ZenovaLauncher/Mods/Mod.cs create mode 100644 ZenovaLauncher/Mods/ModManager.cs rename ZenovaLauncher/{Profiles => Versions}/MinecraftVersion.cs (100%) rename ZenovaLauncher/{Profiles => Versions}/VersionDownloader.cs (100%) rename ZenovaLauncher/{Profiles => Versions}/VersionManager.cs (98%) diff --git a/ZenovaLauncher/App.xaml.cs b/ZenovaLauncher/App.xaml.cs index 409cfff..ae887e8 100644 --- a/ZenovaLauncher/App.xaml.cs +++ b/ZenovaLauncher/App.xaml.cs @@ -28,11 +28,13 @@ public void AppStart(object sender, StartupEventArgs e) ProfileManager.instance = new ProfileManager(DataDirectory); ProfileLauncher.instance = new ProfileLauncher(); AccountManager.instance = new AccountManager(); + ModManager.instance = new ModManager(ModsDirectory); Task loadTask = Task.Run(async () => { await AccountManager.instance.AddAccounts(); await VersionManager.instance.LoadMinecraftVersions(); ProfileManager.instance.AddProfiles(); + ModManager.instance.LoadMods(); Preferences.LoadPreferences(DataDirectory); VersionManager.instance.RemoveUnusedVersions(); }); diff --git a/ZenovaLauncher/Mods/Mod.cs b/ZenovaLauncher/Mods/Mod.cs new file mode 100644 index 0000000..852715a --- /dev/null +++ b/ZenovaLauncher/Mods/Mod.cs @@ -0,0 +1,37 @@ +using Newtonsoft.Json; +using System; + +namespace ZenovaLauncher +{ + public class Mod + { + public string NameId { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public Version Version { get; set; } + public string MinVersion + { + get { return MinMCVersion.InternalName; } + set { MinMCVersion = VersionManager.instance.GetVersionFromString(value); } + } + public string MaxVersion + { + get { return MaxMCVersion.InternalName; } + set { MaxMCVersion = VersionManager.instance.GetVersionFromString(value); } + } + [JsonIgnore] + public string ModDirectory { get; set; } + [JsonIgnore] + public MinecraftVersion MinMCVersion { get; set; } + [JsonIgnore] + public MinecraftVersion MaxMCVersion { get; set; } + [JsonIgnore] + public Version LatestSupported => MaxMCVersion.Version; + + public enum ModSortType + { + ByLatestSupported, + ByName + } + } +} diff --git a/ZenovaLauncher/Mods/ModManager.cs b/ZenovaLauncher/Mods/ModManager.cs new file mode 100644 index 0000000..f8631fd --- /dev/null +++ b/ZenovaLauncher/Mods/ModManager.cs @@ -0,0 +1,54 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Windows; + +namespace ZenovaLauncher +{ + public class ModManager : ObservableCollection + { + public static ModManager instance; + private static JsonSerializerSettings jsonSettings; + + private readonly string _modsFileName = "modinfo.json"; + + public string ModsDirectory { get; set; } + + public ModManager(string modsDir) + { + ModsDirectory = modsDir; + } + + public Mod GetModFromDirectory(string dir) + { + return this.FirstOrDefault(m => m.ModDirectory == dir); + } + + public void LoadMods() + { + jsonSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; + foreach (string dir in Directory.GetDirectories(ModsDirectory)) + { + try + { + if (File.Exists(Path.Combine(dir, _modsFileName))) + { + Mod mod = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(dir, _modsFileName)), jsonSettings); + mod.ModDirectory = dir; + Add(mod); + } + } + catch (Exception e) + { + Trace.WriteLine("Mods JSON Deserialize Failed: " + e.ToString()); + MessageBox.Show("Mods JSON Deserialize Failed: " + e.ToString()); + } + } + } + + } +} diff --git a/ZenovaLauncher/Pages/ModsPage.xaml b/ZenovaLauncher/Pages/ModsPage.xaml index 5be35e7..0833be7 100644 --- a/ZenovaLauncher/Pages/ModsPage.xaml +++ b/ZenovaLauncher/Pages/ModsPage.xaml @@ -5,9 +5,178 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ZenovaLauncher" xmlns:ui="http://schemas.modernwpf.com/2019" - mc:Ignorable="d"> + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" + xmlns:comment="Comments" + mc:Ignorable="d comment"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/ZenovaLauncher/Pages/ModsPage.xaml.cs b/ZenovaLauncher/Pages/ModsPage.xaml.cs index ee0af07..8088a6e 100644 --- a/ZenovaLauncher/Pages/ModsPage.xaml.cs +++ b/ZenovaLauncher/Pages/ModsPage.xaml.cs @@ -1,4 +1,7 @@ -using System.Windows.Controls; +using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; namespace ZenovaLauncher { @@ -10,6 +13,55 @@ public partial class ModsPage : Page public ModsPage() { InitializeComponent(); + + DataContext = ProfileLauncher.instance; + ModsListBox.ItemsSource = ModManager.instance; + SortModsBox.DataContext = Preferences.instance; + + SortModList(Preferences.instance.ModSorting); + } + + private void SelectCurrentItem(object sender, KeyboardFocusChangedEventArgs e) + { + ListBoxItem item = (ListBoxItem)sender; + item.IsSelected = true; + } + + private void ImportModClick(object sender, RoutedEventArgs e) + { + + } + + private void SortChanged(object sender, SelectionChangedEventArgs e) + { + SortModList(Preferences.instance.ModSorting); + } + + private void ModSelected(object sender, MouseButtonEventArgs e) + { + + } + + private void ModDetailsClick(object sender, RoutedEventArgs e) + { + + } + + private void DeleteModClick(object sender, RoutedEventArgs e) + { + + } + + protected void SortModList(Mod.ModSortType sortType) + { + string sortTypeString = sortType == Mod.ModSortType.ByLatestSupported ? "LatestSupported" : "Name"; + ListSortDirection sortDirection = sortType == Mod.ModSortType.ByLatestSupported ? ListSortDirection.Descending : ListSortDirection.Ascending; + if (ModsListBox != null) + { + ModsListBox.Items.SortDescriptions.Clear(); + SortDescription sd = new SortDescription(sortTypeString, sortDirection); + ModsListBox.Items.SortDescriptions.Add(sd); + } } } } diff --git a/ZenovaLauncher/Pages/ProfilesPage.xaml b/ZenovaLauncher/Pages/ProfilesPage.xaml index e2d938e..50aa441 100644 --- a/ZenovaLauncher/Pages/ProfilesPage.xaml +++ b/ZenovaLauncher/Pages/ProfilesPage.xaml @@ -31,8 +31,8 @@ - -