Skip to content

Commit d41a855

Browse files
committed
Refactor file version paging and UI in AddFileInfoControl
[AI] Reworks the file version paging logic by renaming and consolidating properties, introducing HaveNextVersionPage and HaveLastVersionPage, and updating commands for page navigation. Updates the AddFileInfoControl UI to improve layout, add scroll-to-home behavior on item info display, and synchronize with the new paging logic. Minor UI adjustments and cleanup are also included.
1 parent 2c0ebbd commit d41a855

6 files changed

Lines changed: 137 additions & 71 deletions

File tree

src/ColorMC.Gui/UI/Controls/Add/AddFileInfoControl.axaml

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@
8787
<svg:SvgControl Path="/Resource/Icon/close.svg" />
8888
</Button>
8989
</Panel>
90-
<TabControl Margin="5,0,5,10" SelectedIndex="{Binding SelectIndex}">
90+
<TabControl Padding="0" SelectedIndex="{Binding SelectIndex, FallbackValue=1}">
9191
<TabItem Header="{setting:Localize AddModPackWindow.Text36}">
92-
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
93-
<StackPanel Margin="10" DataContext="{Binding Last}">
92+
<ScrollViewer Name="ScrollViewer1" HorizontalScrollBarVisibility="Disabled">
93+
<StackPanel Margin="20,10,20,0" DataContext="{Binding Last}">
9494
<ItemsControl ItemsSource="{Binding Tags}">
9595
<ItemsControl.ItemsPanel>
9696
<ItemsPanelTemplate>
@@ -122,33 +122,58 @@
122122
</ScrollViewer>
123123
</TabItem>
124124
<TabItem Header="{setting:Localize AddModPackWindow.Text35}">
125-
<ScrollViewer>
126-
<StackPanel Name="ModPackFiles" Margin="10">
127-
<WrapPanel Margin="15,15,5,5" DockPanel.Dock="Top">
128-
<DockPanel MinWidth="190" Margin="0,0,10,10">
129-
<TextBlock Margin="0,0,5,0" Text="{setting:Localize Text.GameVersion}" />
130-
<ComboBox
131-
Height="30"
132-
HorizontalAlignment="Stretch"
133-
VerticalAlignment="Center"
134-
ItemsSource="{Binding GameVersionList}"
135-
SelectedItem="{Binding GameVersionDownload}" />
136-
</DockPanel>
137-
<DockPanel MinWidth="140" Margin="0,0,10,10">
138-
<TextBlock Margin="0,0,5,0" Text="{setting:Localize AddModPackWindow.Text5}" />
125+
<ScrollViewer Name="ScrollViewer2" HorizontalScrollBarVisibility="Disabled">
126+
<DockPanel Name="ModPackFiles" Margin="20,10,20,10">
127+
<Grid
128+
Margin="0,0,0,10"
129+
ColumnDefinitions="auto,*,auto,auto"
130+
DockPanel.Dock="Top">
131+
<TextBlock
132+
Grid.Column="0"
133+
Margin="0,0,5,0"
134+
Text="{setting:Localize Text.GameVersion}" />
135+
<ComboBox
136+
Grid.Column="1"
137+
Height="30"
138+
Margin="0,0,10,0"
139+
HorizontalAlignment="Stretch"
140+
VerticalAlignment="Center"
141+
ItemsSource="{Binding GameVersionList}"
142+
SelectedItem="{Binding GameVersionDownload}" />
143+
<StackPanel
144+
Grid.Column="2"
145+
Margin="0,0,10,0"
146+
Orientation="Horizontal">
147+
<Button
148+
Width="35"
149+
Height="35"
150+
Margin="-5"
151+
Classes="top"
152+
Command="{Binding LastVersionPage}"
153+
Content="-"
154+
IsEnabled="{Binding HaveLastVersionPage}" />
139155
<NumericUpDown
156+
Width="60"
140157
Height="30"
141-
HorizontalAlignment="Stretch"
142-
VerticalAlignment="Center"
158+
Margin="5,0,5,0"
143159
FormatString="N0"
144-
Maximum="{Binding MaxPageDownload}"
145-
Minimum="0"
146-
Value="{Binding PageDownload}" />
147-
</DockPanel>
148-
<StackPanel
149-
Margin="0,1,10,10"
150-
HorizontalAlignment="Right"
151-
Orientation="Horizontal">
160+
Maximum="{Binding MaxPageVersion}"
161+
Minimum="1"
162+
ShowButtonSpinner="False"
163+
Value="{Binding PageVersion}" />
164+
<Button
165+
Width="35"
166+
Height="35"
167+
Margin="-5"
168+
Classes="top"
169+
Command="{Binding NextVersionPage}"
170+
Content="+"
171+
IsEnabled="{Binding HaveNextVersionPage}" />
172+
<TextBlock Margin="5,0,0,0" Text="/" />
173+
<TextBlock Text="{Binding MaxPageVersion}" />
174+
<TextBlock Text="{setting:Localize AddModPackWindow.Text42}" />
175+
</StackPanel>
176+
<StackPanel Grid.Column="3" Orientation="Horizontal">
152177
<Button
153178
Width="100"
154179
Height="35"
@@ -166,7 +191,7 @@
166191
Content="{setting:Localize AddModPackWindow.Text12}"
167192
ToolTip.Tip="{setting:Localize ToolTip.Text91}" />
168193
</StackPanel>
169-
</WrapPanel>
194+
</Grid>
170195
<Panel>
171196
<StackPanel IsVisible="{Binding !EmptyVersionDisplay, FallbackValue=true}">
172197
<ItemsControl
@@ -186,10 +211,10 @@
186211
Classes="top"
187212
Command="{Binding NextVersionPage}"
188213
Content="{setting:Localize AddModPackWindow.Text14}"
189-
IsVisible="{Binding EnableNextPageDownload}" />
214+
IsVisible="{Binding HaveNextVersionPage}" />
190215
</StackPanel>
191216
<Border
192-
Margin="10,5,10,10"
217+
Margin="0,10,0,10"
193218
Classes="t1"
194219
IsVisible="{Binding EmptyVersionDisplay}">
195220
<TextBlock
@@ -198,12 +223,15 @@
198223
Text="{setting:Localize AddModPackWindow.Text13}" />
199224
</Border>
200225
</Panel>
201-
</StackPanel>
226+
</DockPanel>
202227
</ScrollViewer>
203228
</TabItem>
204229
<TabItem Header="{setting:Localize AddModPackWindow.Text37}">
205230
<Panel DataContext="{Binding Last}">
206-
<ScrollViewer IsVisible="{Binding HaveScreenshots}">
231+
<ScrollViewer
232+
Name="ScrollViewer3"
233+
HorizontalScrollBarVisibility="Disabled"
234+
IsVisible="{Binding HaveScreenshots}">
207235
<ItemsControl HorizontalAlignment="Center" ItemsSource="{Binding Screenshots}">
208236
<ItemsControl.ItemsPanel>
209237
<ItemsPanelTemplate>

