80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System;
|
||
using Logic.Multilingual;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1_UI.View.Outside
|
||
{
|
||
/// <summary>
|
||
/// 音乐鉴赏室列表项,显示曲名+点击播放
|
||
/// </summary>
|
||
public class UIOutsideLibraryMusicItemMono : MonoBehaviour
|
||
{
|
||
public Button Button;
|
||
public TextMeshProUGUI Name;
|
||
|
||
[Header("选中态:同一张Image,在两张Sprite之间切换")]
|
||
public Image BackgroundImage;
|
||
public Sprite NormalSprite;
|
||
public Sprite SelectedSprite;
|
||
|
||
// 猜歌模式占位文字
|
||
private const string GuessPlaceholder = "?????";
|
||
|
||
private string _musicName;
|
||
private string _realTitleId; // 真实曲名(多语言ID),猜歌模式退出后恢复用
|
||
|
||
public string MusicName => _musicName;
|
||
|
||
public void SetContent(MusicInfo info, Action<string> onClick)
|
||
{
|
||
if (info == null) return;
|
||
_musicName = info.MusicName;
|
||
_realTitleId = info.Title;
|
||
|
||
// 默认按真实曲名显示(SetGuessMode 会覆盖)
|
||
ApplyDisplayedName(false);
|
||
|
||
SetSelected(false);
|
||
|
||
if (Button != null)
|
||
{
|
||
var captureName = info.MusicName;
|
||
Button.onClick.RemoveAllListeners();
|
||
Button.onClick.AddListener(() => onClick?.Invoke(captureName));
|
||
}
|
||
}
|
||
|
||
public void SetSelected(bool selected)
|
||
{
|
||
if (BackgroundImage == null) return;
|
||
var target = selected ? SelectedSprite : NormalSprite;
|
||
if (target != null) BackgroundImage.sprite = target;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换猜歌模式:true时Name显示?????,false时显示真实Title
|
||
/// </summary>
|
||
public void SetGuessMode(bool guess)
|
||
{
|
||
ApplyDisplayedName(guess);
|
||
}
|
||
|
||
private void ApplyDisplayedName(bool guess)
|
||
{
|
||
if (Name == null) return;
|
||
if (guess)
|
||
{
|
||
Name.text = GuessPlaceholder;
|
||
return;
|
||
}
|
||
// 还原真实曲名:多语言ID走SetUIText,无ID直接显示MusicName
|
||
if (!string.IsNullOrEmpty(_realTitleId))
|
||
MultilingualManager.Instance.SetUIText(Name, _realTitleId);
|
||
else
|
||
Name.text = _musicName;
|
||
}
|
||
}
|
||
}
|