mirror of
				https://github.com/Strongleong/ScrapModLoader.git
				synced 2024-08-15 00:03:19 +00:00 
			
		
		
		
	Merge eabb4dca02 into 4f80b72603
				
					
				
			This commit is contained in:
		
						commit
						f27d8938fc
					
				
					 3 changed files with 70 additions and 10 deletions
				
			
		|  | @ -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"; | ||||
|     } | ||||
|  |  | |||
							
								
								
									
										24
									
								
								ScrapModLoader/ModLoadedEventArgs.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								ScrapModLoader/ModLoadedEventArgs.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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<ScrapMod> LoadedModsList { get; set; } = new List<ScrapMod>(); | ||||
|         private List<ScrapMod> UnsupportedModsList { get; set; } = new List<ScrapMod>(); | ||||
| 
 | ||||
|         public ModLoadedEventArgs(IEnumerable<ScrapMod> loadedMods, IEnumerable<ScrapMod> unsupportedMods) : base() | ||||
|         { | ||||
|             LoadedModsList = loadedMods.ToList(); | ||||
|             UnsupportedModsList = unsupportedMods.ToList(); | ||||
|         } | ||||
| 
 | ||||
|         public ReadOnlyCollection<ScrapMod> LoadedMods => LoadedModsList.AsReadOnly(); | ||||
|         public ReadOnlyCollection<ScrapMod> UnsupportedMods => UnsupportedModsList.AsReadOnly(); | ||||
|     } | ||||
| } | ||||
|  | @ -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,18 +98,19 @@ namespace ScrapModLoader | |||
|         public void LoadMods() | ||||
|         { | ||||
|             SelectedGamePath = SelectedGameVersion == "1.0" ? ScraplandPath : ScraplandRemasteredPath; | ||||
|             List<ScrapMod> loadedMods = new List<ScrapMod>(); | ||||
|             List<ScrapMod> unsupportedMods = new List<ScrapMod>(); | ||||
| 
 | ||||
|             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 (IsSupported(mod)) | ||||
|                 { | ||||
|                     if (mod.Checked) | ||||
|                     { | ||||
|                         if (!IsEnabled(mod)) | ||||
|                             Enable(mod); | ||||
| 
 | ||||
|                         loadedMods.Add(mod); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|  | @ -112,6 +118,18 @@ namespace ScrapModLoader | |||
|                             Disable(mod); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     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) =>  | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue