diff --git a/HarmonyPatches/IsPlaylist.cs b/HarmonyPatches/IsPlaylist.cs new file mode 100644 index 0000000..42c1c71 --- /dev/null +++ b/HarmonyPatches/IsPlaylist.cs @@ -0,0 +1,34 @@ +using BeatSaberMarkupLanguage; +using BeatSaberMarkupLanguage.Attributes; +using HarmonyLib; +using HMUI; +using SongDescriptionButItWorks.UI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using PlaylistManager.UI; + +namespace SongDescriptionButItWorks.HarmonyPatches +{ + [HarmonyPatch( + typeof(LevelDetailButtonsViewController), + nameof(LevelDetailButtonsViewController.LevelCollectionUpdated) + )] + static class IsPlaylist + { + + + static void Postfix( + LevelDetailButtonsViewController __instance, + Boolean ____isPlaylistSong + // IPlaylist selectedPlaylist + ) + { + Plugin.Log.Info($"____isPlaylistSong {____isPlaylistSong}"); + Plugin.detail.SetIsPlaylist(____isPlaylistSong); + } + } +} diff --git a/HarmonyPatches/SelectedSongChanged.cs b/HarmonyPatches/SelectedSongChanged.cs index 45f0334..0a79e4a 100644 --- a/HarmonyPatches/SelectedSongChanged.cs +++ b/HarmonyPatches/SelectedSongChanged.cs @@ -18,20 +18,20 @@ namespace SongDescriptionButItWorks.HarmonyPatches )] static class SelectedSongChanged { - static DetailViewController detail = new DetailViewController(); + static void Postfix(StandardLevelDetailView __instance, IBeatmapLevel level) { - detail.SetLevel(level); + Plugin.detail.SetLevel(level); - if (detail.buttonGo != null) + if (Plugin.detail.buttonGo != null) return; // Create the UI if it isnt yet (Button and Modal) BSMLParser.instance.Parse( Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "SongDescriptionButItWorks.UI.detailui.bsml"), __instance.gameObject, - detail + Plugin.detail ); } } diff --git a/Plugin.cs b/Plugin.cs index 6c8fbf5..13273bf 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -2,6 +2,7 @@ using IPA; using IPA.Config; using IPA.Config.Stores; +using SongDescriptionButItWorks.UI; using System; using System.Collections; using System.Collections.Generic; @@ -22,6 +23,7 @@ public class Plugin internal static Plugin Instance; internal static IPALogger Log; internal static Harmony harmony; + internal static DetailViewController detail; [Init] public Plugin(IPALogger logger, IPA.Config.Config conf) @@ -30,6 +32,7 @@ public Plugin(IPALogger logger, IPA.Config.Config conf) Log = logger; //Config.Instance = conf.Generated(); harmony = new Harmony("Kinsi55.BeatSaber.SongDescriptionButItWorks"); + detail = new DetailViewController(); } [OnEnable] diff --git a/SongDescriptionButItWorks.csproj b/SongDescriptionButItWorks.csproj index 1fba7bd..71e1ad3 100644 --- a/SongDescriptionButItWorks.csproj +++ b/SongDescriptionButItWorks.csproj @@ -1,6 +1,6 @@  - net472 + net48 Library 8 false @@ -66,6 +66,9 @@ False False + + ..\..\..\Documents\beat saber\BSLegacyLauncher\Installed Versions\Beat Saber 1.24.0\Plugins\PlaylistManager.dll + diff --git a/UI/DetailViewController.cs b/UI/DetailViewController.cs index 5d5c316..9bc714a 100644 --- a/UI/DetailViewController.cs +++ b/UI/DetailViewController.cs @@ -15,48 +15,106 @@ namespace SongDescriptionButItWorks.UI class DetailViewController { static IPreviewBeatmapLevel lastLevel; + static Boolean isPlaylist; [UIComponent("button")] public readonly NoTransitionsButton buttonGo = null; - [UIComponent("description")] public readonly CurvedTextMeshPro descriptionText = null; + [UIComponent("description")] public readonly CurvedTextMeshPro description = null; + [UIComponent("bsr")] public readonly CurvedTextMeshPro bsr = null; + [UIComponent("mapperName")] public readonly CurvedTextMeshPro mapperName = null; + [UIComponent("date")] public readonly CurvedTextMeshPro date = null; internal void SetLevel(IBeatmapLevel level) { lastLevel = level; } + + internal void SetIsPlaylist(Boolean newIsPlaylist) + { + isPlaylist = newIsPlaylist; + } async void LoadDescription() { if(!lastLevel.levelID.StartsWith("custom_level_")) { - descriptionText.text = "Not a custom level"; + description.text = "Not a custom level"; return; } - descriptionText.text = "Loading..."; + description.text = "Loading..."; var hash = lastLevel.levelID.Substring(13, 40); try { - var description = await Task.Run(() => { + var i = 1; + Plugin.Log.Info($"{i++}"); + var mapInfo = await Task.Run(() => { + Plugin.Log.Info($"{i++}"); var download = new WebClient().DownloadData($"https://api.beatsaver.com/maps/hash/{hash}"); + Plugin.Log.Info($"{i++}"); using (var jsonReader = new JsonTextReader(new StreamReader(new MemoryStream(download)))) { + Plugin.Log.Info($"{i++}"); var ser = new JsonSerializer(); + Plugin.Log.Info($"{i++}"); - return ser.Deserialize(jsonReader).GetValue("description").Value(); + return ser.Deserialize(jsonReader); + // return isPlaylist ? "yes playlist" : "not playlist"; } }); + Plugin.Log.Info($"{i++}"); + + Plugin.Log.Info($"description {mapInfo.GetValue("description").Value()}"); + Plugin.Log.Info($"id {mapInfo.GetValue("id").Value()}"); + Plugin.Log.Info($"updatedAt {mapInfo.GetValue("updatedAt").Value()}"); + // Plugin.Log.Info($"uploader.name {mapInfo.GetValue("uploader.name").Value()}"); + + + try{ + description.text = mapInfo.GetValue("description").Value(); + } catch { Plugin.Log.Error("Error while setting description"); } + + try + { + bsr.text = mapInfo.GetValue("id").Value(); + } catch { Plugin.Log.Error("Error while setting id"); } + + try + { + date.text = mapInfo.GetValue("updatedAt").Value(); + } catch { Plugin.Log.Error("Error while setting updatedAt"); } + + + try + { + // mapperName.text = mapInfo.GetValue("uploader.name").Value(); + mapperName.text = "blackorbit"; + } catch { Plugin.Log.Error("Error while setting uploader.name"); } + + + + + + Plugin.Log.Info($"description2 {description.text}"); + Plugin.Log.Info($"id2 {bsr.text}"); + Plugin.Log.Info($"updatedAt2 {date.text}"); + // Plugin.Log.Info($"uploader.name2 {mapperName.text}"); - descriptionText.text = description; - descriptionText.gameObject.SetActive(false); - descriptionText.gameObject.SetActive(true); + description.gameObject.SetActive(false); + description.gameObject.SetActive(true); + bsr.gameObject.SetActive(false); + bsr.gameObject.SetActive(true); + date.gameObject.SetActive(false); + date.gameObject.SetActive(true); + mapperName.gameObject.SetActive(false); + mapperName.gameObject.SetActive(true); } catch { - descriptionText.text = "Failed to load Description"; + description.text = "Failed to load Description"; } } } diff --git a/UI/detailui.bsml b/UI/detailui.bsml index e2c9b8d..b2c005f 100644 --- a/UI/detailui.bsml +++ b/UI/detailui.bsml @@ -1,10 +1,19 @@  -