Skip to content

Commit 2157bb0

Browse files
committed
up 调整界面功能
1 parent e5d8795 commit 2157bb0

16 files changed

Lines changed: 177 additions & 63 deletions

File tree

src/ColorMC.Core/Game/GameArg.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ void DoLibItem(FileItemObj item)
735735
//非自定义加载器
736736
if (obj.CustomLoader?.CustomJson != true)
737737
{
738-
var game = await obj.CheckGameArgFileAsync();
738+
var game = await obj.CheckGameArgFileAsync()
739+
?? throw new LaunchException(LaunchError.LostVersionFile);
739740
var v2 = obj.IsGameVersionV2();
740741
arg.JavaVersions.Add(game.JavaVersion!.MajorVersion);
741742

src/ColorMC.Core/Helpers/CheckHelpers.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,33 @@ public static ConcurrentBag<FileItemObj> CheckAssets(this AssetsObj obj, Cancell
274274
/// </summary>
275275
/// <param name="obj">游戏实例</param>
276276
/// <returns></returns>
277-
public static async Task<GameArgObj> CheckGameArgFileAsync(this GameSettingObj obj)
277+
public static Task<GameArgObj?> CheckGameArgFileAsync(this GameSettingObj obj)
278278
{
279-
var game = await VersionPath.CheckUpdateAsync(obj.Version);
279+
return CheckGameArgFileAsync(obj.Version);
280+
}
281+
282+
/// <summary>
283+
/// 更新游戏arg文件
284+
/// </summary>
285+
/// <param name="ver"></param>
286+
/// <returns></returns>
287+
/// <exception cref="LaunchException"></exception>
288+
public static async Task<GameArgObj?> CheckGameArgFileAsync(string ver)
289+
{
290+
var game = await VersionPath.CheckUpdateAsync(ver);
280291
//不存在游戏
281292
if (game != null)
282293
{
283294
return game;
284295
}
285296

286297
var var = await VersionPath.GetVersionsAsync();
287-
var version = var?.Versions.FirstOrDefault(a => a.Id == obj.Version)
288-
?? throw new LaunchException(LaunchError.LostVersionFile);
289-
return await VersionPath.AddGameAsync(version)
290-
?? throw new LaunchException(LaunchError.LostVersionFile);
298+
var version = var?.Versions.FirstOrDefault(a => a.Id == ver);
299+
if (version == null)
300+
{
301+
return null;
302+
}
303+
return await VersionPath.AddGameAsync(version);
291304
}
292305

293306
/// <summary>

src/ColorMC.Core/Worker/CurseForgeWork.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public async Task<bool> ReadVersion()
8989

9090
GameVersion = _info.Minecraft.Version;
9191

92-
if (VersionPath.CheckUpdateAsync(GameVersion) == null)
92+
if (CheckHelpers.CheckGameArgFileAsync(GameVersion) == null)
9393
{
9494
await VersionPath.GetFromWebAsync();
95-
if (VersionPath.CheckUpdateAsync(GameVersion) == null)
95+
if (CheckHelpers.CheckGameArgFileAsync(GameVersion) == null)
9696
{
9797
return false;
9898
}

src/ColorMC.Core/Worker/ModrinthWork.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ public async Task<bool> ReadVersion()
303303

304304
GameVersion = _info.Dependencies[Names.NameMinecraftKey];
305305

306-
if (VersionPath.CheckUpdateAsync(GameVersion) == null)
306+
if (CheckHelpers.CheckGameArgFileAsync(GameVersion) == null)
307307
{
308308
await VersionPath.GetFromWebAsync();
309-
if (VersionPath.CheckUpdateAsync(GameVersion) == null)
309+
if (CheckHelpers.CheckGameArgFileAsync(GameVersion) == null)
310310
{
311311
return false;
312312
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ public record LauncherSetting
307307
public bool FastModrinth { get; set; }
308308
}
309309

310+
/// <summary>
311+
/// 界面功能设置
312+
/// </summary>
313+
public record WindowUserStateObj
314+
{
315+
/// <summary>
316+
/// 主窗口状态
317+
/// </summary>
318+
public ItemsGridType MainWindowState { get; set; }
319+
}
320+
310321
/// <summary>
311322
/// Gui配置文件
312323
/// </summary>
@@ -442,5 +453,9 @@ public record GuiConfigObj
442453
/// 启动器功能
443454
/// </summary>
444455
public LauncherSetting LauncherFunction { get; set; }
456+
/// <summary>
457+
/// 启动器窗口
458+
/// </summary>
459+
public WindowUserStateObj WindowState { get; set; }
445460
}
446461

src/ColorMC.Gui/Objs/Results.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,10 @@ public record KeyRes
274274
{
275275
public bool Positive;
276276
public byte Key;
277+
}
278+
279+
public record SetGamesRes
280+
{
281+
public readonly List<GameItemModel> Removes = [];
282+
public readonly List<GameItemModel> Adds = [];
277283
}

src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@
171171
DockPanel.Dock="Top"
172172
IPPort="{Binding Server}"
173173
IsVisible="{Binding MotdDisplay}" />
174-
<DockPanel Margin="30,20,0,0" DockPanel.Dock="Top">
174+
<DockPanel
175+
Margin="30,20,0,0"
176+
DockPanel.Dock="Top"
177+
IsVisible="{Binding HaveGame}">
175178
<Border
176179
Padding="3"
177180
Background="{setting:Theme RadioGroupBG}"

src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ public override void Closed()
249249

250250
public override async void Opened()
251251
{
252+
if (DataContext is MainModel model)
253+
{
254+
if (ColorMCGui.IsCrash)
255+
{
256+
model.Window.Show(LangUtils.Get("MainWindow.Text81"));
257+
}
258+
259+
model.Load();
260+
}
261+
252262
var config = GuiConfigUtils.Config.ServerCustom;
253263
if (ColorMCCore.NewStart || config.CustomStart)
254264
{
@@ -261,12 +271,6 @@ public override async void Opened()
261271
Start.IsVisible = false;
262272
Start.Child = null;
263273
}
264-
265-
if (ColorMCGui.IsCrash)
266-
{
267-
var model = (DataContext as MainModel)!;
268-
model.Window.Show(LangUtils.Get("MainWindow.Text81"));
269-
}
270274
}
271275

272276
public override async Task<bool> Closing()
@@ -397,4 +401,15 @@ public void ReloadBlock()
397401
}
398402
});
399403
}
404+
405+
/// <summary>
406+
/// 加载卡片
407+
/// </summary>
408+
public void LoadCard()
409+
{
410+
if (DataContext is MainModel model)
411+
{
412+
model.LoadCard();
413+
}
414+
}
400415
}

