UI update 02

This commit is contained in:
FloatGaming
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
+83 -92
View File
@@ -38,9 +38,6 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
private static List<dlcData> cachedAll = new List<dlcData>();
private static bool cacheBuilt = false;
private static bool cacheBuilding = false;
private static string cachedFolder = string.Empty;
// Selection management (shared across all dlcButton instances)
private static List<dlcButton> allButtons = new List<dlcButton>();
private static int selectedIndex = -1;
@@ -49,6 +46,20 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
private int instanceIndex = -1;
private Coroutine hoverCoroutine;
private void UpdateSongsAmountText()
{
if (dlcSongsAmount != null)
{
dlcSongsAmount.text = dlcContent != null ? dlcContent.Count.ToString() : "0";
}
}
public static void ResetSelectionState()
{
allButtons.Clear();
selectedIndex = -1;
}
public void OnPointerEnter(PointerEventData eventData)
{
if (hoverCoroutine != null) StopCoroutine(hoverCoroutine);
@@ -61,6 +72,12 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
if (dlcDetailParent != null) dlcDetailParent.SetActive(false);
}
public void SetDlcData(dlcData so)
{
dlcDataSO = so;
ApplyDlcData(so);
}
private IEnumerator HandleHover()
{
yield return new WaitForSecondsRealtime(0.5f);
@@ -109,18 +126,21 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
_btn.onClick.AddListener(OnButtonClicked_ShowSongs);
}
// register this button for centralized selection handling
RegisterInstance();
// ensure border initial state
if (dlc_nowSelectedImageBoarder != null)
{
if (!dlc_nowSelectedImageBoarder.gameObject.activeSelf)
{
dlc_nowSelectedImageBoarder.gameObject.SetActive(true);
}
var c = dlc_nowSelectedImageBoarder.color;
c.a = 0f;
dlc_nowSelectedImageBoarder.color = c;
dlc_nowSelectedImageBoarder.gameObject.SetActive(false);
}
// register this button for centralized selection handling
RegisterInstance();
if (VerboseLogs) Debug.Log($"dlcButton.Awake: registered '{gameObject.name}' as index {instanceIndex}");
}
@@ -149,19 +169,25 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
SetSelectedVisual(false, immediate: true);
}
}
else
{
instanceIndex = allButtons.IndexOf(this);
}
}
private void UnregisterInstance()
{
if (allButtons.Contains(this))
int idx = allButtons.IndexOf(this);
if (idx >= 0)
{
int idx = allButtons.IndexOf(this);
allButtons.Remove(this);
// if removed index was before selectedIndex, adjust saved index
if (idx >= 0 && idx < instanceIndex)
if (selectedIndex == idx)
{
// nothing: instanceIndex only used at registration time
selectedIndex = -1;
}
else if (selectedIndex > idx)
{
selectedIndex--;
}
}
}
@@ -207,7 +233,10 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
if (immediate)
{
dlc_nowSelectedImageBoarder.gameObject.SetActive(selected);
if (!dlc_nowSelectedImageBoarder.gameObject.activeSelf)
{
dlc_nowSelectedImageBoarder.gameObject.SetActive(true);
}
var c = dlc_nowSelectedImageBoarder.color;
c.a = selected ? 1f : 0f;
dlc_nowSelectedImageBoarder.color = c;
@@ -237,10 +266,6 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
var final = img.color;
final.a = targetAlpha;
img.color = final;
if (Mathf.Approximately(targetAlpha, 0f))
{
img.gameObject.SetActive(false);
}
borderFadeCoroutine = null;
}
@@ -309,10 +334,35 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
return false;
}
ui.DisplaySongsFromList(dlcContent);
if (SongSelectUI.ForceFirstSongOnNextRestore)
{
SongDataHolder.SelectedSongData = null;
}
ui.DisplaySongsFromList(GetAccessibleDlcContent());
return true;
}
private List<SongData> GetAccessibleDlcContent()
{
List<SongData> accessible = new List<SongData>();
if (dlcContent == null)
{
return accessible;
}
for (int i = 0; i < dlcContent.Count; i++)
{
SongData song = dlcContent[i];
if (song != null && DlcContentAccess.IsSongAccessible(song))
{
accessible.Add(song);
}
}
return accessible;
}
private IEnumerator RetryDisplaySongsWhenUIReady()
{
const int maxRetryFrames = 8;
@@ -373,14 +423,14 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
// Runtime: search Resources (load all dlcData then filter by name prefix)
try
{
var arr = Resources.LoadAll<dlcData>(runtimeResourcesFolder);
if (VerboseLogs) Debug.Log($"dlcButton.LoadDlcDataById: Resources.LoadAll('{runtimeResourcesFolder}') returned {(arr != null ? arr.Length : 0)} items");
if (arr != null)
var all = RuntimeResourcesCache.LoadAllDlcs();
if (VerboseLogs) Debug.Log($"dlcButton.LoadDlcDataById: runtime cache returned {(all != null ? all.Length : 0)} items");
if (all != null)
{
foreach (var so in arr)
foreach (var so in all)
{
if (so == null) continue;
if (so.name.StartsWith(id.ToString()))
if (so.dlcID == id || so.name.StartsWith(id.ToString()))
{
if (VerboseLogs) Debug.Log($"dlcButton.LoadDlcDataById: found runtime dlcData '{so.name}' for id={id}");
dlcDataSO = so;
@@ -392,25 +442,7 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
}
catch (System.Exception e)
{
Debug.LogWarning($"dlcButton.LoadDlcDataById: Resources search failed: {e.Message}");
}
// fallback: search all Resources
var all = Resources.LoadAll<dlcData>("");
if (VerboseLogs) Debug.Log("dlcButton.LoadDlcDataById: Resources.LoadAll(\"\") returned " + (all != null ? all.Length : 0) + " items");
if (all != null)
{
foreach (var so in all)
{
if (so == null) continue;
if (so.name.StartsWith(id.ToString()))
{
if (VerboseLogs) Debug.Log($"dlcButton.LoadDlcDataById: found fallback dlcData '{so.name}' for id={id}");
dlcDataSO = so;
ApplyDlcData(so);
return;
}
}
Debug.LogWarning($"dlcButton.LoadDlcDataById: runtime cache search failed: {e.Message}");
}
// if no dlcData found, keep dlcContent empty but attempt old behavior: search SongData by id prefix
@@ -429,10 +461,7 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
if (s != null) dlcContent.Add(s);
}
if (dlcSongsAmount != null)
{
dlcSongsAmount.text = dlcContent.Count.ToString();
}
UpdateSongsAmountText();
if (dlcName != null) dlcName.text = so.dlcName ?? dlcName.text;
if (dlcProducer != null) dlcProducer.text = so.dlcProducer ?? dlcProducer.text;
@@ -474,31 +503,17 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
}
}
#endif
if (!string.IsNullOrEmpty(runtimeResourcesFolder))
SongData[] allSongs = RuntimeResourcesCache.LoadAllSongs();
if (allSongs != null)
{
var arr = Resources.LoadAll<SongData>(runtimeResourcesFolder);
if (arr != null)
foreach (var so in allSongs)
{
foreach (var so in arr)
{
if (so == null) continue;
if (so.name.StartsWith(id.ToString())) dlcContent.Add(so);
}
if (so == null) continue;
if (so.name.StartsWith(id.ToString())) dlcContent.Add(so);
}
}
if (dlcContent.Count == 0)
{
var arr2 = Resources.LoadAll<SongData>("");
if (arr2 != null)
{
foreach (var so in arr2)
{
if (so == null) continue;
if (so.name.StartsWith(id.ToString())) dlcContent.Add(so);
}
}
}
UpdateSongsAmountText();
if (VerboseLogs) Debug.Log($"dlcButton: Loaded {dlcContent.Count} SongData entries for DLC id={id} (fallback search)");
}
@@ -601,21 +616,6 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
return false;
}
private static string NormalizeResourcesPath(string path)
{
if (string.IsNullOrEmpty(path))
{
return string.Empty;
}
string p = path.Replace("\\", "/");
int idx = p.IndexOf("Resources/", System.StringComparison.OrdinalIgnoreCase);
if (idx >= 0)
{
p = p.Substring(idx + "Resources/".Length);
}
return p.Trim('/');
}
private static IEnumerator BuildCacheIfNeeded(string runtimeFolder)
{
if (cacheBuilt)
@@ -634,20 +634,11 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
cacheBuilding = true;
cachedById.Clear();
cachedAll.Clear();
cachedFolder = NormalizeResourcesPath(runtimeFolder);
// allow one frame before heavy load
yield return null;
dlcData[] arr = null;
if (!string.IsNullOrEmpty(cachedFolder))
{
arr = Resources.LoadAll<dlcData>(cachedFolder);
}
if (arr == null || arr.Length == 0)
{
arr = Resources.LoadAll<dlcData>("");
}
dlcData[] arr = RuntimeResourcesCache.LoadAllDlcs();
if (arr != null)
{