225 lines
10 KiB
C#
225 lines
10 KiB
C#
using UnityEngine;
|
||
using Logic;
|
||
using RuntimeData;
|
||
using Animancer;
|
||
using UnityEngine.UI;
|
||
using System.Collections.Generic;
|
||
using System.Net;
|
||
using Logic.Multilingual;
|
||
using TH1Resource;
|
||
using TMPro;
|
||
using Unity.VisualScripting;
|
||
|
||
namespace UI.LibraryUI
|
||
{
|
||
public class LibraryGiantUI : LibrarySubUIBase
|
||
{
|
||
public GiantType GiantSelected;
|
||
public LibraryGiantUI(LibrarySubUIType type,Button enterButton, GameObject panel,LibraryUI libraryUI) : base(type,enterButton,panel,libraryUI)
|
||
{
|
||
}
|
||
|
||
//更新listpanel的信息
|
||
protected override void UpdateListPanel()
|
||
{
|
||
var table = ListPanel.transform.Find("Scroll View/Viewport/Content");
|
||
|
||
|
||
//构造needList,需要展示的giant list
|
||
int needCount = 5;
|
||
var needList = new List<GiantType>();
|
||
needList.Add(GiantType.EgyptianRemilia);
|
||
needList.Add(GiantType.EgyptianPatchouli);
|
||
needList.Add(GiantType.EgyptianSakuya);
|
||
needList.Add(GiantType.EgyptianFlandre);
|
||
needList.Add(GiantType.EgyptianMeiling);
|
||
//根据需要展示的情况,确定table下的显示位置够不够,多的setactive false,少的clone
|
||
int hasCount = table.childCount * 3;
|
||
//如果坑位少于需要展示的数量,增加坑位
|
||
var sampleRow = table.Find("SampleRow");
|
||
while (hasCount < needCount)
|
||
{
|
||
GameObject.Instantiate(sampleRow, table);
|
||
hasCount += 3;
|
||
}
|
||
//将最后一行多出来的坑位setactive false
|
||
int lastCount = needCount;
|
||
while (lastCount < hasCount)
|
||
{
|
||
table.GetChild(lastCount / 3).GetChild(lastCount % 3).gameObject.SetActive(false);
|
||
lastCount++;
|
||
}
|
||
|
||
//总计的成就星星数量
|
||
int allStar = 0;
|
||
|
||
//设置每一个giant
|
||
for(int i = 0;i < needList.Count; i++)
|
||
{
|
||
var giant = needList[i];
|
||
if(!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, giant,0, out var unitInfo))continue;
|
||
//更换sprite
|
||
if (table.GetChild(i / 3) == null) continue;
|
||
var slot = table.GetChild( i / 3).GetChild(i % 3);
|
||
if (slot == null) continue;
|
||
slot.Find("TribeIconMask/TribeIcon").GetComponent<Image>().sprite = unitInfo.Sprite;
|
||
//如果是giantCivId !=0 默认锁角色
|
||
if (unitInfo.GiantCivId != 0) continue;
|
||
//处理remilia 阵营
|
||
slot.Find("TribeIconMask").GetComponent<Image>().color = Color.white;
|
||
slot.Find("TribeIconMask/TribeIcon").GetComponent<Image>().color = Color.white;
|
||
slot.Find("TribeIconMask/Locked").gameObject.SetActive(false);
|
||
|
||
Button slotButton = slot.GetComponent<Button>();
|
||
if (slotButton == null)
|
||
slotButton = slot.gameObject.AddComponent<Button>();
|
||
|
||
// 移除旧的监听器,防止重复添加
|
||
slotButton.onClick.RemoveAllListeners();
|
||
// 添加新的监听器,使用 lambda 表达式捕获当前的 giant 变量
|
||
Debug.Log(giant);
|
||
slotButton.onClick.AddListener(() =>
|
||
{
|
||
// 当按钮被点击时,调用 UpdateGiantInfoData 并传入对应的 GiantType
|
||
GiantListItemOnClick(slot,giant);
|
||
});
|
||
|
||
//处理成就星星的显示
|
||
uint bigid = 2;
|
||
uint smallid = giant switch
|
||
{
|
||
GiantType.EgyptianMeiling => 5,
|
||
GiantType.EgyptianFlandre => 4,
|
||
GiantType.EgyptianSakuya => 3,
|
||
GiantType.EgyptianPatchouli => 2,
|
||
_ => 1
|
||
};
|
||
for (uint k = 1; k <= 3; k++)
|
||
{
|
||
//star坑位
|
||
var star = slot.Find($"Stars/Star{k}")?.GetComponent<Image>();
|
||
bool finished = AchievementDataManager.Instance.IsFinished(2, smallid, k);
|
||
if (star != null)
|
||
star.sprite = finished ? ResourceCache.Instance.SpriteCache.AchievementStar : ResourceCache.Instance.SpriteCache.AchievementStarGray ;
|
||
if (finished) allStar++;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
//设置总成就星星数量的显示
|
||
var textUI = ListPanel.transform.Find("TitleBar/StarCount/Text")?.GetComponent<TextMeshProUGUI>();
|
||
if (textUI != null)
|
||
textUI.text = allStar.ToString() + " / " + (needCount * 3).ToString();
|
||
|
||
}
|
||
|
||
private void GiantListItemOnClick(Transform selected, GiantType giant)
|
||
{
|
||
//消除之前选中对象的红圈,换成当前这个
|
||
SelectedListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(false);
|
||
selected.Find("TribeIconMask/Selected")?.gameObject.SetActive(true);
|
||
SelectedListItem = selected;
|
||
GiantSelected = giant;
|
||
|
||
InfoPanel.GetComponent<AnimancerComponent>()?.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
||
|
||
Timer.Instance.TimerRegister(this, () =>
|
||
{
|
||
UpdateInfoPanel();
|
||
InfoPanel.GetComponent<AnimancerComponent>()?.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
||
},ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length,"LibraryGiantUI_ListItemOnClick");
|
||
}
|
||
|
||
//更新infopanel的信息
|
||
protected override void UpdateInfoPanel()
|
||
{
|
||
|
||
var giant = GiantSelected;
|
||
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, giant,0, out var unitInfo)) return;
|
||
if (!Table.Instance.LibraryDataAssets.GetLibraryInfoByGiant(giant, out var libraryInfo)) return;
|
||
if (!Table.Instance.PlayerDataAssets.GetPlayerInfoByCivId(unitInfo.GiantCivId,unitInfo.GiantForceId, out var playerInfo)) return;
|
||
var image = InfoPanel.transform.Find("GiantImage/Img");
|
||
var info = InfoPanel.transform.Find("GiantInfo");
|
||
//设置立绘
|
||
image.GetComponent<Image>().sprite = libraryInfo.Illust;
|
||
//设置英文名称装饰
|
||
if(InfoPanel.transform.Find("TitleEN"))
|
||
InfoPanel.transform.Find("TitleEN").GetComponent<TextMeshProUGUI>().text = libraryInfo.EnglishName.ToUpper();
|
||
//设置角色名称
|
||
Debug.Log(libraryInfo.Name);
|
||
MultilingualManager.Instance.SetUIText(InfoPanel.transform.Find("Title")?.GetComponent<TextMeshProUGUI>(),libraryInfo.Name);
|
||
//设置帝国名称
|
||
//设置角色介绍
|
||
MultilingualManager.Instance.SetUIText(info.Find("Info1/Desc")?.GetComponent<TextMeshProUGUI>(),libraryInfo.Desc);
|
||
//设置角色读白
|
||
MultilingualManager.Instance.SetUIText(info.Find("Info1/Diag/Text")?.GetComponent<TextMeshProUGUI>(),libraryInfo.Diag);
|
||
//设置角色读白角色头像
|
||
info.Find("Info1/Diag/AvatarCircle/Avatar").GetComponent<Image>().sprite = unitInfo.Sprite;
|
||
//设置角色读白对话框背景颜色
|
||
if(info.Find("Info1/Diag") != null)
|
||
info.Find("Info1/Diag").GetComponent<Image>().color = libraryInfo.DiagColor;
|
||
|
||
|
||
//处理成就
|
||
uint bigid = 2;
|
||
uint smallid = giant switch
|
||
{
|
||
GiantType.EgyptianMeiling => 5,
|
||
GiantType.EgyptianFlandre => 4,
|
||
GiantType.EgyptianSakuya => 3,
|
||
GiantType.EgyptianPatchouli => 2,
|
||
_ => 1
|
||
};
|
||
for (uint i = 1; i <= 3; i++)
|
||
{
|
||
//star坑位
|
||
var star = info.Find($"Info3/Star{i}/Star")?.GetComponent<Image>();
|
||
//成就标题star坑位
|
||
var title = info.Find($"Info3/Star{i}/Title")?.GetComponent<TextMeshProUGUI>();
|
||
//成就描述star坑位
|
||
var desc = info.Find($"Info3/Star{i}/Desc")?.GetComponent<TextMeshProUGUI>();
|
||
|
||
var infoData = AchievementDataManager.Instance.Achievement.GetAchievementItem(bigid, smallid, i);
|
||
bool finished = AchievementDataManager.Instance.IsFinished(bigid, smallid, i);
|
||
if (infoData == null) continue;
|
||
MultilingualManager.Instance.SetUIText(title,infoData.Name);
|
||
MultilingualManager.Instance.SetUIText(desc,infoData.Desc);
|
||
if(title != null)
|
||
title.color = finished ? Table.Instance.ColorDataAssets.CommonUITextColor : Table.Instance.ColorDataAssets.CommonUITextColorGray ;
|
||
if(desc != null)
|
||
desc.color = finished ? Table.Instance.ColorDataAssets.CommonUITextColor : Table.Instance.ColorDataAssets.CommonUITextColorGray ;
|
||
if (star != null)
|
||
star.sprite = finished ? ResourceCache.Instance.SpriteCache.AchievementStar : ResourceCache.Instance.SpriteCache.AchievementStarGray ;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
//SwitchTo
|
||
public override void Show()
|
||
{
|
||
UpdateListPanel();
|
||
SetDefaultItem();
|
||
UpdateInfoPanel();
|
||
OpenPanel();
|
||
}
|
||
|
||
public override void Hide()
|
||
{
|
||
ClosePanel();
|
||
}
|
||
|
||
//每个subpanel都有一个初始化函数,如果切换到这个页面,要进行一次初始化选择(默认选择左上角的单位)
|
||
protected override void SetDefaultItem()
|
||
{
|
||
if (ListTable == null) return;
|
||
DefaultListItem = ListTable.transform.GetChild(0).GetChild(0);
|
||
SelectedListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(false);
|
||
DefaultListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(true);
|
||
SelectedListItem = DefaultListItem;
|
||
GiantSelected = GiantType.EgyptianRemilia;
|
||
}
|
||
|
||
}
|
||
} |