217 lines
5.9 KiB
C#
217 lines
5.9 KiB
C#
using Assets.Scripts.Apis.Models;
|
|
using PolyAndCode.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using Assets.Scripts;
|
|
using Assets.Scenes.Ride.Scripts;
|
|
|
|
public class GameRoomCell : MonoBehaviour, ICell, IBeginDragHandler, IDragHandler, IEndDragHandler,IScrollHandler
|
|
{
|
|
public Text IdTxt;
|
|
public Text RouteNameTxt;
|
|
public Text RouteNameLightTxt;
|
|
public Text RoomNameTxt;
|
|
|
|
public Text DistanceTxt;
|
|
public Text AltitudeGraphTxt;
|
|
public Text GradeTxt;
|
|
|
|
public Text DistanceLightTxt;
|
|
public Text AltitudeGraphLightTxt;
|
|
public Text GradeLightTxt;
|
|
|
|
public Text MembersTxt;
|
|
|
|
public Image HoverBgImg;
|
|
|
|
public Image IconDitanceImg;
|
|
public Image IconElevationImg;
|
|
public Image IconGradeImg;
|
|
|
|
public Image IconDistanceLightImg;
|
|
public Image IconElevationLightImg;
|
|
public Image IconGradeLightImg;
|
|
|
|
public RawImage AltitudeGraphImg;
|
|
|
|
public RawImage HeadPrefab;
|
|
public Transform Content;
|
|
|
|
public GameObject JoinBtn;
|
|
public GameObject CycingBtn;
|
|
public GameObject ResultBtn;
|
|
public GameObject Lock;
|
|
public GameObject LockL;
|
|
public GameObject D2;
|
|
public GameObject D3;
|
|
public GameObject AR;
|
|
public GameObject D2L;
|
|
public GameObject D3L;
|
|
public GameObject ARL;
|
|
|
|
private ScrollRect Scroll;
|
|
|
|
private bool IsLock;
|
|
|
|
private int Id;
|
|
|
|
private string FileName;
|
|
|
|
private GameRoomListController manager;
|
|
private GameRoomModel gameRoom;
|
|
|
|
private bool Enable2d { get; set; }
|
|
private bool Enable3d { get; set; }
|
|
private bool EnableAR { get; set; }
|
|
|
|
private void Start()
|
|
{
|
|
manager = FindObjectOfType<GameRoomListController>();
|
|
Scroll = GetComponentInParent<ScrollRect>();
|
|
UIManager.AddEvent(gameObject, EventTriggerType.PointerEnter,OnEnter);
|
|
UIManager.AddEvent(gameObject, EventTriggerType.PointerExit, OnExit);
|
|
UIManager.AddEvent(JoinBtn, EventTriggerType.PointerClick, JoinGameRoom);
|
|
//对战正在进行
|
|
UIManager.AddEvent(CycingBtn, EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
manager.ShowCycingPanel(gameRoom);
|
|
});
|
|
//对战已经结束
|
|
UIManager.AddEvent(ResultBtn, EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
manager.ShowDonePanel(gameRoom.RoomId);
|
|
});
|
|
}
|
|
private void OnEnter(BaseEventData baseEventData)
|
|
{
|
|
LockL.SetActive(IsLock);
|
|
Lock.SetActive(false);
|
|
|
|
D2.SetActive(false);
|
|
D2L.SetActive(Enable2d);
|
|
|
|
D3.SetActive(false);
|
|
D3L.SetActive(Enable3d);
|
|
|
|
AR.SetActive(false);
|
|
ARL.SetActive(EnableAR);
|
|
|
|
|
|
var list = GetComponentsInChildren<GameRoomHead>();
|
|
foreach (var item in list)
|
|
{
|
|
item.ShowLight();
|
|
}
|
|
}
|
|
private void OnExit(BaseEventData baseEventData)
|
|
{
|
|
LockL.SetActive(false);
|
|
Lock.SetActive(IsLock);
|
|
|
|
D2.SetActive(Enable2d);
|
|
D2L.SetActive(false);
|
|
|
|
D3.SetActive(Enable3d);
|
|
D3L.SetActive(false);
|
|
|
|
AR.SetActive(EnableAR);
|
|
ARL.SetActive(false);
|
|
|
|
var list = GetComponentsInChildren<GameRoomHead>();
|
|
foreach (var item in list)
|
|
{
|
|
item.ShowShadow();
|
|
}
|
|
}
|
|
private void JoinGameRoom(BaseEventData baseEventData)
|
|
{
|
|
manager.SelectRoom(gameRoom);
|
|
if (IsLock)
|
|
{
|
|
manager.ShowPwdConfirm();
|
|
}
|
|
else
|
|
{
|
|
manager.ShowDownLoadConfirm();
|
|
}
|
|
}
|
|
//This is called from the SetCell method in DataSource
|
|
public void ConfigureCell(GameRoomModel cell, int cellIndex)
|
|
{
|
|
gameRoom = cell;
|
|
RoomNameTxt.text = cell.Name;
|
|
FileName = cell.FileName;
|
|
var gradeText = $"{Math.Round(cell.AverageGrade,2)}%";
|
|
GradeLightTxt.text = gradeText;
|
|
GradeTxt.text = gradeText;
|
|
|
|
var distanceText = $"{Math.Round(cell.Distance,1)}KM";
|
|
DistanceTxt.text = distanceText;
|
|
DistanceLightTxt.text = distanceText;
|
|
|
|
var totalClimbText = $"{Math.Round(cell.TotalClimb)}M";
|
|
AltitudeGraphTxt.text = totalClimbText;
|
|
AltitudeGraphLightTxt.text = totalClimbText;
|
|
|
|
RouteNameTxt.text = cell.MapRouteName;
|
|
RouteNameLightTxt.text = cell.MapRouteName;
|
|
IdTxt.text = cell.RoomId.ToString().PadLeft(7,'0');
|
|
|
|
IsLock = cell.IsLock;
|
|
Id = cell.RoomId;
|
|
//房间状态
|
|
JoinBtn.SetActive(cell.Status == 0);
|
|
CycingBtn.SetActive(cell.Status == 1);
|
|
ResultBtn.SetActive(cell.Status == 2);
|
|
|
|
Enable2d = !cell.Enable3D && !cell.EnableAR;
|
|
Enable3d = cell.Enable3D && !cell.EnableAR;
|
|
EnableAR = cell.EnableAR;
|
|
|
|
D2.SetActive(Enable2d);
|
|
D3.SetActive(Enable3d);
|
|
AR.SetActive(EnableAR);
|
|
|
|
Lock.SetActive(IsLock);
|
|
LockL.SetActive(false);
|
|
Utils.DisplayImage(AltitudeGraphImg, cell.AltitudeGraph);
|
|
|
|
var playerList = cell.RoomPlayerList;
|
|
if (playerList != null)
|
|
{
|
|
MembersTxt.text = $"{playerList.Count}/{cell.MaxMembers}";
|
|
var s = playerList.Select(c => c.UserId);
|
|
var user = ConfigHelper.mapApi.GetOnlineUserInfo(s);
|
|
foreach (var item in playerList)
|
|
{
|
|
var obj = Instantiate(HeadPrefab, Content);
|
|
obj.GetComponent<GameRoomHead>().Set(item.WxHeadImage,item.IsOwner);
|
|
}
|
|
}
|
|
}
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
Scroll.OnBeginDrag(eventData);
|
|
}
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
Scroll.OnDrag(eventData);
|
|
}
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
Scroll.OnEndDrag(eventData);
|
|
}
|
|
public void OnScroll(PointerEventData eventData)
|
|
{
|
|
Scroll.OnScroll(eventData);
|
|
}
|
|
}
|
|
|
|
|