Skip to content

Commit

Permalink
feat: 基本框架
Browse files Browse the repository at this point in the history
  • Loading branch information
tangge233 committed Oct 12, 2024
1 parent 72d84ab commit dc345f8
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 17 deletions.
57 changes: 57 additions & 0 deletions Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1513,5 +1513,62 @@ Retry:
End Sub

#End Region
Class CompFavorites
''' <summary>
''' 获取全部的收藏工程
''' </summary>
''' <returns></returns>
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
''' <summary>
''' 是否已经收藏
''' </summary>
''' <param name="item">工程</param>
''' <returns></returns>
Public Shared Function Has(item As CompProject) As Boolean
Return GetAll().Find(Function(e) e.IsLike(item)) IsNot Nothing
End Function
''' <summary>
''' 添加收藏
''' </summary>
''' <param name="item">想要收藏的工程</param>
''' <returns>如果有重复会返回 False</returns>
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
''' <summary>
''' 删除收藏
''' </summary>
''' <param name="item">想要删除收藏的工程</param>
''' <returns>如果不存在会返回 False</returns>
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
3 changes: 3 additions & 0 deletions Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<local:MyButton x:Name="BtnIntroWeb" MinWidth="140" Text="转到 CurseForge" Padding="13,0" Margin="0,0,20,0" HorizontalAlignment="Left" ColorType="Highlight" />
<local:MyButton x:Name="BtnIntroWiki" MinWidth="140" Text="转到 MC 百科" Padding="13,0" Margin="0,0,20,0" HorizontalAlignment="Left" />
<local:MyButton x:Name="BtnIntroCopy" MinWidth="140" Text="复制名称" Padding="13,0" Margin="0,0,20,0" HorizontalAlignment="Left" />
<local:MyIconTextButton x:Name="BtnFavorites" Text="收藏"/>
</StackPanel>
</StackPanel>
</local:MyCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,35 @@
<StackPanel Orientation="Vertical" Margin="25">
<StackPanel x:Name="PanContent">
<local:MySearchBox HintText="搜索收藏夹内容" x:Name="PanSearchBox" Margin="0,0,0,15"/>

<local:MyCard x:Name="CardProjectsMod" Title="Mod" UseAnimation="False" Margin="0,0,0,15">
<StackPanel x:Name="PanProjectsMod" Margin="12" />
<local:MyCard x:Name="CardProjectsMod" Title="Mod" IsSwaped="True" CanSwap="True" Margin="0,0,0,15">
<StackPanel x:Name="PanProjectsMod" Margin="12,38,12,12" />
</local:MyCard>
<local:MyCard x:Name="CardProjectsModpack" Title="整合包" UseAnimation="False" Margin="0,0,0,15">
<StackPanel x:Name="PanProjectsModpack" Margin="12" />
<local:MyCard x:Name="CardProjectsModpack" Title="整合包" IsSwaped="True" CanSwap="True" Margin="0,0,0,15">
<StackPanel x:Name="PanProjectsModpack" Margin="12,38,12,12" />
</local:MyCard>

<local:MyCard HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="True" x:Name="PanLoad" UseAnimation="False" Margin="40,50">
<local:MyLoading Text="正在加载收藏夹列表" Margin="20,20,20,17" x:Name="Load" HorizontalAlignment="Center" VerticalAlignment="Center" />
<local:MyCard HorizontalAlignment="Center" VerticalAlignment="Center" Margin="40" x:Name="CardNoContent">
<Grid Margin="20,17">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="4" Margin="0,0,0,9" HorizontalAlignment="Center" Text="还没有收藏内容" FontSize="19" UseLayoutRounding="True" SnapsToDevicePixels="True" Foreground="{DynamicResource ColorBrush3}" />
<Rectangle Grid.Row="1" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" Height="2" Fill="{DynamicResource ColorBrush3}" />
<TextBlock Grid.Row="2" Grid.ColumnSpan="4" Margin="10,15,10,5" Text="在资源详细信息界面的右上角可以点击收藏按钮进行收藏" TextWrapping="Wrap" />
</Grid>
</local:MyCard>
</StackPanel>
<local:MyCard HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="True" x:Name="PanLoad" UseAnimation="False" Margin="40,50">
<local:MyLoading Text="正在加载收藏夹列表" Margin="20,20,20,17" x:Name="Load" HorizontalAlignment="Center" VerticalAlignment="Center" />
</local:MyCard>
</StackPanel>
</local:MyScrollViewer>
</local:MyPageRight>
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc345f8

Please sign in to comment.