286 lines
9.8 KiB
C#
286 lines
9.8 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,IPointerUpHandler
|
|
{
|
|
float width;
|
|
float height;
|
|
void Awake()
|
|
{
|
|
width = this.GetComponent<RectTransform>().rect.width;
|
|
height = this.GetComponent<RectTransform>().rect.height;
|
|
}
|
|
|
|
// 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);
|
|
//});
|
|
|
|
//UIManager.AddEvent(transform.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (Base) =>
|
|
//{
|
|
// App.RouteIdParam = myMap.Id;
|
|
// if (!App.MainSceneParam.ContainsKey("Name"))
|
|
// {
|
|
// App.MainSceneParam.Add("Name", "MapListPanel");
|
|
// }
|
|
// else
|
|
// {
|
|
// App.MainSceneParam["Name"] = "MapListPanel";
|
|
// }
|
|
// SceneManager.LoadScene("Ride");
|
|
//});
|
|
transform.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
//UIManager.ShowMapDetailPanel(myMap.Id);
|
|
App.RouteIdParam = myMap.Id;
|
|
if (!App.MainSceneParam.ContainsKey("Name"))
|
|
{
|
|
App.MainSceneParam.Add("Name", "MapListPanel");
|
|
}
|
|
else
|
|
{
|
|
App.MainSceneParam["Name"] = "MapListPanel";
|
|
}
|
|
SceneManager.LoadScene("Ride");
|
|
});
|
|
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
|
|
|
|
|
transform.Find("Hot").gameObject.SetActive(myMap.IsFire);
|
|
var props = transform.Find("Props");
|
|
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")}%";
|
|
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(transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage, true);
|
|
Utils.DisplayImage(transform.Find("MapHBImg").GetComponent<RawImage>(), myMap.AltitudeGraph, true);
|
|
|
|
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.3f);
|
|
transform.Find("Shadow").gameObject.SetActive(true);
|
|
Cursor.SetCursor(Resources.Load<Texture2D>("Images/PointerButtonHover"), Vector2.zero, CursorMode.Auto);
|
|
//SetActive4Button(true);
|
|
SetColor(true);
|
|
}
|
|
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)
|
|
{
|
|
if (localY != null)
|
|
{
|
|
transform.DOLocalMoveY(localY.Value, 0.3f);
|
|
}
|
|
transform.Find("CollectImg").gameObject.SetActive(false);
|
|
transform.Find("Shadow").gameObject.SetActive(false);
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
//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]);
|
|
});
|
|
transform.Find("MapHBImg").GetComponent<RawImage>().color = Utils.HexToColorHtml(
|
|
PropNames.colorDict[isFav]);
|
|
}
|
|
async void Collect()
|
|
{
|
|
JsonResult<object> r;
|
|
transform.Find("CollectImg").GetComponent<Button>().enabled = false;
|
|
if (map.IsFavorite)
|
|
{
|
|
r = await ConfigHelper.mapApi.CancelFav(map.Id.ToString());
|
|
}
|
|
else
|
|
{
|
|
r = await ConfigHelper.mapApi.AddFav(map.Id.ToString());
|
|
}
|
|
transform.Find("CollectImg").GetComponent<Button>().enabled = true;
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
public void Show(Vector3 position, NearRouteModel model)
|
|
{
|
|
//if(position.y > position.z)
|
|
//{
|
|
// position.y = position.z;
|
|
//}
|
|
this.Move(position);
|
|
|
|
this.gameObject.SetActive(true);
|
|
|
|
//this.SetModel(model);
|
|
Initial(new MapRoute
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Hard = model.Hard,
|
|
CoverImage = model.CoverImage,
|
|
Enable3D = model.Enable3D,
|
|
TheHeat = model.TheHeat,
|
|
TotalClimb = model.TotalClimb,
|
|
AverageGrade = model.AverageGrade,
|
|
CountryCode = model.CountryCode,
|
|
AltitudeGraph = model.AltitudeGraph,
|
|
Distance = model.Distance
|
|
});
|
|
}
|
|
|
|
public void Move(Vector3 position)
|
|
{
|
|
this.transform.position = position;
|
|
|
|
var localPosition = this.transform.localPosition;
|
|
Debug.Log(localPosition.y);
|
|
|
|
//localPosition.y = localPosition.y + (287 * 2);
|
|
//localPosition.x = localPosition.x - 280;
|
|
|
|
localPosition.y = localPosition.y + (width * 2);
|
|
localPosition.x = localPosition.x - height;
|
|
|
|
//if (localPosition.y > 128)
|
|
//{
|
|
// localPosition.y = 128;
|
|
//}
|
|
//if (localPosition.x < -465)
|
|
//{
|
|
// localPosition.x = -465f;
|
|
//}
|
|
//if (localPosition.x > 1080)
|
|
//{
|
|
// localPosition.x = 1080;
|
|
//}
|
|
|
|
this.transform.localPosition = localPosition;
|
|
this.transform.localScale = new Vector2(2, 2);
|
|
|
|
Debug.Log($"{ this.transform.localPosition.y }, { this.transform.localPosition.y }");
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
DestroyImmediate(this.gameObject);
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
}
|
|
}
|