348 lines
15 KiB
C#
348 lines
15 KiB
C#
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class RaceItemScript : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerUpHandler
|
|
{
|
|
// Start is called before the first frame update
|
|
public enum ItemType { big, small }
|
|
private Transform parent;
|
|
[SerializeField] ItemType myType;
|
|
private string _from = null;
|
|
|
|
internal void Refresh()
|
|
{
|
|
if (mapCompetition == null) return;
|
|
var res1 = ConfigHelper.mapCompetitionApi.GetById(mapCompetition.Id);
|
|
if (res1.result)
|
|
{
|
|
Initial(res1.data, null);
|
|
}
|
|
}
|
|
|
|
public MapCompetition mapCompetition { get; set; }
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
public void Initial(MapCompetition mapCompetition,Transform parent,string from = "list")
|
|
{
|
|
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
transform.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
App.RouteIdParam = mapCompetition.RouteId;
|
|
App.CompetionId = mapCompetition.Id;
|
|
SceneManager.LoadScene("Ride");
|
|
});
|
|
Utils.DisplayImage(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, true);
|
|
#else
|
|
if (string.IsNullOrEmpty(_from))
|
|
{
|
|
_from = from;
|
|
}
|
|
if (_from == "list")
|
|
{
|
|
Utils.DisplayImage(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, true);
|
|
transform.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
UIManager.ShowRaceDetailModal(transform,mapCompetition);
|
|
});
|
|
}
|
|
#endif
|
|
Utils.DisplayImage(transform.Find("AltitudeCurve").GetComponent<RawImage>(), mapCompetition.AltitudeGraph, true);
|
|
transform.Find("InfoContainer/Text").GetComponent<Text>().SetTextWithEllipsis(mapCompetition.Title);
|
|
transform.Find("GetReadyContainer").gameObject.SetActive(mapCompetition.Status != 4);
|
|
transform.Find("GetReadyContainer-2").gameObject.SetActive(mapCompetition.Status == 1);
|
|
//transform.Find("Text").GetComponent<Text>().text = mapCompetition.Title;
|
|
//props.Find("DistanceText").GetComponent<Text>().text = $"{myMap.Distance.ToString(myMap.Distance > 1000 ? "#0" : "#0.00")}KM";
|
|
//props.Find("EleText").GetComponent<Text>().text = $"{(myMap.TotalClimb ?? 0.0).ToString(myMap.TotalClimb > 1000 ? "#0" : "#0.00")}M";
|
|
//props.Find("SlopeText").GetComponent<Text>().text = $"{myMap.AverageGrade.ToString("#0.00")}%";
|
|
transform.Find("DataContainer/Distance/Text").GetComponent<Text>().text
|
|
= $"{mapCompetition.Distance.ToString(mapCompetition.Distance > 1000 ? "#0" : "#0.00")}KM";
|
|
transform.Find("DataContainer/Altitude/Text").GetComponent<Text>().text
|
|
= $"{(mapCompetition.TotalClimb ?? 0.0).ToString(mapCompetition.TotalClimb > 1000 ? "#0" : "#0.00")}M";
|
|
transform.Find("DataContainer/Slope/Text").GetComponent<Text>().text
|
|
= $"{mapCompetition.AverageGrade.ToString("#0.00")}%";
|
|
transform.Find("InfoContainer/StartTime/Text").GetComponent<Text>().text = mapCompetition.StartTime.ToLocalTime().ToString();
|
|
transform.Find("CountContainer/Text").GetComponent<Text>().text = mapCompetition.ApplyCount.ToString();
|
|
SetStatus(mapCompetition);
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
SetButtonGroup(mapCompetition);
|
|
#else
|
|
if (_from != "list")
|
|
{
|
|
SetButtonGroup(mapCompetition);
|
|
}
|
|
#endif
|
|
if (parent != null)
|
|
{
|
|
this.parent = parent;
|
|
}
|
|
this.mapCompetition = mapCompetition;
|
|
}
|
|
|
|
private void SetButtonGroup(MapCompetition mapCompetition)
|
|
{
|
|
var container = transform.Find("BtnContainer");
|
|
container.GetComponent<RaceButtonGroupScript>().map = mapCompetition;
|
|
container.GetComponent<RaceButtonGroupScript>().parent = transform;
|
|
container.Find("BtnCancel").gameObject.SetActive(mapCompetition.CanCancelJoin);
|
|
container.Find("BtnJoin").gameObject.SetActive(mapCompetition.CanJoin);
|
|
container.Find("BtnEnter").gameObject.SetActive(true);
|
|
container.Find("BtnWatch").gameObject.SetActive(false);
|
|
//if (transform.Find("BtnContainer") != null)
|
|
//{
|
|
// transform.Find("BtnContainer").gameObject.Destroy();
|
|
//}
|
|
//if (mapCompetition.Status == 1)
|
|
//{
|
|
// var game = Resources.Load<GameObject>("UI/Prefab/Race/ButtonGroup/BtnContainer-Enter");
|
|
// var igame = Instantiate(game);
|
|
// igame.name = "BtnContainer";
|
|
// igame.GetComponent<RaceButtonGroupScript>().map = mapCompetition;
|
|
// igame.GetComponent<RaceButtonGroupScript>().parent = transform;
|
|
// igame.transform.SetParent(transform);
|
|
// igame.transform.localScale = Vector3.one;
|
|
// var loc = Vector3.zero;
|
|
// loc.y = myType == ItemType.big ? -252 : -257;
|
|
// igame.transform.localPosition = loc;
|
|
//}
|
|
//else
|
|
//if (mapCompetition.Status == 4)
|
|
//{
|
|
// var game = Resources.Load<GameObject>("UI/Prefab/Race/ButtonGroup/BtnContainer-Watch");
|
|
// var igame = Instantiate(game);
|
|
// igame.name = "BtnContainer";
|
|
// igame.GetComponent<RaceButtonGroupScript>().map = mapCompetition;
|
|
// igame.GetComponent<RaceButtonGroupScript>().parent = transform;
|
|
// igame.transform.SetParent(transform);
|
|
// igame.transform.localScale = Vector3.one;
|
|
// var loc = Vector3.zero;
|
|
// loc.y = myType == ItemType.big ? -252 : -257;
|
|
// igame.transform.localPosition = loc;
|
|
//}
|
|
//else
|
|
//{
|
|
// if (myType == ItemType.big)
|
|
// {
|
|
// var game = Resources.Load<GameObject>("UI/Prefab/Race/ButtonGroup/BtnContainer-Double-H");
|
|
// var igame = Instantiate(game);
|
|
// igame.name = "BtnContainer";
|
|
// igame.GetComponent<RaceButtonGroupScript>().map = mapCompetition;
|
|
// igame.GetComponent<RaceButtonGroupScript>().parent = transform;
|
|
// igame.transform.Find("BtnJoin").gameObject.SetActive(mapCompetition.CanJoin);
|
|
// igame.transform.Find("BtnCancel").gameObject.SetActive(mapCompetition.CanCancelJoin);
|
|
// igame.transform.SetParent(transform);
|
|
// igame.transform.localScale = Vector3.one;
|
|
// igame.transform.GetComponent<RectTransform>().anchorMax = new Vector2(0, 0);
|
|
// igame.transform.GetComponent<RectTransform>().anchorMin = new Vector2(1, 0);
|
|
// igame.transform.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0);
|
|
// var loc = Vector3.zero;
|
|
// loc.y = 20;
|
|
// loc.y = 20;
|
|
// igame.transform.GetComponent<RectTransform>().anchoredPosition = loc;
|
|
// }
|
|
// else
|
|
// {
|
|
// var game = Resources.Load<GameObject>("UI/Prefab/Race/ButtonGroup/BtnContainer-Double-V");
|
|
// var igame = Instantiate(game);
|
|
// igame.name = "BtnContainer";
|
|
// igame.GetComponent<RaceButtonGroupScript>().map = mapCompetition;
|
|
// igame.GetComponent<RaceButtonGroupScript>().parent = transform;
|
|
// igame.transform.Find("BtnJoin").gameObject.SetActive(mapCompetition.CanJoin);
|
|
// igame.transform.Find("BtnCancel").gameObject.SetActive(mapCompetition.CanCancelJoin);
|
|
|
|
// igame.transform.SetParent(transform);
|
|
// igame.transform.localScale = Vector3.one;
|
|
// igame.transform.GetComponent<RectTransform>().anchorMax = new Vector2(0, 0);
|
|
// igame.transform.GetComponent<RectTransform>().anchorMin = new Vector2(1, 0);
|
|
// igame.transform.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0);
|
|
// var loc = Vector3.zero;
|
|
// loc.y = 20;
|
|
// igame.transform.GetComponent<RectTransform>().anchoredPosition = loc;
|
|
// }
|
|
//}
|
|
//if (transform.Find("Masking").GetComponent<CanvasGroup>().alpha == 1)
|
|
//{
|
|
// transform.Find("BtnContainer").GetComponent<CanvasGroup>().alpha = 1;
|
|
//}
|
|
}
|
|
|
|
private Dictionary<int, string> statusColorDict = new Dictionary<int, string>
|
|
{
|
|
{2,"#F93086" },{3,"#41A6FE" },{4,"#6E6E7D" },
|
|
};
|
|
private void SetStatus(MapCompetition mapCompetition)
|
|
{
|
|
var status = transform.Find("Status");
|
|
if (mapCompetition.Status <= 1)
|
|
{
|
|
status.GetComponent<CanvasGroup>().alpha = 0;
|
|
}
|
|
else
|
|
{
|
|
status.GetComponent<RawImage>().color = Utils.HexToColorHtml(statusColorDict[mapCompetition.Status]);
|
|
if (mapCompetition.Status == 2 && !mapCompetition.HasJoin)
|
|
{
|
|
status.GetComponent<CanvasGroup>().alpha = 0;
|
|
}
|
|
else
|
|
{
|
|
status.GetComponent<CanvasGroup>().alpha = 1;
|
|
status.Find("Text").GetComponent<Text>().text =
|
|
mapCompetition.Status == 2?"Registered":mapCompetition.StatusVlaue;
|
|
}
|
|
}
|
|
if (status.GetComponent<ContentFitterController>())
|
|
{
|
|
Debug.Log("cf刷新一次1");
|
|
status.GetComponent<ContentFitterController>().Refresh();
|
|
}
|
|
}
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
float? localY = null;
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
transform.DOLocalMoveY(localY.Value, 0.3f);
|
|
transform.Find("Masking").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("AltitudeCurve").GetComponent<RawImage>().DOFade(0, 0.5f);
|
|
transform.Find("InfoContainer/Text").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("BtnContainer").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("CountContainer").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("GetReadyContainer").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("GetReadyContainer-2").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("InfoContainer").GetComponent<CanvasGroup>().DOFade(1, 0.2f);
|
|
if (myType == ItemType.small)
|
|
{
|
|
transform.Find("DataContainer").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
}
|
|
else
|
|
{
|
|
transform.Find("InfoContainer/Line").GetComponent<Image>().DOFade(1,0.5f);
|
|
transform.Find("InfoContainer").DOLocalMoveY(-246, 0.3f);
|
|
}
|
|
if (this.parent != null)
|
|
{
|
|
this.parent.GetComponent<RaceScript>().SetCurrentItem(null);
|
|
//this.parent.SendMessage("SetCurrentItem", null, SendMessageOptions.RequireReceiver);
|
|
}
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (localY == null)
|
|
{
|
|
localY = transform.localPosition.y;
|
|
}
|
|
transform.DOLocalMoveY(localY.Value + 5, 0.3f);
|
|
Cursor.SetCursor(Resources.Load<Texture2D>("Images/PointerButtonHover"), Vector2.zero, CursorMode.Auto);
|
|
transform.Find("Masking").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("AltitudeCurve").GetComponent<RawImage>().DOFade(1, 0.5f);
|
|
transform.Find("InfoContainer/Text").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("BtnContainer").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("CountContainer").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("GetReadyContainer").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("GetReadyContainer-2").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("InfoContainer").GetComponent<CanvasGroup>().DOFade(0, 0.2f);
|
|
if (myType == ItemType.small)
|
|
{
|
|
transform.Find("DataContainer").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
}
|
|
else
|
|
{
|
|
transform.Find("InfoContainer/Line").GetComponent<Image>().DOFade(0, 0.5f);
|
|
transform.Find("InfoContainer").DOLocalMoveY(-155, 0.3f);
|
|
}
|
|
if (this.parent != null)
|
|
{
|
|
this.parent.GetComponent<RaceScript>().SetCurrentItem(transform);
|
|
//this.parent.SendMessage("SetCurrentItem", transform);
|
|
}
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
|
|
}
|
|
#else
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
//if (_from == "list")
|
|
//{
|
|
// transform.Find("Masking").GetComponent<CanvasGroup>().DOFade(0, 0.3f);
|
|
//}
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
//if (_from == "list")
|
|
//{
|
|
// transform.Find("Masking").GetComponent<CanvasGroup>().DOFade(1, 0.3f);
|
|
//}
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
|
|
}
|
|
#endif
|
|
public void Join()
|
|
{
|
|
var res = ConfigHelper.mapCompetitionApi.ApplyMapCompetition(mapCompetition.Id);
|
|
if (res.result)
|
|
{
|
|
|
|
//mapCompetition.HasJoin = true;
|
|
//mapCompetition.CanJoin = false;
|
|
//transform.Find("CountContainer/Text").GetComponent<Text>().text = (++mapCompetition.ApplyCount).ToString();
|
|
//SetStatus(mapCompetition);
|
|
//transform.Find("BtnContainer").gameObject.Destroy();
|
|
//SetButtonGroup(mapCompetition);
|
|
Refresh();
|
|
Utils.showToast(null, "success", type: 1);
|
|
}
|
|
else
|
|
{
|
|
Utils.showToast(null, res.errMsg, type: 0);
|
|
}
|
|
}
|
|
public void CancelJoin()
|
|
{
|
|
var res = ConfigHelper.mapCompetitionApi.CancelMapCompetition(mapCompetition.Id);
|
|
if (res.result)
|
|
{
|
|
//mapCompetition.HasJoin = false;
|
|
//mapCompetition.CanJoin = true;
|
|
//transform.Find("CountContainer/Text").GetComponent<Text>().text = (--mapCompetition.ApplyCount).ToString();
|
|
//SetStatus(mapCompetition);
|
|
//transform.Find("BtnContainer").gameObject.Destroy();
|
|
//SetButtonGroup(mapCompetition);
|
|
App.CompetitionIdList.Remove(mapCompetition.Id);
|
|
Refresh();
|
|
Utils.showToast(null, "success", type: 1);
|
|
}
|
|
else
|
|
{
|
|
Utils.showToast(null, res.errMsg, type: 0);
|
|
}
|
|
}
|
|
|
|
|
|
}
|