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

88 lines
3.0 KiB
C#

using asap.core;
using GameCore;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class BarItemTips : MonoBehaviour
{
public RectTransform content;
public GameObject arrow;
public GameObject rewardEmptyGo1, rewardEmptyGo2;
public GameObject[] rewardGos;
public RewardItemNew[] rewards;
public TMP_Text textTarget, textOwned;
public Button btnClose;
public Image require_icon;
private void Start()
{
btnClose.onClick.AddListener(() => gameObject.SetActive(false));
}
public void Init(ItemData itemData, string icon, int targetScore, int score)
{
GContext.container.Resolve<IUIService>().SetImageSprite(require_icon, icon);
rewardEmptyGo1.SetActive(true);
rewardEmptyGo2.SetActive(true);
rewardGos[0].SetActive(true);
for (int i = 1; i < rewardGos.Length; i++)
{
rewardGos[i].SetActive(false);
}
rewards[0].SetData(itemData);
if (textOwned != null)
{
textOwned.text = LocalizationMgr.GetFormatTextValue("UI_item_tips_1", score);
}
textTarget.text = LocalizationMgr.GetFormatTextValue("UI_EventRankPopupPanel_18", targetScore);
}
public void Init(List<ItemData> items, string icon, int targetScore, int score)
{
GContext.container.Resolve<IUIService>().SetImageSprite(require_icon, icon);
if (items.Count == 1)
{
rewardEmptyGo1.SetActive(true);
rewardEmptyGo2.SetActive(true);
rewardGos[0].SetActive(true);
for (int i = 1; i < rewardGos.Length; i++)
{
rewardGos[i].SetActive(false);
}
rewards[0].SetData(items[0]);
}
else if (items.Count > 1)
{
rewardEmptyGo1.SetActive(false);
rewardEmptyGo2.SetActive(false);
for (int i = 0; i < rewardGos.Length; i++)
{
rewardGos[i].SetActive(i < items.Count);
if (i < items.Count)
rewards[i].SetData(items[i]);
}
}
textOwned.text = LocalizationMgr.GetFormatTextValue("UI_item_tips_1", score);
textTarget.text = LocalizationMgr.GetFormatTextValue("UI_EventRankPopupPanel_16", targetScore);
}
public void SetContent(Vector3 pos)
{
content.position = pos;
RectTransform rectTransform = transform.GetComponent<RectTransform>();
float limit = (rectTransform.rect.width - content.rect.width - 80) / 2;
//边界检测
var localPosition = content.transform.localPosition;
localPosition.x = 0;
if (localPosition.x > limit)
{
localPosition.x = limit;
}
else if (localPosition.x < -limit)
{
localPosition.x = -limit;
}
arrow.transform.position = new Vector3(pos.x, arrow.transform.position.y);
content.transform.localPosition = localPosition;
}
}