Skip to content

Commit 32bd968

Browse files
committed
feat:Dialog更改至MainWindow
1 parent 58ea9f6 commit 32bd968

6 files changed

+142
-118
lines changed

MainPage.xaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
</DockPanel>
4040
</Border>
4141
</Grid>
42-
<Grid x:Name="FrontGrid" x:FieldModifier="public" Grid.Row="0" Grid.RowSpan="4" Visibility="Hidden">
43-
<Rectangle x:Name="DialogRect" Opacity="0" Fill="Black" ></Rectangle>
44-
<Border x:Name="DialogBorder" Width="0" Height="0" Background="White" CornerRadius="12">
45-
<StackPanel x:Name="DialogStackPan" VerticalAlignment="Top" HorizontalAlignment="Left" Width="400" Height="250"></StackPanel>
46-
</Border>
47-
<Border x:Name="FrontBorder" Width="400" Height="250" Background="White" CornerRadius="12" Visibility="Hidden"></Border>
48-
</Grid>
42+
4943
</Grid>
5044
</Page>

MainPage.xaml.cs

+9-110
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using static SodaCL.Core.Auth.MSAuth;
1313
using static SodaCL.Launcher.LauncherLogging;
1414
using static SodaCL.Toolkits.GetResources;
15+
using static SodaCL.Toolkits.Dialog;
1516

1617
namespace SodaCL.Pages
1718
{
@@ -112,6 +113,7 @@ private async void GetYiyanAsync()
112113
}
113114
catch (HttpRequestException ex)
114115
{
116+
YiYanTxb.Text = "一言获取失败";
115117
Log(ModuleList.Network, LogInfo.Error, ex.Message, ex.StackTrace);
116118
}
117119
}
@@ -186,8 +188,8 @@ private async void MSOAuth_OpenWindows(object sender, (MSAuth.WindowsTypes, stri
186188
await Dispatcher.InvokeAsync(() =>
187189
{
188190
OpenDialog();
189-
DialogStackPan.Children.Add(new TextBlock() { Text = "正在初始化微软登录服务", FontSize = 18, TextAlignment = TextAlignment.Center });
190-
DialogStackPan.Children.Add(new ProgressBar() { IsIndeterminate = true, Height = 10, Width = 300, Margin = new Thickness(0, 30, 0, 0) });
191+
MainWindow.mainWindow.DialogStackPan.Children.Add(new TextBlock() { Text = "正在初始化微软登录服务", FontSize = 18, TextAlignment = TextAlignment.Center });
192+
MainWindow.mainWindow.DialogStackPan.Children.Add(new ProgressBar() { IsIndeterminate = true, Height = 10, Width = 300, Margin = new Thickness(0, 30, 0, 0) });
191193
});
192194
break;
193195
}
@@ -256,131 +258,28 @@ await Dispatcher.InvokeAsync(() =>
256258
Text = GetI18NText("Login_Microsoft_MessageBox_OpenInBrowser_Title")
257259
});
258260
StackPan.Children.Add(exitButton);
259-
DialogStackPan.Children.Add(StackPan);
260-
DialogStackPan.Children.Add(new TextBlock
261+
MainWindow.mainWindow.DialogStackPan.Children.Add(StackPan);
262+
MainWindow.mainWindow.DialogStackPan.Children.Add(new TextBlock
261263
{
262264
Margin = new Thickness(52, 10, 20, 0),
263265
Text = GetI18NText("Login_Microsoft_MessageBox_OpenInBrowser_Text_Tip")
264266
});
265-
DialogStackPan.Children.Add(new TextBlock
267+
MainWindow.mainWindow.DialogStackPan.Children.Add(new TextBlock
266268
{
267269
Margin = new Thickness(50, 10, 20, 0),
268270
Style = GetStyle("Text_Bold"),
269271
Text = GetI18NText("Login_Microsoft_MessageBox_OpenInBrowser_Text_YourLoginCode")
270272
});
271-
DialogStackPan.Children.Add(new TextBlock
273+
MainWindow.mainWindow.DialogStackPan.Children.Add(new TextBlock
272274
{
273275
Margin = new Thickness(50, 5, 20, 0),
274276
Text = deviceCode,
275277
FontSize = 24,
276278
});
277-
DialogStackPan.Children.Add(okButton);
279+
MainWindow.mainWindow.DialogStackPan.Children.Add(okButton);
278280
});
279281
}
280282

