Skip to content

Commit 95edf9f

Browse files
committed
up
1 parent 2ecf9c3 commit 95edf9f

15 files changed

Lines changed: 320 additions & 130 deletions

File tree

src/ColorMC.Gui/Manager/GameManager.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public static GameGuiSettingObj ReadConfig(GameSettingObj obj)
227227
obj1.Log ??= MakeLog();
228228
obj1.Mod ??= MakeMod();
229229
obj1.ModName ??= [];
230+
obj1.Mod.Groups ??= [];
230231
s_datas.Add(obj.UUID, obj1);
231232
return obj1;
232233
}
@@ -287,7 +288,7 @@ private static GameModSettingObj MakeMod()
287288
{
288289
return new GameModSettingObj
289290
{
290-
291+
Groups = []
291292
};
292293
}
293294

@@ -634,4 +635,27 @@ public static void StartGameHandle(GameSettingObj obj, GameHandle handle)
634635
IsBackground = true
635636
}.Start();
636637
}
638+
639+
/// <summary>
640+
/// 获取模组分组
641+
/// </summary>
642+
/// <param name="game">游戏实例</param>
643+
/// <returns>模组分组</returns>
644+
public static Dictionary<string, List<string>> GetModGroup(GameSettingObj game)
645+
{
646+
var config = ReadConfig(game);
647+
return config.Mod.Groups;
648+
}
649+
650+
/// <summary>
651+
/// 保存模组分组
652+
/// </summary>
653+
/// <param name="game">游戏实例</param>
654+
/// <param name="group">模组分组</param>
655+
public static void SetModGroup(GameSettingObj game, Dictionary<string, List<string>> group)
656+
{
657+
var config = ReadConfig(game);
658+
config.Mod.Groups = group;
659+
WriteConfig(game, config);
660+
}
637661
}

src/ColorMC.Gui/Objs/Config/GameGuiSettingObj.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public record GameLogSettingObj
2222

2323
public record GameModSettingObj
2424
{
25-
25+
/// <summary>
26+
/// 模组分组列表
27+
/// </summary>
28+
public Dictionary<string, List<string>> Groups { get; set; }
2629
}
2730

2831
public record GameGuiSettingObj

src/ColorMC.Gui/Objs/Enums.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,6 @@ public enum ModFilterType
196196
/// </summary>
197197
Modid,
198198
/// <summary>
199-
/// 启用状态
200-
/// </summary>
201-
Enabled,
202-
/// <summary>
203-
/// 禁用状态
204-
/// </summary>
205-
Disabled,
206-
/// <summary>
207199
/// 有新版本
208200
/// </summary>
209201
Newer

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@
512512
"GameEditWindow.Tab4.Text13": "文件编号",
513513
"GameEditWindow.Tab4.Text14": "加载侧",
514514
"GameEditWindow.Tab4.Text15": "备注",
515-
"GameEditWindow.Tab4.Text16": "已启用",
516-
"GameEditWindow.Tab4.Text17": "已禁用",
517515
"GameEditWindow.Tab4.Text18": "有新版本",
518516
"GameEditWindow.Tab4.Text19": "正在加载模组列表",
519517
"GameEditWindow.Tab4.Text20": "添加完成",
@@ -543,6 +541,9 @@
543541
"GameEditWindow.Tab4.Text44": "模组删除失败",
544542
"GameEditWindow.Tab4.Text45": "标记信息不完整",
545543
"GameEditWindow.Tab4.Text46": "标记信息错误",
544+
"GameEditWindow.Tab4.Text47": "无法识别列表",
545+
"GameEditWindow.Tab4.Text48": "已启用列表",
546+
"GameEditWindow.Tab4.Text49": "已禁用列表",
546547
"GameEditWindow.Tab5.Text1": "备份文件夹",
547548
"GameEditWindow.Tab5.Text2": "还原存档备份",
548549
"GameEditWindow.Tab5.Text3": "存档编辑器",

