UI update 02
This commit is contained in:
@@ -7,6 +7,8 @@ public class loadDlcListPrefab : MonoBehaviour
|
||||
{
|
||||
private static readonly bool VerboseLogs = false;
|
||||
private const string RuntimeInstalledColumnName = "Installed DLC";
|
||||
private const int DefaultFallbackDlcId = 66001;
|
||||
private const string DlcSelectedIndexPrefsKey = "dlc_selected_index";
|
||||
[System.Serializable]
|
||||
public class Column
|
||||
{
|
||||
@@ -35,6 +37,8 @@ public class loadDlcListPrefab : MonoBehaviour
|
||||
{
|
||||
if (dlc_scContent == null) return;
|
||||
|
||||
dlcButton.ResetSelectionState();
|
||||
|
||||
for (int i = dlc_scContent.transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var c = dlc_scContent.transform.GetChild(i).gameObject;
|
||||
@@ -89,16 +93,7 @@ public class loadDlcListPrefab : MonoBehaviour
|
||||
{
|
||||
if (dlc != null)
|
||||
{
|
||||
if (btn.dlc_profileImgae != null)
|
||||
{
|
||||
btn.dlc_profileImgae.sprite = dlc.dlc_image;
|
||||
btn.dlc_profileImgae.enabled = dlc.dlc_image != null;
|
||||
}
|
||||
if (btn.dlcName != null) btn.dlcName.text = dlc.dlcName ?? "(Unnamed)";
|
||||
if (btn.dlcID != null) btn.dlcID.text = dlc.dlcID.ToString();
|
||||
if (btn.dlcProducer != null) btn.dlcProducer.text = dlc.dlcProducer ?? "";
|
||||
if (btn.dlcPubliushDate != null) btn.dlcPubliushDate.text = dlc.dlcPublishDate ?? "";
|
||||
if (btn.dlcDescription != null) btn.dlcDescription.text = dlc.dlcDescription ?? "";
|
||||
btn.SetDlcData(dlc);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,6 +101,7 @@ public class loadDlcListPrefab : MonoBehaviour
|
||||
if (btn.dlcID != null) btn.dlcID.text = "";
|
||||
if (btn.dlc_profileImgae != null) btn.dlc_profileImgae.enabled = false;
|
||||
if (btn.dlcDescription != null) btn.dlcDescription.text = "";
|
||||
if (btn.dlcSongsAmount != null) btn.dlcSongsAmount.text = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,29 +131,135 @@ public class loadDlcListPrefab : MonoBehaviour
|
||||
// Let layout and any fades settle for a frame
|
||||
yield return null;
|
||||
|
||||
// Restore last selected DLC button from PlayerPrefs and simulate a click on it
|
||||
int savedIndex = PlayerPrefs.GetInt("dlc_selected_index", 0);
|
||||
if (allButtons != null && allButtons.Length > 0)
|
||||
{
|
||||
if (savedIndex < 0) savedIndex = 0;
|
||||
if (savedIndex >= allButtons.Length) savedIndex = 0;
|
||||
|
||||
var savedBtn = allButtons[savedIndex];
|
||||
if (savedBtn != null)
|
||||
{
|
||||
// simulate a user clicking the button: this will Select() and display its songs
|
||||
savedBtn.OnButtonClicked_ShowSongs();
|
||||
if (VerboseLogs) Debug.Log($"loadDlcListPrefab: restored and clicked saved dlc button index={savedIndex} name={savedBtn.gameObject.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (VerboseLogs) Debug.LogWarning($"loadDlcListPrefab: saved dlc button at index {savedIndex} was null");
|
||||
}
|
||||
}
|
||||
else
|
||||
if (allButtons == null || allButtons.Length == 0)
|
||||
{
|
||||
if (VerboseLogs) Debug.LogWarning("loadDlcListPrefab: no dlc buttons found after RefreshUI");
|
||||
yield break;
|
||||
}
|
||||
|
||||
dlcButton targetButton = ResolvePreferredRestoreButton(allButtons, out bool forceFirstSong);
|
||||
if (targetButton == null)
|
||||
{
|
||||
targetButton = allButtons[0];
|
||||
forceFirstSong = true;
|
||||
}
|
||||
|
||||
SongSelectUI.ForceFirstSongOnNextRestore = forceFirstSong;
|
||||
targetButton.OnButtonClicked_ShowSongs();
|
||||
|
||||
if (VerboseLogs)
|
||||
{
|
||||
Debug.Log(
|
||||
$"loadDlcListPrefab: restored dlc button '{targetButton.gameObject.name}', " +
|
||||
$"dlcId={GetDlcId(targetButton)}, forceFirstSong={forceFirstSong}");
|
||||
}
|
||||
}
|
||||
|
||||
private dlcButton ResolvePreferredRestoreButton(dlcButton[] allButtons, out bool forceFirstSong)
|
||||
{
|
||||
forceFirstSong = true;
|
||||
|
||||
if (allButtons == null || allButtons.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int savedIndex = PlayerPrefs.GetInt(DlcSelectedIndexPrefsKey, 0);
|
||||
if (savedIndex >= 0 && savedIndex < allButtons.Length)
|
||||
{
|
||||
dlcButton savedButton = allButtons[savedIndex];
|
||||
if (HasSavedSongSelection(savedButton))
|
||||
{
|
||||
forceFirstSong = false;
|
||||
return savedButton;
|
||||
}
|
||||
}
|
||||
|
||||
dlcButton fallbackById = FindButtonByDlcId(allButtons, DefaultFallbackDlcId);
|
||||
if (fallbackById != null)
|
||||
{
|
||||
return fallbackById;
|
||||
}
|
||||
|
||||
return allButtons[0];
|
||||
}
|
||||
|
||||
private dlcButton FindButtonByDlcId(dlcButton[] allButtons, int dlcId)
|
||||
{
|
||||
if (allButtons == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < allButtons.Length; i++)
|
||||
{
|
||||
dlcButton button = allButtons[i];
|
||||
if (button == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (GetDlcId(button) == dlcId)
|
||||
{
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool HasSavedSongSelection(dlcButton button)
|
||||
{
|
||||
if (button == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string dlcKey = BuildDlcKey(button);
|
||||
if (string.IsNullOrEmpty(dlcKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string songIdKey = SongButton.BuildSongSelectedIdPrefsKey(dlcKey);
|
||||
if (PlayerPrefs.HasKey(songIdKey) && PlayerPrefs.GetInt(songIdKey, 0) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string songIndexKey = SongButton.BuildSongSelectedIndexPrefsKey(dlcKey);
|
||||
return PlayerPrefs.HasKey(songIndexKey);
|
||||
}
|
||||
|
||||
private string BuildDlcKey(dlcButton button)
|
||||
{
|
||||
int dlcId = GetDlcId(button);
|
||||
if (dlcId > 0)
|
||||
{
|
||||
return "dlc_" + dlcId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int GetDlcId(dlcButton button)
|
||||
{
|
||||
if (button == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (button.dlcDataSO != null && button.dlcDataSO.dlcID > 0)
|
||||
{
|
||||
return button.dlcDataSO.dlcID;
|
||||
}
|
||||
|
||||
if (button.dlcID != null && int.TryParse(button.dlcID.text, out int parsedId))
|
||||
{
|
||||
return parsedId;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private List<Column> BuildDisplayColumns()
|
||||
|
||||
Reference in New Issue
Block a user