Skip to content

Commit 5fd7c26

Browse files
authored
feat(custom-page): 同步上游自定义主页更新 (#1768)
* feat(custom-page): 同步上游自定义主页更新 * feat: 添加了 SetSafe 和 GetSafe 方法 * feat(wip): 大概搭个自定义变量的框架,具体实现有待商榷 * fix: ci * fix: ci * fix ci * feat: 支持自定义变量 * fix: add set * fix * fix
1 parent 9e32146 commit 5fd7c26

34 files changed

Lines changed: 571 additions & 447 deletions

PCL.Core/App/CustomVarible.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

PCL.Core/App/States.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using PCL.Core.App.Configuration;
1+
using System.Collections.Generic;
2+
using PCL.Core.App.Configuration;
23

34
namespace PCL.Core.App;
45

@@ -12,6 +13,11 @@ public static partial class States
1213
/// 唯一标识符。
1314
/// </summary>
1415
[ConfigItem<string>("Identify", "")] public static partial string Identifier { get; set; }
16+
17+
/// <summary>
18+
/// 自定义变量。
19+
/// </summary>
20+
[AnyConfigItem<Dictionary<string, string>>("CustomVariables", ConfigSource.Local)] public static partial Dictionary<string, string> CustomVariables { get; set; }
1521

1622
/// <summary>
1723
/// 提示状态。

Plain Craft Launcher 2/Controls/MyButton.xaml.vb

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -140,39 +140,14 @@ Public Class MyButton
140140
End Try
141141
End Sub
142142

143-
'实现自定义事件
143+
'鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行)
144+
Private IsMouseDown As Boolean = False
144145
Private Sub Button_MouseUp(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp
145146
If Not IsMouseDown Then Return
146147
Log("[Control] 按下按钮:" & Text)
147148
RaiseEvent Click(sender, e)
148-
If Not String.IsNullOrEmpty(Tag) Then
149-
If Tag.ToString.StartsWithF("链接-") OrElse Tag.ToString.StartsWithF("启动-") Then
150-
Hint("主页自定义按钮语法已更新,且不再兼容老版本语法,请查看新的自定义示例!")
151-
End If
152-
End If
153-
ModEvent.TryStartEvent(EventType, EventData)
149+
RaiseCustomEvent() '自定义事件
154150
End Sub
155-
Public Property EventType As String
156-
Get
157-
Return GetValue(EventTypeProperty)
158-
End Get
159-
Set(value As String)
160-
SetValue(EventTypeProperty, value)
161-
End Set
162-
End Property
163-
Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyButton), New PropertyMetadata(Nothing))
164-
Public Property EventData As String
165-
Get
166-
Return GetValue(EventDataProperty)
167-
End Get
168-
Set(value As String)
169-
SetValue(EventDataProperty, value)
170-
End Set
171-
End Property
172-
Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyButton), New PropertyMetadata(Nothing))
173-
174-
'鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行)
175-
Private IsMouseDown As Boolean = False
176151
Private Sub Button_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
177152
IsMouseDown = True
178153
Focus()

Plain Craft Launcher 2/Controls/MyCard.vb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,6 @@ Public Class MyCard
296296
End Property
297297
Private _IsSwapped As Boolean = False
298298

