AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/UI/RomListMenuItem.cs

107 lines
3.3 KiB
C#
Raw Normal View History

2024-08-22 15:16:58 +08:00
using AxibugEmuOnline.Client.UI;
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using UnityEngine;
2024-09-11 18:31:25 +08:00
using App = AxibugEmuOnline.Client.ClientCore.App;
2024-08-22 15:16:58 +08:00
namespace AxibugEmuOnline.Client
{
public class RomListMenuItem : MenuItem
2024-08-22 15:16:58 +08:00
{
[SerializeField]
CanvasGroup RomGroupRoot;
[SerializeField]
EnumPlatform Platform;
2024-08-22 15:16:58 +08:00
private TweenerCore<float, float, FloatOptions> m_showTween;
private RomLib RomLib
{
get
{
switch (Platform)
{
case EnumPlatform.NES:
return App.nesRomLib;
default:
throw new System.NotImplementedException($"δʵ<CEB4>ֵ<EFBFBD>ƽ̨ {Platform}");
}
}
}
2024-09-12 11:02:30 +08:00
protected override void Awake()
2024-08-22 15:16:58 +08:00
{
2024-09-12 11:02:30 +08:00
base.Awake();
2024-08-22 15:16:58 +08:00
RomGroupRoot.gameObject.SetActive(false);
RomGroupRoot.alpha = 0;
}
2024-08-30 16:23:27 +08:00
public override void SetSelectState(bool selected)
{
if (m_select == selected) return;
m_select = selected;
if (ShadowIcon != null) ShadowIcon.gameObject.SetActiveEx(selected);
if (progressTween != null) { progressTween.Kill(); progressTween = null; }
progressTween = DOTween.To(() => m_progress, (x) => m_progress = x, m_select ? 1 : 0, 5)
.SetSpeedBased().OnUpdate(() =>
{
if (InfoNode != null) InfoNode.alpha = m_progress;
Root.localScale = Vector3.one * Mathf.Lerp(UnSelectScale, SelectScale, m_progress);
});
}
2024-09-11 16:33:48 +08:00
public override bool OnEnterItem()
2024-08-22 15:16:58 +08:00
{
RomGroupRoot.gameObject.SetActive(true);
RomGroupRoot.alpha = 0;
if (m_showTween != null)
{
m_showTween.Kill();
m_showTween = null;
}
m_showTween = DOTween.To(() => RomGroupRoot.alpha, (x) => RomGroupRoot.alpha = x, 1, 0.2f);
2024-09-11 16:33:48 +08:00
var thirdMenuGroup = SubMenuItemGroup as ThirdMenuRoot;
thirdMenuGroup.itemGroup.Clear();
RomLib.FetchRomCount((roms) =>
2024-08-22 15:16:58 +08:00
{
2024-08-30 16:23:27 +08:00
var thirdMenuGroup = SubMenuItemGroup as ThirdMenuRoot;
thirdMenuGroup.itemGroup.UpdateDependencyProperty(thirdMenuGroup);
thirdMenuGroup.itemGroup.SetData(roms);
thirdMenuGroup.itemGroup.UpdateProxyVisualState();
2024-09-12 11:02:30 +08:00
thirdMenuGroup.ResetToFirst();
2024-08-22 15:16:58 +08:00
});
2024-08-30 16:23:27 +08:00
if (SubMenuItemGroup != null) SubMenuItemGroup.SetSelect(true);
2024-09-11 16:33:48 +08:00
return true;
2024-08-22 15:16:58 +08:00
}
2024-09-11 16:33:48 +08:00
public override bool OnExitItem()
2024-08-22 15:16:58 +08:00
{
if (m_showTween != null)
{
m_showTween.Kill();
m_showTween = null;
}
m_showTween = DOTween.To(() => RomGroupRoot.alpha, (x) => RomGroupRoot.alpha = x, 0, 0.2f)
.OnComplete(() =>
{
RomGroupRoot.gameObject.SetActive(false);
});
2024-08-30 16:23:27 +08:00
if (SubMenuItemGroup != null) SubMenuItemGroup.SetSelect(false);
2024-09-11 16:33:48 +08:00
return true;
2024-08-22 15:16:58 +08:00
}
}
}