122 lines
3.1 KiB
C#
122 lines
3.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using Logic.Multilingual;
|
||
using TH1_Logic.Net;
|
||
using TH1_Logic.Steam;
|
||
using TH1Renderer;
|
||
using TH1Resource;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using RuntimeData;
|
||
using TH1_Logic.Core;
|
||
using UnityEngine.Serialization;
|
||
|
||
namespace TH1_UI.View.Bottom
|
||
{
|
||
public class UIBottomNetView : Base.View
|
||
{
|
||
public ViDelegateAssisstant.Dele OnBtnCloseClick;
|
||
|
||
public GameObject NetRowPrefab;
|
||
public RectTransform NetRowContainer;
|
||
// NetInfo related
|
||
public Transform NetInfo;
|
||
|
||
private List<UIBottomNetRowMono> _netInfoRowList = null;
|
||
private bool _initialized = false;
|
||
protected override void OnInit()
|
||
{
|
||
base.OnInit();
|
||
_netInfoRowList = new List<UIBottomNetRowMono>();
|
||
}
|
||
|
||
public void SetContent()
|
||
{
|
||
Init();
|
||
UpdateView();
|
||
}
|
||
|
||
//Init将确定进入游戏时所有房间成员的状态,除非有新成员加入,否则不会删减
|
||
private void Init()
|
||
{
|
||
_initialized = true;
|
||
if(Main.MapData == null) return;
|
||
bool isMulti = Main.MapData.Net.Mode == NetMode.Multi;
|
||
NetInfo.gameObject.SetActive(isMulti);
|
||
if (!isMulti) return;
|
||
|
||
var lobbyInfo = LobbyManager.Instance.Lobby as SteamLobbyManager;
|
||
if (lobbyInfo == null) return;
|
||
var mids = lobbyInfo.GetAllMemberInfo();
|
||
while (_netInfoRowList.Count < mids.Count)
|
||
{
|
||
var obj = Instantiate(NetRowPrefab, NetRowContainer);
|
||
var cpn = obj.GetComponent<UIBottomNetRowMono>();
|
||
if (cpn == null) break;
|
||
_netInfoRowList.Add(cpn);
|
||
}
|
||
|
||
int i = 0;
|
||
foreach(var pair in mids)
|
||
{
|
||
_netInfoRowList[i].gameObject.SetActive(true);
|
||
_netInfoRowList[i].SetContent(pair.Key, pair.Value, pair.Key == lobbyInfo.GetLobbyOwnerId(), true);
|
||
i++;
|
||
}
|
||
while(i < _netInfoRowList.Count)
|
||
{
|
||
_netInfoRowList[i].gameObject.SetActive(false);
|
||
i++;
|
||
}
|
||
}
|
||
|
||
//UpdateView只会修改NetStatus和房主标记
|
||
public void UpdateView()
|
||
{
|
||
|
||
if (!_initialized) return;
|
||
if(Main.MapData == null) return;
|
||
bool isMulti = Main.MapData.Net.Mode == NetMode.Multi;
|
||
NetInfo.gameObject.SetActive(isMulti);
|
||
if (!isMulti) return;
|
||
|
||
var lobbyInfo = LobbyManager.Instance.Lobby as SteamLobbyManager;
|
||
if (lobbyInfo == null) return;
|
||
var mids = lobbyInfo.GetAllMemberInfo();
|
||
|
||
//如果发现人数变多了,重新Init(比如继续一个3人局游戏,开始进来的时候只有2人
|
||
if (mids.Count > _netInfoRowList.Count)
|
||
Init();
|
||
|
||
for (int i = 0; i < _netInfoRowList.Count; i++)
|
||
{
|
||
if (!_netInfoRowList[i].gameObject.activeSelf) break;
|
||
bool isOnline = false;
|
||
bool isRoomOwner = false;
|
||
foreach(var pair in mids)
|
||
if (pair.Key == _netInfoRowList[i].MemberId)
|
||
{
|
||
isOnline = true;
|
||
isRoomOwner = pair.Key == lobbyInfo.GetLobbyOwnerId();
|
||
break;
|
||
}
|
||
_netInfoRowList[i].UpdateNetStatus(isRoomOwner, isOnline);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
UpdateView();
|
||
}
|
||
|
||
public void CloseView()
|
||
{
|
||
_initialized = false;
|
||
//AudioManager.Instance.StopMusic();
|
||
}
|
||
}
|
||
}
|