diff --git a/Plain Craft Launcher 2/FormMain.xaml.vb b/Plain Craft Launcher 2/FormMain.xaml.vb index e57bc968..033eeb8f 100644 --- a/Plain Craft Launcher 2/FormMain.xaml.vb +++ b/Plain Craft Launcher 2/FormMain.xaml.vb @@ -1090,6 +1090,7 @@ Install: DownloadLiteLoader = 9 DownloadMod = 11 DownloadPack = 12 + DownloadDataPack = 15 SetupLaunch = 0 SetupUI = 1 SetupSystem = 2 @@ -1125,6 +1126,12 @@ Install: Return "Mod 下载 - " & Project.TranslatedName Case CompType.ModPack Return "整合包下载 - " & Project.TranslatedName + Case CompType.DataPack + If Project.IsMix Then + Return "Mod / 数据包下载 - " & Project.TranslatedName + Else + Return "数据包下载 - " & Project.TranslatedName + End If Case Else 'CompType.ResourcePack Return "资源包下载 - " & Project.TranslatedName End Select diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb b/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb index 591f6746..667d22c2 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb @@ -13,6 +13,10 @@ ''' 资源包。 ''' ResourcePack = 2 + ''' + ''' 数据包。 + ''' + DataPack = 4 End Enum Public Enum CompModLoaderType 'https://docs.curseforge.com/?http#tocS_ModLoaderType @@ -114,6 +118,10 @@ ''' Public ReadOnly Type As CompType ''' + ''' 是否为 Mod / 数据包融合工程。 + ''' + Public ReadOnly IsMix As Boolean + ''' ''' 工程的短名。例如 technical-enchant。 ''' Public ReadOnly Slug As String @@ -273,8 +281,10 @@ Type = CompType.Mod ElseIf Website.Contains("/modpacks/") Then Type = CompType.ModPack - Else + ElseIf Website.Contains("/resourcepacks/") Then Type = CompType.ResourcePack + Else + Type = CompType.DataPack End If 'Tags Tags = New List(Of String) @@ -322,7 +332,15 @@ Case 4480 : Tags.Add("基于地图") Case 4481 : Tags.Add("轻量") Case 4482 : Tags.Add("大型") - 'FUTURE: Res + '数据包 + Case 6946 : Tags.Add("Mod 支持") + Case 6947 : Tags.Add("杂项") + Case 6948 : Tags.Add("冒险") + Case 6949 : Tags.Add("幻想") + Case 6950 : Tags.Add("支持库") + Case 6951 : Tags.Add("科技") + Case 6952 : Tags.Add("魔法") + Case 6953 : Tags.Add("实用工具") End Select Next If Not Tags.Any() Then Tags.Add("杂项") @@ -350,7 +368,12 @@ Case "mod" : Type = CompType.Mod Case "modpack" : Type = CompType.ModPack Case "resourcepack" : Type = CompType.ResourcePack + Case "datapack" : Type = CompType.DataPack End Select + If Data("categories").ToArray.Contains("datapack") Then 'Modrinth 上的数据包由于未知原因,返回的 project_type 为 mod,这里做兜底处理 + Type = CompType.DataPack + IsMix = Data("categories").ToArray.Contains("forge") OrElse Data("categories").ToArray.Contains("fabric") OrElse Data("categories").ToArray.Contains("neoforge") OrElse Data("categories").ToArray.Contains("quilt") + End If 'Tags & ModLoaders Tags = New List(Of String) ModLoaders = New List(Of CompModLoaderType) @@ -388,7 +411,26 @@ Case "adventure" : Tags.Add("冒险") Case "kitchen-sink" : Tags.Add("大杂烩") Case "lightweight" : Tags.Add("轻量") - 'FUTURE: Res + '数据包 + Case "adventure" : Tags.Add("冒险") + Case "cursed" : Tags.Add("Cursed") + Case "decoration" : Tags.Add("装饰") + Case "economy" : Tags.Add("经济") + Case "equipment" : Tags.Add("装备") + Case "food" : Tags.Add("食物") + Case "game-mechanics" : Tags.Add("游戏机制") + Case "library" : Tags.Add("支持库") + Case "magic" : Tags.Add("魔法") + Case "management" : Tags.Add("管理") + Case "minigame" : Tags.Add("小游戏") + Case "mobs" : Tags.Add("生物") + Case "optimization" : Tags.Add("优化") + Case "social" : Tags.Add("社交") + Case "storage" : Tags.Add("存储") + Case "technology" : Tags.Add("科技") + Case "transportation" : Tags.Add("交通") + Case "utility" : Tags.Add("实用工具") + Case "worldgen" : Tags.Add("世界生成") End Select Next If Not Tags.Any() Then Tags.Add("杂项") @@ -749,8 +791,8 @@ NoSubtitle: Address += "&classId=6" Case CompType.ModPack Address += "&classId=4471" - Case CompType.ResourcePack - 'FUTURE: Res + Case CompType.DataPack + Address += "&classId=6945" End Select Address += "&categoryId=" & If(Tag = "", "0", Tag.Before("/")) If ModLoader <> CompModLoaderType.Any Then Address += "&modLoaderType=" & CType(ModLoader, Integer) diff --git a/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb b/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb index ee52b361..a38118c8 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb @@ -194,6 +194,8 @@ RetryStart: TargetLoader = PageDownloadMod.Loader.Input.ModLoader Case CompType.ModPack TargetVersion = If(PageDownloadPack.Loader.Input.GameVersion, "") + Case CompType.DataPack + TargetVersion = If(PageDownloadDataPack.Loader.Input.GameVersion, "") Case Else 'CompType.ResourcePack 'FUTURE: Res TargetVersion = "" 'If(PageDownloadResource.Loader.Input.GameVersion, "") diff --git a/Plain Craft Launcher 2/Modules/ModMain.vb b/Plain Craft Launcher 2/Modules/ModMain.vb index 21362135..ad19c495 100644 --- a/Plain Craft Launcher 2/Modules/ModMain.vb +++ b/Plain Craft Launcher 2/Modules/ModMain.vb @@ -398,6 +398,7 @@ EndHint: Public FrmDownloadFabric As PageDownloadFabric Public FrmDownloadMod As PageDownloadMod Public FrmDownloadPack As PageDownloadPack + Public FrmDownloadDataPack As PageDownloadDataPack '设置页面声明 Public FrmSetupLeft As PageSetupLeft diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb index 60f54bd9..e3c7e24e 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb @@ -205,7 +205,13 @@ RunInNewThread( Sub() Try - Dim Desc As String = If(Project.Type = CompType.ModPack, "整合包", If(Project.Type = CompType.Mod, "Mod ", "资源包")) + Dim Desc As String = "资源" + Select Case Project.Type + Case CompType.ModPack : Desc = "整合包" + Case CompType.Mod : Desc = "Mod " + Case CompType.ResourcePack : Desc = "资源包" + Case CompType.DataPack : Desc = If(File.FileName.EndsWith(".jar"), "Mod ", "数据包") '有些项目同时包含 Mod 版本和数据包版本 + End Select '确认默认保存位置 Dim DefaultFolder As String = Nothing If Project.Type = CompType.Mod Then diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadDataPack.xaml b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadDataPack.xaml new file mode 100644 index 00000000..ea526766 --- /dev/null +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadDataPack.xaml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadDataPack.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadDataPack.xaml.vb new file mode 100644 index 00000000..3adc461d --- /dev/null +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadDataPack.xaml.vb @@ -0,0 +1,122 @@ +Public Class PageDownloadDataPack + + Public Const PageSize = 40 + + '加载器信息 + Public Shared Loader As New LoaderTask(Of CompProjectRequest, Integer)("CompProject Shader", AddressOf CompProjectsGet, AddressOf LoaderInput) With {.ReloadTimeout = 60 * 1000} + Public Shared Storage As New CompProjectStorage + Public Shared Page As Integer = 0 + Private Sub PageDownloadShader_Inited(sender As Object, e As EventArgs) Handles Me.Initialized + PageLoaderInit(Load, PanLoad, PanContent, PanAlways, Loader, AddressOf Load_OnFinish, AddressOf LoaderInput) + If McVersionHighest = -1 Then McVersionHighest = Math.Max(McVersionHighest, Integer.Parse(CType(TextSearchVersion.Items(1), MyComboBoxItem).Content.ToString.Split(".")(1))) + End Sub + Private Shared Function LoaderInput() As CompProjectRequest + Dim Request As New CompProjectRequest(CompType.DataPack, Storage, (Page + 1) * PageSize) + If FrmDownloadDataPack IsNot Nothing Then + With Request + .SearchText = FrmDownloadDataPack.TextSearchName.Text + .GameVersion = If(FrmDownloadDataPack.TextSearchVersion.Text = "全部 (也可自行输入)", Nothing, + If(FrmDownloadDataPack.TextSearchVersion.Text.Contains(".") OrElse FrmDownloadDataPack.TextSearchVersion.Text.Contains("w"), FrmDownloadDataPack.TextSearchVersion.Text, Nothing)) + .Tag = FrmDownloadDataPack.ComboSearchTag.SelectedItem.Tag + .Source = CType(Val(FrmDownloadDataPack.ComboSearchSource.SelectedItem.Tag), CompSourceType) + End With + End If + Return Request + End Function + + '结果 UI 化 + Private Sub Load_OnFinish() + Try + Log($"[Comp] 开始可视化数据包列表,已储藏 {Storage.Results.Count} 个结果,当前在第 {Page + 1} 页") + '列表项 + PanProjects.Children.Clear() + For i = Math.Min(Page * PageSize, Storage.Results.Count - 1) To Math.Min((Page + 1) * PageSize - 1, Storage.Results.Count - 1) + PanProjects.Children.Add(Storage.Results(i).ToCompItem(Loader.Input.GameVersion Is Nothing, False)) + Next + '页码 + CardPages.Visibility = If(Storage.Results.Count > 40 OrElse + Storage.CurseForgeOffset < Storage.CurseForgeTotal OrElse Storage.ModrinthOffset < Storage.ModrinthTotal, + Visibility.Visible, Visibility.Collapsed) + LabPage.Text = Page + 1 + BtnPageFirst.IsEnabled = Page > 1 + BtnPageFirst.Opacity = If(BtnPageFirst.IsEnabled, 1, 0.2) + BtnPageLeft.IsEnabled = Page > 0 + BtnPageLeft.Opacity = If(BtnPageLeft.IsEnabled, 1, 0.2) + BtnPageRight.IsEnabled = Storage.Results.Count > PageSize * (Page + 1) OrElse + Storage.CurseForgeOffset < Storage.CurseForgeTotal OrElse Storage.ModrinthOffset < Storage.ModrinthTotal + BtnPageRight.Opacity = If(BtnPageRight.IsEnabled, 1, 0.2) + '错误信息 + If Storage.ErrorMessage Is Nothing Then + HintError.Visibility = Visibility.Collapsed + Else + HintError.Visibility = Visibility.Visible + HintError.Text = Storage.ErrorMessage + End If + '强制返回顶部 + PanBack.ScrollToTop() + Catch ex As Exception + Log(ex, "可视化数据包列表出错", LogLevel.Feedback) + End Try + End Sub + + '自动重试 + Private Sub Load_State(sender As Object, state As MyLoading.MyLoadingState, oldState As MyLoading.MyLoadingState) Handles Load.StateChanged + Select Case Loader.State + Case LoadState.Failed + Dim ErrorMessage As String = "" + If Loader.Error IsNot Nothing Then ErrorMessage = Loader.Error.Message + If ErrorMessage.Contains("不是有效的 JSON 文件") Then + Log("[Download] 下载的数据包列表 JSON 文件损坏,已自动重试", LogLevel.Debug) + PageLoaderRestart() + End If + End Select + End Sub + + '切换页码 + + Private Sub BtnPageFirst_Click(sender As Object, e As RoutedEventArgs) Handles BtnPageFirst.Click + ChangePage(0) + End Sub + Private Sub BtnPageLeft_Click(sender As Object, e As RoutedEventArgs) Handles BtnPageLeft.Click + ChangePage(Page - 1) + End Sub + Private Sub BtnPageRight_Click(sender As Object, e As RoutedEventArgs) Handles BtnPageRight.Click + ChangePage(Page + 1) + End Sub + Private Sub ChangePage(NewPage As Integer) + CardPages.IsEnabled = False + Page = NewPage + FrmMain.BackToTop() + Log($"[Download] 数据包切换到第 {Page + 1} 页") + RunInThread(Sub() + Thread.Sleep(100) '等待向上滚的动画结束 + RunInUi(Sub() CardPages.IsEnabled = True) + Loader.Start() + End Sub) + End Sub + +#Region "搜索" + + '搜索按钮 + Private Sub StartNewSearch() Handles BtnSearchRun.Click + Page = 0 + If Loader.ShouldStart(LoaderInput()) Then Storage = New CompProjectStorage '避免连续搜索两次使得 CompProjectStorage 引用丢失(#1311) + Loader.Start() + End Sub + Private Sub EnterTrigger(sender As Object, e As KeyEventArgs) Handles TextSearchName.KeyDown, TextSearchVersion.KeyDown + If e.Key = Key.Enter Then StartNewSearch() + End Sub + + '重置按钮 + Private Sub BtnSearchReset_Click(sender As Object, e As EventArgs) Handles BtnSearchReset.Click + TextSearchName.Text = "" + TextSearchVersion.Text = "全部 (也可自行输入)" + TextSearchVersion.SelectedIndex = 0 + ComboSearchSource.SelectedIndex = 0 + ComboSearchTag.SelectedIndex = 0 + Loader.LastFinishedTime = 0 '要求强制重新开始 + End Sub + +#End Region + +End Class diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml index 8a646677..a910b048 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml @@ -84,6 +84,14 @@ + + + + + + + diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb index 2658c33e..fcd1ad12 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb @@ -10,7 +10,7 @@ ''' ''' 勾选事件改变页面。 ''' - Private Sub PageCheck(sender As MyListItem, e As RouteEventArgs) Handles ItemInstall.Check, ItemClient.Check, ItemOptiFine.Check, ItemForge.Check, ItemNeoForge.Check, ItemLiteLoader.Check, ItemMod.Check, ItemFabric.Check, ItemPack.Check + Private Sub PageCheck(sender As MyListItem, e As RouteEventArgs) Handles ItemInstall.Check, ItemClient.Check, ItemOptiFine.Check, ItemForge.Check, ItemNeoForge.Check, ItemLiteLoader.Check, ItemMod.Check, ItemFabric.Check, ItemPack.Check, ItemDataPack.Check '尚未初始化控件属性时,sender.Tag 为 Nothing,会导致切换到页面 0 '若使用 IsLoaded,则会导致模拟点击不被执行(模拟点击切换页面时,控件的 IsLoaded 为 False) If sender.Tag IsNot Nothing Then PageChange(Val(sender.Tag)) @@ -46,6 +46,9 @@ Case FormMain.PageSubType.DownloadPack If FrmDownloadPack Is Nothing Then FrmDownloadPack = New PageDownloadPack Return FrmDownloadPack + Case FormMain.PageSubType.DownloadDataPack + If FrmDownloadDataPack Is Nothing Then FrmDownloadDataPack = New PageDownloadDataPack + Return FrmDownloadDataPack Case Else Throw New Exception("未知的下载子页面种类:" & ID) End Select @@ -114,6 +117,12 @@ CompProjectCache.Clear() If FrmDownloadPack IsNot Nothing Then FrmDownloadPack.PageLoaderRestart() ItemPack.Checked = True + Case FormMain.PageSubType.DownloadDataPack + PageDownloadDataPack.Storage = New CompProjectStorage + PageDownloadDataPack.Page = 0 + CompProjectCache.Clear() + If FrmDownloadDataPack IsNot Nothing Then FrmDownloadDataPack.PageLoaderRestart() + ItemDataPack.Checked = True Case FormMain.PageSubType.DownloadClient DlClientListLoader.Start(IsForceRestart:=True) ItemClient.Checked = True diff --git a/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj b/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj index bc74b16e..863d6912 100644 --- a/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj +++ b/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj @@ -233,6 +233,9 @@ MyCompItem.xaml + + PageDownloadDataPack.xaml + PageDownloadMod.xaml @@ -481,6 +484,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile