149 lines
5.2 KiB
C#
Raw Normal View History

2021-03-25 17:18:51 +08:00
using Assets.Scripts;
using Assets.Scripts.Apis;
2021-04-14 15:02:33 +08:00
using Assets.Scripts.Apis.Models;
using DG.Tweening;
2021-03-25 16:55:36 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2021-04-14 15:02:33 +08:00
using System.Threading.Tasks;
2021-03-25 16:55:36 +08:00
using UnityEngine;
2021-03-29 09:10:59 +08:00
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
2021-03-25 16:55:36 +08:00
using UnityEngine.UI;
2021-03-30 14:23:41 +08:00
public class HomeController : PFUIPanel
2021-03-25 16:55:36 +08:00
{
2021-04-06 15:30:36 +08:00
//[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;
2021-04-06 15:30:36 +08:00
[SerializeField] Transform userInfo;
2021-03-25 16:55:36 +08:00
// Start is called before the first frame update
2021-03-30 14:23:41 +08:00
protected override void Start()
2021-03-25 16:55:36 +08:00
{
2021-03-30 14:23:41 +08:00
base.Start();
2021-03-29 09:10:59 +08:00
//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;
//}
2021-04-14 15:02:33 +08:00
2021-03-29 09:10:59 +08:00
//if (More != null)
//{
// More.onClick.AddListener(MoreFunc);
//}
BtnRide.onClick.AddListener(GoRide);
2021-03-29 09:10:59 +08:00
2021-04-14 15:02:33 +08:00
var avatar = userInfo.Find("Avatar").GetComponent<RawImage>();
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
var rect = ((RectTransform)avatar.transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
avatar.material = material;
2021-03-29 09:10:59 +08:00
UIManager.AddEvent(avatar.gameObject, EventTriggerType.PointerClick, x =>
2021-03-25 16:55:36 +08:00
{
2021-03-29 09:10:59 +08:00
UIManager.ShowUserInfoPanel();
});
2021-04-14 15:02:33 +08:00
UIManager.AddEvent(userInfo.Find("BtnMore").gameObject, EventTriggerType.PointerClick, x =>
{
2021-04-14 15:02:33 +08:00
UIManager.ShowAlert("test");
});
GetSummary();
}
2021-04-14 15:02:33 +08:00
private async Task Login()
{
var result = await new UserApi().Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
2021-03-25 16:55:36 +08:00
}
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");
//});
//});
}
2021-03-29 09:10:59 +08:00
2021-03-25 16:55:36 +08:00
void MoreFunc()
{
//Utils.showToast(gameObject, "更多信息", 1);
//DOTween.ToAlpha(() => )
2021-03-25 16:55:36 +08:00
}
2021-04-14 15:02:33 +08:00
void SetCurrentUser(SummaryResultModel summary)
2021-03-25 16:55:36 +08:00
{
userInfo.Find("NickName").GetComponent<Text>().text = App.CurrentUser.Nickname;
userInfo.Find("GroupTop").Find("FtpContainer").Find("FtpValue").GetComponent<Text>().text = App.CurrentUser.FTP.ToString();
2021-04-06 15:30:36 +08:00
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.Weight}kg/{App.CurrentUser.BicycleWeight}kg";
2021-04-14 15:02:33 +08:00
userInfo.Find("CaloriesContainer").Find("CaloriesValue").GetComponent<Text>().text = summary.Kcal;
userInfo.Find("KMContainer").Find("KMValue").GetComponent<Text>().text = summary.TotalDistance.ToString();
userInfo.Find("ClimbContainer").Find("ClimbValue").GetComponent<Text>().text = summary.TotalClimb;
2021-04-06 15:30:36 +08:00
//var user = ConfigHelper.CurrentUser;
2021-04-14 15:02:33 +08:00
//Ftp.text = summary.Ftp.ToString();
2021-04-06 15:30:36 +08:00
//Weight.text = user.Weight.ToString();
//WKG.text = $"{user.Weight}KG/{user.BicycleWeight}KG";
//NickName.text = user.Nickname;
2021-04-14 15:02:33 +08:00
Utils.DisplayImage(StartCoroutine, userInfo.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
2021-03-25 16:55:36 +08:00
}
2021-04-14 15:02:33 +08:00
async void GetSummary()
2021-03-25 16:55:36 +08:00
{
2021-04-14 15:02:33 +08:00
if (App.CurrentUser == null)
{
await Login();
}
2021-03-25 17:18:51 +08:00
var res = ConfigHelper.userApi.GetSummary();
2021-03-25 16:55:36 +08:00
if (res.result)
{
//App.CurrentUser.Distance = res.data.TotalDistance;
//App.CurrentUser.Climb = res.data.TotalClimb;
//App.CurrentUser.Carlories = res.data.Kcal;
2021-04-14 15:02:33 +08:00
SetCurrentUser(res.data);
2021-04-06 15:30:36 +08:00
//Climb.text = $"{res.data.TotalClimb.ToString()}M";
//Calories.text = $"{res.data.Kcal.ToString()}KCAL";
2021-03-25 16:55:36 +08:00
//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()
{
}
}