MyLocalModItem.xaml.vb 23 KB

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