208 lines
6.4 KiB
C#
208 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Animancer;
|
|
using Logic.Multilingual;
|
|
using RuntimeData;
|
|
using TH1Resource;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TH1_UI.View.Outside
|
|
{
|
|
public class UIOutsideLibraryHeroPanelMono : MonoBehaviour
|
|
{
|
|
|
|
public TextMeshProUGUI TopTitle;
|
|
public Image Illustration;
|
|
public TextMeshProUGUI Name;
|
|
public TextMeshProUGUI CivName;
|
|
public Image CivBG;
|
|
public RectTransform CivRect;
|
|
public TextMeshProUGUI Desc;
|
|
public TextMeshProUGUI Dialogue;
|
|
public Image DialogueAvatar;
|
|
public List<UIOutsideLibraryAchieveItemMono> AchieveItems;
|
|
|
|
public Button CloseButton;
|
|
public Button LeftButton;
|
|
public Button RightButton;
|
|
public AnimancerComponent Animancer;
|
|
|
|
|
|
public void Init(Action onStartClick)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
public bool SetContent(GiantType giantType)
|
|
{
|
|
if (!ContentGate.CanShowHeroIntroduction(giantType)) return false;
|
|
if (!Table.Instance.LibraryDataAssets.GetLibraryInfoByGiant(giantType, out var info)) return false;
|
|
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(new UnitFullType(UnitType.Giant, giantType, 1),
|
|
out var unitInfo)) return false;
|
|
var empire = unitInfo.GiantEmpire;
|
|
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(empire, out var playerInfo)) return false;
|
|
|
|
SetUITextOrRaw(TopTitle,info.Name);
|
|
Illustration.sprite = info.Illust;
|
|
SetUITextOrRaw(Name,info.Name);
|
|
SetUITextOrRaw(CivName,playerInfo.CivName);
|
|
CivBG.color = playerInfo.Color;
|
|
SetUITextOrRaw(Desc,info.Desc);
|
|
SetUITextOrRaw(Dialogue,info.Diag);
|
|
DialogueAvatar.sprite = unitInfo.Sprite;
|
|
|
|
//Step #3 设定成就
|
|
SetAchieveItems(giantType);
|
|
|
|
|
|
CloseButton.onClick.RemoveAllListeners();
|
|
CloseButton.onClick.AddListener(Hide);
|
|
return true;
|
|
|
|
}
|
|
|
|
public void SetNavigationButtons(bool canMoveLeft, bool canMoveRight, Action onLeftClick, Action onRightClick)
|
|
{
|
|
EnsureNavigationButtons();
|
|
SetNavigationButton(LeftButton, canMoveLeft, onLeftClick);
|
|
SetNavigationButton(RightButton, canMoveRight, onRightClick);
|
|
}
|
|
|
|
private void EnsureNavigationButtons()
|
|
{
|
|
if (LeftButton == null)
|
|
{
|
|
LeftButton = FindNavigationButton("LeftButton");
|
|
}
|
|
|
|
if (RightButton == null)
|
|
{
|
|
RightButton = FindNavigationButton("RightButton");
|
|
}
|
|
}
|
|
|
|
private Button FindNavigationButton(string buttonName)
|
|
{
|
|
var buttons = GetComponentsInChildren<Button>(true);
|
|
for (int i = 0; i < buttons.Length; i++)
|
|
{
|
|
if (buttons[i] != null && buttons[i].name == buttonName) return buttons[i];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private static void SetNavigationButton(Button button, bool active, Action onClick)
|
|
{
|
|
if (button == null) return;
|
|
button.gameObject.SetActive(active);
|
|
button.onClick.RemoveAllListeners();
|
|
if (active && onClick != null) button.onClick.AddListener(() => onClick.Invoke());
|
|
}
|
|
|
|
private static void SetUITextOrRaw(TextMeshProUGUI text, string value)
|
|
{
|
|
if (text == null) return;
|
|
|
|
var multilingual = text.gameObject.GetComponent<MultilingualTextMono>();
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
if (multilingual != null)
|
|
{
|
|
multilingual.ID = 0;
|
|
multilingual.Ban = true;
|
|
}
|
|
|
|
text.text = string.Empty;
|
|
return;
|
|
}
|
|
|
|
if (uint.TryParse(value, out _))
|
|
{
|
|
if (multilingual != null) multilingual.Ban = false;
|
|
MultilingualManager.Instance.SetUIText(text, value);
|
|
}
|
|
else
|
|
{
|
|
if (multilingual != null)
|
|
{
|
|
multilingual.ID = 0;
|
|
multilingual.Ban = true;
|
|
}
|
|
|
|
text.text = value;
|
|
}
|
|
}
|
|
|
|
|
|
private void SetAchieveItems(GiantType giantType)
|
|
{
|
|
if (AchieveItems.Count != 3) return;
|
|
if (!UIOutsideLibraryAchievementVisibility.ShouldShowHeroAchievements(giantType))
|
|
{
|
|
SetAchievementSectionActive(false);
|
|
return;
|
|
}
|
|
|
|
if (!AchievementDataManager.Instance.GetSmallIdByGiantType(giantType, out var smallid))
|
|
{
|
|
SetAchievementSectionActive(false);
|
|
return;
|
|
}
|
|
|
|
SetAchievementSectionActive(true);
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
AchieveItems[i].gameObject.SetActive(true);
|
|
AchieveItems[i].SetContent(2,smallid,(uint)i + 1);
|
|
}
|
|
}
|
|
|
|
private void SetAchievementSectionActive(bool active)
|
|
{
|
|
Transform group = null;
|
|
if (AchieveItems.Count > 0 && AchieveItems[0] != null)
|
|
group = AchieveItems[0].transform.parent;
|
|
|
|
if (group != null)
|
|
{
|
|
group.gameObject.SetActive(active);
|
|
var title = group.parent != null ? group.parent.Find("AchieveTitle") : null;
|
|
if (title != null) title.gameObject.SetActive(active);
|
|
}
|
|
|
|
for (int i = 0; i < AchieveItems.Count; i++)
|
|
{
|
|
if (AchieveItems[i] != null) AchieveItems[i].gameObject.SetActive(active);
|
|
}
|
|
}
|
|
public void Show()
|
|
{
|
|
gameObject.SetActive(true);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(CivRect);
|
|
Animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
|
|
|
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
var state = Animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
|
state.Events.OnEnd = () => { gameObject.SetActive(false); };
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|