From 88db341f9d21b9e896806179aba9a48c78b62c14 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Thu, 7 Nov 2024 19:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E5=88=97=E8=A1=A8=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/Manager/AppRoom.cs | 6 +- .../Assets/Script/UI/RoomItem.cs | 59 ++++++++++++++----- .../Assets/Script/UI/RoomListMenuItem.cs | 10 ++++ 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs index ff479737..ec0f1033 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppRoom.cs @@ -204,12 +204,12 @@ namespace AxibugEmuOnline.Client.Manager if (msg.UpdateType == 0) { AddOrUpdateRoomList(msg.RoomMiniInfo); - Eventer.Instance.PostEvent(EEvent.OnRoomListSingleUpdate, msg.RoomMiniInfo.GameRomID); + Eventer.Instance.PostEvent(EEvent.OnRoomListSingleUpdate, msg.RoomMiniInfo.RoomID); } else { - RemoveRoomList(msg.RoomMiniInfo.GameRomID); - Eventer.Instance.PostEvent(EEvent.OnRoomListSingleClose, msg.RoomMiniInfo.GameRomID); + RemoveRoomList(msg.RoomMiniInfo.RoomID); + Eventer.Instance.PostEvent(EEvent.OnRoomListSingleClose, msg.RoomMiniInfo.RoomID); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs index 024e174a..56016ee0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs @@ -1,7 +1,7 @@ using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.Event; using AxibugEmuOnline.Client.UI; using AxibugProtobuf; -using System; using UnityEngine; using UnityEngine.UI; @@ -21,28 +21,55 @@ namespace AxibugEmuOnline.Client private RomFile m_romFile; public int Index { get; set; } + public int roomID { get; private set; } + protected override void Awake() + { + base.Awake(); + + Eventer.Instance.RegisterEvent(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate); + } + + protected override void OnDestroy() + { + Eventer.Instance.UnregisterEvent(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate); + } + + private void OnRoomSingleUpdate(int roomId) + { + if (roomId != roomID) return; + + if (App.roomMgr.GetRoomListMiniInfo(roomId, out var roomInfo)) + { + UpdateUI(roomInfo); + } + } public void SetData(object data) { - if (data is Protobuf_Room_MiniInfo roomInfo) + var roomInfo = data as Protobuf_Room_MiniInfo; + roomID = roomInfo.RoomID; + + UpdateUI(roomInfo); + } + + private void UpdateUI(Protobuf_Room_MiniInfo roomInfo) + { + var hostNick = roomInfo.GetHostNickName(); + roomInfo.GetRoomPlayers(out var cur, out var max); + SetBaseInfo(string.Empty, $"{hostNick}的房间 - {cur}/{max}"); + SetIcon(null); + + roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (romFile) => { - var hostNick = roomInfo.GetHostNickName(); - roomInfo.GetRoomPlayers(out var cur, out var max); - SetBaseInfo(string.Empty, $"{hostNick}的房间 - {cur}/{max}"); - SetIcon(null); + m_romFile = romFile; - roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (romFile) => - { - m_romFile = romFile; + if (romFile.ID == roomInfo.GameRomID) + Txt.text = romFile.Alias; - if (romFile.ID == roomInfo.GameRomID) - Txt.text = romFile.Alias; - - UpdateRomInfoView(); - App.CacheMgr.GetSpriteCache(romFile.ImageURL, OnGetRomImage); - }); - } + UpdateRomInfoView(); + App.CacheMgr.GetSpriteCache(romFile.ImageURL, OnGetRomImage); + }); } private void Update() diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs index 98ed0352..45149131 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs @@ -11,12 +11,15 @@ namespace AxibugEmuOnline.Client protected override void Awake() { Eventer.Instance.RegisterEvent(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll); + Eventer.Instance.RegisterEvent(EEvent.OnRoomListSingleClose, OnRoomClosed); base.Awake(); } + protected override void OnDestroy() { Eventer.Instance.UnregisterEvent(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll); + Eventer.Instance.UnregisterEvent(EEvent.OnRoomListSingleClose, OnRoomClosed); } public override bool OnEnterItem() @@ -40,6 +43,13 @@ namespace AxibugEmuOnline.Client RefreshUI(); } } + private void OnRoomClosed(int obj) + { + if (m_entering) + { + RefreshUI(); + } + } protected override void GetVirtualListDatas(Action datas) {