Skip to content

Commit

Permalink
Merge branch 'main' into quilt
Browse files Browse the repository at this point in the history
  • Loading branch information
Pigeon0v0 authored Dec 21, 2024
2 parents 0e886f1 + e2acdb6 commit daac545
Show file tree
Hide file tree
Showing 16 changed files with 638 additions and 40 deletions.
82 changes: 65 additions & 17 deletions Plain Craft Launcher 2/Controls/MyHint.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
Set(value As Boolean)
If _IsWarn = value Then Exit Property
_IsWarn = value
If _IsWarn Then
BorderBrush = New MyColor("#CCFF4444")
Gradient1.Color = New MyColor("#BBFFBBBB")
Gradient2.Color = New MyColor("#BBFF8888")
Path.Fill = New MyColor("#BF0000")
LabText.Foreground = New MyColor("#BF0000")
BtnClose.Foreground = New MyColor("#BF0000")
Path.Data = (New GeometryConverter).ConvertFromString("F1 M 58.5832,55.4172L 17.4169,55.4171C 15.5619,53.5621 15.5619,50.5546 17.4168,48.6996L 35.201,15.8402C 37.056,13.9852 40.0635,13.9852 41.9185,15.8402L 58.5832,48.6997C 60.4382,50.5546 60.4382,53.5622 58.5832,55.4172 Z M 34.0417,25.7292L 36.0208,41.9584L 39.9791,41.9583L 41.9583,25.7292L 34.0417,25.7292 Z M 38,44.3333C 36.2511,44.3333 34.8333,45.7511 34.8333,47.5C 34.8333,49.2489 36.2511,50.6667 38,50.6667C 39.7489,50.6667 41.1666,49.2489 41.1666,47.5C 41.1666,45.7511 39.7489,44.3333 38,44.3333 Z ")
Else
BorderBrush = New MyColor("#CC4D76FF")
Gradient1.Color = New MyColor("#BBB0D0FF")
Gradient2.Color = New MyColor("#BB9EBAFF")
Path.Fill = New MyColor("#0062BF")
LabText.Foreground = New MyColor("#0062BF")
BtnClose.Foreground = New MyColor("#0062BF")
Path.Data = (New GeometryConverter).ConvertFromString("F1M38,19C48.4934,19 57,27.5066 57,38 57,48.4934 48.4934,57 38,57 27.5066,57 19,48.4934 19,38 19,27.5066 27.5066,19 38,19z M33.25,33.25L33.25,36.4167 36.4166,36.4167 36.4166,47.5 33.25,47.5 33.25,50.6667 44.3333,50.6667 44.3333,47.5 41.1666,47.5 41.1666,36.4167 41.1666,33.25 33.25,33.25z M38.7917,25.3333C37.48,25.3333 36.4167,26.3967 36.4167,27.7083 36.4167,29.02 37.48,30.0833 38.7917,30.0833 40.1033,30.0833 41.1667,29.02 41.1667,27.7083 41.1667,26.3967 40.1033,25.3333 38.7917,25.3333z")
End If
SetStyle()
End Set
End Property

Public Enum HintType
Note
Warning
Caution
End Enum
Private _Type As HintType = HintType.Note
Public Property Type As HintType
Get
Return _Type
End Get
Set(value As HintType)
_Type = value
SetStyle()
End Set
End Property

Expand Down Expand Up @@ -93,6 +93,54 @@
End Property
Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyHint), New PropertyMetadata(Nothing))

