Skip to content

Commit 35dfc0b

Browse files
committed
feat(app): 游戏库界面功能增加 参照GoldenPotato137#329
- 使用面包屑导航栏显示当前路径 - 在更多里面打开当前库的管理界面 - 在空白处右键打开当前库的管理界面 - 在游戏游戏右键添加快捷功能,和主页保持一致(编辑,更新,删除游戏) - 游戏库右下角悬浮窗显示统计数据
1 parent 67ea9ab commit 35dfc0b

File tree

4 files changed

+169
-9
lines changed

4 files changed

+169
-9
lines changed

GalgameManager/Strings/zh-CN/Resources.resw

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,24 @@
17601760
<data name="LibraryPage_DownloadAllData.Label" xml:space="preserve">
17611761
<value>下载所有游戏数据</value>
17621762
</data>
1763+
<data name="LibraryPage_EditCurrentFolder.Text" xml:space="preserve">
1764+
<value>管理当前库</value>
1765+
</data>
1766+
<data name="LibraryPage_EditCurrentFolder_AppBarButton.Label" xml:space="preserve">
1767+
<value>管理当前库</value>
1768+
</data>
1769+
<data name="LibraryPage_EditGameInfo.Text" xml:space="preserve">
1770+
<value>修改游戏信息</value>
1771+
</data>
1772+
<data name="LibraryPage_DownloadGameInfo.Text" xml:space="preserve">
1773+
<value>下载游戏信息</value>
1774+
</data>
1775+
<data name="LibraryPage_RemoveGame.Text" xml:space="preserve">
1776+
<value>从库中移除游戏</value>
1777+
</data>
1778+
<data name="LibraryPage_Statistics" xml:space="preserve">
1779+
<value>游戏库: {0} | 游戏: {1}</value>
1780+
</data>
17631781
<data name="GalgameCollectionService_LoadMetaFailed" xml:space="preserve">
17641782
<value>加载本地Meta失败</value>
17651783
</data>

GalgameManager/ViewModels/LibraryViewModel.cs

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ public partial class LibraryViewModel(
1919
INavigationService navigationService,
2020
IGalgameSourceCollectionService galSourceService,
2121
IInfoService infoService,
22-
IBgTaskService bgTaskService)
22+
IBgTaskService bgTaskService,
23+
IGalgameCollectionService galgameService
24+
)
2325
: ObservableObject, INavigationAware
2426
{
2527
private readonly GalgameSourceCollectionService _galSourceCollectionService = (GalgameSourceCollectionService)galSourceService;
28+
private readonly IGalgameCollectionService _galgameService = galgameService;
2629
private readonly IBgTaskService _bgTaskService = bgTaskService;
2730
[ObservableProperty, NotifyPropertyChangedFor(nameof(IsBackEnabled))]
2831
private GalgameSourceBase? _currentSource;
@@ -39,6 +42,9 @@ public partial class LibraryViewModel(
3942
public bool IsBackEnabled => CurrentSource != null;
4043
[ObservableProperty] private bool _sourceVisible;
4144
[ObservableProperty] private bool _galgamesVisible;
45+
[ObservableProperty] private bool _isPhrasing;
46+
[ObservableProperty]
47+
private ObservableCollection<GalgameSourceBase> _pathNodes = new();
4248

4349
#endregion
4450

@@ -58,6 +64,16 @@ private void Search(string searchKey)
5864

5965
#endregion
6066

67+
[ObservableProperty]
68+
private string _statisticsText = string.Empty;
69+
70+
private void UpdateStatistics()
71+
{
72+
var sourceCount = Source.Count;
73+
var galgameCount = Galgames.Count;
74+
StatisticsText = string.Format("LibraryPage_Statistics".GetLocalized(), sourceCount, galgameCount);
75+
}
76+
6177
public void OnNavigatedTo(object parameter)
6278
{
6379
Source = new AdvancedCollectionView(new ObservableCollection<IDisplayableGameObject>(), true);
@@ -136,7 +152,26 @@ private void NavigateTo(IDisplayableGameObject? clickedItem)
136152
UpdateGridSpacing = true;
137153
SourceVisible = Source.Count > 0;
138154
GalgamesVisible = Galgames.Count > 0;
155+
UpdateStatistics();
156+
157+
// 更新路径节点
158+
PathNodes.Clear();
159+
if (clickedItem is GalgameSourceBase newSource)
160+
{
161+
var currentSource = newSource;
162+
var nodes = new List<GalgameSourceBase>();
163+
while (currentSource != null)
164+
{
165+
nodes.Insert(0, currentSource);
166+
currentSource = currentSource.ParentSource;
167+
}
168+
foreach (var node in nodes)
169+
{
170+
PathNodes.Add(node);
171+
}
172+
}
139173
}
174+
140175

141176
[RelayCommand]
142177
private void Back()
@@ -244,4 +279,60 @@ private void ScanAll()
244279
_galSourceCollectionService.ScanAll();
245280
infoService.Info(InfoBarSeverity.Success, msg: "LibraryPage_ScanAll_Success".GetLocalized(Source.Count));
246281
}
282+
283+
[RelayCommand]
284+
private void EditCurrentFolder()
285+
{
286+
if (CurrentSource is null) return;
287+
_beforeNavigateFromSource = CurrentSource;
288+
navigationService.NavigateTo(typeof(GalgameSourceViewModel).FullName!, CurrentSource.Url);
289+
}
290+
291+
[RelayCommand]
292+
private async Task GalFlyOutDelete(Galgame? galgame)
293+
{
294+
if(galgame == null) return;
295+
ContentDialog dialog = new()
296+
{
297+
XamlRoot = App.MainWindow!.Content.XamlRoot,
298+
Title = "HomePage_Remove_Title".GetLocalized(),
299+
Content = "HomePage_Remove_Message".GetLocalized(),
300+
PrimaryButtonText = "Yes".GetLocalized(),
301+
SecondaryButtonText = "Cancel".GetLocalized()
302+
};
303+
dialog.PrimaryButtonClick += async (_, _) =>
304+
{
305+
await _galgameService.RemoveGalgame(galgame);
306+
};
307+
308+
await dialog.ShowAsync();
309+
310+
// 删除游戏后,刷新当前库
311+
NavigateTo(CurrentSource);
312+
}
313+
314+
[RelayCommand]
315+
private void GalFlyOutEdit(Galgame? galgame)
316+
{
317+
if(galgame == null) return;
318+
_beforeNavigateFromSource = CurrentSource;
319+
navigationService.NavigateTo(typeof(GalgameSettingViewModel).FullName!, galgame);
320+
}
321+
322+
[RelayCommand]
323+
private async Task GalFlyOutGetInfoFromRss(Galgame? galgame)
324+
{
325+
if(galgame == null) return;
326+
IsPhrasing = true;
327+
await _galgameService.PhraseGalInfoAsync(galgame);
328+
IsPhrasing = false;
329+
}
330+
331+
public void OnBreadcrumbBarItemClicked(BreadcrumbBar sender, BreadcrumbBarItemClickedEventArgs args)
332+
{
333+
if (args.Item is GalgameSourceBase source)
334+
{
335+
NavigateTo(source);
336+
}
337+
}
247338
}

