Skip to content

Commit

Permalink
Merge branch 'ResourceFavorites' into MyBranchCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
tangge233 committed Nov 17, 2024
2 parents c5b56c8 + 6e24a7c commit c3bd25a
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 448 deletions.
14 changes: 11 additions & 3 deletions Plain Craft Launcher 2/Controls/MyListItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<ColumnDefinition x:Name="ColumnCheck" Width="2"/>
<ColumnDefinition x:Name="ColumnPaddingLeft" Width="0" />
<ColumnDefinition x:Name="ColumnLogo" Width="4" />
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition x:Name="ColumnPaddingRight" Width="4" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
Expand All @@ -21,7 +22,14 @@
</Grid.RowDefinitions>
<!--<Border x:Name="RectBack" CornerRadius="3" RenderTransformOrigin="0.5,0.5" SnapsToDevicePixels="True" IsHitTestVisible="False" Opacity="0" Grid.ColumnSpan="4" Background="{DynamicResource ColorBrush7}" BorderBrush="{DynamicResource ColorBrush6}" BorderThickness="1" />-->
<!--<StackPanel VerticalAlignment="Center">-->
<TextBlock Grid.Row="1" SnapsToDevicePixels="False" UseLayoutRounding="False" HorizontalAlignment="Left" x:Name="LabTitle" IsHitTestVisible="False" Grid.Column="3" Text="{Binding Title, ElementName=PanBack}" TextTrimming="CharacterEllipsis" FontSize="{Binding FontSize, ElementName=PanBack}" Foreground="{Binding Foreground, ElementName=PanBack}" Margin="4,0,0,0" />
<!--<TextBlock Grid.Row="2" SnapsToDevicePixels="False" UseLayoutRounding="False" HorizontalAlignment="Left" x:Name="LabInfo" IsHitTestVisible="False" Grid.Column="2" TextTrimming="CharacterEllipsis" Visibility="Collapsed" FontSize="12" Foreground="{StaticResource ColorBrushGray2}" Margin="4,0,0,0" />-->
<TextBlock Grid.Row="1" SnapsToDevicePixels="False" UseLayoutRounding="False" HorizontalAlignment="Left" x:Name="LabTitle" IsHitTestVisible="False" Grid.Column="3" Grid.ColumnSpan="2" Text="{Binding Title, ElementName=PanBack}" TextTrimming="CharacterEllipsis" FontSize="{Binding FontSize, ElementName=PanBack}" Foreground="{Binding Foreground, ElementName=PanBack}" Margin="4,0,0,0" />
<!--<StackPanel Orientation="Horizontal" x:Name="PanInfo" Grid.Row="2" Grid.Column="3" Visibility="Collapsed" IsHitTestVisible="False">
<StackPanel x:Name="PanTags" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,0,-3,0">
<Border Background="{DynamicResource ColorBrush6}" Padding="3,1" CornerRadius="3" Margin="0,0,4,0" SnapsToDevicePixels="True" UseLayoutRounding="False">
<TextBlock Text="科技" Foreground="{DynamicResource ColorBrush2}" FontSize="11" />
</Border>
</StackPanel>
<TextBlock Grid.Row="2" SnapsToDevicePixels="False" UseLayoutRounding="False" HorizontalAlignment="Left" x:Name="LabInfo" IsHitTestVisible="False" Grid.Column="2" TextTrimming="CharacterEllipsis" Visibility="Collapsed" FontSize="12" Foreground="{StaticResource ColorBrushGray2}" Margin="4,0,0,0" />
</StackPanel>-->
<!--</StackPanel>-->
</Grid>
60 changes: 58 additions & 2 deletions Plain Craft Launcher 2/Controls/MyListItem.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,62 @@
'勾选条
Public RectCheck As Border


''' <summary>
''' Tags 的存放 StackPanel
''' </summary>
Public _PanTags As StackPanel
Public ReadOnly Property PanTags As StackPanel
Get
If _PanTags IsNot Nothing Then Return _PanTags
Dim NewStack As New StackPanel With {
.IsHitTestVisible = False,
.Orientation = Orientation.Horizontal,
.VerticalAlignment = VerticalAlignment.Bottom,
.Margin = New Thickness(0, 0, -3, 0)
}
SetColumn(NewStack, 3)
SetRow(NewStack, 2)
PanBack.Children.Add(NewStack)
_PanTags = NewStack
Return _PanTags
End Get
End Property

''' <summary>
''' 标签,可以传入 String 和 List(Of String)
''' </summary>
Public WriteOnly Property Tags As Object
Set(value As Object)
Dim list As New List(Of String)
If TypeOf (value) Is String Then
list = CType(value, String).Split("|").ToList()
End If
If TypeOf (value) Is List(Of String) Then
list = CType(value, List(Of String))
End If
PanTags.Children.Clear()
PanTags.Visibility = If(list.Any(), Visibility.Visible, Visibility.Collapsed)
For Each TagText In list
Dim NewTag As New Border With {
.Background = New SolidColorBrush(Color.FromArgb(17, 0, 0, 0)),
.Padding = New Thickness(3, 1, 3, 1),
.CornerRadius = New CornerRadius(3),
.Margin = New Thickness(0, 0, 3, 0),
.SnapsToDevicePixels = True,
.UseLayoutRounding = False
}
Dim TagTextBlock As New TextBlock With {
.Text = TagText,
.Foreground = New SolidColorBrush(Color.FromRgb(134, 134, 134)),
.FontSize = 11
}
NewTag.Child = TagTextBlock
PanTags.Children.Add(NewTag)
Next
End Set
End Property