Private Sub SetStyle()
If Type = HintType.Note Then
If IsWarn Then
BorderBrush = New MyColor("#CCFF4444")
Gradient1.Color = New MyColor("#BBFFBBBB")
Gradient2.Color = New MyColor("#BBFF8888")
Path.Fill = New MyColor("#BF0000")
LabText.Foreground = New MyColor("#BF0000")
BtnClose.Foreground = New MyColor("#BF0000")
Path.Data = (New GeometryConverter).ConvertFromString("F1 M 58.5832,55.4172L 17.4169,55.4171C 15.5619,53.5621 15.5619,50.5546 17.4168,48.6996L 35.201,15.8402C 37.056,13.9852 40.0635,13.9852 41.9185,15.8402L 58.5832,48.6997C 60.4382,50.5546 60.4382,53.5622 58.5832,55.4172 Z M 34.0417,25.7292L 36.0208,41.9584L 39.9791,41.9583L 41.9583,25.7292L 34.0417,25.7292 Z M 38,44.3333C 36.2511,44.3333 34.8333,45.7511 34.8333,47.5C 34.8333,49.2489 36.2511,50.6667 38,50.6667C 39.7489,50.6667 41.1666,49.2489 41.1666,47.5C 41.1666,45.7511 39.7489,44.3333 38,44.3333 Z ")
Else
BorderBrush = New MyColor("#CC4D76FF")
Gradient1.Color = New MyColor("#BBB0D0FF")
Gradient2.Color = New MyColor("#BB9EBAFF")
Path.Fill = New MyColor("#0062BF")
LabText.Foreground = New MyColor("#0062BF")
BtnClose.Foreground = New MyColor("#0062BF")
Path.Data = (New GeometryConverter).ConvertFromString("F1M38,19C48.4934,19 57,27.5066 57,38 57,48.4934 48.4934,57 38,57 27.5066,57 19,48.4934 19,38 19,27.5066 27.5066,19 38,19z M33.25,33.25L33.25,36.4167 36.4166,36.4167 36.4166,47.5 33.25,47.5 33.25,50.6667 44.3333,50.6667 44.3333,47.5 41.1666,47.5 41.1666,36.4167 41.1666,33.25 33.25,33.25z M38.7917,25.3333C37.48,25.3333 36.4167,26.3967 36.4167,27.7083 36.4167,29.02 37.48,30.0833 38.7917,30.0833 40.1033,30.0833 41.1667,29.02 41.1667,27.7083 41.1667,26.3967 40.1033,25.3333 38.7917,25.3333z")
End If
End If

Select Case Type
Case HintType.Warning
BorderBrush = New MyColor("#CCE69900")
Gradient1.Color = New MyColor("#BBFFF4CE")
Gradient2.Color = New MyColor("#BBFFF5CE")
Path.Fill = New MyColor("#957500")
LabText.Foreground = New MyColor("#957500")
BtnClose.Foreground = New MyColor("#957500")
Path.Data = (New GeometryConverter).ConvertFromString("F1 M 58.5832,55.4172L 17.4169,55.4171C 15.5619,53.5621 15.5619,50.5546 17.4168,48.6996L 35.201,15.8402C 37.056,13.9852 40.0635,13.9852 41.9185,15.8402L 58.5832,48.6997C 60.4382,50.5546 60.4382,53.5622 58.5832,55.4172 Z M 34.0417,25.7292L 36.0208,41.9584L 39.9791,41.9583L 41.9583,25.7292L 34.0417,25.7292 Z M 38,44.3333C 36.2511,44.3333 34.8333,45.7511 34.8333,47.5C 34.8333,49.2489 36.2511,50.6667 38,50.6667C 39.7489,50.6667 41.1666,49.2489 41.1666,47.5C 41.1666,45.7511 39.7489,44.3333 38,44.3333 Z ")
Case HintType.Caution
BorderBrush = New MyColor("#CCFF4444")
Gradient1.Color = New MyColor("#BBFFBBBB")
Gradient2.Color = New MyColor("#BBFF8888")
Path.Fill = New MyColor("#BF0000")
LabText.Foreground = New MyColor("#BF0000")
BtnClose.Foreground = New MyColor("#BF0000")
Path.Data = (New GeometryConverter).ConvertFromString("F1 M1024,1024z M0,0z M512,0C229.23,0 0,229.23 0,512 0,794.77 229.23,1024 512,1024 794.768,1024 1024,794.77 1024,512 1024,229.23 794.77,0 512,0z M746.76,656.252C754.568,664.06,754.566,676.724,746.762,684.536L684.534,746.76C676.726,754.568,664.064,754.574,656.248,746.762L512,602.51 367.75,746.76C359.94,754.572,347.276,754.568,339.466,746.76L277.24,684.536C269.43,676.728,269.428,664.064,277.24,656.252L421.492,512 277.242,367.75C269.432,359.942,269.432,347.276,277.242,339.466L339.468,277.242C347.278,269.43,359.942,269.432,367.752,277.242L512,421.49 656.252,277.24C664.058,269.428,676.722,269.43,684.534,277.24L746.76,339.464C754.566,347.276,754.568,359.938,746.76,367.748L602.51,512 746.76,656.252z")
Case Else
BorderBrush = New MyColor("#CC4D76FF")
Gradient1.Color = New MyColor("#BBB0D0FF")
Gradient2.Color = New MyColor("#BB9EBAFF")
Path.Fill = New MyColor("#0062BF")
LabText.Foreground = New MyColor("#0062BF")
BtnClose.Foreground = New MyColor("#0062BF")
Path.Data = (New GeometryConverter).ConvertFromString("F1M38,19C48.4934,19 57,27.5066 57,38 57,48.4934 48.4934,57 38,57 27.5066,57 19,48.4934 19,38 19,27.5066 27.5066,19 38,19z M33.25,33.25L33.25,36.4167 36.4166,36.4167 36.4166,47.5 33.25,47.5 33.25,50.6667 44.3333,50.6667 44.3333,47.5 41.1666,47.5 41.1666,36.4167 41.1666,33.25 33.25,33.25z M38.7917,25.3333C37.48,25.3333 36.4167,26.3967 36.4167,27.7083 36.4167,29.02 37.48,30.0833 38.7917,30.0833 40.1033,30.0833 41.1667,29.02 41.1667,27.7083 41.1667,26.3967 40.1033,25.3333 38.7917,25.3333z")
End Select
End Sub
End Class
Partial Public Module ModAnimation
Public Sub AniDispose(Control As MyHint, RemoveFromChildren As Boolean, Optional CallBack As ParameterizedThreadStart = Nothing)
Expand Down
12 changes: 10 additions & 2 deletions Plain Craft Launcher 2/Controls/MyListItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ColumnDefinition x:Name="ColumnCheck" Width="2"/>
<ColumnDefinition x:Name="ColumnPaddingLeft" Width="0" />
<ColumnDefinition x:Name="ColumnLogo" Width="4" />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition x:Name="ColumnPaddingRight" Width="4" />
</Grid.ColumnDefinitions>
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
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 @@ -965,6 +965,7 @@ Public Class FormMain
DownloadLiteLoader = 9
DownloadMod = 11
DownloadPack = 12
DownloadCompFavorites = 13
SetupLaunch = 0
SetupUI = 1
SetupSystem = 2
Expand Down
119 changes: 119 additions & 0 deletions Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@
If(DownloadCount > 100000, Math.Floor(DownloadCount / 10000) & " 万", DownloadCount))
Return NewItem
End Function
Public Function ToListItem() As MyListItem
Dim Result As New MyListItem()
Result.Title = TranslatedName
Result.Info = Description.Replace(vbCr, "").Replace(vbLf, "")
Result.Logo = LogoUrl
Result.Tags = Tags
Result.Tag = Me
Return Result
End Function
Public Function GetControlLogo() As String
If String.IsNullOrEmpty(LogoUrl) Then
Return PathImage & "Icons/NoIcon.png"
Expand Down Expand Up @@ -1516,5 +1525,115 @@ Retry:
End Sub

