powerfun-unity/Assets/Scripts/UI/Prefab/GameRoom/GameRoomPlayerPanel.cs

120 lines
3.1 KiB
C#

using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
class GameRoomPlayerPanel : MonoBehaviour
{
public Text userNametxt;
public Text weigthTxt;
public Text ftpTxt;
public RawImage head;
public GameObject owner;
public GameObject playerModal;
public GameObject notInUseModal;
public GameObject inviteModal;
public GameObject kickModal;
public GameObject me;
public GameObject ready;
public GameObject kickBtn;
public GameObject cancelBtn;
public int sort;
public int UserId { get; set; }
private void Start()
{
var manager = FindObjectOfType<GameRoomDetailController>();
var inviteBtn = inviteModal.transform.Find("InviteBtn").gameObject;
UIManager.AddEvent(inviteBtn,EventTriggerType.PointerClick,(e)=> {
Utils.CopyToClipboard($"GameRoom/{manager.GameRoom.Id}");
Utils.showToast(transform.parent.gameObject, App.GetLocalString("copy to clipboard successfully!"));
});
UIManager.AddEvent(gameObject, EventTriggerType.PointerClick, (e) =>
{
kickModal.SetActive(true);
});
UIManager.AddEvent(cancelBtn, EventTriggerType.PointerExit, (e) =>
{
kickModal.SetActive(false);
});
UIManager.AddEvent(kickBtn, EventTriggerType.PointerClick, (e) =>
{
MapUDPService.SendGameRoomKick(App.gameRoomDetail.Id, UserId, App.CurrentUser.Id);
});
}
public void Init(int userId, string userName,string headUrl,double weight, float ftp,bool isOwner,int Status)
{
UserId = userId;
inviteModal.SetActive(false);
notInUseModal.SetActive(false);
Utils.DisplayHead(head, headUrl);
userNametxt.text = userName;
weigthTxt.text = weight.ToString();
ftpTxt.text = ftp.ToString();
me.SetActive(App.CurrentUser.Id == userId);
owner.SetActive(isOwner);
//Show ready
ready.SetActive(!isOwner && Status == 1);
}
public void UpdatePlayer(int userId, string userName, string headUrl, double weight, float ftp, bool isOwner, int Status)
{
UserId = userId;
inviteModal.SetActive(false);
notInUseModal.SetActive(false);
userNametxt.text = userName;
weigthTxt.text = weight.ToString();
ftpTxt.text = ftp.ToString();
me.SetActive(App.CurrentUser.Id == userId);
owner.SetActive(isOwner);
ready.SetActive(!isOwner && Status == 1);
}
private void Update()
{
}
public void Ready()
{
ready.SetActive(true);
}
public void UnReady()
{
ready.SetActive(false);
}
public void ForceQuit()
{
//TODO:踢人
NotInUse();
}
public void ShowQuitModal()
{
kickModal.SetActive(true);
}
public void ShowInviteModal()
{
UserId = 0;
inviteModal.SetActive(true);
}
public void NotInUse()
{
UserId = 0;
notInUseModal.SetActive(true);
}
public void Me()
{
me.SetActive(true);
}
}