src/ColorMC.Gui/UI/Controls/Add/AddFileInfoControl.axaml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using System.ComponentModel;
13
using Avalonia.Controls;
24
using Avalonia.Input;
35
using ColorMC.Gui.UI.Model.Add;
@@ -11,6 +13,25 @@ public AddFileInfoControl()
1113
InitializeComponent();
1214

1315
ModPackFiles.PointerPressed += ModPackFiles_PointerPressed;
16+
DataContextChanged += AddFileInfoControl_DataContextChanged;
17+
}
18+
19+
private void AddFileInfoControl_DataContextChanged(object? sender, EventArgs e)
20+
{
21+
if (DataContext is AddBaseModel model)
22+
{
23+
model.PropertyChanged += Model_PropertyChanged;
24+
}
25+
}
26+
27+
private void Model_PropertyChanged(object? sender, PropertyChangedEventArgs e)
28+
{
29+
if (e.PropertyName == nameof(AddBaseModel.DisplayItemInfo))
30+
{
31+
ScrollViewer1.ScrollToHome();
32+
ScrollViewer2.ScrollToHome();
33+
ScrollViewer3.ScrollToHome();
34+
}
1435
}
1536

1637
private void ModPackFiles_PointerPressed(object? sender, PointerPressedEventArgs e)

src/ColorMC.Gui/UI/Controls/Dialog/ProgressControl.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:model="clr-namespace:ColorMC.Gui.UI.Model.Dialog"
88
xmlns:setting="clr-namespace:ColorMC.Gui.UI"
9-
Margin="10"
109
x:DataType="model:ProgressModel"
1110
mc:Ignorable="d">
1211
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

src/ColorMC.Gui/UI/Controls/Items/FileVersionItemControl.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:model="clr-namespace:ColorMC.Gui.UI.Model.Items"
88
xmlns:setting="clr-namespace:ColorMC.Gui.UI"
9+
d:DesignHeight="250"
10+
d:DesignWidth="500"
911
x:DataType="model:FileVersionItemModel"
1012
mc:Ignorable="d">
1113
<Border
12-
Margin="10,5,10,5"
14+
Margin="5,5,5,5"
1315
Background="{setting:Theme ItemBG}"
1416
BoxShadow="{Binding Border}"
1517
CornerRadius="5">

