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

135 lines
3.7 KiB
C#
Raw Normal View History

using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
2024-12-11 21:21:27 +08:00
using System.Collections.Generic;
using UnityEngine;
namespace AxibugEmuOnline.Client
{
public class RomListMenuItem : VirtualSubMenuItem
{
[SerializeField]
protected RomPlatformType Platform;
2024-12-11 21:21:27 +08:00
private RomLib RomLib
{
get
{
switch (Platform)
{
case RomPlatformType.Nes:
2024-12-11 21:21:27 +08:00
return App.nesRomLib;
default:
throw new System.NotImplementedException($"未实现的平台 {Platform}");
2024-12-11 21:21:27 +08:00
}
}
}
private List<OptionMenu> m_options;
protected override void Awake()
{
base.Awake();
m_options = new List<OptionMenu>()
{
new OptMenu_Search(this),
new OptMenu_ShowAll(this),
};
}
public string SearchKey;
protected override void GetVirtualListDatas(VirtualListDataHandle callback)
2024-12-11 21:21:27 +08:00
{
RomLib.FetchRomCount((roms) => callback.Invoke(roms, 0), SearchKey);
2024-12-11 21:21:27 +08:00
}
public override bool OnEnterItem()
{
var res = base.OnEnterItem();
if (res) CommandDispatcher.Instance.RegistController(this);
return true;
}
public override bool OnExitItem()
{
var res = base.OnExitItem();
if (res) CommandDispatcher.Instance.UnRegistController(this);
return false;
}
protected override void OnCmdOptionMenu()
{
2024-12-11 22:45:16 +08:00
OverlayManager.PopSideBar(m_options);
2024-12-11 21:21:27 +08:00
}
public class OptMenu_Search : ExecuteMenu
{
private RomListMenuItem m_romListUI;
2025-01-07 20:11:11 +08:00
public override string Name => "搜索";
2024-12-11 21:21:27 +08:00
2025-01-07 20:11:11 +08:00
public OptMenu_Search(RomListMenuItem romListUI)
2024-12-11 21:21:27 +08:00
{
m_romListUI = romListUI;
}
public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{
OverlayManager.Input(OnSearchCommit, "输入Rom名称", m_romListUI.SearchKey);
2024-12-11 21:21:27 +08:00
}
private void OnSearchCommit(string text)
{
m_romListUI.SearchKey = text;
m_romListUI.RefreshUI();
}
}
public class OptMenu_ShowAll : ExecuteMenu
{
private RomListMenuItem m_ui;
2025-01-07 20:11:11 +08:00
public override string Name => "显示全部";
2024-12-11 21:21:27 +08:00
public override bool Visible => !string.IsNullOrWhiteSpace(m_ui.SearchKey);
2025-01-07 20:11:11 +08:00
public OptMenu_ShowAll(RomListMenuItem romListUI)
2024-12-11 21:21:27 +08:00
{
m_ui = romListUI;
}
public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{
m_ui.SearchKey = null;
m_ui.RefreshUI();
}
}
2025-01-07 20:11:11 +08:00
public class OptMenu_Fav : ExecuteMenu
{
private RomListMenuItem m_romListUI;
private ThirdMenuRoot m_romListSub;
public override string Name
{
get
{
var isFav = (m_romListSub.GetItemUIByIndex(m_romListSub.SelectIndex) as RomItem).IsFav;
return isFav ? "收藏" : "取消收藏";
}
}
public OptMenu_Fav(RomListMenuItem romListUI)
{
m_romListUI = romListUI;
m_romListSub = m_romListUI.SubMenuItemGroup as ThirdMenuRoot;
}
public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{
}
}
2024-12-11 21:21:27 +08:00
}
}