Skip to content

Commit

Permalink
feat: 批量操作(需要优化)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangge233 committed Oct 16, 2024
1 parent 3c177f9 commit 289698b
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Public Class MyMiniCompItem
Anim.Add(AaHeight(RectCheck, -RectCheck.ActualHeight, 120,, New AniEaseInFluent(AniEasePower.Weak)))
Anim.Add(AaOpacity(RectCheck, -RectCheck.Opacity, 70, 40))
RectCheck.VerticalAlignment = VerticalAlignment.Center
Anim.Add(AaColor(LabTitle, TextBlock.ForegroundProperty, If(LabTitle.TextDecorations Is Nothing, "ColorBrush1", "ColorBrushGray4"), 120))
Anim.Add(AaColor(LabTitle, TextBlock.ForegroundProperty, "ColorBrush1", 120))
End If
AniStart(Anim, "MyMiniCompItem Checked " & Uuid)
Else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
<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>
<local:MyCard x:Name="CardSelect" Visibility="Collapsed" Opacity="0"
HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="25,25,25,0" UseAnimation="False" HasMouseAnimation="False">
<local:MyCard.RenderTransform>
<TranslateTransform x:Name="TransSelect" Y="-10" />
</local:MyCard.RenderTransform>
<TextBlock x:Name="LabSelect" Text="已选择 8 个文件" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="9" Foreground="{DynamicResource ColorBrush2}" />
<StackPanel Orientation="Horizontal" Margin="5,28,5,5">
<local:MyIconTextButton x:Name="Btn_FavoritesCancel" Text="取消收藏"
LogoScale="1" Logo="M700.856 155.543c-74.769 0-144.295 72.696-190.046 127.26-45.737-54.576-115.247-127.26-190.056-127.26-134.79 0-244.443 105.78-244.443 235.799 0 77.57 39.278 131.988 70.845 175.713C238.908 694.053 469.62 852.094 479.39 858.757c9.41 6.414 20.424 9.629 31.401 9.629 11.006 0 21.998-3.215 31.398-9.63 9.782-6.662 240.514-164.703 332.238-291.701 31.587-43.724 70.874-98.143 70.874-175.713-0.001-130.02-109.656-235.8-244.445-235.8z m0 0" />
<local:MyIconTextButton x:Name="Btn_SelectCancel" Text="取消选择"
LogoScale="0.8" Logo="M867.648 951.296 512 595.648l-355.648 355.648c-11.52 11.52-30.272 11.52-41.856 0L72.64 909.44c-11.52-11.52-11.52-30.272 0-41.856L428.352 512 72.64 156.352c-11.52-11.52-11.52-30.272 0-41.856l41.856-41.856c11.52-11.52 30.272-11.52 41.856 0L512 428.288l355.648-355.648c11.52-11.52 30.272-11.52 41.856 0l41.856 41.856c11.52 11.52 11.52 30.272 0 41.856L595.648 512l355.648 355.648c11.52 11.52 11.52 30.272 0 41.856l-41.856 41.856C897.984 962.88 879.168 962.88 867.648 951.296L867.648 951.296z" />
</StackPanel>
</local:MyCard>
</Grid>
</local:MyScrollViewer>
</local:MyPageRight>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Public Class PageDownloadCompFavorites

#Region "加载器信息"
'加载器信息
Public Shared Loader As New LoaderTask(Of List(Of String), List(Of CompProject))("CompProject Favorites", AddressOf CompFavoritesGet, AddressOf LoaderInput)

Expand All @@ -18,10 +19,12 @@
Private Shared Sub CompFavoritesGet(Task As LoaderTask(Of List(Of String), List(Of CompProject)))
Task.Output = CompFavorites.GetAllCompProjects(Task.Input)
End Sub
#End Region

Private CompItemList As New List(Of MyMiniCompItem)
Private SelectedItemList As New List(Of MyMiniCompItem)

#Region "UI 化"
'结果 UI 化
Private Sub Load_OnFinish()
CompItemList.Clear()
Expand All @@ -37,11 +40,10 @@
ToolTipService.SetVerticalOffset(Btn_Delete, 30)
ToolTipService.SetHorizontalOffset(Btn_Delete, 2)
AddHandler Btn_Delete.Click, Sub(sender As Object, e As EventArgs)
If CompItem Is Nothing Then Exit Sub
If CompFavorites.Del(CompItem.Entry.Id) Then Hint($"已取消收藏 {CompItem.Entry.TranslatedName}!", HintType.Finish)
CompItemList.Remove(CompItem)
Items_CancelFavorites(CompItem)
RefreshContent()
RefreshCardTitle()
RefreshBar()
End Sub
CompItem.Buttons = {Btn_Delete}
'---操作逻辑---
Expand All @@ -50,7 +52,8 @@
FrmMain.PageChange(New FormMain.PageStackData With {.Page = FormMain.PageType.CompDetail,
.Additional = {CompItem.Entry, New List(Of String), String.Empty, CompModLoaderType.Any}})
End Sub

'---其它事件---
AddHandler CompItem.Changed, AddressOf ItemCheckStatusChanged
CompItemList.Add(CompItem)
Next
Try
Expand Down Expand Up @@ -99,19 +102,79 @@
End Sub

