Skip to content

Commit d75acbe

Browse files
committed
- Add Progress Bar
- Refactor Callbacks
1 parent d67afc6 commit d75acbe

7 files changed

Lines changed: 200 additions & 81 deletions

File tree

Cloaks/Cloaks+.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
107107
<Compile Include="DialogueBox.xaml.cs">
108108
<DependentUpon>DialogueBox.xaml</DependentUpon>
109109
</Compile>
110+
<Compile Include="InstallProgress.xaml.cs">
111+
<DependentUpon>InstallProgress.xaml</DependentUpon>
112+
</Compile>
110113
<Page Include="CloaksLoad.xaml">
111114
<SubType>Designer</SubType>
112115
<Generator>MSBuild:Compile</Generator>
@@ -132,6 +135,10 @@
132135
<SubType>Designer</SubType>
133136
<Generator>MSBuild:Compile</Generator>
134137
</Page>
138+
<Page Include="InstallProgress.xaml">
139+
<SubType>Designer</SubType>
140+
<Generator>MSBuild:Compile</Generator>
141+
</Page>
135142
</ItemGroup>
136143
<ItemGroup>
137144
<Compile Include="Properties\AssemblyInfo.cs">
@@ -223,7 +230,7 @@
223230
<Resource Include="Assets\cloaks_plus.ico" />
224231
</ItemGroup>
225232
<ItemGroup>
226-
<Content Include="EmbeddedAssemblies\Newtonsoft.Json.dll" />
233+
<EmbeddedResource Include="EmbeddedAssemblies\Newtonsoft.Json.dll" />
227234
</ItemGroup>
228235
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
229236
<Target Name="AfterResolveReferences">

Cloaks/DialogueBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
x:Class="Cloaks.DialogueBox"
88
mc:Ignorable="d"
99
Title="Cloaks+ Message"
10-
Topmost="True"
10+
Topmost="False"
1111
WindowStartupLocation="CenterScreen"
1212
WindowStyle="None"
1313
ResizeMode="NoResize"