src/ColorMC.Gui/Resource/ResourceDictionary1.axaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@
4747
<TextBlock Text="{Binding Name}" />
4848
</StackPanel>
4949
</DataTemplate>
50+
<DataTemplate x:Key="ModCell1" DataType="vm:ModNodeModel">
51+
<CheckBox IsChecked="{Binding Enable, Mode=TwoWay}" />
52+
</DataTemplate>
53+
<DataTemplate x:Key="ModCell2" DataType="vm:ModNodeModel">
54+
<TextBlock Text="{Binding Text, Mode=TwoWay}" />
55+
</DataTemplate>
5056
</ResourceDictionary>

src/ColorMC.Gui/UI/Controls/GameEdit/Tab4Control.axaml

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,67 +45,10 @@
4545
DockPanel.Dock="Right"
4646
ToolTip.Tip="{setting:Localize ToolTip.Text55}" />
4747
</Grid>
48-
<DataGrid
49-
Name="DataGrid1"
48+
<TreeDataGrid
49+
Name="TreeView1"
5050
Margin="5"
51-
AutoGenerateColumns="False"
52-
CanUserResizeColumns="True"
53-
HorizontalScrollBarVisibility="Visible"
54-
ItemsSource="{Binding ModList}"
55-
SelectedItem="{Binding ModItem}"
56-
VerticalScrollBarVisibility="Visible">
57-
<DataGrid.Columns>
58-
<DataGridCheckBoxColumn
59-
Binding="{Binding Enable}"
60-
Header="{setting:Localize Text.Enable}"
61-
IsReadOnly="True" />
62-
<DataGridTextColumn Binding="{Binding Text}" Header="{setting:Localize GameEditWindow.Tab4.Text15}" />
63-
<DataGridTextColumn
64-
Binding="{Binding Modid}"
65-
Header="modid"
66-
IsReadOnly="True" />
67-
<DataGridTextColumn
68-
Binding="{Binding Name}"
69-
Header="{setting:Localize Text.Name}"
70-
IsReadOnly="True" />
71-
<DataGridTextColumn
72-
Binding="{Binding Version}"
73-
Header="{setting:Localize Text.Version}"
74-
IsReadOnly="True" />
75-
<DataGridTextColumn
76-
Binding="{Binding Loader}"
77-
Header="{setting:Localize GameEditWindow.Tab4.Text11}"
78-
IsReadOnly="True" />
79-
<DataGridTextColumn
80-
Binding="{Binding Side}"
81-
Header="{setting:Localize GameEditWindow.Tab4.Text14}"
82-
IsReadOnly="True" />
83-
<DataGridTextColumn
84-
Binding="{Binding Source}"
85-
Header="{setting:Localize Text.DownloadSource}"
86-
IsReadOnly="True" />
87-
<DataGridTextColumn
88-
Binding="{Binding PID}"
89-
Header="{setting:Localize GameEditWindow.Tab4.Text12}"
90-
IsReadOnly="True" />
91-
<DataGridTextColumn
92-
Binding="{Binding FID}"
93-
Header="{setting:Localize GameEditWindow.Tab4.Text13}"
94-
IsReadOnly="True" />
95-
<DataGridTextColumn
96-
Binding="{Binding Local}"
97-
Header="{setting:Localize Text.Path}"
98-
IsReadOnly="True" />
99-
<DataGridTextColumn
100-
Binding="{Binding Author}"
101-
Header="{setting:Localize Text.Author}"
102-
IsReadOnly="True" />
103-
<DataGridTextColumn
104-
Binding="{Binding Url}"
105-
Header="{setting:Localize GameEditWindow.Tab4.Text10}"
106-
IsReadOnly="True" />
107-
</DataGrid.Columns>
108-
</DataGrid>
51+
Source="{Binding ModSource}" />
10952
</DockPanel>
11053
</Border>
11154
<Panel

