StandardLevelDetailViewRefreshContent.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using HarmonyLib;
  2. //using CustomUI.BeatSaber;
  3. using SongCore.UI;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using TMPro;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using SongCore.Utilities;
  10. using IPA.Utilities;
  11. namespace SongCore.HarmonyPatches
  12. {
  13. [HarmonyPatch(typeof(StandardLevelDetailViewController))]
  14. [HarmonyPatch("UpdateActionButtonIntractability", MethodType.Normal)]
  15. public class BlockGameButtonInteractabilityUpdateAsItLiterallyAlwaysEnablesIt
  16. {
  17. public static bool Prefix()
  18. {
  19. return false;
  20. }
  21. }
  22. [HarmonyPatch(typeof(StandardLevelDetailView))]
  23. [HarmonyPatch("RefreshContent", MethodType.Normal)]
  24. public class StandardLevelDetailViewRefreshContent
  25. {
  26. public static Dictionary<string, OverrideLabels> levelLabels = new Dictionary<string, OverrideLabels>();
  27. public class OverrideLabels
  28. {
  29. internal string EasyOverride = "";
  30. internal string NormalOverride = "";
  31. internal string HardOverride = "";
  32. internal string ExpertOverride = "";
  33. internal string ExpertPlusOverride = "";
  34. }
  35. public static OverrideLabels currentLabels = new OverrideLabels();
  36. internal static void SetCurrentLabels(OverrideLabels labels)
  37. {
  38. currentLabels.EasyOverride = labels.EasyOverride;
  39. currentLabels.NormalOverride = labels.NormalOverride;
  40. currentLabels.HardOverride = labels.HardOverride;
  41. currentLabels.ExpertOverride = labels.ExpertOverride;
  42. currentLabels.ExpertPlusOverride = labels.ExpertPlusOverride;
  43. }
  44. internal static void clearOverrideLabels()
  45. {
  46. currentLabels.EasyOverride = "";
  47. currentLabels.NormalOverride = "";
  48. currentLabels.HardOverride = "";
  49. currentLabels.ExpertOverride = "";
  50. currentLabels.ExpertPlusOverride = "";
  51. }
  52. static IPreviewBeatmapLevel lastLevel;
  53. static void Postfix(StandardLevelDetailView __instance, ref LevelParamsPanel ____levelParamsPanel, ref IDifficultyBeatmap ____selectedDifficultyBeatmap,
  54. ref PlayerData ____playerData, /*ref TextMeshProUGUI ____songNameText,*/ ref UnityEngine.UI.Button ____actionButton,
  55. ref UnityEngine.UI.Button ____practiceButton, ref BeatmapDifficultySegmentedControlController ____beatmapDifficultySegmentedControlController,
  56. ref BeatmapCharacteristicSegmentedControlController ____beatmapCharacteristicSegmentedControlController)
  57. {
  58. bool firstSelection = false;
  59. var level = ____selectedDifficultyBeatmap.level is CustomBeatmapLevel ? ____selectedDifficultyBeatmap.level as CustomPreviewBeatmapLevel : null;
  60. if (level != lastLevel)
  61. {
  62. firstSelection = true;
  63. lastLevel = level;
  64. }
  65. ____actionButton.interactable = true;
  66. ____practiceButton.interactable = true;
  67. //____songNameText.text = "<size=78%>" + ____songNameText.text.Replace(@"<", "<\u200B").Replace(@">", ">\u200B");
  68. // ____songNameText.overflowMode = TextOverflowModes.Overflow;
  69. // ____songNameText.enableWordWrapping = false;
  70. //____songNameText.richText = true;
  71. RequirementsUI.instance.ButtonGlowColor = false;
  72. RequirementsUI.instance.ButtonInteractable = false;
  73. if (level != null)
  74. {
  75. Data.ExtraSongData songData = Collections.RetrieveExtraSongData(Utilities.Hashing.GetCustomLevelHash(level), level.customLevelPath);
  76. if (songData == null)
  77. {
  78. RequirementsUI.instance.ButtonGlowColor = false;
  79. RequirementsUI.instance.ButtonInteractable = false;
  80. return;
  81. }
  82. bool wipFolderSong = false;
  83. IDifficultyBeatmap selectedDiff = ____selectedDifficultyBeatmap;
  84. Data.ExtraSongData.DifficultyData diffData = Collections.RetrieveDifficultyData(selectedDiff);
  85. //songData._difficulties?.FirstOrDefault(x => x._difficulty == selectedDiff.difficulty
  86. //&& (x._beatmapCharacteristicName == selectedDiff.parentDifficultyBeatmapSet.beatmapCharacteristic.characteristicName || x._beatmapCharacteristicName == selectedDiff.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName));
  87. if (diffData != null)
  88. {
  89. //If no additional information is present
  90. if (diffData.additionalDifficultyData._requirements.Count() == 0 && diffData.additionalDifficultyData._suggestions.Count() == 0
  91. && diffData.additionalDifficultyData._warnings.Count() == 0 && diffData.additionalDifficultyData._information.Count() == 0
  92. && songData.contributors.Count() == 0)
  93. {
  94. RequirementsUI.instance.ButtonGlowColor = false;
  95. RequirementsUI.instance.ButtonInteractable = false;
  96. }
  97. else if (diffData.additionalDifficultyData._warnings.Count() == 0)
  98. {
  99. RequirementsUI.instance.ButtonGlowColor = true;
  100. RequirementsUI.instance.ButtonInteractable = true;
  101. }
  102. else if (diffData.additionalDifficultyData._warnings.Count() > 0)
  103. {
  104. RequirementsUI.instance.ButtonGlowColor = true;
  105. RequirementsUI.instance.ButtonInteractable = true;
  106. if (diffData.additionalDifficultyData._warnings.Contains("WIP"))
  107. {
  108. ____actionButton.interactable = false;
  109. }
  110. }
  111. }
  112. if (level.levelID.EndsWith(" WIP"))
  113. {
  114. RequirementsUI.instance.ButtonGlowColor = true;
  115. RequirementsUI.instance.ButtonInteractable = true;
  116. ____actionButton.interactable = false;
  117. wipFolderSong = true;
  118. }
  119. if (diffData != null)
  120. {
  121. for (int i = 0; i < diffData.additionalDifficultyData._requirements.Count(); i++)
  122. {
  123. if (!Collections.capabilities.Contains(diffData.additionalDifficultyData._requirements[i]))
  124. {
  125. ____actionButton.interactable = false;
  126. ____practiceButton.interactable = false;
  127. RequirementsUI.instance.ButtonGlowColor = true;
  128. RequirementsUI.instance.ButtonInteractable = true;
  129. }
  130. }
  131. }
  132. if (selectedDiff.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName == "MissingCharacteristic")
  133. {
  134. ____actionButton.interactable = false;
  135. ____practiceButton.interactable = false;
  136. RequirementsUI.instance.ButtonGlowColor = true;
  137. RequirementsUI.instance.ButtonInteractable = true;
  138. }
  139. RequirementsUI.instance.level = level;
  140. RequirementsUI.instance.songData = songData;
  141. RequirementsUI.instance.diffData = diffData;
  142. RequirementsUI.instance.wipFolder = wipFolderSong;
  143. //Difficulty Label Handling
  144. levelLabels.Clear();
  145. string currentCharacteristic = "";
  146. foreach (Data.ExtraSongData.DifficultyData diffLevel in songData._difficulties)
  147. {
  148. var difficulty = diffLevel._difficulty;
  149. string characteristic = diffLevel._beatmapCharacteristicName;
  150. if (characteristic == selectedDiff.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)
  151. currentCharacteristic = characteristic;
  152. if (!levelLabels.ContainsKey(characteristic))
  153. levelLabels.Add(characteristic, new OverrideLabels());
  154. OverrideLabels charLabels = levelLabels[characteristic];
  155. if (!string.IsNullOrWhiteSpace(diffLevel._difficultyLabel))
  156. {
  157. switch (difficulty)
  158. {
  159. case BeatmapDifficulty.Easy:
  160. charLabels.EasyOverride = diffLevel._difficultyLabel;
  161. break;
  162. case BeatmapDifficulty.Normal:
  163. charLabels.NormalOverride = diffLevel._difficultyLabel;
  164. break;
  165. case BeatmapDifficulty.Hard:
  166. charLabels.HardOverride = diffLevel._difficultyLabel;
  167. break;
  168. case BeatmapDifficulty.Expert:
  169. charLabels.ExpertOverride = diffLevel._difficultyLabel;
  170. break;
  171. case BeatmapDifficulty.ExpertPlus:
  172. charLabels.ExpertPlusOverride = diffLevel._difficultyLabel;
  173. break;
  174. }
  175. }
  176. }
  177. if (!string.IsNullOrWhiteSpace(currentCharacteristic))
  178. SetCurrentLabels(levelLabels[currentCharacteristic]);
  179. else
  180. clearOverrideLabels();
  181. ____beatmapDifficultySegmentedControlController.SetData(____selectedDifficultyBeatmap.parentDifficultyBeatmapSet.difficultyBeatmaps, ____beatmapDifficultySegmentedControlController.selectedDifficulty);
  182. clearOverrideLabels();
  183. if (songData._defaultCharacteristic != null && firstSelection)
  184. {
  185. if(____beatmapCharacteristicSegmentedControlController.selectedBeatmapCharacteristic.serializedName != songData._defaultCharacteristic)
  186. {
  187. var chars = ____beatmapCharacteristicSegmentedControlController.GetField<List<BeatmapCharacteristicSO>, BeatmapCharacteristicSegmentedControlController>("_beatmapCharacteristics");
  188. int index = 0;
  189. foreach (var characteristic in chars)
  190. {
  191. if (songData._defaultCharacteristic == characteristic.serializedName)
  192. break;
  193. index++;
  194. }
  195. if (index != chars.Count)
  196. ____beatmapCharacteristicSegmentedControlController.GetField<HMUI.IconSegmentedControl, BeatmapCharacteristicSegmentedControlController>("_segmentedControl").SelectCellWithNumber(index);
  197. ____beatmapCharacteristicSegmentedControlController.HandleDifficultySegmentedControlDidSelectCell(
  198. ____beatmapCharacteristicSegmentedControlController.GetField<HMUI.IconSegmentedControl, BeatmapCharacteristicSegmentedControlController>("_segmentedControl"), index);
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }