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

88 lines
3.7 KiB
C#

using Assets.Scripts;
using Assets.Scripts.Apis;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class UserInfoController : PFUIPanel
{
// Start is called before the first frame update
UserApi userApi;
Transform infoPanel,summaryPanel;
protected override void Start()
{
userApi = ConfigHelper.userApi;
this.transform.localPosition = new Vector3(0, 0, 0);
Button exitBtn = this.transform.Find("InfoPanel").Find("Button").GetComponent<Button>();
UIManager.AddEvent(exitBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowHomePanel();
});
//exitBtn.onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
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>();
UIManager.AddEvent(editBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowEditUserPanel();
});
//editBtn.onClick.AddListener(() =>
//{
// UIManager.ShowEditUserPanel();
//});
summaryPanel = transform.Find("SummaryPanel");
Load();
}
async void Load()
{
//if (!App.FromLogin)
//{
// var result = await userApi.Login("15651831367", "123456", "");
// App.CurrentUser = result.data;
//}
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}";
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();
}
}
// Update is called once per frame
void Update()
{
}
}