265 lines
9.4 KiB
C#
265 lines
9.4 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;
|
|
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();
|
|
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);
|
|
}
|
|
statusOptionContainer = transform.Find("ListContainer/Conditions/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 = transform.Find("ListContainer/Conditions/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("ListContainer/Conditions/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("ListContainer/Conditions/SearchInput");
|
|
if (searchInput != null)
|
|
{
|
|
//UIManager.AddEvent(searchInput.Find("Button").gameObject, EventTriggerType.PointerClick, (b) =>
|
|
//{
|
|
// //onEndEdit();
|
|
//});
|
|
searchInput.GetComponent<InputField>().onEndEdit.AddListener((string s) =>
|
|
{
|
|
onEndEdit();
|
|
});
|
|
}
|
|
btnReturn = transform.Find("BtnReturn");
|
|
if (btnReturn != null)
|
|
{
|
|
UIManager.AddEvent(btnReturn.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
{
|
|
UIManager.ShowRaceHomePanel(true);
|
|
});
|
|
}
|
|
//Refresh();
|
|
}
|
|
|
|
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)
|
|
{
|
|
GameObject smallGame = Resources.Load<GameObject>("UI/Prefab/Race/ItemSmall");
|
|
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();
|
|
}
|
|
}
|