MyCompItem.xaml.vb 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. Public Class MyCompItem
  2. #Region "基础属性"
  3. Public Uuid As Integer = GetUuid()
  4. '标题
  5. Public Property Title As String
  6. Get
  7. Return LabTitle.Text
  8. End Get
  9. Set(value As String)
  10. If LabTitle.Text = value Then Return
  11. LabTitle.Text = value
  12. End Set
  13. End Property
  14. '副标题
  15. Public Property SubTitle As String
  16. Get
  17. Return If(LabTitleRaw?.Text, "")
  18. End Get
  19. Set(value As String)
  20. If LabTitleRaw.Text = value Then Return
  21. LabTitleRaw.Text = value
  22. LabTitleRaw.Visibility = If(value = "", Visibility.Collapsed, Visibility.Visible)
  23. End Set
  24. End Property
  25. '描述
  26. Public Property Description As String
  27. Get
  28. Return LabInfo.Text
  29. End Get
  30. Set(value As String)
  31. If LabInfo.Text = value Then Return
  32. LabInfo.Text = value
  33. End Set
  34. End Property
  35. '指向时扩展描述
  36. Private Sub LabInfo_MouseEnter(sender As Object, e As MouseEventArgs) Handles LabInfo.MouseEnter
  37. If IsTextTrimmed(LabInfo) Then
  38. ToolTipInfo.Content = LabInfo.Text
  39. ToolTipInfo.Width = LabInfo.ActualWidth + 25
  40. LabInfo.ToolTip = ToolTipInfo
  41. Else
  42. LabInfo.ToolTip = Nothing
  43. End If
  44. End Sub
  45. Private Function IsTextTrimmed(textBlock As TextBlock) As Boolean
  46. Dim typeface As New Typeface(textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch)
  47. Dim formattedText As New FormattedText(textBlock.Text, Thread.CurrentThread.CurrentCulture, textBlock.FlowDirection, typeface, textBlock.FontSize, textBlock.Foreground, DPI)
  48. Return formattedText.Width > textBlock.ActualWidth
  49. End Function
  50. 'Tag
  51. Public WriteOnly Property Tags As List(Of String)
  52. Set(Tags As List(Of String))
  53. PanTags.Children.Clear()
  54. PanTags.Visibility = If(Tags.Any(), Visibility.Visible, Visibility.Collapsed)
  55. For Each TagText In Tags
  56. Dim BorderTag As New Border With {
  57. .Background = New MyColor("#11000000"), .Padding = New Thickness(3, 1, 3, 1), .CornerRadius = New CornerRadius(3),
  58. .Margin = New Thickness(0, 0, 3, 0), .SnapsToDevicePixels = True, .UseLayoutRounding = False}
  59. Dim LabTag As New TextBlock With {
  60. .Text = TagText, .Foreground = New MyColor("#868686"), .FontSize = 11}
  61. BorderTag.Child = LabTag
  62. PanTags.Children.Add(BorderTag)
  63. Next
  64. End Set
  65. End Property
  66. #End Region
  67. #Region "点击"
  68. '触发点击事件
  69. Public Event Click(sender As Object, e As MouseButtonEventArgs)
  70. Private Sub Button_MouseUp(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseLeftButtonUp
  71. If IsMouseDown Then
  72. RaiseEvent Click(sender, e)
  73. If e.Handled Then Return
  74. Log("[Control] 按下资源工程列表项:" & LabTitle.Text)
  75. End If
  76. End Sub
  77. Private Sub MyCompItem_Click(sender As MyCompItem, e As EventArgs) Handles Me.Click
  78. '记录当前展开的卡片标题(#2712)
  79. Dim Titles As New List(Of String)
  80. If FrmMain.PageCurrent.Page = FormMain.PageType.CompDetail Then
  81. For Each Card As MyCard In FrmDownloadCompDetail.PanResults.Children
  82. If Card.Title <> "" AndAlso Not Card.IsSwapped Then Titles.Add(Card.Title)
  83. Next
  84. Log("[Comp] 记录当前已展开的卡片:" & String.Join("、", Titles))
  85. FrmMain.PageCurrent.Additional(1) = Titles
  86. End If
  87. '打开详情页
  88. Dim TargetType As CompType
  89. Dim TargetVersion As String = Nothing
  90. Dim TargetLoader As CompModLoaderType = CompModLoaderType.Any
  91. If FrmMain.PageCurrent.Page = FormMain.PageType.Download Then
  92. '从下载页进入
  93. Select Case FrmMain.PageCurrentSub
  94. Case FormMain.PageSubType.DownloadMod
  95. TargetType = CompType.Mod
  96. TargetVersion = FrmDownloadMod.Content.Loader.Input.GameVersion
  97. TargetLoader = FrmDownloadMod.Content.Loader.Input.ModLoader
  98. Case FormMain.PageSubType.DownloadPack
  99. TargetType = CompType.ModPack
  100. TargetVersion = FrmDownloadPack.Content.Loader.Input.GameVersion
  101. Case FormMain.PageSubType.DownloadDataPack
  102. TargetType = CompType.DataPack
  103. TargetVersion = FrmDownloadDataPack.Content.Loader.Input.GameVersion
  104. Case FormMain.PageSubType.DownloadResourcePack
  105. TargetType = CompType.ResourcePack
  106. TargetVersion = FrmDownloadResourcePack.Content.Loader.Input.GameVersion
  107. Case FormMain.PageSubType.DownloadShader
  108. TargetType = CompType.Shader
  109. TargetVersion = FrmDownloadShader.Content.Loader.Input.GameVersion
  110. End Select
  111. Else
  112. '从详情页进入(查看前置)
  113. TargetType = CompType.Any '允许任意类别
  114. TargetVersion = FrmMain.PageCurrent.Additional(2)
  115. TargetLoader = FrmMain.PageCurrent.Additional(3)
  116. End If
  117. FrmMain.PageChange(New FormMain.PageStackData With {.Page = FormMain.PageType.CompDetail,
  118. .Additional = {sender.Tag, New List(Of String), TargetVersion, TargetLoader, TargetType}})
  119. End Sub
  120. '鼠标点击判定
  121. Private IsMouseDown As Boolean = False
  122. Private Sub Button_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseLeftButtonDown
  123. If IsMouseOver AndAlso CanInteraction Then IsMouseDown = True
  124. End Sub
  125. Private Sub Button_MouseLeave(sender As Object, e As Object) Handles Me.MouseLeave, Me.PreviewMouseLeftButtonUp
  126. IsMouseDown = False
  127. End Sub
  128. #End Region
  129. #Region "后加载指向背景"
  130. Private _RectBack As Border = Nothing
  131. Public ReadOnly Property RectBack As Border
  132. Get
  133. If _RectBack Is Nothing Then
  134. Dim Rect As New Border With {
  135. .Name = "RectBack",
  136. .CornerRadius = New CornerRadius(3),
  137. .RenderTransform = New ScaleTransform(0.8, 0.8),
  138. .RenderTransformOrigin = New Point(0.5, 0.5),
  139. .BorderThickness = New Thickness(GetWPFSize(1)),
  140. .SnapsToDevicePixels = True,
  141. .IsHitTestVisible = False,
  142. .Opacity = 0
  143. }
  144. Rect.SetResourceReference(Border.BackgroundProperty, "ColorBrush7")
  145. Rect.SetResourceReference(Border.BorderBrushProperty, "ColorBrush6")
  146. SetColumnSpan(Rect, 999)
  147. SetRowSpan(Rect, 999)
  148. Children.Insert(0, Rect)
  149. _RectBack = Rect
  150. '<!--<Border x:Name = "RectBack" CornerRadius="3" RenderTransformOrigin="0.5,0.5" SnapsToDevicePixels="True"
  151. 'IsHitTestVisible = "False" Opacity="0" BorderThickness="1"
  152. 'Grid.ColumnSpan = "4" Background="{DynamicResource ColorBrush7}" BorderBrush="{DynamicResource ColorBrush6}"/>-->
  153. End If
  154. Return _RectBack
  155. End Get
  156. End Property
  157. #End Region
  158. Private StateLast As String
  159. ''' <summary>
  160. ''' 是否允许交互。目前仅用于 PageDownloadCompDetail 的顶部栏展示:若关闭碰撞检测,则无法展开 Tooltip。
  161. ''' </summary>
  162. Public Property CanInteraction As Boolean = True
  163. Public Sub RefreshColor(sender As Object, e As EventArgs) Handles Me.MouseEnter, Me.MouseLeave, Me.MouseLeftButtonDown, Me.MouseLeftButtonUp
  164. If Not CanInteraction Then Return
  165. '判断当前颜色
  166. Dim StateNew As String, Time As Integer
  167. If IsMouseOver Then
  168. If IsMouseDown Then
  169. StateNew = "MouseDown"
  170. Time = 120
  171. Else
  172. StateNew = "MouseOver"
  173. Time = 120
  174. End If
  175. Else
  176. StateNew = "Idle"
  177. Time = 180
  178. End If
  179. If StateLast = StateNew Then Return
  180. StateLast = StateNew
  181. '触发颜色动画
  182. If IsLoaded AndAlso AniControlEnabled = 0 Then '防止默认属性变更触发动画
  183. '有动画
  184. Dim Ani As New List(Of AniData)
  185. If IsMouseOver Then
  186. Ani.AddRange({
  187. AaColor(RectBack, Border.BackgroundProperty, If(IsMouseDown, "ColorBrush6", "ColorBrushBg1"), Time),
  188. AaOpacity(RectBack, 1 - RectBack.Opacity, Time,, New AniEaseOutFluent)
  189. })
  190. If IsMouseDown Then
  191. Ani.Add(AaScaleTransform(RectBack, 0.996 - CType(RectBack.RenderTransform, ScaleTransform).ScaleX, Time * 1.2,, New AniEaseOutFluent))
  192. Else
  193. Ani.Add(AaScaleTransform(RectBack, 1 - CType(RectBack.RenderTransform, ScaleTransform).ScaleX, Time * 1.2,, New AniEaseOutFluent))
  194. End If
  195. Else
  196. Ani.AddRange({
  197. AaOpacity(RectBack, -RectBack.Opacity, Time),
  198. AaColor(RectBack, Border.BackgroundProperty, If(IsMouseDown, "ColorBrush6", "ColorBrush7"), Time),
  199. AaScaleTransform(RectBack, 0.996 - CType(RectBack.RenderTransform, ScaleTransform).ScaleX, Time,, New AniEaseOutFluent),
  200. AaScaleTransform(RectBack, -0.196, 1,,, True)
  201. })
  202. End If
  203. AniStart(Ani, "CompItem Color " & Uuid)
  204. Else
  205. '无动画
  206. AniStop("CompItem Color " & Uuid)
  207. If _RectBack IsNot Nothing Then RectBack.Opacity = 0
  208. End If
  209. End Sub
  210. End Class