From 0e32d52a0bd7da2b16d22d7b4e5675b790e26533 Mon Sep 17 00:00:00 2001
From: Coloryr <402067010@qq.com>
Date: Mon, 15 Jul 2024 18:16:07 +0800
Subject: [PATCH] =?UTF-8?q?up=20=E4=BF=AEbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
TODO | 4 ++++
src/ColorMC.Core/CoreMain.cs | 15 +++++++++++-
src/ColorMC.Core/Helpers/AddGameHelper.cs | 3 +--
src/ColorMC.Core/LaunchPath/InstancesPath.cs | 5 +++-
.../UI/Controls/Add/AddGameControl.axaml.cs | 3 ++-
.../UI/Controls/Main/MainControl.axaml.cs | 8 +++++++
src/ColorMC.Gui/UI/Model/Add/AddGameModel.cs | 4 +++-
.../UI/Model/Items/GameItemModel.cs | 2 ++
.../UI/Model/Main/GameGroupModel.cs | 23 +++++++++++++++----
.../UI/Model/Main/GameListModel.cs | 8 +++++++
.../UI/Model/Main/MinecraftNewsModel.cs | 3 ++-
src/ColorMC.Gui/UIBinding/BaseBinding.cs | 6 +++++
12 files changed, 73 insertions(+), 11 deletions(-)
diff --git a/TODO b/TODO
index cf04a224c..7bc3f81e2 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,7 @@
+⚫2024.7.15
+√ 修复添加游戏分组问题
+√ 修复图标不刷新问题
+
⚫2024.7.2
√ 删除滚轮切换
diff --git a/src/ColorMC.Core/CoreMain.cs b/src/ColorMC.Core/CoreMain.cs
index 4ee73698d..50897c6cb 100644
--- a/src/ColorMC.Core/CoreMain.cs
+++ b/src/ColorMC.Core/CoreMain.cs
@@ -15,7 +15,7 @@ namespace ColorMC.Core;
public static class ColorMCCore
{
public const string TopVersion = "A27";
- public const string DateVersion = "20240711";
+ public const string DateVersion = "20240715";
///
/// 版本号
@@ -143,6 +143,10 @@ public static class ColorMCCore
///
public static event Action? InstanceChange;
///
+ /// 游戏实例图标修改事件
+ ///
+ public static event Action? InstanceIconChange;
+ ///
/// 手机端启动
///
public static Func, Dictionary, IGameHandel> PhoneGameLaunch { internal get; set; }
@@ -318,4 +322,13 @@ internal static void OnInstanceChange()
{
InstanceChange?.Invoke();
}
+
+ ///
+ /// 游戏图标修改
+ ///
+ ///
+ internal static void OnInstanceIconChange(GameSettingObj obj)
+ {
+ InstanceIconChange?.Invoke(obj);
+ }
}
\ No newline at end of file
diff --git a/src/ColorMC.Core/Helpers/AddGameHelper.cs b/src/ColorMC.Core/Helpers/AddGameHelper.cs
index 3dda325c9..754678ca4 100644
--- a/src/ColorMC.Core/Helpers/AddGameHelper.cs
+++ b/src/ColorMC.Core/Helpers/AddGameHelper.cs
@@ -192,6 +192,7 @@ public static async Task InstallZip(InstallZipArg arg)
{
Zip = arg.Dir,
Name = arg.Name,
+ Group = arg.Group,
Request = arg.Request,
Overwirte = arg.Overwirte,
Update = arg.Update,
@@ -546,6 +547,4 @@ public static async Task InstallCurseForge(DownloadCurseForgeArg arg)
return res2;
}
-
-
}
diff --git a/src/ColorMC.Core/LaunchPath/InstancesPath.cs b/src/ColorMC.Core/LaunchPath/InstancesPath.cs
index 6fcb0d661..3bc5d8a2a 100644
--- a/src/ColorMC.Core/LaunchPath/InstancesPath.cs
+++ b/src/ColorMC.Core/LaunchPath/InstancesPath.cs
@@ -1087,7 +1087,7 @@ public static async Task SetGameIconFromUrl(this GameSettingObj obj, strin
if (data.Item1)
{
PathHelper.WriteBytes(obj.GetIconFile(), data.Item2!);
-
+ ColorMCCore.OnInstanceIconChange(obj);
return true;
}
@@ -1108,6 +1108,7 @@ public static bool SetGameIconFromFile(this GameSettingObj obj, string file)
}
PathHelper.CopyFile(file, obj.GetIconFile());
+ ColorMCCore.OnInstanceIconChange(obj);
return true;
}
@@ -1120,6 +1121,7 @@ public static bool SetGameIconFromFile(this GameSettingObj obj, string file)
public static void SetGameIconFromBytes(this GameSettingObj obj, byte[] data)
{
PathHelper.WriteBytes(obj.GetIconFile(), data);
+ ColorMCCore.OnInstanceIconChange(obj);
}
///
@@ -1130,5 +1132,6 @@ public static void SetGameIconFromBytes(this GameSettingObj obj, byte[] data)
public static void SetGameIconFromStream(this GameSettingObj obj, byte[] data)
{
PathHelper.WriteBytes(obj.GetIconFile(), data);
+ ColorMCCore.OnInstanceIconChange(obj);
}
}
\ No newline at end of file
diff --git a/src/ColorMC.Gui/UI/Controls/Add/AddGameControl.axaml.cs b/src/ColorMC.Gui/UI/Controls/Add/AddGameControl.axaml.cs
index b8d57d69b..7c6087127 100644
--- a/src/ColorMC.Gui/UI/Controls/Add/AddGameControl.axaml.cs
+++ b/src/ColorMC.Gui/UI/Controls/Add/AddGameControl.axaml.cs
@@ -84,7 +84,8 @@ public void SetGroup(string? group)
{
if (DataContext is AddGameModel model)
{
- model.Group ??= group;
+ model.DefaultGroup = group;
+ model.Group = group;
}
}
diff --git a/src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs b/src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs
index cea978c04..63d1f1e6d 100644
--- a/src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs
+++ b/src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs
@@ -338,4 +338,12 @@ public override Bitmap GetIcon()
{
return ImageManager.GameIcon;
}
+
+ public void IconChange(string uuid)
+ {
+ if (DataContext is MainModel model)
+ {
+ model.IconChange(uuid);
+ }
+ }
}
diff --git a/src/ColorMC.Gui/UI/Model/Add/AddGameModel.cs b/src/ColorMC.Gui/UI/Model/Add/AddGameModel.cs
index 6bd00c894..558f14084 100644
--- a/src/ColorMC.Gui/UI/Model/Add/AddGameModel.cs
+++ b/src/ColorMC.Gui/UI/Model/Add/AddGameModel.cs
@@ -39,6 +39,8 @@ public partial class AddGameModel : TopModel
public bool IsPhone { get; }
+ public string? DefaultGroup { get; set; }
+
///
/// 是否在加载中
///
@@ -147,7 +149,7 @@ private void Back()
{
Model.PopBack();
Name = null;
- Group = null;
+ Group = DefaultGroup;
Version = null;
LoaderVersion = null;
LoaderTypeList.Clear();
diff --git a/src/ColorMC.Gui/UI/Model/Items/GameItemModel.cs b/src/ColorMC.Gui/UI/Model/Items/GameItemModel.cs
index 2eb6a6085..42c7a7dce 100644
--- a/src/ColorMC.Gui/UI/Model/Items/GameItemModel.cs
+++ b/src/ColorMC.Gui/UI/Model/Items/GameItemModel.cs
@@ -53,6 +53,7 @@ public partial class GameItemModel : GameModel
private readonly IMainTop _top;
public string Name => Obj.Name;
+ public string UUID => Obj.UUID;
[ObservableProperty]
private bool _oneGame;
@@ -71,6 +72,7 @@ public partial class GameItemModel : GameModel
public GameItemModel(BaseModel model, IMainTop top, GameSettingObj obj) : base(model, obj)
{
_top = top;
+ _group = obj.GroupName;
LoadIcon();
}
diff --git a/src/ColorMC.Gui/UI/Model/Main/GameGroupModel.cs b/src/ColorMC.Gui/UI/Model/Main/GameGroupModel.cs
index 4e9c85047..0bfb0183c 100644
--- a/src/ColorMC.Gui/UI/Model/Main/GameGroupModel.cs
+++ b/src/ColorMC.Gui/UI/Model/Main/GameGroupModel.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
@@ -31,6 +32,8 @@ public GameGroupModel(BaseModel model, IMainTop top, string key, string name,
List list) : base(model)
{
_top = top;
+ Header = name;
+ Key = key;
GameList.Clear();
_items.Clear();
foreach (var item in list)
@@ -55,9 +58,6 @@ public GameGroupModel(BaseModel model, IMainTop top, string key, string name,
GameList.Add(_addItem);
});
});
-
- Header = name;
- Key = key;
}
public bool DropIn(IDataObject data)
@@ -194,4 +194,19 @@ public void Display(string value)
}
}
}
+
+ public void IconChange(string uuid)
+ {
+ foreach (var item in GameList)
+ {
+ if (item.IsNew)
+ {
+ continue;
+ }
+ else if(item.UUID == uuid)
+ {
+ item.LoadIcon();
+ }
+ }
+ }
}
diff --git a/src/ColorMC.Gui/UI/Model/Main/GameListModel.cs b/src/ColorMC.Gui/UI/Model/Main/GameListModel.cs
index 946acd3be..cd5a7f4f6 100644
--- a/src/ColorMC.Gui/UI/Model/Main/GameListModel.cs
+++ b/src/ColorMC.Gui/UI/Model/Main/GameListModel.cs
@@ -90,6 +90,14 @@ public void Cancel()
_semaphore.Release();
}
+ public void IconChange(string uuid)
+ {
+ foreach (var item in GameGroups)
+ {
+ item.IconChange(uuid);
+ }
+ }
+
public void Search()
{
GameSearch = true;
diff --git a/src/ColorMC.Gui/UI/Model/Main/MinecraftNewsModel.cs b/src/ColorMC.Gui/UI/Model/Main/MinecraftNewsModel.cs
index 4d5ee2ae7..eebc77a95 100644
--- a/src/ColorMC.Gui/UI/Model/Main/MinecraftNewsModel.cs
+++ b/src/ColorMC.Gui/UI/Model/Main/MinecraftNewsModel.cs
@@ -1,4 +1,5 @@
-using System.Collections.ObjectModel;
+using System;
+using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using ColorMC.Gui.UI.Model.Items;
diff --git a/src/ColorMC.Gui/UIBinding/BaseBinding.cs b/src/ColorMC.Gui/UIBinding/BaseBinding.cs
index 7107d1591..f8bb5e5b8 100644
--- a/src/ColorMC.Gui/UIBinding/BaseBinding.cs
+++ b/src/ColorMC.Gui/UIBinding/BaseBinding.cs
@@ -97,6 +97,7 @@ public static void Init()
ColorMCCore.OnDownload = WindowManager.ShowDownload;
ColorMCCore.GameExit += GameExit;
ColorMCCore.InstanceChange += InstanceChange;
+ ColorMCCore.InstanceIconChange += InstanceIconChange;
if (ColorMCGui.RunType == RunType.Program && SystemInfo.Os != OsType.Android)
{
@@ -130,6 +131,11 @@ public static void Init()
}, handledEventsToo: true);
}
+ private static void InstanceIconChange(GameSettingObj obj)
+ {
+ WindowManager.MainWindow?.IconChange(obj.UUID);
+ }
+
private static void InstanceChange()
{
WindowManager.MainWindow?.LoadMain();