2022-04-28 18:01:51 +08:00
|
|
|
|
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;
|
2022-05-10 19:24:07 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
2022-04-28 18:01:51 +08:00
|
|
|
|
|
|
|
|
|
|
public class GameRoomDetailController : PFUIPanel
|
|
|
|
|
|
{
|
2022-08-05 15:10:09 +08:00
|
|
|
|
public Text versionText;
|
2022-04-28 18:01:51 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
2022-05-10 19:24:07 +08:00
|
|
|
|
public GameObject d2;
|
|
|
|
|
|
public GameObject d3;
|
|
|
|
|
|
public GameObject ar;
|
|
|
|
|
|
|
2022-04-28 18:01:51 +08:00
|
|
|
|
public GameRoomModel GameRoom { get; set; }
|
|
|
|
|
|
public DateTime? StartTime { get; set; }
|
|
|
|
|
|
public int Status { get; set; }
|
|
|
|
|
|
protected override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Start();
|
2022-05-10 19:24:07 +08:00
|
|
|
|
UIManager.AddBackHandler((e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
MapUDPService.SendGameRoomKick(GameRoom.RoomId,App.CurrentUser.Id,App.CurrentUser.Id);
|
|
|
|
|
|
App.gameRoomDetail = null;
|
|
|
|
|
|
});
|
2022-04-28 18:01:51 +08:00
|
|
|
|
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
|
|
|
|
|
|
Utils.DisplayHead(Avatar, App.CurrentUser.WxHeadImg);
|
|
|
|
|
|
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
var list = GameRoom.RoomPlayerList;
|
|
|
|
|
|
var notReady = list.Where(c => c.Status == 0 && c.IsOwner == false).Any();
|
2022-04-29 19:03:18 +08:00
|
|
|
|
if (notReady)
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
Utils.showToast(gameObject, App.GetLocalString("have to wait for all ready!"));
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.RoomId, App.CurrentUser.Id);
|
|
|
|
|
|
}
|
2022-04-28 18:01:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
//准备
|
|
|
|
|
|
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = 1;
|
|
|
|
|
|
readyBtn.SetActive(false);
|
|
|
|
|
|
cancelBtn.SetActive(true);
|
2022-05-10 19:24:07 +08:00
|
|
|
|
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
2022-04-28 18:01:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
//取消准备
|
|
|
|
|
|
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = 0;
|
|
|
|
|
|
readyBtn.SetActive(true);
|
|
|
|
|
|
cancelBtn.SetActive(false);
|
2022-05-10 19:24:07 +08:00
|
|
|
|
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
|
|
|
|
|
});
|
|
|
|
|
|
//退出
|
|
|
|
|
|
UIManager.AddEvent(quitBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
App.gameRoomDetail = null;
|
|
|
|
|
|
MapUDPService.SendGameRoomKick(GameRoom.RoomId, App.CurrentUser.Id, App.CurrentUser.Id);
|
|
|
|
|
|
UIManager.ShowGameRoomListPanel();
|
2022-04-28 18:01:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Show()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Show();
|
|
|
|
|
|
Init();
|
|
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
private bool DataSourceChanged { get; set; }
|
|
|
|
|
|
private void ListenerHandler(List<ReceiveMsgModel> message)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var detail = message.FirstOrDefault();
|
|
|
|
|
|
if (detail != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (detail.RoomList != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameRoom = detail.RoomList.Where(c => c.RoomId == GameRoom.RoomId).FirstOrDefault();
|
2022-05-25 18:40:47 +08:00
|
|
|
|
if (GameRoom != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataSourceChanged = true;
|
|
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-04-28 18:01:51 +08:00
|
|
|
|
float timer = 0f;
|
|
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
TcpHandler();
|
2022-04-28 18:01:51 +08:00
|
|
|
|
timer -= Time.deltaTime;
|
|
|
|
|
|
while (timer < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
timer += 1f;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Init()
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
App.Model = "GameRoom";
|
2022-08-05 15:10:09 +08:00
|
|
|
|
versionText.text = "V"+App.AppVersion.ToString();
|
2022-05-10 19:24:07 +08:00
|
|
|
|
MapUDPService.MessageListener = ListenerHandler;
|
|
|
|
|
|
GameRoom = App.gameRoomDetail;
|
|
|
|
|
|
|
|
|
|
|
|
var enable2d = !GameRoom.Enable3D && !GameRoom.EnableAR;
|
|
|
|
|
|
var enable3d = GameRoom.Enable3D && !GameRoom.EnableAR;
|
|
|
|
|
|
d2.SetActive(enable2d);
|
|
|
|
|
|
d3.SetActive(enable3d);
|
|
|
|
|
|
ar.SetActive(GameRoom.EnableAR);
|
|
|
|
|
|
|
|
|
|
|
|
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, 0, 1, GameRoom.RoomId.ToString());
|
2022-05-25 18:40:47 +08:00
|
|
|
|
var isOwner = GameRoom.UserId == App.CurrentUser.Id;
|
|
|
|
|
|
readyBtn.SetActive(!isOwner);
|
|
|
|
|
|
cancelBtn.SetActive(!isOwner);
|
|
|
|
|
|
startBtn.SetActive(isOwner);
|
2022-05-10 19:24:07 +08:00
|
|
|
|
|
|
|
|
|
|
idText.text = GameRoom.RoomId.ToString().PadLeft(7, '0');
|
2022-04-28 18:01:51 +08:00
|
|
|
|
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)}%";
|
2022-05-10 19:24:07 +08:00
|
|
|
|
//查询某线路最佳
|
|
|
|
|
|
var result = ConfigHelper.mapApi.GetMapBestInfo(GameRoom.MapRouteId);
|
|
|
|
|
|
if (result.result && !string.IsNullOrEmpty(result.data.BestNickName))
|
2022-04-28 18:01:51 +08:00
|
|
|
|
{
|
|
|
|
|
|
bestTab.SetActive(true);
|
2022-05-10 19:24:07 +08:00
|
|
|
|
bestTabName.text = result.data.BestNickName;
|
|
|
|
|
|
bestTabTimer.text = result.data.BestTotalTime;
|
|
|
|
|
|
Utils.DisplayHead(bestTabHead, result.data.BestWxHeadImg);
|
2022-04-28 18:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
|
|
|
|
|
|
2022-04-29 19:03:18 +08:00
|
|
|
|
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
2022-05-10 19:24:07 +08:00
|
|
|
|
foreach (var item in playerList)
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
if (GameRoom.MaxMembers - item.sort < 0)
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
item.NotInUse();
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
item.ShowInviteModal();
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
}
|
2022-05-25 18:40:47 +08:00
|
|
|
|
private bool isOwner { get; set; } = true;
|
2022-05-10 19:24:07 +08:00
|
|
|
|
private void TcpHandler()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DataSourceChanged)
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
|
|
|
|
|
var list = GameRoom.RoomPlayerList;
|
2022-05-25 18:40:47 +08:00
|
|
|
|
//自己是否是房主
|
2022-05-10 19:24:07 +08:00
|
|
|
|
var mine = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
2022-05-25 18:40:47 +08:00
|
|
|
|
if (mine != null && isOwner != mine.IsOwner)
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-25 18:40:47 +08:00
|
|
|
|
isOwner = mine.IsOwner;
|
|
|
|
|
|
readyBtn.SetActive(!isOwner);
|
|
|
|
|
|
startBtn.SetActive(isOwner);
|
|
|
|
|
|
cancelBtn.SetActive(!isOwner);
|
2022-05-10 19:24:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
//新增/更新
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
|
{
|
|
|
|
|
|
var userName =item.Name;
|
|
|
|
|
|
var headurl = item.WxHeadImage;
|
|
|
|
|
|
var ftp = item.FTP;
|
|
|
|
|
|
var weight = item.Weight;
|
|
|
|
|
|
var sex = item.Sex;
|
|
|
|
|
|
var current = playerList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
2022-04-29 19:03:18 +08:00
|
|
|
|
if (current == null)
|
|
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
var s = playerList.Where(c => c.UserId == 0 && c.NotUse == false).OrderBy(c => c.sort).FirstOrDefault();
|
|
|
|
|
|
if (s != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
s.Init(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
|
|
|
|
|
}
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
else
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
current.UpdatePlayer(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
//删除
|
|
|
|
|
|
foreach (var item in playerList)
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
if (item.UserId != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var current = list.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
|
|
|
|
|
if (current == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.ShowInviteModal();
|
|
|
|
|
|
}
|
|
|
|
|
|
var myself = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
2022-09-06 13:47:45 +08:00
|
|
|
|
//被移除房间 or 掉线
|
2022-05-10 19:24:07 +08:00
|
|
|
|
if (myself == null)
|
|
|
|
|
|
{
|
2022-09-06 13:47:45 +08:00
|
|
|
|
Utils.showToast(gameObject, App.GetLocalString("you have been kicked out of the room"));
|
2022-05-10 19:24:07 +08:00
|
|
|
|
UIManager.ShowGameRoomListPanel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
//收到服务器开始命令进入 loading页面
|
|
|
|
|
|
if (GameRoom.Status == 1)
|
2022-04-29 19:03:18 +08:00
|
|
|
|
{
|
2022-05-10 19:24:07 +08:00
|
|
|
|
//路线
|
|
|
|
|
|
App.RouteIdParam = GameRoom.MapRouteId;
|
2022-08-24 18:43:43 +08:00
|
|
|
|
App.MainSceneParam["Name"] = "GameRoomList";
|
2022-05-10 19:24:07 +08:00
|
|
|
|
if (GameRoom.EnableAR)
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneManager.LoadScene("VideoPlay");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneManager.LoadScene("Ride");
|
|
|
|
|
|
}
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
2022-05-10 19:24:07 +08:00
|
|
|
|
DataSourceChanged = false;
|
2022-04-29 19:03:18 +08:00
|
|
|
|
}
|
2022-04-28 18:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnDisable()
|
|
|
|
|
|
{
|
2022-08-05 15:10:09 +08:00
|
|
|
|
App.Model = "";
|
2022-04-28 18:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|