Files
bansonic_beta_main/Assets/songsDatabase/SongDataController/SongButton.cs
T
FloatGaming e7f4ac72d5 重做粗略选曲界面 浮动小游戏可开关
修复一些小bug和加入部分新功能
2025-12-30 03:26:39 +08:00

147 lines
5.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SongButton : MonoBehaviour
{
[Header("thisSong_so")]
public ScriptableObject thisSong_so;
[Header("展示的信息")]
public Text songNameText;
public Text multiNameText;
public Text joinTime_and_dlcName_Text;
public Text songOverallDescriptionText;
public Text highestScoreText;
public Text difficultyIDText;
public Text songIDText;
public Image buttonImage;
[Header("头图")]
public Image profileImage;
public int song_songSerialID;
public void Start()
{
}
public void SetButtonData(string songName, int highestScore, int difficultyID, Sprite songSprite, int songID)
{
Debug.Log("SetButtonData 被调用, songID 参数: " + songID);
// try to load SongData by id and populate fields from SO when available
var sd = SongDataLibrary.Instance != null ? SongDataLibrary.Instance.GetSongDataByID(songID) : null;
if (sd != null)
{
// song name
if (songNameText != null) songNameText.text = sd.songName;
// multi name text: 音乐:artist | 曲绘:painter | 制谱:level_creator
if (multiNameText != null)
multiNameText.text = "音乐:" + sd.artistName + " | 曲绘:" + sd.painter + " | 制谱:" + sd.level_creator;
// song join time and DLC
if (joinTime_and_dlcName_Text != null)
{
string join = string.IsNullOrEmpty(sd.thisLevel_addDateString) ? "未知" : sd.thisLevel_addDateString;
string dlc = string.IsNullOrEmpty(sd.belongsTo_whichDLC) ? "未归档DLC" : sd.belongsTo_whichDLC;
joinTime_and_dlcName_Text.text = "歌曲收录时间:" + join + " | " + "所属DLC" + dlc;
}
// song overall description
if (songOverallDescriptionText != null)
{
songOverallDescriptionText.text = string.IsNullOrEmpty(sd.thisLevel_overallDescription) ? "暂无歌曲简介。" : sd.thisLevel_overallDescription;
}
// compute highest total (chart personal + idol) and its difficulty
int bestTotal = 0;
int bestDiff = -1;
if (sd.personalRecordMap != null)
{
foreach (var kvp in sd.personalRecordMap)
{
int diff = kvp.Key;
int p = kvp.Value;
int i = sd.GetIdolRecord(diff);
int combined = p + i;
if (combined > bestTotal)
{
bestTotal = combined;
bestDiff = diff;
}
}
}
// fallback: use stored personalRecord and selected difficulty if maps empty
if (bestDiff == -1)
{
bestTotal = sd.personalRecord;
bestDiff = sd.thisLevel_selectedDifficultyID;
}
if (highestScoreText != null) highestScoreText.text = bestTotal.ToString();
// difficultyIDText: show difficultyLEVEL from ChartFileEntry of bestDiff if available, else show numeric id
string diffDisplay = bestDiff.ToString();
if (sd.chartFiles != null)
{
foreach (var entry in sd.chartFiles)
{
if (entry != null && entry.difficulty == bestDiff)
{
diffDisplay = entry.difficultyLEVEL.ToString();
break;
}
}
}
if (difficultyIDText != null) difficultyIDText.text = diffDisplay;
// button image
if (buttonImage != null) buttonImage.sprite = sd.backgroudPIC;
// profile image: use card_profileImage from SO
if (profileImage != null)
{
profileImage.sprite = sd.card_profileImage;
if (sd.card_profileImage != null)
{
profileImage.color = new Color(profileImage.color.r, profileImage.color.g, profileImage.color.b, 1f);
profileImage.enabled = true;
}
else
{
// hide if no sprite
profileImage.enabled = false;
}
}
song_songSerialID = songID;
if (songIDText != null) songIDText.text = "数据库索引号:" + song_songSerialID.ToString();
}
else
{
// fallback to original behavior if SO not found
if (songNameText != null) songNameText.text = songName;
if (highestScoreText != null) highestScoreText.text = "PR: " + highestScore.ToString();
if (difficultyIDText != null) difficultyIDText.text = difficultyID.ToString();
if (buttonImage != null) buttonImage.sprite = songSprite;
song_songSerialID = songID;
if (songIDText != null) songIDText.text = "Song ID: " + song_songSerialID.ToString();
}
}
public void OnSongButtonClick()
{
Debug.Log("点击按钮的 song_songSerialID: " + song_songSerialID);
SongData selectedSong = SongDataLibrary.Instance.GetSongDataByID(song_songSerialID);
if (selectedSong != null)
{
SongDataHolder.SelectedSongData = selectedSong;
SceneManager.LoadScene("Songs_Select");
}
else
{
Debug.LogError("未找到对应的 SongData, songID: " + song_songSerialID);
}
}
}