242 lines
11 KiB
C#
242 lines
11 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.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;
|
|
public MapCompetition mapCompetition { get; set; }
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
public void Initial(MapCompetition mapCompetition,Transform parent)
|
|
{
|
|
Utils.DisplayImage(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, true);
|
|
Utils.DisplayImage(transform.Find("InfoContainer/AltitudeCurve").GetComponent<RawImage>(), mapCompetition.AltitudeGraph, true);
|
|
transform.Find("Text").GetComponent<Text>().SetTextWithEllipsis(mapCompetition.Title);
|
|
transform.Find("GetReadyContainer").gameObject.SetActive(mapCompetition.Status == 2);
|
|
//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("InfoContainer/DataContainer/Distance/Text").GetComponent<Text>().text
|
|
= $"{mapCompetition.Distance.ToString(mapCompetition.Distance > 1000 ? "#0" : "#0.00")}KM";
|
|
transform.Find("InfoContainer/DataContainer/Altitude/Text").GetComponent<Text>().text
|
|
= $"{(mapCompetition.TotalClimb ?? 0.0).ToString(mapCompetition.TotalClimb > 1000 ? "#0" : "#0.00")}M";
|
|
transform.Find("InfoContainer/DataContainer/Slope/Text").GetComponent<Text>().text
|
|
= $"{mapCompetition.AverageGrade.ToString("#0.00")}%";
|
|
transform.Find("InfoContainer/DataContainer/StartTime/Text").GetComponent<Text>().text = mapCompetition.StartTime.ToString();
|
|
transform.Find("CountContainer/Text").GetComponent<Text>().text = mapCompetition.ApplyCount.ToString();
|
|
SetStatus(mapCompetition);
|
|
SetButtonGroup(mapCompetition);
|
|
this.parent = parent;
|
|
this.mapCompetition = mapCompetition;
|
|
}
|
|
|
|
private void SetButtonGroup(MapCompetition mapCompetition)
|
|
{
|
|
if (mapCompetition.Status == 1 || mapCompetition.Status == 3 || (mapCompetition.Status == 2 && !mapCompetition.HasJoin))
|
|
{
|
|
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.SetParent(transform);
|
|
igame.transform.localScale = Vector3.one;
|
|
var loc = Vector3.zero;
|
|
loc.y = -252;
|
|
igame.transform.localPosition = 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.SetParent(transform);
|
|
igame.transform.localScale = Vector3.one;
|
|
var loc = Vector3.zero;
|
|
loc.y = -209;
|
|
igame.transform.localPosition = loc;
|
|
}
|
|
}
|
|
}
|
|
|
|
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.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
status.GetComponent<RawImage>().color = Utils.HexToColorHtml(statusColorDict[mapCompetition.Status]);
|
|
if (mapCompetition.Status == 2 && mapCompetition.HasJoin)
|
|
{
|
|
status.Find("Text").GetComponent<Text>().text = "Applied";
|
|
}
|
|
else
|
|
{
|
|
status.Find("Text").GetComponent<Text>().text = mapCompetition.StatusVlaue;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
transform.Find("Masking").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("Text").GetComponent<CanvasGroup>().DOFade(0, 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("InfoContainer").GetComponent<Image>().DOFade(1, 0.5f);
|
|
if (myType == ItemType.small)
|
|
{
|
|
transform.Find("InfoContainer/DataContainer").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("InfoContainer/AltitudeCurve").DOScaleY(1f, 0.5f);
|
|
transform.Find("InfoContainer").DOLocalMoveY(-225, 0.3f);
|
|
}
|
|
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)
|
|
{
|
|
Cursor.SetCursor(Resources.Load<Texture2D>("Images/PointerButtonHover"), Vector2.zero, CursorMode.Auto);
|
|
transform.Find("Masking").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
transform.Find("Text").GetComponent<CanvasGroup>().DOFade(1, 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("InfoContainer").GetComponent<Image>().DOFade(0, 0.5f);
|
|
if (myType == ItemType.small)
|
|
{
|
|
transform.Find("InfoContainer/DataContainer").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
transform.Find("InfoContainer/AltitudeCurve").DOScaleY(1.7f, 0.5f);
|
|
transform.Find("InfoContainer").DOLocalMoveY(-124 + 50, 0.3f);
|
|
//transform.Find("InfoContainer").DOLocalMoveY(-139, 0.3f);
|
|
}
|
|
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);
|
|
|
|
}
|
|
/*
|
|
//先报名
|
|
if (_canJoin)
|
|
{
|
|
MapCompetitionApi s = new MapCompetitionApi();
|
|
var rrr = s.ApplyMapCompetition(cyclingController.competitionId);
|
|
if (rrr.Result.result)
|
|
{
|
|
var competition = s.GetById(cyclingController.competitionId).data;
|
|
_canStart = competition.CanStart;
|
|
}
|
|
rideNowText.text = "RideNow";
|
|
}
|
|
else
|
|
{
|
|
base.StartRide(baseEvent);
|
|
}
|
|
*/
|
|
async public void Join()
|
|
{
|
|
var res = await ConfigHelper.mapCompetitionApi.ApplyMapCompetition(mapCompetition.Id);
|
|
if (res.result)
|
|
{
|
|
mapCompetition.HasJoin = true;
|
|
transform.Find("CountContainer/Text").GetComponent<Text>().text = (++mapCompetition.ApplyCount).ToString();
|
|
SetStatus(mapCompetition);
|
|
transform.Find("BtnContainer").gameObject.Destroy();
|
|
SetButtonGroup(mapCompetition);
|
|
Utils.showToast(null, "Successful application!", type: 1);
|
|
}
|
|
}
|
|
async public void CancelJoin()
|
|
{
|
|
var res = await ConfigHelper.mapCompetitionApi.CancelMapCompetition(mapCompetition.Id);
|
|
if (res.result)
|
|
{
|
|
mapCompetition.HasJoin = false;
|
|
transform.Find("CountContainer/Text").GetComponent<Text>().text = (--mapCompetition.ApplyCount).ToString();
|
|
SetStatus(mapCompetition);
|
|
transform.Find("BtnContainer").gameObject.Destroy();
|
|
SetButtonGroup(mapCompetition);
|
|
Utils.showToast(null, "Successful cancellation application!", type: 1);
|
|
}
|
|
}
|
|
}
|