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(), mapCompetition.RouteCover, true); Utils.DisplayImage(transform.Find("InfoContainer/AltitudeCurve").GetComponent(), mapCompetition.AltitudeGraph, true); transform.Find("Text").GetComponent().SetTextWithEllipsis(mapCompetition.Title); transform.Find("GetReadyContainer").gameObject.SetActive(mapCompetition.Status == 2); //transform.Find("Text").GetComponent().text = mapCompetition.Title; //props.Find("DistanceText").GetComponent().text = $"{myMap.Distance.ToString(myMap.Distance > 1000 ? "#0" : "#0.00")}KM"; //props.Find("EleText").GetComponent().text = $"{(myMap.TotalClimb ?? 0.0).ToString(myMap.TotalClimb > 1000 ? "#0" : "#0.00")}M"; //props.Find("SlopeText").GetComponent().text = $"{myMap.AverageGrade.ToString("#0.00")}%"; transform.Find("InfoContainer/DataContainer/Distance/Text").GetComponent().text = $"{mapCompetition.Distance.ToString(mapCompetition.Distance > 1000 ? "#0" : "#0.00")}KM"; transform.Find("InfoContainer/DataContainer/Altitude/Text").GetComponent().text = $"{(mapCompetition.TotalClimb ?? 0.0).ToString(mapCompetition.TotalClimb > 1000 ? "#0" : "#0.00")}M"; transform.Find("InfoContainer/DataContainer/Slope/Text").GetComponent().text = $"{mapCompetition.AverageGrade.ToString("#0.00")}%"; transform.Find("InfoContainer/DataContainer/StartTime/Text").GetComponent().text = mapCompetition.StartTime.ToString(); transform.Find("CountContainer/Text").GetComponent().text = mapCompetition.ApplyCount.ToString(); SetStatus(mapCompetition); SetButtonGroup(mapCompetition); this.parent = parent; this.mapCompetition = mapCompetition; } private void SetButtonGroup(MapCompetition mapCompetition) { if (mapCompetition.Status == 1) { var game = Resources.Load("UI/Prefab/Race/ButtonGroup/BtnContainer-Enter"); var igame = Instantiate(game); igame.name = "BtnContainer"; igame.GetComponent().map = mapCompetition; igame.GetComponent().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("UI/Prefab/Race/ButtonGroup/BtnContainer-Watch"); var igame = Instantiate(game); igame.name = "BtnContainer"; igame.GetComponent().map = mapCompetition; igame.GetComponent().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("UI/Prefab/Race/ButtonGroup/BtnContainer-Double-H"); var igame = Instantiate(game); igame.name = "BtnContainer"; igame.GetComponent().map = mapCompetition; igame.GetComponent().parent = transform; igame.transform.Find("BtnJoin").gameObject.SetActive(mapCompetition.CanJoin); igame.transform.Find("BtnCancel").gameObject.SetActive(mapCompetition.HasJoin); igame.transform.SetParent(transform); igame.transform.localScale = Vector3.one; igame.transform.GetComponent().anchorMax = new Vector2(0, 0); igame.transform.GetComponent().anchorMin = new Vector2(1, 0); igame.transform.GetComponent().pivot = new Vector2(0.5f, 0); var loc = Vector3.zero; loc.y = 20; igame.transform.GetComponent().anchoredPosition = loc; } else { var game = Resources.Load("UI/Prefab/Race/ButtonGroup/BtnContainer-Double-V"); var igame = Instantiate(game); igame.name = "BtnContainer"; igame.GetComponent().map = mapCompetition; igame.GetComponent().parent = transform; igame.transform.Find("BtnJoin").gameObject.SetActive(mapCompetition.CanJoin); igame.transform.Find("BtnCancel").gameObject.SetActive(mapCompetition.HasJoin); igame.transform.SetParent(transform); igame.transform.localScale = Vector3.one; igame.transform.GetComponent().anchorMax = new Vector2(0, 0); igame.transform.GetComponent().anchorMin = new Vector2(1, 0); igame.transform.GetComponent().pivot = new Vector2(0.5f, 0); var loc = Vector3.zero; loc.y = 20; igame.transform.GetComponent().anchoredPosition = loc; } } } private Dictionary statusColorDict = new Dictionary { {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().color = Utils.HexToColorHtml(statusColorDict[mapCompetition.Status]); if (mapCompetition.Status == 2 && mapCompetition.HasJoin) { status.Find("Text").GetComponent().text = "Applied"; } else { status.Find("Text").GetComponent().text = mapCompetition.StatusVlaue; } } } public void OnPointerExit(PointerEventData eventData) { Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); transform.Find("Masking").GetComponent().DOFade(0, 0.5f); transform.Find("Text").GetComponent().DOFade(0, 0.5f); transform.Find("BtnContainer").GetComponent().DOFade(0, 0.5f); transform.Find("CountContainer").GetComponent().DOFade(0, 0.5f); transform.Find("GetReadyContainer").GetComponent().DOFade(0, 0.5f); transform.Find("InfoContainer").GetComponent().DOFade(1, 0.5f); if (myType == ItemType.small) { transform.Find("InfoContainer/DataContainer").GetComponent().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().DOFade(1,0.5f); transform.Find("InfoContainer").DOLocalMoveY(-246, 0.3f); } if (this.parent != null) { this.parent.GetComponent().SetCurrentItem(null); //this.parent.SendMessage("SetCurrentItem", null, SendMessageOptions.RequireReceiver); } } public void OnPointerEnter(PointerEventData eventData) { Cursor.SetCursor(Resources.Load("Images/PointerButtonHover"), Vector2.zero, CursorMode.Auto); transform.Find("Masking").GetComponent().DOFade(1, 0.5f); transform.Find("Text").GetComponent().DOFade(1, 0.5f); transform.Find("BtnContainer").GetComponent().DOFade(1, 0.5f); transform.Find("CountContainer").GetComponent().DOFade(1, 0.5f); transform.Find("GetReadyContainer").GetComponent().DOFade(1, 0.5f); transform.Find("InfoContainer").GetComponent().DOFade(0, 0.5f); if (myType == ItemType.small) { transform.Find("InfoContainer/DataContainer").GetComponent().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().DOFade(0, 0.5f); transform.Find("InfoContainer").DOLocalMoveY(-155, 0.3f); } if (this.parent != null) { this.parent.GetComponent().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); } */ 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 = (++mapCompetition.ApplyCount).ToString(); SetStatus(mapCompetition); transform.Find("BtnContainer").gameObject.Destroy(); SetButtonGroup(mapCompetition); Utils.showToast(null, "Successful application!", 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 = (--mapCompetition.ApplyCount).ToString(); SetStatus(mapCompetition); transform.Find("BtnContainer").gameObject.Destroy(); SetButtonGroup(mapCompetition); Utils.showToast(null, "Successful cancellation application!", type: 1); } else { Utils.showToast(null, res.errMsg, type: 0); } } }