-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathDialogControl.cs
More file actions
193 lines (170 loc) · 5.8 KB
/
Copy pathDialogControl.cs
File metadata and controls
193 lines (170 loc) · 5.8 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
182
183
184
185
186
187
188
189
190
191
192
193
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Threading;
using PCL.Core.UI;
using PCL.Core.UI.Controls;
namespace PCL;
public partial class DialogControl
{
private int _result;
private bool _exited;
private readonly int _uuid = ModBase.GetUuid();
internal readonly List<(DialogButton Data, MyButton Control)> _buttons = [];
public DispatcherFrame WaitFrame { get; } = new(true);
public string Title
{
get => LabTitle.Text;
set => LabTitle.Text = value;
}
public bool IsWarn { get; set; }
private bool _showTitle = true;
internal bool ShowTitle
{
get => _showTitle;
set
{
_showTitle = value;
LabTitle.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
ShapeLine.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
}
}
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(DialogButton button)
{
var btn = DialogButtonBuilder.Build(button, IsWarn);
var buttonId = button.Id > 0 ? button.Id : _buttons.Count + 1;
btn.Click += (_, _) =>
{
if (_exited) return;
if (button.OnClick is not null)
button.OnClick();
else
Close(buttonId);
};
_buttons.Add((button, btn));
PanBtn.Children.Add(btn);
return btn;
}
public event Action<int>? OnClosed;
private void OnLoad(object sender, RoutedEventArgs e)
{
try
{
if (IsWarn)
LabTitle.SetResourceReference(TextBlock.ForegroundProperty, "ColorBrushRedLight");
if (_buttons.Count > 1 && _buttons[0].Control.ColorType != MyButton.ColorState.Red)
_buttons[0].Control.ColorType = MyButton.ColorState.Highlight;
if (_buttons.Count > 0)
_buttons[0].Control.Focus();
else
PanBtn.Visibility = Visibility.Collapsed;
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(int result)
{
if (_exited) return;
_exited = true;
_result = result;
CloseInternal();
}
public void Close()
{
if (_exited) return;
_exited = true;
_result = -1;
CloseInternal();
}
private void CloseInternal()
{
try
{
WaitFrame.Continue = false;
}
catch
{
// ignore
}
try
{
ComponentDispatcher.PopModal();
}
catch
{
// ignore
}
OnClosed?.Invoke(_result);
ModAnimation.AniStart(
new ModAnimation.AniData[]
{
ModAnimation.AaCode(() =>
{
var hasMore = (ModMain.frmMain?.PanMsg?.Children.Count ?? 0) > 1;
if (!hasMore)
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);
}
}
}