Files
back_cantanBuilding/Assets/Scripts/UI/Albun/PictureAttribute.cs
2026-05-26 16:15:54 +08:00

108 lines
3.0 KiB
C#

using System.Collections.Generic;
using asap.core;
using cfg;
using GameCore;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PictureAttribute : MonoBehaviour
{
string[] sp_bg_card_string =
{
"sp_album_card_bg_white",
"sp_album_card_bg_blue",
"sp_album_card_bg_purple",
"sp_album_card_bg_yellow",
"sp_album_card_bg_yellow"
};
[HideInInspector]
public Image img_card;
Image sp_bg_card;
Image bg_title;
public TMP_Text[] text_names;
List<GameObject> starList = new List<GameObject>();
[HideInInspector]
public TMP_Text text_num;
public Picture data;
[HideInInspector]
public GameObject newTag;
bool isShow;
bool newState;
private void Awake()
{
InitPanel();
if (isShow)
{
Show();
}
isShow = true;
}
void InitPanel()
{
img_card = transform.Find("img_card").GetComponent<Image>();
sp_bg_card = transform.Find("sp_bg_card").GetComponent<Image>();
bg_title = transform.Find("bg_title").GetComponent<Image>();
newTag = transform.Find("new")?.gameObject;
text_num = transform.Find("extra_card/text_extra_card").GetComponent<TMP_Text>();
Transform star = transform.Find("star");
int count = star.childCount;
for (int i = 0; i < count; i++)
{
starList.Add(star.GetChild(i).gameObject);
}
}
public void Init(Picture _data)
{
data = _data;
if (isShow)
{
Show();
}
isShow = true;
}
public void SetNewState(bool newState)
{
this.newState = newState;
if (newTag != null)
{
newTag.SetActive(newState);
}
}
void Show()
{
if (newTag != null)
{
newTag.SetActive(newState);
}
GContext.container.Resolve<IUIService>().SetImageSprite(sp_bg_card, sp_bg_card_string[data.Quality - 1], BasePanel.PanelName);
GContext.container.Resolve<IUIService>().SetImageSprite(bg_title, AlbumAttribute.sp_album_card_title[data.Quality - 1], BasePanel.PanelName);
GContext.container.Resolve<IUIService>().SetImageSprite(img_card, data.Image, BasePanel.PanelName);
for (int i = 0; i < text_names.Length; i++)
{
text_names[i].gameObject.SetActive(i == data.Quality - 1);
if (data.Quality - 1 == i)
{
text_names[i].text = LocalizationMgr.GetText(data.Title_l10n_key);
}
}
if (data.Quality > text_names.Length)
{
text_names[^1].text = LocalizationMgr.GetText(data.Title_l10n_key);
text_names[^1].gameObject.SetActive(true);
}
for (int i = 0; i < starList.Count; i++)
{
starList[i].SetActive(i == data.Quality - 1);
}
if (data.Quality > starList.Count)
{
starList[^1].gameObject.SetActive(true);
}
}
}