Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jul 24, 2024
1 parent 8796e9e commit e074ec2
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 18 deletions.
100 changes: 100 additions & 0 deletions src/Starward/Controls/InstallGameController.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl x:Class="Starward.Controls.InstallGameController"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Starward.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Button Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<Grid>
<FontIcon FontSize="16"
Glyph="&#xEBD3;"
IsTextScaleFactorEnabled="False" />
</Grid>

<Button.Flyout>
<Flyout Placement="RightEdgeAlignedBottom">
<Grid Width="240" Height="200">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid Height="44">
<Grid Width="44"
Height="44"
HorizontalAlignment="Left"
VerticalAlignment="Top"
CornerRadius="8">
<Image Width="44"
Height="44"
Source="ms-appx:///Assets/Image/icon_ys.jpg" />
<Image Width="22"
Height="22"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Source="ms-appx:///Assets/Image/gameicon_hyperion.png" />

</Grid>


<ProgressBar MinHeight="4"
Margin="56,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Value="40">
<ProgressBar.Resources>
<x:Double x:Key="ProgressBarTrackHeight">4</x:Double>
<CornerRadius x:Key="ProgressBarTrackCornerRadius">4</CornerRadius>
</ProgressBar.Resources>
</ProgressBar>

<TextBlock Margin="56,0,0,0"
FontSize="12"
Text="Downloading" />

<TextBlock Margin="56,0,0,10"
VerticalAlignment="Bottom"
FontSize="12"
Text="21.35/43.56 GB" />

<StackPanel HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal">
<Button Width="28"
Height="28"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon FontSize="16"
Glyph="&#xE768;"
IsTextScaleFactorEnabled="False" />
</Button>
<Button Width="28"
Height="28"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
Visibility="Collapsed">
<FontIcon FontSize="16"
Glyph="&#xEA39;"
IsTextScaleFactorEnabled="False" />
</Button>
</StackPanel>

</Grid>

</Grid>
</Flyout>
</Button.Flyout>

</Button>

</UserControl>
56 changes: 56 additions & 0 deletions src/Starward/Controls/InstallGameController.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Starward.Services.Download;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Starward.Controls;

[INotifyPropertyChanged]
public sealed partial class InstallGameController : UserControl
{


private readonly ILogger<InstallGameController> _logger = AppConfig.GetLogger<InstallGameController>();


private readonly InstallGameManager _installGameManager = AppConfig.GetService<InstallGameManager>();


public InstallGameController()
{
this.InitializeComponent();
}





private ObservableCollection<InstallGameStateModel> _installServices = new();










}
8 changes: 4 additions & 4 deletions src/Starward/Controls/InstallGameDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
Margin="0,8,0,0"
Orientation="Horizontal"
Spacing="8">
<TextBlock FontSize="12"
<TextBlock FontSize="14"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsTextScaleFactorEnabled="False"
Text="">
Expand All @@ -93,7 +93,7 @@
</TextBlock>
<AppBarSeparator Padding="2" Foreground="{ThemeResource TextFillColorTertiaryBrush}" />
<TextBlock x:Name="TextBlock_AvailableSpace"
FontSize="12"
FontSize="14"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsTextScaleFactorEnabled="False">
<Run Text="Space Available" />
Expand All @@ -110,12 +110,12 @@
Margin="0,8,0,0"
Orientation="Horizontal"
Visibility="Collapsed">
<TextBlock FontSize="12"
<TextBlock FontSize="14"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsTextScaleFactorEnabled="False"
Text="No write permission, please restart as administrator." />
<TextBlock Margin="6,0,0,0"
FontSize="12"
FontSize="14"
IsTextScaleFactorEnabled="False">
<Hyperlink x:Name="Hyperlink_Restart"
Click="Hyperlink_Restart_Click"
Expand Down
11 changes: 10 additions & 1 deletion src/Starward/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,18 @@
</NavigationViewItem>
</NavigationView.MenuItems>

<NavigationView.PaneFooter>
<sc:InstallGameController Width="48"
Height="40"
Margin="4,0,4,0" />
</NavigationView.PaneFooter>

<NavigationView.FooterMenuItems>
<!-- 小提示 -->
<NavigationViewItem Name="NavigationViewItem_Tips"
Tag="Tips"
ToolTipService.ToolTip="{x:Bind lang:Lang.MainPage_Tips}">
ToolTipService.ToolTip="{x:Bind lang:Lang.MainPage_Tips}"
Visibility="Collapsed">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE82F;" />
</NavigationViewItem.Icon>
Expand All @@ -191,6 +198,8 @@
</NavigationViewItem>
</NavigationView.FooterMenuItems>



<Grid Name="Grid_FrameContent" Margin="0,48,0,0">
<ProgressBar Name="ProgressBar_LoadBackground"
HorizontalAlignment="Stretch"
Expand Down
92 changes: 81 additions & 11 deletions src/Starward/Services/Download/InstallGameManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.Extensions.Logging;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.Logging;
using Starward.Core;
using System;
using Starward.Helpers;
using Starward.Models;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Starward.Services.Download;

Expand All @@ -32,15 +31,15 @@ public InstallGameManager(ILogger<InstallGameManager> logger)



public InstallGameService CurrentInstallService;
public InstallGameService CurrentInstallService { get; private set; }



public double Speed { get; set; }

public double SpeedLimit { get; set; }


public double SpeedLimit { get; set; }



Expand Down Expand Up @@ -70,20 +69,91 @@ public void AddInstallService(InstallGameService service)



public void Pause()
{

}


}



public partial class InstallGameStateModel : ObservableObject
{


public void Continue()
private const string PlayGlyph = "\uE768";


private const string PauseGlyph = "\uE769";



private InstallGameService _service;


internal InstallGameStateModel(InstallGameService service)
{
_service = service;
GameBiz = _service.CurrentGameBiz;
Icon = new GameBizIcon { GameBiz = _service.CurrentGameBiz };
_service.StateChanged += _service_StateChanged;
_service.InstallFailed += _service_InstallFailed;
}



public GameBiz GameBiz { get; set; }


public GameBizIcon Icon { get; set; }


[ObservableProperty]
private string _StateText;


[ObservableProperty]
private string _ButtonGlyph;


[ObservableProperty]
private double _Progress;



private void _service_StateChanged(object? sender, InstallGameState e)
{
switch (e)
{
case InstallGameState.None:
StateText = "Paused";
break;
case InstallGameState.Download:
StateText = "Downloading";
break;
case InstallGameState.Verify:
StateText = "Verifying";
break;
case InstallGameState.Decompress:
StateText = "Decompressing";
break;
case InstallGameState.Clean:
break;
case InstallGameState.Finish:
StateText = "Finished";
break;
case InstallGameState.Error:
StateText = "Error";
break;
default:
break;
}
}


private void _service_InstallFailed(object? sender, System.Exception e)
{
NotificationBehavior.Instance.Error(e, $"Game ({GameBiz.ToGameName()} - {GameBiz.ToGameServer()}) install failed.");
}



Expand Down
4 changes: 2 additions & 2 deletions src/Starward/Services/Download/InstallGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public InstallGameState State
}


public EventHandler<InstallGameState> StateChanged;
public event EventHandler<InstallGameState> StateChanged;


public EventHandler<Exception> InstallFailed;
public event EventHandler<Exception> InstallFailed;


protected void OnInstallFailed(Exception ex)
Expand Down

0 comments on commit e074ec2

Please sign in to comment.