204 lines
6.5 KiB
C#
204 lines
6.5 KiB
C#
using Assets.Scenes.Ride.Scripts;
|
|
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameRoomDetailController : PFUIPanel
|
|
{
|
|
|
|
public RawImage Avatar;
|
|
public Text idText;
|
|
public Text roomName;
|
|
public Text routeName;
|
|
public Text distanceText;
|
|
public Text eleText;
|
|
public Text slopeText;
|
|
public Text rideText;
|
|
public RawImage altitudeGraph;
|
|
|
|
public GameObject bestTab;
|
|
public Text bestTabName;
|
|
public Text bestTabTimer;
|
|
public RawImage bestTabHead;
|
|
|
|
public GameObject readyBtn;
|
|
public GameObject startBtn;
|
|
public GameObject quitBtn;
|
|
public GameObject cancelBtn;
|
|
|
|
|
|
|
|
public GameRoomModel GameRoom { get; set; }
|
|
public DateTime? StartTime { get; set; }
|
|
public int Status { get; set; }
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
|
|
Utils.DisplayHead(Avatar, App.CurrentUser.WxHeadImg);
|
|
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
var startTime = UIManager.Now.GetDateTime().ToUniversalTime().AddMilliseconds(10);
|
|
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.Id, startTime);
|
|
});
|
|
//准备
|
|
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
Status = 1;
|
|
readyBtn.SetActive(false);
|
|
cancelBtn.SetActive(true);
|
|
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.Id, App.CurrentUser.Id, Status);
|
|
});
|
|
//取消准备
|
|
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
Status = 0;
|
|
readyBtn.SetActive(true);
|
|
cancelBtn.SetActive(false);
|
|
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.Id, App.CurrentUser.Id, Status);
|
|
});
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
GameRoom = App.gameRoomDetail;
|
|
Init();
|
|
}
|
|
float timer = 0f;
|
|
private void Update()
|
|
{
|
|
timer -= Time.deltaTime;
|
|
while (timer < 0)
|
|
{
|
|
MapUDPService.Send(0, App.CurrentUser.Id, new double[] { 0d, 0d }, competitionId: 0, roomId: GameRoom.Id);
|
|
var list = MapUDPService.GetGameRoomList(GameRoom.Id);
|
|
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
|
//自己
|
|
var mine = list.Where(c => c.RoomDetail.UserId == App.CurrentUser.Id).FirstOrDefault();
|
|
if (mine != null)
|
|
{
|
|
//是否是房主
|
|
var owner = mine.RoomDetail.IsOwner;
|
|
readyBtn.SetActive(!owner);
|
|
startBtn.SetActive(owner);
|
|
//是否准备
|
|
//readyBtn.SetActive(!owner && mine.RoomDetail.Status == 0);
|
|
//cancelBtn.SetActive(!owner && mine.RoomDetail.Status == 1);
|
|
}
|
|
//新增/更新
|
|
foreach (var item in list)
|
|
{
|
|
var current = playerList.Where(c => c.UserId == item.Id).FirstOrDefault();
|
|
if (current == null)
|
|
{
|
|
var s = playerList.Where(c => c.UserId == 0).OrderBy(c=>c.sort).FirstOrDefault();
|
|
if (s != null)
|
|
{
|
|
s.Init(item.Id,item.Name, item.HeadImage, item.Weight, item.FTP, item.RoomDetail.IsOwner, item.RoomDetail.Status);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
current.UpdatePlayer(item.Id, item.Name, item.HeadImage, item.Weight, item.FTP, item.RoomDetail.IsOwner,item.RoomDetail.Status);
|
|
}
|
|
}
|
|
//删除
|
|
foreach (var item in playerList)
|
|
{
|
|
if (item.UserId != 0)
|
|
{
|
|
var current = list.Where(c => c.Id == item.UserId).FirstOrDefault();
|
|
if (current == null)
|
|
{
|
|
item.ShowInviteModal();
|
|
}
|
|
var myself = list.Where(c => c.RoomDetail.UserId == App.CurrentUser.Id).FirstOrDefault();
|
|
if (myself == null)
|
|
{
|
|
Utils.showToast(gameObject,App.GetLocalString("you've been kicked out of the room"));
|
|
UIManager.ShowGameRoomListPanel();
|
|
}
|
|
}
|
|
}
|
|
|
|
////监听startTime
|
|
//var msg = list.Where(c => c.RoomDetail != null && c.RoomDetail.s.HasValue).FirstOrDefault();
|
|
//if (msg != null)
|
|
//{
|
|
// StartTime = msg.StartTime.Value.ToLocalTime();
|
|
// Debug.Log(StartTime);
|
|
//}
|
|
//倒计时
|
|
|
|
|
|
//4.更换房间房主
|
|
|
|
//5.标记当前用户
|
|
|
|
timer += 1f;
|
|
}
|
|
}
|
|
private void Init()
|
|
{
|
|
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
//TODO:
|
|
});
|
|
UIManager.AddEvent(quitBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
//TODO:
|
|
});
|
|
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
//TODO:
|
|
});
|
|
idText.text = GameRoom.Id.ToString().PadLeft(7, '0');
|
|
roomName.text = GameRoom.Name;
|
|
routeName.text = GameRoom.MapRouteName;
|
|
distanceText.text = $"{Math.Round(GameRoom.Distance, 1)}KM";
|
|
eleText.text = $"{Math.Round(GameRoom.TotalClimb, 0)}M";
|
|
slopeText.text = $"{Math.Round(GameRoom.AverageGrade, 1)}%";
|
|
if (!string.IsNullOrEmpty(GameRoom.BestNickName))
|
|
{
|
|
bestTab.SetActive(true);
|
|
bestTabName.text = GameRoom.BestNickName;
|
|
bestTabTimer.text = GameRoom.BestTotalTime;
|
|
Utils.DisplayHead(bestTabHead, GameRoom.BestWxHeadImg);
|
|
}
|
|
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
|
}
|
|
|
|
public void Ready()
|
|
{
|
|
|
|
}
|
|
|
|
public void Quit()
|
|
{
|
|
|
|
}
|
|
|
|
public void NotInUse()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
protected override void OnDisable()
|
|
{
|
|
App.gameRoomDetail = null;
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
App.gameRoomDetail = null;
|
|
}
|
|
}
|