创建房间
This commit is contained in:
1 parent
597929cd32
commit
de8dd933e8
8 files changed
+12757
-770
No files matched your search
@@ -0,0 +1,281 @@
|
||||
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 GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerUpHandler
|
||||
{
|
||||
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 bool isModal = false;
|
||||
float width;
|
||||
float height;
|
||||
GameRoomListController listController;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
width = this.GetComponent<RectTransform>().rect.width;
|
||||
height = this.GetComponent<RectTransform>().rect.height;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
listController = FindObjectOfType<GameRoomListController>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
float? localY = null;
|
||||
MapRoute map;
|
||||
Dictionary<string, Texture> caches;
|
||||
private MapRouteAreaItem area = null;
|
||||
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches, MapRouteAreaItem area = null)
|
||||
{
|
||||
if (caches != null)
|
||||
{
|
||||
this.caches = caches;
|
||||
}
|
||||
this.area = area;
|
||||
map = myMap;
|
||||
if (!isModal)
|
||||
{
|
||||
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
transform.GetComponent<Button>().onClick.AddListener(Ride);
|
||||
}
|
||||
|
||||
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
||||
|
||||
transform.Find("IdContainer/Text").GetComponent<Text>().text = $"#{myMap.Id}";
|
||||
transform.Find("TimesContainer").gameObject.SetActive(myMap.MineCount > 0);
|
||||
transform.Find("TimesContainer/Text").GetComponent<Text>().text = myMap.MineCountString;
|
||||
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);
|
||||
//if (!isModal)
|
||||
//{
|
||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.AddListener(Collect);
|
||||
//}
|
||||
//transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
||||
// UIManager.Instance.collectDict[myMap.IsFavorite];
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
//transform.Find("CollectImg").gameObject.SetActive(false);
|
||||
#endif
|
||||
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
||||
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
||||
|
||||
Utils.DisplayImageTempDict(transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage, this.caches);
|
||||
Utils.DisplayImageTempDict(transform.Find("MapHBImg").GetComponent<RawImage>(), myMap.AltitudeGraph, this.caches);
|
||||
|
||||
SetActive4Button(false);
|
||||
|
||||
var isRecent = App.CurrentRouteType == "Recent Routes" && myMap.RecentRecord != null && myMap.RecentRecord.ContinueCyclingParam != null && !isModal;
|
||||
transform.Find("BtnContinue").gameObject.SetActive(isRecent);
|
||||
transform.Find("BtnReride").gameObject.SetActive(isRecent);
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!isRecent);
|
||||
|
||||
}
|
||||
|
||||
private void Ride()
|
||||
{
|
||||
var list = FindObjectsOfType<GameRoomMapItem>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.HiddenOutLine();
|
||||
}
|
||||
ShowOutLine();
|
||||
listController.Select(map);
|
||||
}
|
||||
|
||||
public void ShowOutLine()
|
||||
{
|
||||
var outlineDown = transform.Find("Panel").GetComponent<Outline>();
|
||||
var outlineUp = transform.Find("MapTitleImg").GetComponent<Outline>();
|
||||
outlineDown.effectDistance = new Vector2(2, 2);
|
||||
outlineUp.effectDistance = new Vector2(2, 2);
|
||||
}
|
||||
|
||||
public void HiddenOutLine()
|
||||
{
|
||||
var outlineDown = transform.Find("Panel").GetComponent<Outline>();
|
||||
var outlineUp = transform.Find("MapTitleImg").GetComponent<Outline>();
|
||||
outlineDown.effectDistance = new Vector2(0,0);
|
||||
outlineUp.effectDistance = new Vector2(0,0);
|
||||
}
|
||||
|
||||
private void Info()
|
||||
{
|
||||
UIManager.ShowMapDetailPanel(map.Id);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (isModal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
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);
|
||||
SetColor(false);
|
||||
#else
|
||||
transform.Find("Shadow").GetComponent<Image>().DOFade(0, 0.3f);
|
||||
#endif
|
||||
}
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (isModal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
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);
|
||||
SetColor(true);
|
||||
#else
|
||||
transform.Find("Shadow").GetComponent<Image>().DOFade(1, 0.3f);
|
||||
#endif
|
||||
}
|
||||
void SetActive4Button(bool b)
|
||||
{
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
||||
transform.Find("BtnInfo").gameObject.SetActive(b);
|
||||
transform.Find("BtnRide").gameObject.SetActive(b);
|
||||
}
|
||||
|
||||
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];
|
||||
if (this.model != null)
|
||||
{
|
||||
this.model.IsFavorite = map.IsFavorite;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.ShowAlert("WARNING", r.errMsg);
|
||||
}
|
||||
}
|
||||
NearRouteModel model { get; set; }
|
||||
|
||||
public void Show(Vector3 position, NearRouteModel model)
|
||||
{
|
||||
this.model = model;
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
this.Move(position);
|
||||
#endif
|
||||
this.gameObject.SetActive(true);
|
||||
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,
|
||||
IsFavorite = model.IsFavorite,
|
||||
}, null);
|
||||
}
|
||||
|
||||
public void Move(Vector3 position)
|
||||
{
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
this.transform.position = position;
|
||||
|
||||
var localPosition = this.transform.localPosition;
|
||||
localPosition.y = localPosition.y + (width * 2);
|
||||
localPosition.x = localPosition.x - height;
|
||||
|
||||
this.transform.localPosition = localPosition;
|
||||
this.transform.localScale = new Vector2(2, 2);
|
||||
|
||||
Debug.Log($"{ this.transform.localPosition.y }, { this.transform.localPosition.y }");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
this.gameObject.SetActive(false);
|
||||
#else
|
||||
DestroyImmediate(this.gameObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b8467bb6fa339c4c9f6abbf32033a2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user