2024-08-16 14:45:44 +08:00
|
|
|
using DG.Tweening;
|
|
|
|
using DG.Tweening.Core;
|
|
|
|
using DG.Tweening.Plugins.Options;
|
2024-08-16 10:24:40 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client.UI
|
|
|
|
{
|
2024-11-13 13:55:36 +08:00
|
|
|
public class MenuItem : CommandExecuter
|
2024-08-16 10:24:40 +08:00
|
|
|
{
|
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected Image Icon;
|
2024-08-16 10:24:40 +08:00
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected Text Txt;
|
2024-08-16 10:53:43 +08:00
|
|
|
[SerializeField]
|
2024-11-15 10:53:19 +08:00
|
|
|
protected Text SubTitle;
|
|
|
|
[SerializeField]
|
|
|
|
protected Image spline;
|
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected Text Descript;
|
2024-08-16 14:45:44 +08:00
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected Transform Root;
|
2024-08-16 14:45:44 +08:00
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected Image ShadowIcon;
|
2024-08-16 14:45:44 +08:00
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected CanvasGroup InfoNode;
|
2024-08-22 15:16:58 +08:00
|
|
|
[SerializeField]
|
2024-08-30 16:23:27 +08:00
|
|
|
protected SubMenuItemGroup SubMenuItemGroup;
|
2024-08-16 10:53:43 +08:00
|
|
|
|
|
|
|
public float SelectScale = 1f;
|
|
|
|
public float UnSelectScale = 0.85f;
|
2024-08-16 10:24:40 +08:00
|
|
|
|
|
|
|
public RectTransform Rect => transform as RectTransform;
|
|
|
|
|
2024-08-30 16:23:27 +08:00
|
|
|
protected bool m_select;
|
|
|
|
protected TweenerCore<float, float, FloatOptions> progressTween;
|
|
|
|
protected float m_progress;
|
2024-09-11 16:33:48 +08:00
|
|
|
|
2024-11-13 13:55:36 +08:00
|
|
|
protected override void Awake()
|
2024-09-12 11:02:30 +08:00
|
|
|
{
|
2024-11-13 13:55:36 +08:00
|
|
|
base.Awake();
|
2024-09-12 11:02:30 +08:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2024-09-11 16:33:48 +08:00
|
|
|
public void SetData(MenuData data)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
2024-11-15 10:53:19 +08:00
|
|
|
SetBaseInfo(data.Name, data.Description, data.SubTitle);
|
2024-09-11 16:33:48 +08:00
|
|
|
SetIcon(data.Icon);
|
|
|
|
if (SubMenuItemGroup != null) SubMenuItemGroup.Init(data.SubMenus);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void Reset()
|
2024-08-16 14:45:44 +08:00
|
|
|
{
|
|
|
|
m_select = false;
|
|
|
|
m_progress = 0f;
|
|
|
|
|
2024-09-11 16:33:48 +08:00
|
|
|
Root.localScale = Vector3.one * UnSelectScale;
|
2024-11-13 13:55:36 +08:00
|
|
|
|
2024-09-11 16:33:48 +08:00
|
|
|
if (progressTween != null) { progressTween.Kill(); progressTween = null; }
|
|
|
|
|
2024-08-16 14:45:44 +08:00
|
|
|
if (ShadowIcon != null) ShadowIcon.gameObject.SetActive(false);
|
|
|
|
|
2024-08-22 17:25:00 +08:00
|
|
|
if (InfoNode != null) InfoNode.alpha = 0;
|
2024-11-15 10:53:19 +08:00
|
|
|
if (spline != null) spline.SetAlpha(0);
|
2024-08-16 14:45:44 +08:00
|
|
|
if (ShadowIcon != null) ShadowIcon.gameObject.SetActiveEx(false);
|
|
|
|
if (SubMenuItemGroup != null) SubMenuItemGroup.SetSelect(false);
|
|
|
|
}
|
|
|
|
|
2024-11-15 10:53:19 +08:00
|
|
|
protected void SetBaseInfo(string name, string descript, string subTitle)
|
2024-08-22 15:16:58 +08:00
|
|
|
{
|
|
|
|
this.name = name;
|
2024-08-16 14:45:44 +08:00
|
|
|
|
2024-08-22 15:16:58 +08:00
|
|
|
if (Txt != null) Txt.text = name;
|
2024-11-15 10:53:19 +08:00
|
|
|
if (SubTitle != null) SubTitle.text = subTitle;
|
2024-08-22 15:16:58 +08:00
|
|
|
if (Descript != null) Descript.text = descript;
|
2024-08-22 17:25:00 +08:00
|
|
|
}
|
2024-08-16 14:45:44 +08:00
|
|
|
|
2024-08-22 17:25:00 +08:00
|
|
|
protected void SetIcon(Sprite icon)
|
|
|
|
{
|
|
|
|
if (Icon != null) Icon.sprite = icon;
|
|
|
|
if (ShadowIcon != null) ShadowIcon.sprite = icon;
|
2024-08-16 10:24:40 +08:00
|
|
|
}
|
|
|
|
|
2024-08-30 16:23:27 +08:00
|
|
|
public virtual void SetSelectState(bool selected)
|
2024-08-16 10:24:40 +08:00
|
|
|
{
|
2024-08-16 14:45:44 +08:00
|
|
|
if (m_select == selected) return;
|
|
|
|
|
|
|
|
m_select = selected;
|
|
|
|
|
|
|
|
if (ShadowIcon != null) ShadowIcon.gameObject.SetActiveEx(selected);
|
2024-09-12 11:19:40 +08:00
|
|
|
if (SubMenuItemGroup != null)
|
|
|
|
{
|
|
|
|
SubMenuItemGroup.SetSelect(selected);
|
|
|
|
}
|
2024-08-16 14:45:44 +08:00
|
|
|
|
|
|
|
if (progressTween != null) { progressTween.Kill(); progressTween = null; }
|
|
|
|
|
2024-11-15 10:53:19 +08:00
|
|
|
progressTween = DOTween.To(() => m_progress, (x) => m_progress = x, m_select ? 1 : 0, 0.3f)
|
|
|
|
.OnUpdate(() =>
|
2024-08-16 14:45:44 +08:00
|
|
|
{
|
2024-08-22 17:25:00 +08:00
|
|
|
if (InfoNode != null) InfoNode.alpha = m_progress;
|
2024-11-15 10:53:19 +08:00
|
|
|
if (spline != null) spline.SetAlpha(m_progress);
|
2024-08-16 14:45:44 +08:00
|
|
|
Root.localScale = Vector3.one * Mathf.Lerp(UnSelectScale, SelectScale, m_progress);
|
|
|
|
});
|
2024-08-16 10:24:40 +08:00
|
|
|
}
|
2024-08-16 17:26:28 +08:00
|
|
|
|
2024-09-11 16:33:48 +08:00
|
|
|
public virtual bool OnEnterItem() => true;
|
2024-08-21 16:28:23 +08:00
|
|
|
|
2024-09-11 16:33:48 +08:00
|
|
|
public virtual bool OnExitItem() => true;
|
2024-11-13 13:55:36 +08:00
|
|
|
|
|
|
|
public override bool Enable => true;
|
2024-08-16 10:24:40 +08:00
|
|
|
}
|
|
|
|
}
|