Skip to content

Commit c13cdaf

Browse files
authored
Add progress text for download and improve layout (#134)
1 parent 4eac17b commit c13cdaf

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

UnitystationLauncher/Models/Api/Server.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public bool HasTrustedUrlSource
5959

6060
public string InstallationName => ForkName + BuildVersion;
6161

62-
public string Description => $"BuildVersion: {BuildVersion} - Map: {CurrentMap} - Gamemode: {GameMode} - Time: {InGameTime}";
63-
6462
public string InstallationPath => Path.Combine(Config.InstallationsPath, InstallationName);
6563

6664
public override bool Equals(object? obj)

UnitystationLauncher/Models/Download.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.IO;
33
using System.IO.Compression;
44
using System.Net.Http;
5-
using System.Reactive.Linq;
65
using System.Threading.Tasks;
76
using Humanizer;
87
using ReactiveUI;
@@ -18,7 +17,7 @@ public class Download : ReactiveObject
1817
private readonly string _installationPath;
1918
private long _size;
2019
private bool _active;
21-
private int _progress;
20+
private long _downloaded;
2221

2322
public Download(string url, string installationPath)
2423
{
@@ -33,7 +32,11 @@ public Download(string url, string installationPath)
3332
public long Size
3433
{
3534
get => _size;
36-
set => this.RaiseAndSetIfChanged(ref _size, value);
35+
set
36+
{
37+
this.RaiseAndSetIfChanged(ref _size, value);
38+
this.RaisePropertyChanged(nameof(Progress));
39+
}
3740
}
3841

3942
public bool Active
@@ -42,12 +45,18 @@ public bool Active
4245
set => this.RaiseAndSetIfChanged(ref _active, value);
4346
}
4447

45-
public int Progress
48+
public long Downloaded
4649
{
47-
get => _progress;
48-
set => this.RaiseAndSetIfChanged(ref _progress, value);
50+
get => _downloaded;
51+
set
52+
{
53+
this.RaiseAndSetIfChanged(ref _downloaded, value);
54+
this.RaisePropertyChanged(nameof(Progress));
55+
}
4956
}
5057

58+
public int Progress => (int)(Downloaded * 100 / Math.Max(1, Size));
59+
5160
public (string, int) ForkAndVersion => (ForkName, BuildVersion);
5261
public string ForkName => Installation.GetForkName(InstallationPath);
5362
public int BuildVersion => Installation.GetBuildVersion(InstallationPath);
@@ -81,9 +90,7 @@ public async Task StartAsync(HttpClient http)
8190
using var logProgDisposable = LogProgress(progStream);
8291

8392
using var progDisposable = progStream.Progress
84-
.Select(p => (int)(p * 100 / Size))
85-
.DistinctUntilChanged()
86-
.Subscribe(p => { Progress = p; });
93+
.Subscribe(p => { Downloaded = p; });
8794

8895
await Task.Run(() =>
8996
{

UnitystationLauncher/ViewModels/ServerViewModel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net;
33
using System.Net.NetworkInformation;
44
using System.Reactive.Linq;
5+
using Humanizer;
56
using Reactive.Bindings;
67
using ReactiveUI;
78
using Serilog;
@@ -53,6 +54,17 @@ public ServerViewModel(Server server, Installation? installation, Download? down
5354
_pingSender.PingCompleted += PingCompletedCallback;
5455
_pingSender.SendAsync(Server.ServerIp, 7);
5556
#endif
57+
DownloadedAmount = (
58+
Download?.WhenAnyValue(d => d.Downloaded)
59+
?? Observable.Return(0L)
60+
)
61+
.Select(p => p.Bytes().ToString("# MB"));
62+
63+
DownloadSize = (
64+
Download?.WhenAnyValue(d => d.Size)
65+
?? Observable.Return(0L)
66+
)
67+
.Select(p => p.Bytes().ToString("# MB"));
5668
}
5769

5870
public Server Server { get; }
@@ -64,6 +76,9 @@ public ServerViewModel(Server server, Installation? installation, Download? down
6476

6577
public IObservable<bool> Downloading => Download?.WhenAnyValue(d => d.Active) ?? Observable.Return(false);
6678

79+
public IObservable<string> DownloadedAmount { get; }
80+
public IObservable<string> DownloadSize { get; }
81+
6782
private void PingCompletedCallback(object sender, PingCompletedEventArgs e)
6883
{
6984
// If an error occurred, display the exception to the user.
@@ -79,7 +94,8 @@ private void PingCompletedCallback(object sender, PingCompletedEventArgs e)
7994

8095
public void Start()
8196
{
82-
Installation?.Start(IPAddress.Parse(Server.ServerIp), (short)Server.ServerPort, _authService.CurrentRefreshToken, _authService.Uid);
97+
Installation?.Start(IPAddress.Parse(Server.ServerIp), (short)Server.ServerPort,
98+
_authService.CurrentRefreshToken, _authService.Uid);
8399
}
84100

85101
public void Dispose()

UnitystationLauncher/Views/ServerView.axaml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</Style>
1212
</DockPanel.Styles>
1313
<Image DockPanel.Dock="Left" Source="/Assets/unityico.png" Margin="5" Width="65" Height="65" Stretch="Uniform" />
14-
<Panel DockPanel.Dock="Right" Margin="5" Width="140">
14+
<Panel DockPanel.Dock="Right" Margin="5" MinWidth="180">
1515
<Panel Height="40">
1616
<Panel.IsVisible>
1717
<MultiBinding Converter="{x:Static BoolConverters.And}">
@@ -39,9 +39,13 @@
3939
<Button Command="{Binding Start}" Content="Start" Background="{StaticResource PrimaryTransparent4}"
4040
BorderThickness="0" />
4141
</Panel>
42-
<Panel IsVisible="{Binding Downloading^}" Height="10">
43-
<ProgressBar Value="{Binding Download.Progress}" MinWidth="0" MinHeight="0" />
44-
</Panel>
42+
<StackPanel IsVisible="{Binding Downloading^}" VerticalAlignment="Center">
43+
<ProgressBar Value="{Binding Download.Progress}" MinWidth="0" MinHeight="0" Height="10"/>
44+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
45+
<TextBlock Text="{Binding DownloadedAmount^}"/>
46+
<TextBlock> / </TextBlock>
47+
<TextBlock Text="{Binding DownloadSize^}"/></StackPanel>
48+
</StackPanel>
4549
</Panel>
4650
<Grid ColumnDefinitions="*, auto, auto" RowDefinitions="*, *" VerticalAlignment="Center">
4751
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Server.ServerName}" />
@@ -54,6 +58,29 @@
5458
</StackPanel>
5559
<TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding RoundTrip.Value}" MinWidth="75"
5660
TextAlignment="Right" VerticalAlignment="Center" />
61+
<WrapPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
62+
<WrapPanel.Styles>
63+
<Style Selector="TextBlock">
64+
<Setter Property="FontSize" Value="12"></Setter>
65+
</Style>
66+
</WrapPanel.Styles>
67+
<StackPanel Orientation="Horizontal">
68+
<TextBlock>BuildVersion: </TextBlock>
69+
<TextBlock Text="{Binding Server.BuildVersion}" />
70+
</StackPanel>
71+
<StackPanel Orientation="Horizontal">
72+
<TextBlock>Map: </TextBlock>
73+
<TextBlock Text="{Binding Server.CurrentMap}" />
74+
</StackPanel>
75+
<StackPanel Orientation="Horizontal">
76+
<TextBlock>Game-mode: </TextBlock>
77+
<TextBlock Text="{Binding Server.GameMode}" />
78+
</StackPanel>
79+
<StackPanel Orientation="Horizontal">
80+
<TextBlock>Time: </TextBlock>
81+
<TextBlock Text="{Binding Server.InGameTime}" />
82+
</StackPanel>
83+
</WrapPanel>
5784
</Grid>
5885
</DockPanel>
5986
</UserControl>

0 commit comments

Comments
 (0)