357 lines
13 KiB
C#
357 lines
13 KiB
C#
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using Assets.Scripts.UI.Prefab.Race;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class RaceListScript : RaceScript
|
|
{
|
|
// Start is called before the first frame update
|
|
private GameObject scroll;
|
|
private Transform content,statusOptionContainer, reserveContainer,dirContainer, searchInput,btnReturn,avatar, btnFilter,conditions;
|
|
private bool startMouse = false,isEnd = false;
|
|
private int pageIndex = 0, pageSize = 24;
|
|
private string raceName = "";
|
|
//筛选条件
|
|
private List<string> statusOptions = new List<string>();
|
|
bool isReserve = false;
|
|
int order = 1;
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
handleAvatar();
|
|
ResetPanel();
|
|
}
|
|
void ResetPanel()
|
|
{
|
|
if (statusOptionContainer != null)
|
|
{
|
|
foreach (Transform t in statusOptionContainer)
|
|
{
|
|
var image = t.GetComponent<Image>();
|
|
var text = t.Find("Text").GetComponent<Text>();
|
|
if (t.name == "Btn1")
|
|
{
|
|
image.color = Utils.HexToColorHtml("#F93086");
|
|
text.color = new Color(1, 1, 1, 1);
|
|
}
|
|
else
|
|
{
|
|
image.color = Utils.HexToColorHtml("#23232D");
|
|
text.color = new Color(1, 1, 1, 1);
|
|
}
|
|
}
|
|
statusOptions = new List<string>();
|
|
}
|
|
if (reserveContainer != null)
|
|
{
|
|
reserveContainer.Find("Gou").gameObject.SetActive(false);
|
|
isReserve = false;
|
|
}
|
|
if (searchInput != null)
|
|
{
|
|
searchInput.GetComponent<InputField>().text = "";
|
|
raceName = "";
|
|
}
|
|
Refresh();
|
|
}
|
|
//筛选条件
|
|
void Awake()
|
|
{
|
|
scroll = transform.Find("ListContainer/List").gameObject;
|
|
if (scroll != null)
|
|
{
|
|
content = scroll.GetComponent<ScrollRect>().content;
|
|
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
|
}
|
|
conditions = transform.Find("Conditions");
|
|
statusOptionContainer = conditions.Find("StatusContainer");
|
|
if (statusOptionContainer != null)
|
|
{
|
|
foreach (Transform t in statusOptionContainer)
|
|
{
|
|
var button = t.GetComponent<Button>();
|
|
var image = t.GetComponent<Image>();
|
|
var text = t.Find("Text").GetComponent<Text>();
|
|
if (t.name == "Btn1")
|
|
{
|
|
image.color = Utils.HexToColorHtml("#F93086");
|
|
text.color = new Color(1, 1, 1, 1);
|
|
UIManager.AddEvent(button.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
foreach (Transform t1 in statusOptionContainer)
|
|
{
|
|
var image1 = t1.GetComponent<Image>();
|
|
var text1 = t1.Find("Text").GetComponent<Text>();
|
|
if (t1.name == t.name)
|
|
{
|
|
image1.color = Utils.HexToColorHtml("#F93086");
|
|
text1.color = new Color(1, 1, 1, 1);
|
|
}
|
|
else
|
|
{
|
|
image1.color = Utils.HexToColorHtml("#23232D");
|
|
text1.color = new Color(1, 1, 1, 1);
|
|
}
|
|
}
|
|
statusOptions.Clear();
|
|
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition = 1;
|
|
Refresh();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
UIManager.AddEvent(button.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
Color c1 = Utils.HexToColorHtml("#23232D");
|
|
if (image.color.r == c1.r && image.color.g == c1.g && image.color.b == c1.b)
|
|
{
|
|
image.color = Utils.HexToColorHtml("#F93086");
|
|
text.color = new Color(1, 1, 1, 1);
|
|
statusOptions.Add(RaceFilterOptions.statusDict[t.name]);
|
|
}
|
|
else
|
|
{
|
|
image.color = c1;
|
|
text.color = new Color(1, 1, 1, 1);
|
|
statusOptions.Remove(RaceFilterOptions.statusDict[t.name]);
|
|
}
|
|
Transform t1 = statusOptionContainer.GetChild(0);
|
|
var image1 = t1.GetComponent<Image>();
|
|
var text1 = t1.Find("Text").GetComponent<Text>();
|
|
if (statusOptions.Count == 0)
|
|
{
|
|
image1.color = Utils.HexToColorHtml("#F93086");
|
|
text1.color = new Color(1, 1, 1, 1);
|
|
}
|
|
else
|
|
{
|
|
image1.color = Utils.HexToColorHtml("#23232D");
|
|
text1.color = new Color(1, 1, 1, 1);
|
|
}
|
|
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition = 1;
|
|
Refresh();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
reserveContainer = conditions.Find("ReserveContainer");
|
|
if (reserveContainer != null)
|
|
{
|
|
UIManager.AddEvent(reserveContainer.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b=>
|
|
{
|
|
var gou = reserveContainer.Find("Gou").gameObject;
|
|
bool v = !gou.activeSelf;
|
|
gou.SetActive(v);
|
|
isReserve = v;
|
|
Refresh();
|
|
});
|
|
}
|
|
dirContainer = transform.Find("Dir");
|
|
if (dirContainer != null)
|
|
{
|
|
var image = dirContainer.Find("Image").GetComponent<Image>();
|
|
UIManager.AddEvent(dirContainer.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
if (image.sprite.name == "DOWN")
|
|
{
|
|
image.sprite = Resources.Load<Sprite>("Images/UP");
|
|
order = 0;
|
|
}
|
|
else
|
|
{
|
|
image.sprite = Resources.Load<Sprite>("Images/DOWN");
|
|
order = 1;
|
|
}
|
|
Refresh();
|
|
});
|
|
}
|
|
searchInput = transform.Find("Conditions/SearchInput");
|
|
if (searchInput != null)
|
|
{
|
|
searchInput.GetComponent<InputField>().onEndEdit.AddListener((t) =>
|
|
{
|
|
raceName = t;
|
|
});
|
|
UIManager.AddEvent(searchInput.Find("Button").gameObject, EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
var t = searchInput.GetComponent<InputField>().text;
|
|
raceName = t;
|
|
onEndEdit();
|
|
});
|
|
//searchInput.GetComponent<InputField>().onEndEdit.AddListener((string s) =>
|
|
//{
|
|
// onEndEdit();
|
|
//});
|
|
}
|
|
btnReturn = transform.Find("SwitchMode/BtnReturn");
|
|
if (btnReturn != null)
|
|
{
|
|
UIManager.AddEvent(btnReturn.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
UIManager.ShowRaceHomePanel(true);
|
|
});
|
|
}
|
|
|
|
|
|
//Refresh();
|
|
}
|
|
protected override void Start()
|
|
{
|
|
#if (UNITY_ANDROID || UNITY_IOS)
|
|
//var rectTransform = transform.GetComponent<RectTransform>();
|
|
//var offsetMax = rectTransform.offsetMax;
|
|
//rectTransform.offsetMax = new Vector2(0, offsetMax.y);
|
|
//var offsetMin = rectTransform.offsetMin;
|
|
//rectTransform.offsetMin = new Vector2(0, offsetMin.y);
|
|
var rect = transform.GetComponent<RectTransform>();
|
|
rect.offsetMax = new Vector2(rect.offsetMax.x, 0);
|
|
rect.offsetMin = new Vector2(rect.offsetMin.x, 0);
|
|
|
|
var widthDelta = (transform.parent.parent.GetComponent<RectTransform>().sizeDelta.x -
|
|
transform.GetComponent<RectTransform>().sizeDelta.x) / 2;
|
|
var topRect = conditions.GetComponent<RectTransform>();
|
|
topRect.localPosition = new Vector3(topRect.localPosition.x - widthDelta
|
|
, topRect.localPosition.y, topRect.localPosition.z);
|
|
if (!App.topRectStartX.HasValue)
|
|
{
|
|
App.topRectStartX = topRect.localPosition.x;
|
|
}
|
|
if (App.isFullScreen)
|
|
{
|
|
topRect.sizeDelta = new Vector2(topRect.sizeDelta.x + 20, topRect.sizeDelta.y);
|
|
}
|
|
|
|
|
|
var mc = transform.Find("MC");
|
|
UIManager.AddEvent(transform.Find("SwitchMode/BtnFilter").gameObject, EventTriggerType.PointerClick, b =>
|
|
{
|
|
conditions.DOLocalMoveX(App.topRectStartX.Value + topRect.rect.width, 0.3f);
|
|
mc.gameObject.SetActive(true);
|
|
mc.GetComponent<CanvasGroup>().alpha = 0;
|
|
mc.GetComponent<CanvasGroup>().DOFade(1, 0.3f);
|
|
});
|
|
UIManager.AddEvent(mc.gameObject, EventTriggerType.PointerClick, b =>
|
|
{
|
|
conditions.DOLocalMoveX(App.topRectStartX.Value, 0.3f);
|
|
mc.GetComponent<CanvasGroup>().DOFade(0, 0.3f).onComplete = () =>
|
|
{
|
|
mc.gameObject.SetActive(false);
|
|
};
|
|
});
|
|
#else
|
|
#endif
|
|
}
|
|
private async Task Login()
|
|
{
|
|
var result = await ConfigHelper.userApi.Login("13115011550", "laozhong", "");
|
|
App.CurrentUser = result.data;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
|
{
|
|
if (scroll.GetComponent<ScrollRect>().verticalNormalizedPosition <= 0 ||
|
|
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1))
|
|
{
|
|
startMouse = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (startMouse)
|
|
{
|
|
startMouse = false;
|
|
OnEndDrag(null);
|
|
}
|
|
}
|
|
//if (Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
|
|
//{
|
|
// onEndEdit();
|
|
//}
|
|
}
|
|
|
|
private void OnEndDrag(BaseEventData arg0)
|
|
{
|
|
var scrollrect = scroll.GetComponent<ScrollRect>();
|
|
Debug.Log(scrollrect.verticalNormalizedPosition);
|
|
if (scrollrect.verticalNormalizedPosition <= 0)
|
|
{
|
|
pageIndex++;
|
|
GetList();
|
|
}
|
|
if (scrollrect.verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1))
|
|
{
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
content.transform.DestroyChildren();
|
|
pageIndex = 0;
|
|
isEnd = false;
|
|
GetList();
|
|
}
|
|
|
|
private async void GetList()
|
|
{
|
|
if (isEnd) return;
|
|
var res = await ConfigHelper.mapCompetitionApi.GetCompetitionListV2(raceName, pageIndex,pageSize,
|
|
status:string.Join(",", statusOptions),self:isReserve,order:1);
|
|
if (res.result)
|
|
{
|
|
if (res.data.Count == 0)
|
|
{
|
|
if (pageIndex != 0)
|
|
{
|
|
isEnd = true;
|
|
scroll.transform.Find("Error").gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("当前没查到内容");
|
|
scroll.transform.Find("Error").gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
isEnd = false;
|
|
DisplayMaps(res.data);
|
|
scroll.transform.Find("Error").gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DisplayMaps(List<MapCompetition> list)
|
|
{
|
|
#if UNITY_ANDROID || UNITY_IOS
|
|
GameObject smallGame = Resources.Load<GameObject>("UI/Prefab/Race/Mobile/ItemSmall-Mobile");
|
|
#else
|
|
GameObject smallGame = Resources.Load<GameObject>("UI/Prefab/Race/ItemSmall");
|
|
#endif
|
|
|
|
foreach (var map in list)
|
|
{
|
|
var game = Instantiate<GameObject>(smallGame);
|
|
game.GetComponent<RaceItemScript>().Initial(map, transform);
|
|
game.transform.SetParent(scroll.GetComponent<ScrollRect>().content);
|
|
game.transform.localScale = Vector3.one;
|
|
}
|
|
}
|
|
void onEndEdit()
|
|
{
|
|
var t = searchInput.GetComponent<InputField>().text;
|
|
raceName = t;
|
|
Refresh();
|
|
}
|
|
}
|