GalgameManager/Views/GalgameSettingPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<Grid Grid.Column="1" Margin="50 0 0 0">
9494
<Grid.ColumnDefinitions>
9595
<ColumnDefinition Width="Auto" />
96-
<ColumnDefinition Width="*" />
96+
<ColumnDefinition Width="Auto" />
9797
<ColumnDefinition Width="Auto"/>
9898
</Grid.ColumnDefinitions>
9999
<TextBlock x:Uid="GalgameSettingPage_GalgameRssType" VerticalAlignment="Center"
@@ -132,8 +132,8 @@
132132

133133
<Grid>
134134
<Grid.ColumnDefinitions>
135-
<ColumnDefinition Width="Auto" />
136-
<ColumnDefinition Width="Auto" />
135+
<ColumnDefinition Width="*" />
136+
<ColumnDefinition Width="*" />
137137
<ColumnDefinition Width="*" />
138138
</Grid.ColumnDefinitions>
139139

GalgameManager/Views/LibraryPage.xaml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,36 @@
1313
x:Name="Page">
1414

1515
<Page.Resources>
16-
<MenuFlyout Placement="Right" x:Key="Flyout">
16+
<MenuFlyout Placement="Right" x:Key="FolderFlyout">
1717
<MenuFlyoutItem Icon="Edit" x:Uid="LibraryPage_EditFolder"
1818
Command="{x:Bind ViewModel.EditLibraryCommand}" CommandParameter="{Binding}"/>
1919
<MenuFlyoutItem Icon="Delete" x:Uid="LibraryPage_DeleteFolder"
2020
Command="{x:Bind ViewModel.DeleteFolderCommand}" CommandParameter="{Binding}"/>
2121
</MenuFlyout>
22+
23+
<MenuFlyout Placement="Right" x:Key="PageFlyout">
24+
<MenuFlyoutItem Icon="Edit" x:Uid="LibraryPage_EditCurrentFolder"
25+
Command="{x:Bind ViewModel.EditCurrentFolderCommand}"
26+
IsEnabled="{x:Bind ViewModel.IsBackEnabled, Mode=OneWay}"/>
27+
</MenuFlyout>
28+
29+
<MenuFlyout Placement="Right" x:Key="GameFlyout">
30+
<MenuFlyoutItem Icon="Edit" x:Uid="LibraryPage_EditGameInfo"
31+
Command="{x:Bind ViewModel.GalFlyOutEditCommand}"
32+
CommandParameter="{Binding}"/>
33+
<MenuFlyoutItem Icon="Download" x:Uid="LibraryPage_DownloadGameInfo"
34+
Command="{x:Bind ViewModel.GalFlyOutGetInfoFromRssCommand}"
35+
CommandParameter="{Binding}"/>
36+
<MenuFlyoutItem Icon="Delete" x:Uid="LibraryPage_RemoveGame"
37+
Command="{x:Bind ViewModel.GalFlyOutDeleteCommand}"
38+
CommandParameter="{Binding}"/>
39+
</MenuFlyout>
2240
</Page.Resources>
2341

