2022-04-07 09:23:44 +08:00

162 lines
7.7 KiB
C#

using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using Facebook.Unity;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RowerWelldone : PFUIPanel
{
[SerializeField]
GameObject AllRecord, Record,Rank;
Dictionary<string, Texture> caches;
Transform rankContent, gradeContent;
public string id { get; private set; }
public override void Show()
{
base.Show();
Debug.Log("well done show");
}
// Start is called before the first frame update
protected override void Awake()
{
caches = new Dictionary<string, Texture>();
rankContent = transform.Find("Container/Left/Scroll View").GetComponent<ScrollRect>().content;
gradeContent = transform.Find("Container/Right/Scroll View").GetComponent<ScrollRect>().content;
}
void Start()
{
UIManager.AddEvent(transform.Find("Container/BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
startTime = false;
Close();
//UIManager.ShowHomePanel();
//UIManager.ShowUserInfoPanel();
});
UIManager.AddEvent(transform.Find("Container/BtnView").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Close();
Application.OpenURL($"{App.websiteDict[App.Host]}rower/record/{id}?Token={App.CurrentUser.cookie}");
});
UIManager.AddEvent(transform.Find("Container/Share/Wx").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (data == null) return;
App.weChatController.ShareWebpageToWX(0, $"{App.websiteDict[App.Host]}rower/record/{id}?UserId={App.CurrentUser.Id}", $"PowerFun {data.info.TypeStr} Rowing", $"By {App.CurrentUser.Nickname}",null);
});
UIManager.AddEvent(transform.Find("Container/Share/WxMoment").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (data == null) return;
App.weChatController.ShareWebpageToWX(1, $"{App.websiteDict[App.Host]}rower/record/{id}?UserId={App.CurrentUser.Id}", $"PowerFun {data.info.TypeStr} Rowing", $"By {App.CurrentUser.Nickname}", null);
});
UIManager.AddEvent(transform.Find("Container/Share/Fb").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (data == null) return;
FB.ShareLink(contentURL: new Uri($"{App.websiteDict[App.Host]}rower/record/{id}?UserId={App.CurrentUser.Id}"),
contentTitle: $"PowerFun {data.info.TypeStr} Rowing",
contentDescription: $"By {App.CurrentUser.Nickname}");
//App.weChatController.ShareWebpageToWX(1, , , , null);
});
}
// Update is called once per frame
void Update()
{
if (startTime)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
remainTime--;
if (remainTime == 0)
{
startTime = false;
Close();
return;
}
transform.Find("Container/BtnDefine/Text").GetComponent<Text>().text = $"{App.GetLocalString("DEFINE")}({remainTime.ToString("#0")})";
timer += 1f;
}
}
}
float timer = 1f, remainTime = 10f;
bool startTime = false;
RowerSegmentData data;
public async void Initial(string id)
{
Debug.Log("Initial");
if (string.IsNullOrEmpty(id)) return;
this.id = id;
var res = await ConfigHelper.rowerApi.GetSegmentDataAndRanking(id);
if (res.result)
{
this.data = res.data;
DisplayData(res.data, caches);
startTime = true;
remainTime = 10f;
timer = 1f;
transform.Find("Container/BtnDefine/Text").GetComponent<Text>().text = $"{App.GetLocalString("DEFINE")}({remainTime.ToString("#0")})";
}
}
private void DisplayData(RowerSegmentData data, Dictionary<string, Texture> caches)
{
rankContent.DestroyChildren();
gradeContent.DestroyChildren();
for (int i = 0; i < data.ranks.Count; i++)
{
var item = data.ranks[i];
var game = Instantiate<GameObject>(Rank);
game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.WxHeadImg, caches);
game.transform.Find("Content/Time").GetComponent<Text>().text = data.info.Type == 1 ? TimeSpan.FromSeconds(item.Time).ToString(@"hh\:mm\:ss") : item.TotalDistance.ToString("#0M");
game.transform.SetParent(rankContent);
game.transform.localScale = Vector3.one;
game.SetActive(true);
if (item.UserId == App.CurrentUser.Id)
{
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
}
else
{
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
}
for (int i = 0; i < data.segmentList.Count; i++)
{
var item = data.segmentList[i];
var game = i == 0 ? Instantiate<GameObject>(AllRecord) : Instantiate<GameObject>(Record);
var content = i != 0 ? game.transform.Find("Content") : game.transform;
content.Find("Index").GetComponent<Text>().text = i == 0 ? "ALL" : i.ToString("00");
content.Find("Time").GetComponent<Text>().text = TimeSpan.FromSeconds(item.Ticks).ToString();
content.Find("Distance").GetComponent<Text>().text = item.Distance.ToString("#0");
content.Find("500").GetComponent<Text>().text = TimeSpan.FromSeconds(item.Speed).ToString();
content.Find("Power").GetComponent<Text>().text = item.Power.ToString("#0");
content.Find("HR").GetComponent<Text>().text = item.HeartRate.ToString("#0");
content.Find("Count").GetComponent<Text>().text = item.StrokeCount.ToString("#0");
content.Find("Carlories").GetComponent<Text>().text = item.Rate.ToString("#0");
//game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
//game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
//Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.WxHeadImg, caches);
//game.transform.Find("Content/Time").GetComponent<Text>().text = data.info.Type == 1 ? TimeSpan.FromSeconds(item.Time).ToString() : item.TotalDistance.ToString("#0");
game.transform.SetParent(gradeContent);
game.transform.localScale = Vector3.one;
game.SetActive(true);
}
transform.Find("Container/Left/MyRank").GetComponent<Text>().text = data.info.MyRank;
transform.Find("Container/Right/Time").GetComponent<Text>().text = data.info.CreateTime;
}
}