重做粗略选曲界面 浮动小游戏可开关
修复一些小bug和加入部分新功能
This commit is contained in:
@@ -1,36 +1,134 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SongButton : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI songNameText; // 歌曲名称文本
|
||||
public TextMeshProUGUI highestScoreText; // 个人最高分文本
|
||||
public TextMeshProUGUI difficultyIDText; // 难度ID文本
|
||||
public TextMeshProUGUI songIDText;
|
||||
public Image buttonImage; // 按钮的 Image 组件,用于设置背景图像
|
||||
public int song_songSerialID; // 按钮对应的歌曲ID
|
||||
|
||||
// 设置按钮的数据
|
||||
[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);
|
||||
songNameText.text = songName;
|
||||
highestScoreText.text = "PR: " + highestScore.ToString();
|
||||
difficultyIDText.text = "" + difficultyID.ToString();
|
||||
buttonImage.sprite = songSprite;
|
||||
song_songSerialID = songID;
|
||||
songIDText.text = "Song ID: " + song_songSerialID.ToString();
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 按钮点击事件:根据 song_songSerialID 查找对应的 SongData,并传递到下个场景
|
||||
public void OnSongButtonClick()
|
||||
{
|
||||
Debug.Log("点击按钮的 song_songSerialID: " + song_songSerialID);
|
||||
@@ -45,5 +143,4 @@ public class SongButton : MonoBehaviour
|
||||
Debug.LogError("未找到对应的 SongData, songID: " + song_songSerialID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user