24-
<Grid Margin="0 0 0 20">
42+
43+
<Grid Margin="0 0 0 20" ContextFlyout="{StaticResource PageFlyout}">
2544
<Grid.RowDefinitions>
45+
<RowDefinition Height="Auto" />
2646
<RowDefinition Height="Auto" />
2747
<RowDefinition Height="*" />
2848
<RowDefinition Height="Auto" />
@@ -77,10 +97,29 @@
7797
<KeyboardAccelerator Modifiers="Control" Key="I" />
7898
</AppBarButton.KeyboardAccelerators>
7999
</AppBarButton>
100+
<AppBarButton Icon="Edit" x:Uid="LibraryPage_EditCurrentFolder_AppBarButton"
101+
Command="{x:Bind ViewModel.EditCurrentFolderCommand}"
102+
IsEnabled="{x:Bind ViewModel.IsBackEnabled, Mode=OneWay}">
103+
<AppBarButton.KeyboardAccelerators>
104+
<KeyboardAccelerator Modifiers="Control" Key="E" />
105+
</AppBarButton.KeyboardAccelerators>
106+
</AppBarButton>
80107
</CommandBar.SecondaryCommands>
81108
</CommandBar>
82109

83-
<ScrollViewer Grid.Row="1">
110+
<!-- 添加面包屑导航栏 -->
111+
<BreadcrumbBar Grid.Row="1"
112+
ItemsSource="{x:Bind ViewModel.PathNodes, Mode=OneWay}"
113+
ItemClicked="{x:Bind ViewModel.OnBreadcrumbBarItemClicked}"
114+
Margin="40,8,40,8">
115+
<BreadcrumbBar.ItemTemplate>
116+
<DataTemplate x:DataType="sources:GalgameSourceBase">
117+
<TextBlock Text="{x:Bind Name}"/>
118+
</DataTemplate>
119+
</BreadcrumbBar.ItemTemplate>
120+
</BreadcrumbBar>
121+
122+
<ScrollViewer Grid.Row="2">
84123
<StackPanel>
85124
<!-- 游戏库列表 -->
86125
<GridView x:Name="GridView"
@@ -99,7 +138,7 @@
99138
Command="{Binding ElementName=Page, Path=ViewModel.NavigateToCommand}"
100139
CommandParameter="{x:Bind}"
101140
Width="175"
102-
ContextFlyout="{StaticResource Flyout}">
141+
ContextFlyout="{StaticResource FolderFlyout}">
103142
<prefab:SourcePrefab Source="{x:Bind}" />
104143
</Button>
105144
</DataTemplate>
@@ -121,13 +160,25 @@
121160
<Button Style="{StaticResource TransparentButtonWithHover}"
122161
DataContext="{x:Bind}"
123162
Command="{Binding ElementName=Page, Path=ViewModel.NavigateToCommand}"
124-
CommandParameter="{x:Bind}">
163+
CommandParameter="{x:Bind}"
164+
ContextFlyout="{StaticResource GameFlyout}">
125165
<prefab:GalgamePrefab Galgame="{x:Bind}" />
126166
</Button>
127167
</DataTemplate>
128168
</GridView.ItemTemplate>
129169
</GridView>
130170
</StackPanel>
131171
</ScrollViewer>
172+
173+
<!-- 添加统计信息悬浮窗 -->
174+
<InfoBar Grid.Row="3"
175+
IsOpen="True"
176+
IsClosable="False"
177+
IsIconVisible="False"
178+
Severity="Informational"
179+
Message="{x:Bind ViewModel.StatisticsText, Mode=OneWay}"
180+
VerticalAlignment="Bottom"
181+
HorizontalAlignment="Right"
182+
Margin="0,0,24,24"/>
132183
</Grid>
133184
</Page>

0 commit comments

Comments
 (0)