Skip to content

Commit

Permalink
up 修bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Jul 15, 2024
1 parent efd2743 commit 0e32d52
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 11 deletions.
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
⚫2024.7.15
√ 修复添加游戏分组问题
√ 修复图标不刷新问题

⚫2024.7.2
√ 删除滚轮切换

Expand Down
15 changes: 14 additions & 1 deletion src/ColorMC.Core/CoreMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// 版本号
Expand Down Expand Up @@ -143,6 +143,10 @@ public static class ColorMCCore
/// </summary>
public static event Action? InstanceChange;
/// <summary>
/// 游戏实例图标修改事件
/// </summary>
public static event Action<GameSettingObj>? InstanceIconChange;
/// <summary>
/// 手机端启动
/// </summary>
public static Func<LoginObj, GameSettingObj, JavaInfo, List<string>, Dictionary<string, string>, IGameHandel> PhoneGameLaunch { internal get; set; }
Expand Down Expand Up @@ -318,4 +322,13 @@ internal static void OnInstanceChange()
{
InstanceChange?.Invoke();
}

/// <summary>
/// 游戏图标修改
/// </summary>
/// <param name="obj"></param>
internal static void OnInstanceIconChange(GameSettingObj obj)
{
InstanceIconChange?.Invoke(obj);
}
}
3 changes: 1 addition & 2 deletions src/ColorMC.Core/Helpers/AddGameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public static async Task<GameRes> InstallZip(InstallZipArg arg)
{
Zip = arg.Dir,
Name = arg.Name,
Group = arg.Group,
Request = arg.Request,
Overwirte = arg.Overwirte,
Update = arg.Update,
Expand Down Expand Up @@ -546,6 +547,4 @@ public static async Task<GameRes> InstallCurseForge(DownloadCurseForgeArg arg)

return res2;
}


}
5 changes: 4 additions & 1 deletion src/ColorMC.Core/LaunchPath/InstancesPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ public static async Task<bool> SetGameIconFromUrl(this GameSettingObj obj, strin
if (data.Item1)
{
PathHelper.WriteBytes(obj.GetIconFile(), data.Item2!);

ColorMCCore.OnInstanceIconChange(obj);
return true;
}

Expand All @@ -1108,6 +1108,7 @@ public static bool SetGameIconFromFile(this GameSettingObj obj, string file)
}

PathHelper.CopyFile(file, obj.GetIconFile());
ColorMCCore.OnInstanceIconChange(obj);

return true;
}
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}
}
3 changes: 2 additions & 1 deletion src/ColorMC.Gui/UI/Controls/Add/AddGameControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void SetGroup(string? group)
{
if (DataContext is AddGameModel model)
{
model.Group ??= group;
model.DefaultGroup = group;
model.Group = group;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,12 @@ public override Bitmap GetIcon()
{
return ImageManager.GameIcon;
}

public void IconChange(string uuid)
{
if (DataContext is MainModel model)
{
model.IconChange(uuid);
}
}
}
4 changes: 3 additions & 1 deletion src/ColorMC.Gui/UI/Model/Add/AddGameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public partial class AddGameModel : TopModel

public bool IsPhone { get; }

public string? DefaultGroup { get; set; }

/// <summary>
/// 是否在加载中
/// </summary>
Expand Down Expand Up @@ -147,7 +149,7 @@ private void Back()
{
Model.PopBack();
Name = null;
Group = null;
Group = DefaultGroup;
Version = null;
LoaderVersion = null;
LoaderTypeList.Clear();
Expand Down
2 changes: 2 additions & 0 deletions src/ColorMC.Gui/UI/Model/Items/GameItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down
23 changes: 19 additions & 4 deletions src/ColorMC.Gui/UI/Model/Main/GameGroupModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -31,6 +32,8 @@ public GameGroupModel(BaseModel model, IMainTop top, string key, string name,
List<GameSettingObj> list) : base(model)
{
_top = top;
Header = name;
Key = key;
GameList.Clear();
_items.Clear();
foreach (var item in list)
Expand All @@ -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)
Expand Down Expand Up @@ -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();
}
}
}
}
8 changes: 8 additions & 0 deletions src/ColorMC.Gui/UI/Model/Main/GameListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/ColorMC.Gui/UI/Model/Main/MinecraftNewsModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/ColorMC.Gui/UIBinding/BaseBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0e32d52

Please sign in to comment.