powerfun-unity/Assets/Scripts/UI/Prefab/Panel/UserInfoController.cs
2021-06-09 17:29:38 +08:00

130 lines
5.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;
using UnityEngine.EventSystems;
public class UserInfoController : PFUIPanel
{
// Start is called before the first frame update
UserApi userApi;
Transform infoPanel,summaryPanel;
protected override void Awake()
{
this.transform.localPosition = new Vector3(0, 0, 0);
Button exitBtn = this.transform.Find("InfoPanel").Find("Button").GetComponent<Button>();
UIManager.AddEvent(exitBtn.gameObject, EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowPrePanel();
//UIManager.ShowHomePanel();
});
//exitBtn.onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
UIManager.AddEvent(transform.Find("InfoPanel").Find("SwitchAccountButton").gameObject,
EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowConfirm("Logout", "Do you want to log out and change accounts?", () =>
{
SceneManager.LoadScene("Login");
UIManager.CloseConfirm();
},2);
});
infoPanel = transform.Find("InfoPanel").Find("P");
Button editBtn = infoPanel.Find("EditButton").GetComponent<Button>();
UIManager.AddEvent(editBtn.gameObject, EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowEditUserPanel();
});
//editBtn.onClick.AddListener(() =>
//{
// UIManager.ShowEditUserPanel();
//});
UIManager.AddEvent(transform.Find("InfoPanel").gameObject, EventTriggerType.PointerEnter, (b) =>
{
editBtn.gameObject.SetActive(true);
});
UIManager.AddEvent(transform.Find("InfoPanel").gameObject, EventTriggerType.PointerExit, (b) =>
{
editBtn.gameObject.SetActive(false);
});
summaryPanel = transform.Find("SummaryPanel");
}
public override void Show()
{
base.Show();
Load();
if (summaryPanel != null)
{
summaryPanel.Find("Panel").Find("RideResultList").GetComponent<ResultListController>().Load();
}
}
async void Load()
{
//if (!App.FromLogin)
//{
// var result = await userApi.Login("15651831367", "123456", "");
// App.CurrentUser = result.data;
//}
var r = await ConfigHelper.userApi.GetSummary();
if (r.result)
{
var summary = r.data;
var user = App.CurrentUser;
Utils.DisplayHead(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.ToString("000000")}";
infoPanel.Find("NameText").GetComponent<Text>().text = $"{user.Nickname}";
infoPanel.Find("EmailText").GetComponent<Text>().text = $"{user.Phone}";
infoPanel.Find("DescText").GetComponent<Text>().text = $"{summary.Tips}";
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";
infoPanel.Find("Ftp").Find("Time").GetComponent<Text>().text = user.LastUpdateFtpTime.ToString("dd-MM-yyyy");
infoPanel.Find("Weight").Find("Time").GetComponent<Text>().text = user.LastUpdateWeightTime.ToString("dd-MM-yyyy");
infoPanel.Find("BW").Find("Time").GetComponent<Text>().text = user.LastUpdateBicycleWeightTime.ToString("dd-MM-yyyy");
infoPanel.Find("WD").Find("Time").GetComponent<Text>().text = user.LastUpdateWheelStraight.ToString("dd-MM-yyyy");
infoPanel.Find("MHR").Find("Time").GetComponent<Text>().text = user.LastUpdateMaxHeartRate.ToString("dd-MM-yyyy");
if (user.Sex == 2)
{
infoPanel.Find("SexIcon").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/woman");
}
else
{
infoPanel.Find("SexIcon").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/man");
}
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();
}
}
public void Reset()
{
if (summaryPanel != null)
{
summaryPanel.Find("Panel").Find("RideResultList").GetComponent<ResultListController>().Reset();
}
}
// Update is called once per frame
void Update()
{
}
}