#End Region
Class CompFavorites

''' <summary>
''' 收藏的工程列表
''' </summary>
Private Shared _FavoritesList As List(Of String) = Nothing
Public Shared Property FavoritesList As List(Of String)
Get
If _FavoritesList Is Nothing Then
Dim RawData As String = Setup.Get("CompFavorites")
Dim RawList As JArray = JArray.Parse(RawData)
_FavoritesList = RawList.ToObject(Of List(Of String))()
End If
Return _FavoritesList
End Get
Set
_FavoritesList = Value
Dim RawList As New JArray
For Each item In _FavoritesList
RawList.Add(item)
Next
Setup.Set("CompFavorites", RawList.ToString())
End Set
End Property

End Class

Class CompRequest
''' <summary>
''' 通过项目 Id 判断是否来自 CurseForge
''' </summary>
''' <param name="Id"></param>
''' <returns></returns>
Public Shared Function IsFromCurseForge(Id As String) As Boolean
Dim res As Integer = 0
Return Integer.TryParse(Id, res) 'CurseForge 数字 ID Modrinth 乱序 ID
End Function

''' <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

Public Shared Function GetCompProjectsByIds(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 New List(Of String)
Dim CurseForgeProjectIds As New List(Of String)
Dim Res As List(Of CompProject) = New List(Of CompProject)
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
Res.AddRange(CompRequest.GetListByIdsFromCurseforge(CurseForgeProjectIds))
FinishedTask += 1
Catch ex As Exception
Log(ex, "[Favorites] 获取 CurseForge 数据失败", LogLevel.Hint)
End Try
End Sub, "Favorites CurseForge")
End If
If ModrinthProjectIds.Any() Then
NeedCompleteTask += 1
RunInNewThread(Sub()
Try
Res.AddRange(CompRequest.GetListByIdsFromModrinth(ModrinthProjectIds))
FinishedTask += 1
Catch ex As Exception
Log(ex, "[Favorites] 获取 Modrinth 数据失败", LogLevel.Hint)
End Try
End Sub, "Favorites Modrinth")
End If
Do Until FinishedTask = NeedCompleteTask
Thread.Sleep(50)
Loop
Return Res
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 @@ -108,6 +108,9 @@
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
Loading

0 comments on commit daac545

Please sign in to comment.