src/ColorMC.Gui/UI/Model/Add/AddFileInfoControlModel.cs

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public partial class AddBaseModel : IAddFileControl
3030
/// 文件列表当前页数
3131
/// </summary>
3232
[ObservableProperty]
33-
private int? _pageDownload = 0;
33+
private int? _pageVersion = 1;
3434
/// <summary>
3535
/// 文件列表最大页数
3636
/// </summary>
3737
[ObservableProperty]
38-
private int _maxPageDownload;
38+
private int _maxPageVersion;
3939
/// <summary>
4040
/// 文件列表游戏版本
4141
/// </summary>
@@ -48,11 +48,6 @@ public partial class AddBaseModel : IAddFileControl
4848
[ObservableProperty]
4949
private bool _emptyVersionDisplay;
5050
/// <summary>
51-
/// 是否允许文件列表下一页
52-
/// </summary>
53-
[ObservableProperty]
54-
private bool _enableNextPageDownload;
55-
/// <summary>
5651
/// 是否显示项目详情
5752
/// </summary>
5853
[ObservableProperty]
@@ -69,6 +64,17 @@ public partial class AddBaseModel : IAddFileControl
6964
[ObservableProperty]
7065
private int _selectIndex = 0;
7166

67+
/// <summary>
68+
/// 项目列表是否有下一页
69+
/// </summary>
70+
[ObservableProperty]
71+
private bool _haveNextVersionPage;
72+
/// <summary>
73+
/// 是否有上一页
74+
/// </summary>
75+
[ObservableProperty]
76+
private bool _haveLastVersionPage;
77+
7278
partial void OnSelectIndexChanged(int value)
7379
{
7480
if (_load)
@@ -86,7 +92,7 @@ partial void OnSelectIndexChanged(int value)
8692
/// 页数改变
8793
/// </summary>
8894
/// <param name="value"></param>
89-
partial void OnPageDownloadChanged(int? value)
95+
partial void OnPageVersionChanged(int? value)
9096
{
9197
if (_load)
9298
{
@@ -110,6 +116,34 @@ partial void OnGameVersionDownloadChanged(string? value)
110116
LoadVersion(Last.SourceType, Last.ID);
111117
}
112118

119+
/// <summary>
120+
/// 返回上一页
121+
/// </summary>
122+
[RelayCommand]
123+
public void LastVersionPage()
124+
{
125+
if (_load || PageVersion <= 1)
126+
{
127+
return;
128+
}
129+
130+
PageVersion -= 1;
131+
}
132+
133+
/// <summary>
134+
/// 下一页
135+
/// </summary>
136+
[RelayCommand]
137+
public void NextVersionPage()
138+
{
139+
if (_load)
140+
{
141+
return;
142+
}
143+
144+
PageVersion += 1;
145+
}
146+
113147
/// <summary>
114148
/// 搜索文件列表
115149
/// </summary>
@@ -141,6 +175,8 @@ public async Task Download()
141175
public void CloseView()
142176
{
143177
DisplayItemInfo = false;
178+
FileList.Clear();
179+
SelectIndex = 0;
144180
}
145181

146182
/// <summary>
@@ -152,18 +188,19 @@ public async void LoadVersion(SourceType type, string pid)
152188
FileList.Clear();
153189
var dialog = Window.ShowProgress(LanguageUtils.Get("AddModPackWindow.Text19"));
154190
List<FileVersionItemModel>? list = null;
155-
var page = 0;
156-
PageDownload ??= 0;
191+
var page = 1;
192+
PageVersion ??= 1;
157193

158194
if (type == SourceType.CurseForge)
159195
{
160-
page = PageDownload ?? 0;
196+
page = PageVersion ?? 1;
161197
}
162198

199+
page--;
163200
var res = await WebBinding.GetFileListAsync(type,
164201
pid, page,
165202
GameVersionDownload, Loaders.Normal);
166-
MaxPageDownload = res.Count / 50;
203+
MaxPageVersion = res.Count / 50;
167204
list = res.List;
168205
var title = res.Name;
169206

@@ -173,7 +210,7 @@ public async void LoadVersion(SourceType type, string pid)
173210
page = 0;
174211
}
175212

176-
EnableNextPageDownload = (MaxPageDownload - PageDownload) > 0;
213+
VersionPageLoad();
177214

178215
if (list == null)
179216
{
@@ -221,29 +258,9 @@ public void SetSelect(FileVersionItemModel item)
221258
item.IsSelect = true;
222259
}
223260

224-
/// <summary>
225-
/// 返回上一页
226-
/// </summary>
227-
public void LastVersionPage()
228-
{
229-
if (_load || PageDownload <= 0)
230-
{
231-
return;
232-
}
233-
234-
PageDownload -= 1;
235-
}
236-
237-
/// <summary>
238-
/// 下一页
239-
/// </summary>
240-
public void NextVersionPage()
261+
protected void VersionPageLoad()
241262
{
242-
if (_load)
243-
{
244-
return;
245-
}
246-
247-
PageDownload += 1;
263+
HaveNextVersionPage = PageVersion < MaxPageVersion;
264+
HaveLastVersionPage = PageVersion > 1;
248265
}
249266
}

src/ColorMC.Gui/UI/Windows/MainView.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
DisableOpeningAnimation="True"
3333
Identifier="{Binding WindowId}"
3434
IsMultipleDialogsEnabled="True"
35-
DialogMargin="0"
3635
OverlayBackground="Transparent">
3736
<dialog:DialogHost.DataTemplates>
3837
<utils:TemplateSelector />

0 commit comments

Comments
 (0)