299-
''' <summary>
300-
''' 是否已被折叠。(已过时,请使用 IsSwapped)
301-
''' </summary>
302299
<Obsolete("请使用 IsSwapped 属性,IsSwaped 存在拼写错误")>
303300
Public Property IsSwaped As Boolean
304301
Get
@@ -310,37 +307,45 @@ Public Class MyCard
310307
End Property
311308

312309
Public Property SwapLogoRight As Boolean = False
313-
Private IsMouseDown As Boolean = False
310+
Private IsSwapMouseDown As Boolean = False '用于触发卡片展开/折叠的 MouseDown
311+
Private IsCustomMouseDown As Boolean = False '用于触发自定义事件的 MouseDown
314312
Public Event PreviewSwap(sender As Object, e As RouteEventArgs)
315313
Public Event Swap(sender As Object, e As RouteEventArgs)
316314
Public Const SwapedHeight As Integer = 40
317315
Private Sub MyCard_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
318316
Dim Pos As Double = Mouse.GetPosition(Me).Y
319317
If Not IsSwapped AndAlso
320-
(SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判
321-
IsMouseDown = True
318+
(Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return
319+
IsCustomMouseDown = True
320+
If Not IsSwapped AndAlso
321+
(SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判
322+
IsSwapMouseDown = True
322323
End Sub
323-
Private Sub MyCard_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp
324-
If Not IsMouseDown Then Return
325-
IsMouseDown = False
324+
Private Sub MyCard_MouseLeftButtonUp() Handles Me.MouseLeftButtonUp
325+
If Not IsCustomMouseDown Then Return
326+
IsCustomMouseDown = False
327+
RaiseCustomEvent() '触发自定义事件
328+
329+
If Not IsSwapMouseDown Then Return
330+
IsSwapMouseDown = False
326331

327332
Dim Pos As Double = Mouse.GetPosition(Me).Y
328333
If Not IsSwapped AndAlso
329-
(SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判
334+
(SwapControl Is Nothing OrElse Pos > If(IsSwapped, SwapedHeight, SwapedHeight - 6) OrElse (Pos = 0 AndAlso Not IsMouseDirectlyOver)) Then Return '检测点击位置;或已经不在可视树上的误判
330335

331-
Dim ee = New RouteEventArgs(True)
332-
RaiseEvent PreviewSwap(Me, ee)
333-
If ee.Handled Then
334-
IsMouseDown = False
336+
Dim e = New RouteEventArgs(True)
337+
RaiseEvent PreviewSwap(Me, e)
338+
If e.Handled Then
339+
IsSwapMouseDown = False
335340
Return
336341
End If
337342

338343
IsSwapped = Not IsSwapped
339344
Log("[Control] " & If(IsSwapped, "折叠卡片", "展开卡片") & If(Title Is Nothing, "", ":" & Title))
340-
RaiseEvent Swap(Me, ee)
345+
RaiseEvent Swap(Me, e)
341346
End Sub
342347
Private Sub MyCard_MouseLeave_Swap(sender As Object, e As MouseEventArgs) Handles Me.MouseLeave
343-
IsMouseDown = False
348+
IsSwapMouseDown = False
344349
End Sub
345350

346351
#End Region

Plain Craft Launcher 2/Controls/MyCheckBox.xaml.vb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ Public Class MyCheckBox
1212
''' <param name="user">是否为用户手动改变的勾选状态。</param>
1313
Public Event Change(sender As Object, user As Boolean)
1414
Public Event PreviewChange(sender As Object, e As RouteEventArgs)
15-
Public Sub RaiseChange()
16-
RaiseEvent Change(Me, False)
17-
End Sub '使外部程序引发本控件的 Change 事件
1815

1916
'自定义属性
2017
Public Property Checked As Boolean?
@@ -78,6 +75,7 @@ Public Class MyCheckBox
7875

7976
'更改动画
8077
SyncUI()
78+
RaiseCustomEvent()
8179
Catch ex As Exception
8280
Log(ex, "设置 Checked 失败")
8381
End Try

Plain Craft Launcher 2/Controls/MyComboBox.vb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,25 @@
133133
Private IsTextChanging As Boolean = False
134134
Private Sub MyComboBox_TextChanged(sender As Object, e As TextChangedEventArgs) Handles Me.TextChanged
135135
If IsTextChanging OrElse Not IsEditable Then Return
136-
If SelectedItem IsNot Nothing AndAlso Text <> SelectedItem.ToString Then
137-
Dim RawText As String = Text
138-
Dim RawSelectionStart As Integer = TextBox.SelectionStart
139-
IsTextChanging = True
140-
SelectedItem = Nothing
141-
Text = RawText
142-
TextBox.SelectionStart = RawSelectionStart
143-
IsTextChanging = False
144-
End If
136+
If SelectedItem Is Nothing OrElse Text = SelectedItem.ToString Then Return
137+
Dim rawText As String = Text
138+
Dim rawSelectionStart As Integer = TextBox.SelectionStart
139+
IsTextChanging = True
140+
SelectedItem = Nothing
141+
Text = rawText
142+
TextBox.SelectionStart = rawSelectionStart
143+
IsTextChanging = False
145144
End Sub
146145

