对战初步完成
This commit is contained in:
1 parent
b0c0890ca3
commit
509c309252
55 files changed
+7079
-6748
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameRoomCountDownController : PFUIPanel
|
||||
{
|
||||
public Text count;
|
||||
|
||||
private int Seconds { get; set; }
|
||||
public GameRoomModel GameRoom { get; set; }
|
||||
|
||||
private Action Callback { get; set; }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
}
|
||||
|
||||
public void Init(int seconds,Action action)
|
||||
{
|
||||
Seconds = seconds;
|
||||
Callback = action;
|
||||
}
|
||||
|
||||
float timer = 0f;
|
||||
private void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
while (timer < 0)
|
||||
{
|
||||
if (Seconds == 0)
|
||||
{
|
||||
Callback?.Invoke();
|
||||
}
|
||||
if (Seconds < 0)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
count.text = Seconds.ToString();
|
||||
Seconds--;
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b84f9a966f56dc54d8e49acc631ae62f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
|
||||
public class GameRoomDetailController : PFUIPanel
|
||||
{
|
||||
@@ -31,27 +32,35 @@ public class GameRoomDetailController : PFUIPanel
|
||||
public GameObject quitBtn;
|
||||
public GameObject cancelBtn;
|
||||
|
||||
public GameObject d2;
|
||||
public GameObject d3;
|
||||
public GameObject ar;
|
||||
|
||||
public GameRoomModel GameRoom { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public int Status { get; set; }
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
UIManager.AddBackHandler((e) =>
|
||||
{
|
||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId,App.CurrentUser.Id,App.CurrentUser.Id);
|
||||
App.gameRoomDetail = null;
|
||||
});
|
||||
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
|
||||
Utils.DisplayHead(Avatar, App.CurrentUser.WxHeadImg);
|
||||
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
//判断房间内的人是否都准备
|
||||
var list = MapUDPService.GetGameRoomList(GameRoom.Id);
|
||||
var notReady = list.Where(c => c.RoomDetail.Status == 0 && c.RoomDetail.IsOwner == false).Any();
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
var notReady = list.Where(c => c.Status == 0 && c.IsOwner == false).Any();
|
||||
if (notReady)
|
||||
{
|
||||
Utils.showToast(gameObject,App.GetLocalString("have to wait for all ready!"));
|
||||
Utils.showToast(gameObject, App.GetLocalString("have to wait for all ready!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.Id, App.CurrentUser.Id);
|
||||
}
|
||||
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.RoomId, App.CurrentUser.Id);
|
||||
}
|
||||
});
|
||||
//准备
|
||||
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
@@ -59,7 +68,7 @@ public class GameRoomDetailController : PFUIPanel
|
||||
Status = 1;
|
||||
readyBtn.SetActive(false);
|
||||
cancelBtn.SetActive(true);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.Id, App.CurrentUser.Id, Status);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||
});
|
||||
//取消准备
|
||||
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
@@ -67,133 +76,180 @@ public class GameRoomDetailController : PFUIPanel
|
||||
Status = 0;
|
||||
readyBtn.SetActive(true);
|
||||
cancelBtn.SetActive(false);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.Id, App.CurrentUser.Id, Status);
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
GameRoom = App.gameRoomDetail;
|
||||
Init();
|
||||
}
|
||||
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();
|
||||
DataSourceChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
float timer = 0f;
|
||||
private void Update()
|
||||
{
|
||||
TcpHandler();
|
||||
timer -= Time.deltaTime;
|
||||
while (timer < 0)
|
||||
{
|
||||
TcpHandler();
|
||||
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');
|
||||
App.Model = "GameRoom";
|
||||
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);
|
||||
|
||||
DataSourceChanged = true;
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, 0, 1, GameRoom.RoomId.ToString());
|
||||
readyBtn.SetActive(true);
|
||||
cancelBtn.SetActive(false);
|
||||
startBtn.SetActive(false);
|
||||
|
||||
idText.text = GameRoom.RoomId.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))
|
||||
//查询某线路最佳
|
||||
var result = ConfigHelper.mapApi.GetMapBestInfo(GameRoom.MapRouteId);
|
||||
if (result.result && !string.IsNullOrEmpty(result.data.BestNickName))
|
||||
{
|
||||
bestTab.SetActive(true);
|
||||
bestTabName.text = GameRoom.BestNickName;
|
||||
bestTabTimer.text = GameRoom.BestTotalTime;
|
||||
Utils.DisplayHead(bestTabHead, GameRoom.BestWxHeadImg);
|
||||
bestTabName.text = result.data.BestNickName;
|
||||
bestTabTimer.text = result.data.BestTotalTime;
|
||||
Utils.DisplayHead(bestTabHead, result.data.BestWxHeadImg);
|
||||
}
|
||||
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
||||
|
||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||
foreach (var item in playerList)
|
||||
{
|
||||
if (GameRoom.MaxMembers - item.sort < 0)
|
||||
{
|
||||
item.NotInUse();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.ShowInviteModal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TcpHandler()
|
||||
{
|
||||
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)
|
||||
if (DataSourceChanged)
|
||||
{
|
||||
//是否是房主
|
||||
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 playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
//自己
|
||||
var mine = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
||||
if (mine != 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);
|
||||
}
|
||||
//是否是房主
|
||||
var owner = mine.IsOwner;
|
||||
readyBtn.SetActive(!owner);
|
||||
startBtn.SetActive(owner);
|
||||
}
|
||||
else
|
||||
//新增/更新
|
||||
foreach (var item in list)
|
||||
{
|
||||
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();
|
||||
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();
|
||||
if (current == null)
|
||||
{
|
||||
item.ShowInviteModal();
|
||||
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);
|
||||
}
|
||||
}
|
||||
var myself = list.Where(c => c.RoomDetail.UserId == App.CurrentUser.Id).FirstOrDefault();
|
||||
if (myself == null)
|
||||
else
|
||||
{
|
||||
Utils.showToast(gameObject, App.GetLocalString("you've been kicked out of the room"));
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
current.UpdatePlayer(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||
}
|
||||
}
|
||||
}
|
||||
//收到服务器开始命令进入 loading页面
|
||||
var roomStart = list.Where(c => c.Room != null && c.Room.Status == 1).FirstOrDefault();
|
||||
if (roomStart != null)
|
||||
{
|
||||
//UIManager.ShowGameRoomLoadingPanel();
|
||||
//路线
|
||||
App.RouteIdParam = GameRoom.MapRouteId;
|
||||
if (GameRoom.EnableAR)
|
||||
//删除
|
||||
foreach (var item in playerList)
|
||||
{
|
||||
SceneManager.LoadScene("VideoPlay");
|
||||
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();
|
||||
//被移除房间 or 掉线 or
|
||||
if (myself == null)
|
||||
{
|
||||
//Utils.showToast(gameObject, App.GetLocalString("you've been kicked out of the room"));
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
//收到服务器开始命令进入 loading页面
|
||||
if (GameRoom.Status == 1)
|
||||
{
|
||||
SceneManager.LoadScene("Ride");
|
||||
//路线
|
||||
App.RouteIdParam = GameRoom.MapRouteId;
|
||||
if (GameRoom.EnableAR)
|
||||
{
|
||||
SceneManager.LoadScene("VideoPlay");
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneManager.LoadScene("Ride");
|
||||
}
|
||||
}
|
||||
DataSourceChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
//App.gameRoomDetail = null;
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
//App.gameRoomDetail = null;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scripts.UI.Control;
|
||||
using Assets.Scripts.UI.Prefab.MapList;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
@@ -63,6 +67,10 @@ public class GameRoomListController : PFUIPanel
|
||||
private GameObject btn6;
|
||||
|
||||
private Transform enterRoomModal;
|
||||
private Transform cycingRoomModal;
|
||||
private Transform resultRoomModal;
|
||||
|
||||
private GameObject RoomRankItem;
|
||||
|
||||
private string RoomName;
|
||||
private string Roompwd;
|
||||
@@ -72,9 +80,93 @@ public class GameRoomListController : PFUIPanel
|
||||
private int Members;
|
||||
private GameRoomModel GameRoom;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
RectTransform _rectTransform;
|
||||
|
||||
[SerializeField]
|
||||
InputField _searchInputField;
|
||||
|
||||
[SerializeField]
|
||||
GameObject _searchBtn;
|
||||
|
||||
private GameObject RoomCell { get; set; }
|
||||
|
||||
//Dummy data List
|
||||
private List<GameRoomModel> _list = new List<GameRoomModel>();
|
||||
|
||||
private string seachName = "";
|
||||
private bool ListChanged = false;
|
||||
private bool CreateRoomSuccessed = false;
|
||||
PFUIPageHelper pageHelper;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
RoomRankItem = Resources.Load<GameObject>("UI/Prefab/GameRoom/RoomRankItem");
|
||||
|
||||
RoomCell = Resources.Load<GameObject>("UI/Prefab/GameRoom/Room");
|
||||
//分页
|
||||
pageHelper = FindObjectOfType<PFUIPageHelper>();
|
||||
pageHelper.PageIndex = 0;
|
||||
pageHelper.PageSize = 6;
|
||||
pageHelper.Register((e) =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
|
||||
_searchInputField.onValueChanged.AddListener((e) => { seachName = e; });
|
||||
_searchInputField.onEndEdit.AddListener((e) => {
|
||||
seachName = e;
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
});
|
||||
UIManager.AddEvent(_searchBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Search);
|
||||
}
|
||||
private void Search(BaseEventData data)
|
||||
{
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
}
|
||||
private void Refreash()
|
||||
{
|
||||
Utils.DestroyChildren(_rectTransform);
|
||||
if (list == null)
|
||||
return;
|
||||
int index = 0;
|
||||
foreach (var item in list)
|
||||
{
|
||||
index++;
|
||||
var g = Instantiate(RoomCell, _rectTransform);
|
||||
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
||||
}
|
||||
pageHelper.Total = 10;
|
||||
pageHelper.Build();
|
||||
}
|
||||
List<GameRoomModel> list;
|
||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||
{
|
||||
try
|
||||
{
|
||||
//查询列表
|
||||
var roomList = message.Where(c => c.RoomList != null).FirstOrDefault();
|
||||
if (roomList != null)
|
||||
{
|
||||
list = roomList.RoomList;
|
||||
ListChanged = true;
|
||||
}
|
||||
//查询自己当前创建的房间信息并进入
|
||||
var info = message.Where(c => c.RoomList.Where(o => o.UserId == App.CurrentUser.Id).Any()).FirstOrDefault();
|
||||
if (info != null)
|
||||
{
|
||||
GameRoom = info.RoomList[0];
|
||||
App.gameRoomDetail = GameRoom;
|
||||
CreateRoomSuccessed = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
protected override void Start()
|
||||
{
|
||||
@@ -86,30 +178,41 @@ public class GameRoomListController : PFUIPanel
|
||||
|
||||
MapList = transform.Find("MapList").gameObject;
|
||||
enterRoomModal = transform.Find("EnterRoomModal");
|
||||
cycingRoomModal = transform.Find("GameRoomInProgress");
|
||||
resultRoomModal = transform.Find("GameRoomDone");
|
||||
|
||||
InitStep1();
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
App.Model = "GameRoom";
|
||||
MapUDPService.MessageListener = ListenerHandler;
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
}
|
||||
float timer = 1f;
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
timer -= Time.deltaTime;
|
||||
if (cycingRoomModal.gameObject.activeSelf)
|
||||
{
|
||||
if (scroll.GetComponent<ScrollRect>().verticalNormalizedPosition <= 0 ||
|
||||
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1))
|
||||
{
|
||||
startMouse = true;
|
||||
}
|
||||
var s = UIManager.Now.GetDateTime() - modelGameRoom.StartTime.Value.ToLocalTime();
|
||||
CyclingTimer.text = Helper.FormatTicks((int)s.TotalSeconds);
|
||||
}
|
||||
else
|
||||
while (timer < 0)
|
||||
{
|
||||
if (startMouse)
|
||||
if (ListChanged)
|
||||
{
|
||||
startMouse = false;
|
||||
OnEndDrag(null);
|
||||
Refreash();
|
||||
ListChanged = false;
|
||||
}
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
|
||||
{
|
||||
onEndEdit();
|
||||
if (CreateRoomSuccessed & CreateClicked)
|
||||
{
|
||||
CreateRoomSuccessed = false;
|
||||
CreateClicked = false;
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
}
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
private void InitStep1()
|
||||
@@ -128,6 +231,8 @@ public class GameRoomListController : PFUIPanel
|
||||
distanceOptions = topContainer.Find("distanceOptions");
|
||||
if (distanceOptions != null)
|
||||
{
|
||||
distance = "";
|
||||
distanceOptions.GetComponent<Dropdown>().value = 0;
|
||||
var dDropdown = distanceOptions.GetComponent<Dropdown>();
|
||||
dDropdown.options = MapFilterOptions.distances;
|
||||
dDropdown.onValueChanged.AddListener(ChangeDistance);
|
||||
@@ -138,6 +243,9 @@ public class GameRoomListController : PFUIPanel
|
||||
//是否是3d
|
||||
if (tdContainer != null)
|
||||
{
|
||||
var g = tdContainer.Find("Gou").gameObject;
|
||||
g.SetActive(false);
|
||||
is3d = false;
|
||||
UIManager.AddEvent(tdContainer.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
var gou = tdContainer.Find("Gou").gameObject;
|
||||
@@ -150,6 +258,9 @@ public class GameRoomListController : PFUIPanel
|
||||
//是否收藏
|
||||
if (favContainer != null)
|
||||
{
|
||||
var g = favContainer.Find("Gou").gameObject;
|
||||
g.SetActive(false);
|
||||
isFav = false;
|
||||
UIManager.AddEvent(favContainer.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
var gou = favContainer.Find("Gou").gameObject;
|
||||
@@ -163,6 +274,8 @@ public class GameRoomListController : PFUIPanel
|
||||
searchInput = topContainer.Find("SearchInput");
|
||||
if (searchInput != null)
|
||||
{
|
||||
searchInput.GetComponent<InputField>().text = "";
|
||||
ftname = "";
|
||||
searchInput.GetComponent<InputField>().onEndEdit.AddListener((s) =>
|
||||
{
|
||||
var t = searchInput.GetComponent<InputField>().text;
|
||||
@@ -178,11 +291,16 @@ public class GameRoomListController : PFUIPanel
|
||||
var diffOptions = topContainer.Find("DifficultyContainer");
|
||||
if (diffOptions != null)
|
||||
{
|
||||
hands = new List<string>();
|
||||
foreach (Transform t in diffOptions)
|
||||
{
|
||||
var button = t.GetComponent<Button>();
|
||||
var image = t.GetComponent<Image>();
|
||||
var text = t.Find("Text").GetComponent<Text>();
|
||||
|
||||
ColorUtility.TryParseHtmlString("#23232D", out Color cc);
|
||||
image.color = cc;
|
||||
text.color = new Color(1, 1, 1, 1);
|
||||
UIManager.AddEvent(button.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
ColorUtility.TryParseHtmlString("#23232D", out Color c1);
|
||||
@@ -291,19 +409,19 @@ public class GameRoomListController : PFUIPanel
|
||||
HandleStepBtn(previous.name);
|
||||
});
|
||||
|
||||
UIManager.AddEvent(create, EventTriggerType.PointerClick, async (e) =>
|
||||
UIManager.AddEvent(create, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
var result = await ConfigHelper.GameRoomApi.Add(RoomName,selectedRouteId,Roompwd,UIManager.Now.GetDateTime(),CloseTime,Members);
|
||||
if (result.result)
|
||||
{
|
||||
MapList.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.ShowAlert("error", result.errMsg);
|
||||
}
|
||||
MapUDPService.SendCreateGameRoom(RoomName, selectedRouteId, Roompwd, UIManager.Now.GetDateTime(), CloseTime, Members, Map.AverageGrade, (Map.TotalClimb ?? 0), Map.Distance, Map.Enable3D, Map.EnableAR, Map.Name, Map.FileName, Map.Url, Map.AltitudeGraph);
|
||||
MapList.SetActive(false);
|
||||
CreateClicked = true;
|
||||
});
|
||||
}
|
||||
private bool CreateClicked { get; set; }
|
||||
private void ResetMapList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void InitStep2()
|
||||
{
|
||||
//关门时间
|
||||
@@ -322,6 +440,16 @@ public class GameRoomListController : PFUIPanel
|
||||
var minInputField = right2.transform.Find("MinInputField").GetComponent<InputField>();
|
||||
var roomNameInputField = right2.transform.Find("RoomNameInputField").GetComponent<InputField>();
|
||||
var passwordInputField = right2.transform.Find("PasswordInputField").GetComponent<InputField>();
|
||||
hourInputField.text = "0";
|
||||
minInputField.text = "0";
|
||||
roomNameInputField.text = "";
|
||||
passwordInputField.text = "";
|
||||
RoomName = "";
|
||||
Roompwd = "";
|
||||
hourInputField.GetComponent<Outline>().enabled = false;
|
||||
HandleFormInput();
|
||||
HandleCloseTimeBtnClick(0, "");
|
||||
HandleMembersBtnClick(0, "");
|
||||
//房间名
|
||||
roomNameInputField.onValueChanged.AddListener((e) => {
|
||||
RoomName = e;
|
||||
@@ -336,11 +464,10 @@ public class GameRoomListController : PFUIPanel
|
||||
hourInputField.GetComponent<Outline>().enabled = true;
|
||||
HandleFormInput();
|
||||
});
|
||||
|
||||
UIManager.AddEvent(btn30,EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
HandleCloseTimeBtnClick(30, btn30.name);
|
||||
});
|
||||
UIManager.AddEvent(btn30, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
HandleCloseTimeBtnClick(30, btn30.name);
|
||||
});
|
||||
UIManager.AddEvent(btn40, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
HandleCloseTimeBtnClick(40, btn40.name);
|
||||
@@ -420,7 +547,7 @@ public class GameRoomListController : PFUIPanel
|
||||
create.GetComponent<Button>().enabled = false;
|
||||
}
|
||||
}
|
||||
private void HandleCloseTimeBtnClick(int closeTime,string btnName)
|
||||
private void HandleCloseTimeBtnClick(int closeTime, string btnName)
|
||||
{
|
||||
ColorUtility.TryParseHtmlString("#3D3E4D", out Color grey);
|
||||
ColorUtility.TryParseHtmlString("#F93086", out Color pink);
|
||||
@@ -431,7 +558,7 @@ public class GameRoomListController : PFUIPanel
|
||||
btn60.GetComponent<Image>().color = btn60.name == btnName ? pink : grey;
|
||||
HandleFormInput();
|
||||
}
|
||||
private void HandleMembersBtnClick(int members,string btnName)
|
||||
private void HandleMembersBtnClick(int members, string btnName)
|
||||
{
|
||||
ColorUtility.TryParseHtmlString("#3D3E4D", out Color grey);
|
||||
ColorUtility.TryParseHtmlString("#F93086", out Color pink);
|
||||
@@ -474,49 +601,114 @@ public class GameRoomListController : PFUIPanel
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + "/" + fileName;
|
||||
var download = transform.Find("DownloadPanel").gameObject;
|
||||
if (!File.Exists(filepath))
|
||||
if (GameRoom.EnableAR && !File.Exists(filepath))
|
||||
{
|
||||
download.SetActive(true);
|
||||
download.GetComponent<GameRoomDownLoad>().Init(RoomId, GameRoom.FileName, GameRoom.FileUrl, this);
|
||||
}
|
||||
else
|
||||
GetInRoom();
|
||||
}
|
||||
|
||||
private GameRoomModel modelGameRoom { get; set; }
|
||||
//private GameRoomModel modelGameRoom { get; set; }
|
||||
private Text CyclingTimer { get; set; }
|
||||
public void ShowCycingPanel(GameRoomModel gameRoomModel)
|
||||
{
|
||||
ShowStatusModal(cycingRoomModal, gameRoomModel);
|
||||
//倒计时
|
||||
modelGameRoom = gameRoomModel;
|
||||
CyclingTimer = cycingRoomModal.Find("Modal/Timer").GetComponent<Text>();
|
||||
}
|
||||
public void ShowDonePanel(int roomId)
|
||||
{
|
||||
var result = ConfigHelper.GameRoomApi.GetDetail(roomId);
|
||||
if (result.result)
|
||||
{
|
||||
if (File.Exists(filepath))
|
||||
ShowStatusModal(resultRoomModal, result.data);
|
||||
resultRoomModal.Find("Modal/EndTime").GetComponent<Text>().text = result.data.EndTime.HasValue?result.data.EndTime.Value.ToLocalTime().ToString(): "--:--:--";
|
||||
//排行榜
|
||||
var list = result.data.RoomRankingList;
|
||||
var content = resultRoomModal.Find("Modal/Scroll View/Viewport/Content");
|
||||
Utils.DestroyChildren(content);
|
||||
foreach (var item in list)
|
||||
{
|
||||
GetInRoom();
|
||||
var t = Instantiate(RoomRankItem, content);
|
||||
t.transform.Find("Bg").gameObject.SetActive(App.CurrentUser.Id == item.UserId);
|
||||
t.transform.Find("Rank").GetComponent<Text>().text = item.Rank.ToString().PadLeft(2,'0');
|
||||
Utils.DisplayImage(t.transform.Find("Head").GetComponent<RawImage>(), item.WxHeadImg);
|
||||
t.transform.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImageByName(item.Country);
|
||||
t.transform.Find("Name").GetComponent<Text>().text = item.NickName;
|
||||
t.transform.Find("Timer").GetComponent<Text>().text = item.TotalTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ShowStatusModal(Transform tr,GameRoomModel data)
|
||||
{
|
||||
tr.Find("Modal/Id").GetComponent<Text>().text = data.RoomId.ToString().PadLeft(7, '0');
|
||||
tr.Find("Modal/RoomName").GetComponent<Text>().text = data.Name;
|
||||
tr.Find("Modal/RouteName").GetComponent<Text>().text = data.MapRouteName;
|
||||
var graph = tr.Find("Modal/AltitudeGraph").GetComponent<RawImage>();
|
||||
var bestHead = tr.Find("Modal/BestTab/Head").GetComponent<RawImage>();
|
||||
var bestName = tr.Find("Modal/BestTab/NickName").GetComponent<Text>();
|
||||
var bestTimer = tr.Find("Modal/BestTab/Timer").GetComponent<Text>();
|
||||
|
||||
bestName.text = data.BestNickName;
|
||||
bestTimer.text = data.BestTotalTime;
|
||||
|
||||
Utils.DisplayImage(graph, data.AltitudeGraph);
|
||||
Utils.DisplayImage(bestHead, data.BestWxHeadImg);
|
||||
tr.Find("Modal/Props/DistanceText").GetComponent<Text>().text = data.Distance.ToString("f1") + "KM";
|
||||
tr.Find("Modal/Props/EleText").GetComponent<Text>().text = data.TotalClimb.ToString("f0") + "M";
|
||||
tr.Find("Modal/Props/SlopeText").GetComponent<Text>().text = data.AverageGrade.ToString("f1") + "%";
|
||||
tr.Find("Modal/StartTime").GetComponent<Text>().text = data.StartTime.Value.ToLocalTime().ToString();
|
||||
//var timegap = data.StartTime.Value.ToLocalTime() - UIManager.Now.GetDateTime();
|
||||
//if (timegap.Ticks > 0)
|
||||
//{
|
||||
// tr.Find("Modal/StartTime").GetComponent<Text>().text = Helper.FormatTicks((int)timegap.Ticks);
|
||||
//}
|
||||
var close = tr.Find("Modal/Close").gameObject;
|
||||
var quit = tr.Find("Modal/Quit").gameObject;
|
||||
UIManager.AddEvent(close, EventTriggerType.PointerClick, (e) => { tr.gameObject.SetActive(false); });
|
||||
UIManager.AddEvent(quit, EventTriggerType.PointerClick, (e) => { tr.gameObject.SetActive(false); });
|
||||
tr.gameObject.SetActive(true);
|
||||
}
|
||||
private int RoomId;
|
||||
|
||||
public void GetInRoom()
|
||||
{
|
||||
var result = ConfigHelper.GameRoomApi.GetDetail(RoomId);
|
||||
if (result.result)
|
||||
//1.房间人数已经满了
|
||||
var max = GameRoom.MaxMembers;
|
||||
var count = GameRoom.RoomPlayerList.Count;
|
||||
if (count + 1 > max)
|
||||
{
|
||||
App.gameRoomDetail = result.data;
|
||||
//TODO:一些状态的校验
|
||||
//1.房间人数已经满了
|
||||
//2.房间状态不对
|
||||
//发送TCP信息
|
||||
MapUDPService.SendJoinGameRoom(App.gameRoomDetail.Id,App.CurrentUser.Id,UIManager.Now.GetDateTime().ToUniversalTime());
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
Utils.showToast(gameObject, App.GetLocalString("exceeded the maximum number!"));
|
||||
return;
|
||||
}
|
||||
else
|
||||
//2.房间状态不对
|
||||
if (GameRoom.Status > 0)
|
||||
{
|
||||
Utils.showToast(gameObject, result.errMsg);
|
||||
Utils.showToast(gameObject, App.GetLocalString("Game has already been processing!"));
|
||||
return;
|
||||
}
|
||||
App.gameRoomDetail = GameRoom;
|
||||
//发送TCP信息
|
||||
MapUDPService.SendJoinGameRoom(App.gameRoomDetail.RoomId,App.CurrentUser.Id,UIManager.Now.GetDateTime().ToUniversalTime());
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
}
|
||||
public void SelectRoom(GameRoomModel room)
|
||||
{
|
||||
GameRoom = room;
|
||||
RoomId = GameRoom.Id;
|
||||
RoomId = GameRoom.RoomId;
|
||||
}
|
||||
|
||||
public int GetRoomId()
|
||||
{
|
||||
return RoomId;
|
||||
}
|
||||
public GameRoomModel GetCurrentRoom()
|
||||
{
|
||||
return GameRoom;
|
||||
}
|
||||
public void Select(MapRoute map)
|
||||
{
|
||||
Map = map;
|
||||
@@ -607,8 +799,22 @@ public class GameRoomListController : PFUIPanel
|
||||
//创建房间
|
||||
private void CreateGameRoom(BaseEventData data)
|
||||
{
|
||||
MapList.SetActive(true);
|
||||
InitStep1();
|
||||
InitStep2();
|
||||
|
||||
next.GetComponent<Image>().color = PFConstants.Dark;
|
||||
next.transform.Find("Text").GetComponent<Text>().color = PFConstants.LightGrey;
|
||||
next.GetComponent<Button>().interactable = false;
|
||||
next.GetComponent<Button>().enabled = false;
|
||||
HandleStepBtn(previous.name);
|
||||
HandleCloseTimeBtnClick(0, "");
|
||||
|
||||
MapList.SetActive(true);
|
||||
}
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
MapUDPService.MessageListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scripts.Scenes.VideoRide;
|
||||
using DG.Tweening;
|
||||
using PolyAndCode.UI;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameRoomLoadingController : PFUIPanel
|
||||
@@ -33,45 +36,89 @@ public class GameRoomLoadingController : PFUIPanel
|
||||
GameRoom = App.gameRoomDetail;
|
||||
roomName.text = GameRoom.Name;
|
||||
routeName.text = GameRoom.MapRouteName;
|
||||
idtext.text = GameRoom.Id.ToString().PadLeft(7, '0');
|
||||
idtext.text = GameRoom.RoomId.ToString().PadLeft(7, '0');
|
||||
distanceText.text = GameRoom.Distance.ToString("f1") + "KM";
|
||||
gradeText.text = GameRoom.AverageGrade.ToString("f1") + "%";
|
||||
totalClimbText.text = GameRoom.TotalClimb.ToString("f0")+"M";
|
||||
totalClimbText.text = GameRoom.TotalClimb.ToString("f0") + "M";
|
||||
DrawMapRouteAsync(GameRoom.MapRouteId);
|
||||
prefab = Resources.Load<GameObject>("UI/Prefab/GameRoom/LoadingItem");
|
||||
MapUDPService.MessageListener = ListenerHandler;
|
||||
|
||||
videoLoading = FindObjectOfType<VideoLoading>();
|
||||
playerLoading = FindObjectOfType<LoadingController>();
|
||||
videoManager = FindObjectOfType<VideoGameManager>();
|
||||
videoManager?.SetCyclingModel(Assets.Scenes.Ride.Scripts.Model.CyclingModel.GameRoom);
|
||||
}
|
||||
private bool DataSourceChanged { get; set; }
|
||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||
{
|
||||
try
|
||||
{
|
||||
//查询列表
|
||||
var roomList = message.Where(c => c.RoomList != null).FirstOrDefault();
|
||||
if (roomList != null)
|
||||
{
|
||||
var room = App.gameRoomDetail;
|
||||
GameRoom = roomList.RoomList.Where(c=>c.RoomId == GameRoom.RoomId).FirstOrDefault();
|
||||
DataSourceChanged = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
float timer = 1f;
|
||||
VideoLoading videoLoading { get; set; }
|
||||
LoadingController playerLoading { get; set; }
|
||||
VideoGameManager videoManager { get; set; }
|
||||
private void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
while (timer < 0)
|
||||
{
|
||||
//获取当前进度
|
||||
var currentScene = SceneManager.GetActiveScene();
|
||||
double process = 100d;
|
||||
if (!currentScene.name.Equals("VideoPlay"))
|
||||
{
|
||||
process = playerLoading.GetProcess();
|
||||
}
|
||||
//发送当前进度
|
||||
MapUDPService.SendGameRoomLoadingProcess(GameRoom.Id, App.CurrentUser.Id, 56);
|
||||
MapUDPService.SendGameRoomLoadingProcess(GameRoom.RoomId, App.CurrentUser.Id, process);
|
||||
|
||||
timer += 1f;
|
||||
}
|
||||
if (DataSourceChanged)
|
||||
{
|
||||
DataSourceChanged = false;
|
||||
|
||||
//新增
|
||||
var list = MapUDPService.GetGameRoomList(GameRoom.Id);
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
var items = FindObjectsOfType<GameRoomLoadingItem>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var roomDetail = items.Where(c => c.UserId == item.RoomDetail.UserId).FirstOrDefault();
|
||||
var roomDetail = items.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
if (roomDetail == null)
|
||||
{
|
||||
var detail = Instantiate(prefab, content);
|
||||
roomDetail = detail.GetComponent<GameRoomLoadingItem>();
|
||||
roomDetail.Init(item.Id,item.Name,item.Room.Id,0);
|
||||
roomDetail.Init(item.UserId, item.WxHeadImage, item.RoomId, item.Process);
|
||||
}
|
||||
}
|
||||
//判断是否进入骑行场景
|
||||
var startTime = MapUDPService.GetRoomStartTime(GameRoom.Id);
|
||||
var startTime = GameRoom.StartTime;
|
||||
var singleUi = FindObjectOfType<SingleUIManager>();
|
||||
if (startTime.HasValue)
|
||||
{
|
||||
var v = FindObjectOfType<VideoLoading>();
|
||||
v.StartRide(null);
|
||||
//TODO:倒计时
|
||||
var dateTime = UIManager.Now.GetDateTime();
|
||||
var gap = startTime.Value.ToLocalTime() - dateTime;
|
||||
var interval = (int)Math.Floor(gap.TotalSeconds);
|
||||
playerLoading?.StartRide(interval);
|
||||
singleUi?.StartRide(interval);
|
||||
videoLoading?.StartRide(interval);
|
||||
transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user