2021-04-09 15:57:50 +08:00
|
|
|
|
using Assets.Scripts;
|
|
|
|
|
|
using Assets.Scripts.Apis.Models;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
2021-04-19 14:38:31 +08:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
public class RouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
|
|
|
|
|
|
{
|
2021-04-19 14:38:31 +08:00
|
|
|
|
RouteResult routeResult;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
// 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";
|
2021-04-19 14:36:08 +08:00
|
|
|
|
RouteResult data;
|
2021-04-19 15:44:11 +08:00
|
|
|
|
//滑动索引 0route 1match
|
|
|
|
|
|
int index;
|
|
|
|
|
|
public void Initial(RouteResult result,int index)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-19 14:38:31 +08:00
|
|
|
|
routeResult = result;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
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;
|
2021-04-27 18:26:30 +08:00
|
|
|
|
left.Find("Main").Find("Time").GetComponent<Text>().text = result.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
2021-04-09 15:57:50 +08:00
|
|
|
|
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}";
|
2021-04-19 15:44:11 +08:00
|
|
|
|
if (index == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
row1.Find("Rank").GetComponent<Text>().text = $"<color={titleColor}>Rank:</color>{result.Ranking}";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
row1.Find("Rank").GetComponent<Text>().text = $"";
|
|
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
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}";
|
2021-04-19 15:44:11 +08:00
|
|
|
|
if (index == 0)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
right = transform.Find("Right");
|
|
|
|
|
|
btnContinue = right.Find("BtnContinue");
|
|
|
|
|
|
if (btnContinue)
|
|
|
|
|
|
{
|
2021-04-25 19:41:35 +08:00
|
|
|
|
bool enabled = result.ContinueCyclingParam != null;
|
|
|
|
|
|
|
2021-04-19 15:44:11 +08:00
|
|
|
|
//btnContinue.gameObject.SetActive(false);
|
2021-04-25 15:33:17 +08:00
|
|
|
|
//btnContinue.GetComponent<Button>().onClick.AddListener(GoContinue);
|
|
|
|
|
|
UIManager.AddEvent(btnContinue.gameObject, EventTriggerType.PointerClick, (b) => GoContinue());
|
2021-04-25 19:41:35 +08:00
|
|
|
|
btnContinue.GetComponent<Button>().interactable = enabled;
|
|
|
|
|
|
btnContinue.GetComponent<Button>().enabled = enabled;
|
2021-04-19 15:44:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
btnReRide = right.Find("BtnReRide");
|
|
|
|
|
|
if (btnReRide)
|
|
|
|
|
|
{
|
|
|
|
|
|
//btnReRide.gameObject.SetActive(false);
|
2021-04-25 15:33:17 +08:00
|
|
|
|
UIManager.AddEvent(btnReRide.gameObject, EventTriggerType.PointerClick, (b) => GoReRide());
|
|
|
|
|
|
//btnReRide.GetComponent<Button>().onClick.AddListener(GoReRide);
|
2021-04-19 15:44:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
btnDelete = right.Find("BtnDelete");
|
|
|
|
|
|
if (btnDelete)
|
|
|
|
|
|
{
|
|
|
|
|
|
//btnDelete.gameObject.SetActive(false);
|
2021-04-25 15:33:17 +08:00
|
|
|
|
//btnDelete.GetComponent<Button>().onClick.AddListener(Delete);
|
|
|
|
|
|
UIManager.AddEvent(btnDelete.gameObject, EventTriggerType.PointerClick, (b) => Delete());
|
2021-04-19 15:44:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
SetButtonColor(false);
|
|
|
|
|
|
transform.Find("RightMatch").gameObject.SetActive(false);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
2021-04-19 15:44:11 +08:00
|
|
|
|
else
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
right = transform.Find("RightMatch");
|
|
|
|
|
|
transform.Find("Right").gameObject.SetActive(false);
|
|
|
|
|
|
right.Find("Value").GetComponent<Text>().text = result.Ranking.ToString();
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
2021-04-19 15:44:11 +08:00
|
|
|
|
right.gameObject.SetActive(true);
|
2021-04-28 15:21:06 +08:00
|
|
|
|
gameObject.GetComponent<Button>().onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Application.OpenURL(result.ViewUrl);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-04-19 15:44:11 +08:00
|
|
|
|
this.index = index;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Delete()
|
|
|
|
|
|
{
|
2021-04-28 15:21:06 +08:00
|
|
|
|
UIManager.ShowConfirm("Delete", "Delete this record?", async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var r = await ConfigHelper.mapApi.DeleteRecord(routeResult.Id);
|
|
|
|
|
|
UIManager.CloseConfirm();
|
|
|
|
|
|
if (r.result)
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyImmediate(gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Utils.showToast(gameObject, r.errMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GoReRide()
|
|
|
|
|
|
{
|
2021-04-28 15:21:06 +08:00
|
|
|
|
UIManager.ShowConfirm("ReRide", "Ride again?", () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
App.RouteIdParam = routeResult.RouteId;
|
|
|
|
|
|
App.routeResult = routeResult;
|
|
|
|
|
|
App.routeResult.ContinueCyclingParam = null;
|
|
|
|
|
|
SceneManager.LoadScene("Ride");
|
|
|
|
|
|
});
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GoContinue()
|
|
|
|
|
|
{
|
2021-04-28 15:21:06 +08:00
|
|
|
|
UIManager.ShowConfirm("Continue", "Continue riding?", () =>
|
2021-04-19 14:38:31 +08:00
|
|
|
|
{
|
2021-04-28 15:21:06 +08:00
|
|
|
|
if (routeResult.ContinueCyclingParam != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
App.RouteIdParam = routeResult.RouteId;
|
|
|
|
|
|
App.routeResult = routeResult;
|
|
|
|
|
|
SceneManager.LoadScene("Ride");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
2021-04-19 15:44:11 +08:00
|
|
|
|
void SetButtonColor(bool f)
|
|
|
|
|
|
{
|
2021-04-28 15:21:06 +08:00
|
|
|
|
if (index == 0 && routeResult!=null)
|
2021-04-19 15:44:11 +08:00
|
|
|
|
{
|
2021-04-26 16:25:52 +08:00
|
|
|
|
if (f)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool enabled = routeResult.ContinueCyclingParam == null;
|
|
|
|
|
|
btnContinue.GetComponent<Image>().color =
|
|
|
|
|
|
enabled ? Utils.HexToColorHtml("#75264e") : 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");
|
|
|
|
|
|
}
|
2021-04-19 15:44:11 +08:00
|
|
|
|
}
|
2021-04-26 16:25:52 +08:00
|
|
|
|
|
2021-04-19 15:44:11 +08:00
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.GetComponent<Image>().color = Utils.HexToColorHtml("#23232d");
|
2021-04-19 15:44:11 +08:00
|
|
|
|
if (index == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
right.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#414251");
|
|
|
|
|
|
right.Find("Value").GetComponent<Text>().color = Utils.HexToColorHtml("#5c5c6e");
|
|
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
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";
|
2021-04-19 15:44:11 +08:00
|
|
|
|
SetButtonColor(false);
|
2021-04-28 15:21:06 +08:00
|
|
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.GetComponent<Image>().color = Utils.HexToColorHtml("#353543");
|
2021-04-19 15:44:11 +08:00
|
|
|
|
if (index == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
right.Find("Text").GetComponent<Text>().color = Utils.HexToColorHtml("#5c5c6e");
|
|
|
|
|
|
right.Find("Value").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
|
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
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";
|
2021-04-19 15:44:11 +08:00
|
|
|
|
SetButtonColor(true);
|
2021-04-28 15:21:06 +08:00
|
|
|
|
Cursor.SetCursor(Resources.Load<Texture2D>("Images/PointerButtonHover"), Vector2.zero, CursorMode.Auto);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|