AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/UI/RoomUI/RoomListMenuItem.cs

72 lines
1.9 KiB
C#
Raw Normal View History

2024-09-18 15:53:58 +08:00
using AxibugEmuOnline.Client.ClientCore;
2024-11-07 19:18:50 +08:00
using AxibugEmuOnline.Client.Event;
2024-09-18 15:53:58 +08:00
using System;
namespace AxibugEmuOnline.Client
{
public class RoomListMenuItem : VirtualSubMenuItem
{
2024-11-07 19:18:50 +08:00
bool m_entering;
protected override void Awake()
2024-09-18 15:53:58 +08:00
{
2024-11-08 13:48:53 +08:00
Eventer.Instance.RegisterEvent(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
2024-11-07 19:38:48 +08:00
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleClose, OnRoomClosed);
2024-11-08 11:31:12 +08:00
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleAdd, OnRoomSingleAdd);
2024-11-07 19:23:59 +08:00
base.Awake();
}
2024-11-07 19:38:48 +08:00
2024-11-07 19:23:59 +08:00
protected override void OnDestroy()
{
2024-11-08 13:48:53 +08:00
Eventer.Instance.UnregisterEvent(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
2024-11-08 11:31:12 +08:00
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSingleAdd);
2024-11-07 19:38:48 +08:00
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleClose, OnRoomClosed);
2024-09-18 15:53:58 +08:00
}
2024-11-07 19:18:50 +08:00
public override bool OnEnterItem()
2024-09-18 15:53:58 +08:00
{
2024-11-07 19:18:50 +08:00
var res = base.OnEnterItem();
if (res) m_entering = true;
return res;
}
2024-09-18 15:53:58 +08:00
2024-11-07 19:18:50 +08:00
public override bool OnExitItem()
{
var res = base.OnExitItem();
if (res) m_entering = false;
return res;
}
2024-09-18 15:53:58 +08:00
2024-11-08 11:31:12 +08:00
private void OnRoomSingleAdd(int obj)
2024-11-07 20:20:53 +08:00
{
if (m_entering)
{
RefreshUI();
}
}
2024-11-08 13:48:53 +08:00
private void OnRoomListUpdateAll()
2024-11-07 19:18:50 +08:00
{
if (m_entering)
{
RefreshUI();
}
}
2024-11-07 19:38:48 +08:00
private void OnRoomClosed(int obj)
{
if (m_entering)
{
RefreshUI();
}
}
2024-09-18 15:53:58 +08:00
2024-11-07 19:18:50 +08:00
protected override void GetVirtualListDatas(Action<object> datas)
{
var roomList = App.roomMgr.GetRoomList();
datas.Invoke(roomList);
2024-09-18 15:53:58 +08:00
}
2024-11-07 19:18:50 +08:00
2024-09-18 15:53:58 +08:00
}
}