158 lines
5.7 KiB
C#
158 lines
5.7 KiB
C#
using Assets.Scripts;
|
|
using Assets.Scripts.Apis;
|
|
using Assets.Scripts.Apis.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
public class CompetitionLoadingController : AbstratctLoadingController
|
|
{
|
|
private GameObject Watch { get; set; }
|
|
private bool _canJoin = false;
|
|
private bool _canStart = false;
|
|
|
|
private RawImage CompetitionDesc;
|
|
private Text StartTime { get; set; }
|
|
private Text Contestant { get; set; }
|
|
|
|
private Transform PlayersPanel {get;set;}
|
|
|
|
|
|
public override void InjectController(CyclingController controller)
|
|
{
|
|
cyclingController = controller;
|
|
//渲染比赛界面
|
|
panel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitonPanel"), transform);
|
|
PFUIPanel mainPanel = panel.GetComponent<PFUIPanel>();
|
|
PFUIPanel modelPanel = transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
|
cyclingController.SetUIManager(mainPanel, modelPanel);
|
|
}
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
}
|
|
protected override void ShowLoading()
|
|
{
|
|
loadingPanel = panel.transform.Find("LoadingPanel").gameObject;
|
|
loadingPanel.showLoadingExtension();
|
|
}
|
|
//初始化
|
|
public override void Init()
|
|
{
|
|
InitGameObject();
|
|
InitGameObjectData();
|
|
}
|
|
//构建赛事界面
|
|
protected override void InitGameObject()
|
|
{
|
|
base.InitGameObject();
|
|
CompetitionDesc = panel.transform.Find("CompetitionDesc").GetComponent<RawImage>();
|
|
StartTime = panel.transform.Find("Time").GetComponent<Text>();
|
|
Contestant = panel.transform.Find("Contestant").GetComponent<Text>();
|
|
Watch = panel.transform.Find("Watch").gameObject;
|
|
PlayersPanel = panel.transform.Find("PlayersPanel/List/Viewport/Content");
|
|
UIManager.AddEvent(Watch, EventTriggerType.PointerClick, StartWatch);
|
|
}
|
|
//查询赛事相关数据
|
|
protected override void InitGameObjectData()
|
|
{
|
|
var route = cyclingController.mapRoute;
|
|
var competition = cyclingController.competition;
|
|
//赛事状态按钮控制
|
|
_canJoin = competition.CanJoin;
|
|
_canStart = competition.CanStart;
|
|
|
|
var showWatch = !_canJoin && !_canStart && !competition.HasRecord;
|
|
Watch.SetActive(showWatch);
|
|
rideNow.gameObject.SetActive(!showWatch);
|
|
rideNowText.text = _canJoin ? "Apply" : "RideNow";
|
|
|
|
#region 赛事基本信息
|
|
//赛事名称
|
|
mapName.text = competition.Title;
|
|
//距离
|
|
distance.text = route.Distance.ToString("f1") + "KM";
|
|
//海拔
|
|
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
|
//平均破度
|
|
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
|
//比赛开始时间
|
|
StartTime.text = competition.StartTime.ToLongTimeString();
|
|
//参赛选手
|
|
Contestant.text = competition.UserList.Count.ToString() + "Players";
|
|
ShowPlayers(competition.UserList);
|
|
//路书描述
|
|
mapDescText.text = route.Dec;
|
|
//主办方logo
|
|
|
|
//赛事详情
|
|
//异步请求mapbox画出当前路书路线图
|
|
DrawMapRouteAsync(route.Id,1);
|
|
AddProcess(20);
|
|
#endregion
|
|
|
|
StartCoroutine(HiddenLoading());
|
|
}
|
|
private int maxShowCout = 15;
|
|
private void ShowPlayers(List<CompetitionPlayer> list)
|
|
{
|
|
var watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
|
|
var moreHead = Resources.Load<GameObject>("UI/Prefab/Match/MoreHead");
|
|
int index = 0;
|
|
foreach (var item in list)
|
|
{
|
|
index++;
|
|
if (index >= maxShowCout) {
|
|
Instantiate(moreHead, PlayersPanel);
|
|
break;
|
|
}
|
|
var head = Instantiate(watcher, PlayersPanel);
|
|
var headiamge = head.GetComponent<RawImage>();
|
|
if (!string.IsNullOrEmpty(item.WxHeadImg))
|
|
{
|
|
Utils.DisplayImage(headiamge, item.WxHeadImg, true);
|
|
}
|
|
}
|
|
}
|
|
//显示比赛详情图片:如果没有比赛详情图则显示地图
|
|
private void ShowCompetitionDescImage()
|
|
{
|
|
|
|
}
|
|
#region 事件
|
|
//先报名后开始
|
|
protected override void StartRide(BaseEventData baseEvent)
|
|
{
|
|
//先报名
|
|
if (_canJoin)
|
|
{
|
|
MapCompetitionApi s = new MapCompetitionApi();
|
|
var rrr = s.ApplyMapCompetition(cyclingController.competitionId);
|
|
if (rrr.Result.result)
|
|
{
|
|
var competition = s.GetById(cyclingController.competitionId).data;
|
|
_canStart = competition.CanStart;
|
|
}
|
|
rideNowText.text = "RideNow";
|
|
}
|
|
else
|
|
{
|
|
base.StartRide(baseEvent);
|
|
}
|
|
}
|
|
//观察
|
|
protected void StartWatch(BaseEventData baseEvent)
|
|
{
|
|
//隐藏当前用户
|
|
cyclingController.isWatch = true;
|
|
cyclingController.player.SetActive(false);
|
|
base.StartRide(baseEvent);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|