Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Plain Craft Launcher 2/Modules/Minecraft/ModLoaderType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace PCL;

/// <summary>
/// 实例安装流程中可互斥选择的主 Mod 加载器。
/// </summary>
internal enum ModLoaderType
{
Forge,
NeoForge,
Cleanroom,
Fabric,
LegacyFabric,
LabyMod
}
119 changes: 81 additions & 38 deletions Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ public void MinecraftSelected(MyListItem sender, MouseButtonEventArgs e)
private ModDownload.DlOptiFineListEntry? selectedOptiFine;

/// <summary>
/// 选定的 Mod Loader 名称,内容应为 Forge / NeoForge / Fabric / Cleanroom / LabyMod / LegacyFabric
/// 选定的主 Mod 加载器。
/// </summary>
private string? selectedLoaderName;
private ModLoaderType? _selectedLoaderType;

/// <summary>
/// 选定的 Mod Loader API 名称,内容应为 Fabric API
Expand Down Expand Up @@ -785,7 +785,7 @@ private void ClearSelected()
_vanillaIcon = null;
selectedOptiFine = null;
selectedLiteLoader = null;
selectedLoaderName = null;
_selectedLoaderType = null;
selectedAPIName = null;
selectedForge = null;
selectedNeoForge = null;
Expand All @@ -801,6 +801,49 @@ private void ClearSelected()
selectedLegacyFabricApi = null;
}

/// <summary>
/// 选择主 Mod 加载器时,清除其它主加载器及其专属组件。
/// OptiFine 与 LiteLoader 可与部分加载器共存,故不在此处清除。
/// </summary>
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)
{
Expand Down Expand Up @@ -1083,18 +1126,18 @@ private static void _StackInstall(StackPanel stack)
/// </summary>
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);
Expand All @@ -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 兼容
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 检查
Expand Down Expand Up @@ -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))
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand All @@ -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(
Expand Down
Loading
Loading