'副文本
Private _LabInfo As TextBlock = Nothing
Public ReadOnly Property LabInfo As TextBlock
Expand All @@ -63,9 +119,9 @@
.Margin = New Thickness(4, 0, 0, 0),
.Opacity = 0.6
}
SetColumn(Lab, 3)
SetColumn(Lab, 4)
SetRow(Lab, 2)
Children.Add(Lab)
PanBack.Children.Add(Lab)
_LabInfo = Lab
'<TextBlock Grid.Row="2" SnapsToDevicePixels="False" UseLayoutRounding="False" HorizontalAlignment="Left" x:Name = "LabInfo" IsHitTestVisible="False" Grid.Column="2"
'TextTrimming = "CharacterEllipsis" Visibility="Collapsed" FontSize="12" Foreground="{StaticResource ColorBrushGray2}" Margin="4,0,0,0" />
Expand Down
68 changes: 48 additions & 20 deletions Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,13 @@
NewItem.LabDownload.Text = GetLocationNum(DownloadCount)
Return NewItem
End Function
Public Function ToMiniCompItem() As MyMiniCompItem
Dim Result As New MyMiniCompItem()
Public Function ToListItem() As MyListItem
Dim Result As New MyListItem()
Result.Title = TranslatedName
Result.Description = Description.Replace(vbCr, "").Replace(vbLf, "")
Result.Info = Description.Replace(vbCr, "").Replace(vbLf, "")
Result.Logo = LogoUrl
Result.Tags = Tags
Result.Entry = Me
Result.Tag = Me
Return Result
End Function
Public Function GetControlLogo() As String
Expand Down Expand Up @@ -1625,41 +1625,38 @@ Retry:
Public Shared Function GetAllCompProjects(Input As List(Of String)) As List(Of CompProject)
If Not Input.Any() Then Return New List(Of CompProject)
Dim RawList As List(Of String) = Input
Dim ModrinthProjectIds As List(Of String)
Dim CurseForgeProjectIds As List(Of String)
Dim ModrinthProjectIds As New List(Of String)
Dim CurseForgeProjectIds As New List(Of String)
Dim Res As List(Of CompProject) = New List(Of CompProject)
CurseForgeProjectIds = RawList.Where(Function(e) IsFromCurseForge(e)).ToList()
ModrinthProjectIds = RawList.Where(Function(e) Not IsFromCurseForge(e)).ToList()
Dim RawProjectsData As JArray
For Each Id In RawList
If IsFromCurseForge(Id) Then
CurseForgeProjectIds.Add(Id)
Else
ModrinthProjectIds.Add(Id)
End If
Next
'在线信息获取
Dim FinishedTask = 0
Dim NeedCompleteTask = 0
If CurseForgeProjectIds.Any() Then
NeedCompleteTask += 1
RunInNewThread(Sub()
Try
RawProjectsData = GetJson(DlModRequest("https://api.curseforge.com/v1/mods",
"POST", "{""modIds"": [" & CurseForgeProjectIds.Join(",") & "]}", "application/json"))("data")
For Each RawData In RawProjectsData
Res.Add(New CompProject(RawData))
Next
Res.AddRange(CompRequest.GetListByIdsFromCurseforge(CurseForgeProjectIds))
FinishedTask += 1
Catch ex As Exception
Log(ex, "[Favorites] 获取 CurseForge 数据失败")
Log(ex, "[Favorites] 获取 CurseForge 数据失败", LogLevel.Hint)
End Try
End Sub, "Favorites CurseForge")
End If
If ModrinthProjectIds.Any() Then
NeedCompleteTask += 1
RunInNewThread(Sub()
Try
RawProjectsData = DlModRequest($"https://api.modrinth.com/v2/projects?ids=[""{ModrinthProjectIds.Join(""",""")}""]", IsJson:=True)
For Each RawData In RawProjectsData
Res.Add(New CompProject(RawData))
Next
Res.AddRange(CompRequest.GetListByIdsFromModrinth(ModrinthProjectIds))
FinishedTask += 1
Catch ex As Exception
Log(ex, "[Favorites] 获取 Modrinth 数据失败")
Log(ex, "[Favorites] 获取 Modrinth 数据失败", LogLevel.Hint)
End Try
End Sub, "Favorites Modrinth")
End If
Expand All @@ -1676,4 +1673,35 @@ Retry:
Public Shared FavoritesList As List(Of String)

End Class

Class CompRequest
''' <summary>
''' 通过一堆 ID 从 Modrinth 那获取项目信息
''' </summary>
''' <param name="Ids"></param>
''' <returns></returns>
Public Shared Function GetListByIdsFromModrinth(Ids As List(Of String)) As List(Of CompProject)
Dim Res As New List(Of CompProject)
Dim RawProjectsData = DlModRequest($"https://api.modrinth.com/v2/projects?ids=[""{Ids.Join(""",""")}""]", IsJson:=True)
For Each RawData In RawProjectsData
Res.Add(New CompProject(RawData))
Next
Return Res
End Function

''' <summary>
''' 通过一堆 ID 从 CurseForge 那获取项目信息
''' </summary>
''' <param name="Ids"></param>
''' <returns></returns>
Public Shared Function GetListByIdsFromCurseforge(Ids As List(Of String)) As List(Of CompProject)
Dim Res As New List(Of CompProject)
Dim RawProjectsData = GetJson(DlModRequest("https://api.curseforge.com/v1/mods",
"POST", "{""modIds"": [" & Ids.Join(",") & "]}", "application/json"))("data")
For Each RawData In RawProjectsData
Res.Add(New CompProject(RawData))
Next
Return Res
End Function
End Class
End Module
52 changes: 0 additions & 52 deletions Plain Craft Launcher 2/Modules/Minecraft/MyMiniCompItem.xaml

This file was deleted.

Loading

0 comments on commit c3bd25a

Please sign in to comment.