147146
Public ReadOnly Property ContentPresenter As ContentPresenter
148147
Get
149148
Return Template.FindName("PART_Content", Me)
150149
End Get
151150
End Property
151+
152+
Private Sub MyComboBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles Me.SelectionChanged
153+
If IsLoaded AndAlso AniControlEnabled = 0 Then RaiseCustomEvent()
154+
End Sub
152155

153156
'用于 ItemsSource 的自定义容器
154157
Protected Overrides Function GetContainerForItemOverride() As DependencyObject

Plain Craft Launcher 2/Controls/MyExtraButton.xaml.vb

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,26 @@
5353
Set(value As Boolean)
5454
If _Show = value Then Return
5555
_Show = value
56-
RunInUi(Sub()
57-
If value Then
58-
'有了
59-
Visibility = Visibility.Visible
60-
AniStart({
61-
AaScaleTransform(Me, 0.3 - CType(RenderTransform, ScaleTransform).ScaleX, 500, 60, New AniEaseOutFluent(AniEasePower.Weak)),
62-
AaScaleTransform(Me, 0.7, 500, 60, New AniEaseOutBack(AniEasePower.Weak)),
63-
AaHeight(Me, 50 - Height, 200,, New AniEaseOutFluent(AniEasePower.Weak))
64-
}, "MyExtraButton MainScale " & Uuid)
65-
Else
66-
'没了
67-
AniStart({
68-
AaScaleTransform(Me, -CType(RenderTransform, ScaleTransform).ScaleX, 100,, New AniEaseInFluent(AniEasePower.Weak)),
69-
AaHeight(Me, -Height, 400, 100, New AniEaseOutFluent()),
70-
AaCode(Sub() Visibility = Visibility.Collapsed,, True)
71-
}, "MyExtraButton MainScale " & Uuid)
72-
End If
73-
IsHitTestVisible = value '防止缩放动画中依然可以点进去
74-
End Sub)
56+
RunInUi(
57+
Sub()
58+
If value Then
59+
'有了
60+
Visibility = Visibility.Visible
61+
AniStart({
62+
AaScaleTransform(Me, 0.3 - CType(RenderTransform, ScaleTransform).ScaleX, 500, 60, New AniEaseOutFluent(AniEasePower.Weak)),
63+
AaScaleTransform(Me, 0.7, 500, 60, New AniEaseOutBack(AniEasePower.Weak)),
64+
AaHeight(Me, 50 - Height, 200,, New AniEaseOutFluent(AniEasePower.Weak))
65+
}, "MyExtraButton MainScale " & Uuid)
66+
Else
67+
'没了
68+
AniStart({
69+
AaScaleTransform(Me, -CType(RenderTransform, ScaleTransform).ScaleX, 100,, New AniEaseInFluent(AniEasePower.Weak)),
70+
AaHeight(Me, -Height, 400, 100, New AniEaseOutFluent()),
71+
AaCode(Sub() Visibility = Visibility.Collapsed,, True)
72+
}, "MyExtraButton MainScale " & Uuid)
73+
End If
74+
IsHitTestVisible = value '防止缩放动画中依然可以点进去
75+
End Sub)
7576
End Set
7677
End Property
7778
Public Delegate Function ShowCheckDelegate() As Boolean
@@ -137,6 +138,7 @@
137138
AaScaleTransform(PanScale, 1 - CType(PanScale.RenderTransform, ScaleTransform).ScaleX, 300,, New AniEaseOutBack)
138139
}, "MyExtraButton Scale " & Uuid)
139140
End If
141+
If IsLeftMouseHeld Then RaiseCustomEvent()
140142
IsLeftMouseHeld = False
141143
RefreshColor() '直接刷新颜色以判断是否已触发 MouseLeave
142144
End Sub
@@ -199,16 +201,17 @@
199201
''' 发出一圈波浪效果提示。
200202
''' </summary>
201203
Public Sub Ribble()
202-
RunInUi(Sub()
203-
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()}
204-
Shape.SetResourceReference(Border.BackgroundProperty, "ColorBrush5")
205-
PanScale.Children.Insert(0, Shape)
206-
AniStart({
207-
AaScaleTransform(Shape, 13, 1000, Ease:=New AniEaseInoutFluent(AniEasePower.Strong, 0.3)),
208-
AaOpacity(Shape, -Shape.Opacity, 1000),
209-
AaCode(Sub() PanScale.Children.Remove(Shape), After:=True)
210-
}, "ExtraButton Ribble " & GetUuid())
211-
End Sub)
204+
RunInUi(
205+
Sub()
206+
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()}
207+
shape.SetResourceReference(Border.BackgroundProperty, "ColorBrush5")
208+
PanScale.Children.Insert(0, shape)
209+
AniStart({
210+
AaScaleTransform(shape, 13, 1000, Ease:=New AniEaseInoutFluent(AniEasePower.Strong, 0.3)),
211+
AaOpacity(shape, -shape.Opacity, 1000),
212+
AaCode(Sub() PanScale.Children.Remove(shape), After:=True)
213+
}, "ExtraButton Ribble " & GetUuid())
214+
End Sub)
212215
End Sub
213216

