房间列表获取,调用实装

This commit is contained in:
ALIENJACK\alien 2024-11-07 19:18:50 +08:00
parent 88313eee6b
commit 9f732c7719
6 changed files with 58 additions and 39 deletions

View File

@ -89,7 +89,7 @@ namespace AxibugEmuOnline.Client.Manager
List<Protobuf_Room_MiniInfo> result = new List<Protobuf_Room_MiniInfo>();
foreach (var item in dictRoomListID2Info)
{
result.Add(new Protobuf_Room_MiniInfo());
result.Add(item.Value);
}
return result;
}

View File

@ -1,6 +1,5 @@
using AxibugEmuOnline.Client.ClientCore;
using System.Diagnostics;
using VirtualNes.Core;
namespace AxibugEmuOnline.Client
{
@ -16,10 +15,14 @@ namespace AxibugEmuOnline.Client
public override void OnExcute()
{
object state = m_gameUI.GetQuickState();
Stopwatch sw = Stopwatch.StartNew();
m_gameUI.Core.LoadState(m_gameUI.GetQuickState());
sw.Stop();
App.log.Info($"{m_gameUI.RomFile.Platform}====>快照加载耗时:{sw.Elapsed.TotalMilliseconds}ms");
if (state != null)
{
m_gameUI.Core.LoadState(state);
sw.Stop();
App.log.Info($"{m_gameUI.RomFile.Platform}====>快照加载耗时:{sw.Elapsed.TotalMilliseconds}ms");
}
}
}
}

View File

@ -517,6 +517,7 @@ public class ItemPresent : GridLayoutGroup, IVirtualLayout
}
public RectTransform GetItemUIIfExist(int index)
{
if (index < 0) return null;
if (children.Count <= index) return null;
var proxy = children[index];

View File

@ -1,34 +1,45 @@
using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
using AxibugEmuOnline.Client.Event;
using System;
using System.Collections;
using System.Collections.Generic;
namespace AxibugEmuOnline.Client
{
public class RoomListMenuItem : VirtualSubMenuItem
{
bool m_entering;
protected override void Awake()
{
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
}
public override bool OnEnterItem()
{
var res = base.OnEnterItem();
if (res) m_entering = true;
return res;
}
public override bool OnExitItem()
{
var res = base.OnExitItem();
if (res) m_entering = false;
return res;
}
private void OnRoomListUpdateAll(int obj)
{
if (m_entering)
{
RefreshUI();
}
}
protected override void GetVirtualListDatas(Action<object> datas)
{
App.StartCoroutine(Test(datas));
var roomList = App.roomMgr.GetRoomList();
datas.Invoke(roomList);
}
private IEnumerator Test(Action<object> datas)
{
yield return null;
List<Protobuf_Room_MiniInfo> fakeData = new List<Protobuf_Room_MiniInfo>()
{
new Protobuf_Room_MiniInfo{ GameRomID = 1, RoomID = 1, HostPlayerUID = 1, Player1UID = 1, Player1NickName = "Test1"},
new Protobuf_Room_MiniInfo{ GameRomID = 2, RoomID = 2, HostPlayerUID = 2, Player1UID = 2, Player1NickName = "Test2"},
new Protobuf_Room_MiniInfo{ GameRomID = 3, RoomID = 3, HostPlayerUID = 3, Player1UID = 3, Player1NickName = "Test3"},
new Protobuf_Room_MiniInfo{ GameRomID = 4, RoomID = 4, HostPlayerUID = 4, Player1UID = 4, Player1NickName = "Test4"},
new Protobuf_Room_MiniInfo{ GameRomID = 5, RoomID = 5, HostPlayerUID = 5, Player1UID = 5, Player1NickName = "Test5"},
};
datas.Invoke(fakeData);
yield break;
}
}
}

View File

@ -47,7 +47,7 @@ namespace AxibugEmuOnline.Client
protected override MenuItem GetItemUIByIndex(int index)
{
return itemGroup.GetItemUIByDataIndex(index).GetComponent<MenuItem>();
return itemGroup.GetItemUIByDataIndex(index)?.GetComponent<MenuItem>();
}
protected override void Awake()
@ -63,13 +63,16 @@ namespace AxibugEmuOnline.Client
protected override bool OnCmdEnter()
{
var item = GetItemUIByIndex(SelectIndex);
return item.OnEnterItem();
if (item != null)
return item.OnEnterItem();
else
return true;
}
protected override void OnCmdBack()
{
var item = GetItemUIByIndex(SelectIndex);
item.OnExitItem();
item?.OnExitItem();
}
private void LateUpdate()

View File

@ -3,11 +3,7 @@ using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VirtualNes.Core;
using App = AxibugEmuOnline.Client.ClientCore.App;
namespace AxibugEmuOnline.Client
{
@ -15,7 +11,7 @@ namespace AxibugEmuOnline.Client
{
[SerializeField]
protected CanvasGroup RomGroupRoot;
private TweenerCore<float, float, FloatOptions> m_showTween;
@ -60,7 +56,16 @@ namespace AxibugEmuOnline.Client
var thirdMenuGroup = SubMenuItemGroup as ThirdMenuRoot;
thirdMenuGroup.itemGroup.Clear();
RefreshUI();
if (SubMenuItemGroup != null) SubMenuItemGroup.SetSelect(true);
return true;
}
protected void RefreshUI()
{
GetVirtualListDatas((datas) =>
{
var thirdMenuGroup = SubMenuItemGroup as ThirdMenuRoot;
@ -69,10 +74,6 @@ namespace AxibugEmuOnline.Client
thirdMenuGroup.itemGroup.UpdateProxyVisualState();
thirdMenuGroup.ResetToFirst();
});
if (SubMenuItemGroup != null) SubMenuItemGroup.SetSelect(true);
return true;
}
protected abstract void GetVirtualListDatas(Action<object> datas);