Skip to content

Commit

Permalink
部分交互逻辑调整
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Nov 18, 2024
1 parent 1b4d976 commit b3eb309
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 40 deletions.
1 change: 0 additions & 1 deletion WonderLab.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Avalonia;
using System;
using System.Runtime.InteropServices;
using WonderLab.Extensions;

namespace WonderLab.Desktop;

Expand Down
1 change: 1 addition & 0 deletions WonderLab/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<StyleInclude Source="/Controls/Style/SelectorBarStyle.axaml"/>
<StyleInclude Source="/Controls/Style/ToggleButtonStyle.axaml"/>
<StyleInclude Source="avares://DialogHost.Avalonia/Styles.xaml"/>
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml"/>
</Application.Styles>

<Application.Resources>
Expand Down
15 changes: 9 additions & 6 deletions WonderLab/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
Expand All @@ -10,14 +9,14 @@
using Microsoft.Extensions.Logging;
using Serilog;
using System;
using System.Diagnostics;
using System.IO;
using WonderLab.Extensions;
using WonderLab.Extensions.Hosting;
using WonderLab.Services;
using WonderLab.Services.Account;
using WonderLab.Services.Accounts;
using WonderLab.Services.Launch;
using WonderLab.Services.UI;
using WonderLab.ViewModels.Dialog;
using WonderLab.ViewModels.Page;
using WonderLab.ViewModels.Page.Download;
using WonderLab.ViewModels.Page.Setting;
Expand All @@ -33,9 +32,9 @@ public sealed class App : Application {

private static IServiceProvider ServiceProvider { get; set; }

private static TKey Get<TKey>() {
public static TKey Get<TKey>() {
return ServiceProvider.GetRequiredService<TKey>();
}
}

public override void Initialize() {
AvaloniaXamlLoader.Load(this);
Expand Down Expand Up @@ -81,6 +80,7 @@ private void OnStartup(object sender, ControlledApplicationLifetimeStartupEventA
configService.Load();

Get<GameService>().Initialize();
Get<AccountService>().Initialize();

//Override AccentColors
Current.Resources["NormalAccentBrush"] =
Expand Down Expand Up @@ -116,11 +116,14 @@ private static IHost ConfigureIoC(out IHost host) {
builder.Services.AddSingleton<LaunchService>();
builder.Services.AddSingleton<AccountService>();
builder.Services.AddSingleton<NotificationService>();

//Configure Window
builder.Services.AddSingleton<MainWindow>();
builder.Services.AddSingleton<MainWindowViewModel>();

//Configure Dialog
builder.Services.AddTransient<ChooseAccountTypeDialogViewModel>();

//Configure Page
var page = builder.PageProvider;
page.AddPage<HomePage, HomePageViewModel>("Home");
Expand Down
24 changes: 13 additions & 11 deletions WonderLab/Controls/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@ public AvaloniaPageProvider PageProvider {
set => SetValue(PageProviderProperty, value);
}

private async void RunAnimation(object page) {
private void RunAnimation(object page) {
using (_cancellationTokenSource) {
_cancellationTokenSource.Cancel();
_cancellationTokenSource = new();
}

if (_controlType is ControlType.Control1) {
_PART_LeftContentPresenter.Content = page;
await PageTransition.Start(_PART_RightContentPresenter, _PART_LeftContentPresenter, true, _cancellationTokenSource.Token);
_controlType = ControlType.Control2;
}else {
_PART_RightContentPresenter.Content = page;
await PageTransition.Start(_PART_LeftContentPresenter, _PART_RightContentPresenter, false, _cancellationTokenSource.Token);
_controlType = ControlType.Control1;
}

Dispatcher.UIThread.Post(async () => {
if (_controlType is ControlType.Control1) {
_PART_LeftContentPresenter.Content = page;
await PageTransition.Start(_PART_RightContentPresenter, _PART_LeftContentPresenter, true, _cancellationTokenSource.Token);
_controlType = ControlType.Control2;
} else {
_PART_RightContentPresenter.Content = page;
await PageTransition.Start(_PART_LeftContentPresenter, _PART_RightContentPresenter, false, _cancellationTokenSource.Token);
_controlType = ControlType.Control1;
}
}, DispatcherPriority.Render);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e) {
Expand Down
1 change: 1 addition & 0 deletions WonderLab/Controls/Theme/NotificationCardTheme.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Style Selector="^:information /template/ Panel#PART_HeaderBar">
<Setter Property="Background" Value="{DynamicResource NotificationCardInformationBackgroundBrush}"/>
</Style>

<Style Selector="^:success /template/ Panel#PART_HeaderBar">
<Setter Property="Background" Value="{DynamicResource NotificationCardSuccessBackgroundBrush}"/>
</Style>
Expand Down
16 changes: 15 additions & 1 deletion WonderLab/Services/Account/AccountService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
namespace WonderLab.Services.Account;
using MinecraftLaunch.Classes.Models.Auth;
using System.Collections.ObjectModel;

namespace WonderLab.Services.Accounts;

public sealed class AccountService {
private readonly ConfigService _configService;

public ObservableCollection<Account> Accounts { get; set; }

public AccountService(ConfigService configService) {
_configService = configService;
}

public void Initialize() {
Accounts = new(_configService?.Entries?.Accounts ?? []);
}
}
4 changes: 2 additions & 2 deletions WonderLab/Services/Launch/LaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using WonderLab.Infrastructure.Models;
using WonderLab.Infrastructure.Models.Launch;
using WonderLab.Services.Account;
using WonderLab.Services.Accounts;
using WonderLab.Services.UI;
using WonderLab.ViewModels.Tasks;

Expand All @@ -27,8 +27,8 @@ public sealed class LaunchService {
public LaunchService(
GameService gameService,
TaskService taskService,
AccountService accountService,
ConfigService configService,
AccountService accountService,
NotificationService notificationService) {
_taskService = taskService;
_gameService = gameService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace WonderLab.ViewModels.Dialog;

public sealed partial class ChooseAccountTypeDialogViewModel : ObservableObject {
}
42 changes: 30 additions & 12 deletions WonderLab/ViewModels/Page/Setting/AccountPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DialogHostAvalonia;
using MinecraftLaunch.Classes.Models.Auth;
using MinecraftLaunch.Components.Authenticator;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using WonderLab.Services.Accounts;
using WonderLab.ViewModels.Dialog;

namespace WonderLab.ViewModels.Page.Setting;

public sealed partial class AccountPageViewModel : ObservableObject {
public List<Account> Test => [
new OfflineAuthenticator("Account1").Authenticate(),
new OfflineAuthenticator("Account2").Authenticate(),
new OfflineAuthenticator("Account3").Authenticate(),
new OfflineAuthenticator("Account4").Authenticate(),
new OfflineAuthenticator("Account5").Authenticate(),
new OfflineAuthenticator("Account6").Authenticate(),
new OfflineAuthenticator("Account7").Authenticate(),
];
private readonly AccountService _accountService;

public bool HasAccount => Accounts?.Count > 0;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(HasAccount))]
private ReadOnlyObservableCollection<Account> _accounts;

public AccountPageViewModel(AccountService accountService) {
_accountService = accountService;

Accounts = new(_accountService.Accounts);
}

[RelayCommand]
private Task CreateAccount() => Dispatcher.UIThread.InvokeAsync(async () => {
ChooseAccountTypeDialog dialog = new() {
DataContext = App.Get<ChooseAccountTypeDialogViewModel>()
};

await DialogHost.Show(dialog, "PART_DialogHost");
});
}
2 changes: 0 additions & 2 deletions WonderLab/ViewModels/Page/Setting/AppearancePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public sealed partial class AppearancePageViewModel : ObservableObject {

public IEnumerable<Color> ImageColors => ActiveImage?.ToRgba32Bitmap()?.GetPaletteFromBitmap().Select(x => x.Color);

public List<Color> Colors { get; } = ColorExtension.Colors;

public List<CultureInfo> Languages { get; } = [
new("zh-Hans"),
new("zh-Hant"),
Expand Down
8 changes: 8 additions & 0 deletions WonderLab/Views/Dialog/ChooseAccountTypeDialog.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="WonderLab.ChooseAccountTypeDialog">
Welcome to Avalonia!
</UserControl>
7 changes: 7 additions & 0 deletions WonderLab/Views/Dialog/ChooseAccountTypeDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Avalonia.Controls;

namespace WonderLab;

public partial class ChooseAccountTypeDialog : UserControl {
public ChooseAccountTypeDialog() => InitializeComponent();
}
19 changes: 17 additions & 2 deletions WonderLab/Views/Page/Setting/AccountPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@
<wc:SettingExpander Glyph="&#xE8B7;"
Header="{I18N {x:Static w:LanguageKeys.Settings_Account_Title}}">
<wc:SettingExpanderItem Description="{I18N {x:Static w:LanguageKeys.Settings_Account_Add_Description}}">
<Button Content="{I18N {x:Static w:LanguageKeys.Item_Add}}"/>
<Button Command="{Binding CreateAccountCommand}"
Content="{I18N {x:Static w:LanguageKeys.Item_Add}}"/>
</wc:SettingExpanderItem>
</wc:SettingExpander>

<TextBlock Margin="0 20 0 0"
Classes="BodyStrong"
Text="保存的游戏账户"/>

<StackPanel Spacing="8"
Grid.Row="1"
Margin="0 50"
VerticalAlignment="Center"
HorizontalAlignment="Center"
IsVisible="{Binding HasAccount, Converter={StaticResource BooleanReverseConverter}}">
<wc:FontIcon FontSize="28"
Glyph="&#xF133;"
HorizontalAlignment="Center"/>

<TextBlock Classes="BodyStrong"
Text="没有任何账户"/>
</StackPanel>

<ItemsRepeater Margin="0 8 0 0"
ItemsSource="{Binding Test}">
ItemsSource="{Binding Accounts}">
<ItemsRepeater.Layout>
<UniformGridLayout MinItemWidth="260"
ItemsStretch="Fill"
Expand Down
5 changes: 3 additions & 2 deletions WonderLab/Views/Page/Setting/AppearancePage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@
</wc:SettingExpanderItem>

<wc:SettingExpanderItem Description="{I18N {x:Static w:LanguageKeys.Settings_Appearance_Color}}">
<ListBox Classes="colorbox"
<!--<ListBox Classes="colorbox"
ItemsSource="{Binding Colors}"
SelectedItem="{Binding Color}">
</ListBox>
</ListBox>-->
<ColorPicker Color="{Binding Color}"/>
</wc:SettingExpanderItem>

<wc:SettingExpanderItem IsVisible="{Binding IsImageBackground}"
Expand Down
1 change: 0 additions & 1 deletion WonderLab/WonderLab.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@

<ItemGroup>
<Folder Include="Platform\Linux\Wayland\" />
<Folder Include="Views\Dialog\" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit b3eb309

Please sign in to comment.