diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModLoaderType.cs b/Plain Craft Launcher 2/Modules/Minecraft/ModLoaderType.cs new file mode 100644 index 000000000..e7c1308e5 --- /dev/null +++ b/Plain Craft Launcher 2/Modules/Minecraft/ModLoaderType.cs @@ -0,0 +1,14 @@ +namespace PCL; + +/// +/// 实例安装流程中可互斥选择的主 Mod 加载器。 +/// +internal enum ModLoaderType +{ + Forge, + NeoForge, + Cleanroom, + Fabric, + LegacyFabric, + LabyMod +} diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs index 437bedeb9..96248a843 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs @@ -338,9 +338,9 @@ public void MinecraftSelected(MyListItem sender, MouseButtonEventArgs e) private ModDownload.DlOptiFineListEntry? selectedOptiFine; /// - /// 选定的 Mod Loader 名称,内容应为 Forge / NeoForge / Fabric / Cleanroom / LabyMod / LegacyFabric + /// 选定的主 Mod 加载器。 /// - private string? selectedLoaderName; + private ModLoaderType? _selectedLoaderType; /// /// 选定的 Mod Loader API 名称,内容应为 Fabric API @@ -785,7 +785,7 @@ private void ClearSelected() _vanillaIcon = null; selectedOptiFine = null; selectedLiteLoader = null; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; selectedForge = null; selectedNeoForge = null; @@ -801,6 +801,49 @@ private void ClearSelected() selectedLegacyFabricApi = null; } + /// + /// 选择主 Mod 加载器时,清除其它主加载器及其专属组件。 + /// OptiFine 与 LiteLoader 可与部分加载器共存,故不在此处清除。 + /// + private void SelectModLoader(ModLoaderType loaderType) + { + if (loaderType != ModLoaderType.Forge) + selectedForge = null; + + if (loaderType != ModLoaderType.NeoForge) + selectedNeoForge = null; + + if (loaderType != ModLoaderType.Cleanroom) + selectedCleanroom = null; + + if (loaderType != ModLoaderType.Fabric) + { + selectedFabric = null; + selectedFabricApi = null; + selectedOptiFabric = null; + autoSelectedFabricApi = false; + autoSelectedOptiFabric = false; + } + + if (loaderType != ModLoaderType.LegacyFabric) + { + selectedLegacyFabric = null; + selectedLegacyFabricApi = null; + autoSelectedLegacyFabricApi = false; + } + + if (loaderType != ModLoaderType.LabyMod) + { + selectedLabyModChannel = null; + selectedLabyModCommitRef = null; + selectedLabyModBaseVersion = null; + selectedLabyModVersion = null; + } + + _selectedLoaderType = loaderType; + selectedAPIName = null; + } + // 信息栏动画 private void SetPanelVisibility(Grid panel, bool visible) { @@ -1083,18 +1126,18 @@ private static void _StackInstall(StackPanel stack) /// private string LoadOptiFineGetError() { - if (selectedLoaderName == "NeoForge" || selectedLoaderName == "LabyMod" || selectedLoaderName == "Cleanroom") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is ModLoaderType.NeoForge or ModLoaderType.LabyMod or ModLoaderType.Cleanroom) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (LoadOptiFine is null || LoadOptiFine.State.LoadingState == MyLoading.MyLoadingState.Run) return Lang.Text("Download.Install.State.Loading"); if (LoadOptiFine.State.LoadingState == MyLoading.MyLoadingState.Error) return $"{Lang.Text("Download.Install.State.GetVersionListFailed")}{((ModLoader.LoaderBase)LoadOptiFine.State).Error.Message}"; // 检查 Forge 1.13 - 1.14.3:全部不兼容 - if (selectedLoaderName == "Forge" && McVersionComparer.CompareVersion(_vanillaName, "1.13") >= 0 && - McVersionComparer.CompareVersion("1.14.3", _vanillaName) >= 0) return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType == ModLoaderType.Forge && McVersionComparer.CompareVersion(_vanillaName, "1.13") >= 0 && + McVersionComparer.CompareVersion("1.14.3", _vanillaName) >= 0) return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Fabric 1.20.5+: 全部不兼容 if (selectedFabric is not null && McVersionComparer.CompareVersion(_vanillaName, "1.20.4") > 0) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Loader if (GetLoaderError(LoadOptiFine) is not null) return GetLoaderError(LoadOptiFine); @@ -1118,7 +1161,7 @@ private string LoadOptiFineGetError() if (hasRequiredVersion) return Lang.Text("Download.Install.Compat.CompatForgeSpecificOnly"); - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); } // 检查某个 OptiFine 是否与某个 Forge 兼容 @@ -1232,8 +1275,8 @@ private string LoadLiteLoaderGetError() // 检查 Loader if (GetLoaderError(LoadLiteLoader) is not null) return GetLoaderError(LoadLiteLoader); - if (selectedLoaderName == "NeoForge" || selectedLoaderName == "LegacyFabric" || selectedLoaderName == "LabyMod" || selectedLoaderName == "Cleanroom") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is ModLoaderType.NeoForge or ModLoaderType.LegacyFabric or ModLoaderType.LabyMod or ModLoaderType.Cleanroom) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查版本 return ModDownload.dlLiteLoaderListLoader.output.Value.Any(v => (v.Inherit ?? "") == (_vanillaName ?? "")) ? null @@ -1307,8 +1350,8 @@ private string LoadForgeGetError() if (McVersionComparer.CompareVersionGe("1.5.1", _vanillaName) && McVersionComparer.CompareVersionGe(_vanillaName, "1.1")) return Lang.Text("Download.Install.State.NoVersion"); - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "Forge")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Forge) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Loader if (GetLoaderError(LoadForge) is not null) @@ -1322,7 +1365,7 @@ private string LoadForgeGetError() if (Version.Category == "universal" || Version.Category == "client") continue; // 跳过无法自动安装的版本 if (selectedNeoForge is not null || selectedFabric is not null) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (selectedOptiFine is not null && McVersionComparer.CompareVersionGe(_vanillaName, "1.13") && McVersionComparer.CompareVersionGe("1.14.3", _vanillaName)) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); // 1.13 ~ 1.14.3 OptiFine 检查 @@ -1388,8 +1431,8 @@ private void Forge_Loaded() // 选择与清除 private void Forge_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.Forge); selectedForge = (ModDownload.DlForgeVersionEntry)(dynamic)sender.Tag; - selectedLoaderName = "Forge"; CardForge.IsSwapped = true; if (selectedOptiFine is not null && !(bool)IsOptiFineSuitForForge(selectedOptiFine, selectedForge)) @@ -1401,7 +1444,7 @@ private void Forge_Selected(MyListItem sender, EventArgs e) private void Forge_Clear(object sender, MouseButtonEventArgs e) { selectedForge = null; - selectedLoaderName = null; + _selectedLoaderType = null; CardForge.IsSwapped = true; e.Handled = true; OptiFine_Loaded(); @@ -1419,8 +1462,8 @@ private string LoadNeoForgeGetError() { if (selectedOptiFine is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "NeoForge")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.NeoForge) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Loader if (GetLoaderError(LoadNeoForge) is not null) return GetLoaderError(LoadNeoForge); @@ -1474,8 +1517,8 @@ private void NeoForge_Loaded() // 选择与清除 private void NeoForge_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.NeoForge); selectedNeoForge = (ModDownload.DlNeoForgeListEntry)(dynamic)sender.Tag; - selectedLoaderName = "NeoForge"; CardNeoForge.IsSwapped = true; OptiFine_Loaded(); ReloadSelected(); @@ -1484,7 +1527,7 @@ private void NeoForge_Selected(MyListItem sender, EventArgs e) private void NeoForge_Clear(object sender, MouseButtonEventArgs e) { selectedNeoForge = null; - selectedLoaderName = null; + _selectedLoaderType = null; CardNeoForge.IsSwapped = true; e.Handled = true; OptiFine_Loaded(); @@ -1504,8 +1547,8 @@ private void NeoForge_Clear(object sender, MouseButtonEventArgs e) return Lang.Text("Download.Install.State.NoAvailableVersion"); if (selectedOptiFine is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); - if (selectedLoaderName is not null && selectedLoaderName != "Cleanroom") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Cleanroom) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (selectedLiteLoader is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithLiteLoader"); // 检查 Loader @@ -1560,8 +1603,8 @@ private void Cleanroom_Loaded() // 选择与清除 private void Cleanroom_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.Cleanroom); selectedCleanroom = (ModDownload.DlCleanroomListEntry)(dynamic)sender.Tag; - selectedLoaderName = "Cleanroom"; CardCleanroom.IsSwapped = true; OptiFine_Loaded(); ReloadSelected(); @@ -1570,7 +1613,7 @@ private void Cleanroom_Selected(MyListItem sender, EventArgs e) private void Cleanroom_Clear(object sender, MouseButtonEventArgs e) { selectedCleanroom = null; - selectedLoaderName = null; + _selectedLoaderType = null; CardCleanroom.IsSwapped = true; e.Handled = true; OptiFine_Loaded(); @@ -1597,8 +1640,8 @@ private string LoadFabricGetError() if ((version["version"].ToString() ?? "") == (_vanillaName.Replace("∞", "infinite").Replace("Combat Test 7c", "1.16_combat-3") ?? "")) { - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "Fabric")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Fabric) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); return null; } @@ -1650,9 +1693,9 @@ private void Fabric_Loaded() // 选择与清除 public void Fabric_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.Fabric); ModBase.Log(((dynamic)sender.Tag).ToString()); selectedFabric = ((dynamic)sender.Tag)["version"].ToString(); - selectedLoaderName = "Fabric"; FabricApi_Loaded(); OptiFabric_Loaded(); CardFabric.IsSwapped = true; @@ -1666,7 +1709,7 @@ private void Fabric_Clear(object sender, MouseButtonEventArgs e) autoSelectedFabricApi = false; selectedOptiFabric = null; autoSelectedOptiFabric = false; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; CardFabric.IsSwapped = true; e.Handled = true; @@ -1815,8 +1858,8 @@ private string LoadLegacyFabricGetError() { if (selectedLiteLoader is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithLiteLoader"); - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "LegacyFabric")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.LegacyFabric) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); return null; } @@ -1867,8 +1910,8 @@ private void LegacyFabric_Loaded() // 选择与清除 public void LegacyFabric_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.LegacyFabric); selectedLegacyFabric = ((dynamic)sender.Tag)["version"].ToString(); - selectedLoaderName = "LegacyFabric"; LegacyFabricApi_Loaded(); CardLegacyFabric.IsSwapped = true; ReloadSelected(); @@ -1879,7 +1922,7 @@ private void LegacyFabric_Clear(object sender, MouseButtonEventArgs e) selectedLegacyFabric = null; selectedLegacyFabricApi = null; autoSelectedLegacyFabricApi = false; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; CardLegacyFabric.IsSwapped = true; e.Handled = true; @@ -2165,8 +2208,8 @@ private string LoadLabyModGetError() return GetLoaderError(LoadLabyMod); if (selectedOptiFine is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); - if (selectedLoaderName is not null && selectedLoaderName != "LabyMod") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.LabyMod) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (selectedLiteLoader is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithLiteLoader"); foreach (JsonObject Version in ModDownload.dlLabyModListLoader.output.Value["production"]["minecraftVersions"].AsArray()) @@ -2244,12 +2287,12 @@ private void LabyMod_Loaded() // 选择与清除 public void LabyMod_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.LabyMod); selectedLabyModChannel = ((dynamic)sender.Tag)["channel"].ToString(); selectedLabyModCommitRef = ((dynamic)sender.Tag)["commitReference"].ToString(); selectedLabyModBaseVersion = ((dynamic)sender.Tag)["version"].ToString(); selectedLabyModVersion = selectedLabyModBaseVersion + " " + (selectedLabyModChannel == "snapshot" ? Lang.Text("Download.Version.Type.Snapshot") : Lang.Text("Download.Version.Type.Stable")); - selectedLoaderName = "LabyMod"; CardLabyMod.IsSwapped = true; ReloadSelected(); } @@ -2261,9 +2304,9 @@ private void LabyMod_Clear(object sender, MouseButtonEventArgs e) selectedLabyModBaseVersion = null; selectedLabyModChannel = null; - if (selectedLoaderName == "LabyMod") + if (_selectedLoaderType == ModLoaderType.LabyMod) { - selectedLoaderName = null; + _selectedLoaderType = null; } selectedAPIName = null; @@ -2285,7 +2328,7 @@ private void TextSelectName_KeyDown(object sender, KeyEventArgs e) private void BtnStart_Click() { // 确认版本隔离 - if (selectedLoaderName is not null && + if (_selectedLoaderType is not null && (Config.Launch.IndieSolutionV2 == 0 || Config.Launch.IndieSolutionV2 == 2)) if (ModMain.MyMsgBox( diff --git a/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs b/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs index fe5e3e0b2..728f1b111 100644 --- a/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs +++ b/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceInstall.xaml.cs @@ -106,7 +106,7 @@ private void BtnSelectStart_Click(object sender, MouseButtonEventArgs mouseButto } // 确认版本隔离 - if (selectedLoaderName is not null && + if (_selectedLoaderType is not null && (Config.Launch.IndieSolutionV2 == 0 || Config.Launch.IndieSolutionV2 == 2)) if (ModMain.MyMsgBox( @@ -383,9 +383,9 @@ private void CardMinecraft_PreviewSwap(object sender, ModBase.RouteEventArgs e) private ModDownload.DlOptiFineListEntry? selectedOptiFine; /// - /// 选定的 Mod Loader 名称,内容应为 Forge / NeoForge / Fabric / Cleanroom / LabyMod / LegacyFabric + /// 选定的主 Mod 加载器。 /// - private string? selectedLoaderName; + private ModLoaderType? _selectedLoaderType; /// /// 选定的 Mod Loader API 名称,内容应为 Fabric API @@ -852,7 +852,7 @@ private void ClearSelected() _vanillaIcon = null; selectedOptiFine = null; selectedLiteLoader = null; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; selectedForge = null; selectedNeoForge = null; @@ -869,6 +869,54 @@ private void ClearSelected() selectedLegacyFabricApi = null; } + /// + /// 选择主 Mod 加载器时,清除其它主加载器及其专属组件。 + /// OptiFine 与 LiteLoader 可与部分加载器共存,故不在此处清除。 + /// + private void SelectModLoader(ModLoaderType loaderType) + { + if (loaderType != ModLoaderType.Forge) + selectedForge = null; + + if (loaderType != ModLoaderType.NeoForge) + { + selectedNeoForge = null; + selectedNeoForgeVersion = null; + } + + if (loaderType != ModLoaderType.Cleanroom) + { + selectedCleanroom = null; + selectedCleanroomVersion = null; + } + + if (loaderType != ModLoaderType.Fabric) + { + selectedFabric = null; + selectedFabricApi = null; + selectedOptiFabric = null; + autoSelectedFabricApi = false; + autoSelectedOptiFabric = false; + } + + if (loaderType != ModLoaderType.LegacyFabric) + { + selectedLegacyFabric = null; + selectedLegacyFabricApi = null; + autoSelectedLegacyFabricApi = false; + } + + if (loaderType != ModLoaderType.LabyMod) + { + selectedLabyModChannel = null; + selectedLabyModCommitRef = null; + selectedLabyModVersion = null; + } + + _selectedLoaderType = loaderType; + selectedAPIName = null; + } + // 信息栏动画 private void SetPanelVisibility(Grid panel, bool visible) { @@ -1048,14 +1096,14 @@ public void GetCurrentInfo() }; if (currentInstance.HasCleanroom) { - selectedLoaderName = "Cleanroom"; + _selectedLoaderType = ModLoaderType.Cleanroom; selectedAPIName = "Cleanroom"; selectedCleanroomVersion = currentInstance.Cleanroom; selectedCleanroom = new ModDownload.DlCleanroomListEntry(selectedCleanroomVersion); } else if (currentInstance.HasForge) { - selectedLoaderName = "Forge"; + _selectedLoaderType = ModLoaderType.Forge; selectedForge = new ModDownload.DlForgeVersionEntry(currentInstance.Forge, null, currentInstance.VanillaName) { @@ -1065,24 +1113,24 @@ public void GetCurrentInfo() } else if (currentInstance.HasLegacyFabric) { - selectedLoaderName = "LegacyFabric"; + _selectedLoaderType = ModLoaderType.LegacyFabric; selectedLegacyFabric = currentInstance.LegacyFabric; selectedLegacyFabricApi = (ModComp.CompFile)GetCurrentLegacyFabricApi(); } else if (currentInstance.HasFabric) { - selectedLoaderName = "Fabric"; + _selectedLoaderType = ModLoaderType.Fabric; selectedFabric = currentInstance.Fabric; selectedFabricApi = (ModComp.CompFile)GetCurrentFabricApi(); } else if (currentInstance.HasLabyMod) { - selectedLoaderName = "LabyMod"; + _selectedLoaderType = ModLoaderType.LabyMod; selectedLabyModVersion = currentInstance.LabyMod; } else if (currentInstance.HasNeoForge) { - selectedLoaderName = "NeoForge"; + _selectedLoaderType = ModLoaderType.NeoForge; selectedNeoForgeVersion = currentInstance.NeoForge; selectedNeoForge = new ModDownload.DlNeoForgeListEntry(currentInstance.NeoForge) { @@ -1323,18 +1371,18 @@ void StackInstall(StackPanel stack) /// private string LoadOptiFineGetError() { - if (selectedLoaderName == "NeoForge" || selectedLoaderName == "LabyMod" || selectedLoaderName == "Cleanroom") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is ModLoaderType.NeoForge or ModLoaderType.LabyMod or ModLoaderType.Cleanroom) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (LoadOptiFine is null || LoadOptiFine.State.LoadingState == MyLoading.MyLoadingState.Run) return Lang.Text("Download.Install.State.Loading"); if (LoadOptiFine.State.LoadingState == MyLoading.MyLoadingState.Error) return $"{Lang.Text("Download.Install.State.GetVersionListFailed")}{((ModLoader.LoaderBase)LoadOptiFine.State).Error.Message}"; // 检查 Forge 1.13 - 1.14.3:全部不兼容 - if (selectedLoaderName == "Forge" && McVersionComparer.CompareVersion(_vanillaName, "1.13") >= 0 && - McVersionComparer.CompareVersion("1.14.3", _vanillaName) >= 0) return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType == ModLoaderType.Forge && McVersionComparer.CompareVersion(_vanillaName, "1.13") >= 0 && + McVersionComparer.CompareVersion("1.14.3", _vanillaName) >= 0) return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Fabric 1.20.5+: 全部不兼容 if (selectedFabric is not null && McVersionComparer.CompareVersion(_vanillaName, "1.20.4") > 0) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Loader if (GetLoaderError(LoadOptiFine) is not null) return GetLoaderError(LoadOptiFine); @@ -1358,7 +1406,7 @@ private string LoadOptiFineGetError() if (hasRequiredVersion) return Lang.Text("Download.Install.Compat.CompatForgeSpecificOnly"); - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); } // 检查某个 OptiFine 是否与某个 Forge 兼容 @@ -1472,8 +1520,8 @@ private string LoadLiteLoaderGetError() // 检查 Loader if (GetLoaderError(LoadLiteLoader) is not null) return GetLoaderError(LoadLiteLoader); - if (selectedLoaderName == "NeoForge" || selectedLoaderName == "LegacyFabric" || selectedLoaderName == "LabyMod" || selectedLoaderName == "Cleanroom") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is ModLoaderType.NeoForge or ModLoaderType.LegacyFabric or ModLoaderType.LabyMod or ModLoaderType.Cleanroom) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查版本 return ModDownload.dlLiteLoaderListLoader.output.Value.Any(v => (v.Inherit ?? "") == (_vanillaName ?? "")) ? null @@ -1547,8 +1595,8 @@ private string LoadForgeGetError() if (McVersionComparer.CompareVersionGe("1.5.1", _vanillaName) && McVersionComparer.CompareVersionGe(_vanillaName, "1.1")) return Lang.Text("Download.Install.State.NoVersion"); - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "Forge")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Forge) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Loader if (GetLoaderError(LoadForge) is not null) @@ -1561,8 +1609,8 @@ private string LoadForgeGetError() { if (Version.Category == "universal" || Version.Category == "client") continue; // 跳过无法自动安装的版本 - if (selectedLoaderName is not null && selectedLoaderName != "Forge") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Forge) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (selectedOptiFine is not null && McVersionComparer.CompareVersionGe(_vanillaName, "1.13") && McVersionComparer.CompareVersionGe("1.14.3", _vanillaName)) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); // 1.13 ~ 1.14.3 OptiFine 检查 @@ -1628,8 +1676,8 @@ private void Forge_Loaded() // 选择与清除 private void Forge_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.Forge); selectedForge = (ModDownload.DlForgeVersionEntry)sender.Tag; - selectedLoaderName = "Forge"; CardForge.IsSwapped = true; if (selectedOptiFine is not null && !(bool)IsOptiFineSuitForForge(selectedOptiFine, selectedForge)) @@ -1641,7 +1689,7 @@ private void Forge_Selected(MyListItem sender, EventArgs e) private void Forge_Clear(object sender, MouseButtonEventArgs e) { selectedForge = null; - selectedLoaderName = null; + _selectedLoaderType = null; CardForge.IsSwapped = true; e.Handled = true; OptiFine_Loaded(); @@ -1659,8 +1707,8 @@ private string LoadNeoForgeGetError() { if (selectedOptiFine is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "NeoForge")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.NeoForge) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); // 检查 Loader if (GetLoaderError(LoadNeoForge) is not null) return GetLoaderError(LoadNeoForge); @@ -1714,8 +1762,8 @@ private void NeoForge_Loaded() // 选择与清除 private void NeoForge_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.NeoForge); selectedNeoForge = (ModDownload.DlNeoForgeListEntry)sender.Tag; - selectedLoaderName = "NeoForge"; CardNeoForge.IsSwapped = true; OptiFine_Loaded(); ReloadSelected(); @@ -1724,7 +1772,7 @@ private void NeoForge_Selected(MyListItem sender, EventArgs e) private void NeoForge_Clear(object sender, MouseButtonEventArgs e) { selectedNeoForge = null; - selectedLoaderName = null; + _selectedLoaderType = null; CardNeoForge.IsSwapped = true; e.Handled = true; OptiFine_Loaded(); @@ -1744,8 +1792,8 @@ private string LoadCleanroomGetError() return Lang.Text("Download.Install.State.NoAvailableVersion"); if (selectedOptiFine is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); - if (selectedLoaderName is not null && selectedLoaderName != "Cleanroom") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Cleanroom) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (selectedLiteLoader is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithLiteLoader"); // 检查 Loader @@ -1800,8 +1848,8 @@ private void Cleanroom_Loaded() // 选择与清除 private void Cleanroom_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.Cleanroom); selectedCleanroom = (ModDownload.DlCleanroomListEntry)sender.Tag; - selectedLoaderName = "Cleanroom"; CardCleanroom.IsSwapped = true; OptiFine_Loaded(); ReloadSelected(); @@ -1811,7 +1859,7 @@ private void Cleanroom_Clear(object sender, MouseButtonEventArgs e) { selectedCleanroom = null; selectedCleanroomVersion = null; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; CardCleanroom.IsSwapped = true; e.Handled = true; @@ -1839,8 +1887,8 @@ private string LoadFabricGetError() if ((version["version"].ToString() ?? "") == (_vanillaName.Replace("∞", "infinite").Replace("Combat Test 7c", "1.16_combat-3") ?? "")) { - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "Fabric")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.Fabric) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); return null; } @@ -1892,8 +1940,8 @@ private void Fabric_Loaded() // 选择与清除 public void Fabric_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.Fabric); selectedFabric = ((dynamic)sender.Tag)["version"].ToString(); - selectedLoaderName = "Fabric"; FabricApi_Loaded(); OptiFabric_Loaded(); CardFabric.IsSwapped = true; @@ -1907,7 +1955,7 @@ private void Fabric_Clear(object sender, MouseButtonEventArgs e) autoSelectedFabricApi = false; selectedOptiFabric = null; autoSelectedOptiFabric = false; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; CardFabric.IsSwapped = true; e.Handled = true; @@ -2093,8 +2141,8 @@ private string LoadLegacyFabricGetError() { if (selectedLiteLoader is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithLiteLoader"); - if (selectedLoaderName is not null && !ReferenceEquals(selectedLoaderName, "LegacyFabric")) - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.LegacyFabric) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); return null; } @@ -2145,8 +2193,8 @@ private void LegacyFabric_Loaded() // 选择与清除 public void LegacyFabric_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.LegacyFabric); selectedLegacyFabric = ((dynamic)sender.Tag)["version"].ToString(); - selectedLoaderName = "LegacyFabric"; LegacyFabricApi_Loaded(); CardLegacyFabric.IsSwapped = true; ReloadSelected(); @@ -2157,7 +2205,7 @@ private void LegacyFabric_Clear(object sender, MouseButtonEventArgs e) selectedLegacyFabric = null; selectedLegacyFabricApi = null; autoSelectedLegacyFabricApi = false; - selectedLoaderName = null; + _selectedLoaderType = null; selectedAPIName = null; CardLegacyFabric.IsSwapped = true; e.Handled = true; @@ -2444,8 +2492,8 @@ private string LoadLabyModGetError() return GetLoaderError(LoadLabyMod); if (selectedOptiFine is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithOptiFine"); - if (selectedLoaderName is not null && selectedLoaderName != "LabyMod") - return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", selectedLoaderName); + if (_selectedLoaderType is not null && _selectedLoaderType != ModLoaderType.LabyMod) + return Lang.Text("Download.Install.Compat.IncompatibleWithLoader", _selectedLoaderType); if (selectedLiteLoader is not null) return Lang.Text("Download.Install.Compat.IncompatibleWithLiteLoader"); foreach (JsonObject Version in ModDownload.dlLabyModListLoader.output.Value["production"]["minecraftVersions"].AsArray()) @@ -2523,11 +2571,11 @@ private void LabyMod_Loaded() // 选择与清除 public void LabyMod_Selected(MyListItem sender, EventArgs e) { + SelectModLoader(ModLoaderType.LabyMod); selectedLabyModChannel = ((dynamic)sender.Tag)("channel").ToString(); selectedLabyModCommitRef = ((dynamic)sender.Tag)("commitReference").ToString(); selectedLabyModVersion = ((dynamic)sender.Tag)("version").ToString() + (selectedLabyModChannel == "snapshot" ? " " + Lang.Text("Download.Version.Type.Snapshot") : " " + Lang.Text("Download.Version.Type.Stable")); - selectedLoaderName = "LabyMod"; CardLabyMod.IsSwapped = true; ReloadSelected(); } @@ -2538,9 +2586,9 @@ private void LabyMod_Clear(object sender, MouseButtonEventArgs e) selectedLabyModVersion = null; selectedLabyModChannel = null; - if (selectedLoaderName == "LabyMod") + if (_selectedLoaderType == ModLoaderType.LabyMod) { - selectedLoaderName = null; + _selectedLoaderType = null; } selectedAPIName = null;