完成了libriryUI的结构迭代
This commit is contained in:
parent
9899cbfe8c
commit
5b770b7386
@ -301,7 +301,7 @@ GameObject:
|
||||
- component: {fileID: 9161833284301621424}
|
||||
- component: {fileID: 5913617355368473729}
|
||||
m_Layer: 5
|
||||
m_Name: StarImg
|
||||
m_Name: Star1
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -376,7 +376,7 @@ GameObject:
|
||||
- component: {fileID: 1119575788612082855}
|
||||
- component: {fileID: 1712236966958661298}
|
||||
m_Layer: 5
|
||||
m_Name: StarImg (4)
|
||||
m_Name: Star3
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -666,7 +666,7 @@ GameObject:
|
||||
- component: {fileID: 6221544809802481683}
|
||||
- component: {fileID: 2676771624809184846}
|
||||
m_Layer: 5
|
||||
m_Name: StarImg (1)
|
||||
m_Name: Star2
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
||||
@ -122809,7 +122809,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 949176087}
|
||||
m_Layer: 5
|
||||
m_Name: WonderListPanel
|
||||
m_Name: ListPanel
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -166282,7 +166282,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &1267340850
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -166601,7 +166601,7 @@ GameObject:
|
||||
- component: {fileID: 1269548255}
|
||||
- component: {fileID: 1269548254}
|
||||
m_Layer: 5
|
||||
m_Name: LibraryGiantInfoPanel
|
||||
m_Name: InfoPanel
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -179541,7 +179541,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 1378116948}
|
||||
m_Layer: 5
|
||||
m_Name: WonderInfoPanel
|
||||
m_Name: InfoPanel
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -227773,7 +227773,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 1759379789}
|
||||
m_Layer: 5
|
||||
m_Name: LibraryGiantListPanel
|
||||
m_Name: ListPanel
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
||||
@ -6,7 +6,7 @@ using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using RuntimeData;
|
||||
using UnityEngine.AI;
|
||||
|
||||
using UI.LibraryUI;
|
||||
public class GameUI
|
||||
{
|
||||
private Main _main;
|
||||
|
||||
@ -1,372 +0,0 @@
|
||||
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 YooAsset.Editor;
|
||||
|
||||
public enum LibraryTabType
|
||||
{
|
||||
Force,
|
||||
Giant,
|
||||
Wonder,
|
||||
Achievement
|
||||
}
|
||||
|
||||
public class LibraryUI
|
||||
{
|
||||
private Main _main;
|
||||
private MapData _mapData;
|
||||
public GameObject ROLibraryUI;
|
||||
|
||||
public bool NeedShow = false;
|
||||
|
||||
private bool _isShowing = false;
|
||||
private bool _isAnimating = false;
|
||||
private float _fadeDuration = 0.2f;
|
||||
|
||||
public Button ForceButton;
|
||||
public Button GiantButton;
|
||||
public Button WonderButton;
|
||||
public Button AchievementButton;
|
||||
|
||||
public Transform SelectedGiantListItem;
|
||||
public Transform DefaultGiantListItem;
|
||||
|
||||
private class LibraryTab
|
||||
{
|
||||
public LibraryTabType Type;
|
||||
public GameObject Panel;
|
||||
public string FadeInClipPath;
|
||||
public string FadeOutClipPath;
|
||||
|
||||
public LibraryTab(LibraryTabType type, GameObject panel, string fadeIn, string fadeOut)
|
||||
{
|
||||
Type = type;
|
||||
Panel = panel;
|
||||
FadeInClipPath = fadeIn;
|
||||
FadeOutClipPath = fadeOut;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<LibraryTabType, LibraryTab> _tabs = new();
|
||||
private LibraryTabType? _currentTab = null;
|
||||
|
||||
public LibraryUI(Main main, MapData mapData)
|
||||
{
|
||||
_main = main;
|
||||
_mapData = mapData;
|
||||
ROLibraryUI = UIManager.Instance.ROUIManager.transform.Find("GameUI/LibraryUI").gameObject;
|
||||
ROLibraryUI.transform.Find("CloseButton").GetComponent<Button>().onClick.AddListener(
|
||||
() => {
|
||||
NeedShow = false;
|
||||
UIManager.Instance.GameUI.MainUI.NeedShow = true;
|
||||
});
|
||||
ROLibraryUI.gameObject.SetActive(false);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
ForceButton = ROLibraryUI.transform.Find("TopBar/Force").GetComponent<Button>();
|
||||
GiantButton = ROLibraryUI.transform.Find("TopBar/Giant").GetComponent<Button>();
|
||||
WonderButton = ROLibraryUI.transform.Find("TopBar/Wonder").GetComponent<Button>();
|
||||
AchievementButton = ROLibraryUI.transform.Find("TopBar/Achievement").GetComponent<Button>();
|
||||
|
||||
_tabs[LibraryTabType.Force] = new LibraryTab(
|
||||
LibraryTabType.Force,
|
||||
ROLibraryUI.transform.Find("Force").gameObject,
|
||||
"Animations/UI/LibraryForceUIFadeIn",
|
||||
"Animations/UI/LibraryForceUIFadeOut");
|
||||
|
||||
_tabs[LibraryTabType.Giant] = new LibraryTab(
|
||||
LibraryTabType.Giant,
|
||||
ROLibraryUI.transform.Find("Giant").gameObject,
|
||||
"Animations/UI/LibraryGiantUIFadeIn",
|
||||
"Animations/UI/LibraryGiantUIFadeOut");
|
||||
|
||||
_tabs[LibraryTabType.Wonder] = new LibraryTab(
|
||||
LibraryTabType.Wonder,
|
||||
ROLibraryUI.transform.Find("Wonder").gameObject,
|
||||
"Animations/UI/LibraryWonderUIFadeIn",
|
||||
"Animations/UI/LibraryWonderUIFadeOut");
|
||||
|
||||
_tabs[LibraryTabType.Achievement] = new LibraryTab(
|
||||
LibraryTabType.Achievement,
|
||||
ROLibraryUI.transform.Find("Achievement").gameObject,
|
||||
"Animations/UI/LibraryAchievementUIFadeIn",
|
||||
"Animations/UI/LibraryAchievementUIFadeOut");
|
||||
|
||||
//ForceButton.onClick.AddListener(() => SwitchTab(LibraryTabType.Force));
|
||||
GiantButton.onClick.AddListener(() =>
|
||||
{
|
||||
|
||||
SwitchTab(LibraryTabType.Giant);
|
||||
});
|
||||
WonderButton.onClick.AddListener(() =>
|
||||
{
|
||||
UpdateWonderListData();
|
||||
SwitchTab(LibraryTabType.Wonder);
|
||||
});
|
||||
//AchievementButton.onClick.AddListener(() => SwitchTab(LibraryTabType.Achievement));
|
||||
|
||||
|
||||
//设置各种初始化值
|
||||
_currentTab = LibraryTabType.Giant;
|
||||
DefaultGiantListItem = ROLibraryUI.transform.Find("Giant/LibraryGiantListPanel/Scroll View/Viewport/Content")?.GetChild(0)?.GetChild(0);
|
||||
UpdateGiantListData();
|
||||
InitSubPanel(LibraryTabType.Giant);
|
||||
}
|
||||
|
||||
public void UpdateGiantListData()
|
||||
{
|
||||
var table = ROLibraryUI.transform.Find("Giant/LibraryGiantListPanel/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++;
|
||||
}
|
||||
|
||||
|
||||
//设置每一个giant
|
||||
for(int i = 0;i < needList.Count; i++)
|
||||
{
|
||||
var giant = needList[i];
|
||||
if(!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, giant, 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(table,slot,giant);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void GiantListItemOnClick(Transform table, Transform selected, GiantType giant)
|
||||
{
|
||||
//消除之前选中对象的红圈,换成当前这个
|
||||
SelectedGiantListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(false);
|
||||
selected.Find("TribeIconMask/Selected")?.gameObject.SetActive(true);
|
||||
SelectedGiantListItem = selected;
|
||||
|
||||
var infoPanel = ROLibraryUI.transform.Find("Giant/LibraryGiantInfoPanel");
|
||||
infoPanel.GetComponent<AnimancerComponent>()?.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
||||
|
||||
Timer.Instance.TimerRegister(this, () =>
|
||||
{
|
||||
UpdateGiantInfoData(giant);
|
||||
infoPanel.GetComponent<AnimancerComponent>()?.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
||||
},ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length);
|
||||
}
|
||||
|
||||
public void UpdateGiantInfoData(GiantType giant)
|
||||
{
|
||||
Debug.Log(giant);
|
||||
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, giant, 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 = ROLibraryUI.transform.Find("Giant/LibraryGiantInfoPanel/GiantImage/Img");
|
||||
var info = ROLibraryUI.transform.Find("Giant/LibraryGiantInfoPanel/GiantInfo");
|
||||
//设置立绘
|
||||
image.GetComponent<Image>().sprite = libraryInfo.Illust;
|
||||
//设置英文名称装饰
|
||||
if(ROLibraryUI.transform.Find("Giant/LibraryGiantInfoPanel/TitleEN"))
|
||||
ROLibraryUI.transform.Find("Giant/LibraryGiantInfoPanel/TitleEN").GetComponent<TextMeshProUGUI>().text = libraryInfo.EnglishName.ToUpper();
|
||||
//设置角色名称
|
||||
Debug.Log(libraryInfo.Name);
|
||||
MultilingualManager.Instance.SetUIText(ROLibraryUI.transform.Find("Giant/LibraryGiantInfoPanel/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 = 0; i < 3; i++)
|
||||
{
|
||||
//star坑位
|
||||
var star = info.Find($"Info3/Star{i + 1}/Star")?.GetComponent<Image>();
|
||||
//成就标题star坑位
|
||||
var title = info.Find($"Info3/Star{i + 1}/Title")?.GetComponent<TextMeshProUGUI>();
|
||||
//成就描述star坑位
|
||||
var desc = info.Find($"Info3/Star{i + 1}/Desc")?.GetComponent<TextMeshProUGUI>();
|
||||
|
||||
var infoData = AchievementDataManager.Instance.Achievement.GetAchievementItem(bigid, smallid, i + 1);
|
||||
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 (star != null)
|
||||
star.sprite = finished ? ResourceCache.Instance.SpriteCache.AchievementStar : ResourceCache.Instance.SpriteCache.AchievementStarGray ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void UpdateWonderListData()
|
||||
{
|
||||
return;
|
||||
var fa = ROLibraryUI.transform.Find("Wonder").Find("WonderListPanel").Find("WonderList");
|
||||
for (int i = 0; i < 4; i++)
|
||||
for(int j = 0;j < 7; j++)
|
||||
{
|
||||
var p = fa.Find($"LibraryWonder{i}").Find($"LibraryWonderItem ({j})");
|
||||
/*p.Find("TribeIconMask").Find("GroundIcon").GetComponent<Image>().sprite
|
||||
= null;*/
|
||||
p.Find("Size/TribeIconMask/TribeIcon").GetComponent<Image>().sprite
|
||||
= Table.Instance.GridAndResourceDataAssets.WonderInfoList[i * 7 + j].Sprite;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_isAnimating) return;
|
||||
|
||||
if (NeedShow && !ROLibraryUI.activeSelf)
|
||||
{
|
||||
Show();
|
||||
}
|
||||
else if (!NeedShow && ROLibraryUI.activeSelf)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (_isShowing || _isAnimating) return;
|
||||
|
||||
_isShowing = true;
|
||||
_isAnimating = true;
|
||||
ROLibraryUI.SetActive(true);
|
||||
|
||||
var animancer = ROLibraryUI.GetComponent<AnimancerComponent>();
|
||||
var fadeIn = ResourceCache.Instance.AnimCache.UICommonPanelFadeIn;
|
||||
animancer.Play(fadeIn);
|
||||
if (_currentTab == LibraryTabType.Giant)
|
||||
UpdateGiantListData();
|
||||
SwitchTab(LibraryTabType.Giant);
|
||||
Timer.Instance.TimerRegister(ROLibraryUI, () =>
|
||||
{
|
||||
_isAnimating = false;
|
||||
}, fadeIn.length);
|
||||
}
|
||||
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (!_isShowing || _isAnimating) return;
|
||||
|
||||
_isShowing = false;
|
||||
_isAnimating = true;
|
||||
|
||||
var animancer = ROLibraryUI.GetComponent<AnimancerComponent>();
|
||||
var fadeOut = Resources.Load<AnimationClip>("Animations/UI/LibraryUIFadeOut");
|
||||
if (fadeOut != null) animancer.Play(fadeOut);
|
||||
|
||||
Timer.Instance.TimerRegister(ROLibraryUI, () =>
|
||||
{
|
||||
ROLibraryUI.SetActive(false);
|
||||
_isAnimating = false;
|
||||
}, _fadeDuration);
|
||||
}
|
||||
|
||||
private void SwitchTab(LibraryTabType target)
|
||||
{
|
||||
if (_currentTab == target) return;
|
||||
|
||||
if (_currentTab.HasValue)
|
||||
{
|
||||
var oldTab = _tabs[_currentTab.Value];
|
||||
var animancerOut = oldTab.Panel.GetComponent<AnimancerComponent>();
|
||||
var fadeOut = Resources.Load<AnimationClip>(oldTab.FadeOutClipPath);
|
||||
if (fadeOut != null) animancerOut.Play(fadeOut);
|
||||
Timer.Instance.TimerRegister(oldTab.Panel, () => oldTab.Panel.SetActive(false), _fadeDuration);
|
||||
}
|
||||
|
||||
var newTab = _tabs[target];
|
||||
newTab.Panel.SetActive(true);
|
||||
var animancerIn = newTab.Panel.GetComponent<AnimancerComponent>();
|
||||
var fadeIn = Resources.Load<AnimationClip>(newTab.FadeInClipPath);
|
||||
if (fadeIn != null) animancerIn.Play(fadeIn);
|
||||
|
||||
_currentTab = target;
|
||||
InitSubPanel(target);
|
||||
}
|
||||
|
||||
//每个subpanel都有一个初始化函数,如果切换到这个页面,要进行一次初始化选择(默认选择左上角的单位)
|
||||
private void InitSubPanel(LibraryTabType target)
|
||||
{
|
||||
if (target == LibraryTabType.Giant)
|
||||
{
|
||||
SelectedGiantListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(false);
|
||||
DefaultGiantListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(true);
|
||||
SelectedGiantListItem = DefaultGiantListItem;
|
||||
UpdateGiantInfoData(GiantType.EgyptianRemilia);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
8
My project/Assets/Scripts/UI/LibraryUI.meta
Normal file
8
My project/Assets/Scripts/UI/LibraryUI.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a3b1f0ff952d5444a5b04f3c713711f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
228
My project/Assets/Scripts/UI/LibraryUI/LibraryGiantUI.cs
Normal file
228
My project/Assets/Scripts/UI/LibraryUI/LibraryGiantUI.cs
Normal file
@ -0,0 +1,228 @@
|
||||
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) : base(type,enterButton,panel)
|
||||
{
|
||||
}
|
||||
|
||||
//更新listpanel的信息
|
||||
public 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, 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(table,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 = 0; k < 3; k++)
|
||||
{
|
||||
//star坑位
|
||||
var star = slot.Find($"Stars/Star{k + 1}")?.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();
|
||||
|
||||
}
|
||||
|
||||
public void GiantListItemOnClick(Transform table, Transform selected, GiantType giant)
|
||||
{
|
||||
//消除之前选中对象的红圈,换成当前这个
|
||||
SelectedListItem?.Find("TribeIconMask/Selected")?.gameObject.SetActive(false);
|
||||
selected.Find("TribeIconMask/Selected")?.gameObject.SetActive(true);
|
||||
SelectedListItem = selected;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//更新infopanel的信息
|
||||
public override void UpdateInfoPanel()
|
||||
{
|
||||
|
||||
var giant = GiantSelected;
|
||||
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, giant, 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 = 0; i < 3; i++)
|
||||
{
|
||||
//star坑位
|
||||
var star = info.Find($"Info3/Star{i + 1}/Star")?.GetComponent<Image>();
|
||||
//成就标题star坑位
|
||||
var title = info.Find($"Info3/Star{i + 1}/Title")?.GetComponent<TextMeshProUGUI>();
|
||||
//成就描述star坑位
|
||||
var desc = info.Find($"Info3/Star{i + 1}/Desc")?.GetComponent<TextMeshProUGUI>();
|
||||
|
||||
var infoData = AchievementDataManager.Instance.Achievement.GetAchievementItem(bigid, smallid, i + 1);
|
||||
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 (star != null)
|
||||
star.sprite = finished ? ResourceCache.Instance.SpriteCache.AchievementStar : ResourceCache.Instance.SpriteCache.AchievementStarGray ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override void SwitchTo(LibraryUI libraryUI)
|
||||
{
|
||||
if (IsShowing) return;
|
||||
var dict = libraryUI.SubUIDict;
|
||||
|
||||
foreach (var otherPanelPair in dict)
|
||||
if(otherPanelPair.Value.IsShowing)
|
||||
otherPanelPair.Value.ClosePanel(libraryUI);
|
||||
|
||||
InitBeforeSwitchTo();
|
||||
|
||||
Timer.Instance.TimerRegister(Panel, () =>
|
||||
{
|
||||
OpenPanel(libraryUI);
|
||||
}, ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length);
|
||||
}
|
||||
|
||||
//每个subpanel都有一个初始化函数,如果切换到这个页面,要进行一次初始化选择(默认选择左上角的单位)
|
||||
public override void InitBeforeSwitchTo()
|
||||
{
|
||||
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;
|
||||
UpdateInfoPanel();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44330464eb45c0f449eedf7c1f29da48
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
217
My project/Assets/Scripts/UI/LibraryUI/LibraryUI.cs
Normal file
217
My project/Assets/Scripts/UI/LibraryUI/LibraryUI.cs
Normal file
@ -0,0 +1,217 @@
|
||||
using System.Collections.Generic;
|
||||
using Animancer;
|
||||
using Logic;
|
||||
using Logic.Multilingual;
|
||||
using RuntimeData;
|
||||
using TH1Resource;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI.LibraryUI
|
||||
{
|
||||
|
||||
public enum LibrarySubUIType
|
||||
{
|
||||
Force,
|
||||
Giant,
|
||||
Wonder,
|
||||
Achievement
|
||||
}
|
||||
|
||||
public abstract class LibrarySubUIBase
|
||||
{
|
||||
//成就大类
|
||||
public LibrarySubUIType Type;
|
||||
//成就大类的id
|
||||
public int AchievementBigId;
|
||||
//对应整个panel,listpanel和infopanel
|
||||
public GameObject Panel;
|
||||
public GameObject ListPanel;
|
||||
public GameObject InfoPanel;
|
||||
public GameObject ListTable;
|
||||
public GameObject ListDefault;
|
||||
//进入该panel的总开关
|
||||
public Button EnterButton;
|
||||
//记录当前是否正在展示
|
||||
public bool IsShowing;
|
||||
|
||||
//默认list选择的目标
|
||||
public Transform SelectedListItem;
|
||||
public Transform DefaultListItem;
|
||||
|
||||
protected LibrarySubUIBase(LibrarySubUIType type, Button enterButton,GameObject panel)
|
||||
{
|
||||
EnterButton = enterButton;
|
||||
Type = type;
|
||||
Panel = panel;
|
||||
ListPanel = panel.transform.Find("ListPanel").gameObject;
|
||||
InfoPanel = panel.transform.Find("InfoPanel").gameObject;
|
||||
ListTable = ListPanel.transform.Find("Scroll View/Viewport/Content").gameObject;
|
||||
//EnterButton.onClick.AddListener(() => { UpdateListData();SwitchTo(LibrarySubUIDict); });
|
||||
}
|
||||
|
||||
//更新listpanel的信息
|
||||
public abstract void UpdateListPanel();
|
||||
//更新infopanel的信息
|
||||
public abstract void UpdateInfoPanel();
|
||||
//switch到这个panel之前要做的初始化函数
|
||||
public abstract void InitBeforeSwitchTo();
|
||||
|
||||
public abstract void SwitchTo(LibraryUI libraryUI);
|
||||
|
||||
|
||||
public virtual void DeselectButton()
|
||||
{
|
||||
//设置文字alpha=64
|
||||
var text = EnterButton.gameObject.transform.Find("Text")?.GetComponent<TextMeshProUGUI>();
|
||||
if (text != null)
|
||||
{
|
||||
Color color = text.color;
|
||||
color.a = 64;
|
||||
text.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SelectButton()
|
||||
{
|
||||
//设置文字alpha=255
|
||||
var text = EnterButton.gameObject.transform.Find("Text")?.GetComponent<TextMeshProUGUI>();
|
||||
if (text != null)
|
||||
{
|
||||
Color color = text.color;
|
||||
color.a = 255;
|
||||
text.color = color;
|
||||
}
|
||||
}
|
||||
public virtual void ClosePanel(LibraryUI libraryUI)
|
||||
{
|
||||
//topbar 的button要改为熄灭
|
||||
DeselectButton();
|
||||
|
||||
//panel要隐藏
|
||||
var anim = Panel.GetComponent<AnimancerComponent>();
|
||||
if (anim != null)
|
||||
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
||||
IsShowing = false;
|
||||
}
|
||||
|
||||
public virtual void OpenPanel(LibraryUI libraryUI)
|
||||
{
|
||||
//topbar的button要改为选中
|
||||
SelectButton();
|
||||
//panel要显示
|
||||
var anim = Panel.GetComponent<AnimancerComponent>();
|
||||
if (anim != null)
|
||||
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
||||
libraryUI.SelectedSubUIType = Type;
|
||||
IsShowing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class LibraryUI
|
||||
{
|
||||
private Main _main;
|
||||
private MapData _mapData;
|
||||
public GameObject ROLibraryUI;
|
||||
|
||||
public bool NeedShow = false;
|
||||
private bool _isShowing = false;
|
||||
private bool _isAnimating = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Dictionary<LibrarySubUIType, LibrarySubUIBase> SubUIDict = new();
|
||||
public LibrarySubUIType SelectedSubUIType;
|
||||
|
||||
public LibraryUI(Main main, MapData mapData)
|
||||
{
|
||||
_main = main;
|
||||
_mapData = mapData;
|
||||
ROLibraryUI = UIManager.Instance.ROUIManager.transform.Find("GameUI/LibraryUI").gameObject;
|
||||
ROLibraryUI.transform.Find("CloseButton").GetComponent<Button>().onClick.AddListener(
|
||||
() => {
|
||||
NeedShow = false;
|
||||
UIManager.Instance.GameUI.MainUI.NeedShow = true;
|
||||
});
|
||||
ROLibraryUI.gameObject.SetActive(false);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
//新建四个tabs对象
|
||||
SubUIDict[LibrarySubUIType.Giant] = new LibraryGiantUI(LibrarySubUIType.Giant,ROLibraryUI.transform.Find("TopBar/Giant").GetComponent<Button>(), ROLibraryUI.transform.Find("Giant").gameObject);
|
||||
}
|
||||
|
||||
public void DataPrepareBeforeShow()
|
||||
{
|
||||
//设置各种初始化值
|
||||
SelectedSubUIType = LibrarySubUIType.Giant;
|
||||
//更新默认panel giant页面的list情况
|
||||
SubUIDict[LibrarySubUIType.Giant].UpdateListPanel();
|
||||
//设置default选项
|
||||
SubUIDict[LibrarySubUIType.Giant].InitBeforeSwitchTo();
|
||||
//更新基于default的infopanel
|
||||
SubUIDict[LibrarySubUIType.Giant].UpdateInfoPanel();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_isAnimating) return;
|
||||
|
||||
if (NeedShow && !ROLibraryUI.activeSelf)
|
||||
{
|
||||
Show();
|
||||
}
|
||||
else if (!NeedShow && ROLibraryUI.activeSelf)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (_isShowing || _isAnimating) return;
|
||||
|
||||
_isShowing = true;
|
||||
_isAnimating = true;
|
||||
ROLibraryUI.SetActive(true);
|
||||
|
||||
var animancer = ROLibraryUI.GetComponent<AnimancerComponent>();
|
||||
var fadeIn = ResourceCache.Instance.AnimCache.UICommonPanelFadeIn;
|
||||
DataPrepareBeforeShow();
|
||||
animancer.Play(fadeIn);
|
||||
|
||||
Timer.Instance.TimerRegister(ROLibraryUI, () =>
|
||||
{
|
||||
_isAnimating = false;
|
||||
}, fadeIn.length);
|
||||
}
|
||||
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (!_isShowing || _isAnimating) return;
|
||||
|
||||
_isShowing = false;
|
||||
_isAnimating = true;
|
||||
|
||||
var animancer = ROLibraryUI.GetComponent<AnimancerComponent>();
|
||||
var fadeOut = Resources.Load<AnimationClip>("Animations/UI/LibraryUIFadeOut");
|
||||
if (fadeOut != null) animancer.Play(fadeOut);
|
||||
|
||||
Timer.Instance.TimerRegister(ROLibraryUI, () =>
|
||||
{
|
||||
ROLibraryUI.SetActive(false);
|
||||
_isAnimating = false;
|
||||
}, fadeOut.length);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user