MyCompItem.xaml.vb 10.0 KB

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