src/ColorMC.Gui/UI/Controls/GameEdit/Tab4Control.axaml.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public Tab4Control()
1616
{
1717
InitializeComponent();
1818

19-
DataGrid1.DoubleTapped += DataGrid1_DoubleTapped;
20-
DataGrid1.CellPointerPressed += DataGrid1_CellPointerPressed;
19+
TreeView1.DoubleTapped += DataGrid1_DoubleTapped;
20+
TreeView1.PointerPressed += DataGrid1_CellPointerPressed;
2121

2222
AddHandler(DragDrop.DragEnterEvent, DragEnter);
2323
AddHandler(DragDrop.DragLeaveEvent, DragLeave);
@@ -43,9 +43,9 @@ private void Drop(object? sender, DragEventArgs e)
4343
(DataContext as GameEditModel)!.DropMod(e.DataTransfer);
4444
}
4545

46-
private void DataGrid1_CellPointerPressed(object? sender, DataGridCellPointerPressedEventArgs e)
46+
private void DataGrid1_CellPointerPressed(object? sender, PointerPressedEventArgs e)
4747
{
48-
if (e.PointerPressedEventArgs.GetCurrentPoint(this).Properties.IsRightButtonPressed)
48+
if (e.GetCurrentPoint(this).Properties.IsRightButtonPressed)
4949
{
5050
Flyout((sender as Control)!);
5151
}
@@ -73,7 +73,11 @@ private void Flyout(Control control)
7373

7474
Dispatcher.UIThread.Post(() =>
7575
{
76-
var items = DataGrid1.SelectedItems;
76+
var items = TreeView1.RowSelection?.SelectedItems;
77+
if (items == null)
78+
{
79+
return;
80+
}
7781
GameEditFlyout1.Show(control, items, model);
7882
});
7983
}

src/ColorMC.Gui/UI/Flyouts/GameEditFlyout1.cs

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Linq;
54
using Avalonia.Controls;
@@ -19,21 +18,64 @@ namespace ColorMC.Gui.UI.Flyouts;
1918
/// </summary>
2019
public static class GameEditFlyout1
2120
{
22-
public static void Show(Control con, IList list, GameEditModel model)
21+
public static void Show(Control con, IReadOnlyList<object?> list, GameEditModel model)
2322
{
24-
ModDisplayModel obj = null!;
23+
ModNodeModel obj = null!;
2524
bool single = false;
26-
IEnumerable<ModDisplayModel> mods;
27-
mods = list.Cast<ModDisplayModel>();
25+
var mods = list.Cast<ModNodeModel>();
2826
if (mods.Count() == 1)
2927
{
30-
single = true;
31-
obj = mods.ToList()[0];
28+
var item = mods.First();
29+
if (item.IsGroup)
30+
{
31+
if (item.Children.Count == 0)
32+
{
33+
return;
34+
}
35+
else if (item.Children.Count == 1)
36+
{
37+
single = true;
38+
obj = item.Children.First();
39+
}
40+
else
41+
{
42+
mods = item.Children;
43+
}
44+
}
45+
else
46+
{
47+
single = true;
48+
obj = item;
49+
}
50+
}
51+
else
52+
{
53+
bool group = false;
54+
bool isitem = false;
55+
foreach (var item in mods)
56+
{
57+
if (item.IsGroup)
58+
{
59+
group = true;
60+
continue;
61+
}
62+
else
63+
{
64+
isitem = true;
65+
}
66+
67+
if (group && isitem)
68+
{
69+
break;
70+
}
71+
}
72+
73+
mods = [.. mods.Where(item => !item.IsGroup)];
3274
}
3375

3476
new FlyoutsControl(
35-
[
36-
new FlyoutMenuModel(LangUtils.Get("GameEditWindow.Flyouts.Text1"), true, () =>
77+
[
78+
new FlyoutMenuModel(LangUtils.Get("GameEditWindow.Flyouts.Text1"), true, () =>
3779
{
3880
if (single)
3981
{

src/ColorMC.Gui/UI/Model/GameEdit/GameEditModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ public override void Close()
345345
LoaderVersionList.Clear();
346346
GroupList.Clear();
347347
JvmList.Clear();
348-
ModList.Clear();
348+
_root.Clear();
349349
_modItems.Clear();
350+
_displayModList.Clear();
350351
foreach (var item in WorldList)
351352
{
352353
item.Close();

0 commit comments

Comments
 (0)