Skip to content

Commit

Permalink
添加 UserDataPanel添加解锁音乐功能
Browse files Browse the repository at this point in the history
  • Loading branch information
WYH2004-MC committed Oct 8, 2024
1 parent 47dc279 commit e37152d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SinmaiAssist {
public static partial class BuildInfo {
public const string CommitHash = "c23d5c7";
public const string BuildDate = "2024-10-08T11:55:00.8502037+08:00";
public const string CommitHash = "47dc279";
public const string BuildDate = "2024-10-08T18:37:12.4228763+08:00";
}
}
67 changes: 63 additions & 4 deletions GUI/UserDataPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Linq;
using MAI2.Util;
using Manager;
using MelonLoader;
Expand All @@ -21,7 +23,7 @@ private enum CollectionType
Frame = UserData.Collection.Frame
}

private static string[] _collectionId = new string[6] { "", "", "", "", "", ""};
private static string[] _userInputId = new string[6] { "", "", "", "", "", ""};

public static void OnGUI()
{
Expand All @@ -44,15 +46,26 @@ public static void OnGUI()
GUILayout.BeginHorizontal();
int typeId = (int)type;
GUILayout.Label(type.ToString(), new GUIStyle(UnityEngine.GUI.skin.label){fixedWidth = 50});
_collectionId[typeId] = GUILayout.TextField(_collectionId[typeId]);
_userInputId[typeId] = GUILayout.TextField(_userInputId[typeId]);
if (GUILayout.Button("Add", new GUIStyle(UnityEngine.GUI.skin.button){ fixedWidth = 50}))
{
AddCollections(0, type, _collectionId[typeId]);
AddCollections(1, type, _collectionId[typeId]);
AddCollections(0, type, _userInputId[typeId]);
AddCollections(1, type, _userInputId[typeId]);
}
GUILayout.EndHorizontal();
}

GUILayout.Label("Unlock Music", MainGUI.Style.Title);
GUILayout.BeginHorizontal();
GUILayout.Label("Music", new GUIStyle(UnityEngine.GUI.skin.label){fixedWidth = 50});
_userInputId[0] = GUILayout.TextField(_userInputId[0]);
if (GUILayout.Button("Add", new GUIStyle(UnityEngine.GUI.skin.button){ fixedWidth = 50}))
{
UnlockMusic(0, _userInputId[0]);
UnlockMusic(1, _userInputId[0]);
}
GUILayout.EndHorizontal();

GUILayout.Label("User Data Backup", MainGUI.Style.Title);
GUILayout.BeginHorizontal();
if (GUILayout.Button("1P")) User.ExportBackupData(0);
Expand Down Expand Up @@ -93,4 +106,50 @@ private static void AddCollections(long index, CollectionType type, string input
MelonLogger.Error(e);
}
}

private static void UnlockMusic(long index, string input)
{
UserData userData = Singleton<UserDataManager>.Instance.GetUserData(index);
if (userData.IsGuest())
{
GameMessageManager.SendGameMessage("Guest Account\nUnable to unlock music", (int)index);
return;
}
try
{
if (int.TryParse(input, out int id))
{
if (!userData.IsUnlockMusic(UserData.MusicUnlock.Base, id))
{
if (userData.AddUnlockMusic(UserData.MusicUnlock.Base, id))
{
GameMessageManager.SendGameMessage($"Unlock Music \n{id}", (int)index);
}
else
{
GameMessageManager.SendGameMessage($"Failed to unlock music \n{id}", (int)index);
}
}
else if(!userData.IsUnlockMusic(UserData.MusicUnlock.Master, id))
{
userData.AddUnlockMusic(UserData.MusicUnlock.Master, id);
userData.AddUnlockMusic(UserData.MusicUnlock.ReMaster, id);
GameMessageManager.SendGameMessage($"Unlock Master \n{id}", (int)index);
}
else
{
GameMessageManager.SendGameMessage($"Music not found or already unlocked\n{id}", (int)index);
}
}
else
{
GameMessageManager.SendGameMessage($"Invalid ID\n {input}", (int)index);
}
}
catch (Exception e)
{
GameMessageManager.SendGameMessage($"Unknown error", (int)index);
MelonLogger.Error(e);
}
}
}
2 changes: 2 additions & 0 deletions Utils/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ public static UserData GetUserData(long index)
{
return Singleton<UserDataManager>.Instance.GetUserData(index);
}


}

0 comments on commit e37152d

Please sign in to comment.