Cloaks/DialogueBox.xaml.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,49 @@ namespace Cloaks
77
{
88
public partial class DialogueBox : Window
99
{
10-
private Action<bool> callback;
1110
private string title;
1211
private string message;
1312
private bool error;
1413
private MainWindow main;
1514
private bool eula;
1615

17-
private DialogueBox(string title, string message, bool error, Action<bool> callback, MainWindow main, bool eula)
16+
private bool result;
17+
18+
private DialogueBox(string title, string message, bool error, MainWindow main, bool eula)
1819
{
1920
this.title = title;
2021
this.message = message;
2122
this.error = error;
22-
this.callback = callback;
2323
this.main = main;
2424
this.eula = eula;
2525

2626
InitializeComponent();
2727
Hide();
2828
}
2929

30-
public static void Show(string title, string message, MainWindow main)
30+
public static bool Show(string title, string message, MainWindow main)
3131
{
32-
33-
new DialogueBox(title, message, false, null, main, false).ShowDialog();
34-
}
3532

36-
public static void ShowWithCallback(string title, string message, Action<bool> callback, MainWindow main)
37-
{
38-
39-
new DialogueBox(title, message, false, callback, main, false).ShowDialog();
40-
}
33+
DialogueBox w = new DialogueBox(title, message, false, main, false);
34+
w.ShowDialog();
4135

42-
public static void ShowError(string title, string message, MainWindow main)
43-
{
44-
45-
new DialogueBox(title, message, true, null, main, false).ShowDialog();
36+
return w.result;
4637
}
4738

48-
public static void ShowErrorWithCallback(string title, string message, Action<bool> callback, MainWindow main)
39+
public static bool ShowError(string title, string message, MainWindow main)
4940
{
50-
51-
new DialogueBox(title, message, true, callback, main, false).ShowDialog();
41+
DialogueBox w = new DialogueBox(title, message, true, main, false);
42+
w.ShowDialog();
43+
44+
return w.result;
5245
}
5346

54-
public static void ShowEULA(Action<bool> callback, MainWindow main)
47+
public static bool ShowEULA(MainWindow main)
5548
{
56-
57-
new DialogueBox("Cloaks+ End User License Agreement", @"By clicking 'I Agree' below, you agree to the Cloaks+ End User License Agreement. To view the contents of the agreement, click the 'EULA' button below.", false, callback, main, true).ShowDialog();
49+
DialogueBox w = new DialogueBox("Cloaks+ End User License Agreement", @"By clicking 'I Agree' below, you agree to the Cloaks+ End User License Agreement. To view the contents of the agreement, click the 'EULA' button below.", false, main, true);
50+
w.ShowDialog();
51+
52+
return w.result;
5853
}
5954

6055
private void Box_Loaded(object sender, RoutedEventArgs e)
@@ -100,15 +95,16 @@ private void OKButton_Click(object sender, RoutedEventArgs e)
10095

10196
private void CloseDialogue(bool result)
10297
{
103-
Close();
98+
this.result = result;
99+
104100
try
105101
{
106102
main.Show();
107103
main.Activate();
108104
}
109105
catch (Exception) { };
110106

111-
callback?.Invoke(result);
107+
Close();
112108
}
113109

114110
private void EULAButton_Click(object sender, RoutedEventArgs e)

Cloaks/InstallProgress.xaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<Window
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
7+
x:Class="Cloaks.InstallProgress"
8+
mc:Ignorable="d"
9+
Title="Cloaks+ Install Prompt"
10+
Topmost="False"
11+
WindowStartupLocation="CenterScreen"
12+
WindowStyle="None"
13+
ResizeMode="NoResize"
14+
AllowsTransparency="True"
15+
BorderThickness="0"
16+
Background="Transparent"
17+
Width="450"
18+
Loaded="Box_Loaded"
19+
>
20+
<Window.TaskbarItemInfo>
21+
<TaskbarItemInfo
22+
x:Name="taskBarItemInfo"
23+
ThumbnailClipMargin="0,0,0,0"
24+
Description="Cloaks+ Message Box"
25+
></TaskbarItemInfo>
26+
</Window.TaskbarItemInfo>
27+
28+
<Grid Margin="0,50,0,0">
29+
<Border x:Name="MainBorder" BorderThickness="0" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center" Width="400" Background="#FF151515" CornerRadius="5" Grid.RowSpan="2">
30+
<Border.Effect>
31+
<DropShadowEffect ShadowDepth="0" BlurRadius="20"/>
32+
</Border.Effect>
33+
<Grid>
34+
35+
<!--Window Title Bar-->
36+
<Border x:Name="TopBorder" Style="{DynamicResource dialogueWindowTitleBar}" MouseDown="TopBorder_MouseDown">
37+
<Grid>
38+
<Label x:Name="Title" Content="" Style="{DynamicResource windowTitle}"/>
39+
<Image x:Name="Logo" Source="Assets/logo_transparent.png" Margin="2,0,0,1" HorizontalAlignment="Left" />
40+
</Grid>
41+
</Border>
42+
43+
<Border x:Name="DialogueContent">
44+
<Grid Margin="10,60,10,10" Height="20">
45+
<ProgressBar x:Name="InstallProgressBar"/>
46+
</Grid>
47+
</Border>
48+
</Grid>
49+
</Border>
50+
</Grid>
51+
</Window>

Cloaks/InstallProgress.xaml.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Windows.Forms;
3+
using System.Windows;
4+
using System.Windows.Input;
5+
6+
namespace Cloaks
7+
{
8+
public partial class InstallProgress : Window
9+
{
10+
11+
private Timer windowTimer = new Timer();
12+
private string title;
13+
14+
private InstallProgress(string title)
15+
{
16+
this.title = title;
17+
18+
InitializeComponent();
19+
Activate();
20+
}
21+
22+
public static void Show(string title, MainWindow main)
23+
{
24+
new InstallProgress(title).ShowDialog();
25+
main.Activate();
26+
}
27+
28+
private void Box_Loaded(object sender, RoutedEventArgs e)
29+
{
30+
Title.Content = title;
31+
32+
windowTimer.Enabled = true;
33+
windowTimer.Start();
34+
windowTimer.Interval = 1;
35+
InstallProgressBar.Maximum = 25;
36+
37+
windowTimer.Tick += new EventHandler(OnTimerTick);
38+
39+
}
40+
41+
private void OnTimerTick(Object source, EventArgs e)
42+
{
43+
if (InstallProgressBar.Value < 25)
44+
{
45+
if (new Random().NextDouble() < 0.5)
46+
InstallProgressBar.Value++;
47+
}
48+
else
49+
{
50+
windowTimer.Stop();
51+
Close();
52+
}
53+
}
54+
55+
private void TopBorder_MouseDown(object sender, MouseButtonEventArgs e)
56+
{
57+
if (Mouse.LeftButton == MouseButtonState.Pressed)
58+
{
59+
DragMove();
60+
}
61+
}
62+
}
63+
64+
65+
66+
}

Cloaks/MainWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
<TextBlock Style="{DynamicResource frameText}">
9191
Cloaks+ is 'use at your own risk' with any third party Minecraft client, and is not guaranteed to work with all versions.
9292
</TextBlock>
93+
94+
9395

9496
<Button x:Name="InstallButton" Style="{DynamicResource installButton}" Click="InstallButton_Click" Margin="-220, 240, 0, 0">
9597
<Grid Style="{DynamicResource installButtonGrid}">

0 commit comments

Comments
 (0)