164 lines
5.6 KiB
C#

using Assets.Scripts;
using Assets.Scripts.Apis;
using Assets.Scripts.Apis.Models;
using Assets.Scripts.UI.Control;
using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class HomeController : PFUIPanel
{
//[SerializeField] Text Ftp;
//[SerializeField] RawImage Avatar;
//[SerializeField] Text Weight;
//[SerializeField] Text WKG;
//[SerializeField] Text Calories;
//[SerializeField] Text KM;
//[SerializeField] Text Climb;
//[SerializeField] Text NickName;
//[SerializeField] Button More;
[SerializeField] Button BtnRide;
[SerializeField] Transform userInfo;
private MainNav mainNav;
// Start is called before the first frame update
protected override void Start()
{
base.Start();
mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
mainNav.ShowExit();
//var parent = Utils.FindUpParent(gameObject.transform);
//if (parent.Find("ToastContainer") == null)
//{
// var toast = Instantiate(Resources.Load<GameObject>("UI/Prefab/ToastContainer"));
// toast.name = "ToastContainer";
// toast.GetComponent<RectTransform>().position = new Vector3(Screen.width / 2, Screen.height / 2, 0);
// toast.transform.parent = parent;
//}
//if (More != null)
//{
// More.onClick.AddListener(MoreFunc);
//}
BtnRide.onClick.AddListener(GoRide);
var avatar = userInfo.Find("Avatar").GetComponent<RawImage>();
var rect = ((RectTransform)avatar.transform).rect;
SetRounded(avatar.transform, rect.height);
UIManager.AddEvent(avatar.gameObject, EventTriggerType.PointerClick, x =>
{
UIManager.ShowUserInfoPanel();
});
userInfo.Find("BtnMore").GetComponent<PfUIButton>().SetEnabled(false);
UIManager.AddEvent(userInfo.Find("BtnMore").gameObject, EventTriggerType.PointerClick, x =>
{
UIManager.ShowAlert("test");
//UIManager.ShowConfirm("Quit", "Do you want to quit PowerFun?", null);
});
GetSummary();
}
private async Task Login()
{
var result = await new UserApi().Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
}
private void GoRide()
{
UIManager.ShowMapListPanel();
//SceneManager.LoadScene("3-MapList");
//DOTween.To()
//this.transform.DOLocalMove(new Vector2(1000, 0), 2.0f).SetEase(Ease.InOutExpo).OnComplete(() =>
//{
//Loom.QueueOnMainThread(() =>
//{
// Debug.Log("ddddddddddddddddddddddddddd");
//});
//});
}
void MoreFunc()
{
//Utils.showToast(gameObject, "更多信息", 1);
//DOTween.ToAlpha(() => )
}
void SetCurrentUser(SummaryResultModel summary)
{
userInfo.Find("NickName").GetComponent<Text>().text = App.CurrentUser.Nickname;
userInfo.Find("GroupTop").Find("FtpContainer").Find("FtpValue").GetComponent<Text>().text = App.CurrentUser.FTP.ToString();
userInfo.Find("GroupTop").Find("WeightContainer").Find("WeightValue").GetComponent<Text>().text = App.CurrentUser.Weight.ToString();
userInfo.Find("GroupTop").Find("WKGContainer").Find("WKGValue").GetComponent<Text>().text = $"{ (App.CurrentUser.FTP/ App.CurrentUser.Weight).ToString("0.0") }";
userInfo.Find("CaloriesContainer").Find("CaloriesValue").GetComponent<Text>().text = summary.Kcal +" KCAL";
userInfo.Find("KMContainer").Find("KMValue").GetComponent<Text>().text = summary.TotalDistance.ToString("0") +" KM";
userInfo.Find("ClimbContainer").Find("ClimbValue").GetComponent<Text>().text = summary.TotalClimb +" M";
userInfo.Find("IDText").GetComponent<Text>().text = "ID:"+App.CurrentUser.Id.ToString("000000");
//var user = ConfigHelper.CurrentUser;
//Ftp.text = summary.Ftp.ToString();
//Weight.text = user.Weight.ToString();
//WKG.text = $"{user.Weight}KG/{user.BicycleWeight}KG";
//NickName.text = user.Nickname;
Utils.DisplayImage(StartCoroutine, userInfo.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
}
async void GetSummary()
{
if (App.CurrentUser == null)
{
await Login();
}
var res = ConfigHelper.userApi.GetSummary();
if (res.result)
{
//App.CurrentUser.Distance = res.data.TotalDistance;
//App.CurrentUser.Climb = res.data.TotalClimb;
//App.CurrentUser.Carlories = res.data.Kcal;
SetCurrentUser(res.data);
//Climb.text = $"{res.data.TotalClimb.ToString()}M";
//Calories.text = $"{res.data.Kcal.ToString()}KCAL";
//Calories.text = res.data.
}
else
{
Utils.showToast(gameObject, res.errMsg);
}
//var res = await NoAuthApi.GetCurrentUser();
//if (res.result)
//{
// Global.CurrentUser = res.data;
// SetCurrentUser();
//}
//else
//{
// Utils.showToast(gameObject, res.errMsg);
//}
}
// Update is called once per frame
void Update()
{
}
public override void Show()
{
var cg = this.GetComponent<CanvasGroup>();
cg.alpha = 0;
base.Show();
cg.DOFade(1f, 0.3f);
}
}