Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 资源收藏 #4933

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
08635a8
feat: 创建界面
tangge233 Oct 11, 2024
f1ed80e
Revert "feat: 创建界面"
tangge233 Oct 12, 2024
72d84ab
feat: 修改界面
tangge233 Oct 12, 2024
dc345f8
feat: 基本框架
tangge233 Oct 12, 2024
10a5dc8
feat: 界面小调整
tangge233 Oct 12, 2024
3c5533a
feat: 重构一下获取方法
tangge233 Oct 12, 2024
3ff0d63
chore: UI 调整
tangge233 Oct 12, 2024
f5306e9
chore: 搜索功能先砍了
tangge233 Oct 12, 2024
7c54739
feat: 搜索框
tangge233 Oct 12, 2024
56b69ee
fix: 按钮状态在切换页面时没有切换
tangge233 Oct 12, 2024
01e6267
fix: 不会自动刷新
tangge233 Oct 12, 2024
e37e559
chore: 漏了个注释……
tangge233 Oct 12, 2024
eb377a3
Apply suggestions from code review
tangge233 Oct 12, 2024
d2d4416
feat: 搜索整合进一张卡片
tangge233 Oct 12, 2024
f99ea3e
feat: 防止全炸
tangge233 Oct 12, 2024
9e31960
fix: API 同时请求
tangge233 Oct 12, 2024
2d71404
fix: 使用 Setup 而不是 ReadReg
tangge233 Oct 12, 2024
f04e63b
chore: 删除无用字段
tangge233 Oct 12, 2024
2247674
feat: 减少不必要的多次全部读取构造
tangge233 Oct 12, 2024
292ef62
fix: 可能卡住的任务
tangge233 Oct 13, 2024
87e4c51
chore: UI 优化
tangge233 Oct 13, 2024
2d39394
feat: 仅存储 ID 信息
tangge233 Oct 13, 2024
3eb69f9
Merge branch 'Hex-Dragon:main' into ResourceFavorites
tangge233 Oct 13, 2024
1b62bec
Update Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompFavo…
tangge233 Oct 13, 2024
08b25a7
chore: 优化结构
tangge233 Oct 14, 2024
fc0495d
Merge branch 'main' into ResourceFavorites
tangge233 Oct 14, 2024
49f3879
Merge branch 'main' into ResourceFavorites
tangge233 Oct 15, 2024
e047260
feat: 先抄个界面
tangge233 Oct 16, 2024
625ddbc
Merge branch 'main' into ResourceFavorites
tangge233 Oct 16, 2024
eb766ff
feat: 修改界面
tangge233 Oct 16, 2024
ff1b373
feat: 加入删除按钮
tangge233 Oct 16, 2024
3c177f9
feat: 进入详情页面
tangge233 Oct 16, 2024
289698b
feat: 批量操作(需要优化)
tangge233 Oct 16, 2024
9d0a496
chore: UI 错误
tangge233 Oct 16, 2024
eb86965
feat: 完善界面
tangge233 Oct 17, 2024
74ac8be
fix: 错误的界面展示
tangge233 Oct 18, 2024
ae2f662
chore: 逻辑小优化
tangge233 Oct 18, 2024
d02ecd5
chore: 多余代码内容
tangge233 Oct 18, 2024
770d9e3
fix: 不符合直觉的全选
tangge233 Oct 18, 2024
49d8d7f
Update Plain Craft Launcher 2/Pages/PageDownload/PageDownloadCompDeta…
tangge233 Oct 18, 2024
ea5f049
chore: apply suggestions
tangge233 Oct 19, 2024
8624129
Merge branch 'ResourceFavorites' of https://github.com/tangge233/PCL2…
tangge233 Oct 19, 2024
67ef710
chore: 使用 CompFavorites 作为存储名称
tangge233 Oct 19, 2024
f09fb31
Merge branch 'main' into ResourceFavorites
tangge233 Oct 29, 2024
6a6e4a3
Merge branch 'main' into ResourceFavorites
tangge233 Nov 12, 2024
d8f404f
feat: MyListItem 修改
tangge233 Nov 13, 2024
85d4df1
chore: remove MyMiniCompItem
tangge233 Nov 13, 2024
5a1a670
fix: ListItem click ability
tangge233 Nov 13, 2024
5d67724
chore: decoupling
tangge233 Nov 13, 2024
5e7d57c
fix: abnormal reload
tangge233 Nov 13, 2024
6e24a7c
apply suggestions
tangge233 Nov 14, 2024
f9bde27
fix: listitem layout error
tangge233 Nov 17, 2024
34c6a22
feat: 使用 Property 自动处理……
tangge233 Dec 21, 2024
dd05cf1
Merge branch 'main' into ResourceFavorites
tangge233 Dec 21, 2024
4e41461
fix: 保存问题
tangge233 Dec 24, 2024
b855cc3
chore: 默认展开卡片
tangge233 Dec 24, 2024
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
1 change: 1 addition & 0 deletions Plain Craft Launcher 2/FormMain.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ Install:
DownloadLiteLoader = 9
DownloadMod = 11
DownloadPack = 12
DownloadCompFavorites = 13
SetupLaunch = 0
SetupUI = 1
SetupSystem = 2
Expand Down
153 changes: 153 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,158 @@ Retry:
End Sub

