mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Compare commits
1 Commits
fix/1571
...
feat/reord
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ceb26bb669 |
@@ -14,7 +14,7 @@ namespace Snap.Hutao.Model.Entity;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Table("game_accounts")]
|
||||
internal sealed class GameAccount : ObservableObject, IMappingFrom<GameAccount, string, string, SchemeType>
|
||||
internal sealed class GameAccount : ObservableObject, IMappingFrom<GameAccount, string, string, SchemeType>, ICloneable<GameAccount>
|
||||
{
|
||||
/// <summary>
|
||||
/// 内部Id
|
||||
@@ -54,6 +54,17 @@ internal sealed class GameAccount : ObservableObject, IMappingFrom<GameAccount,
|
||||
};
|
||||
}
|
||||
|
||||
public GameAccount Clone()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
AttachUid = AttachUid,
|
||||
Name = Name,
|
||||
MihoyoSDK = MihoyoSDK,
|
||||
Type = Type,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新绑定的Uid
|
||||
/// </summary>
|
||||
|
||||
@@ -120,6 +120,11 @@ internal sealed partial class GameAccountService : IGameAccountService
|
||||
await gameDbService.RemoveGameAccountByIdAsync(gameAccount.InnerId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts)
|
||||
{
|
||||
gameDbService.ReorderGameAccounts(reorderedGameAccounts);
|
||||
}
|
||||
|
||||
private static GameAccount? SingleGameAccountOrDefault(ObservableCollection<GameAccount> gameAccounts, string registrySdk)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -22,4 +22,6 @@ internal interface IGameAccountService
|
||||
ValueTask RemoveGameAccountAsync(GameAccount gameAccount);
|
||||
|
||||
bool SetGameAccount(GameAccount account);
|
||||
|
||||
void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts);
|
||||
}
|
||||
@@ -59,4 +59,19 @@ internal sealed partial class GameDbService : IGameDbService
|
||||
await appDbContext.GameAccounts.ExecuteDeleteWhereAsync(a => a.InnerId == id).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts)
|
||||
{
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
appDbContext.GameAccounts.ExecuteDelete();
|
||||
|
||||
// Use foreach to avoid ORDER BY InnerId
|
||||
foreach (GameAccount gameAccount in reorderedGameAccounts)
|
||||
{
|
||||
appDbContext.GameAccounts.AddAndSave(gameAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,4 +76,9 @@ internal sealed partial class GameServiceFacade : IGameServiceFacade
|
||||
{
|
||||
return LaunchExecutionEnsureGameNotRunningHandler.IsGameRunning(out _);
|
||||
}
|
||||
|
||||
public void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts)
|
||||
{
|
||||
gameAccountService.ReorderGameAccounts(reorderedGameAccounts);
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,6 @@ internal interface IGameDbService
|
||||
void UpdateGameAccount(GameAccount gameAccount);
|
||||
|
||||
ValueTask UpdateGameAccountAsync(GameAccount gameAccount);
|
||||
|
||||
void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts);
|
||||
}
|
||||
@@ -62,4 +62,6 @@ internal interface IGameServiceFacade
|
||||
ValueTask RemoveGameAccountAsync(GameAccount gameAccount);
|
||||
|
||||
GameAccount? DetectCurrentGameAccount(SchemeType scheme);
|
||||
|
||||
void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts);
|
||||
}
|
||||
@@ -202,6 +202,10 @@
|
||||
IsClickEnabled="True"/>
|
||||
<Border Padding="0,1" Style="{StaticResource BorderCardStyle}">
|
||||
<ListView
|
||||
AllowDrop="True"
|
||||
CanDragItems="True"
|
||||
CanReorderItems="True"
|
||||
DragItemsCompleted="OnAccountListViewReordered"
|
||||
ItemTemplate="{StaticResource GameAccountListTemplate}"
|
||||
ItemsSource="{Binding GameAccountsView}"
|
||||
SelectedItem="{Binding SelectedGameAccount, Mode=TwoWay}"/>
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Collections;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.Control;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.ViewModel.Game;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Snap.Hutao.View.Page;
|
||||
|
||||
@@ -20,4 +24,20 @@ internal sealed partial class LaunchGamePage : ScopedPage
|
||||
InitializeWith<LaunchGameViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void OnAccountListViewReordered(object sender, DragItemsCompletedEventArgs e)
|
||||
{
|
||||
ListView listView = (ListView)sender;
|
||||
AdvancedCollectionView advancedCollectionView = (AdvancedCollectionView)listView.ItemsSource;
|
||||
ObservableCollection<GameAccount> gameAccounts = (ObservableCollection<GameAccount>)advancedCollectionView.Source;
|
||||
|
||||
List<GameAccount> newGameAccounts = [];
|
||||
|
||||
foreach (GameAccount gameAccount in gameAccounts)
|
||||
{
|
||||
newGameAccounts.Add(gameAccount.Clone());
|
||||
}
|
||||
|
||||
((LaunchGameViewModel)DataContext).ReorderGameAccounts(newGameAccounts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,11 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView
|
||||
SelectedGamePathEntry = selectedEntry;
|
||||
}
|
||||
|
||||
public void ReorderGameAccounts(IEnumerable<GameAccount> reorderedGameAccounts)
|
||||
{
|
||||
gameService.ReorderGameAccounts(reorderedGameAccounts);
|
||||
}
|
||||
|
||||
protected override ValueTask<bool> InitializeUIAsync()
|
||||
{
|
||||
ImmutableList<GamePathEntry> gamePathEntries = launchOptions.GetGamePathEntries(out GamePathEntry? entry);
|
||||
|
||||
Reference in New Issue
Block a user