2024-12-19 20:36:04 +08:00
|
|
|
|
using AxibugEmuOnline.Client.ClientCore;
|
2025-01-07 19:42:07 +08:00
|
|
|
|
using AxibugEmuOnline.Client.Event;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
using AxibugEmuOnline.Client.UI;
|
2025-01-07 19:42:07 +08:00
|
|
|
|
using Coffee.UIExtensions;
|
|
|
|
|
using System;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client
|
|
|
|
|
{
|
|
|
|
|
public class RomItem : MenuItem, IVirtualItem
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
|
|
|
|
Image m_romImage;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject DownloadingFlag;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
Slider DownProgress;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject FileReadyFlag;
|
2025-01-07 19:42:07 +08:00
|
|
|
|
[SerializeField]
|
|
|
|
|
UIShiny DownloadComplete;
|
2025-01-07 20:29:31 +08:00
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject Star;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
|
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
2025-01-07 20:29:31 +08:00
|
|
|
|
public bool IsStar
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return m_romfile != null && m_romfile.InfoReady ? m_romfile.Star : false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int RomID { get { return m_romfile != null && m_romfile.InfoReady ? m_romfile.ID : -1; } }
|
2025-01-07 20:11:11 +08:00
|
|
|
|
|
2025-01-07 20:29:31 +08:00
|
|
|
|
private RomLib m_romlib => App.nesRomLib;
|
|
|
|
|
|
|
|
|
|
public bool RomInfoReady => m_romfile != null && m_romfile.InfoReady;
|
|
|
|
|
|
2024-12-11 21:21:27 +08:00
|
|
|
|
private RomFile m_romfile;
|
|
|
|
|
|
2025-01-07 19:42:07 +08:00
|
|
|
|
protected override void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
Eventer.Instance.RegisterEvent<int>(EEvent.OnRomFileDownloaded, OnRomDownloaded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRomFileDownloaded, OnRomDownloaded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRomDownloaded(int romID)
|
|
|
|
|
{
|
|
|
|
|
if (m_romfile == null || m_romfile.ID != romID) return;
|
|
|
|
|
|
|
|
|
|
DownloadComplete.Play();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 21:21:27 +08:00
|
|
|
|
public void SetData(object data)
|
|
|
|
|
{
|
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
|
|
m_romfile = (RomFile)data;
|
|
|
|
|
m_romfile.OnInfoFilled += OnRomInfoFilled;
|
|
|
|
|
m_romImage.sprite = null;
|
|
|
|
|
|
|
|
|
|
UpdateView();
|
|
|
|
|
|
|
|
|
|
if (!m_romfile.InfoReady)
|
|
|
|
|
{
|
|
|
|
|
m_romlib.BeginFetchRomInfo(m_romfile);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 01:06:27 +08:00
|
|
|
|
SetSelectState(data is ThirdMenuRoot && ((ThirdMenuRoot)data).SelectIndex == Index);
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetDependencyProperty(object data)
|
|
|
|
|
{
|
2024-12-23 01:06:27 +08:00
|
|
|
|
SetSelectState(data is ThirdMenuRoot && ((ThirdMenuRoot)data).SelectIndex == Index);
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-07 16:43:54 +08:00
|
|
|
|
protected override void OnSelected(float progress)
|
|
|
|
|
{
|
|
|
|
|
base.OnSelected(progress);
|
|
|
|
|
|
|
|
|
|
if (m_romImage.sprite == null) LaunchUI.Instance.HideRomPreview();
|
|
|
|
|
else LaunchUI.Instance.SetRomPreview(m_romImage.sprite);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 21:21:27 +08:00
|
|
|
|
public void Release()
|
|
|
|
|
{
|
|
|
|
|
m_romfile.OnInfoFilled -= OnRomInfoFilled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRomInfoFilled()
|
|
|
|
|
{
|
|
|
|
|
UpdateView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateView()
|
|
|
|
|
{
|
|
|
|
|
if (!m_romfile.InfoReady)
|
|
|
|
|
{
|
2024-12-19 20:36:04 +08:00
|
|
|
|
SetBaseInfo("正在拉取", "---", "---");
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetBaseInfo(m_romfile.Alias, m_romfile.Descript, m_romfile.GameTypeDes);
|
|
|
|
|
App.CacheMgr.GetSpriteCache(m_romfile.ImageURL, (img, url) =>
|
|
|
|
|
{
|
2024-12-24 21:46:31 +08:00
|
|
|
|
if (!m_romfile.InfoReady || url != m_romfile.ImageURL) return;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
|
|
|
|
|
m_romImage.sprite = img;
|
2025-01-07 16:43:54 +08:00
|
|
|
|
if (m_select) LaunchUI.Instance.SetRomPreview(img);
|
2024-12-11 21:21:27 +08:00
|
|
|
|
});
|
2025-01-07 20:29:31 +08:00
|
|
|
|
Star.SetActiveEx(m_romfile.Star);
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnEnterItem()
|
|
|
|
|
{
|
|
|
|
|
if (!m_romfile.RomReady)
|
|
|
|
|
{
|
|
|
|
|
m_romfile.BeginDownload();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
App.emu.BeginGame(m_romfile);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
DownloadingFlag.SetActiveEx(false);
|
|
|
|
|
FileReadyFlag.SetActiveEx(false);
|
|
|
|
|
|
|
|
|
|
if (m_romfile == null) return;
|
|
|
|
|
if (!m_romfile.InfoReady) return;
|
|
|
|
|
|
|
|
|
|
if (m_romfile.IsDownloading)
|
|
|
|
|
{
|
|
|
|
|
DownloadingFlag.SetActiveEx(true);
|
|
|
|
|
DownProgress.value = m_romfile.Progress;
|
|
|
|
|
}
|
|
|
|
|
else if (m_romfile.RomReady)
|
|
|
|
|
{
|
|
|
|
|
FileReadyFlag.SetActiveEx(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|