From ddaf3941cb8dff251b7902ed6d3794f2beda59bf Mon Sep 17 00:00:00 2001 From: JLChnToZ Date: Tue, 23 Apr 2024 18:08:37 +0800 Subject: [PATCH] Fix title not display correctly on play custom URL... after play from playlist without YTTL config'd. --- .../idv.jlchntoz.vvmw/Runtime/VVMW/Core.asset | 53 +++++++++++++++++- .../idv.jlchntoz.vvmw/Runtime/VVMW/Core.cs | 55 ++++++++++++------- .../Runtime/VVMW/FrontendHandler.asset | 2 +- .../Runtime/VVMW/FrontendHandler.cs | 7 ++- 4 files changed, 91 insertions(+), 26 deletions(-) diff --git a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.asset b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.asset index d511c8d..6b09337 100644 --- a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.asset +++ b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.asset @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3} m_Name: Core m_EditorClassIdentifier: - serializedUdonProgramAsset: {fileID: 11400000, guid: c66af6782ebcca44cb681de0d9b43652, + serializedUdonProgramAsset: {fileID: 11400000, guid: 0fc467ba7ec4fbf43a9186c70fe1d22a, type: 2} udonAssembly: assemblyError: @@ -44,7 +44,7 @@ MonoBehaviour: Data: - Name: Entry: 12 - Data: 65 + Data: 66 - Name: Entry: 7 Data: @@ -3751,6 +3751,55 @@ MonoBehaviour: - Name: Entry: 8 Data: + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 1 + Data: hasCustomTitle + - Name: $v + Entry: 7 + Data: 213|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: hasCustomTitle + - Name: k__BackingField + Entry: 9 + Data: 46 + - Name: k__BackingField + Entry: 9 + Data: 46 + - Name: k__BackingField + Entry: 7 + Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib + - Name: + Entry: 6 + Data: + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 5 + Data: false + - Name: _fieldAttributes + Entry: 7 + Data: 214|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], + mscorlib + - Name: + Entry: 12 + Data: 0 + - Name: + Entry: 13 + Data: + - Name: + Entry: 8 + Data: + - Name: + Entry: 8 + Data: + - Name: + Entry: 8 + Data: - Name: Entry: 13 Data: diff --git a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.cs b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.cs index cbaafc1..9acd46f 100644 --- a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.cs +++ b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/Core.cs @@ -101,6 +101,7 @@ public class Core : UdonSharpEventSender { public string viewCount = ""; [NonSerialized, FieldChangeCallback(nameof(Description))] public string description = ""; + bool hasCustomTitle; public string[] PlayerNames { get { @@ -282,7 +283,7 @@ public bool IsTrusted { string Title { get => title; set { - if (url == null || !url.Equals(localUrl)) return; + if (hasCustomTitle || url == null || !url.Equals(localUrl)) return; title = value; } } @@ -290,7 +291,7 @@ string Title { string Author { get => author; set { - if (url == null || !url.Equals(localUrl)) return; + if (hasCustomTitle || url == null || !url.Equals(localUrl)) return; author = value; } } @@ -298,7 +299,7 @@ string Author { string ViewCount { get => viewCount; set { - if (url == null || !url.Equals(localUrl)) return; + if (hasCustomTitle || url == null || !url.Equals(localUrl)) return; viewCount = value; } } @@ -306,7 +307,7 @@ string ViewCount { string Description { get => description; set { - if (url == null || !url.Equals(localUrl)) return; + if (hasCustomTitle || url == null || !url.Equals(localUrl)) return; description = value; } } @@ -405,15 +406,7 @@ public void PlayUrlMP(VRCUrl pcUrl, VRCUrl questUrl, byte playerType) { #endif activeHandler.LoadUrl(url, false); if (RequestSync()) state = LOADING; - if (yttl != null) { - if (!url.Equals(this.url)) { - author = ""; - title = ""; - viewCount = ""; - description = ""; - } - yttl.LoadData(url, this); - } + LoadYTTL(); } public override void OnVideoError(VideoError videoError) { @@ -756,7 +749,8 @@ public override void OnDeserialization() { url = pcUrl; altUrl = questUrl; } - if (state != IDLE && localUrl != url && (!IsUrlValid(localUrl) || !IsUrlValid(url) || localUrl.Get() != url.Get())) { + bool shouldReload = state != IDLE && localUrl != url && (!IsUrlValid(localUrl) || !IsUrlValid(url) || localUrl.Get() != url.Get()); + if (shouldReload) { if (activeHandler == null) { Debug.LogWarning($"[VVMW] Owner serialization incomplete, will queue a sync request."); SendCustomEventDelayedSeconds(nameof(_RequestOwnerSync), 1); @@ -770,15 +764,9 @@ public override void OnDeserialization() { trustUpdated = false; SendEvent("_OnVideoBeginLoad"); activeHandler.LoadUrl(url, false); - if (yttl != null) { - author = ""; - title = ""; - viewCount = ""; - description = ""; - yttl.LoadData(url, this); - } } localUrl = url; + if (shouldReload) LoadYTTL(); if (activeHandler != null && activeHandler.IsReady) { int intState = state; switch (intState) { @@ -934,6 +922,7 @@ public void _SyncAudioLink() { public void Yttl_OnDataLoaded() => SendEvent("_OnTitleData"); public void SetTitle(string title, string author) { + hasCustomTitle = true; url = VRCUrl.Empty; this.title = title; this.author = author; @@ -941,5 +930,29 @@ public void SetTitle(string title, string author) { viewCount = ""; SendEvent("_OnTitleData"); } + + public void _ResetTitle() { + if (!hasCustomTitle) return; + hasCustomTitle = false; + url = VRCUrl.Empty; + if (yttl == null) { + author = ""; + title = ""; + viewCount = ""; + description = ""; + } else + LoadYTTL(); + SendEvent("_OnTitleData"); + } + + void LoadYTTL() { + if (yttl == null || hasCustomTitle || url.Equals(localUrl)) return; + author = ""; + title = ""; + viewCount = ""; + description = ""; + if (localUrl != null) + yttl.LoadData(localUrl, this); + } } } diff --git a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.asset b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.asset index f8e515d..797a265 100644 --- a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.asset +++ b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.asset @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3} m_Name: FrontendHandler m_EditorClassIdentifier: - serializedUdonProgramAsset: {fileID: 11400000, guid: 5c092b7f8962cd844be63af6e369643f, + serializedUdonProgramAsset: {fileID: 11400000, guid: 774834c68f75e0341872b18681f02dda, type: 2} udonAssembly: assemblyError: diff --git a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.cs b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.cs index c4a6e09..668ca6c 100644 --- a/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.cs +++ b/Packages/idv.jlchntoz.vvmw/Runtime/VVMW/FrontendHandler.cs @@ -367,8 +367,10 @@ public override void OnDeserialization() { localHistoryTitles = string.IsNullOrEmpty(historyTitles) && (historyUrls == null || historyUrls.Length == 0) ? new string[0] : historyTitles.Split('\u2029'); localFlags = flags; - if (playListIndex > 0 && (localPlayListIndex != playListIndex || localPlayingIndex != playingIndex)) - core.SetTitle(playListEntryTitles[playingIndex], playListTitles[playListIndex - 1]); + if (playListIndex > 0) { + if (localPlayListIndex != playListIndex || localPlayingIndex != playingIndex) + core.SetTitle(playListEntryTitles[playingIndex], playListTitles[playListIndex - 1]); + } else core._ResetTitle(); localPlayListIndex = playListIndex; localPlayingIndex = playingIndex; core.Loop = RepeatOne; @@ -565,6 +567,7 @@ void PlayQueueList(int index, bool deleteOnly) { localQueuedTitles = newTitles; if (!deleteOnly) { core.PlayUrl(url, playerIndex); + core._ResetTitle(); RecordPlaybackHistory(url, playerIndex, title); } RequestSync();