214217
End Class

Plain Craft Launcher 2/Controls/MyExtraTextButton.xaml.vb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ Public Class MyExtraTextButton
8181

8282
'触发点击事件
8383
Private Sub Button_LeftMouseUp(sender As Object, e As MouseButtonEventArgs) Handles PanClick.MouseLeftButtonUp
84-
If IsLeftMouseHeld Then
85-
Log("[Control] 按下附加图标按钮:" & Text)
86-
RaiseEvent Click(sender, e)
87-
e.Handled = True
88-
Button_LeftMouseUp()
89-
End If
84+
If Not IsLeftMouseHeld Then Return
85+
Log("[Control] 按下附加图标按钮:" & Text)
86+
RaiseEvent Click(sender, e)
87+
e.Handled = True
88+
RaiseCustomEvent()
89+
Button_LeftMouseUp()
9090
End Sub
9191

9292
'鼠标点击判定(务必放在点击事件之后,以使得 Button_MouseUp 先于 Button_MouseLeave 执行)

Plain Craft Launcher 2/Controls/MyHint.xaml.vb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,14 @@ Public Class MyHint
113113
IsMouseDown = False
114114
Log("[Control] 按下提示条" & If(String.IsNullOrEmpty(Name), "", ":" & Name))
115115
e.Handled = True
116-
ModEvent.TryStartEvent(EventType, EventData)
116+
RaiseCustomEvent() '自定义事件
117117
End Sub
118118
Private Sub MyHint_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
119119
IsMouseDown = True
120120
End Sub
121121
Private Sub MyHint_MouseLeave() Handles Me.MouseLeave
122122
IsMouseDown = False
123123
End Sub
124-
Public Property EventType As String
125-
Get
126-
Return GetValue(EventTypeProperty)
127-
End Get
128-
Set(value As String)
129-
SetValue(EventTypeProperty, value)
130-
End Set
131-
End Property
132-
Public Shared ReadOnly EventTypeProperty As DependencyProperty = DependencyProperty.Register("EventType", GetType(String), GetType(MyHint), New PropertyMetadata(Nothing))
133-
Public Property EventData As String
134-
Get
135-
Return GetValue(EventDataProperty)
136-
End Get
137-
Set(value As String)
138-
SetValue(EventDataProperty, value)
139-
End Set
140-
End Property
141-
Public Shared ReadOnly EventDataProperty As DependencyProperty = DependencyProperty.Register("EventData", GetType(String), GetType(MyHint), New PropertyMetadata(Nothing))
142124

143125
Private Sub _ThemeChanged(isDarkMode As Boolean, theme As ColorTheme)
144126
UpdateUI()

0 commit comments

Comments
 (0)