281-
private void OpenDialog()
282-
{
283-
FrontGrid.Visibility = Visibility.Visible;
284-
var easingFunc = new CubicEase
285-
{
286-
EasingMode = EasingMode.EaseInOut
287-
};
288-
var diaSbBig = new Storyboard();
289-
var rectBigOpacAni = new DoubleAnimation(0.6, TimeSpan.FromSeconds(1));
290-
Storyboard.SetTarget(rectBigOpacAni, DialogRect);
291-
Storyboard.SetTargetProperty(rectBigOpacAni, new PropertyPath("Opacity"));
292-
var borderBigWidthAni = new DoubleAnimation(400, TimeSpan.FromSeconds(1));
293-
borderBigWidthAni.EasingFunction = easingFunc;
294-
Storyboard.SetTarget(borderBigWidthAni, DialogBorder);
295-
Storyboard.SetTargetProperty(borderBigWidthAni, new PropertyPath("Width"));
296-
var borderBigHeightAni = new DoubleAnimation(250, TimeSpan.FromSeconds(1));
297-
borderBigHeightAni.EasingFunction = easingFunc;
298-
Storyboard.SetTarget(borderBigHeightAni, DialogBorder);
299-
Storyboard.SetTargetProperty(borderBigHeightAni, new PropertyPath("Height"));
300-
diaSbBig.Children.Add(rectBigOpacAni);
301-
diaSbBig.Children.Add(borderBigWidthAni);
302-
diaSbBig.Children.Add(borderBigHeightAni);
303-
diaSbBig.Begin();
304-
}
305-
306-
private void ChangeDialog()
307-
{
308-
DialogStackPan.Children.Clear();
309-
FrontBorder.Visibility = Visibility.Visible;
310-
DialogBorder.Visibility = Visibility.Hidden;
311-
var easingFunc = new CubicEase
312-
{
313-
EasingMode = EasingMode.EaseInOut
314-
};
315-
var froSbSmall = new Storyboard();
316-
317-
var borderSmallWidthAni = new DoubleAnimation(400, 0, TimeSpan.FromSeconds(0.5));
318-
borderSmallWidthAni.EasingFunction = easingFunc;
319-
320-
Storyboard.SetTarget(borderSmallWidthAni, FrontBorder);
321-
Storyboard.SetTargetProperty(borderSmallWidthAni, new PropertyPath("Width"));
322-
323-
var borderSmallHeightAni = new DoubleAnimation(250, 0, TimeSpan.FromSeconds(0.5));
324-
borderSmallHeightAni.EasingFunction = easingFunc;
325-
326-
Storyboard.SetTarget(borderSmallHeightAni, FrontBorder);
327-
Storyboard.SetTargetProperty(borderSmallHeightAni, new PropertyPath("Height"));
328-
329-
froSbSmall.Children.Add(borderSmallWidthAni);
330-
froSbSmall.Children.Add(borderSmallHeightAni);
331283

332-
var diaSbBig = new Storyboard();
333-
334-
var forBorderBigWidthAni = new DoubleAnimation(0, 400, TimeSpan.FromSeconds(1));
335-
forBorderBigWidthAni.EasingFunction = easingFunc;
336-
Storyboard.SetTarget(forBorderBigWidthAni, DialogBorder);
337-
Storyboard.SetTargetProperty(forBorderBigWidthAni, new PropertyPath("Width"));
338-
339-
var forBorderBigHeightAni = new DoubleAnimation(0, 250, TimeSpan.FromSeconds(1));
340-
forBorderBigHeightAni.EasingFunction = easingFunc;
341-
Storyboard.SetTarget(forBorderBigHeightAni, DialogBorder);
342-
Storyboard.SetTargetProperty(forBorderBigHeightAni, new PropertyPath("Height"));
343-
diaSbBig.Children.Add(forBorderBigWidthAni);
344-
diaSbBig.Children.Add(forBorderBigHeightAni);
345-
346-
froSbSmall.Completed += (object sender, EventArgs e) =>
347-
{
348-
FrontBorder.Visibility = Visibility.Hidden;
349-
DialogBorder.Visibility = Visibility.Visible;
350-
351-
diaSbBig.Begin();
352-
Trace.WriteLine(FrontBorder.Width + FrontBorder.Width);
353-
};
354-
froSbSmall.Begin();
355-
}
356-
357-
private void CloseDialog()
358-
{
359-
var easingFunc = new CubicEase
360-
{
361-
EasingMode = EasingMode.EaseInOut
362-
};
363-
var diaSbSmall = new Storyboard();
364-
var rectSmallOpacAni = new DoubleAnimation(0, TimeSpan.FromSeconds(0.6));
365-
Storyboard.SetTarget(rectSmallOpacAni, DialogRect);
366-
Storyboard.SetTargetProperty(rectSmallOpacAni, new PropertyPath("Opacity"));
367-
var borderSmallWidthAni = new DoubleAnimation(0, TimeSpan.FromSeconds(1));
368-
borderSmallWidthAni.EasingFunction = easingFunc;
369-
Storyboard.SetTarget(borderSmallWidthAni, DialogBorder);
370-
Storyboard.SetTargetProperty(borderSmallWidthAni, new PropertyPath("Width"));
371-
var borderSmallHeightAni = new DoubleAnimation(0, TimeSpan.FromSeconds(1));
372-
borderSmallHeightAni.EasingFunction = easingFunc;
373-
Storyboard.SetTarget(borderSmallHeightAni, DialogBorder);
374-
Storyboard.SetTargetProperty(borderSmallHeightAni, new PropertyPath("Height"));
375-
diaSbSmall.Children.Add(rectSmallOpacAni);
376-
diaSbSmall.Children.Add(borderSmallWidthAni);
377-
diaSbSmall.Children.Add(borderSmallHeightAni);
378-
diaSbSmall.Completed += (object sender, EventArgs e) =>
379-
{
380-
FrontGrid.Visibility = Visibility.Hidden;
381-
DialogStackPan.Children.Clear();
382-
};
383-
diaSbSmall.Begin();
384-
}
385284
}
386285
}