src/ColorMC.Gui/UI/Controls/Main/SimpleControl.axaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
mc:Ignorable="d">
1414
<Border Classes="t2">
1515
<StackPanel
16-
Margin="10"
16+
Margin="20"
1717
HorizontalAlignment="Center"
1818
VerticalAlignment="Center"
1919
RenderOptions.TextRenderingMode="Antialias">
2020
<Image
21-
Width="120"
22-
Height="120"
21+
Width="100"
22+
Height="100"
2323
Source="{Binding GameIcon}" />
2424
<TextBlock
25-
Margin="0,10,0,10"
25+
Margin="0,5,0,10"
2626
HorizontalAlignment="Center"
2727
FontSize="20"
2828
MaxLines="3"
@@ -97,9 +97,7 @@
9797
OffContent="{setting:Localize SettingWindow.Tab4.Text12}"
9898
OnContent="{setting:Localize SettingWindow.Tab4.Text12}" />
9999
</Grid>
100-
101100
<Grid
102-
Margin="0,0,0,10"
103101
ColumnDefinitions="auto,*,auto,*"
104102
IsEnabled="{Binding HaveGame}"
105103
IsVisible="{Binding EnableArg}">

src/ColorMC.Gui/UI/Model/Main/GameGroupModel.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using ColorMC.Core;
1010
using ColorMC.Core.Objs;
1111
using ColorMC.Gui.Manager;
12+
using ColorMC.Gui.Objs;
1213
using ColorMC.Gui.UI.Model.Items;
1314
using ColorMC.Gui.UIBinding;
1415
using ColorMC.Gui.Utils;
@@ -205,7 +206,7 @@ public void Drop(IDataTransfer data)
205206
/// 设置游戏实例项目
206207
/// </summary>
207208
/// <param name="list"></param>
208-
public void SetItems(List<GameSettingObj> list)
209+
public SetGamesRes? SetItems(List<GameSettingObj> list)
209210
{
210211
var remove = new List<Guid>();
211212
var ins = new List<GameSettingObj>();
@@ -229,28 +230,31 @@ public void SetItems(List<GameSettingObj> list)
229230
remove.Add(item);
230231
}
231232

233+
//完全空的组,不会存在这样的情况
232234
if (GameList.Count == 0 || GameList.Count - 1 < 0)
233235
{
234-
return;
236+
return null;
235237
}
236238
GameList.RemoveAt(GameList.Count - 1);
237239

240+
var res = new SetGamesRes();
241+
238242
foreach (var item in remove)
239243
{
240-
Items.Remove(item);
241-
var model = GameList.FirstOrDefault(item1 => item1.Obj.UUID == item);
242-
if (model != null)
244+
if (Items.Remove(item, out var item1))
243245
{
244-
model.Close();
245-
GameList.Remove(model);
246+
GameList.Remove(item1);
247+
res.Removes.Add(item1);
248+
item1.Close();
246249
}
247250
}
248251

249252
//筛选添加的内容
250253
foreach (var item in ins)
251254
{
252-
var model1 = new GameItemModel(Window, Top, item);
253-
Items.Add(item.UUID, model1);
255+
var model = new GameItemModel(Window, Top, item);
256+
Items.Add(item.UUID, model);
257+
res.Adds.Add(model);
254258
}
255259

256260
Task.Run(() =>
@@ -269,6 +273,8 @@ public void SetItems(List<GameSettingObj> list)
269273
GameList.Add(_addItem);
270274
});
271275
});
276+
277+
return res;
272278
}
273279

274280
public override void Close()

0 commit comments

Comments
 (0)