217 lines
6.9 KiB
C#
217 lines
6.9 KiB
C#
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);
|
|
}
|
|
}
|
|
|
|
} |