diff --git a/PCL.Core/App/CustomVarible.cs b/PCL.Core/App/CustomVarible.cs deleted file mode 100644 index 578e06af4..000000000 --- a/PCL.Core/App/CustomVarible.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.Json.Nodes; - -namespace PCL.Core.App; - -public class CustomVarible -{ - /// - /// 自定义主页变量保存路径。 - /// - public static string VaribleJsonPath { get; } = Path.Combine(Paths.SharedData, "varibles.json"); - - /// - /// 存放所有自定义主页变量的 JSON 对象。 - /// - public static JsonNode? VaribleJson; - - public static Dictionary VaribleDict = new(); - - public static void Set(string key, string value) - { - - } - - public static void Get(string key, string value) - { - - } - - public static void Init() - { - if (!File.Exists(VaribleJsonPath)) - { - File.Create(VaribleJsonPath).Close(); - } - else - { - try - { - VaribleJson = JsonNode.Parse(File.ReadAllText(VaribleJsonPath)); - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } - } - } -} \ No newline at end of file diff --git a/PCL.Core/App/States.cs b/PCL.Core/App/States.cs index 7e697a41f..f1c926a81 100644 --- a/PCL.Core/App/States.cs +++ b/PCL.Core/App/States.cs @@ -1,4 +1,5 @@ -using PCL.Core.App.Configuration; +using System.Collections.Generic; +using PCL.Core.App.Configuration; namespace PCL.Core.App; @@ -12,6 +13,11 @@ public static partial class States /// 唯一标识符。 /// [ConfigItem("Identify", "")] public static partial string Identifier { get; set; } + + /// + /// 自定义变量。 + /// + [AnyConfigItem>("CustomVariables", ConfigSource.Local)] public static partial Dictionary CustomVariables { get; set; } /// /// 提示状态。 diff --git a/Plain Craft Launcher 2/Controls/MyButton.xaml.vb b/Plain Craft Launcher 2/Controls/MyButton.xaml.vb index 94a0677d4..992673e57 100644 --- a/Plain Craft Launcher 2/Controls/MyButton.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyButton.xaml.vb @@ -140,39 +140,14 @@ Public Class MyButton End Try End Sub - '实现自定义事件 + '鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行) + Private IsMouseDown As Boolean = False Private Sub Button_MouseUp(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp If Not IsMouseDown Then Return Log("[Control] 按下按钮:" & Text) RaiseEvent Click(sender, e) - If Not String.IsNullOrEmpty(Tag) Then - If Tag.ToString.StartsWithF("链接-") OrElse Tag.ToString.StartsWithF("启动-") Then - Hint("主页自定义按钮语法已更新,且不再兼容老版本语法,请查看新的自定义示例!") - End If - End If - ModEvent.TryStartEvent(EventType, EventData) + RaiseCustomEvent() '自定义事件 End Sub - Public Property EventType As String - Get - Return GetValue(EventTypeProperty) - End Get - Set(value As String) - SetValue(EventTypeProperty, value) - End Set - End Property - Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyButton), New PropertyMetadata(Nothing)) - Public Property EventData As String - Get - Return GetValue(EventDataProperty) - End Get - Set(value As String) - SetValue(EventDataProperty, value) - End Set - End Property - Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyButton), New PropertyMetadata(Nothing)) - - '鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行) - Private IsMouseDown As Boolean = False Private Sub Button_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown IsMouseDown = True Focus() diff --git a/Plain Craft Launcher 2/Controls/MyCard.vb b/Plain Craft Launcher 2/Controls/MyCard.vb index 4b3f31047..8b615bf67 100644 --- a/Plain Craft Launcher 2/Controls/MyCard.vb +++ b/Plain Craft Launcher 2/Controls/MyCard.vb @@ -296,9 +296,6 @@ Public Class MyCard End Property Private _IsSwapped As Boolean = False - ''' - ''' 是否已被折叠。(已过时,请使用 IsSwapped) - ''' Public Property IsSwaped As Boolean Get @@ -310,37 +307,45 @@ Public Class MyCard End Property Public Property SwapLogoRight As Boolean = False - Private IsMouseDown As Boolean = False + Private IsSwapMouseDown As Boolean = False '用于触发卡片展开/折叠的 MouseDown + Private IsCustomMouseDown As Boolean = False '用于触发自定义事件的 MouseDown Public Event PreviewSwap(sender As Object, e As RouteEventArgs) Public Event Swap(sender As Object, e As RouteEventArgs) Public Const SwapedHeight As Integer = 40 Private Sub MyCard_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown Dim Pos As Double = Mouse.GetPosition(Me).Y If Not IsSwapped AndAlso - (SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判 - IsMouseDown = True + (Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return + IsCustomMouseDown = True + If Not IsSwapped AndAlso + (SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判 + IsSwapMouseDown = True End Sub - Private Sub MyCard_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp - If Not IsMouseDown Then Return - IsMouseDown = False + Private Sub MyCard_MouseLeftButtonUp() Handles Me.MouseLeftButtonUp + If Not IsCustomMouseDown Then Return + IsCustomMouseDown = False + RaiseCustomEvent() '触发自定义事件 + + If Not IsSwapMouseDown Then Return + IsSwapMouseDown = False Dim Pos As Double = Mouse.GetPosition(Me).Y If Not IsSwapped AndAlso - (SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判 + (SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判 - Dim ee = New RouteEventArgs(True) - RaiseEvent PreviewSwap(Me, ee) - If ee.Handled Then - IsMouseDown = False + Dim e = New RouteEventArgs(True) + RaiseEvent PreviewSwap(Me, e) + If e.Handled Then + IsSwapMouseDown = False Return End If IsSwapped = Not IsSwapped Log("[Control] " & If(IsSwapped, "折叠卡片", "展开卡片") & If(Title Is Nothing, "", ":" & Title)) - RaiseEvent Swap(Me, ee) + RaiseEvent Swap(Me, e) End Sub Private Sub MyCard_MouseLeave_Swap(sender As Object, e As MouseEventArgs) Handles Me.MouseLeave - IsMouseDown = False + IsSwapMouseDown = False End Sub #End Region diff --git a/Plain Craft Launcher 2/Controls/MyCheckBox.xaml.vb b/Plain Craft Launcher 2/Controls/MyCheckBox.xaml.vb index c0e62f140..249be46a9 100644 --- a/Plain Craft Launcher 2/Controls/MyCheckBox.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyCheckBox.xaml.vb @@ -12,9 +12,6 @@ Public Class MyCheckBox ''' 是否为用户手动改变的勾选状态。 Public Event Change(sender As Object, user As Boolean) Public Event PreviewChange(sender As Object, e As RouteEventArgs) - Public Sub RaiseChange() - RaiseEvent Change(Me, False) - End Sub '使外部程序引发本控件的 Change 事件 '自定义属性 Public Property Checked As Boolean? @@ -78,6 +75,7 @@ Public Class MyCheckBox '更改动画 SyncUI() + RaiseCustomEvent() Catch ex As Exception Log(ex, "设置 Checked 失败") End Try diff --git a/Plain Craft Launcher 2/Controls/MyComboBox.vb b/Plain Craft Launcher 2/Controls/MyComboBox.vb index ff1bf2150..f58f41156 100644 --- a/Plain Craft Launcher 2/Controls/MyComboBox.vb +++ b/Plain Craft Launcher 2/Controls/MyComboBox.vb @@ -133,15 +133,14 @@ Private IsTextChanging As Boolean = False Private Sub MyComboBox_TextChanged(sender As Object, e As TextChangedEventArgs) Handles Me.TextChanged If IsTextChanging OrElse Not IsEditable Then Return - If SelectedItem IsNot Nothing AndAlso Text <> SelectedItem.ToString Then - Dim RawText As String = Text - Dim RawSelectionStart As Integer = TextBox.SelectionStart - IsTextChanging = True - SelectedItem = Nothing - Text = RawText - TextBox.SelectionStart = RawSelectionStart - IsTextChanging = False - End If + If SelectedItem Is Nothing OrElse Text = SelectedItem.ToString Then Return + Dim rawText As String = Text + Dim rawSelectionStart As Integer = TextBox.SelectionStart + IsTextChanging = True + SelectedItem = Nothing + Text = rawText + TextBox.SelectionStart = rawSelectionStart + IsTextChanging = False End Sub Public ReadOnly Property ContentPresenter As ContentPresenter @@ -149,6 +148,10 @@ Return Template.FindName("PART_Content", Me) End Get End Property + + Private Sub MyComboBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles Me.SelectionChanged + If IsLoaded AndAlso AniControlEnabled = 0 Then RaiseCustomEvent() + End Sub '用于 ItemsSource 的自定义容器 Protected Overrides Function GetContainerForItemOverride() As DependencyObject diff --git a/Plain Craft Launcher 2/Controls/MyExtraButton.xaml.vb b/Plain Craft Launcher 2/Controls/MyExtraButton.xaml.vb index 0bb1b3a35..033893d8f 100644 --- a/Plain Craft Launcher 2/Controls/MyExtraButton.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyExtraButton.xaml.vb @@ -53,25 +53,26 @@ Set(value As Boolean) If _Show = value Then Return _Show = value - RunInUi(Sub() - If value Then - '有了 - Visibility = Visibility.Visible - AniStart({ - AaScaleTransform(Me, 0.3 - CType(RenderTransform, ScaleTransform).ScaleX, 500, 60, New AniEaseOutFluent(AniEasePower.Weak)), - AaScaleTransform(Me, 0.7, 500, 60, New AniEaseOutBack(AniEasePower.Weak)), - AaHeight(Me, 50 - Height, 200,, New AniEaseOutFluent(AniEasePower.Weak)) - }, "MyExtraButton MainScale " & Uuid) - Else - '没了 - AniStart({ - AaScaleTransform(Me, -CType(RenderTransform, ScaleTransform).ScaleX, 100,, New AniEaseInFluent(AniEasePower.Weak)), - AaHeight(Me, -Height, 400, 100, New AniEaseOutFluent()), - AaCode(Sub() Visibility = Visibility.Collapsed,, True) - }, "MyExtraButton MainScale " & Uuid) - End If - IsHitTestVisible = value '防止缩放动画中依然可以点进去 - End Sub) + RunInUi( + Sub() + If value Then + '有了 + Visibility = Visibility.Visible + AniStart({ + AaScaleTransform(Me, 0.3 - CType(RenderTransform, ScaleTransform).ScaleX, 500, 60, New AniEaseOutFluent(AniEasePower.Weak)), + AaScaleTransform(Me, 0.7, 500, 60, New AniEaseOutBack(AniEasePower.Weak)), + AaHeight(Me, 50 - Height, 200,, New AniEaseOutFluent(AniEasePower.Weak)) + }, "MyExtraButton MainScale " & Uuid) + Else + '没了 + AniStart({ + AaScaleTransform(Me, -CType(RenderTransform, ScaleTransform).ScaleX, 100,, New AniEaseInFluent(AniEasePower.Weak)), + AaHeight(Me, -Height, 400, 100, New AniEaseOutFluent()), + AaCode(Sub() Visibility = Visibility.Collapsed,, True) + }, "MyExtraButton MainScale " & Uuid) + End If + IsHitTestVisible = value '防止缩放动画中依然可以点进去 + End Sub) End Set End Property Public Delegate Function ShowCheckDelegate() As Boolean @@ -137,6 +138,7 @@ AaScaleTransform(PanScale, 1 - CType(PanScale.RenderTransform, ScaleTransform).ScaleX, 300,, New AniEaseOutBack) }, "MyExtraButton Scale " & Uuid) End If + If IsLeftMouseHeld Then RaiseCustomEvent() IsLeftMouseHeld = False RefreshColor() '直接刷新颜色以判断是否已触发 MouseLeave End Sub @@ -199,16 +201,17 @@ ''' 发出一圈波浪效果提示。 ''' Public Sub Ribble() - RunInUi(Sub() - Dim Shape As New Border With {.CornerRadius = New CornerRadius(1000), .BorderThickness = New Thickness(0.001), .Opacity = 0.5, .RenderTransformOrigin = New Point(0.5, 0.5), .RenderTransform = New ScaleTransform()} - Shape.SetResourceReference(Border.BackgroundProperty, "ColorBrush5") - PanScale.Children.Insert(0, Shape) - AniStart({ - AaScaleTransform(Shape, 13, 1000, Ease:=New AniEaseInoutFluent(AniEasePower.Strong, 0.3)), - AaOpacity(Shape, -Shape.Opacity, 1000), - AaCode(Sub() PanScale.Children.Remove(Shape), After:=True) - }, "ExtraButton Ribble " & GetUuid()) - End Sub) + RunInUi( + Sub() + Dim shape As New Border With {.CornerRadius = New CornerRadius(1000), .BorderThickness = New Thickness(0.001), .Opacity = 0.5, .RenderTransformOrigin = New Point(0.5, 0.5), .RenderTransform = New ScaleTransform()} + shape.SetResourceReference(Border.BackgroundProperty, "ColorBrush5") + PanScale.Children.Insert(0, shape) + AniStart({ + AaScaleTransform(shape, 13, 1000, Ease:=New AniEaseInoutFluent(AniEasePower.Strong, 0.3)), + AaOpacity(shape, -shape.Opacity, 1000), + AaCode(Sub() PanScale.Children.Remove(shape), After:=True) + }, "ExtraButton Ribble " & GetUuid()) + End Sub) End Sub End Class diff --git a/Plain Craft Launcher 2/Controls/MyExtraTextButton.xaml.vb b/Plain Craft Launcher 2/Controls/MyExtraTextButton.xaml.vb index 9784cd08a..266ba4778 100644 --- a/Plain Craft Launcher 2/Controls/MyExtraTextButton.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyExtraTextButton.xaml.vb @@ -81,12 +81,12 @@ Public Class MyExtraTextButton '触发点击事件 Private Sub Button_LeftMouseUp(sender As Object, e As MouseButtonEventArgs) Handles PanClick.MouseLeftButtonUp - If IsLeftMouseHeld Then - Log("[Control] 按下附加图标按钮:" & Text) - RaiseEvent Click(sender, e) - e.Handled = True - Button_LeftMouseUp() - End If + If Not IsLeftMouseHeld Then Return + Log("[Control] 按下附加图标按钮:" & Text) + RaiseEvent Click(sender, e) + e.Handled = True + RaiseCustomEvent() + Button_LeftMouseUp() End Sub '鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行) diff --git a/Plain Craft Launcher 2/Controls/MyHint.xaml.vb b/Plain Craft Launcher 2/Controls/MyHint.xaml.vb index 450c2e2e0..781e4c9d9 100644 --- a/Plain Craft Launcher 2/Controls/MyHint.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyHint.xaml.vb @@ -113,7 +113,7 @@ Public Class MyHint IsMouseDown = False Log("[Control] 按下提示条" & If(String.IsNullOrEmpty(Name), "", ":" & Name)) e.Handled = True - ModEvent.TryStartEvent(EventType, EventData) + RaiseCustomEvent() '自定义事件 End Sub Private Sub MyHint_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown IsMouseDown = True @@ -121,24 +121,6 @@ Public Class MyHint Private Sub MyHint_MouseLeave() Handles Me.MouseLeave IsMouseDown = False End Sub - Public Property EventType As String - Get - Return GetValue(EventTypeProperty) - End Get - Set(value As String) - SetValue(EventTypeProperty, value) - End Set - End Property - Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyHint), New PropertyMetadata(Nothing)) - Public Property EventData As String - Get - Return GetValue(EventDataProperty) - End Get - Set(value As String) - SetValue(EventDataProperty, value) - End Set - End Property - Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyHint), New PropertyMetadata(Nothing)) Private Sub _ThemeChanged(isDarkMode As Boolean, theme As ColorTheme) UpdateUI() diff --git a/Plain Craft Launcher 2/Controls/MyIconButton.xaml.vb b/Plain Craft Launcher 2/Controls/MyIconButton.xaml.vb index 154c2de1c..9fb5ad8c6 100644 --- a/Plain Craft Launcher 2/Controls/MyIconButton.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyIconButton.xaml.vb @@ -48,36 +48,16 @@ End Set End Property - '触发点击事件 + '鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行) + Private IsMouseDown As Boolean = False Private Sub Button_MouseUp(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp If Not IsMouseDown Then Return Log("[Control] 按下图标按钮" & If(String.IsNullOrEmpty(Name), "", ":" & Name)) RaiseEvent Click(sender, e) e.Handled = True Button_MouseUp() - ModEvent.TryStartEvent(EventType, EventData) + RaiseCustomEvent() '自定义事件 End Sub - Public Property EventType As String - Get - Return GetValue(EventTypeProperty) - End Get - Set(value As String) - SetValue(EventTypeProperty, value) - End Set - End Property - Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyIconButton), New PropertyMetadata(Nothing)) - Public Property EventData As String - Get - Return GetValue(EventDataProperty) - End Get - Set(value As String) - SetValue(EventDataProperty, value) - End Set - End Property - Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyIconButton), New PropertyMetadata(Nothing)) - - '鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行) - Private IsMouseDown As Boolean = False Private Sub Button_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown IsMouseDown = True Focus() @@ -101,8 +81,7 @@ }, "MyIconButton Scale " & Uuid) RefreshAnim() '直接刷新颜色以判断是否已触发 MouseLeave End Sub - - '自定义事件 + '务必放在 IsMouseDown 更新之后 Private Const AnimationColorIn As Integer = 120 Private Const AnimationColorOut As Integer = 150 diff --git a/Plain Craft Launcher 2/Controls/MyIconTextButton.xaml.vb b/Plain Craft Launcher 2/Controls/MyIconTextButton.xaml.vb index 47fdbf963..dd5ed21e7 100644 --- a/Plain Craft Launcher 2/Controls/MyIconTextButton.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyIconTextButton.xaml.vb @@ -8,9 +8,6 @@ Public Class MyIconTextButton Public Uuid As Integer = GetUuid() Public Event Check(sender As Object, raiseByMouse As Boolean) Public Event Change(sender As Object, raiseByMouse As Boolean) - Public Sub RaiseChange() - RaiseEvent Change(Me, False) - End Sub '使外部程序可以引发本控件的 Change 事件 '自定义属性 @@ -76,7 +73,7 @@ Public Class MyIconTextButton Log("[Control] 按下带图标按钮:" & Text) IsMouseDown = False RaiseEvent Click(Me, New RouteEventArgs(True)) - ModEvent.TryStartEvent(EventType, EventData) + RaiseCustomEvent() '自定义事件 RefreshColor() End Sub Private Sub MyIconTextButton_MouseDown() Handles Me.MouseLeftButtonDown @@ -87,24 +84,6 @@ Public Class MyIconTextButton IsMouseDown = False RefreshColor() End Sub - Public Property EventType As String - Get - Return GetValue(EventTypeProperty) - End Get - Set(value As String) - SetValue(EventTypeProperty, value) - End Set - End Property - Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyIconTextButton), New PropertyMetadata(Nothing)) - Public Property EventData As String - Get - Return GetValue(EventDataProperty) - End Get - Set(value As String) - SetValue(EventDataProperty, value) - End Set - End Property - Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyIconTextButton), New PropertyMetadata(Nothing)) '动画 diff --git a/Plain Craft Launcher 2/Controls/MyListItem.xaml.vb b/Plain Craft Launcher 2/Controls/MyListItem.xaml.vb index 531c9b8ff..4ee7340ef 100644 --- a/Plain Craft Launcher 2/Controls/MyListItem.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyListItem.xaml.vb @@ -580,8 +580,8 @@ Public Class MyListItem RaiseEvent Click(sender, e) If e.Handled Then Return '触发自定义事件 - If Not String.IsNullOrEmpty(EventType) Then - ModEvent.TryStartEvent(EventType, EventData) + If CustomEventService.GetEventType(sender) <> CustomEvent.EventType.None Then + RaiseCustomEvent() e.Handled = True End If If e.Handled Then Return @@ -611,26 +611,6 @@ Public Class MyListItem If ButtonStack IsNot Nothing Then ButtonStack.IsHitTestVisible = True End Sub - '实现自定义事件 - Public Property EventType As String - Get - Return GetValue(EventTypeProperty) - End Get - Set(value As String) - SetValue(EventTypeProperty, value) - End Set - End Property - Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyListItem), New PropertyMetadata(Nothing)) - Public Property EventData As String - Get - Return GetValue(EventDataProperty) - End Get - Set(value As String) - SetValue(EventDataProperty, value) - End Set - End Property - Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyListItem), New PropertyMetadata(Nothing)) - #End Region Private StateLast As String @@ -731,13 +711,14 @@ Public Class MyListItem SetResourceReference(ForegroundProperty, "ColorBrush1") End If ColumnPaddingRight.Width = New GridLength(MinPaddingRight) - If EventType = "打开帮助" AndAlso Not (Title <> "" AndAlso Info <> "") Then '#3266 + If CustomEventService.GetEventType(Me) = CustomEvent.EventType.打开帮助 AndAlso Not (Title <> "" AndAlso Info <> "") Then '#3266 Try - Dim Unused = New HelpEntry(GetEventAbsoluteUrls(EventData, EventType)(0)).SetToListItem(Me) + Dim Entry As New HelpEntry(CustomEvent.GetAbsoluteUrls(CustomEventService.GetEventData(Me), CustomEventService.GetEventType(Me))(0)) + Entry.SetToListItem(Me) Catch ex As Exception Log(ex, "设置帮助 MyListItem 失败", LogLevel.Msgbox) - EventType = Nothing - EventData = Nothing + CustomEventService.SetEventType(Me, CustomEvent.EventType.None) + CustomEventService.SetEventData(Me, "") End Try End If End Sub diff --git a/Plain Craft Launcher 2/Controls/MyMenuItem.vb b/Plain Craft Launcher 2/Controls/MyMenuItem.vb index cc70ee6cd..4c22da392 100644 --- a/Plain Craft Launcher 2/Controls/MyMenuItem.vb +++ b/Plain Craft Launcher 2/Controls/MyMenuItem.vb @@ -54,4 +54,7 @@ End If End Sub + Private Sub MyMenuItem_Click(sender As Object, e As RoutedEventArgs) Handles Me.Click + RaiseCustomEvent() + End Sub End Class diff --git a/Plain Craft Launcher 2/Controls/MyRadioBox.xaml.vb b/Plain Craft Launcher 2/Controls/MyRadioBox.xaml.vb index 5dd839f94..ba77d6fab 100644 --- a/Plain Craft Launcher 2/Controls/MyRadioBox.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyRadioBox.xaml.vb @@ -93,6 +93,7 @@ Public Class MyRadioBox If IsChanged Then If Checked Then RaiseEvent Check(Me, New RouteEventArgs(user)) RaiseEvent Changed(Me, New RouteEventArgs(user)) + RaiseCustomEvent() End If '更改动画 diff --git a/Plain Craft Launcher 2/Controls/MyRadioButton.xaml.vb b/Plain Craft Launcher 2/Controls/MyRadioButton.xaml.vb index 3f4e9613b..b4cdf82b7 100644 --- a/Plain Craft Launcher 2/Controls/MyRadioButton.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MyRadioButton.xaml.vb @@ -7,10 +7,6 @@ Public Class MyRadioButton Public Uuid As Integer = GetUuid() Public Event Check(sender As Object, raiseByMouse As Boolean) - Public Event Change(sender As Object, raiseByMouse As Boolean) - Public Sub RaiseChange() - RaiseEvent Change(Me, False) - End Sub '使外部程序可以引发本控件的 Change 事件 '自定义属性 @@ -46,23 +42,22 @@ Public Class MyRadioButton ''' 手动设置 Checked 属性。 ''' ''' 新的 Checked 属性。 - ''' 是否由用户引发。 + ''' 是否由用户引发。 ''' 是否执行动画。 - Public Sub SetChecked(value As Boolean, user As Boolean, anime As Boolean) + Public Sub SetChecked(value As Boolean, raiseByMouse As Boolean, anime As Boolean) Try '自定义属性基础 Dim IsChanged As Boolean = False - If IsLoaded AndAlso Not value = _Checked Then RaiseEvent Change(Me, user) - If Not value = _Checked Then + If _Checked <> value Then _Checked = value IsChanged = True End If '保证只有一个单选框选中 - If IsNothing(Parent) Then Return + If Parent Is Nothing Then Return Dim RadioboxList As New List(Of MyRadioButton) Dim CheckedCount As Integer = 0 '收集控件列表与选中个数 @@ -105,8 +100,8 @@ Public Class MyRadioButton RefreshColor(Nothing, anime) '触发事件 - If Checked Then RaiseEvent Check(Me, user) - + If Checked Then RaiseEvent Check(Me, raiseByMouse) + RaiseCustomEvent() Catch ex As Exception Log(ex, "单选按钮勾选改变错误", LogLevel.Hint) End Try diff --git a/Plain Craft Launcher 2/Controls/MySearchBox.xaml.vb b/Plain Craft Launcher 2/Controls/MySearchBox.xaml.vb index b8e04ba0a..4d4eaa40b 100644 --- a/Plain Craft Launcher 2/Controls/MySearchBox.xaml.vb +++ b/Plain Craft Launcher 2/Controls/MySearchBox.xaml.vb @@ -6,6 +6,10 @@ TextBox.Focus() End Sub + Private Sub MySearchBox_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp + If e.Key = Key.Enter Then RaiseCustomEvent() + End Sub + '属性 Public Property HintText() As String Get diff --git a/Plain Craft Launcher 2/Controls/MyTextBox.vb b/Plain Craft Launcher 2/Controls/MyTextBox.vb index e847a5874..4d3d9ee5a 100644 --- a/Plain Craft Launcher 2/Controls/MyTextBox.vb +++ b/Plain Craft Launcher 2/Controls/MyTextBox.vb @@ -291,4 +291,9 @@ End If End Sub + '在按下回车时触发自定义事件 + Private Sub MyTextBox_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp + If e.Key = Key.Enter Then RaiseCustomEvent() + End Sub + End Class diff --git a/Plain Craft Launcher 2/Controls/MyTextButton.vb b/Plain Craft Launcher 2/Controls/MyTextButton.vb index 687ab88af..4bde410b0 100644 --- a/Plain Craft Launcher 2/Controls/MyTextButton.vb +++ b/Plain Craft Launcher 2/Controls/MyTextButton.vb @@ -22,15 +22,15 @@ End Set End Property Public Shared ReadOnly TextProperty As DependencyProperty = - DependencyProperty.Register("Text", GetType(String), GetType(MyTextButton), New PropertyMetadata("", Sub(sender As MyTextButton, e As DependencyPropertyChangedEventArgs) - If Not e.OldValue = e.NewValue Then - AniStart({ - AaOpacity(sender, -sender.Opacity, 50), - AaCode(Sub() sender.Content = e.NewValue,, True), - AaOpacity(sender, 1, 170) - }, "MyTextButton Text " & sender.Uuid) - End If - End Sub)) + DependencyProperty.Register("Text", GetType(String), GetType(MyTextButton), New PropertyMetadata("", + Sub(sender As MyTextButton, e As DependencyPropertyChangedEventArgs) + If e.OldValue = e.NewValue Then Return + AniStart({ + AaOpacity(sender, -sender.Opacity, 50), + AaCode(Sub() sender.Content = e.NewValue,, True), + AaOpacity(sender, 1, 170) + }, "MyTextButton Text " & sender.Uuid) + End Sub)) '鼠标事件 @@ -43,13 +43,12 @@ IsMouseDown = False End Sub Private Sub MyTextButton_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseLeftButtonUp - If IsMouseDown Then - IsMouseDown = False - Log("[Control] 按下文本按钮:" & Text) - RaiseEvent Click(Me, Nothing) - ModEvent.TryStartEvent(EventType, EventData) - e.Handled = True - End If + If Not IsMouseDown Then Return + IsMouseDown = False + Log("[Control] 按下文本按钮:" & Text) + RaiseEvent Click(Me, Nothing) + RaiseCustomEvent() + e.Handled = True End Sub '指向动画 @@ -85,26 +84,4 @@ End If End Sub - '实现自定义事件 - Public Property EventType As String - Get - Return GetValue(EventTypeProperty) - End Get - Set(value As String) - SetValue(EventTypeProperty, value) - End Set - End Property - Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register( - "EventType", GetType(String), GetType(MyTextButton), New PropertyMetadata(Nothing)) - Public Property EventData As String - Get - Return GetValue(EventDataProperty) - End Get - Set(value As String) - SetValue(EventDataProperty, value) - End Set - End Property - Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register( - "EventData", GetType(String), GetType(MyTextButton), New PropertyMetadata(Nothing)) - End Class diff --git a/Plain Craft Launcher 2/Modules/Base/ModBase.vb b/Plain Craft Launcher 2/Modules/Base/ModBase.vb index cdb273826..53f7a4bef 100644 --- a/Plain Craft Launcher 2/Modules/Base/ModBase.vb +++ b/Plain Craft Launcher 2/Modules/Base/ModBase.vb @@ -2714,6 +2714,11 @@ NextElement: ''' 将 XML 转换为对应 UI 对象。 ''' Public Function GetObjectFromXML(Str As String) As Object + Str = Str. '兼容旧版自定义事件写法 + Replace("EventType=""", "local:CustomEventService.EventType="""). + Replace("EventData=""", "local:CustomEventService.EventData="""). + Replace("Property=""EventType""", "Property=""local:CustomEventService.EventType"""). + Replace("Property=""EventData""", "Property=""local:CustomEventService.EventData""") Using Stream As New MemoryStream(Encoding.UTF8.GetBytes(Str)) '类型检查 Using Reader As New XamlXmlReader(Stream) diff --git a/Plain Craft Launcher 2/Modules/Base/ModSetup.vb b/Plain Craft Launcher 2/Modules/Base/ModSetup.vb index fead1fb1d..4c9c13055 100644 --- a/Plain Craft Launcher 2/Modules/Base/ModSetup.vb +++ b/Plain Craft Launcher 2/Modules/Base/ModSetup.vb @@ -49,6 +49,17 @@ Public Class ModSetup Public Sub [Set](key As String, value As Object, Optional forceReload As Boolean = False, Optional instance As McInstance = Nothing) GetConfigItem(key).SetValueNoType(value, instance?.PathInstance) End Sub + + ''' + ''' 写入某个未经加密的设置项。 + ''' 若该设置项经过了加密,则会抛出异常。 + ''' + Public Sub SetSafe(key As String, value As Object, Optional forceReload As Boolean = False, Optional instance As McInstance = Nothing) + Dim item As ConfigItem = Nothing + If Not ConfigService.TryGetConfigItemNoType(key, item) Then Return + If item.Source = ConfigSource.SharedEncrypt Then Throw New InvalidOperationException("禁止写入加密设置项:" & Key) + [Set](key, value, forceReload, instance) + End Sub ''' ''' 应用某个设置项的值。 @@ -67,6 +78,17 @@ Public Class ModSetup Return GetConfigItem(key).GetValueNoType(instance?.PathInstance) End Function + ''' + ''' 获取某个未经加密的设置项的值。 + ''' 若该设置项经过了加密,则会抛出异常。 + ''' + Public Function GetSafe(key As String, Optional instance As McInstance = Nothing) + Dim item As ConfigItem = Nothing + If Not ConfigService.TryGetConfigItemNoType(key, item) Then Return Nothing + If item.Source = ConfigSource.SharedEncrypt Then Throw New InvalidOperationException("禁止读取加密设置项:" & key) + Return [Get](key, instance) + End Function + ''' ''' 初始化某个设置项的值。 ''' @@ -268,8 +290,7 @@ Public Class ModSetup FrmSetupUI.HintCustom.Visibility = Visibility.Visible FrmSetupUI.HintCustomWarn.Visibility = If(Setup.Get("HintCustomWarn"), Visibility.Collapsed, Visibility.Visible) FrmSetupUI.HintCustom.Text = $"从 PCL 文件夹下的 Custom.xaml 读取主页内容。{vbCrLf}你可以手动编辑该文件,向主页添加文本、图片、常用网站、快捷启动等功能。" - FrmSetupUI.HintCustom.EventType = "" - FrmSetupUI.HintCustom.EventData = "" + CustomEventService.SetEventType(FrmSetupUI.HintCustom, CustomEvent.EventType.None) Case 2 '联网 FrmSetupUI.PanCustomPreset.Visibility = Visibility.Collapsed FrmSetupUI.PanCustomLocal.Visibility = Visibility.Collapsed @@ -277,8 +298,8 @@ Public Class ModSetup FrmSetupUI.HintCustom.Visibility = Visibility.Visible FrmSetupUI.HintCustomWarn.Visibility = If(Setup.Get("HintCustomWarn"), Visibility.Collapsed, Visibility.Visible) FrmSetupUI.HintCustom.Text = $"从指定网址联网获取主页内容。服主也可以用于动态更新服务器公告。{vbCrLf}如果你制作了稳定运行的联网主页,可以点击这条提示投稿,若合格即可加入预设!" - FrmSetupUI.HintCustom.EventType = "打开网页" - FrmSetupUI.HintCustom.EventData = "https://github.com/Meloong-Git/PCL/discussions/2528" + CustomEventService.SetEventType(FrmSetupUI.HintCustom, CustomEvent.EventType.打开网页) + CustomEventService.SetEventData(FrmSetupUI.HintCustom, "https://github.com/Meloong-Git/PCL/discussions/2528") Case 3 '预设 FrmSetupUI.PanCustomPreset.Visibility = Visibility.Visible FrmSetupUI.PanCustomLocal.Visibility = Visibility.Collapsed diff --git a/Plain Craft Launcher 2/Modules/ModEvent.vb b/Plain Craft Launcher 2/Modules/ModEvent.vb index 7dd3b7769..f9a6dce8d 100644 --- a/Plain Craft Launcher 2/Modules/ModEvent.vb +++ b/Plain Craft Launcher 2/Modules/ModEvent.vb @@ -1,149 +1,316 @@ -Public Module ModEvent +Imports PCL.Core.App +Imports PCL.Core.App.Basics +Imports PCL.Core.Utils.OS +Imports PCL.Core.Utils.Exts.StringExtension - Public Sub TryStartEvent(Type As String, Data As String) - If String.IsNullOrWhiteSpace(Type) Then Return - Dim RealData As String() = {""} - If Data IsNot Nothing Then RealData = Data.Split("|") - StartEvent(Type, RealData) +#Region "附加属性" + +''' +''' 用于在 XAML 中初始化列表对象。 +''' 附加属性无法在 XAML 中为每个对象初始化独立的列表对象,因此需要一个包装类,然后在 XAML 中显式初始化。 +''' + +Public Class CustomEventCollection + Implements IEnumerable(Of CustomEvent) + Dim _events As New List(Of CustomEvent) + Public ReadOnly Property Events As List(Of CustomEvent) + Get + Return _events + End Get + End Property + Public Function GetEnumerator() As IEnumerator(Of CustomEvent) Implements IEnumerable(Of CustomEvent).GetEnumerator + Return DirectCast(Events, IEnumerable(Of CustomEvent)).GetEnumerator() + End Function + Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator + Return DirectCast(Events, IEnumerable).GetEnumerator() + End Function +End Class + +''' +''' 提供自定义事件的附加属性。 +''' +Public Class CustomEventService + + 'Events + Public Shared ReadOnly EventsProperty As DependencyProperty = + DependencyProperty.RegisterAttached("Events", GetType(CustomEventCollection), GetType(CustomEventService), New PropertyMetadata(Nothing)) + + Public Shared Sub SetEvents(d As DependencyObject, value As CustomEventCollection) + d.SetValue(EventsProperty, value) + End Sub + + Public Shared Function GetEvents(d As DependencyObject) As CustomEventCollection + If d.GetValue(EventsProperty) Is Nothing Then d.SetValue(EventsProperty, New CustomEventCollection) + Return d.GetValue(EventsProperty) + End Function + + 'EventType + Public Shared ReadOnly EventTypeProperty As DependencyProperty = + DependencyProperty.RegisterAttached("EventType", GetType(CustomEvent.EventType), GetType(CustomEventService), New PropertyMetadata(Nothing)) + + Public Shared Sub SetEventType(d As DependencyObject, value As CustomEvent.EventType) + d.SetValue(EventTypeProperty, value) + End Sub + + Public Shared Function GetEventType(d As DependencyObject) As CustomEvent.EventType + Return d.GetValue(EventTypeProperty) + End Function + + 'EventData + Public Shared ReadOnly EventDataProperty As DependencyProperty = + DependencyProperty.RegisterAttached("EventData", GetType(String), GetType(CustomEventService), New PropertyMetadata(Nothing)) + + Public Shared Sub SetEventData(d As DependencyObject, value As String) + d.SetValue(EventDataProperty, value) + End Sub + + Public Shared Function GetEventData(d As DependencyObject) As String + Return d.GetValue(EventDataProperty) + End Function + +End Class + +Partial Public Module ModMain + + ''' + ''' 触发该控件上的自定义事件。 + ''' 事件会在新线程中执行。 + ''' + + Public Sub RaiseCustomEvent(control As DependencyObject) + '收集事件列表 + Dim events = CustomEventService.GetEvents(control).ToList + Dim eventType = CustomEventService.GetEventType(control) + If eventType <> CustomEvent.EventType.None Then events.Add(New CustomEvent(eventType, CustomEventService.GetEventData(control))) + '执行事件 + If Not events.Any Then Return + RunInNewThread( + Sub() + For Each e In events + e.Raise() + Next + End Sub, "执行自定义事件 " & GetUuid()) + End Sub + +End Module + +#End Region + +''' +''' 自定义事件。 +''' +Public Class CustomEvent + +#Region "属性与触发" + + Public Property Type As EventType = EventType.None + Public Property Data As String = Nothing + Public Sub New() End Sub - Public Sub StartEvent(Type As String, Data As String()) + Public Sub New(type As EventType, data As String) + Me.Type = type + Me.Data = data + End Sub + + ''' + ''' 在当前线程中触发该自定义事件。 + ''' + Public Sub Raise() + Raise(Type, Data) + End Sub + +#End Region + + Public Enum EventType + None = 0 + 打开网页 + 打开文件 + 打开帮助 + 执行命令 + 启动游戏 + 复制文本 + 刷新主页 + 刷新主页市场 + 刷新页面 + 刷新帮助 + 今日人品 + 内存优化 + 清理垃圾 + 弹出窗口 + 弹出提示 + 切换页面 + 导入整合包 + 安装整合包 + 下载文件 + 修改设置 + 写入设置 + 修改变量 + 写入变量 + End Enum + + ''' + ''' 在当前线程中触发一个自定义事件。 + ''' + Public Shared Sub Raise(type As EventType, arg As String) + If type = EventType.None Then Return + Log($"[Control] 执行自定义事件:{type}, {arg}") Try - Log("[Control] 执行自定义事件:" & Type & ", " & Join(Data, ", ")) - Select Case Type + Dim args As String() = If(arg?.Split("|"), {""}) + Select Case type - Case "打开网页" - Data(0) = Data(0).Replace("\", "/") - If Not Data(0).Contains("://") OrElse Data(0).StartsWithF("file", True) Then '为了支持更多协议(#2200) + Case EventType.打开网页 + arg = arg.Replace("\", "/") + If Not arg.Contains("://") OrElse arg.StartsWithF("file", True) Then '为了支持更多协议(#2200) MyMsgBox("EventData 必须为一个网址。" & vbCrLf & "如果想要启动程序,请将 EventType 改为 打开文件。", "事件执行失败") Return End If - Hint("正在开启中,请稍候……") - OpenWebsite(Data(0)) + Hint("正在开启中,请稍候:" & arg) + RunInThread(Sub() OpenWebsite(arg)) - Case "打开文件", "打开帮助", "执行命令" + Case EventType.打开文件, EventType.打开帮助, EventType.执行命令 RunInThread( Sub() Try '确认实际路径 - Dim ActualPaths = GetEventAbsoluteUrls(Data(0), Type) - Dim Location = ActualPaths(0), WorkingDir = ActualPaths(1) - Log($"[Control] 打开类自定义事件实际路径:{Location},工作目录:{WorkingDir}") + Dim actualPaths = GetAbsoluteUrls(args(0), type) + Dim location = actualPaths(0), workingDir = actualPaths(1) + Log($"[Control] 打开类自定义事件实际路径:{location},工作目录:{workingDir}") '执行 - If Type = "打开帮助" Then + If Type = EventType.打开帮助 Then PageToolsHelp.EnterHelpPage(Location) Else - If Not Setup.Get("HintCustomCommand") Then - Select Case MyMsgBox( - "即将执行:" & Location & If(Data.Length >= 2, " " & Data(1), "") & vbCrLf & - "请在确认该操作没有安全隐患后继续。", "执行确认", "继续", "继续且今后不再要求确认", "取消") - Case 2 - Setup.Set("HintCustomCommand", True) - Case 3 - Return - End Select - End If - Dim Info As New ProcessStartInfo With { - .Arguments = If(Data.Length >= 2, Data(1), ""), - .FileName = Location, - .WorkingDirectory = ShortenPath(WorkingDir), - .UseShellExecute = True - } - Process.Start(Info) + If Not EventSafetyConfirm("即将执行:" & location & If(args.Length >= 2, " " & args(1), "")) Then Return + ProcessInterop.Start(location, If(args.Length >= 2, args(1), "")) End If Catch ex As Exception Log(ex, "执行打开类自定义事件失败", LogLevel.Msgbox) End Try End Sub) - Case "启动游戏" - If Data(0) = "\current" Then + Case EventType.启动游戏 + If args(0) = "\current" Then If McInstanceSelected Is Nothing Then - Hint("请先选择一个 Minecraft 实例!", HintType.Critical) + Hint("请先选择一个 Minecraft 版本!", HintType.Critical) Return Else - Data(0) = McInstanceSelected.Name + args(0) = McInstanceSelected.Name End If End If - If McLaunchStart(New McLaunchOptions With - {.ServerIp = If(Data.Length >= 2, Data(1), Nothing), .Instance = New McInstance(Data(0))}) Then - Hint("正在启动 " & Data(0) & "……") - End If + RunInUi( + Sub() + If McLaunchStart(New McLaunchOptions With + {.ServerIp = If(args.Length >= 2, args(1), Nothing), .Instance = New McInstance(args(0))}) Then + Hint($"正在启动 {args(0)}……") + End If + End Sub) - Case "复制文本" - ClipboardSet(Join(Data, "|")) + Case EventType.复制文本 + ClipboardSet(arg) - Case "刷新主页" - FrmLaunchRight.ForceRefresh() - If Data(0) = "" Then Hint("已刷新主页!", HintType.Finish) + Case EventType.刷新主页, EventType.刷新页面 + If TypeOf FrmMain.PageRight Is IRefreshable Then + RunInUiWait(Sub() CType(FrmMain.PageRight, IRefreshable).Refresh()) + If String.IsNullOrEmpty(arg) Then Hint("已刷新!", HintType.Finish) + Else + Hint("当前页面不支持刷新操作!", HintType.Critical) + End If - Case "刷新主页市场" + Case EventType.刷新主页市场 FrmHomePageMarket.Refresh() - If Data(0) = "" Then Hint("已刷新主页市场!", HintType.Finish) + If args(0) = "" Then Hint("已刷新主页市场!", HintType.Finish) - Case "刷新帮助" + Case EventType.刷新帮助 PageToolsLeft.RefreshHelp() + Case EventType.刷新帮助 + RunInUiWait(Sub() PageToolsLeft.RefreshHelp()) + If String.IsNullOrEmpty(arg) Then Hint("已刷新!", HintType.Finish) - Case "今日人品" + Case EventType.今日人品 PageToolsTest.Jrrp() - Case "内存优化" + Case EventType.内存优化 RunInThread(Sub() PageToolsTest.MemoryOptimize(True)) - Case "清理垃圾" + Case EventType.清理垃圾 RunInThread(Sub() PageToolsTest.RubbishClear()) - Case "弹出窗口" - MyMsgBox(Data(1).Replace("\n", vbCrLf), Data(0).Replace("\n", vbCrLf)) + Case EventType.弹出窗口 + If args.Length = 1 Then Throw New Exception($"EventType {type} 需要至少 2 个以 | 分割的参数,例如 弹窗标题|弹窗内容") + MyMsgBox(args(1).Replace("\n", vbCrLf), args(0).Replace("\n", vbCrLf), If(args.Length > 2, args(2), "确定")) - Case "切换页面" - FrmMain.PageChange(Val(Data(0)), Val(Data(1))) + Case EventType.弹出提示 + Hint(args(0).Replace("\n", vbCrLf), If(args.Length = 1, HintType.Info, args(1).ParseToEnum(Of HintType))) - Case "导入整合包", "安装整合包" + Case EventType.切换页面 + RunInUi(Sub() FrmMain.PageChange( + args(0).ParseToEnum(Of FormMain.PageType), + If(args.Length = 1, FormMain.PageSubType.Default, args(1).ParseToEnum(Of FormMain.PageSubType)))) + + Case EventType.导入整合包, EventType.安装整合包 RunInUi(Sub() ModpackInstall()) - Case "下载文件" - Data(0) = Data(0).Replace("\", "/") - If Not (Data(0).StartsWithF("http://", True) OrElse Data(0).StartsWithF("https://", True)) Then + Case EventType.下载文件 + args(0) = args(0).Replace("\", "/") + If Not (args(0).StartsWithF("http://", True) OrElse args(0).StartsWithF("https://", True)) Then MyMsgBox("EventData 必须为以 http:// 或 https:// 开头的网址。" & vbCrLf & "PCL 不支持其他乱七八糟的下载协议。", "事件执行失败") Return End If + If Not EventSafetyConfirm("即将从该网址下载文件:" & vbCrLf & args(0)) Then Return Try - Select Case Data.Length + Select Case args.Length Case 1 - PageToolsTest.StartCustomDownload(Data(0), GetFileNameFromPath(Data(0))) + PageToolsTest.StartCustomDownload(args(0), GetFileNameFromPath(args(0))) Case 2 - PageToolsTest.StartCustomDownload(Data(0), Data(1)) + PageToolsTest.StartCustomDownload(args(0), args(1)) Case Else - PageToolsTest.StartCustomDownload(Data(0), Data(1), Data(2)) + PageToolsTest.StartCustomDownload(args(0), args(1), args(2)) End Select Catch - PageToolsTest.StartCustomDownload(Data(0), "未知") + PageToolsTest.StartCustomDownload(args(0), "未知") End Try + Case EventType.修改设置, EventType.写入设置 + If args.Length = 1 Then Throw New Exception($"EventType {type} 需要至少 2 个以 | 分割的参数,例如 UiLauncherTransparent|400") + Setup.SetSafe(args(0), args(1), instance:=McInstanceSelected) + If args.Length = 2 Then Hint($"已写入设置:{args(0)} → {args(1)}", HintType.Finish) + + Case EventType.修改变量, EventType.写入变量 + If args.Length = 1 Then Throw New Exception($"EventType {type} 需要至少 2 个以 | 分割的参数,例如 VariableName|Value") + States.CustomVariables.Add(args(0), args(1)) + States.CustomVariables = States.CustomVariables + If args.Length = 2 Then Hint($"已写入变量:{args(0)} → {args(1)}", HintType.Finish) Case Else - MyMsgBox("未知的事件类型:" & Type & vbCrLf & "请检查事件类型填写是否正确,或者 PCL 是否为最新版本。", "事件执行失败") + MyMsgBox("未知的事件类型:" & type & vbCrLf & "请检查事件类型填写是否正确,或者 PCL 是否为最新版本。", "事件执行失败") End Select Catch ex As Exception - Log(ex, "事件执行失败", LogLevel.Msgbox) + Log(ex, $"事件执行失败({type}, {arg})", LogLevel.Msgbox) End Try End Sub - + + ''' + ''' 获取自定义变量的值。若不存在这个变量则返回 Nothing。 + ''' + Public Shared Function GetCustomVariable(name As String) As String + If States.CustomVariables.ContainsKey(name) Then Return States.CustomVariables(name) + Return Nothing + End Function + ''' ''' 返回自定义事件的绝对 Url。实际返回 {绝对 Url, WorkingDir}。 ''' 失败会抛出异常。 ''' - Public Function GetEventAbsoluteUrls(RelativeUrl As String, EventType As String) As String() - + Public Shared Function GetAbsoluteUrls(relativeUrl As String, type As EventType) As String() + '网页确认 - If RelativeUrl.StartsWithF("http", True) Then + If relativeUrl.StartsWithF("http", True) Then If RunInUi() Then Throw New Exception("能打开联网帮助页面的 MyListItem 必须手动设置 Title、Info 属性!") End If '获取文件名 - Dim RawFileName As String + Dim rawFileName As String Try - RawFileName = GetFileNameFromPath(RelativeUrl) - If Not RawFileName.EndsWithF(".json", True) Then Throw New Exception("未指向 .json 后缀的文件") + rawFileName = GetFileNameFromPath(relativeUrl) + If Not rawFileName.EndsWithF(".json", True) Then Throw New Exception("未指向 .json 后缀的文件") Catch ex As Exception Throw New Exception("联网帮助页面须指向一个帮助 JSON 文件,并在同路径下包含相应 XAML 文件!" & vbCrLf & "例如:" & vbCrLf & @@ -151,11 +318,11 @@ " - https://www.baidu.com/test.xaml(同时也需要包含这个文件)", ex) End Try '下载文件 - Dim LocalTemp As String = RequestTaskTempFolder() & RawFileName - Log("[Event] 转换网络资源:" & RelativeUrl & " -> " & LocalTemp) + Dim localTemp As String = RequestTaskTempFolder() & rawFileName + Log("[Event] 转换网络资源:" & relativeUrl & " -> " & localTemp) Try - NetDownloadByClient(RelativeUrl, LocalTemp).GetAwaiter().GetResult() - NetDownloadByClient(RelativeUrl.Replace(".json", ".xaml"), LocalTemp.Replace(".json", ".xaml")).GetAwaiter().GetResult() + NetDownloadByClient(relativeUrl, localTemp).GetAwaiter().GetResult() + NetDownloadByClient(relativeUrl.Replace(".json", ".xaml"), localTemp.Replace(".json", ".xaml")).GetAwaiter().GetResult() Catch ex As Exception Throw New Exception("下载指定的文件失败!" & vbCrLf & "注意,联网帮助页面须指向一个帮助 JSON 文件,并在同路径下包含相应 XAML 文件!" & vbCrLf & @@ -163,41 +330,57 @@ " - https://www.baidu.com/test.json(填写这个路径)" & vbCrLf & " - https://www.baidu.com/test.xaml(同时也需要包含这个文件)", ex) End Try - RelativeUrl = LocalTemp + relativeUrl = localTemp End If - RelativeUrl = RelativeUrl.Replace("/", "\").ToLower.TrimStart("\") - + relativeUrl = relativeUrl.Replace("/", "\").ToLower.TrimStart("\") + '确认实际路径 - Dim Location As String, WorkingDir As String = ExePath & "PCL" + Dim location As String, workingDir As String = IO.Path.Combine(ExecutableDirectory, "PCL") HelpExtract() - If RelativeUrl.Contains(":\") Then + If relativeUrl.Contains(":\") Then '绝对路径 - Location = RelativeUrl - Log("[Control] 自定义事件中由绝对路径" & EventType & ":" & Location) - ElseIf File.Exists(ExePath & "PCL\" & RelativeUrl) Then + location = relativeUrl + Log("[Control] 自定义事件中由绝对路径" & type & ":" & location) + ElseIf File.Exists(IO.Path.Combine(ExecutableDirectory, "PCL", relativeUrl)) Then '相对 PCL 文件夹的路径 - Location = ExePath & "PCL\" & RelativeUrl - Log("[Control] 自定义事件中由相对 PCL 文件夹的路径" & EventType & ":" & Location) - ElseIf File.Exists(ExePath & "PCL\Help\" & RelativeUrl) Then + location = IO.Path.Combine(ExecutableDirectory, "PCL", relativeUrl) + Log("[Control] 自定义事件中由相对 PCL 文件夹的路径" & type & ":" & location) + ElseIf File.Exists(IO.Path.Combine(ExecutableDirectory, "PCL", "Help", relativeUrl)) Then '相对 PCL 本地帮助文件夹的路径 - Location = ExePath & "PCL\Help\" & RelativeUrl - WorkingDir = ExePath & "PCL\Help\" - Log("[Control] 自定义事件中由相对 PCL 本地帮助文件夹的路径" & EventType & ":" & Location) - ElseIf EventType = "打开帮助" AndAlso File.Exists(PathHelpFolder & RelativeUrl) Then + location = IO.Path.Combine(ExecutableDirectory, "PCL", "Help", relativeUrl) + workingDir = IO.Path.Combine(ExecutableDirectory, "PCL", "Help") + Log("[Control] 自定义事件中由相对 PCL 本地帮助文件夹的路径" & type & ":" & location) + ElseIf type = EventType.打开帮助 AndAlso File.Exists(IO.Path.Combine(PathTemp, "Help", relativeUrl)) Then '相对 PCL 自带帮助文件夹的路径 - Location = PathHelpFolder & RelativeUrl - WorkingDir = PathHelpFolder - Log("[Control] 自定义事件中由相对 PCL 自带帮助文件夹的路径" & EventType & ":" & Location) - ElseIf EventType = "打开文件" OrElse EventType = "执行命令" Then + location = IO.Path.Combine(PathTemp, "Help", relativeUrl) + workingDir = IO.Path.Combine(PathTemp, "Help") + Log("[Control] 自定义事件中由相对 PCL 自带帮助文件夹的路径" & type & ":" & location) + ElseIf type = EventType.打开文件 OrElse type = EventType.执行命令 Then '直接使用原有路径启动程序 - Location = RelativeUrl - Log("[Control] 自定义事件中直接" & EventType & ":" & Location) + location = relativeUrl + Log("[Control] 自定义事件中直接" & type & ":" & location) Else '打开帮助,但是格式不对劲 - Throw New FileNotFoundException("未找到 EventData 指向的本地 xaml 文件:" & RelativeUrl, RelativeUrl) + Throw New FileNotFoundException("未找到 EventData 指向的本地 xaml 文件:" & relativeUrl, relativeUrl) End If + + Return {location, workingDir} + End Function - Return {Location, WorkingDir} + ''' + ''' 弹出安全确认弹窗。返回是否继续执行。 + ''' + Private Shared Function EventSafetyConfirm(message As String) As Boolean + If Setup.Get("HintCustomCommand") Then Return True + Select Case MyMsgBox(message & vbCrLf & "请在确认没有安全隐患后再继续。", "执行确认", "继续", "继续且今后不再要求确认", "取消") + Case 1 + Return True + Case 2 + Setup.Set("HintCustomCommand", True) + Return True + Case Else + Return False + End Select End Function -End Module +End Class diff --git a/Plain Craft Launcher 2/Modules/ModMain.vb b/Plain Craft Launcher 2/Modules/ModMain.vb index 6ddbc0bed..e29ce1c89 100644 --- a/Plain Craft Launcher 2/Modules/ModMain.vb +++ b/Plain Craft Launcher 2/Modules/ModMain.vb @@ -2,6 +2,7 @@ Imports System.Windows.Interop Imports System.Windows.Threading Imports Microsoft.Win32 Imports PCL.Core.IO +Imports PCL.Core.App Imports PCL.Core.Utils Public Module ModMain @@ -625,7 +626,7 @@ EndHint: ''' Public Sub New(FilePath As String) RawPath = FilePath - Dim JsonData As JObject = GetJson(HelpArgumentReplace(ReadFile(FilePath))) + Dim JsonData As JObject = GetJson(ArgumentReplace(ReadFile(FilePath))) If JsonData Is Nothing Then Throw New FileNotFoundException("未找到帮助文件:" & FilePath, FilePath) '加载常规信息 If JsonData("Title") IsNot Nothing Then @@ -645,8 +646,7 @@ EndHint: Next '加载事件信息 If If(JsonData("IsEvent"), False) Then - EventType = JsonData("EventType") - If EventType Is Nothing Then Throw New ArgumentException("未找到 EventType 项") + EventType = [Enum].Parse(GetType(CustomEvent.EventType), JsonData("EventType").ToString) EventData = If(JsonData("EventData"), "") IsEvent = True Else @@ -671,7 +671,7 @@ EndHint: Public Function SetToListItem(Item As MyListItem) As MyListItem Dim Logo As String If IsEvent Then - If EventType = "弹出窗口" Then + If EventType = CustomEvent.EventType.弹出窗口 Then Logo = PathImage & "Blocks/GrassPath.png" Else Logo = PathImage & "Blocks/CommandBlock.png" @@ -688,9 +688,9 @@ EndHint: .Height = 42 .Type = MyListItem.CheckType.Clickable .Tag = Me - .EventType = Nothing - .EventData = Nothing End With + CustomEventService.SetEventType(Item, CustomEvent.EventType.None) '清空自定义事件属性,它们会被下面的点击事件处理 + CustomEventService.SetEventData(Item, Nothing) '项目的点击事件 AddHandler Item.Click, Sub(sender, e) PageToolsHelp.OnItemClick(sender.Tag) Return Item @@ -961,6 +961,76 @@ NextFile: End If End Sub + ''' + ''' 对替换标记进行处理。会对替换内容使用 EscapeHandler 进行转义。 + ''' + Public Function ArgumentReplace(text As String, Optional escapeHandler As Func(Of String, String) = Nothing, Optional replaceTime As Boolean = True) As String + '预处理 + If text Is Nothing Then Return Nothing + Dim replacer = + Function(s As String) As String + If s Is Nothing Then Return "" + If escapeHandler Is Nothing Then Return s + If s.Contains(":\") Then s = ShortenPath(s) + Return escapeHandler(s) + End Function + '基础 + text = text.Replace("{pcl_version}", replacer(VersionBaseName)) + text = text.Replace("{pcl_version_code}", replacer(VersionCode)) + text = text.Replace("{pcl_version_branch}", replacer(VersionBranchName)) + text = text.Replace("{pcl_branch}", replacer(VersionBranchName)) + text = text.Replace("{identify}", replacer(UniqueAddress)) + text = text.Replace("{path}", replacer(Basics.ExecutableDirectory)) + text = text.Replace("{path_with_name}", replacer(Basics.ExecutableName)) + text = text.Replace("{path_temp}", replacer(PathTemp)) + '时间 + If replaceTime Then '在窗口标题中,时间会被后续动态替换,所以此时不应该替换 + text = text.Replace("{date}", replacer(Date.Now.ToString("yyyy/M/d"))) + text = text.Replace("{time}", replacer(Date.Now.ToString("HH:mm:ss"))) + End If + 'Minecraft + text = text.Replace("{java}", replacer(McLaunchJavaSelected?.Installation.JavaFolder)) + text = text.Replace("{minecraft}", replacer(McFolderSelected)) + If McInstanceSelected IsNot Nothing Then + text = text.Replace("{version_path}", replacer(McInstanceSelected.PathInstance)) : text = text.Replace("{verpath}", replacer(McInstanceSelected.PathInstance)) + text = text.Replace("{version_indie}", replacer(McInstanceSelected.PathIndie)) : text = text.Replace("{verindie}", replacer(McInstanceSelected.PathIndie)) + text = text.Replace("{name}", replacer(McInstanceSelected.Name)) + If {"unknown", "old", "pending"}.Contains(McInstanceSelected.Info.VanillaName) Then + text = text.Replace("{version}", replacer(McInstanceSelected.Name)) + Else + text = text.Replace("{version}", replacer(McInstanceSelected.Info.VanillaName)) + End If + Else + text = text.Replace("{version_path}", replacer(Nothing)) : text = text.Replace("{verpath}", replacer(Nothing)) + text = text.Replace("{version_indie}", replacer(Nothing)) : text = text.Replace("{verindie}", replacer(Nothing)) + text = text.Replace("{name}", replacer(Nothing)) + text = text.Replace("{version}", replacer(Nothing)) + End If + '验证信息 + If McLoginLoader.State = LoadState.Finished Then + text = text.Replace("{user}", replacer(McLoginLoader.Output.Name)) + text = text.Replace("{uuid}", replacer(McLoginLoader.Output.Uuid.ToLower)) + Select Case McLoginLoader.Input.Type + Case McLoginType.Legacy + text = text.Replace("{login}", replacer("离线")) + Case McLoginType.Ms + text = text.Replace("{login}", replacer("正版")) + Case McLoginType.Auth + text = text.Replace("{login}", replacer("Authlib-Injector")) + End Select + Else + text = text.Replace("{user}", replacer(Nothing)) + text = text.Replace("{uuid}", replacer(Nothing)) + text = text.Replace("{login}", replacer(Nothing)) + End If + '高级 + text = text.RegexReplaceEach("\{hint\}", Function() replacer(PageToolsTest.GetRandomHint())) + text = text.RegexReplaceEach("\{cave\}", Function() replacer(PageToolsTest.GetRandomCave())) + text = text.RegexReplaceEach("\{setup:([a-zA-Z0-9]+)\}", Function(m) replacer(Setup.GetSafe(m.Groups(1).Value, McInstanceSelected))) + text = text.RegexReplaceEach("\{varible:([^\}]+)\}", Function(m) replacer(CustomEvent.GetCustomVariable(m.Groups(1).Value))) + text = text.RegexReplaceEach("\{variable:([^\}]+)\}", Function(m) replacer(CustomEvent.GetCustomVariable(m.Groups(1).Value))) + Return text + End Function #End Region #Region "任务缓存" diff --git a/Plain Craft Launcher 2/Modules/ModSecret.vb b/Plain Craft Launcher 2/Modules/ModSecret.vb index f6a109819..03ed2970f 100644 --- a/Plain Craft Launcher 2/Modules/ModSecret.vb +++ b/Plain Craft Launcher 2/Modules/ModSecret.vb @@ -431,7 +431,7 @@ PCL-Community 及其成员与龙腾猫跃无从属关系,且均不会为您的 Catch ex As Win32Exception Log(ex, "自动更新时触发 Win32 错误,疑似被拦截", LogLevel.Debug, "出现错误") If MyMsgBox(String.Format("由于被 Windows 安全中心拦截,或者存在权限问题,导致 PCL 无法更新。{0}请将 PCL 所在文件夹加入白名单,或者手动用 {1}PCL\Plain Craft Launcher Community Edition.exe 替换当前文件!", vbCrLf, ModBase.ExePath), "更新失败", "查看帮助", "确定", "", True, True, False, Nothing, Nothing, Nothing) = 1 Then - TryStartEvent("打开帮助", "启动器/Microsoft Defender 添加排除项.json") + CustomEvent.Raise(CustomEvent.EventType.打开帮助, "启动器/Microsoft Defender 添加排除项.json") End If End Try End Sub @@ -497,10 +497,10 @@ PCL-Community 及其成员与龙腾猫跃无从属关系,且均不会为您的 If(item.btn2 Is Nothing, "", item.btn2.text), "关闭", Button1Action:=Sub() - TryStartEvent(item.btn1.command, item.btn1.command_paramter) + CustomEvent.Raise(item.btn1.command, item.btn1.command_paramter) End Sub, Button2Action:=Sub() - TryStartEvent(item.btn2.command, item.btn2.command_paramter) + CustomEvent.Raise(item.btn2.command, item.btn2.command_paramter) End Sub ) Next diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadNeoForge.xaml b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadNeoForge.xaml index 886c34374..b91fa5423 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadNeoForge.xaml +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadNeoForge.xaml @@ -14,7 +14,7 @@ + local:CustomEventService.EventType="打开网页" local:CustomEventService.EventData="https://neoforged.net/" /> diff --git a/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml b/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml index 891ae0045..05a9ab338 100644 --- a/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml +++ b/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml @@ -254,7 +254,7 @@ + local:CustomEventService.EventType="打开帮助" /> diff --git a/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.vb b/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.vb index e08562a79..a3b341b69 100644 --- a/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.vb @@ -23,7 +23,7 @@ Public Class PageInstanceExport Private Sub PageInstanceExport_Loaded() Handles Me.Loaded AniControlEnabled += 1 If CurrentVersion <> PageInstanceLeft.Instance.PathInstance Then RefreshAll() '切换到了另一个实例,重置页面 - BtnAdvancedHelp.EventData = "指南/整合包制作.json" + CustomEventService.SetEventData(BtnAdvancedHelp, "指南/整合包制作.json") AniControlEnabled -= 1 End Sub Public Sub RefreshAll() Implements IRefreshable.Refresh diff --git a/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml b/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml index 8ed5b6f55..cc32d237e 100644 --- a/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml +++ b/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml @@ -1,7 +1,7 @@ @@ -24,17 +24,17 @@ - - + - - - + + + diff --git a/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb b/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb index 50dca7835..33c704738 100644 --- a/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb @@ -102,14 +102,14 @@ Public Class MyMsgLogin End If '设置 UI LabTitle.Text = "登录 Minecraft" - Btn1.EventData = Website - Btn2.EventData = UserCode + CustomEventService.SetEventData(Btn1, Website) + CustomEventService.SetEventData(Btn2, UserCode) '启动工作线程 RunInNewThread(AddressOf WorkThread, "MyMsgLogin") End Sub Private Sub WorkThread() - Thread.Sleep(3000) + Thread.Sleep(2000) If MyConverter.IsExited Then Return OpenWebsite(Website) ClipboardSet(UserCode) diff --git a/Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchRight.xaml.vb b/Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchRight.xaml.vb index 9a144364b..e1a4e6449 100644 --- a/Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchRight.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchRight.xaml.vb @@ -279,7 +279,7 @@ Download: Dim LoadStartTime As Date = Date.Now Try '修改时应同时修改 PageOtherHelpDetail.Init - Content = HelpArgumentReplace(Content) + Content = ArgumentReplace(Content) Do While Content.Contains("xmlns") Content = Content.RegexReplace("xmlns[^""']*(""|')[^""']*(""|')", "").Replace("xmlns", "") Loop diff --git a/Plain Craft Launcher 2/Pages/PageLaunch/PageLoginMs.xaml b/Plain Craft Launcher 2/Pages/PageLaunch/PageLoginMs.xaml index d3e282f4c..2acd9732b 100644 --- a/Plain Craft Launcher 2/Pages/PageLaunch/PageLoginMs.xaml +++ b/Plain Craft Launcher 2/Pages/PageLaunch/PageLoginMs.xaml @@ -27,9 +27,9 @@ - - diff --git a/Plain Craft Launcher 2/Pages/PageSetup/PageSetupAbout.xaml b/Plain Craft Launcher 2/Pages/PageSetup/PageSetupAbout.xaml index 59ddb5481..62fd97339 100644 --- a/Plain Craft Launcher 2/Pages/PageSetup/PageSetupAbout.xaml +++ b/Plain Craft Launcher 2/Pages/PageSetup/PageSetupAbout.xaml @@ -35,9 +35,9 @@ - - - + + + @@ -61,15 +61,15 @@ - + - + - + - + - + @@ -163,14 +163,14 @@ Margin="0,8,0,0" HorizontalAlignment="Center" MaxWidth="90" - EventType="打开网页" - EventData="{Binding HtmlUrl}" + local:CustomEventService.EventType="打开网页" + local:CustomEventService.EventData="{Binding HtmlUrl}" ToolTip="{Binding Login}" /> - + @@ -181,9 +181,9 @@ - - - + + + @@ -194,8 +194,8 @@ - - + + @@ -215,10 +215,10 @@ diff --git a/Plain Craft Launcher 2/Pages/PageTools/PageToolsGameLink.xaml b/Plain Craft Launcher 2/Pages/PageTools/PageToolsGameLink.xaml index 1551906bb..39b7b5961 100644 --- a/Plain Craft Launcher 2/Pages/PageTools/PageToolsGameLink.xaml +++ b/Plain Craft Launcher 2/Pages/PageTools/PageToolsGameLink.xaml @@ -61,10 +61,10 @@ @@ -118,21 +118,21 @@ - + - + - + - + - + - + diff --git a/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelp.xaml.vb b/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelp.xaml.vb index 6d42016f0..214df84e4 100644 --- a/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelp.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelp.xaml.vb @@ -73,7 +73,7 @@ Public Shared Sub OnItemClick(Entry As HelpEntry) Try If Entry.IsEvent Then - ModEvent.TryStartEvent(Entry.EventType, Entry.EventData) + CustomEvent.Raise(Entry.EventType, Entry.EventData) Else EnterHelpPage(Entry) End If diff --git a/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelpDetail.xaml.vb b/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelpDetail.xaml.vb index 45624c3e9..d86f8c247 100644 --- a/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelpDetail.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageTools/PageToolsHelpDetail.xaml.vb @@ -18,7 +18,7 @@ If Content = "" Then Throw New Exception("帮助 xaml 文件为空") Try '修改时应同时修改 PageLaunchRight.LoadContent - Content = HelpArgumentReplace(Content) + Content = ArgumentReplace(Content) If Content.Contains("xmlns") Then Content = Content.RegexReplace("xmlns[^""']*(""|')[^""']*(""|')", "").Replace("xmlns", "") '禁止声明命名空间 Content = "" & Content & "" Me.Entry = Entry