Private Sub RefreshCardTitle()
Dim ModRes As Integer = 0
Dim ModpackRes As Integer = 0
If IsSearching Then
ModRes = PanProjectsMod.Children.Count
CardProjectsMod.Title = $"搜索结果 ({ModRes})"
CardProjectsMod.Title = $"搜索结果 ({SearchResult.Count})"
Else
ModRes = If(Loader.Output.Exists(Function(e) e.Type = CompType.Mod), PanProjectsMod.Children.Count, 0)
Dim ModRes As Integer = 0
Dim ModpackRes As Integer = 0
ModRes = CompItemList.Where(Function(e) e.Entry.Type.Equals(CompType.Mod)).Count()
CardProjectsMod.Title = $"Mod ({ModRes})"
ModpackRes = If(Loader.Output.Exists(Function(e) e.Type = CompType.ModPack), PanProjectsModpack.Children.Count, 0)
ModpackRes = CompItemList.Where(Function(e) e.Entry.Type.Equals(CompType.ModPack)).Count()
CardProjectsModpack.Title = $"整合包 ({ModpackRes})"
End If
End Sub

Private BottomBarShownCount As Integer = 0

Private Sub RefreshBar()
Dim NewCount As Integer = SelectedItemList.Count
Dim Selected = NewCount > 0
If Selected Then LabSelect.Text = $"已选择 {NewCount} 个收藏项目" '取消所有选择时不更新数字
'更新显示状态
If AniControlEnabled = 0 Then
CardProjectsModpack.Margin = New Thickness(0, 0, 0, If(Selected, 95, 15))
If Selected Then
'仅在数量增加时播放出现/跳跃动画
If BottomBarShownCount >= NewCount Then
BottomBarShownCount = NewCount
Return
Else
BottomBarShownCount = NewCount
End If
'出现/跳跃动画
CardSelect.Visibility = Visibility.Visible
AniStart({
AaOpacity(CardSelect, 1 - CardSelect.Opacity, 60),
AaTranslateY(CardSelect, -27 - TransSelect.Y, 120, Ease:=New AniEaseOutFluent(AniEasePower.Weak)),
AaTranslateY(CardSelect, 3, 150, 120, Ease:=New AniEaseInoutFluent(AniEasePower.Weak)),
AaTranslateY(CardSelect, -1, 90, 270, Ease:=New AniEaseInoutFluent(AniEasePower.Weak))
}, "CompFavorites Sidebar")
Else
'不重复播放隐藏动画
If BottomBarShownCount = 0 Then Return
BottomBarShownCount = 0
'隐藏动画
AniStart({
AaOpacity(CardSelect, -CardSelect.Opacity, 90),
AaTranslateY(CardSelect, -10 - TransSelect.Y, 90, Ease:=New AniEaseInFluent(AniEasePower.Weak)),
AaCode(Sub() CardSelect.Visibility = Visibility.Collapsed, After:=True)
}, "CompFavorites Sidebar")
End If
Else
AniStop("CompFavorites Sidebar")
BottomBarShownCount = NewCount
If Selected Then
CardSelect.Visibility = Visibility.Visible
CardSelect.Opacity = 1
TransSelect.Y = -25
Else
CardSelect.Visibility = Visibility.Collapsed
CardSelect.Opacity = 0
TransSelect.Y = -10
End If
End If
End Sub

#End Region

'选中状态改变
Private Sub ItemCheckStatusChanged(sender As Object, e As RouteEventArgs)
Dim SenderItem As MyMiniCompItem = sender
If SelectedItemList.Contains(SenderItem) Then SelectedItemList.Remove(SenderItem)
If SenderItem.Checked Then SelectedItemList.Add(SenderItem)
RefreshBar()
End Sub

'自动重试
Private Sub Load_State(sender As Object, state As MyLoading.MyLoadingState, oldState As MyLoading.MyLoadingState) Handles Load.StateChanged
Select Case Loader.State
Expand All @@ -125,6 +188,33 @@
End Select
End Sub

Private Sub Btn_FavoritesCancel_Clicked(sender As Object, e As RouteEventArgs) Handles Btn_FavoritesCancel.Click
For Each Items In SelectedItemList.Clone()
Items_CancelFavorites(Items)
Next
RefreshContent()
RefreshCardTitle()
RefreshBar()
End Sub

Private Sub Btn_SelectCancel_Clicked(sender As Object, e As RouteEventArgs) Handles Btn_SelectCancel.Click
SelectedItemList.Clear()
Items_SetSelectAll(False)
End Sub

Private Sub Items_SetSelectAll(TargetStatus As Boolean)
For Each item In CompItemList
item.Checked = TargetStatus
Next
SelectedItemList = CompItemList.Where(Function(e) e.Checked).ToList()
End Sub

Private Sub Items_CancelFavorites(Item As MyMiniCompItem)
CompItemList.Remove(Item)
If SelectedItemList.Contains(Item) Then SelectedItemList.Remove(Item)
If SearchResult.Contains(Item) Then SearchResult.Remove(Item)
CompFavorites.Del(Item.Entry.Id)
End Sub

#Region "搜索"

Expand Down

0 comments on commit 289698b

Please sign in to comment.