-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathDialogControl.cs
More file actions
181 lines (161 loc) · 5.54 KB
/
Copy pathDialogControl.cs
File metadata and controls
181 lines (161 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Threading;
using PCL.Core.UI.Controls;
namespace PCL;
public partial class DialogControl
{
private int _result;
private bool _exited;
private readonly int _uuid = ModBase.GetUuid();
private readonly List<MyButton> _buttons = [];
public DispatcherFrame WaitFrame { get; } = new(true);
public string Title
{
get => LabTitle.Text;
set => LabTitle.Text = value;
}
public bool IsWarn { get; set; }
public UIElement? DialogContent
{
get => (UIElement?)ContentArea.Content;
set => ContentArea.Content = value;
}
public int Result => _result;
public DialogControl()
{
try
{
InitializeComponent();
ShapeLine.StrokeThickness = ModBase.GetWPFSize(1d);
}
catch (Exception ex)
{
ModBase.Log(ex, "DialogControl 初始化失败", ModBase.LogLevel.Hint);
}
Loaded += OnLoad;
}
public MyButton AddButton(string text, Action? onClick = null, bool isPrimary = false)
{
var btn = new MyButton
{
Text = text,
ColorType = isPrimary
? (IsWarn ? MyButton.ColorState.Red : MyButton.ColorState.Highlight)
: MyButton.ColorState.Normal,
Visibility = string.IsNullOrEmpty(text) ? Visibility.Collapsed : Visibility.Visible,
IsEnabled = true,
};
btn.ApplyTemplate();
btn.TextPadding = new Thickness(7);
btn.Padding = new Thickness(5, 0, 5, 0);
btn.Margin = new Thickness(12, 0, 0, 0);
btn.Name += ModBase.GetUuid();
var index = _buttons.Count + 1;
btn.Click += (_, _) =>
{
if (_exited) return;
if (onClick is not null)
{
onClick();
}
else
{
_exited = true;
_result = index;
Close();
}
};
_buttons.Add(btn);
PanBtn.Children.Add(btn);
return btn;
}
public event Action<int>? OnClosed;
private void OnLoad(object sender, RoutedEventArgs e)
{
try
{
if (_buttons.Count > 1 && _buttons[0].ColorType != MyButton.ColorState.Red)
_buttons[0].ColorType = MyButton.ColorState.Highlight;
if (_buttons.Count > 0)
_buttons[0].Focus();
Opacity = 0d;
ModAnimation.AniStart(
ModAnimation.AaColor(ModMain.frmMain.PanMsgBackground, BlurBorder.BackgroundProperty,
(IsWarn
? new ModBase.MyColor(140d, 80d, 0d, 0d)
: new ModBase.MyColor(90d, 0d, 0d, 0d)) - ModMain.frmMain.PanMsgBackground.Background, 200),
"PanMsgBackground Background");
ModAnimation.AniStart(
new ModAnimation.AniData[]
{
ModAnimation.AaOpacity(this, 1d, 120, 60),
ModAnimation.AaDouble(i => TransformPos.Y += (double)i,
-TransformPos.Y, 300, 60, new ModAnimation.AniEaseOutBack(ModAnimation.AniEasePower.Weak)),
ModAnimation.AaDouble(i => TransformRotate.Angle += (double)i,
-TransformRotate.Angle, 300, 60,
new ModAnimation.AniEaseOutFluent(ModAnimation.AniEasePower.Weak))
}, "DialogControl " + _uuid);
ModBase.Log("[Dialog] " + LabTitle.Text);
}
catch (Exception ex)
{
ModBase.Log(ex, "DialogControl 加载失败", ModBase.LogLevel.Hint);
}
}
public void Close()
{
if (_exited && _result == 0)
_result = -1;
_exited = true;
try
{
WaitFrame.Continue = false;
}
catch
{
// ignore
}
try
{
ComponentDispatcher.PopModal();
}
catch
{
// ignore
}
OnClosed?.Invoke(_result);
ModAnimation.AniStart(
new ModAnimation.AniData[]
{
ModAnimation.AaCode(() =>
{
if (!ModMain.WaitingMyMsgBox.Any())
ModAnimation.AniStart(ModAnimation.AaColor(ModMain.frmMain.PanMsgBackground,
BlurBorder.BackgroundProperty,
new ModBase.MyColor(0d, 0d, 0d, 0d) - ModMain.frmMain.PanMsgBackground.Background, 200,
ease: new ModAnimation.AniEaseOutFluent(ModAnimation.AniEasePower.Weak)));
}, 30),
ModAnimation.AaOpacity(this, -Opacity, 80, 20),
ModAnimation.AaDouble(i => TransformPos.Y += (double)i, 20d - TransformPos.Y,
150, 0, new ModAnimation.AniEaseOutFluent()),
ModAnimation.AaDouble(i => TransformRotate.Angle += (double)i,
6d - TransformRotate.Angle, 150, 0, new ModAnimation.AniEaseInFluent(ModAnimation.AniEasePower.Weak)),
ModAnimation.AaCode(() => ((Grid)Parent)?.Children.Remove(this), after: true)
}, "DialogControl " + _uuid);
}
private void Drag(object sender, MouseButtonEventArgs e)
{
try
{
if (e.LeftButton == MouseButtonState.Pressed && e.GetPosition(ShapeLine).Y <= 2d)
ModMain.frmMain.DragMove();
}
catch (Exception ex)
{
ModBase.Log(ex, "拖拽移动失败", ModBase.LogLevel.Hint);
}
}
}