Skip to content

Commit 029cd38

Browse files
committed
up 收藏下载与资源添加互锁
1 parent 177e59e commit 029cd38

17 files changed

Lines changed: 447 additions & 327 deletions

src/ColorMC.Gui/Manager/EventManager.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static class EventManager
1313
private static readonly List<Action<SourceItemObj, bool>> s_modpackStop = [];
1414
private static readonly List<Action<Guid, SourceItemObj>> s_resourceInstall = [];
1515
private static readonly List<Action<Guid, SourceItemObj, bool>> s_resourceStop = [];
16-
private static readonly List<Action<Guid>> s_throwResourceDownload = [];
1716

1817
/// <summary>
1918
/// 游戏实例图标修改
@@ -120,21 +119,6 @@ public static event Action<Guid, SourceItemObj, bool> ResourceStop
120119
}
121120
}
122121

123-
/// <summary>
124-
/// 其他窗口关闭资源下载
125-
/// </summary>
126-
public static event Action<Guid> ThrowResourceDownload
127-
{
128-
add
129-
{
130-
s_throwResourceDownload.Add(value);
131-
}
132-
remove
133-
{
134-
s_throwResourceDownload.Remove(value);
135-
}
136-
}
137-
138122
public static void OnGameIconChange(Guid uuid)
139123
{
140124
foreach (var item in s_gameIconChange.ToArray())
@@ -190,12 +174,4 @@ public static void OnResourceStop(Guid game, SourceItemObj obj, bool res)
190174
item.Invoke(game, obj, res);
191175
}
192176
}
193-
194-
public static void OnThrowResourceDownload(Guid game)
195-
{
196-
foreach (var item in s_throwResourceDownload.ToArray())
197-
{
198-
item.Invoke(game);
199-
}
200-
}
201177
}

src/ColorMC.Gui/Manager/GameManager.cs

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Threading;
56
using ColorMC.Core;
67
using ColorMC.Core.Config;
@@ -45,81 +46,118 @@ public static class GameManager
4546
/// <summary>
4647
/// 正在安装的整合包
4748
/// </summary>
48-
private static readonly List<FileItemDownloadModel> s_installModpack = [];
49+
private static readonly List<SourceItemObj> s_installModpack = [];
4950
/// <summary>
5051
/// 正在安装资源的游戏实例
5152
/// </summary>
52-
private static readonly Dictionary<Guid, List<FileItemDownloadModel>> s_gameDownload = [];
53+
private static readonly Dictionary<Guid, List<SourceItemObj>> s_gameDownload = [];
5354

54-
public static void StartDownload(Guid game, FileItemDownloadModel download)
55+
public static void StartDownload(Guid game, SourceItemObj obj)
5556
{
5657
if (s_gameDownload.TryGetValue(game, out var list))
5758
{
58-
list.Add(download);
59+
list.Add(obj);
5960
}
6061
else
6162
{
62-
s_gameDownload[game] = [download];
63+
s_gameDownload[game] = [obj];
6364
}
65+
66+
EventManager.OnResourceInstall(game, obj);
6467
}
6568

66-
public static void StopDownload(Guid game, FileItemDownloadModel download)
69+
public static void StopDownload(Guid game, SourceItemObj obj, bool res)
6770
{
6871
if (s_gameDownload.TryGetValue(game, out var list))
6972
{
70-
list.Remove(download);
73+
list.Remove(obj);
7174
}
75+
76+
EventManager.OnResourceStop(game, obj, res);
7277
}
7378

7479
/// <summary>
7580
/// 开始下载整合包
7681
/// </summary>
7782
/// <param name="obj"></param>
78-
public static void StartDownload(FileItemDownloadModel obj)
83+
public static void StartDownload(SourceItemObj obj)
7984
{
8085
foreach (var item in s_installModpack)
8186
{
82-
if (item.Obj.Source == obj.Obj.Source && item.Obj.Pid == obj.Obj.Pid)
87+
if (item.CheckProject(obj))
8388
{
8489
return;
8590
}
8691
}
8792

8893
s_installModpack.Add(obj);
8994

90-
EventManager.OnModpackInstall(obj.Obj);
95+
EventManager.OnModpackInstall(obj);
9196
}
9297

93-
public static void StopDownload(FileItemDownloadModel obj, bool res)
98+
public static void StopDownload(SourceItemObj obj, bool res)
9499
{
95100
s_installModpack.Remove(obj);
96101

97-
EventManager.OnModpackStop(obj.Obj, res);
102+
EventManager.OnModpackStop(obj, res);
98103
}
99104

