170 lines
6.2 KiB
C#
170 lines
6.2 KiB
C#
using Assets.Scripts;
|
|
using Assets.Scripts.Apis;
|
|
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 PropNames
|
|
{
|
|
public static List<string> icons = new List<string> { "icon1", "icon2", "icon3" };
|
|
public static List<string> texts = new List<string> { "DistanceText", "EleText", "SlopeText" };
|
|
public static Dictionary<bool, string> colorDict = new Dictionary<bool, string>
|
|
{
|
|
{ true,"#ffffff"},{false,"#5c5c6e" }
|
|
};
|
|
}
|
|
public class MapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
|
|
{
|
|
// Start is called before the first frame update
|
|
//[SerializeField] Text text;
|
|
//[SerializeField] GameObject panel;
|
|
//[SerializeField] RawImage rawImage;
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
float? localY = null;
|
|
MapRoute map;
|
|
public void Initial(MapRoute myMap)
|
|
{
|
|
map = myMap;
|
|
//localY = transform.GetComponent<RectTransform>().rect.height;
|
|
//Debug.Log(localY);
|
|
//UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (Base) =>
|
|
//{
|
|
// UIManager.ShowMapDetailPanel(myMap.Id);
|
|
//});
|
|
//UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerEnter, (Base) =>
|
|
//{
|
|
// if (localY == null)
|
|
// {
|
|
// localY = transform.localPosition.y;
|
|
// }
|
|
// //transform.localPosition.Set(transform.localPosition.x,localY.Value+8, transform.localPosition.z);
|
|
// //transform.DOLocalMoveY(localY.Value + 8, 0.5f);
|
|
// //transform.domov(localY+8, 0.5f);
|
|
//});
|
|
//UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerExit, (Base) =>
|
|
//{
|
|
// //transform.localPosition.Set(transform.localPosition.x, localY.Value, transform.localPosition.z);
|
|
// //transform.DOLocalMoveY(localY.Value, 0.5f);
|
|
//});
|
|
transform.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
UIManager.ShowMapDetailPanel(myMap.Id);
|
|
});
|
|
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
|
Utils.DisplayImage(StartCoroutine, transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage);
|
|
|
|
transform.Find("Hot").gameObject.SetActive(myMap.IsFire);
|
|
var props = transform.Find("Props");
|
|
props.Find("DistanceText").GetComponent<Text>().text = $"{myMap.Distance.ToString("#0.00")}KM";
|
|
props.Find("EleText").GetComponent<Text>().text = $"{(myMap.TotalClimb ?? 0.0).ToString("#0.00")}M";
|
|
props.Find("SlopeText").GetComponent<Text>().text = $"{myMap.AverageGrade.ToString("#0.00")}%";
|
|
props.Find("rideText").GetComponent<Text>().text = myMap.TheHeat.ToString();
|
|
var tabContainer = transform.Find("TabContainer");
|
|
var diff = tabContainer.Find("Diff");
|
|
diff.Find("Text").GetComponent<Text>().text = myMap.Hard;
|
|
tabContainer.Find("3d").gameObject.SetActive(myMap.Enable3D);
|
|
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(myMap.CountryCode);
|
|
transform.Find("CollectImg").GetComponent<Button>().onClick.AddListener(Collect);
|
|
transform.Find("CollectImg").gameObject.SetActive(false);
|
|
transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
|
UIManager.Instance.collectDict[myMap.IsFavorite];
|
|
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
|
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
|
Utils.DisplayImage(StartCoroutine, transform.Find("MapHBImg").GetComponent<RawImage>(), myMap.AltitudeGraph);
|
|
SetActive4Button(false);
|
|
}
|
|
|
|
private void Ride()
|
|
{
|
|
App.RouteIdParam = map.Id;
|
|
if (!App.MainSceneParam.ContainsKey("Name"))
|
|
{
|
|
App.MainSceneParam.Add("Name", "MapListPanel");
|
|
}
|
|
else
|
|
{
|
|
App.MainSceneParam["Name"] = "MapListPanel";
|
|
}
|
|
SceneManager.LoadScene("Ride");
|
|
}
|
|
|
|
private void Info()
|
|
{
|
|
UIManager.ShowMapDetailPanel(map.Id);
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (localY == null)
|
|
{
|
|
localY = transform.localPosition.y;
|
|
}
|
|
transform.Find("CollectImg").gameObject.SetActive(true);
|
|
transform.DOLocalMoveY(localY.Value + 5, 0.5f);
|
|
SetActive4Button(true);
|
|
SetColor(map.IsFavorite);
|
|
}
|
|
void SetActive4Button(bool b)
|
|
{
|
|
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
|
transform.Find("BtnInfo").gameObject.SetActive(b);
|
|
transform.Find("BtnRide").gameObject.SetActive(b);
|
|
}
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
transform.DOLocalMoveY(localY.Value, 0.5f);
|
|
transform.Find("CollectImg").gameObject.SetActive(false);
|
|
SetActive4Button(false);
|
|
SetColor(false);
|
|
}
|
|
private void SetColor(bool isFav)
|
|
{
|
|
PropNames.icons.ForEach((v) =>
|
|
{
|
|
transform.Find("Props").Find(v).GetComponent<Image>().color = Utils.HexToColorHtml(
|
|
PropNames.colorDict[isFav]);
|
|
});
|
|
PropNames.texts.ForEach((v) =>
|
|
{
|
|
transform.Find("Props").Find(v).GetComponent<Text>().color = Utils.HexToColorHtml(
|
|
PropNames.colorDict[isFav]);
|
|
});
|
|
}
|
|
async void Collect()
|
|
{
|
|
JsonResult<object> r;
|
|
if (map.IsFavorite)
|
|
{
|
|
r = await ConfigHelper.mapApi.CancelFav(map.Id.ToString());
|
|
}
|
|
else
|
|
{
|
|
r = await ConfigHelper.mapApi.AddFav(map.Id.ToString());
|
|
}
|
|
if (r.result)
|
|
{
|
|
map.IsFavorite = !map.IsFavorite;
|
|
transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
|
UIManager.Instance.collectDict[map.IsFavorite];
|
|
SetColor(map.IsFavorite);
|
|
}
|
|
else
|
|
{
|
|
UIManager.ShowAlert(r.errMsg);
|
|
}
|
|
}
|
|
}
|