Files
2026-05-26 16:15:54 +08:00

86 lines
2.3 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class GradeMapItem : MonoBehaviour
{
public Button button;
[SerializeField]
GameObject go_lock,
pts,
redpoints;
[SerializeField]
Image img_bg;
[SerializeField]
TMP_Text
txt_levelRequired,
txt_mapName,
text_pts;
public MapData mapData;
Action<GradeMapItem> _action;
int allPTS;
bool isLock;
private void Start()
{
button.onClick.AddListener(OnClick);
}
public void SetData(MapData mapData, int requiredLevel, Action<GradeMapItem> action)
{
_action = action;
this.mapData = mapData;
gameObject.SetActive(true);
txt_mapName.text = LocalizationMgr.GetText(mapData.Name_l10n_key);
allPTS = GContext.container.Resolve<PlayerFishData>().GetAllPTSByMap(mapData.ID);
GContext.container.Resolve<IUIService>().SetImageSprite(img_bg, mapData.Bg);
isLock = GContext.container.Resolve<PlayerData>().lv < requiredLevel;
if (isLock)
{
redpoints.SetActive(false);
go_lock.SetActive(true);
pts.SetActive(false);
txt_levelRequired.text = requiredLevel.ToString();
}
else
{
text_pts.text = allPTS.ToString();
go_lock.SetActive(false);
pts.SetActive(true);
Refresh();
}
}
//刷新
public void Refresh()
{
int progress = GContext.container.Resolve<PlayerFishData>().GetMapProgress(mapData.ID);
var pointsRequire = mapData.PointsRequire;
if (progress >= pointsRequire.Count)
{
redpoints.SetActive(false);
}
else
{
redpoints.SetActive(allPTS >= pointsRequire[progress]);
}
}
void OnClick()
{
if (isLock)
{
var mapdata = GContext.container.Resolve<Tables>().TbMapData.GetOrDefault(mapData.ID - 1);
if (mapdata != null)
{
ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_ToastPanel_4", mapdata.LevelRequired));
}
}
else
{
_action?.Invoke(this);
}
}
}