mu3-mods/SortByInternalDifficulty/MU3.ViewData/patch_MusicSelectViewDataList.cs

128 lines
5.4 KiB
C#
Raw Permalink Normal View History

using MU3.DataStudio;
using MU3.DB;
using MU3.Util;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace MU3.ViewData;
class patch_MusicSelectViewDataList: MusicSelectViewDataList {
private delegate int CompareProc(MusicSelectViewData d1, MusicSelectViewData d2, bool forSort1);
private delegate string GetCategoryNameProc(MusicSelectViewData d);
private MusicSort1ID __sort1;
private CompareProc _compareProc1;
2024-07-05 10:49:45 +00:00
private CompareProc _compareProc2;
private GetCategoryNameProc _getCategoryNameProc;
2024-08-30 17:20:26 +00:00
private PropertyInfo _reMasterPi = null;
private extern void orig_set__sort1(MusicSort1ID value);
2024-07-05 10:49:45 +00:00
private extern void orig_set__sort2(MusicSort2ID value);
private void set__sort1(MusicSort1ID value) {
if(value == (MusicSort1ID)patch_MusicSort1ID.InternalLevel) {
__sort1 = value;
_compareProc1 = compareByInternalLevel;
_getCategoryNameProc = getCategoryNameByInternalLevel;
} else {
orig_set__sort1(value);
}
}
2024-07-05 10:49:45 +00:00
private void set__sort2(MusicSort2ID value) {
orig_set__sort2(value);
if(value == MusicSort2ID.Level) {
_compareProc2 = compareByInternalLevel;
}
}
private bool isReMaster(Data.MusicData d) {
// Fall back for pre-Act3
2024-08-30 17:20:26 +00:00
if(_reMasterPi == null) {
return false;
}
2024-08-30 17:20:26 +00:00
return (bool)_reMasterPi.GetValue(d, null);
}
public extern void orig_create(GameViewData gameViewData, ChapterSelection chapterSelection, FumenDifficulty difficulty, MusicSort1ID sort1, MusicSort2ID sort2);
public new void create(GameViewData gameViewData, ChapterSelection chapterSelection, FumenDifficulty difficulty, MusicSort1ID sort1, MusicSort2ID sort2) {
2024-08-30 17:20:26 +00:00
_reMasterPi = typeof(Data.MusicData).GetProperty("isReMaster");
orig_create(gameViewData, chapterSelection, difficulty, sort1, sort2);
}
private string getMetaGategoryName(MusicSelectViewData d) {
var remas = isReMaster(d.musicViewData.data);
if(d.musicViewData.data.isBonusTrack) {
return "ボーナストラック";
}
if(d.musicViewData.data.isLunatic && remas && __sort1 != MusicSort1ID.Level && __sort1 != (MusicSort1ID)patch_MusicSort1ID.InternalLevel) {
return "Re:MASTER";
}
return d.musicViewData.data.isLunatic && !remas ? "LUNATIC" : null;
}
private string getCategoryNameByInternalLevel(MusicSelectViewData d) {
StringBuilder stringBuilder = Singleton<MU3.Sys.System>.instance.getStringBuilder();
Data.FumenData fumenData = ((d.musicViewData.data == null) ? null : d.musicViewData.data.fumenData[(int)d.difficulty]);
stringBuilder.Append("LEVEL ");
stringBuilder.AppendFormat("{0}", (fumenData == null) ? (-1) : (fumenData.fumenConst.ToString("0.0")));
return stringBuilder.ToString();
}
2024-07-05 10:49:45 +00:00
private int getSortKeyByInternalLevel(MusicSelectViewData d) {
return (int)Math.Round(d.musicViewData.data.fumenData[(int)d.difficulty].fumenConst * 10.0);
}
private int compareByInternalLevel(MusicSelectViewData d1, MusicSelectViewData d2, bool forSort1) {
2024-07-05 10:49:45 +00:00
return getSortKeyByInternalLevel(d1) - getSortKeyByInternalLevel(d2);
}
private extern bool orig_isDifferentMyListSet(patch_MusicSort1ID oldSort1, patch_MusicSort1ID nowSort1);
private bool isDifferentMyListSet(patch_MusicSort1ID oldSort1, patch_MusicSort1ID nowSort1) {
if(oldSort1 == patch_MusicSort1ID.InternalLevel && nowSort1 != patch_MusicSort1ID.InternalLevel) {
return true;
}
if(oldSort1 != patch_MusicSort1ID.InternalLevel && nowSort1 == patch_MusicSort1ID.InternalLevel) {
return true;
}
return orig_isDifferentMyListSet(oldSort1, nowSort1);
}
private extern int orig_createMyListMusicDataAllDifficulty(List<MusicSelectViewData> list, HashSet<int> idList, MU3.Data.MusicData musicData, MusicSort1ID sort1, int initOrder);
private int createMyListMusicDataAllDifficulty(List<MusicSelectViewData> list, HashSet<int> idList, MU3.Data.MusicData musicData, MusicSort1ID sort1, int initOrder) {
if(sort1 == (MusicSort1ID)patch_MusicSort1ID.InternalLevel) {
sort1 = MusicSort1ID.Level;
}
return orig_createMyListMusicDataAllDifficulty(list, idList, musicData, sort1, initOrder);
}
private extern int orig_getMetaSortKey(MusicSelectViewData d, bool forCategorySort);
private int getMetaSortKey(MusicSelectViewData d, bool forCategorySort) {
2024-08-30 17:20:26 +00:00
if(_reMasterPi == null) {
return orig_getMetaSortKey(d, forCategorySort);
}
var remas = isReMaster(d.musicViewData.data);
if(forCategorySort) {
if(d.musicViewData.data.isBonusTrack) {
return 3;
}
if(d.musicViewData.data.isLunatic && remas && __sort1 != MusicSort1ID.Level && __sort1 != (MusicSort1ID)patch_MusicSort1ID.InternalLevel) {
return 1;
}
if(d.musicViewData.data.isLunatic && !remas) {
return 2;
}
} else {
if(d.musicViewData.data.isLunatic && remas && __sort1 != MusicSort1ID.Level && __sort1 != (MusicSort1ID)patch_MusicSort1ID.InternalLevel) {
return 1;
}
if(d.musicViewData.data.isLunatic && !remas) {
return 2;
}
}
return 0;
}
}