ModMain.vb 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. Imports System.Windows.Interop
  2. Imports System.Windows.Threading
  3. Public Module ModMain
  4. #Region "弹出提示"
  5. ''' <summary>
  6. ''' 提示信息的种类。
  7. ''' </summary>
  8. Public Enum HintType
  9. ''' <summary>
  10. ''' 信息,通常是蓝色的“i”。
  11. ''' </summary>
  12. ''' <remarks></remarks>
  13. Info
  14. ''' <summary>
  15. ''' 已完成,通常是绿色的“√”。
  16. ''' </summary>
  17. ''' <remarks></remarks>
  18. Finish
  19. ''' <summary>
  20. ''' 错误,通常是红色的“×”。
  21. ''' </summary>
  22. ''' <remarks></remarks>
  23. Critical
  24. End Enum
  25. Private Structure HintMessage
  26. Public Text As String
  27. Public Type As HintType
  28. Public Log As Boolean
  29. End Structure
  30. ''' <summary>
  31. ''' 等待弹出的提示列表。以 {String, HintType, Log As Boolean} 形式存储为数组。
  32. ''' </summary>
  33. Private HintWaiting As List(Of HintMessage) = If(HintWaiting, New List(Of HintMessage))
  34. ''' <summary>
  35. ''' 在窗口左下角弹出提示文本。
  36. ''' </summary>
  37. Public Sub Hint(Text As String, Optional Type As HintType = HintType.Info, Optional Log As Boolean = True)
  38. If HintWaiting Is Nothing Then HintWaiting = New List(Of HintMessage)
  39. HintWaiting.Add(New HintMessage With {.Text = If(Text, ""), .Type = Type, .Log = Log})
  40. End Sub
  41. Private Sub HintTick()
  42. Try
  43. 'Tag 存储了:{ 是否可以重用, Uuid }
  44. If Not HintWaiting.Any() Then Exit Sub
  45. Do While HintWaiting.Any
  46. ''清除空提示
  47. 'If IsNothing(HintWaiting(0)) OrElse IsNothing(HintWaiting(0)(0)) Then
  48. ' HintWaiting.RemoveAt(0)
  49. ' Continue Do
  50. 'End If
  51. Dim CurrentHint = HintWaiting(0)
  52. '去回车
  53. CurrentHint.Text = CurrentHint.Text.Replace(vbCrLf, " ").Replace(vbCr, " ").Replace(vbLf, " ")
  54. '超量提示直接忽略
  55. If FrmMain.PanHint.Children.Count >= 20 Then GoTo EndHint
  56. '检查是否有重复提示
  57. Dim DoubleStack As Border = Nothing
  58. For Each stack As Border In FrmMain.PanHint.Children
  59. If stack.Tag(0) AndAlso CType(stack.Child, TextBlock).Text = CurrentHint.Text Then DoubleStack = stack
  60. Next
  61. '获取渐变颜色
  62. Dim TargetColor0, TargetColor1 As MyColor
  63. Dim Percent As Double = 0.3
  64. Select Case CurrentHint.Type
  65. Case HintType.Info
  66. TargetColor0 = New MyColor(37, 155, 252)
  67. TargetColor1 = New MyColor(10, 142, 252)
  68. Case HintType.Finish
  69. TargetColor0 = New MyColor(33, 177, 33)
  70. TargetColor1 = New MyColor(29, 160, 29)
  71. Case Else 'HintType.Critical
  72. TargetColor0 = New MyColor(255, 53, 11)
  73. TargetColor1 = New MyColor(255, 43, 0)
  74. End Select
  75. If Not IsNothing(DoubleStack) Then
  76. '有重复提示,且该提示的进入动画已播放
  77. If Not AniIsRun("Hint Show " & DoubleStack.Tag(1)) Then
  78. AniStop("Hint Hide " & DoubleStack.Tag(1))
  79. Dim Delay As Double = (800 + MathClamp(CurrentHint.Text.Length, 5, 23) * 180) * AniSpeed
  80. AniStart({
  81. AaX(DoubleStack, -12 - DoubleStack.Margin.Left, 50,, New AniEaseOutFluent),
  82. AaX(DoubleStack, -8, 50, 50, New AniEaseInFluent),
  83. AaX(DoubleStack, 8, 50, 100, New AniEaseOutFluent),
  84. AaX(DoubleStack, -8, 50, 150, New AniEaseInFluent),
  85. AaDouble(Sub(i)
  86. Percent += i
  87. Dim Gradient As LinearGradientBrush = DoubleStack.Background
  88. Gradient.GradientStops(0).Color = TargetColor0 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  89. Gradient.GradientStops(1).Color = TargetColor1 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  90. End Sub, 0.7, 250),
  91. AaX(DoubleStack, -50, 200, Delay, New AniEaseInFluent),
  92. AaOpacity(DoubleStack, -1, 150, Delay),
  93. AaCode(Sub() DoubleStack.Tag(0) = False, Delay),
  94. AaHeight(DoubleStack, -26, 100,, New AniEaseOutFluent, True),
  95. AaCode(Sub() FrmMain.PanHint.Children.Remove(DoubleStack), , True)
  96. }, "Hint Hide " & DoubleStack.Tag(1))
  97. End If
  98. Else
  99. '准备控件
  100. Dim NewHintControl As New Border With {.Tag = {True, GetUuid()}, .Margin = New Thickness(-70, 0, 20, 0), .Opacity = 0, .Height = 0, .HorizontalAlignment = HorizontalAlignment.Left, .CornerRadius = New CornerRadius(0, 6, 6, 0)}
  101. NewHintControl.Background = New LinearGradientBrush(New GradientStopCollection(New List(Of GradientStop) From {
  102. New GradientStop(TargetColor0 * Percent + New MyColor(255, 255, 255) * (1 - Percent), 0),
  103. New GradientStop(TargetColor1 * Percent + New MyColor(255, 255, 255) * (1 - Percent), 1)}), 90)
  104. NewHintControl.Child = New TextBlock With {.TextTrimming = TextTrimming.CharacterEllipsis, .FontSize = 13, .Text = CurrentHint.Text, .Foreground = New MyColor(255, 255, 255), .Margin = New Thickness(33, 5, 8, 5)}
  105. 'AddHandler NewHintControl.MouseLeftButtonDown, AddressOf HideAllHint
  106. FrmMain.PanHint.Children.Add(NewHintControl)
  107. '控件动画
  108. Dim Animations As New List(Of AniData)
  109. If FrmMain.PanHint.Children.Count > 1 Then
  110. '已有提示
  111. Animations.Add(AaHeight(NewHintControl, 26, 150, , New AniEaseOutFluent))
  112. Else
  113. '是唯一提示
  114. NewHintControl.Height = 26
  115. End If
  116. '开始动画
  117. Animations.AddRange({
  118. AaX(NewHintControl, 30, 400, , New AniEaseOutElastic(AniEasePower.Weak)),
  119. AaX(NewHintControl, 20, 200, , New AniEaseOutFluent),
  120. AaOpacity(NewHintControl, 1, 100),
  121. AaDouble(Sub(i)
  122. Percent += i
  123. Dim Gradient As LinearGradientBrush = NewHintControl.Background
  124. Gradient.GradientStops(0).Color = TargetColor0 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  125. Gradient.GradientStops(1).Color = TargetColor1 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  126. End Sub, 0.7, 250, 100)
  127. })
  128. AniStart(Animations, "Hint Show " & NewHintControl.Tag(1))
  129. '结束动画
  130. Dim Delay As Double = (800 + MathClamp(CurrentHint.Text.Length, 5, 23) * 180) * AniSpeed
  131. AniStart({
  132. AaX(NewHintControl, -50, 200, Delay, New AniEaseInFluent),
  133. AaOpacity(NewHintControl, -1, 150, Delay),
  134. AaCode(Sub() NewHintControl.Tag(0) = False, Delay),
  135. AaHeight(NewHintControl, -26, 100,, New AniEaseOutFluent, True),
  136. AaCode(Sub() FrmMain.PanHint.Children.Remove(NewHintControl), , True)
  137. }, "Hint Hide " & NewHintControl.Tag(1))
  138. End If
  139. '结束处理
  140. EndHint:
  141. If CurrentHint.Log Then Log("[UI] 弹出提示:" & CurrentHint.Text)
  142. HintWaiting.RemoveAt(0)
  143. Loop
  144. Catch ex As Exception
  145. Log(ex, "显示弹出提示失败", LogLevel.Normal)
  146. End Try
  147. End Sub
  148. Private Sub HideAllHint()
  149. For Each Control As Border In FrmMain.PanHint.Children
  150. Control.IsHitTestVisible = False
  151. AniStart({
  152. AaX(Control, -50, 200, , New AniEaseInFluent),
  153. AaOpacity(Control, -1, 150, , New AniEaseInFluent),
  154. AaCode(Sub() Control.Tag(0) = False),
  155. AaHeight(Control, -26, 100,, New AniEaseOutFluent, True),
  156. AaCode(Sub() FrmMain.PanHint.Children.Remove(Control), , True)
  157. }, "Hint Hide " & Control.Tag(1))
  158. Next
  159. End Sub
  160. #End Region
  161. #Region "弹窗"
  162. ''' <summary>
  163. ''' 存储弹窗信息的转换器。
  164. ''' </summary>
  165. Public Class MyMsgBoxConverter
  166. Public Type As MyMsgBoxType
  167. Public Title As String
  168. Public Text As String
  169. ''' <summary>
  170. ''' 输入框模式:文本框的文本;选择模式:需要放进去的 List(Of MyListItem)。
  171. ''' </summary>
  172. Public Content As Object
  173. ''' <summary>
  174. ''' 仅输入框模式:输入验证规则。
  175. ''' </summary>
  176. Public ValidateRules As ObjectModel.Collection(Of Validate)
  177. ''' <summary>
  178. ''' 仅输入框模式:提示文本。
  179. ''' </summary>
  180. Public HintText As String = ""
  181. ''' <summary>
  182. ''' 有多个按钮时,是否给第一个按钮加高亮。
  183. ''' </summary>
  184. Public HighLight As Boolean
  185. Public Button1 As String = "确定"
  186. Public Button2 As String = ""
  187. Public Button3 As String = ""
  188. ''' <summary>
  189. ''' 点击第一个按钮将执行该方法,不关闭弹窗。
  190. ''' </summary>
  191. Public Button1Action As Action = Nothing
  192. ''' <summary>
  193. ''' 点击第二个按钮将执行该方法,不关闭弹窗。
  194. ''' </summary>
  195. Public Button2Action As Action = Nothing
  196. ''' <summary>
  197. ''' 点击第三个按钮将执行该方法,不关闭弹窗。
  198. ''' </summary>
  199. Public Button3Action As Action = Nothing
  200. Public IsWarn As Boolean = False
  201. Public ForceWait As Boolean = False
  202. Public WaitFrame As New DispatcherFrame(True)
  203. ''' <summary>
  204. ''' 弹窗是否已经关闭。
  205. ''' </summary>
  206. Public IsExited As Boolean = False
  207. ''' <summary>
  208. ''' 点击的按钮编号或输入的文本。若输入弹窗点击了非第一个按钮,则为 Nothing。
  209. ''' </summary>
  210. Public Result As Object
  211. End Class
  212. Public Enum MyMsgBoxType
  213. Text
  214. [Select]
  215. Input
  216. End Enum
  217. ''' <summary>
  218. ''' 显示弹窗,返回点击按钮的编号(从 1 开始)。
  219. ''' </summary>
  220. ''' <param name="Title">弹窗的标题。</param>
  221. ''' <param name="Caption">弹窗的内容。</param>
  222. ''' <param name="Button1">显示的第一个按钮,默认为“确定”。</param>
  223. ''' <param name="Button2">显示的第二个按钮,默认为空。</param>
  224. ''' <param name="Button3">显示的第三个按钮,默认为空。</param>
  225. ''' <param name="Button1Action">点击第一个按钮将执行该方法,不关闭弹窗。</param>
  226. ''' <param name="Button2Action">点击第二个按钮将执行该方法,不关闭弹窗。</param>
  227. ''' <param name="Button3Action">点击第三个按钮将执行该方法,不关闭弹窗。</param>
  228. ''' <param name="IsWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
  229. Public Function MyMsgBox(Caption As String, Optional Title As String = "提示",
  230. Optional Button1 As String = "确定", Optional Button2 As String = "", Optional Button3 As String = "",
  231. Optional IsWarn As Boolean = False, Optional HighLight As Boolean = True, Optional ForceWait As Boolean = False,
  232. Optional Button1Action As Action = Nothing, Optional Button2Action As Action = Nothing, Optional Button3Action As Action = Nothing) As Integer
  233. '将弹窗列入队列
  234. Dim Converter As New MyMsgBoxConverter With {.Type = MyMsgBoxType.Text, .Button1 = Button1, .Button2 = Button2, .Button3 = Button3, .Text = Caption, .IsWarn = IsWarn, .Title = Title, .HighLight = HighLight, .ForceWait = True, .Button1Action = Button1Action, .Button2Action = Button2Action, .Button3Action = Button3Action}
  235. WaitingMyMsgBox.Add(Converter)
  236. If RunInUi() Then
  237. '若为 UI 线程,立即执行弹窗刻, 避免快速(连点器)点击时多次弹窗
  238. MyMsgBoxTick()
  239. End If
  240. If Button2.Length > 0 OrElse ForceWait Then
  241. '若有多个按钮则开始等待
  242. If FrmMain Is Nothing OrElse FrmMain.PanMsg Is Nothing AndAlso RunInUi() Then
  243. '主窗体尚未加载,用老土的弹窗来替代
  244. WaitingMyMsgBox.Remove(Converter)
  245. If Button2.Length > 0 Then
  246. Dim RawResult As MsgBoxResult = MsgBox(Caption, If(Button3.Length > 0, MsgBoxStyle.YesNoCancel, MsgBoxStyle.YesNo) + If(IsWarn, MsgBoxStyle.Critical, MsgBoxStyle.Question), Title)
  247. Select Case RawResult
  248. Case MsgBoxResult.Yes
  249. Converter.Result = 1
  250. Case MsgBoxResult.No
  251. Converter.Result = 2
  252. Case MsgBoxResult.Cancel
  253. Converter.Result = 3
  254. End Select
  255. Else
  256. MsgBox(Caption, MsgBoxStyle.OkOnly + If(IsWarn, MsgBoxStyle.Critical, MsgBoxStyle.Question), Title)
  257. Converter.Result = 1
  258. End If
  259. Log("[Control] 主窗体加载完成前出现意料外的等待弹窗:" & Button1 & "," & Button2 & "," & Button3, LogLevel.Debug)
  260. Else
  261. Try
  262. FrmMain.DragStop()
  263. ComponentDispatcher.PushModal()
  264. Dispatcher.PushFrame(Converter.WaitFrame)
  265. Finally
  266. ComponentDispatcher.PopModal()
  267. End Try
  268. End If
  269. Log("[Control] 普通弹框返回:" & If(Converter.Result, "null"))
  270. Return Converter.Result
  271. Else
  272. '不进行等待,直接返回
  273. Return 1
  274. End If
  275. End Function
  276. ''' <summary>
  277. ''' 显示输入框并返回输入的文本。若点击第二个按钮,则返回 Nothing。
  278. ''' </summary>
  279. ''' <param name="Title">弹窗的标题。</param>
  280. ''' <param name="ValidateRules">文本框的输入检测。</param>
  281. ''' <param name="Text">弹窗的介绍文本。</param>
  282. ''' <param name="DefaultInput">文本框的默认内容。</param>
  283. ''' <param name="HintText">文本框的提示内容。</param>
  284. ''' <param name="Button1">显示的第一个按钮,默认为“确定”。</param>
  285. ''' <param name="Button2">显示的第二个按钮,默认为“取消”。</param>
  286. ''' <param name="IsWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
  287. Public Function MyMsgBoxInput(Title As String, Optional Text As String = "", Optional DefaultInput As String = "", Optional ValidateRules As ObjectModel.Collection(Of Validate) = Nothing, Optional HintText As String = "", Optional Button1 As String = "确定", Optional Button2 As String = "取消", Optional IsWarn As Boolean = False) As String
  288. '将弹窗列入队列
  289. Dim Converter As New MyMsgBoxConverter With {.Text = Text, .HintText = HintText, .Type = MyMsgBoxType.Input, .ValidateRules = If(ValidateRules, New ObjectModel.Collection(Of Validate)), .Button1 = Button1, .Button2 = Button2, .Content = DefaultInput, .IsWarn = IsWarn, .Title = Title}
  290. WaitingMyMsgBox.Add(Converter)
  291. '虽然我也不知道这是啥但是能用就成了 :)
  292. Try
  293. If FrmMain IsNot Nothing Then FrmMain.DragStop()
  294. ComponentDispatcher.PushModal()
  295. Dispatcher.PushFrame(Converter.WaitFrame)
  296. Finally
  297. ComponentDispatcher.PopModal()
  298. End Try
  299. Log("[Control] 输入弹框返回:" & If(Converter.Result, "null"))
  300. Return Converter.Result
  301. End Function
  302. ''' <summary>
  303. ''' 显示选择框并返回选择的第几项(从 0 开始)。若点击第二个按钮,则返回 Nothing。
  304. ''' </summary>
  305. ''' <param name="Title">弹窗的标题。</param>
  306. ''' <param name="Button1">显示的第一个按钮,默认为 “确定”。</param>
  307. ''' <param name="Button2">显示的第二个按钮,默认为空。</param>
  308. ''' <param name="IsWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
  309. Public Function MyMsgBoxSelect(Selections As List(Of IMyRadio), Optional Title As String = "提示", Optional Button1 As String = "确定", Optional Button2 As String = "", Optional IsWarn As Boolean = False) As Integer?
  310. '将弹窗列入队列
  311. Dim Converter As New MyMsgBoxConverter With {.Type = MyMsgBoxType.Select, .Button1 = Button1, .Button2 = Button2, .Content = Selections, .IsWarn = IsWarn, .Title = Title}
  312. WaitingMyMsgBox.Add(Converter)
  313. '虽然我也不知道这是啥但是能用就成了 :)
  314. Try
  315. If FrmMain IsNot Nothing Then FrmMain.DragStop()
  316. ComponentDispatcher.PushModal()
  317. Dispatcher.PushFrame(Converter.WaitFrame)
  318. Finally
  319. ComponentDispatcher.PopModal()
  320. End Try
  321. Log("[Control] 选择弹框返回:" & If(Converter.Result, "null"))
  322. Return Converter.Result
  323. End Function
  324. ''' <summary>
  325. ''' 等待显示的弹窗。
  326. ''' </summary>
  327. Public WaitingMyMsgBox As List(Of MyMsgBoxConverter) = If(WaitingMyMsgBox, New List(Of MyMsgBoxConverter))
  328. Public Sub MyMsgBoxTick()
  329. Try
  330. If FrmMain Is Nothing OrElse FrmMain.PanMsg Is Nothing OrElse FrmMain.WindowState = WindowState.Minimized Then Exit Sub
  331. If FrmMain.PanMsg.Children.Count > 0 Then
  332. '弹窗中
  333. FrmMain.PanMsg.Visibility = Visibility.Visible
  334. ElseIf WaitingMyMsgBox.Any Then
  335. '没有弹窗,显示一个等待的弹窗
  336. FrmMain.PanMsg.Visibility = Visibility.Visible
  337. Select Case CType(WaitingMyMsgBox(0), MyMsgBoxConverter).Type
  338. Case MyMsgBoxType.Input
  339. FrmMain.PanMsg.Children.Add(New MyMsgInput(WaitingMyMsgBox(0)))
  340. Case MyMsgBoxType.Select
  341. FrmMain.PanMsg.Children.Add(New MyMsgSelect(WaitingMyMsgBox(0)))
  342. Case MyMsgBoxType.Text
  343. FrmMain.PanMsg.Children.Add(New MyMsgText(WaitingMyMsgBox(0)))
  344. End Select
  345. WaitingMyMsgBox.RemoveAt(0)
  346. Else
  347. '没有弹窗,没有等待的弹窗
  348. If Not FrmMain.PanMsg.Visibility = Visibility.Collapsed Then FrmMain.PanMsg.Visibility = Visibility.Collapsed
  349. End If
  350. Catch ex As Exception
  351. Log(ex, "处理等待中的弹窗失败", LogLevel.Feedback)
  352. End Try
  353. End Sub
  354. #End Region
  355. #Region "页面声明"
  356. '在最后进行页面声明,避免颜色尚未加载完毕
  357. '窗体声明
  358. Public FrmMain As FormMain
  359. Public FrmStart As SplashScreen
  360. '页面声明(出于单元测试考虑,初始化页面已转入 FormMain 中)
  361. Public FrmLaunchLeft As PageLaunchLeft
  362. Public FrmLaunchRight As PageLaunchRight
  363. Public FrmSelectLeft As PageSelectLeft
  364. Public FrmSelectRight As PageSelectRight
  365. Public FrmSpeedLeft As PageSpeedLeft
  366. Public FrmSpeedRight As PageSpeedRight
  367. '联机页面声明
  368. Public FrmLinkLeft As PageLinkLeft
  369. Public FrmLinkIoi As PageLinkIoi
  370. Public FrmLinkHiper As PageLinkHiper
  371. Public FrmLinkHelp As PageOtherHelpDetail
  372. Public FrmLinkFeedback As PageLinkFeedback
  373. '下载页面声明
  374. Public FrmDownloadLeft As PageDownloadLeft
  375. Public FrmDownloadInstall As PageDownloadInstall
  376. Public FrmDownloadClient As PageDownloadClient
  377. Public FrmDownloadOptiFine As PageDownloadOptiFine
  378. Public FrmDownloadLiteLoader As PageDownloadLiteLoader
  379. Public FrmDownloadForge As PageDownloadForge
  380. Public FrmDownloadNeoForge As PageDownloadNeoForge
  381. Public FrmDownloadFabric As PageDownloadFabric
  382. Public FrmDownloadMod As PageDownloadMod
  383. Public FrmDownloadPack As PageDownloadPack
  384. Public FrmDownloadShader As PageDownloadShader
  385. '设置页面声明
  386. Public FrmSetupLeft As PageSetupLeft
  387. Public FrmSetupLaunch As PageSetupLaunch
  388. Public FrmSetupUI As PageSetupUI
  389. Public FrmSetupSystem As PageSetupSystem
  390. Public FrmSetupLink As PageSetupLink
  391. '其他页面声明
  392. Public FrmOtherLeft As PageOtherLeft
  393. Public FrmOtherHelp As PageOtherHelp
  394. Public FrmOtherAbout As PageOtherAbout
  395. Public FrmOtherTest As PageOtherTest
  396. '登录页面声明
  397. Public FrmLoginLegacy As PageLoginLegacy
  398. Public FrmLoginNide As PageLoginNide
  399. Public FrmLoginNideSkin As PageLoginNideSkin
  400. Public FrmLoginAuth As PageLoginAuth
  401. Public FrmLoginAuthSkin As PageLoginAuthSkin
  402. Public FrmLoginMs As PageLoginMs
  403. Public FrmLoginMsSkin As PageLoginMsSkin
  404. '版本设置页面声明
  405. Public FrmVersionLeft As PageVersionLeft
  406. Public FrmVersionOverall As PageVersionOverall
  407. Public FrmVersionMod As PageVersionMod
  408. Public FrmVersionModDisabled As PageVersionModDisabled
  409. Public FrmVersionSetup As PageVersionSetup
  410. '资源信息分页声明
  411. Public FrmDownloadCompDetail As PageDownloadCompDetail
  412. #End Region
  413. #Region "帮助"
  414. Public Class HelpEntry
  415. '基础
  416. ''' <summary>
  417. ''' 显示标题。
  418. ''' </summary>
  419. Public Title As String
  420. ''' <summary>
  421. ''' 显示描述。
  422. ''' </summary>
  423. Public Desc As String
  424. ''' <summary>
  425. ''' 检索关键字。
  426. ''' </summary>
  427. Public Search As String
  428. ''' <summary>
  429. ''' 用于分类的标签列表。
  430. ''' </summary>
  431. Public Types As List(Of String)
  432. '显示(可选)
  433. ''' <summary>
  434. ''' 帮助项的自定义图标。可能为 Nothing。
  435. ''' </summary>
  436. Public Logo As String = Nothing
  437. ''' <summary>
  438. ''' 是否显示在搜索结果。默认为 True。
  439. ''' </summary>
  440. Public ShowInSearch As Boolean = True
  441. ''' <summary>
  442. ''' 是否在公开版的 PCL 中显示(这会影响主页与搜索)。默认为 True。
  443. ''' </summary>
  444. Public ShowInPublic As Boolean = True
  445. ''' <summary>
  446. ''' 是否在快照版的 PCL 中显示(这会影响主页与搜索)。默认为 True。
  447. ''' </summary>
  448. Public ShowInSnapshot As Boolean = True
  449. '动作
  450. ''' <summary>
  451. ''' 是否为 “执行事件”。
  452. ''' </summary>
  453. Public IsEvent As Boolean
  454. Public EventType As String
  455. Public EventData As String
  456. ''' <summary>
  457. ''' 若非执行事件,其对应的 .xaml 本地文件内容。
  458. ''' </summary>
  459. Public XamlContent As String
  460. '转换
  461. ''' <summary>
  462. ''' 从文件初始化 HelpEntry 对象,失败会抛出异常。
  463. ''' </summary>
  464. Public Sub New(FilePath As String)
  465. Dim JsonData As JObject = GetJson(HelpArgumentReplace(ReadFile(FilePath)))
  466. If JsonData Is Nothing Then Throw New FileNotFoundException("未找到帮助文件:" & FilePath, FilePath)
  467. '加载常规信息
  468. If JsonData("Title") IsNot Nothing Then
  469. Title = JsonData("Title")
  470. Else
  471. Throw New ArgumentException("未找到 Title 项")
  472. End If
  473. Desc = If(JsonData("Description"), "")
  474. Search = If(JsonData("Keywords"), "")
  475. Logo = JsonData("Logo") '为保持 Nothing,不要加 If
  476. ShowInSearch = If(JsonData("ShowInSearch"), ShowInSearch)
  477. ShowInPublic = If(JsonData("ShowInPublic"), ShowInPublic)
  478. ShowInSnapshot = If(JsonData("ShowInSnapshot"), ShowInSnapshot)
  479. Types = New List(Of String)
  480. For Each NameOfType In If(JsonData("Types"), GetJson("[]"))
  481. Types.Add(NameOfType)
  482. Next
  483. '加载事件信息
  484. If If(JsonData("IsEvent"), False) Then
  485. EventType = JsonData("EventType")
  486. If EventType Is Nothing Then Throw New ArgumentException("未找到 EventType 项")
  487. EventData = If(JsonData("EventData"), "")
  488. IsEvent = True
  489. Else
  490. Dim XamlAddress As String = FilePath.ToLower.Replace(".json", ".xaml")
  491. If File.Exists(XamlAddress) Then
  492. XamlContent = ReadFile(XamlAddress)
  493. IsEvent = False
  494. Else
  495. Throw New FileNotFoundException("未找到帮助条目 .json 对应的 .xaml 文件(" & XamlAddress & ")")
  496. End If
  497. End If
  498. End Sub
  499. ''' <summary>
  500. ''' 获取该 HelpEntry 对应的 MyListItem。
  501. ''' </summary>
  502. Public Function ToListItem() As MyListItem
  503. Return SetToListItem(New MyListItem)
  504. End Function
  505. ''' <summary>
  506. ''' 将属性设置入一个现有的 ListItem。
  507. ''' </summary>
  508. Public Function SetToListItem(Item As MyListItem) As MyListItem
  509. Dim Logo As String
  510. If IsEvent Then
  511. If EventType = "弹出窗口" Then
  512. Logo = PathImage & "Blocks/GrassPath.png"
  513. Else
  514. Logo = PathImage & "Blocks/CommandBlock.png"
  515. End If
  516. Else
  517. Logo = PathImage & "Blocks/Grass.png"
  518. End If
  519. '设置属性
  520. With Item
  521. .SnapsToDevicePixels = True
  522. .Title = Title
  523. .Info = Desc
  524. .Logo = If(Me.Logo, Logo)
  525. .Height = 42
  526. .Type = MyListItem.CheckType.Clickable
  527. .Tag = Me
  528. .EventType = Nothing
  529. .EventData = Nothing
  530. End With
  531. '项目的点击事件
  532. AddHandler Item.Click, Sub(sender, e) PageOtherHelp.OnItemClick(sender.Tag)
  533. Return Item
  534. End Function
  535. End Class
  536. Public HelpLoader As New LoaderTask(Of Integer, List(Of HelpEntry))("Help Page", AddressOf HelpLoad,, ThreadPriority.BelowNormal)
  537. Private ReadOnly HelpLoadLock As New Object
  538. ''' <summary>
  539. ''' 初始化帮助列表对象。
  540. ''' </summary>
  541. Private Sub HelpLoad(Loader As LoaderTask(Of Integer, List(Of HelpEntry)))
  542. SyncLock HelpLoadLock '避免重复解压文件导致出错
  543. Try
  544. '解压内置文件
  545. HelpTryExtract()
  546. '遍历文件
  547. Dim FileList As New List(Of String)
  548. Try
  549. Dim IgnoreList As New List(Of String)
  550. '读取自定义文件
  551. If Directory.Exists(Path & "PCL\Help\") Then
  552. For Each File In EnumerateFiles(Path & "PCL\Help\")
  553. Select Case File.Extension.ToLower
  554. Case ".helpignore"
  555. '加载忽略列表
  556. Log("[Help] 发现 .helpignore 文件:" & File.FullName)
  557. For Each Line In ReadFile(File.FullName).Split(vbCrLf.ToCharArray)
  558. Dim RealString As String = Line.Before("#").Trim
  559. If String.IsNullOrWhiteSpace(RealString) Then Continue For
  560. IgnoreList.Add(RealString)
  561. If ModeDebug Then Log("[Help] > " & RealString)
  562. Next
  563. Case ".json"
  564. FileList.Add(File.FullName)
  565. End Select
  566. Next
  567. End If
  568. Log("[Help] 已扫描 PCL 文件夹下的帮助文件,目前总计 " & FileList.Count & " 条")
  569. '读取自带文件
  570. For Each File In EnumerateFiles(PathTemp & "Help")
  571. '跳过非 json 文件与以 . 开头的文件夹
  572. If File.Extension.ToLower <> ".json" OrElse File.Directory.FullName.Replace(PathTemp & "Help", "").Contains("\.") Then Continue For
  573. '检查忽略列表
  574. Dim RealPath As String = File.FullName.Replace(PathTemp & "Help\", "")
  575. For Each Ignore In IgnoreList
  576. If RegexCheck(RealPath, Ignore) Then
  577. If ModeDebug Then Log("[Help] 已忽略 " & RealPath & ":" & Ignore)
  578. GoTo NextFile
  579. End If
  580. Next
  581. FileList.Add(File.FullName)
  582. NextFile:
  583. Next
  584. Log("[Help] 已扫描缓存文件夹下的帮助文件,目前总计 " & FileList.Count & " 条")
  585. Catch ex As Exception
  586. Log(ex, "检查帮助文件夹失败", LogLevel.Msgbox)
  587. End Try
  588. If Loader.IsAborted Then Exit Sub
  589. '将文件实例化
  590. Dim Dict As New List(Of HelpEntry)
  591. For Each FilePath As String In FileList
  592. Try
  593. Dim Entry As New HelpEntry(FilePath)
  594. Dict.Add(Entry)
  595. If ModeDebug Then Log("[Help] 已加载的帮助条目:" & Entry.Title & " ← " & FilePath)
  596. Catch ex As Exception
  597. Log(ex, "初始化帮助条目失败(" & FilePath & ")", LogLevel.Msgbox)
  598. End Try
  599. Next
  600. '回设
  601. If Not Dict.Any() Then Throw New Exception("未找到可用的帮助;若不需要帮助页面,可以在 设置 → 个性化 → 功能隐藏 中将其隐藏")
  602. If Loader.IsAborted Then Exit Sub
  603. Loader.Output = Dict
  604. Catch ex As Exception
  605. Log(ex, "帮助列表初始化失败")
  606. Throw
  607. End Try
  608. End SyncLock
  609. End Sub
  610. ''' <summary>
  611. ''' 尝试解压内置帮助文件。
  612. ''' </summary>
  613. Public Sub HelpTryExtract()
  614. If Setup.Get("SystemHelpVersion") <> VersionCode OrElse Not File.Exists(PathTemp & "Help\启动器\备份设置.xaml") Then
  615. DeleteDirectory(PathTemp & "Help")
  616. Directory.CreateDirectory(PathTemp & "Help")
  617. WriteFile(PathTemp & "Cache\Help.zip", GetResources("Help"))
  618. ExtractFile(PathTemp & "Cache\Help.zip", PathTemp & "Help", Encoding.UTF8)
  619. Setup.Set("SystemHelpVersion", VersionCode)
  620. Log("[Help] 已解压内置帮助文件,目前状态:" & File.Exists(PathTemp & "Help\启动器\备份设置.xaml"), LogLevel.Debug)
  621. End If
  622. End Sub
  623. ''' <summary>
  624. ''' 对帮助文件约定的替换标记进行处理,如果遇到需要转义的字符会进行转义。
  625. ''' </summary>
  626. Public Function HelpArgumentReplace(Xaml As String) As String
  627. Dim Result = Xaml.Replace("{path}", EscapeXML(Path))
  628. Result = RegexReplaceEach(Result, Function() EscapeXML(PageOtherTest.GetRandomHint()), "\{hint\}")
  629. Result = RegexReplaceEach(Result, Function() EscapeXML(PageOtherTest.GetRandomCave()), "\{cave\}")
  630. Return Result
  631. End Function
  632. #End Region
  633. #Region "愚人节"
  634. Public IsAprilEnabled As Boolean = Date.Now.Month = 4 AndAlso Date.Now.Day = 1
  635. Public IsAprilGiveup As Boolean = False
  636. Private AprilSpeed As New Vector(0, 0)
  637. Private AprilIdieCount As Integer = 0, AprilMousePosLast As New Point(0, 0)
  638. Private AprilDistance As Integer = 0
  639. Private Sub TimerFool()
  640. Try
  641. If FrmLaunchLeft Is Nothing OrElse FrmLaunchLeft.AprilPosTrans Is Nothing OrElse FrmMain.lastMouseArg Is Nothing Then Exit Sub
  642. If IsAprilGiveup OrElse FrmMain.PageCurrent <> FormMain.PageType.Launch OrElse AniControlEnabled <> 0 OrElse Not FrmLaunchLeft.BtnLaunch.IsLoaded Then Exit Sub
  643. '计算是否空闲
  644. Dim MousePos = FrmMain.lastMouseArg.GetPosition(FrmMain)
  645. If MousePos = AprilMousePosLast Then
  646. AprilIdieCount += 1
  647. Else
  648. AprilMousePosLast = MousePos
  649. AprilIdieCount = 0
  650. End If
  651. '计算躲避移动
  652. Dim Direction As Vector
  653. Dim Distance As Double
  654. Dim ButtonWidth = FrmLaunchLeft.BtnLaunch.ActualWidth / 2, ButtonHeight = FrmLaunchLeft.BtnLaunch.ActualHeight / 2
  655. Dim Vec As Vector = FrmMain.lastMouseArg.GetPosition(FrmLaunchLeft.BtnLaunch) - New Vector(ButtonWidth, ButtonHeight)
  656. Dim Dir As New Vector(Vec.X, Vec.Y)
  657. Dir.Normalize()
  658. Direction = -Dir
  659. Distance = New Vector(Math.Max(0, Math.Abs(Vec.X) - ButtonWidth), Math.Max(0, Math.Abs(Vec.Y) - ButtonHeight)).Length
  660. Dim BreathScale = Math.Sin(Timer150Count / 37.5 * Math.PI)
  661. Dim Acc = Math.Max(0, BreathScale * 0.25 - 0.65 - Math.Log((Distance + 0.4) / 200)) * Direction '加速度
  662. '计算回归移动
  663. If AprilIdieCount >= 64 * 5 Then
  664. Dim SafeDist As Vector = FrmMain.lastMouseArg.GetPosition(FrmMain.PanMain) - New Vector(ButtonWidth, FrmMain.PanMain.ActualHeight - ButtonHeight * 3)
  665. Dim Back As New Vector(FrmLaunchLeft.AprilPosTrans.X, FrmLaunchLeft.AprilPosTrans.Y)
  666. If SafeDist.Length > 250 AndAlso Back.Length > 0.4 Then
  667. Acc -= Back * 0.0005
  668. Back.Normalize()
  669. Acc -= Back * 0.15
  670. End If
  671. End If
  672. '回到边界
  673. Dim Relative As Point = FrmLaunchLeft.BtnLaunch.TranslatePoint(New Point(0, 0), FrmMain.PanForm)
  674. If Relative.X < -ButtonWidth * 2 Then
  675. FrmLaunchLeft.AprilPosTrans.X += FrmMain.PanForm.ActualWidth + ButtonWidth * 2 '离开左边界
  676. AprilSpeed.X -= 80
  677. If Relative.Y < 0 Then
  678. FrmLaunchLeft.AprilPosTrans.Y += ButtonHeight * 2.5
  679. ElseIf Relative.Y > FrmMain.PanForm.ActualHeight - ButtonHeight * 2 Then
  680. FrmLaunchLeft.AprilPosTrans.Y -= ButtonHeight * 2.5
  681. End If
  682. ElseIf Relative.X > FrmMain.PanForm.ActualWidth Then
  683. FrmLaunchLeft.AprilPosTrans.X -= FrmMain.PanForm.ActualWidth + ButtonWidth * 2 '离开右边界
  684. AprilSpeed.X += 80
  685. If Relative.Y < 0 Then
  686. FrmLaunchLeft.AprilPosTrans.Y += ButtonHeight * 2.5
  687. ElseIf Relative.Y > FrmMain.PanForm.ActualHeight - ButtonHeight * 2 Then
  688. FrmLaunchLeft.AprilPosTrans.Y -= ButtonHeight * 2.5
  689. End If
  690. ElseIf Relative.Y < -ButtonHeight * 2 Then
  691. FrmLaunchLeft.AprilPosTrans.Y += FrmMain.PanForm.ActualHeight + ButtonHeight * 2 '离开上边界
  692. AprilSpeed.Y -= 25
  693. If Relative.X < 0 Then
  694. FrmLaunchLeft.AprilPosTrans.X += ButtonWidth * 2
  695. ElseIf Relative.X > FrmMain.PanForm.ActualWidth - ButtonWidth * 2 Then
  696. FrmLaunchLeft.AprilPosTrans.X -= ButtonWidth * 2
  697. End If
  698. ElseIf Relative.Y > FrmMain.PanForm.ActualHeight Then
  699. FrmLaunchLeft.AprilPosTrans.Y -= FrmMain.PanForm.ActualHeight + ButtonHeight * 2 '离开下边界
  700. AprilSpeed.Y += 25
  701. If Relative.X < 0 Then
  702. FrmLaunchLeft.AprilPosTrans.X += ButtonWidth * 2
  703. ElseIf Relative.X > FrmMain.PanForm.ActualWidth - ButtonWidth * 2 Then
  704. FrmLaunchLeft.AprilPosTrans.X -= ButtonWidth * 2
  705. End If
  706. End If
  707. '移动
  708. AprilSpeed = AprilSpeed * 0.8 + Acc
  709. Dim SpeedValue = Math.Min(60, AprilSpeed.Length)
  710. If SpeedValue < 0.01 Then Exit Sub
  711. AprilSpeed.Normalize()
  712. AprilSpeed *= SpeedValue
  713. AprilDistance += SpeedValue
  714. FrmLaunchLeft.AprilPosTrans.X += AprilSpeed.X
  715. FrmLaunchLeft.AprilPosTrans.Y += AprilSpeed.Y
  716. '大小改变
  717. FrmLaunchLeft.AprilScaleTrans.ScaleX = MathClamp(1 - (Math.Abs(Direction.X) - Math.Abs(Direction.Y)) * (SpeedValue / 160), 0.2, 1.8)
  718. FrmLaunchLeft.AprilScaleTrans.ScaleY = MathClamp(1 - (Math.Abs(Direction.Y) - Math.Abs(Direction.X)) * (SpeedValue / 100), 0.2, 1.8)
  719. '放弃提示
  720. If AprilDistance > 4000 Then
  721. AprilDistance = -4000
  722. Select Case RandomInteger(0, 3)
  723. Case 0
  724. Hint("放弃吧!只需要点一下右下角的小白旗……")
  725. Case 1
  726. Hint("看到右下角的那面小白旗了吗?")
  727. Case 2
  728. Hint("这里建议点一下右下角的小白旗投降呢.jpg")
  729. Case 3
  730. Hint("右下角的小白旗永远等着你……")
  731. End Select
  732. End If
  733. Catch ex As Exception
  734. Log(ex, "愚人节移动出错", LogLevel.Feedback)
  735. End Try
  736. End Sub
  737. #End Region
  738. #Region "系统"
  739. ''' <summary>
  740. ''' 把某个 PCL 窗口拖到最前面。
  741. ''' </summary>
  742. Public Sub ShowWindowToTop(Handle As IntPtr)
  743. Try
  744. PostMessage(Handle, 400 * 16 + 2, 0, 0)
  745. SetForegroundWindow(Handle) '不在这里放不行,神秘 WinAPI,建议别动
  746. Catch ex As Exception
  747. Log(ex, "设置窗口置顶失败", LogLevel.Hint)
  748. End Try
  749. End Sub
  750. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ClassName As String, WindowName As String) As IntPtr
  751. Public Declare Function SetForegroundWindow Lib "user32" (hWnd As IntPtr) As Integer
  752. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (hWnd As IntPtr, msg As UInteger, wParam As Long, lParam As Long) As Boolean
  753. #End Region
  754. Public DragControl = Nothing
  755. Private Timer4Count As Integer = 0
  756. Private Timer150Count As Integer = 0
  757. Private Sub TimerMain()
  758. Try
  759. #Region "每 50ms 执行一次的代码"
  760. HintTick()
  761. MyMsgBoxTick()
  762. FrmMain.DragTick()
  763. LoaderTaskbarProgressRefresh()
  764. If ThemeDontClick = 2 Then ThemeRefresh()
  765. #End Region
  766. Catch ex As Exception
  767. Log(ex, "短程主时钟执行异常", LogLevel.Assert)
  768. End Try
  769. Timer4Count += 1
  770. If Timer4Count = 4 Then
  771. Timer4Count = 0
  772. Try
  773. #Region "每 250ms 执行一次的代码"
  774. If ThemeNow = 12 Then ThemeRefresh()
  775. #End Region
  776. Catch ex As Exception
  777. Log(ex, "中程主时钟执行异常", LogLevel.Debug)
  778. End Try
  779. End If
  780. Timer150Count += 1
  781. If Timer150Count = 150 Then
  782. Timer150Count = 0
  783. Try
  784. #Region "每 7.5s 执行一次的代码"
  785. If FrmMain.BtnExtraApril_ShowCheck AndAlso AprilDistance <> 0 Then FrmMain.BtnExtraApril.Ribble()
  786. '以未知原因窗口被丢到一边去的修复(Top、Left = -25600),还有 #745
  787. RunInUi(Sub()
  788. If Not FrmMain.Hidden Then
  789. If FrmMain.Top < -9000 Then FrmMain.Top = 100
  790. If FrmMain.Left < -9000 Then FrmMain.Left = 100 '窗口拉至最大时 Left = -18.8
  791. End If
  792. End Sub)
  793. #End Region
  794. Catch ex As Exception
  795. Log(ex, "长程主时钟执行异常", LogLevel.Assert)
  796. End Try
  797. End If
  798. End Sub
  799. Public Sub TimerMainStart()
  800. RunInNewThread(
  801. Sub()
  802. Try
  803. Do While True
  804. RunInUiWait(AddressOf TimerMain)
  805. Thread.Sleep(50 * 0.98)
  806. Loop
  807. Catch ex As Exception
  808. Log(ex, "程序主时钟出错", LogLevel.Feedback)
  809. End Try
  810. End Sub, "Timer Main")
  811. If Not IsAprilEnabled Then Exit Sub
  812. RunInNewThread(
  813. Sub()
  814. Try
  815. Dim LastTime = My.Computer.Clock.TickCount
  816. Do While True
  817. If LastTime <> My.Computer.Clock.TickCount Then
  818. LastTime = My.Computer.Clock.TickCount
  819. RunInUiWait(AddressOf TimerFool)
  820. End If
  821. Thread.Sleep(1)
  822. Loop
  823. Catch ex As Exception
  824. Log(ex, "愚人节主时钟出错", LogLevel.Feedback)
  825. End Try
  826. End Sub, "Timer Main Fool")
  827. End Sub
  828. End Module