MainWindow.xaml

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
</Grid>
5656
</Border>
5757
<Frame x:Name="MainFram" Grid.Row="1" Source="./MainPage.xaml" NavigationUIVisibility="Hidden" Style="{x:Null}"></Frame>
58+
<Grid x:Name="FrontGrid" x:FieldModifier="public" Grid.Row="3" Grid.RowSpan="4" Visibility="Hidden">
59+
<Rectangle x:Name="DialogRect" Opacity="0" Fill="Black" ></Rectangle>
60+
<Border x:Name="DialogBorder" Width="0" Height="0" Background="White" CornerRadius="12">
61+
<StackPanel x:Name="DialogStackPan" VerticalAlignment="Top" HorizontalAlignment="Left" Width="400" Height="250"></StackPanel>
62+
</Border>
63+
<Border x:Name="FrontBorder" Width="400" Height="250" Background="White" CornerRadius="12" Visibility="Hidden"></Border>
64+
</Grid>
5865
</Grid>
5966
</Border>
6067
</Border>

MainWindow.xaml.cs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Windows;
67
using System.Windows.Input;
78
using System.Windows.Media.Animation;
@@ -17,11 +18,15 @@ namespace SodaCL
1718
/// </summary>
1819
public partial class MainWindow : Window
1920
{
21+
public static MainWindow mainWindow;
2022
public static LauncherInfo launcherInfo;
2123
public static List<MCClient> clients = new();
2224

2325
public MainWindow()
2426
{
27+
mainWindow = Application.Current.Windows
28+
.Cast<Window>()
29+
.FirstOrDefault(window => window is MainWindow) as MainWindow;
2530
InitializeComponent();
2631
}
2732

Soda_Craft_Launcher.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.3.32929.385
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SodaCL", ".\SodaCL.csproj", "{DCA68EDB-AF33-4F64-BD6E-DD2D852DF9B4}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SodaCL", "SodaCL.csproj", "{DCA68EDB-AF33-4F64-BD6E-DD2D852DF9B4}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Toolkits/Dialog.cs

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Media.Animation;
8+
using System.Windows;
9+
10+
namespace SodaCL.Toolkits
11+
{
12+
public class Dialog
13+
{
14+
public static void OpenDialog()
15+
{
16+
MainWindow.mainWindow.FrontGrid.Visibility = Visibility.Visible;
17+
var easingFunc = new CubicEase
18+
{
19+
EasingMode = EasingMode.EaseInOut
20+
};
21+
var diaSbBig = new Storyboard();
22+
var rectBigOpacAni = new DoubleAnimation(0.6, TimeSpan.FromSeconds(1));
23+
Storyboard.SetTarget(rectBigOpacAni, MainWindow.mainWindow.DialogRect);
24+
Storyboard.SetTargetProperty(rectBigOpacAni, new PropertyPath("Opacity"));
25+
var borderBigWidthAni = new DoubleAnimation(400, TimeSpan.FromSeconds(1));
26+
borderBigWidthAni.EasingFunction = easingFunc;
27+
Storyboard.SetTarget(borderBigWidthAni, MainWindow.mainWindow.DialogBorder);
28+
Storyboard.SetTargetProperty(borderBigWidthAni, new PropertyPath("Width"));
29+
var borderBigHeightAni = new DoubleAnimation(250, TimeSpan.FromSeconds(1));
30+
borderBigHeightAni.EasingFunction = easingFunc;
31+
Storyboard.SetTarget(borderBigHeightAni, MainWindow.mainWindow.DialogBorder);
32+
Storyboard.SetTargetProperty(borderBigHeightAni, new PropertyPath("Height"));
33+
diaSbBig.Children.Add(rectBigOpacAni);
34+
diaSbBig.Children.Add(borderBigWidthAni);
35+
diaSbBig.Children.Add(borderBigHeightAni);
36+
diaSbBig.Begin();
37+
}
38+
39+
public static void ChangeDialog()
40+
{
41+
MainWindow.mainWindow.DialogStackPan.Children.Clear();
42+
MainWindow.mainWindow.FrontBorder.Visibility = Visibility.Visible;
43+
MainWindow.mainWindow.DialogBorder.Visibility = Visibility.Hidden;
44+
var easingFunc = new CubicEase
45+
{
46+
EasingMode = EasingMode.EaseInOut
47+
};
48+
var froSbSmall = new Storyboard();
49+
50+
var borderSmallWidthAni = new DoubleAnimation(400, 0, TimeSpan.FromSeconds(0.5));
51+
borderSmallWidthAni.EasingFunction = easingFunc;
52+
53+
Storyboard.SetTarget(borderSmallWidthAni, MainWindow.mainWindow.FrontBorder);
54+
Storyboard.SetTargetProperty(borderSmallWidthAni, new PropertyPath("Width"));
55+
56+
var borderSmallHeightAni = new DoubleAnimation(250, 0, TimeSpan.FromSeconds(0.5));
57+
borderSmallHeightAni.EasingFunction = easingFunc;
58+
59+
Storyboard.SetTarget(borderSmallHeightAni, MainWindow.mainWindow.FrontBorder);
60+
Storyboard.SetTargetProperty(borderSmallHeightAni, new PropertyPath("Height"));
61+
62+
froSbSmall.Children.Add(borderSmallWidthAni);
63+
froSbSmall.Children.Add(borderSmallHeightAni);
64+
65+
var diaSbBig = new Storyboard();
66+
67+
var forBorderBigWidthAni = new DoubleAnimation(0, 400, TimeSpan.FromSeconds(1));
68+
forBorderBigWidthAni.EasingFunction = easingFunc;
69+
Storyboard.SetTarget(forBorderBigWidthAni, MainWindow.mainWindow.DialogBorder);
70+
Storyboard.SetTargetProperty(forBorderBigWidthAni, new PropertyPath("Width"));
71+
72+
var forBorderBigHeightAni = new DoubleAnimation(0, 250, TimeSpan.FromSeconds(1));
73+
forBorderBigHeightAni.EasingFunction = easingFunc;
74+
Storyboard.SetTarget(forBorderBigHeightAni, MainWindow.mainWindow.DialogBorder);
75+
Storyboard.SetTargetProperty(forBorderBigHeightAni, new PropertyPath("Height"));
76+
diaSbBig.Children.Add(forBorderBigWidthAni);
77+
diaSbBig.Children.Add(forBorderBigHeightAni);
78+
79+
froSbSmall.Completed += (object sender, EventArgs e) =>
80+
{
81+
MainWindow.mainWindow.FrontBorder.Visibility = Visibility.Hidden;
82+
MainWindow.mainWindow.DialogBorder.Visibility = Visibility.Visible;
83+
84+
diaSbBig.Begin();
85+
Trace.WriteLine(MainWindow.mainWindow.FrontBorder.Width + MainWindow.mainWindow.FrontBorder.Width);
86+
};
87+
froSbSmall.Begin();
88+
}
89+
90+
public static void CloseDialog()
91+
{
92+
var easingFunc = new CubicEase
93+
{
94+
EasingMode = EasingMode.EaseInOut
95+
};
96+
var diaSbSmall = new Storyboard();
97+
var rectSmallOpacAni = new DoubleAnimation(0, TimeSpan.FromSeconds(0.6));
98+
Storyboard.SetTarget(rectSmallOpacAni, MainWindow.mainWindow.DialogRect);
99+
Storyboard.SetTargetProperty(rectSmallOpacAni, new PropertyPath("Opacity"));
100+
var borderSmallWidthAni = new DoubleAnimation(0, TimeSpan.FromSeconds(1));
101+
borderSmallWidthAni.EasingFunction = easingFunc;
102+
Storyboard.SetTarget(borderSmallWidthAni, MainWindow.mainWindow.DialogBorder);
103+
Storyboard.SetTargetProperty(borderSmallWidthAni, new PropertyPath("Width"));
104+
var borderSmallHeightAni = new DoubleAnimation(0, TimeSpan.FromSeconds(1));
105+
borderSmallHeightAni.EasingFunction = easingFunc;
106+
Storyboard.SetTarget(borderSmallHeightAni, MainWindow.mainWindow.DialogBorder);
107+
Storyboard.SetTargetProperty(borderSmallHeightAni, new PropertyPath("Height"));
108+
diaSbSmall.Children.Add(rectSmallOpacAni);
109+
diaSbSmall.Children.Add(borderSmallWidthAni);
110+
diaSbSmall.Children.Add(borderSmallHeightAni);
111+
diaSbSmall.Completed += (object sender, EventArgs e) =>
112+
{
113+
MainWindow.mainWindow.FrontGrid.Visibility = Visibility.Hidden;
114+
MainWindow.mainWindow.DialogStackPan.Children.Clear();
115+
};
116+
diaSbSmall.Begin();
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)