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

143 lines
6.3 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-04-23 09:22:12 +08:00
using UnityEngine.EventSystems;
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-04-21 11:19:31 +08:00
protected override void Awake()
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-23 09:22:12 +08:00
UIManager.AddEvent(exitBtn.gameObject, EventTriggerType.PointerClick, (b) =>
2021-03-29 09:10:59 +08:00
{
2021-04-23 15:36:18 +08:00
UIManager.ShowPrePanel();
//UIManager.ShowHomePanel();
2021-03-29 09:10:59 +08:00
});
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,
2021-04-23 09:22:12 +08:00
EventTriggerType.PointerClick, (b) =>
2021-04-16 17:49:11 +08:00
{
UIManager.ShowConfirm("Logout", "Do you want to log out and change accounts?", () =>
{
2021-05-08 11:07:55 +08:00
SceneManager.LoadScene("Login");
UIManager.CloseConfirm();
},2);
2021-04-16 17:49:11 +08:00
});
infoPanel = transform.Find("InfoPanel").Find("P");
2021-04-23 15:36:18 +08:00
2021-04-16 17:49:11 +08:00
Button editBtn = infoPanel.Find("EditButton").GetComponent<Button>();
2021-04-23 09:22:12 +08:00
UIManager.AddEvent(editBtn.gameObject, EventTriggerType.PointerClick, (b) =>
2021-04-19 15:44:11 +08:00
{
UIManager.ShowEditUserPanel();
});
2021-08-09 16:32:47 +08:00
UIManager.AddEvent(infoPanel.Find("Avatar").gameObject, EventTriggerType.PointerClick, (b) =>
{
UIManager.ShowEditUserPanel();
});
2021-04-19 15:44:11 +08:00
//editBtn.onClick.AddListener(() =>
//{
// UIManager.ShowEditUserPanel();
//});
2021-04-23 15:36:18 +08:00
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);
});
2021-04-16 17:49:11 +08:00
summaryPanel = transform.Find("SummaryPanel");
//创建比赛
var createBtn = summaryPanel.Find("CreateBtn").gameObject;
UIManager.AddEvent(createBtn, EventTriggerType.PointerClick, (b) =>
{
Application.OpenURL(App.CurrentUser.WebHost + "Mine/EditMatch?Token=" + App.CurrentUser.cookie);
});
2021-04-21 11:19:31 +08:00
}
public override void Show()
{
base.Show();
2021-04-16 17:49:11 +08:00
Load();
2021-04-29 23:45:29 +08:00
if (summaryPanel != null)
2021-04-29 22:05:19 +08:00
{
2021-04-29 23:45:29 +08:00
summaryPanel.Find("Panel").Find("RideResultList").GetComponent<ResultListController>().Load();
2021-04-29 22:05:19 +08:00
}
2021-03-25 16:53:39 +08:00
}
2021-04-30 21:09:21 +08:00
async void Load()
2021-04-16 17:49:11 +08:00
{
//if (!App.FromLogin)
//{
// var result = await userApi.Login("15651831367", "123456", "");
// App.CurrentUser = result.data;
//}
2021-04-30 21:09:21 +08:00
var r = await ConfigHelper.userApi.GetSummary();
2021-04-16 17:49:11 +08:00
if (r.result)
{
var summary = r.data;
var user = App.CurrentUser;
Debug.Log(user.CanCreateRace);
2021-05-20 20:00:33 +08:00
Utils.DisplayHead(infoPanel.Find("Avatar").GetComponent<RawImage>(), user.WxHeadImg);
2021-04-16 17:49:11 +08:00
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));
2021-04-23 09:22:12 +08:00
infoPanel.Find("IdText").GetComponent<Text>().text = $"ID:{user.Id.ToString("000000")}";
2021-04-16 17:49:11 +08:00
infoPanel.Find("NameText").GetComponent<Text>().text = $"{user.Nickname}";
infoPanel.Find("EmailText").GetComponent<Text>().text = $"{user.Phone}";
2021-04-23 15:36:18 +08:00
infoPanel.Find("DescText").GetComponent<Text>().text = $"{summary.Tips}";
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";
2021-06-09 17:29:38 +08:00
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");
2021-04-27 18:26:30 +08:00
if (user.Sex == 2)
{
infoPanel.Find("SexIcon").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/woman");
}
2021-04-28 15:21:06 +08:00
else
{
infoPanel.Find("SexIcon").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/man");
}
2021-04-16 17:49:11 +08:00
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();
summaryPanel.Find("CreateBtn").gameObject.SetActive(user.CanCreateRace);
2021-04-16 17:49:11 +08:00
}
}
public void Reset()
{
if (summaryPanel != null)
{
summaryPanel.Find("Panel").Find("RideResultList").GetComponent<ResultListController>().Reset();
}
}
2021-03-25 16:53:39 +08:00
// Update is called once per frame
void Update()
{
}
}