Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions HarmonyPatches/IsPlaylist.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 4 additions & 4 deletions HarmonyPatches/SelectedSongChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -30,6 +32,7 @@ public Plugin(IPALogger logger, IPA.Config.Config conf)
Log = logger;
//Config.Instance = conf.Generated<Config>();
harmony = new Harmony("Kinsi55.BeatSaber.SongDescriptionButItWorks");
detail = new DetailViewController();
}

[OnEnable]
Expand Down
5 changes: 4 additions & 1 deletion SongDescriptionButItWorks.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<LangVersion>8</LangVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
Expand Down Expand Up @@ -66,6 +66,9 @@
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="PlaylistManager">
<HintPath>..\..\..\Documents\beat saber\BSLegacyLauncher\Installed Versions\Beat Saber 1.24.0\Plugins\PlaylistManager.dll</HintPath>
</Reference>
<Reference Include="System">
</Reference>
<Reference Include="System.Core">
Expand Down
76 changes: 67 additions & 9 deletions UI/DetailViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JObject>(jsonReader).GetValue("description").Value<string>();
return ser.Deserialize<JObject>(jsonReader);
// return isPlaylist ? "yes playlist" : "not playlist";
}
});
Plugin.Log.Info($"{i++}");

Plugin.Log.Info($"description {mapInfo.GetValue("description").Value<string>()}");
Plugin.Log.Info($"id {mapInfo.GetValue("id").Value<string>()}");
Plugin.Log.Info($"updatedAt {mapInfo.GetValue("updatedAt").Value<string>()}");
// Plugin.Log.Info($"uploader.name {mapInfo.GetValue("uploader.name").Value<string>()}");


try{
description.text = mapInfo.GetValue("description").Value<string>();
} catch { Plugin.Log.Error("Error while setting description"); }

try
{
bsr.text = mapInfo.GetValue("id").Value<string>();
} catch { Plugin.Log.Error("Error while setting id"); }

try
{
date.text = mapInfo.GetValue("updatedAt").Value<string>();
} catch { Plugin.Log.Error("Error while setting updatedAt"); }


try
{
// mapperName.text = mapInfo.GetValue("uploader.name").Value<string>();
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";
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions UI/detailui.bsml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<bg xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='- https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'>
<button id='button' text='I' on-click='LoadDescription' click-event='openDescription' ignore-layout='true' anchor-min-x='0.91' anchor-min-y='0.68' />
<!--<clickable-image src='#RandomIcon' anchor-pos-x='0.9' anchor-pos-y='0.6' hover-hint='Map info' click-event='openDescription' on-click='LoadDescription' preserve-aspect='true' min-width='7'/>-->
<clickable-image anchor-pos-x='-25' anchor-pos-y='22' hover-hint='Map info' click-event='openDescription' on-click='LoadDescription' preserve-aspect='true' min-width='4'/>

<modal move-to-center='true' hide-event='eventThatClosesModal' show-event='openDescription' size-delta-x='80' size-delta-y='50'>
<vertical horizontal-fit='Unconstrained' pad='2'>
<vertical horizontal-fit='Unconstrained' preferred-height='15'>
<image src='#RandomIcon' id="mapperAvatar" preserve-aspect="true" min-width='1.5' anchor-pos-x='20' anchor-pos-y='20'/>
<text id='mapperName' text='Loading mapper name...' anchor-pos-x='5' anchor-pos-y='10'/>
</vertical>
<vertical vertical-fit='PreferredSize' preferred-height='10'>
<text id='bsr' text='Loading bsr...' size-delta-y='2'/>
<text id='date' text='Loading date...' size-delta-y='2'/>
</vertical>
<vertical horizontal-fit='Unconstrained' vertical-fit='Unconstrained' preferred-height='40'>
<text-page id='description' text='Loading...'/>
<text-page id='description' text='Loading description...'/>
</vertical>
<vertical vertical-fit='PreferredSize' preferred-height='10'>
<button text='Close this' click-event='eventThatClosesModal'/>
Expand Down