some updates
This commit is contained in:
@@ -152,50 +152,7 @@ public class SongButton : MonoBehaviour
|
||||
songOverallDescriptionText.text = string.IsNullOrEmpty(sd.thisLevel_overallDescription) ? "" : sd.thisLevel_overallDescription;
|
||||
}
|
||||
|
||||
sd.GetAbsoluteHighestScore(out int bestTotal, out int bestDiff, out string bestDiffName);
|
||||
|
||||
if (bestTotal < 0) bestTotal = 0;
|
||||
|
||||
if (highestScoreText != null) highestScoreText.text = bestTotal.ToString();
|
||||
|
||||
if (highestScoreDifficultyText != null)
|
||||
highestScoreDifficultyText.text = string.IsNullOrEmpty(bestDiffName) ? "" : "(" + bestDiffName + ")";
|
||||
|
||||
if (scoreLevelImage != null)
|
||||
{
|
||||
if (rankConfig != null)
|
||||
{
|
||||
scoreLevelImage.sprite = rankConfig.GetRankSprite(bestTotal);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("SongButton: rankConfig is not assigned!");
|
||||
}
|
||||
}
|
||||
|
||||
// Determine displayed difficulty: show the highest difficultyLEVEL present in chartFiles (if any)
|
||||
string diffDisplay = "0";
|
||||
if (sd.chartFiles != null && sd.chartFiles.Count > 0)
|
||||
{
|
||||
float maxLevel = float.MinValue;
|
||||
foreach (var entry in sd.chartFiles)
|
||||
{
|
||||
if (entry == null) continue;
|
||||
if (entry.difficultyLEVEL > maxLevel)
|
||||
{
|
||||
maxLevel = entry.difficultyLEVEL;
|
||||
}
|
||||
}
|
||||
if (maxLevel != float.MinValue)
|
||||
{
|
||||
diffDisplay = maxLevel.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (difficultyIDText != null) difficultyIDText.text = diffDisplay;
|
||||
|
||||
// Set rank images for the first three difficulties
|
||||
SetDifficultyRankImages(sd);
|
||||
RefreshCurrentDifficultyDisplay(sd, difficultyID);
|
||||
|
||||
if (buttonImage != null) buttonImage.sprite = resolvedIllustration != null ? resolvedIllustration : songSprite;
|
||||
|
||||
@@ -227,34 +184,166 @@ public class SongButton : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDifficultyRankImages(SongData sd)
|
||||
public void RefreshCurrentDifficultyDisplay()
|
||||
{
|
||||
if (rankConfig == null) return;
|
||||
SongData sd = null;
|
||||
if (SongDataLibrary.Instance != null && SongDataLibrary.Instance.IsLoaded)
|
||||
{
|
||||
sd = SongDataLibrary.Instance.GetSongDataByID(song_songSerialID);
|
||||
}
|
||||
if (sd == null)
|
||||
{
|
||||
sd = thisSong_so as SongData;
|
||||
}
|
||||
|
||||
RefreshCurrentDifficultyDisplay(sd, 0);
|
||||
}
|
||||
|
||||
public static void RefreshAllButtonsForCurrentDifficulty()
|
||||
{
|
||||
SongButton[] buttons = UnityEngine.Object.FindObjectsByType<SongButton>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
if (buttons[i] == null) continue;
|
||||
buttons[i].RefreshCurrentDifficultyDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshCurrentDifficultyDisplay(SongData sd, int fallbackDifficulty)
|
||||
{
|
||||
if (sd == null)
|
||||
{
|
||||
if (highestScoreText != null) highestScoreText.text = "0";
|
||||
if (highestScoreDifficultyText != null) highestScoreDifficultyText.text = "";
|
||||
if (difficultyIDText != null) difficultyIDText.text = fallbackDifficulty.ToString();
|
||||
ApplyScoreRankSprite(0);
|
||||
ClearDifficultyRankImages();
|
||||
return;
|
||||
}
|
||||
|
||||
sd.EnsurePersistentDataLoaded();
|
||||
int currentDifficulty = ResolveCurrentDisplayDifficulty(sd, fallbackDifficulty);
|
||||
ChartFileEntry entry = FindChartEntry(sd, currentDifficulty);
|
||||
|
||||
float difficultyLevel = entry != null ? entry.difficultyLEVEL : currentDifficulty;
|
||||
int totalForDifficulty = GetTotalRecordForDifficulty(sd, currentDifficulty, entry);
|
||||
string difficultyName = GetDifficultyCode(currentDifficulty);
|
||||
|
||||
if (highestScoreText != null) highestScoreText.text = totalForDifficulty.ToString();
|
||||
if (highestScoreDifficultyText != null) highestScoreDifficultyText.text = "(" + difficultyName + ")";
|
||||
if (difficultyIDText != null)
|
||||
{
|
||||
string difficultyLevelText = difficultyLevel.ToString("0.#");
|
||||
difficultyIDText.text = string.IsNullOrEmpty(difficultyName)
|
||||
? difficultyLevelText
|
||||
: difficultyLevelText + " (" + difficultyName + ")";
|
||||
}
|
||||
|
||||
ApplyScoreRankSprite(totalForDifficulty);
|
||||
ClearDifficultyRankImages();
|
||||
}
|
||||
|
||||
private int ResolveCurrentDisplayDifficulty(SongData sd, int fallbackDifficulty)
|
||||
{
|
||||
if (sd == null)
|
||||
{
|
||||
return Mathf.Clamp(fallbackDifficulty, 0, 3);
|
||||
}
|
||||
|
||||
int difficulty = Mathf.Clamp(sd.thisLevel_selectedDifficultyID, 0, 3);
|
||||
string difficultyKey = BuildSongSelectedDifficultyPrefsKey(sd.songID);
|
||||
if (PlayerPrefs.HasKey(difficultyKey))
|
||||
{
|
||||
difficulty = Mathf.Clamp(PlayerPrefs.GetInt(difficultyKey, difficulty), 0, 3);
|
||||
}
|
||||
|
||||
if (FindChartEntry(sd, difficulty) != null || sd.GetResolvedChartFile(difficulty) != null)
|
||||
{
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
int fallback = Mathf.Clamp(fallbackDifficulty, 0, 3);
|
||||
if (FindChartEntry(sd, fallback) != null || sd.GetResolvedChartFile(fallback) != null)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return GetFirstAvailableDifficulty(sd);
|
||||
}
|
||||
|
||||
private string GetDifficultyCode(int difficulty)
|
||||
{
|
||||
switch (difficulty)
|
||||
{
|
||||
case 0: return "EZ";
|
||||
case 1: return "HD";
|
||||
case 2: return "IN";
|
||||
case 3: return "IM";
|
||||
default: return difficulty.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private ChartFileEntry FindChartEntry(SongData sd, int difficulty)
|
||||
{
|
||||
if (sd == null || sd.chartFiles == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sd.chartFiles.Count; i++)
|
||||
{
|
||||
ChartFileEntry entry = sd.chartFiles[i];
|
||||
if (entry != null && entry.difficulty == difficulty)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int GetTotalRecordForDifficulty(SongData sd, int difficulty, ChartFileEntry entry)
|
||||
{
|
||||
int total = entry != null ? entry.totalPersonalRecordForThisDifficulty : 0;
|
||||
if (total <= 0 && entry != null)
|
||||
{
|
||||
total = entry.chartPersonalRecordForThisDifficulty + entry.idolPersonalRecordForThisDifficulty;
|
||||
}
|
||||
|
||||
if (total <= 0 && sd != null)
|
||||
{
|
||||
total = sd.GetPersonalRecord(difficulty) + sd.GetIdolRecord(difficulty);
|
||||
}
|
||||
|
||||
return Mathf.Max(0, total);
|
||||
}
|
||||
|
||||
private void ApplyScoreRankSprite(int score)
|
||||
{
|
||||
if (scoreLevelImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rankConfig != null)
|
||||
{
|
||||
scoreLevelImage.sprite = rankConfig.GetRankSprite(score);
|
||||
scoreLevelImage.enabled = scoreLevelImage.sprite != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
scoreLevelImage.enabled = false;
|
||||
Debug.LogWarning("SongButton: rankConfig is not assigned!");
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearDifficultyRankImages()
|
||||
{
|
||||
Image[] rankImages = { lvl_img_01, lvl_img_02, lvl_img_03 };
|
||||
|
||||
for (int i = 0; i < rankImages.Length; i++)
|
||||
{
|
||||
if (rankImages[i] == null) continue;
|
||||
|
||||
if (sd.chartFiles != null && i < sd.chartFiles.Count)
|
||||
{
|
||||
var entry = sd.chartFiles[i];
|
||||
if (entry != null)
|
||||
{
|
||||
int score = entry.totalPersonalRecordForThisDifficulty;
|
||||
rankImages[i].sprite = rankConfig.GetRankSprite(score);
|
||||
rankImages[i].enabled = rankImages[i].sprite != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
rankImages[i].enabled = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rankImages[i].enabled = false;
|
||||
}
|
||||
rankImages[i].enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,6 +371,7 @@ public class SongButton : MonoBehaviour
|
||||
FadeInSelectedBorder();
|
||||
|
||||
SongDataHolder.SelectedSongData = selectedSong;
|
||||
RefreshCurrentDifficultyDisplay(selectedSong, selectedSong.thisLevel_selectedDifficultyID);
|
||||
var selectedInfo = SceneObjectLookupCache.FindAny<selected_songInfo>();
|
||||
if (selectedInfo != null)
|
||||
{
|
||||
@@ -313,6 +403,12 @@ public class SongButton : MonoBehaviour
|
||||
}
|
||||
|
||||
int songId = selectedSong.songID;
|
||||
int globalDifficulty = SongSelectUI.GetSelectedDifficulty();
|
||||
if (IsDifficultyAvailable(selectedSong, globalDifficulty))
|
||||
{
|
||||
return globalDifficulty;
|
||||
}
|
||||
|
||||
string difficultyKey = BuildSongSelectedDifficultyPrefsKey(songId);
|
||||
if (PlayerPrefs.HasKey(difficultyKey))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user