倒计时的算法及界面调整

This commit is contained in:
lishuo committed 2021-07-30 15:38:40 +08:00
1 parent bea0e40ec1
commit 074200cb4f
16 files changed
+2714 -2596

No files matched your search

@@ -172,7 +172,7 @@ namespace Assets.Scenes.Ride.Scripts
//平均破度
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
//比赛开始时间
StartTime.text = competition.StartTime.ToLocalTime().ToString()+"-"+ competition.EndApplyTime.ToLocalTime().ToString();
StartTime.text = competition.StartTime.ToLocalTime().ToString()+" TO "+ competition.EndApplyTime.ToLocalTime().ToString();
//比赛结束时间
// EndTime.text = competition.EndTime.ToLocalTime().ToString();
//比赛状态
@@ -282,6 +282,7 @@ namespace Assets.Scenes.Ride.Scripts
_canCancelApply = competition.CanCancelJoin;
_canWatch = competition.CanWatch;
_raceStart = competition.Status == 3;
_canEnter = competition.CanEnter;
Contestant.text = competition.UserList.Count.ToString() + "Riders";
ShowPlayers(competition.UserList);
@@ -65,7 +65,7 @@ namespace Assets.Scenes.Ride.Scripts
if (rankingList == null) return;
//当前参赛总人数
var totalCount = rankingList.Count();
OnlineUserNum.text = totalCount.ToString();
OnlineUserNum.text = " "+totalCount.ToString();
//当前用户排名
var currentIndex = rankingList.Where(c => c.UserId == cyclingController.currentPlayer.UserId).FirstOrDefault()?.Index ?? 0;
totalPages = (pageSize>0?totalCount / pageSize:0) + (totalCount % pageSize> 0? 1:0);
@@ -16,7 +16,6 @@ namespace Assets.Scenes.Ride.Scripts
CompetitionModel competitionModel { get; set; }
CyclingController cyclingController { get; set; }
private void Start()
{
cyclingController = FindObjectOfType<CyclingController>();
@@ -25,6 +24,7 @@ namespace Assets.Scenes.Ride.Scripts
TimerTitle = transform.Find("ConpetitionTimerTitle").GetComponent<Text>();
Timer = transform.Find("ConpetitionTimer").GetComponent<Text>();
competitionModel = cyclingController.cyclingController as CompetitionModel;
}
GameObject competitionResultPanel { get; set; }
@@ -46,10 +46,10 @@ namespace Assets.Scenes.Ride.Scripts
var isAutoSave = s.Item1 <= 0 && !cyclingController.cyclingController.recorderData.Saved && !cyclingController.isWatch;
//显示关门时间
if (s.Item2 && !isAutoSave)
if (s.Item3 && !isAutoSave)
{
//显示倒计时面板信息
ShowCountDown(s.Item1, "Get The First Place. Time Limit:");
ShowCountDown(s.Item1, "Get The First Place. Time Limit");
}
else if (s.Item1 > 0)
{
@@ -60,7 +60,7 @@ namespace Assets.Scenes.Ride.Scripts
//显示当前选手骑行时间
Timer.gameObject.SetActive(true);
TimerTitle.gameObject.SetActive(true);
Timer.text = Helper.FormatTicks(cyclingController.currentPlayer.TotalTicks);
Timer.text = Helper.FormatTicks(s.Item2);// Helper.FormatTicks(cyclingController.currentPlayer.TotalTicks);
}
}
}
@@ -140,6 +140,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
HeartRate = item.HeartRate,
Cadence = item.Cadence,
TotalTicks = item.TotalTicks,
WeightKg = item.WeightKg,
});
}
@@ -367,27 +368,38 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
if (CanStart()) return 0;
return (int)Math.Floor((mapCompetition.StartTime.ToLocalTime() - Now).TotalSeconds);
}
public int RaceStartTime()
{
return (int)Math.Floor((Now - mapCompetition.StartTime.ToLocalTime() ).TotalSeconds);
}
/// <summary>
/// 结束倒计时,bool值为true说明倒计时是关门时间
/// </summary>
/// <returns></returns>
public (int, bool) EndCountDown()
public (int,int, bool) EndCountDown()
{
//if (CanStart() == false) return (0, false);
//if (recorderData.IsCompleted) return 0;
var end1 = (int)Math.Floor((mapCompetition.EndTime.ToLocalTime() - Now).TotalSeconds);
var now = Now ;
var mi = now.Millisecond;
now = now.AddMilliseconds(-mi);
var end1 = (int)Math.Floor((mapCompetition.EndTime.ToLocalTime() - now).TotalSeconds);
var s = (int)Math.Floor((now - mapCompetition.EndTime.ToLocalTime()).TotalSeconds);
var start = (int)Math.Floor((now - mapCompetition.StartTime.ToLocalTime()).TotalSeconds);
if (!FirstEndTime.HasValue)
{
return (end1, false);
return (end1, start, false);
}
//var end2 = (int)Math.Floor((FirstEndTime.Value - Now).TotalSeconds);
var end2 = (int)Math.Floor((FirstEndTime.Value.ToLocalTime().AddMinutes(mapCompetition.CloseTime) - Now).TotalSeconds);
if (end1 < end2)
{
return (end1, false);
return (end1, start, false);
}
//return Math.Min(end1, end2);
return (end2, true);
return (end2, start, true);
}
}
}
@@ -224,6 +224,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
}
catch (Exception ex)
{
Helper.DelectDir(path);
Debug.Log(ex.Message);
}
recordData.Add(interruptRecord, files);
@@ -249,7 +250,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
{
if (result.result && Directory.Exists(path))
{
Helper.DelectDir(path);
//Helper.DelectDir(path);
}
}
catch (Exception e)
@@ -650,7 +650,6 @@ public class CyclingController : DeviceServiceMonoBase
//}
isStart = false;
isQuit = true;
recorderData.EndTime = UIManager.Now.GetDateTime();
}
#endregion
@@ -677,7 +676,7 @@ public class CyclingController : DeviceServiceMonoBase
public void Save(double totalDistance)
{
//cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
isQuit = true;
isStart = false;
string recordId = Guid.NewGuid().ToString();