#End Region
Class CompFavorites
''' <summary>
''' 获取全部的收藏工程
''' </summary>
''' <returns></returns>
Public Shared Function GetAll() As List(Of Data)
Dim res As New List(Of Data)
Dim RawData As String = ReadReg("CustomCompFavorites")
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
If String.IsNullOrWhiteSpace(RawData) Then Return res
Dim RawList As JArray = JArray.Parse(RawData)
For Each CompRawItem As JObject In RawList
res.Add(New Data(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(New Data(item.Id, item.FromCurseForge, item.Type))
Next
WriteReg("CustomCompFavorites", RawList.ToString())
End Sub
Public Shared Sub SaveAll(items As List(Of Data))
Dim RawList As JArray = New JArray()
For Each item As Data 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
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
Return GetAll().Find(Function(e) e.Id = item.Id) IsNot Nothing
End Function
Public Shared Function Has(item As Data) As Boolean
Return GetAll().Find(Function(e) e.Id = item.Id) 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 Data) = GetAll()
res.Add(New Data(item))
SaveAll(res)
Return True
End Function
Public Shared Function Add(item As Data) As Boolean
If Has(item) Then Return False
Dim res As List(Of Data) = 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
Dim RawList As List(Of Data) = GetAll()
Dim SearchRes = RawList.Where(Function(e) e.Id = item.Id).ToList()
If Not SearchRes.Any() Then Return False
RawList.Remove(SearchRes.First())
SaveAll(RawList)
Return True
End Function
Public Shared Function Del(item As Data) As Boolean
Dim RawList As List(Of Data) = GetAll()
Dim SearchRes = RawList.Where(Function(e) e.Id = item.Id).ToList()
If Not SearchRes.Any() Then Return False
RawList.Remove(SearchRes.First())
SaveAll(RawList)
Return True
End Function

Public Shared Function GetAllCompProjects(Input As List(Of Data)) As List(Of CompProject)
If Not Input.Any() Then Return New List(Of CompProject)
Dim RawList As List(Of Data) = Input
Dim ModrinthProjectIds As List(Of String) = New List(Of String)
Dim CurseForgeProjectIds As List(Of String) = New List(Of String)
Dim Res As List(Of CompProject) = New List(Of CompProject)
For Each Item In RawList
If Item.IsFromCurseForge Then
CurseForgeProjectIds.Add(Item.Id)
Else
ModrinthProjectIds.Add(Item.Id)
End If
Next
Dim RawProjectsData As JArray
RawProjectsData = GetJson(DlModRequest("https://api.curseforge.com/v1/mods",
"POST", "{""modIds"": [" & CurseForgeProjectIds.Join(",") & "]}", "application/json"))("data")
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
For Each RawData In RawProjectsData
Res.Add(New CompProject(RawData))
Next
RawProjectsData = DlModRequest($"https://api.modrinth.com/v2/projects?ids=[""{ModrinthProjectIds.Join(""",""")}""]", IsJson:=True)
For Each RawData In RawProjectsData
Res.Add(New CompProject(RawData))
Next
Return Res
End Function

Public Class Data
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
Public Id As String
Public IsFromCurseForge As Boolean
Public Type As CompType
Public FormatData As CompProject

Public Sub New(RawId As String, RawIsFromCurseForge As Boolean, RawType As CompType)
Id = RawId
IsFromCurseForge = RawIsFromCurseForge
Type = RawType
End Sub
Public Sub New(Json As JObject)
Id = Json("Id")
IsFromCurseForge = Json("IsCF")
Type = Integer.Parse(Json("Type"))
End Sub
Public Sub New(CompItem As CompProject)
Id = CompItem.Id
IsFromCurseForge = CompItem.FromCurseForge
Type = CompItem.Type
End Sub

Public Function ToJson() As JObject
Dim Json As New JObject
Json("Id") = Id
Json("IsCF") = IsFromCurseForge
Json("Type") = Type
Return Json
End Function

Public Function ToCompProject() As CompProject
Dim Projects As JArray
If IsFromCurseForge Then
Projects = GetJson(DlModRequest("https://api.curseforge.com/v1/mods",
"POST", "{""modIds"": [" & Id & "]}", "application/json"))("data")
Else
Projects = DlModRequest($"https://api.modrinth.com/v2/projects?ids=[""{Id}""]", IsJson:=True)
End If
For Each Project As JObject In Projects
Return New CompProject(Project)
Next
Return Nothing
End Function
End Class
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 = CompModLoaderType.Any
Else
Select Case CType(sender.Tag, CompProject).Type
Case CompType.Mod
Expand Down
1 change: 1 addition & 0 deletions Plain Craft Launcher 2/Modules/ModMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ EndHint:
Public FrmDownloadFabric As PageDownloadFabric
Public FrmDownloadMod As PageDownloadMod
Public FrmDownloadPack As PageDownloadPack
Public FrmDownloadCompFavorites As PageDownloadCompFavorites

'设置页面声明
Public FrmSetupLeft As PageSetupLeft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
</Grid.RowDefinitions>
<local:MyCard Margin="0,0,0,25" x:Name="CardIntro">
<StackPanel Margin="22,18,22,19" x:Name="PanIntro">
<StackPanel Orientation="Horizontal" Height="35">
<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" />
</StackPanel>
<Grid Height="35">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<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" />
</StackPanel>
<local:MyIconTextButton x:Name="BtnFavorites" LogoScale="0.75" HorizontalAlignment="Right"/>
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
</Grid>
</StackPanel>
</local:MyCard>
<StackPanel Grid.Row="1" Grid.RowSpan="2" Name="PanMain" Grid.IsSharedSizeScope="True" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@
AniControlEnabled += 1
Project = FrmMain.PageCurrent.Additional(0)
PanBack.ScrollToHome()

If CompFavorites.Has(Project) Then
BtnFavorites.Text = "取消收藏"
BtnFavorites.Logo = Logo.IconButtonLikeFill
Else
BtnFavorites.Text = "收藏"
BtnFavorites.Logo = Logo.IconButtonLikeLine
End If
'重启加载器
If IsFirstInit Then
'在 Me.Initialized 已经初始化了加载器,不再重复初始化
Expand Down Expand Up @@ -327,5 +333,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("已取消收藏!")
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
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
@@ -0,0 +1,46 @@
<local:MyPageRight
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PCL" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" x:Class="PageDownloadCompFavorites"
PanScroll="{Binding ElementName=PanBack}">
<local:MyScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" x:Name="PanBack">
<Grid>
<Grid x:Name="PanContent">
<StackPanel Orientation="Vertical" Margin="25">
<StackPanel>
<local:MySearchBox HintText="搜索收藏夹内容" x:Name="PanSearchBox" Margin="0,0,0,15"/>
<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="整合包" IsSwaped="True" CanSwap="True" Margin="0,0,0,15">
<StackPanel x:Name="PanProjectsModpack" Margin="12,38,12,12" />
</local:MyCard>
</StackPanel>
</StackPanel>
<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" />
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
</Grid>
</local:MyCard>
</Grid>
<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>
</Grid>
</local:MyScrollViewer>
</local:MyPageRight>
Loading