2021-04-19 17:59:45 +08:00

184 lines
7.8 KiB
C#

using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class RouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
{
RouteResult routeResult;
// Start is called before the first frame update
Transform left,row1,row2,right;
Transform btnReRide, btnContinue, btnDelete;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
string titleColor = "#5c5c6e";
RouteResult data;
//滑动索引 0route 1match
int index;
public void Initial(RouteResult result,int index)
{
routeResult = result;
left = transform.Find("Left");
row1 = left.Find("Main").Find("Row1");
row2 = left.Find("Main").Find("Row2");
Utils.DisplayImage(StartCoroutine, transform.Find("CoverImage").GetComponent<RawImage>(), result.RouteImage);
left.Find("Main").Find("Name").GetComponent<Text>().text = result.RouteName;
left.Find("Main").Find("Time").GetComponent<Text>().text = result.CreateTime.ToString("yyyy-MM-dd HH-mm-ss");
row1.Find("Time").GetComponent<Text>().text = $"<color={titleColor}>Riding time:</color>{result.TrainingTime}";
row1.Find("Distance").GetComponent<Text>().text = $"<color={titleColor}>Mileage:</color>{result.EndDistance.ToString("#0.00")}KM";
row1.Find("Times").GetComponent<Text>().text = $"<color={titleColor}>Times:</color>{result.Count}";
if (index == 0)
{
row1.Find("Rank").GetComponent<Text>().text = $"<color={titleColor}>Rank:</color>{result.Ranking}";
}
else
{
row1.Find("Rank").GetComponent<Text>().text = $"";
}
left.Find("Progress").Find("Image").GetComponent<Image>().fillAmount = (float)result.Progress;
left.Find("Progress").Find("Value").GetComponent<Text>().text = (result.Progress * 100).ToString("#0");
row2.Find("Device").GetComponent<Text>().text = $"<color={titleColor}>Cycling equipment:</color>{result.ManufacturerName}";
if (index == 0)
{
right = transform.Find("Right");
btnContinue = right.Find("BtnContinue");
if (btnContinue)
{
//btnContinue.gameObject.SetActive(false);
btnContinue.GetComponent<Button>().onClick.AddListener(GoContinue);
}
btnReRide = right.Find("BtnReRide");
if (btnReRide)
{
//btnReRide.gameObject.SetActive(false);
btnReRide.GetComponent<Button>().onClick.AddListener(GoReRide);
}
btnDelete = right.Find("BtnDelete");
if (btnDelete)
{
//btnDelete.gameObject.SetActive(false);
btnDelete.GetComponent<Button>().onClick.AddListener(Delete);
}
SetButtonColor(false);
transform.Find("RightMatch").gameObject.SetActive(false);
}
else
{
right = transform.Find("RightMatch");
transform.Find("Right").gameObject.SetActive(false);
right.Find("Value").GetComponent<Text>().text = result.Ranking.ToString();
}
right.gameObject.SetActive(true);
this.index = index;
}
private void Delete()
{
//throw new NotImplementedException();
UIManager.ShowAlert("暂未实现");
}
private void GoReRide()
{
App.RouteIdParam = routeResult.RouteId;
App.routeResult = routeResult;
App.routeResult.ContinueCyclingParam = null;
SceneManager.LoadScene("Ride");
}
private void GoContinue()
{
if (routeResult.ContinueCyclingParam != null)
{
App.RouteIdParam = routeResult.RouteId;
App.routeResult = routeResult;
SceneManager.LoadScene("Ride");
}
}
void SetButtonColor(bool f)
{
if (f)
{
btnContinue.GetComponent<Image>().color = Utils.HexToColorHtml("#F93086");
btnReRide.GetComponent<Image>().color = Utils.HexToColorHtml("#F93086");
btnDelete.GetComponent<Image>().color = Utils.HexToColorHtml("#353543");
btnContinue.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
btnReRide.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
btnDelete.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#474759");
}
else
{
btnContinue.GetComponent<Image>().color = Utils.HexToColorHtml("#414251");
btnReRide.GetComponent<Image>().color = Utils.HexToColorHtml("#414251");
btnDelete.GetComponent<Image>().color = Utils.HexToColorHtml("#23232D");
btnContinue.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#353543");
btnReRide.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#353543");
btnDelete.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#353543");
}
}
public void OnPointerExit(PointerEventData eventData)
{
transform.GetComponent<Image>().color = Utils.HexToColorHtml("#23232d");
if (index == 1)
{
right.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#414251");
right.Find("Value").GetComponent<Text>().color = Utils.HexToColorHtml("#5c5c6e");
}
if (left != null)
{
left.Find("Main").Find("Time").GetComponent<Text>().color = Utils.HexToColorHtml("#414251");
left.Find("Progress").Find("Image").GetComponent<Image>().color = Utils.HexToColorHtml("#5c5c6e");
left.Find("Progress").Find("Value").GetComponent<Text>().color = Utils.HexToColorHtml("#414251");
left.Find("Progress").Find("bf").GetComponent<Text>().color = Utils.HexToColorHtml("#414251");
}
if (row1 != null)
{
row1.Find("Time").GetComponent<Text>().color = Utils.HexToColorHtml("#9E9EAD");
row1.Find("Distance").GetComponent<Text>().color = Utils.HexToColorHtml("#9E9EAD");
row1.Find("Times").GetComponent<Text>().color = Utils.HexToColorHtml("#9E9EAD");
row1.Find("Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#9E9EAD");
}
titleColor = "#414251";
SetButtonColor(false);
}
public void OnPointerEnter(PointerEventData eventData)
{
transform.GetComponent<Image>().color = Utils.HexToColorHtml("#353543");
if (index == 1)
{
right.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#5c5c6e");
right.Find("Value").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
if (left != null)
{
left.Find("Main").Find("Time").GetComponent<Text>().color = Utils.HexToColorHtml("#5c5c6e");
left.Find("Progress").Find("Image").GetComponent<Image>().color = Utils.HexToColorHtml("#F93086");
left.Find("Progress").Find("Value").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
left.Find("Progress").Find("bf").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
if (row1 != null)
{
row1.Find("Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
row1.Find("Distance").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
row1.Find("Times").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
row1.Find("Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
titleColor = "#5c5c6e";
SetButtonColor(true);
}
}