100105
/// <summary>
101106
/// 检查资源是否在下载
102107
/// </summary>
103108
/// <param name="obj"></param>
104109
/// <returns></returns>
105-
public static bool TestDowload(Guid game, SourceItemObj obj)
106-
{
107-
//foreach (var item in s_installModpack)
108-
//{
109-
// if (item.FileType == info.Type && item.SourceType == info.Source)
110-
// {
111-
// if (item.ID == info.Pid)
112-
// {
113-
// item.NowDownload = false;
114-
// item.IsDownload = done;
115-
// }
116-
// else if (info.SubPid != null && info.SubPid.Contains(item.ID))
117-
// {
118-
// item.NowDownload = false;
119-
// item.NowDownload = done;
120-
// }
121-
// }
122-
//}
110+
public static bool IsDownload(Guid game, SourceItemObj obj)
111+
{
112+
if (s_gameDownload.TryGetValue(game, out var list))
113+
{
114+
foreach (var item in list)
115+
{
116+
if (item.CheckProject(obj))
117+
{
118+
return true;
119+
}
120+
}
121+
}
122+
123+
return false;
124+
}
125+
126+
/// <summary>
127+
/// 检查游戏资源是否在下载
128+
/// </summary>
129+
/// <param name="obj"></param>
130+
/// <returns></returns>
131+
public static bool IsDownload(Guid game, SourceType source, FileType type, string pid)
132+
{
133+
if (s_gameDownload.TryGetValue(game, out var list))
134+
{
135+
foreach (var item in list)
136+
{
137+
if (item.Source == source && item.Pid == pid && item.Type == type)
138+
{
139+
return true;
140+
}
141+
}
142+
}
143+
144+
return false;
145+
}
146+
147+
/// <summary>
148+
/// 检查整合包是否在下载
149+
/// </summary>
150+
/// <param name="obj"></param>
151+
/// <returns></returns>
152+
public static bool IsDownload(SourceItemObj obj)
153+
{
154+
foreach (var item in s_installModpack)
155+
{
156+
if (item.Source == obj.Source && item.Pid == obj.Pid)
157+
{
158+
return true;
159+
}
160+
}
123161

124162
return false;
125163
}
@@ -129,11 +167,11 @@ public static bool TestDowload(Guid game, SourceItemObj obj)
129167
/// </summary>
130168
/// <param name="obj"></param>
131169
/// <returns></returns>
132-
public static bool TestDowload(SourceItemObj obj)
170+
public static bool IsDownload(SourceType source, string pid)
133171
{
134172
foreach (var item in s_installModpack)
135173
{
136-
if (item.Obj.Source == obj.Source && item.Obj.Pid == obj.Pid)
174+
if (item.Source == source && item.Pid == pid)
137175
{
138176
return true;
139177
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ColorMC.Core.Objs;
2+
3+
namespace ColorMC.Gui.Objs;
4+
5+
/// <summary>
6+
/// 收藏资源下载项目
7+
/// </summary>
8+
public record CollectFileItemObj
9+
{
10+
public FileItemObj File;
11+
public SourceItemObj Source;
12+
public bool Download;
13+
}

src/ColorMC.Gui/Objs/SourceItemObj.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using ColorMC.Core.Objs;
34

45
namespace ColorMC.Gui.Objs;
@@ -24,10 +25,6 @@ public record SourceItemObj
2425
/// 文件ID
2526
/// </summary>
2627
public required string Fid;
27-
/// <summary>
28-
/// 项目子ID
29-
/// </summary>
30-
public List<string>? SubPid;
3128

3229
public bool CheckProject(SourceItemObj other)
3330
{
@@ -38,13 +35,4 @@ public bool CheckProject(SourceType source, FileType type, string pid)
3835
{
3936
return Type == type && Source == source && Pid == pid;
4037
}
41-
42-
public bool CheckSubPid(SourceItemObj other)
43-
{
44-
if (SubPid == null)
45-
{
46-
return false;
47-
}
48-
return Type == other.Type && Source == other.Source && SubPid.Contains(other.Pid);
49-
}
5038
}

src/ColorMC.Gui/Resource/Language/zh-cn.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@
761761
"AddModPackWindow.Text43": "是否需要取消安装整合包",
762762
"AddModPackWindow.Text44": "搜索名字",
763763
"AddModPackWindow.Text45": "没有正在安装的项目",
764+
"AddModPackWindow.Text46": "该整合包正在下载中",
764765
"AddResourceWindow.Title": "游戏实例添加资源 {0}",
765766
"AddResourceWindow.Text2": "搜索源",
766767
"AddResourceWindow.Text6": "全部下载",
@@ -1057,6 +1058,10 @@
10571058
"CollectWindow.Text29": "无法找到游戏实例",
10581059
"CollectWindow.Text30": "数据获取失败,安装已取消",
10591060
"CollectWindow.Text31": "整合包安装失败,是否继续安装",
1061+
"CollectWindow.Text32": "选中的资源正在其他地方下载,是否跳过后继续",
1062+
"CollectWindow.Text33": "收藏资源下载",
1063+
"CollectWindow.Text34": "选中的整合包正在其他地方下载,是否跳过后继续",
1064+
"CollectWindow.Text35": "没有需要下载的资源",
10601065
"BuildPackWindow.Title": "导出客户端",
10611066
"BuildPackWindow.Text1": "正在生成客户端包",
10621067
"BuildPackWindow.Text2": "生成的位置",
@@ -1485,6 +1490,7 @@
14851490
"Type.ModpackState.Item4": "正在解压文件",
14861491
"Type.ModpackState.Item5": "已完成",
14871492
"Type.ModpackState.Item6": "正在下载整合包",
1493+
"ToolTip.Text1": "关闭",
14881494
"ToolTip.Text7": "请选中到bin文件夹内的java",
14891495
"ToolTip.Text9": "打开皮肤查看窗口",
14901496
"ToolTip.Text11": "登录并启动游戏",

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,33 @@
1010
d:DesignWidth="800"
1111
x:DataType="model:AddBaseModel"
1212
mc:Ignorable="d">
13+
<UserControl.Styles>
14+
<!-- 定义显示/隐藏的动画效果 -->
15+
<Style Selector="ScrollViewer.DownloadCard">
16+
<Setter Property="Opacity" Value="0" />
17+
<Setter Property="RenderTransform" Value="translateY(20px)" />
18+
<Setter Property="Transitions">
19+
<Transitions>
20+
<DoubleTransition Property="Opacity" Duration="0:0:0.2" />
21+
<TransformOperationsTransition
22+
Easing="CubicEaseOut"
23+
Property="RenderTransform"
24+
Duration="0:0:0.2" />
25+
</Transitions>
26+
</Setter>
27+
</Style>
28+
<Style Selector="ScrollViewer.DownloadCard[IsVisible=True]">
29+
<Setter Property="Opacity" Value="1" />
30+
<Setter Property="RenderTransform" Value="translateY(0px)" />
31+
</Style>
32+
</UserControl.Styles>
1333
<Panel>
1434
<ScrollViewer
1535
Name="DownloadInfo"
1636
Margin="0,0,0,50"
37+
Classes="DownloadCard"
1738
HorizontalScrollBarVisibility="Disabled"
18-
IsVisible="False"
39+
IsVisible="{Binding DisplayDownload}"
1940
VerticalScrollBarVisibility="Auto">
2041
<ItemsControl ItemsSource="{Binding NowDownload}">
2142
<ItemsControl.ItemTemplate>
@@ -26,12 +47,13 @@
2647
</ItemsControl>
2748
</ScrollViewer>
2849
<Button
29-
Height="30"
50+
Height="40"
3051
Margin="10"
3152
HorizontalAlignment="Right"
3253
VerticalAlignment="Bottom"
54+
Classes="top"
3355
Command="{Binding ShowDownload}"
34-
CornerRadius="20"
56+
CornerRadius="30"
3557
IsVisible="{Binding HaveDownload}">
3658
<StackPanel Margin="10,0,10,0" Orientation="Horizontal">
3759
<TextBlock Text="{Binding DownloadText}" />

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ private void AddDownloadListControl_DataContextChanged(object? sender, EventArgs
2525

2626
private void Model_PropertyChanged(object? sender, PropertyChangedEventArgs e)
2727
{
28-
if (e.PropertyName == nameof(AddBaseModel.DisplayDownload))
29-
{
30-
if ((DataContext as AddBaseModel)!.DisplayDownload)
31-
{
32-
ThemeManager.CrossFade.Start(null, DownloadInfo);
33-
}
34-
else
35-
{
36-
ThemeManager.CrossFade.Start(DownloadInfo, null);
37-
}
38-
}
28+
//if (e.PropertyName == nameof(AddBaseModel.DisplayDownload))
29+
//{
30+
// if ((DataContext as AddBaseModel)!.DisplayDownload)
31+
// {
32+
// ThemeManager.CrossFade.Start(null, DownloadInfo);
33+
// }
34+
// else
35+
// {
36+
// ThemeManager.CrossFade.Start(DownloadInfo, null);
37+
// }
38+
//}
3939
}
4040
}

0 commit comments

Comments
 (0)