diff --git a/ScrapModLoader/MainWindow.xaml.cs b/ScrapModLoader/MainWindow.xaml.cs index d85297d..fc0f35c 100644 --- a/ScrapModLoader/MainWindow.xaml.cs +++ b/ScrapModLoader/MainWindow.xaml.cs @@ -6,6 +6,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; +using System.Text; namespace ScrapModLoader { @@ -21,6 +22,7 @@ namespace ScrapModLoader public MainWindow() { modsLauncher = new ModsLauncher(); + modsLauncher.ModsLoaded += ModsLauncher_ModsLoaded; InitializeComponent(); } @@ -187,6 +189,22 @@ namespace ScrapModLoader Close(); } + private void ModsLauncher_ModsLoaded(ModLoadedEventArgs eventArgs) + { + if (eventArgs.UnsupportedMods.Count != 0) + { + StringBuilder unsupportedModsBuilder = new StringBuilder(); + unsupportedModsBuilder.AppendLine("Next mod is unsupported and don't be loaded:"); + unsupportedModsBuilder.AppendLine(); + foreach (ScrapMod mod in eventArgs.UnsupportedMods) + { + unsupportedModsBuilder.AppendLine(mod.Name); + } + + MessageBox.Show(unsupportedModsBuilder.ToString(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + private void ScraplandVersion_SelectionChanged(Object sender, SelectionChangedEventArgs e) => modsLauncher.SelectedGameVersion = ScraplandVersion.SelectedIndex == 0 ? "1.0" : "1.1"; } diff --git a/ScrapModLoader/ModLoadedEventArgs.cs b/ScrapModLoader/ModLoadedEventArgs.cs new file mode 100644 index 0000000..70d1487 --- /dev/null +++ b/ScrapModLoader/ModLoadedEventArgs.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScrapModLoader +{ + public class ModLoadedEventArgs : EventArgs + { + private List LoadedModsList { get; set; } = new List(); + private List UnsupportedModsList { get; set; } = new List(); + + public ModLoadedEventArgs(IEnumerable loadedMods, IEnumerable unsupportedMods) : base() + { + LoadedModsList = loadedMods.ToList(); + UnsupportedModsList = unsupportedMods.ToList(); + } + + public ReadOnlyCollection LoadedMods => LoadedModsList.AsReadOnly(); + public ReadOnlyCollection UnsupportedMods => UnsupportedModsList.AsReadOnly(); + } +} diff --git a/ScrapModLoader/ModsLauncher.cs b/ScrapModLoader/ModsLauncher.cs index 8afcaaf..b46b377 100644 --- a/ScrapModLoader/ModsLauncher.cs +++ b/ScrapModLoader/ModsLauncher.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -20,6 +21,10 @@ namespace ScrapModLoader public String LauncherVersion { get; set; } = "0.3"; public String SelectedGamePath { get; set; } = String.Empty; + public delegate void ModsLoadedHandler(ModLoadedEventArgs eventArgs); + + public event ModsLoadedHandler? ModsLoaded; + public ModsLauncher() { @@ -93,25 +98,38 @@ namespace ScrapModLoader public void LoadMods() { SelectedGamePath = SelectedGameVersion == "1.0" ? ScraplandPath : ScraplandRemasteredPath; + List loadedMods = new List(); + List unsupportedMods = new List(); foreach (ScrapMod mod in Mods) { - // TODO: Warning about not loading mods that not supports selected version - if (!mod.SupportedGameVersions.Contains(SelectedGameVersion) || - Single.Parse(mod.RequiredLauncher, CultureInfo.InvariantCulture) < Single.Parse(LauncherVersion, CultureInfo.InvariantCulture)) - continue; - - if (mod.Checked) + if (IsSupported(mod)) { - if (!IsEnabled(mod)) - Enable(mod); + if (mod.Checked) + { + if (!IsEnabled(mod)) + Enable(mod); + + loadedMods.Add(mod); + } + else + { + if (IsEnabled(mod)) + Disable(mod); + } } else { - if (IsEnabled(mod)) - Disable(mod); + unsupportedMods.Add(mod); } } + ModsLoaded?.Invoke(new ModLoadedEventArgs(loadedMods, unsupportedMods)); + } + + public Boolean IsSupported(ScrapMod mod) + { + return mod.SupportedGameVersions.Contains(SelectedGameVersion) || + Single.Parse(mod.RequiredLauncher, CultureInfo.InvariantCulture) < Single.Parse(LauncherVersion, CultureInfo.InvariantCulture); } private String ModPath(ScrapMod mod) =>