diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb b/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
index 73614ed2..7dc27f4b 100644
--- a/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
+++ b/Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
@@ -1513,5 +1513,62 @@ Retry:
End Sub
#End Region
+ Class CompFavorites
+ '''
+ ''' 获取全部的收藏工程
+ '''
+ '''
+ Public Shared Function GetAll() As List(Of CompProject)
+ Dim res As New List(Of CompProject)
+ Dim RawData As String = ReadReg("CustomCompFavorites")
+ If String.IsNullOrWhiteSpace(RawData) Then Return res
+ Dim RawList As JArray = JArray.Parse(RawData)
+ For Each CompRawItem As JObject In RawList
+ res.Add(New CompProject(CompRawItem))
+ Next
+ Return res
+ End Function
+ Public Shared Sub SaveAll(items As List(Of CompProject))
+ Dim RawList As JArray = New JArray()
+ For Each item As CompProject In items
+ RawList.Add(item.ToJson())
+ Next
+ WriteReg("CustomCompFavorites", RawList.ToString())
+ End Sub
+ '''
+ ''' 是否已经收藏
+ '''
+ ''' 工程
+ '''
+ Public Shared Function Has(item As CompProject) As Boolean
+ Return GetAll().Find(Function(e) e.IsLike(item)) IsNot Nothing
+ End Function
+ '''
+ ''' 添加收藏
+ '''
+ ''' 想要收藏的工程
+ ''' 如果有重复会返回 False
+ Public Shared Function Add(item As CompProject) As Boolean
+ If Has(item) Then Return False
+ Dim res As List(Of CompProject) = GetAll()
+ res.Add(item)
+ SaveAll(res)
+ Return True
+ End Function
+ '''
+ ''' 删除收藏
+ '''
+ ''' 想要删除收藏的工程
+ ''' 如果不存在会返回 False
+ Public Shared Function Del(item As CompProject) As Boolean
+ 'If Not Has(item) Then Return False
+ Dim RawList As List(Of CompProject) = GetAll()
+ Dim SearchRes = RawList.Where(Function(e) e.IsLike(item)).ToList()
+ If Not SearchRes.Any() Then Return False
+ RawList.Remove(SearchRes.First())
+ SaveAll(RawList)
+ Return True
+ End Function
+ End Class
End Module
diff --git a/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb b/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb
index f1fce69b..7d12792a 100644
--- a/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb
+++ b/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb
@@ -181,6 +181,9 @@ RetryStart:
If FrmMain.PageCurrent.Page = FormMain.PageType.CompDetail Then
TargetVersion = FrmMain.PageCurrent.Additional(2)
TargetLoader = FrmMain.PageCurrent.Additional(3)
+ ElseIf FrmMain.PageCurrent.Page = FormMain.PageType.Download AndAlso FrmMain.PageCurrentSub = FormMain.PageSubType.DownloadCompFavorites Then
+ TargetVersion = ""
+ TargetLoader = 0
Else
Select Case CType(sender.Tag, CompProject).Type
Case CompType.Mod
diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml
index 7333268e..09814b08 100644
--- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml
+++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml
@@ -17,6 +17,7 @@
+
diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb
index 60f54bd9..2ea1cb50 100644
--- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb
+++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDetail.xaml.vb
@@ -112,6 +112,14 @@
If PanMain.Children.Count = 1 Then
CType(PanMain.Children(0), MyCard).IsSwaped = False
End If
+
+ If CompFavorites.Has(Project) Then
+ BtnFavorites.Text = "取消收藏"
+ BtnFavorites.Logo = Logo.IconButtonLikeFill
+ Else
+ BtnFavorites.Text = "收藏"
+ BtnFavorites.Logo = Logo.IconButtonLikeLine
+ End If
Catch ex As Exception
Log(ex, "可视化工程下载列表出错", LogLevel.Feedback)
End Try
@@ -327,5 +335,16 @@
Private Sub BtnIntroCopy_Click(sender As Object, e As EventArgs) Handles BtnIntroCopy.Click
ClipboardSet(CompItem.LabTitle.Text)
End Sub
+ Private Sub BtnFavorites_Click(sender As Object, e As EventArgs) Handles BtnFavorites.Click
+ If CompFavorites.Has(Project) Then
+ If CompFavorites.Del(Project) Then Hint("已取消收藏!")
+ BtnFavorites.Text = "收藏"
+ BtnFavorites.Logo = Logo.IconButtonLikeLine
+ Else
+ If CompFavorites.Add(Project) Then Hint("已收藏!")
+ BtnFavorites.Text = "取消收藏"
+ BtnFavorites.Logo = Logo.IconButtonLikeFill
+ End If
+ End Sub
End Class
diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml
index 2a32cbdc..d0ef69f9 100644
--- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml
+++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml
@@ -8,18 +8,35 @@
-
-
-
+
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml.vb
index 19d2c617..75d4ff2c 100644
--- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml.vb
+++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavorites.xaml.vb
@@ -1,25 +1,55 @@
Public Class PageDownloadCompFavorites
- Public Const PageSize = 40
-
'加载器信息
- Public Shared Loader As New LoaderTask(Of String, Integer)("CompProject Mod", AddressOf CompFavoritesGet, AddressOf LoaderInput)
- Public Shared Storage As New CompProjectStorage
+ Public Shared Loader As New LoaderTask(Of List(Of CompProject), Integer)("CompProject Favorites", AddressOf CompFavoritesGet, AddressOf LoaderInput)
Private Sub PageDownloadMod_Inited(sender As Object, e As EventArgs) Handles Me.Initialized
PageLoaderInit(Load, PanLoad, PanContent, Nothing, Loader, AddressOf Load_OnFinish, AddressOf LoaderInput)
End Sub
- Private Shared Function LoaderInput() As String
- Return ReadReg("CustomCompFavorites")
- End Function
- Private Shared Function CompFavoritesGet(Task As LoaderTask(Of String, Integer))
-
+ Private Shared Function LoaderInput() As List(Of CompProject)
+ Return CompFavorites.GetAll()
End Function
+ Private Shared Sub CompFavoritesGet(Task As LoaderTask(Of List(Of CompProject), Integer))
+ Task.Output = Task.Input.Count
+ ' TODO: 刷新已存储的收藏
+ End Sub
'结果 UI 化
Private Sub Load_OnFinish()
Try
+ If Loader.Output.Equals(0) Then '没收藏
+ PanSearchBox.Visibility = Visibility.Collapsed
+ CardProjectsMod.Visibility = Visibility.Collapsed
+ CardProjectsModpack.Visibility = Visibility.Collapsed
+ CardNoContent.Visibility = Visibility.Visible
+ Else '有收藏
+ PanSearchBox.Visibility = Visibility.Visible
+ CardProjectsMod.Visibility = Visibility.Visible
+ CardProjectsModpack.Visibility = Visibility.Visible
+ CardNoContent.Visibility = Visibility.Collapsed
+ PanProjectsMod.Children.Clear()
+ PanProjectsModpack.Children.Clear()
+ For Each item As CompProject In Loader.Input
+ Dim EleItem As MyCompItem = item.ToCompItem(True, True)
+ If item.Type = CompType.Mod Then
+ PanProjectsMod.Children.Add(EleItem)
+ ElseIf item.Type = CompType.ModPack Then
+ PanProjectsModpack.Children.Add(EleItem)
+ Else
+ Log("未知工程类型:" & item.Type)
+ End If
+ Next
+
+ Dim NoContentTip As TextBlock = New TextBlock With {.Text = "暂时没有收藏内容", .Margin = New Thickness(0, 0, 0, 9), .HorizontalAlignment = HorizontalAlignment.Center, .FontSize = 19, .UseLayoutRounding = True, .SnapsToDevicePixels = True, .Foreground = DirectCast(FindResource("ColorBrush3"), SolidColorBrush)}
+ If PanProjectsMod.Children.Count.Equals(0) Then
+ PanProjectsMod.Children.Add(NoContentTip)
+ End If
+
+ If PanProjectsModpack.Children.Count.Equals(0) Then
+ PanProjectsModpack.Children.Add(NoContentTip)
+ End If
+ End If
Catch ex As Exception
Log(ex, "可视化收藏夹列表出错", LogLevel.Feedback)
End Try
diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb
index da3b9d73..8edd87aa 100644
--- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb
+++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadLeft.xaml.vb
@@ -135,6 +135,9 @@
Case FormMain.PageSubType.DownloadFabric
DlFabricListLoader.Start(IsForceRestart:=True)
ItemFabric.Checked = True
+ Case FormMain.PageSubType.DownloadCompFavorites
+ If FrmDownloadCompFavorites IsNot Nothing Then FrmDownloadCompFavorites.PageLoaderRestart()
+ ItemFavorites.Checked = True
End Select
Hint("正在刷新……", Log:=False)
End Sub