powerfun-unity/Assets/Scripts/UI/Prefab/Panel/UserInfoController.cs

88 lines
3.7 KiB
C#
Raw Normal View History

2021-04-16 17:49:11 +08:00
using Assets.Scripts;
using Assets.Scripts.Apis;
using System.Collections;
2021-03-25 16:53:39 +08:00
using System.Collections.Generic;
using UnityEngine;
2021-04-16 17:49:11 +08:00
using UnityEngine.SceneManagement;
2021-03-29 09:10:59 +08:00
using UnityEngine.UI;
2021-03-25 16:53:39 +08:00
2021-03-30 14:23:41 +08:00
public class UserInfoController : PFUIPanel
2021-03-25 16:53:39 +08:00
{
// Start is called before the first frame update
2021-04-16 17:49:11 +08:00
UserApi userApi;
Transform infoPanel,summaryPanel;
2021-03-30 14:23:41 +08:00
protected override void Start()
2021-03-25 16:53:39 +08:00
{
2021-04-16 17:49:11 +08:00
userApi = ConfigHelper.userApi;
2021-03-25 16:53:39 +08:00
this.transform.localPosition = new Vector3(0, 0, 0);
2021-03-29 09:10:59 +08:00
Button exitBtn = this.transform.Find("InfoPanel").Find("Button").GetComponent<Button>();
2021-04-19 15:44:11 +08:00
UIManager.AddEvent(exitBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
2021-03-29 09:10:59 +08:00
{
UIManager.ShowHomePanel();
});
2021-04-19 15:44:11 +08:00
//exitBtn.onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
2021-04-16 17:49:11 +08:00
UIManager.AddEvent(transform.Find("InfoPanel").Find("SwitchAccountButton").gameObject,
UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
SceneManager.LoadScene("1-Login");
});
infoPanel = transform.Find("InfoPanel").Find("P");
Button editBtn = infoPanel.Find("EditButton").GetComponent<Button>();
2021-04-19 15:44:11 +08:00
UIManager.AddEvent(editBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowEditUserPanel();
});
//editBtn.onClick.AddListener(() =>
//{
// UIManager.ShowEditUserPanel();
//});
2021-04-16 17:49:11 +08:00
summaryPanel = transform.Find("SummaryPanel");
Load();
2021-03-25 16:53:39 +08:00
}
2021-04-16 17:49:11 +08:00
async void Load()
{
//if (!App.FromLogin)
//{
// var result = await userApi.Login("15651831367", "123456", "");
// App.CurrentUser = result.data;
//}
2021-04-16 17:49:11 +08:00
var r = userApi.GetSummary();
if (r.result)
{
var summary = r.data;
var user = App.CurrentUser;
Utils.DisplayImage(StartCoroutine, infoPanel.Find("Avatar").GetComponent<RawImage>(), user.WxHeadImg);
infoPanel.Find("Status").Find("Country").GetComponent<RawImage>().texture
= UIManager.Instance.loginRegOptions.GetCountryImageByName(user.Country);
infoPanel.Find("Status").Find("Wx").gameObject.SetActive(
!string.IsNullOrEmpty(user.Unionid));
infoPanel.Find("IdText").GetComponent<Text>().text = $"ID:{user.Id}";
infoPanel.Find("NameText").GetComponent<Text>().text = $"{user.Nickname}";
infoPanel.Find("EmailText").GetComponent<Text>().text = $"{user.Phone}";
2021-03-25 16:53:39 +08:00
2021-04-16 17:49:11 +08:00
infoPanel.Find("Ftp").Find("Value").GetComponent<Text>().text = user.FTP.ToString();
infoPanel.Find("MHR").Find("Value").GetComponent<Text>().text = user.MaxHeartRate.ToString();
infoPanel.Find("Weight").Find("Value").GetComponent<Text>().text = $"{user.Weight}KG";
infoPanel.Find("BW").Find("Value").GetComponent<Text>().text = $"{user.BicycleWeight}KG";
infoPanel.Find("WD").Find("Value").GetComponent<Text>().text = $"{user.WheelDiameter}MM";
summaryPanel.Find("Number").Find("Value").GetComponent<Text>().text = summary.Count.ToString();
summaryPanel.Find("Time").Find("Value").GetComponent<Text>().text = summary.TotalTicks.ToString();
summaryPanel.Find("KM").Find("Value").GetComponent<Text>().text = summary.TotalDistance.ToString();
summaryPanel.Find("Climb").Find("Value").GetComponent<Text>().text = summary.TotalClimb.ToString();
summaryPanel.Find("Calories").Find("Value").GetComponent<Text>().text = summary.TotalKj.ToString();
}
}
2021-03-25 16:53:39 +08:00
// Update is called once per frame
void Update()
{
}
}