298 lines
13 KiB
C#
Raw Normal View History

using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
using Assets.Scripts.Apis;
2021-04-14 15:02:33 +08:00
using Assets.Scripts.Apis.Models;
using Assets.Scripts.UI.Control;
using DG.Tweening;
2021-03-25 16:55:36 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
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;
Transform BtnMatch, BtnTraining;
private MainNav mainNav;
private Dictionary<string, Sprite[]> dict;
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-12-27 09:39:07 +08:00
#if UNITY_ANDROID || UNITY_IOS
var nav = transform.Find("MainNav-mobile").GetComponent<NewMainNav>();
nav.SetButtonActive(new List<int> { 1, 3, 4, 6 });
2021-12-29 14:23:37 +08:00
newNav = nav;
2021-12-28 11:25:09 +08:00
UIManager.AddEvent(transform.Find("TodayData/Avatar").gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowUserInfoPanel();
});
2021-12-29 14:23:37 +08:00
UIManager.AddEvent(transform.Find("TodayData/Datas/Distance").gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowResultListPanel();
});
2021-12-27 09:39:07 +08:00
#else
mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
mainNav.ShowExit();
2021-12-27 09:39:07 +08:00
#endif
var BtnContainer = transform.Find("MainFuncContainer");
2021-04-23 09:22:12 +08:00
UIManager.AddEvent(BtnRide.gameObject, EventTriggerType.PointerClick, GoRide);
2021-04-25 15:33:17 +08:00
UIManager.AddEvent(BtnRide.gameObject, EventTriggerType.PointerEnter, OnHover);
UIManager.AddEvent(BtnRide.gameObject, EventTriggerType.PointerExit, OnExit);
BtnMatch = BtnContainer.Find("BtnMatch");
//BtnMatch.GetComponent<Button>().onClick.AddListener(() =>
//{
// Debug.Log(45);
//});
UIManager.AddEvent(BtnMatch.gameObject, EventTriggerType.PointerClick, GoMatch);
UIManager.AddEvent(BtnMatch.gameObject, EventTriggerType.PointerEnter, OnHover);
UIManager.AddEvent(BtnMatch.gameObject, EventTriggerType.PointerExit, OnExit);
BtnTraining = BtnContainer.Find("BtnTraining");
UIManager.AddEvent(BtnTraining.gameObject, EventTriggerType.PointerClick, (e) =>
{
2021-08-09 10:01:17 +08:00
Debug.Log(Application.platform);
goTraining(e);
});
UIManager.AddEvent(BtnTraining.gameObject, EventTriggerType.PointerEnter, OnHover);
UIManager.AddEvent(BtnTraining.gameObject, EventTriggerType.PointerExit, OnExit);
2021-04-14 15:02:33 +08:00
var avatar = userInfo.Find("Avatar").GetComponent<RawImage>();
var rect = ((RectTransform)avatar.transform).rect;
SetRounded(avatar.transform, rect.height);
2021-04-14 15:02:33 +08:00
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-23 09:22:12 +08:00
2021-04-14 15:02:33 +08:00
UIManager.AddEvent(userInfo.Find("BtnMore").gameObject, EventTriggerType.PointerClick, x =>
{
2021-07-26 14:09:21 +08:00
UIManager.ShowUserInfoPanel();
//UIManager.ShowConfirm("Quit", "Do you want to quit PowerFun?", null);
2021-04-14 15:02:33 +08:00
});
2021-09-23 18:14:53 +08:00
if (transform.Find("Other/BtnRower"))
{
UIManager.AddEvent(transform.Find("Other/BtnRower").gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowRowerPanel();
});
}
//GetSummary();
dict = new Dictionary<string, Sprite[]>
{
2021-07-26 14:08:43 +08:00
//{
// "BtnMatch",new Sprite[]
// {
// Resources.Load<Sprite>("Images/home/Entrance - MATCH_soon"),
// Resources.Load<Sprite>("Images/home/Entrance - MATCH_soon_hover"),
// }
//},
//{
// "BtnTraining",new Sprite[]
// {
// Resources.Load<Sprite>("Images/home/Entrance - TRAINING_soon"),
// Resources.Load<Sprite>("Images/home/Entrance - TRAINING_soon_hover"),
// }
//},
};
}
2021-04-23 09:22:12 +08:00
private void GoRide(BaseEventData e)
{
2021-08-25 14:32:49 +08:00
Debug.Log(App.firstEnter.ToString());
//UIManager.ShowEarthPanel(App.latitude, App.longitude);
2021-08-25 14:32:49 +08:00
#if UNITY_ANDROID || UNITY_IOS
2021-12-14 18:10:58 +08:00
UIManager.ShowNewRouteOverviewPanel();
2021-08-25 14:32:49 +08:00
#else
if (App.firstEnter == 0)
{
App.firstEnter = 1;
UIManager.ShowEarthPanel(App.latitude, App.longitude);
}
else
{
2021-12-10 09:53:49 +08:00
UIManager.ShowNewRouteOverviewPanel();
}
2021-08-25 14:32:49 +08:00
#endif
2021-04-25 15:33:17 +08:00
OnExit(e);
}
2021-08-09 10:01:17 +08:00
void goTraining(BaseEventData e)
{
#if !(UNITY_IOS || UNITY_ANDROID)
var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\PowerFun\Rhino.PowerFun.exe";
//Debug.Log(System.IO.File.Exists(path + ));
if (!System.IO.File.Exists(path))
{
//TODO: auto update
UIManager.ShowDownloadWorkoutsPanel();
//Application.OpenURL("https://powerfun.oss-cn-shanghai.aliyuncs.com/Releases/PowerFunWorkouts.exe");
return;
}
UIManager.ShowConfirm("Switch to PowerFun Workouts?", "We will close the Powerfun and start PowerFun Workouts.", () =>
{
Utils.ExecFile(path);
Application.Quit();
});
#else
2021-08-26 15:08:02 +08:00
if (App.weChatController.isApplicationAvilible("com.zhixingpai.powerfun", "powerfun"))
{
2021-09-06 16:53:48 +08:00
UIManager.ShowConfirm("Switch to PowerFun Workouts?", "We will close the Powerfun and start PowerFun Workouts.", () =>
{
UIManager.CloseConfirm();
Application.OpenURL("powerfun://app");
2021-09-16 16:24:54 +08:00
Application.Quit();
2021-09-06 16:53:48 +08:00
});
2021-08-26 15:08:02 +08:00
}
else
{
UIManager.ShowConfirm("Workouts not installed", "Go to the official website to download?", () =>
2021-09-06 16:53:48 +08:00
{
UIManager.CloseConfirm();
2021-10-21 18:04:01 +08:00
Application.OpenURL(App.WorkoutsUrl);
2021-09-06 16:53:48 +08:00
});
2021-08-26 15:08:02 +08:00
}
2021-08-09 10:01:17 +08:00
#endif
}
//进入比赛
private void GoMatch(BaseEventData e)
{
2021-07-20 09:58:01 +08:00
UIManager.ShowRaceHomePanel();
OnExit(e);
}
2021-04-25 15:33:17 +08:00
private void OnHover(BaseEventData e)
{
var pe = (PointerEventData)e;
var parent = pe.pointerEnter.transform.parent;
if (dict.ContainsKey(parent.name))
{
parent.Find("Image").GetComponent<Image>().sprite = dict[parent.name][1];
}
//parent.Find("Image").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/home/Entrance - ROUTES_hover");
//parent.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
parent.DOScale(new Vector3(1.05f, 1.05f, 0), 0.3f);
//parent.GetComponent<RectTransform>().localScale = ;
2021-04-25 15:33:17 +08:00
}
private void OnExit(BaseEventData e)
{
var pe = (PointerEventData)e;
var parent = pe.pointerEnter.transform.parent;
//parent.Find("Image").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/home/Entrance - ROUTES_nomal");
//parent.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#5C5C6E");
if (dict.ContainsKey(parent.name))
{
parent.Find("Image").GetComponent<Image>().sprite = dict[parent.name][0];
}
parent.DOScale(new Vector3(1f, 1f, 0), 0.3f);
//parent.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 0);
}
2021-03-25 16:55:36 +08:00
void MoreFunc()
{
//Utils.showToast(gameObject, "更多信息", 1);
2021-04-23 09:22:12 +08:00
//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.FTP/ App.CurrentUser.Weight).ToString("0.0") }";
2021-04-23 09:22:12 +08:00
userInfo.Find("IDText").GetComponent<Text>().text = "ID:" + App.CurrentUser.Id.ToString("000000");
if (!string.IsNullOrWhiteSpace(App.CurrentUser.Unionid))
{
userInfo.Find("Wx").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/Wechat_person_1");
}
if (App.CurrentUser.Sex == 2)
{
userInfo.Find("SexIcon").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/woman");
}
2021-04-28 15:21:06 +08:00
else
{
userInfo.Find("SexIcon").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/man");
}
2021-05-20 20:00:33 +08:00
Utils.DisplayHead(userInfo.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
2021-04-25 15:33:17 +08:00
userInfo.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImageByName(App.CurrentUser.Country);
userInfo.Find("CaloriesContainer").Find("CaloriesValue").GetComponent<Text>().text = double.Parse(summary.Kcal,CultureInfo.InvariantCulture).ToString("0") +" KCAL";
2021-04-19 14:36:08 +08:00
userInfo.Find("KMContainer").Find("KMValue").GetComponent<Text>().text = summary.TotalDistance.ToString("0") +" KM";
userInfo.Find("ClimbContainer").Find("ClimbValue").GetComponent<Text>().text = double.Parse(summary.TotalClimb,CultureInfo.InvariantCulture).ToString("0") + " M";
2021-06-09 17:29:38 +08:00
userInfo.Find("GroupTop").Find("FtpContainer").Find("FtpTime").GetComponent<Text>().text = App.CurrentUser.LastUpdateFtpTime.ToString("dd.MM.yyyy");
userInfo.Find("GroupTop").Find("WeightContainer").Find("WeightTime").GetComponent<Text>().text = App.CurrentUser.LastUpdateWeightTime.ToString("dd.MM.yyyy");
2021-04-28 18:41:54 +08:00
userInfo.Find("GroupTop").Find("WKGContainer").Find("WKGTime").GetComponent<Text>().text =
DateTime.Compare(App.CurrentUser.LastUpdateFtpTime, App.CurrentUser.LastUpdateWeightTime)>0
2021-06-09 17:29:38 +08:00
? App.CurrentUser.LastUpdateFtpTime.ToString("dd.MM.yyyy")
: App.CurrentUser.LastUpdateWeightTime.ToString("dd.MM.yyyy");
2021-12-28 11:25:09 +08:00
//新版设计稿
var todayData = transform.Find("TodayData");
2021-12-29 14:23:37 +08:00
if (todayData)
{
Utils.DisplayHead(todayData.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
todayData.Find("Datas/Distance/Value").GetComponent<Text>().text = $"{summary.ContinuesDay}"+ (summary.ContinuesDay > 1 ? App.GetLocalString("DAYS") : App.GetLocalString("DAY"));
2021-12-29 17:05:58 +08:00
todayData.Find("Datas/Climb/Value").GetComponent<Text>().text = $"{summary.ContinuesKm.ToString("#0")}KM";//$"{double.Parse(summary.TotalClimb, CultureInfo.InvariantCulture).ToString("0")}M";
todayData.Find("Datas/Carlories/Value").GetComponent<Text>().text = $"{summary.ContinuesKcal.ToString("#0")}KCAL";
2021-12-29 14:23:37 +08:00
//todayData.Find("Datas/Distance/Rank").GetComponent<Text>().text = summary.CurrentTotalDistance == 0 ? "——" : $"+{summary.CurrentTotalDistance.ToString("#0")}";
todayData.Find("Datas/Climb/Rank").GetComponent<Text>().text = summary.CurrentTotalDistance == 0 ? "——" : $"+{summary.CurrentTotalDistance.ToString("#0")}";
todayData.Find("Datas/Carlories/Rank").GetComponent<Text>().text = summary.CurrentTotalKcal == 0 ? "——" : $"+{summary.CurrentTotalKcal.ToString("#0")}";
}
2021-03-25 16:55:36 +08:00
}
2021-04-30 21:09:21 +08:00
async void GetSummary()
2021-03-25 16:55:36 +08:00
{
2021-04-30 21:09:21 +08:00
var res = await 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()
{
}
2021-04-19 14:36:08 +08:00
public override void Show()
{
base.Show();
transform.MyDOFade();
2021-04-23 15:36:18 +08:00
GetSummary();
2021-04-19 14:36:08 +08:00
}
2021-03-25 16:55:36 +08:00
}