123 lines
5.2 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.UI;
public class RouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
{
// 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";
public void Initial(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}";
row1.Find("Rank").GetComponent<Text>().text = $"<color={titleColor}>Rank:</color>{result.Ranking}";
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}";
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);
}
}
private void Delete()
{
throw new NotImplementedException();
}
private void GoReRide()
{
throw new NotImplementedException();
}
private void GoContinue()
{
throw new NotImplementedException();
}
public void OnPointerExit(PointerEventData eventData)
{
transform.GetComponent<Image>().color = Utils.HexToColorHtml("#23232d");
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";
btnContinue.gameObject.SetActive(false);
btnReRide.gameObject.SetActive(false);
btnDelete.gameObject.SetActive(false);
}
public void OnPointerEnter(PointerEventData eventData)
{
transform.GetComponent<Image>().color = Utils.HexToColorHtml("#353543");
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";
btnContinue.gameObject.SetActive(true);
btnReRide.gameObject.SetActive(true);
btnDelete.gameObject.SetActive(true);
}
}