MyLocalModItem.xaml.vb 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. Imports System.Windows.Forms
  2. Public Class MyLocalModItem
  3. #Region "基础属性"
  4. Public Uuid As Integer = GetUuid()
  5. 'Logo
  6. Public Property Logo As String
  7. Get
  8. Return PathLogo.Source
  9. End Get
  10. Set(value As String)
  11. PathLogo.Source = value
  12. End Set
  13. End Property
  14. '标题
  15. Private _Title As String
  16. Public Property Title As String
  17. Get
  18. Return _Title
  19. End Get
  20. Set(value As String)
  21. Dim RawValue = value
  22. Select Case Entry.State
  23. Case McMod.McModState.Fine
  24. LabTitle.TextDecorations = Nothing
  25. Case McMod.McModState.Disabled
  26. LabTitle.TextDecorations = TextDecorations.Strikethrough
  27. Case McMod.McModState.Unavailable
  28. LabTitle.TextDecorations = TextDecorations.Strikethrough
  29. value &= " [错误]"
  30. End Select
  31. If LabTitle.Text = value Then Return
  32. LabTitle.Text = value
  33. _Title = RawValue
  34. End Set
  35. End Property
  36. '副标题
  37. Public Property SubTitle As String
  38. Get
  39. Return If(LabSubtitle?.Text, "")
  40. End Get
  41. Set(value As String)
  42. If LabSubtitle.Text = value Then Return
  43. LabSubtitle.Text = value
  44. LabSubtitle.Visibility = If(value = "", Visibility.Collapsed, Visibility.Visible)
  45. End Set
  46. End Property
  47. '描述
  48. Public Property Description As String
  49. Get
  50. Return LabInfo.Text
  51. End Get
  52. Set(value As String)
  53. If LabInfo.Text = value Then Return
  54. LabInfo.Text = value
  55. End Set
  56. End Property
  57. 'Tag
  58. Public WriteOnly Property Tags As List(Of String)
  59. Set(value As List(Of String))
  60. PanTags.Children.Clear()
  61. PanTags.Visibility = If(value.Any(), Visibility.Visible, Visibility.Collapsed)
  62. For Each TagText In value
  63. Dim NewTag = GetObjectFromXML(
  64. "<Border xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
  65. Background=""#0C000000"" Padding=""3,1"" CornerRadius=""3"" Margin=""0,0,3,0""
  66. SnapsToDevicePixels=""True"" UseLayoutRounding=""False"">
  67. <TextBlock Text=""" & TagText & """ Foreground=""#88000000"" FontSize=""11"" />
  68. </Border>")
  69. PanTags.Children.Add(NewTag)
  70. Next
  71. End Set
  72. End Property
  73. '相关联的 Mod
  74. Public Property Entry As McMod
  75. Get
  76. Return Tag
  77. End Get
  78. Set(value As McMod)
  79. Tag = value
  80. End Set
  81. End Property
  82. #End Region
  83. #Region "点击与勾选"
  84. '触发点击事件
  85. Public Event Click(sender As Object, e As MouseButtonEventArgs)
  86. Private Sub Button_MouseUp(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseLeftButtonUp
  87. If IsMouseDown Then
  88. RaiseEvent Click(sender, e)
  89. If e.Handled Then Return
  90. Log("[Control] 按下本地 Mod 列表项:" & LabTitle.Text)
  91. End If
  92. End Sub
  93. '鼠标点击判定
  94. Private IsMouseDown As Boolean = False
  95. Private Sub Button_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseLeftButtonDown
  96. If Not IsMouseDirectlyOver Then Return
  97. IsMouseDown = True
  98. If ButtonStack IsNot Nothing Then ButtonStack.IsHitTestVisible = False
  99. End Sub
  100. Private Sub Button_MouseLeave(sender As Object, e As Object) Handles Me.MouseLeave, Me.PreviewMouseLeftButtonUp
  101. IsMouseDown = False
  102. If ButtonStack IsNot Nothing Then ButtonStack.IsHitTestVisible = True
  103. End Sub
  104. '滑动选中
  105. Private Shared SwipeStart As Integer, SwipeEnd As Integer
  106. Private Shared _Swiping As Boolean = False
  107. Private Shared Property Swiping As Boolean
  108. Get
  109. Return _Swiping
  110. End Get
  111. Set(value As Boolean)
  112. _Swiping = value
  113. FrmVersionMod.CardSelect.IsHitTestVisible = Not value
  114. End Set
  115. End Property
  116. Private Shared SwipToState As Boolean '被滑动到的目标应将 Checked 改为此值
  117. Private Sub Button_MouseSwipeStart(sender As Object, e As Object) Handles Me.MouseLeftButtonDown
  118. If Parent Is Nothing Then Return 'Mod 可能已被删除(#3824)
  119. '开始滑动
  120. Dim Index = CType(Parent, StackPanel).Children.IndexOf(Me)
  121. SwipeStart = Index
  122. SwipeEnd = Index
  123. Swiping = True
  124. SwipToState = Not Checked
  125. End Sub
  126. Private Sub Button_MouseSwipe(sender As Object, e As Object) Handles Me.MouseEnter, Me.MouseLeave, Me.MouseLeftButtonUp
  127. If Parent Is Nothing Then Return 'Mod 可能已被删除(#3824)
  128. '结束滑动
  129. If Mouse.LeftButton <> MouseButtonState.Pressed OrElse
  130. TypeOf Mouse.DirectlyOver IsNot MyLocalModItem Then '#5771
  131. Swiping = False
  132. Return
  133. End If
  134. '计算滑动范围
  135. Dim Elements = CType(Parent, StackPanel).Children
  136. Dim Index As Integer = Elements.IndexOf(Me)
  137. SwipeStart = MathClamp(Math.Min(SwipeStart, Index), 0, Elements.Count - 1)
  138. SwipeEnd = MathClamp(Math.Max(SwipeEnd, Index), 0, Elements.Count - 1)
  139. '勾选所有范围中的项
  140. If SwipeStart = SwipeEnd Then Return
  141. For i = SwipeStart To SwipeEnd
  142. Dim Item As MyLocalModItem = Elements(i)
  143. Item.InitLate(Item, e)
  144. Item.Checked = SwipToState
  145. Next
  146. End Sub
  147. '勾选状态
  148. Public Event Check(sender As Object, e As RouteEventArgs)
  149. Public Event Changed(sender As Object, e As RouteEventArgs)
  150. Private _Checked As Boolean = False
  151. Public Property Checked As Boolean
  152. Get
  153. Return _Checked
  154. End Get
  155. Set(value As Boolean)
  156. Try
  157. '触发属性值修改
  158. Dim RawValue = _Checked
  159. If value = _Checked Then Return
  160. _Checked = value
  161. Dim ChangedEventArgs As New RouteEventArgs(False)
  162. If IsInitialized Then
  163. RaiseEvent Changed(Me, ChangedEventArgs)
  164. If ChangedEventArgs.Handled Then
  165. _Checked = RawValue
  166. Return
  167. End If
  168. End If
  169. If value Then
  170. Dim CheckEventArgs As New RouteEventArgs(False)
  171. RaiseEvent Check(Me, CheckEventArgs)
  172. If CheckEventArgs.Handled Then Return
  173. End If
  174. '更改动画
  175. If IsVisibleInForm() Then
  176. Dim Anim As New List(Of AniData)
  177. If Checked Then
  178. '由无变有
  179. Dim Delta = 32 - RectCheck.ActualHeight
  180. Anim.Add(AaHeight(RectCheck, Delta * 0.4, 200,, New AniEaseOutFluent(AniEasePower.Weak)))
  181. Anim.Add(AaHeight(RectCheck, Delta * 0.6, 300,, New AniEaseOutBack(AniEasePower.Weak)))
  182. Anim.Add(AaOpacity(RectCheck, 1 - RectCheck.Opacity, 30))
  183. RectCheck.VerticalAlignment = VerticalAlignment.Center
  184. RectCheck.Margin = New Thickness(-3, 0, 0, 0)
  185. Anim.Add(AaColor(LabTitle, TextBlock.ForegroundProperty, If(Entry.State = McMod.McModState.Fine, "ColorBrush2", "ColorBrush5"), 200))
  186. Else
  187. '由有变无
  188. Anim.Add(AaHeight(RectCheck, -RectCheck.ActualHeight, 120,, New AniEaseInFluent(AniEasePower.Weak)))
  189. Anim.Add(AaOpacity(RectCheck, -RectCheck.Opacity, 70, 40))
  190. RectCheck.VerticalAlignment = VerticalAlignment.Center
  191. Anim.Add(AaColor(LabTitle, TextBlock.ForegroundProperty, If(LabTitle.TextDecorations Is Nothing, "ColorBrush1", "ColorBrushGray4"), 120))
  192. End If
  193. AniStart(Anim, "MyLocalModItem Checked " & Uuid)
  194. Else
  195. '不在窗口上时直接设置
  196. RectCheck.VerticalAlignment = VerticalAlignment.Center
  197. RectCheck.Margin = New Thickness(-3, 0, 0, 0)
  198. If Checked Then
  199. RectCheck.Height = 32
  200. RectCheck.Opacity = 1
  201. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, If(Entry.State = McMod.McModState.Fine, "ColorBrush2", "ColorBrush5"))
  202. Else
  203. RectCheck.Height = 0
  204. RectCheck.Opacity = 0
  205. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, If(Entry.State = McMod.McModState.Fine, "ColorBrush1", "ColorBrushGray4"))
  206. End If
  207. AniStop("MyLocalModItem Checked " & Uuid)
  208. End If
  209. Catch ex As Exception
  210. Log(ex, "设置 Checked 失败")
  211. End Try
  212. End Set
  213. End Property
  214. #End Region
  215. #Region "后加载内容"
  216. '右下角状态指示图标
  217. Private ImgState As Image
  218. '指向背景
  219. Private _RectBack As Border = Nothing
  220. Public ReadOnly Property RectBack As Border
  221. Get
  222. If _RectBack Is Nothing Then
  223. Dim Rect As New Border With {
  224. .Name = "RectBack",
  225. .CornerRadius = New CornerRadius(3),
  226. .RenderTransform = New ScaleTransform(0.8, 0.8),
  227. .RenderTransformOrigin = New Point(0.5, 0.5),
  228. .BorderThickness = New Thickness(GetWPFSize(1)),
  229. .SnapsToDevicePixels = True,
  230. .IsHitTestVisible = False,
  231. .Opacity = 0
  232. }
  233. Rect.SetResourceReference(Border.BackgroundProperty, "ColorBrush7")
  234. Rect.SetResourceReference(Border.BorderBrushProperty, "ColorBrush6")
  235. SetColumnSpan(Rect, 999)
  236. SetRowSpan(Rect, 999)
  237. Children.Insert(0, Rect)
  238. _RectBack = Rect
  239. '<!--<Border x:Name = "RectBack" CornerRadius="3" RenderTransformOrigin="0.5,0.5" SnapsToDevicePixels="True"
  240. 'IsHitTestVisible = "False" Opacity="0" BorderThickness="1"
  241. 'Grid.ColumnSpan = "4" Background="{DynamicResource ColorBrush7}" BorderBrush="{DynamicResource ColorBrush6}"/>-->
  242. End If
  243. Return _RectBack
  244. End Get
  245. End Property
  246. '按钮
  247. Public ButtonHandler As Action(Of MyLocalModItem, EventArgs)
  248. Public ButtonStack As FrameworkElement
  249. Private _Buttons As IEnumerable(Of MyIconButton)
  250. Public Property Buttons As IEnumerable(Of MyIconButton)
  251. Get
  252. Return _Buttons
  253. End Get
  254. Set(value As IEnumerable(Of MyIconButton))
  255. _Buttons = value
  256. '移除原 Stack
  257. If ButtonStack IsNot Nothing Then
  258. Children.Remove(ButtonStack)
  259. ButtonStack = Nothing
  260. End If
  261. If Not value.Any() Then Return
  262. '添加新 Stack
  263. ButtonStack = New StackPanel With {.Opacity = 0, .Margin = New Thickness(0, 0, 5, 0), .SnapsToDevicePixels = False, .Orientation = Orientation.Horizontal,
  264. .HorizontalAlignment = HorizontalAlignment.Right, .VerticalAlignment = VerticalAlignment.Center, .UseLayoutRounding = False}
  265. SetColumnSpan(ButtonStack, 10) : SetRowSpan(ButtonStack, 10)
  266. '构造按钮
  267. For Each Btn As MyIconButton In value
  268. If Btn.Height.Equals(Double.NaN) Then Btn.Height = 25
  269. If Btn.Width.Equals(Double.NaN) Then Btn.Width = 25
  270. CType(ButtonStack, StackPanel).Children.Add(Btn)
  271. Next
  272. Children.Add(ButtonStack)
  273. End Set
  274. End Property
  275. '勾选条
  276. Private _RectCheck As Border
  277. Public ReadOnly Property RectCheck As Border
  278. Get
  279. If _RectCheck Is Nothing Then
  280. _RectCheck = New Border With {.Width = 5, .Height = If(Checked, Double.NaN, 0), .CornerRadius = New CornerRadius(2, 2, 2, 2),
  281. .VerticalAlignment = If(Checked, VerticalAlignment.Stretch, VerticalAlignment.Center),
  282. .HorizontalAlignment = HorizontalAlignment.Left, .UseLayoutRounding = False, .SnapsToDevicePixels = False,
  283. .Margin = If(Checked, New Thickness(-3, 6, 0, 6), New Thickness(-3, 0, 0, 0))}
  284. _RectCheck.SetResourceReference(Border.BackgroundProperty, "ColorBrush3")
  285. SetRowSpan(_RectCheck, 10)
  286. Children.Add(_RectCheck)
  287. End If
  288. Return _RectCheck
  289. End Get
  290. End Property
  291. #End Region
  292. Private Function GetUpdateCompareDescription() As String
  293. Dim CurrentName = Entry.CompFile.FileName.Replace(".jar", "")
  294. Dim NewestName = Entry.UpdateFile.FileName.Replace(".jar", "")
  295. '简化名称对比
  296. Dim CurrentSegs = CurrentName.Split("-"c).ToList()
  297. Dim NewestSegs = NewestName.Split("-"c).ToList()
  298. Dim Shortened As Boolean = False
  299. For Each Seg In CurrentSegs.ToList()
  300. If Not NewestSegs.Contains(Seg) Then Continue For
  301. CurrentSegs.Remove(Seg)
  302. NewestSegs.Remove(Seg)
  303. Shortened = True
  304. Next
  305. If Shortened AndAlso CurrentSegs.Any() AndAlso NewestSegs.Any() Then
  306. CurrentName = Join(CurrentSegs, "-")
  307. NewestName = Join(NewestSegs, "-")
  308. Entry._Version = CurrentName '使用网络信息作为显示的版本号
  309. End If
  310. Return $"当前版本:{CurrentName}({GetTimeSpanString(Entry.CompFile.ReleaseDate - Date.Now, False)}){vbCrLf}最新版本:{NewestName}({GetTimeSpanString(Entry.UpdateFile.ReleaseDate - Date.Now, False)})"
  311. End Function
  312. Public Sub Refresh() Handles Me.Loaded
  313. RunInUi(
  314. Sub()
  315. '更新
  316. If Entry.CanUpdate Then
  317. BtnUpdate.Visibility = Visibility.Visible
  318. BtnUpdate.ToolTip = $"{GetUpdateCompareDescription()}{vbCrLf}点击以更新,右键查看更新日志。"
  319. Else
  320. BtnUpdate.Visibility = Visibility.Collapsed
  321. End If
  322. '标题与描述
  323. Dim DescFileName As String
  324. If Entry.State = McMod.McModState.Fine OrElse Entry.State = McMod.McModState.Disabled Then
  325. DescFileName = IO.Path.GetFileNameWithoutExtension(Entry.Path)
  326. Else
  327. DescFileName = GetFileNameFromPath(Entry.Path)
  328. End If
  329. Dim NewDescription As String
  330. If Setup.Get("ToolModLocalNameStyle") = 1 Then
  331. '标题显示文件名,详情显示译名
  332. '标题
  333. Title = DescFileName
  334. SubTitle = ""
  335. '描述
  336. If Entry.Comp Is Nothing Then
  337. NewDescription = Entry.Name
  338. Else
  339. Dim Titles = Entry.Comp.GetControlTitle(False)
  340. NewDescription = Titles.Key & Titles.Value
  341. End If
  342. NewDescription = NewDescription.Replace(" | ", " / ")
  343. If Entry.Version IsNot Nothing Then NewDescription &= $" ({Entry.Version})"
  344. Else
  345. '标题显示译名,详情显示文件名
  346. '标题
  347. If Entry.Comp Is Nothing Then
  348. Title = Entry.Name
  349. SubTitle = If(Entry.Version Is Nothing, "", " | " & Entry.Version)
  350. Else
  351. Dim Titles = Entry.Comp.GetControlTitle(False)
  352. Title = Titles.Key
  353. SubTitle = Titles.Value & If(Entry.Version Is Nothing, "", " | " & Entry.Version)
  354. End If
  355. '描述
  356. NewDescription = DescFileName
  357. End If
  358. If Entry.Comp IsNot Nothing Then
  359. NewDescription += ": " & Entry.Comp.Description.Replace(vbCr, "").Replace(vbLf, "")
  360. ElseIf Entry.Description IsNot Nothing Then
  361. NewDescription += ": " & Entry.Description.Replace(vbCr, "").Replace(vbLf, "")
  362. ElseIf Not Entry.IsFileAvailable Then
  363. NewDescription += ": " & "存在错误,无法获取信息"
  364. End If
  365. Description = NewDescription
  366. If Checked Then
  367. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, If(Entry.State = McMod.McModState.Fine, "ColorBrush2", "ColorBrush5"))
  368. Else
  369. LabTitle.SetResourceReference(TextBlock.ForegroundProperty, If(Entry.State = McMod.McModState.Fine, "ColorBrush1", "ColorBrushGray4"))
  370. End If
  371. '主 Logo
  372. Logo = If(Entry.Comp Is Nothing, PathImage & "Icons/NoIcon.png", Entry.Comp.GetControlLogo())
  373. '图标右下角的 Logo
  374. If Entry.State = McMod.McModState.Fine Then
  375. If ImgState IsNot Nothing Then
  376. Children.Remove(ImgState)
  377. ImgState = Nothing
  378. End If
  379. Else
  380. If ImgState Is Nothing Then
  381. ImgState = New Image With {
  382. .Width = 20, .Height = 20, .Margin = New Thickness(0, 0, -5, -3), .IsHitTestVisible = False,
  383. .HorizontalAlignment = HorizontalAlignment.Right, .VerticalAlignment = VerticalAlignment.Bottom
  384. }
  385. RenderOptions.SetBitmapScalingMode(ImgState, BitmapScalingMode.HighQuality)
  386. SetColumn(ImgState, 1) : SetRow(ImgState, 1) : SetRowSpan(ImgState, 2)
  387. Children.Add(ImgState)
  388. '<Image x:Name="ImgState" RenderOptions.BitmapScalingMode="HighQuality" Width="16" Height="16" Margin="0,0,-3,-1"
  389. ' Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" IsHitTestVisible="False"
  390. ' HorizontalAlignment="Right" VerticalAlignment="Bottom"
  391. ' Source="/Images/Icons/Unavailable.png" />
  392. End If
  393. ImgState.Source = New MyBitmap(PathImage & $"Icons/{Entry.State}.png")
  394. End If
  395. '标签
  396. If Entry.Comp IsNot Nothing Then Tags = Entry.Comp.Tags
  397. End Sub)
  398. End Sub
  399. Public Sub RefreshColor(sender As Object, e As EventArgs) Handles Me.MouseEnter, Me.MouseLeave, Me.MouseLeftButtonDown, Me.MouseLeftButtonUp, Me.Changed
  400. InitLate(sender, e)
  401. '触发颜色动画
  402. Dim Time As Integer = If(IsMouseOver, 120, 180)
  403. Dim Ani As New List(Of AniData)
  404. 'ButtonStack
  405. If ButtonStack IsNot Nothing Then
  406. If IsMouseOver Then
  407. Ani.Add(AaOpacity(ButtonStack, 1 - ButtonStack.Opacity, Time * 0.7, Time * 0.3))
  408. Ani.Add(AaDouble(Sub(i) ColumnPaddingRight.Width = New GridLength(Math.Max(0, ColumnPaddingRight.Width.Value + i)),
  409. 5 + Buttons.Count * 25 - ColumnPaddingRight.Width.Value, Time * 0.3, Time * 0.7))
  410. Else
  411. Ani.Add(AaOpacity(ButtonStack, -ButtonStack.Opacity, Time * 0.4))
  412. Ani.Add(AaDouble(Sub(i) ColumnPaddingRight.Width = New GridLength(Math.Max(0, ColumnPaddingRight.Width.Value + i)),
  413. 4 - ColumnPaddingRight.Width.Value, Time * 0.4))
  414. End If
  415. End If
  416. 'RectBack
  417. If IsMouseOver OrElse Checked Then
  418. Ani.AddRange({
  419. AaColor(RectBack, Border.BackgroundProperty, If(IsMouseDown, "ColorBrush6", "ColorBrushBg1"), Time),
  420. AaOpacity(RectBack, 1 - RectBack.Opacity, Time,, New AniEaseOutFluent)
  421. })
  422. If IsMouseDown Then
  423. Ani.Add(AaScaleTransform(RectBack, 0.996 - CType(RectBack.RenderTransform, ScaleTransform).ScaleX, Time * 1.2,, New AniEaseOutFluent))
  424. Else
  425. Ani.Add(AaScaleTransform(RectBack, 1 - CType(RectBack.RenderTransform, ScaleTransform).ScaleX, Time * 1.2,, New AniEaseOutFluent))
  426. End If
  427. Else
  428. Ani.AddRange({
  429. AaOpacity(RectBack, -RectBack.Opacity, Time),
  430. AaScaleTransform(RectBack, 0.996 - CType(RectBack.RenderTransform, ScaleTransform).ScaleX, Time,, New AniEaseOutFluent),
  431. AaScaleTransform(RectBack, -0.196, 1,,, True)
  432. })
  433. End If
  434. AniStart(Ani, "LocalModItem Color " & Uuid)
  435. End Sub
  436. '触发虚拟化内容
  437. Private Sub InitLate(sender As Object, e As EventArgs)
  438. If ButtonHandler IsNot Nothing Then
  439. ButtonHandler(sender, e)
  440. ButtonHandler = Nothing
  441. End If
  442. End Sub
  443. '显示更新日志
  444. Private Sub BtnUpdate_PreviewMouseRightButtonUp(sender As Object, e As MouseButtonEventArgs) Handles BtnUpdate.PreviewMouseRightButtonUp
  445. e.Handled = True
  446. ShowUpdateLog()
  447. End Sub
  448. Private Sub ShowUpdateLog()
  449. Dim CurseForgeUrl As String = Entry.ChangelogUrls.FirstOrDefault(Function(x) x.Contains("curseforge.com"))
  450. Dim ModrinthUrl As String = Entry.ChangelogUrls.FirstOrDefault(Function(x) x.Contains("modrinth.com"))
  451. If CurseForgeUrl Is Nothing OrElse ModrinthUrl Is Nothing Then
  452. OpenWebsite(Entry.ChangelogUrls.First)
  453. Else
  454. Select Case MyMsgBox("要在哪个网站上查看更新日志?", "查看更新日志", "Modrinth", "CurseForge", "取消")
  455. Case 1
  456. OpenWebsite(ModrinthUrl)
  457. Case 2
  458. OpenWebsite(CurseForgeUrl)
  459. End Select
  460. End If
  461. End Sub
  462. '触发更新
  463. Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles BtnUpdate.Click
  464. Select Case MyMsgBox($"是否要更新 {Entry.Name}?{vbCrLf}{vbCrLf}{GetUpdateCompareDescription()}", "Mod 更新确认", "更新", "查看更新日志", "取消")
  465. Case 1 '更新
  466. FrmVersionMod.UpdateMods({Entry})
  467. Case 2 '查看更新日志
  468. ShowUpdateLog()
  469. Case 3 '取消
  470. End Select
  471. End Sub
  472. '自适应(#4465)
  473. Private Sub PanTitle_SizeChanged() Handles PanTitle.SizeChanged
  474. '0:全部舒展:Auto - Auto - (Auto) - 1*
  475. '1:压缩 Subtitle:Auto - 1* - (Auto) - 0
  476. '2:继续压缩 Title:1* - 0 - (Auto) - 0
  477. Dim CurrentCompressLevel As Integer =
  478. If(ColumnExtend.Width.IsStar, 0, If(ColumnTitle.Width.IsStar, 2, 1)) 'Subtitle 可能是 Collapsed
  479. Dim NewCompressLevel As Integer
  480. Select Case CurrentCompressLevel
  481. Case 0
  482. If ColumnExtend.ActualWidth < 0.5 Then
  483. NewCompressLevel = If(LabSubtitle.Visibility = Visibility.Collapsed, 2, 1)
  484. Else
  485. Return
  486. End If
  487. Case 1
  488. If ColumnSubtitle.ActualWidth < 0.5 Then
  489. NewCompressLevel = 2
  490. ElseIf Not LabSubtitle.IsTextTrimmed Then
  491. NewCompressLevel = 0
  492. Else
  493. Return
  494. End If
  495. Case 2
  496. If Not LabTitle.IsTextTrimmed Then
  497. NewCompressLevel = If(LabSubtitle.Visibility = Visibility.Collapsed, 0, 1)
  498. Else
  499. Return
  500. End If
  501. End Select
  502. Select Case NewCompressLevel
  503. Case 0
  504. '全部舒展:Auto - Auto - (Auto) - 1*
  505. ColumnTitle.Width = GridLength.Auto
  506. ColumnSubtitle.Width = GridLength.Auto
  507. ColumnExtend.Width = New GridLength(1, GridUnitType.Star)
  508. Case 1
  509. '压缩 Subtitle:Auto - 1* - (Auto) - 0
  510. ColumnTitle.Width = GridLength.Auto
  511. ColumnSubtitle.Width = New GridLength(1, GridUnitType.Star)
  512. ColumnExtend.Width = New GridLength(0, GridUnitType.Pixel)
  513. Case 2
  514. '继续压缩 Title:1* - 0 - (Auto) - 0
  515. ColumnTitle.Width = New GridLength(1, GridUnitType.Star)
  516. ColumnSubtitle.Width = New GridLength(0, GridUnitType.Pixel)
  517. ColumnExtend.Width = New GridLength(0, GridUnitType.Pixel)
  518. End Select
  519. End Sub
  520. End Class