2021-04-09 15:57:50 +08:00
|
|
|
|
using Assets.Scripts;
|
|
|
|
|
|
using Assets.Scripts.Apis;
|
|
|
|
|
|
using Assets.Scripts.Apis.Models;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
public class ResultListController : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField]Transform routeResult;
|
|
|
|
|
|
Transform scrollContent;
|
|
|
|
|
|
Transform routeScroll, matchScroll;
|
|
|
|
|
|
Transform routeContent, matchContent;
|
|
|
|
|
|
Transform btnRoute, btnMatch,searchInput;
|
|
|
|
|
|
Color c1, c2;
|
|
|
|
|
|
// Start is called before the first frame update
|
2021-04-19 15:44:11 +08:00
|
|
|
|
int pageSize = 20;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
string name = "";
|
2021-04-25 15:33:17 +08:00
|
|
|
|
Transform[] contents,scrolls;
|
2021-04-19 15:44:11 +08:00
|
|
|
|
Dictionary<int, string> filterOptionDict = new Dictionary<int, string>
|
|
|
|
|
|
{
|
|
|
|
|
|
{0,"routes" },{1,"competition" }
|
|
|
|
|
|
};
|
2021-04-09 15:57:50 +08:00
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
2021-04-15 15:58:37 +08:00
|
|
|
|
//ApiBase.SetCookie("73385F5F719B610D132C1ECF3E9143272BF15214D57ED91CD7A9DFD832407471535112AAEB8E9271F75D54FBBF2D99F18FA313C1EEA5676F5D722D7FBB07C926BEC5905591BF9AFDDC6336552DF273112C2DA1794E6FA2F465B11FECD2E82E52");
|
2021-04-09 15:57:50 +08:00
|
|
|
|
InitialColor();
|
|
|
|
|
|
scroll = transform.Find("ListPanel").Find("Scroll").GetComponent<ScrollRect>();
|
|
|
|
|
|
btnMatch = transform.Find("ListPanel").Find("BtnMatch");
|
|
|
|
|
|
btnRoute = transform.Find("ListPanel").Find("BtnRoute");
|
|
|
|
|
|
searchInput = transform.Find("ListPanel").Find("SearchInput");
|
|
|
|
|
|
scrollContent = scroll.transform.Find("Viewport").Find("Content");
|
|
|
|
|
|
routeScroll = scrollContent.Find("RouteList");
|
|
|
|
|
|
routeContent = routeScroll.Find("Viewport").Find("Content");
|
|
|
|
|
|
matchScroll = scrollContent.Find("MatchList");
|
|
|
|
|
|
matchContent = matchScroll.Find("Viewport").Find("Content");
|
2021-04-15 15:58:37 +08:00
|
|
|
|
contents = new Transform[] { routeContent, matchContent};
|
2021-04-09 15:57:50 +08:00
|
|
|
|
if (btnMatch != null)
|
|
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
UIManager.AddEvent(btnMatch.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
StartScroll(0);
|
|
|
|
|
|
});
|
|
|
|
|
|
//btnMatch.GetComponent<Button>().onClick.AddListener(() => StartScroll(0));
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (btnRoute != null)
|
|
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
UIManager.AddEvent(btnRoute.gameObject, EventTriggerType.PointerClick, (b) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
StartScroll(1);
|
|
|
|
|
|
});
|
|
|
|
|
|
//btnRoute.GetComponent<Button>().onClick.AddListener(() => StartScroll(1));
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (searchInput != null)
|
|
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
UIManager.AddEvent(searchInput.Find("Button").gameObject, EventTriggerType.PointerClick, (b) =>
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-23 15:36:18 +08:00
|
|
|
|
onEndEdit();
|
2021-04-09 15:57:50 +08:00
|
|
|
|
});
|
2021-04-19 15:44:11 +08:00
|
|
|
|
//searchInput.Find("Button").GetComponent<Button>().onClick.AddListener(() =>
|
|
|
|
|
|
//{
|
|
|
|
|
|
// name = searchInput.GetComponent<InputField>().text;
|
|
|
|
|
|
// Refresh(contents[scrollIndex]);
|
|
|
|
|
|
//});
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (routeScroll != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.AddEvent(routeScroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
|
|
|
|
|
}
|
2021-04-25 15:33:17 +08:00
|
|
|
|
if (matchScroll != null)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
UIManager.AddEvent(matchScroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
|
|
|
|
|
}
|
2021-04-25 15:33:17 +08:00
|
|
|
|
scrolls = new Transform[] { routeScroll, matchScroll };
|
2021-04-19 15:44:11 +08:00
|
|
|
|
GetList(0);
|
|
|
|
|
|
GetList(1);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-29 23:45:29 +08:00
|
|
|
|
public void Load()
|
2021-04-29 22:05:19 +08:00
|
|
|
|
{
|
2021-04-29 23:45:29 +08:00
|
|
|
|
if (contents != null && contents.Length == 2)
|
2021-04-29 22:05:19 +08:00
|
|
|
|
{
|
2021-04-29 23:45:29 +08:00
|
|
|
|
Refresh(contents[scrollIndex]);
|
2021-04-29 22:05:19 +08:00
|
|
|
|
}
|
2021-04-29 23:45:29 +08:00
|
|
|
|
//if (scroll!=null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// scroll.transform.Find("Error").gameObject.SetActive(false);
|
|
|
|
|
|
//}
|
2021-04-29 22:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-09 15:57:50 +08:00
|
|
|
|
private void OnEndDrag(BaseEventData e)
|
|
|
|
|
|
{
|
2021-04-25 15:33:17 +08:00
|
|
|
|
ScrollRect scrollrect = null;
|
|
|
|
|
|
if (e != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pe = (PointerEventData)e;
|
|
|
|
|
|
scrollrect = pe.pointerDrag.GetComponent<ScrollRect>();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollrect = scrolls[scrollIndex].GetComponent<ScrollRect>();
|
|
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
if (scrollrect.verticalNormalizedPosition <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log(scrollrect.verticalNormalizedPosition);
|
2021-04-19 15:44:11 +08:00
|
|
|
|
pageIndex[scrollIndex]++;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
GetList();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (scrollrect.verticalNormalizedPosition >= 1)
|
|
|
|
|
|
{
|
2021-04-15 15:58:37 +08:00
|
|
|
|
Refresh(contents[scrollIndex]);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-04-15 15:58:37 +08:00
|
|
|
|
private void Refresh(Transform content)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-15 15:58:37 +08:00
|
|
|
|
content.transform.DestroyChildren();
|
2021-04-19 15:44:11 +08:00
|
|
|
|
isEnd[scrollIndex] = false;
|
|
|
|
|
|
pageIndex[scrollIndex] = 0;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
GetList();
|
|
|
|
|
|
}
|
2021-04-19 15:44:11 +08:00
|
|
|
|
Dictionary<int, bool> isEnd = new Dictionary<int, bool>
|
|
|
|
|
|
{
|
|
|
|
|
|
{0,false },{1,false }
|
|
|
|
|
|
};
|
|
|
|
|
|
Dictionary<int, int> pageIndex = new Dictionary<int, int>
|
|
|
|
|
|
{
|
|
|
|
|
|
{0,0 },{1,0 }
|
|
|
|
|
|
};
|
|
|
|
|
|
async void GetList(int? sindex = null)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
var index = sindex ?? scrollIndex;
|
|
|
|
|
|
if (isEnd[index]) return;
|
|
|
|
|
|
var r = await ConfigHelper.mapInterruptRecordApi.GetMapInterruptRecord(name, pageIndex[index], 20,filterOptionDict[index]);
|
2021-04-23 15:36:18 +08:00
|
|
|
|
|
2021-04-09 15:57:50 +08:00
|
|
|
|
if (r.result)
|
|
|
|
|
|
{
|
2021-04-23 15:36:18 +08:00
|
|
|
|
if (r.data.Count == 0)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
2021-04-23 15:36:18 +08:00
|
|
|
|
if (pageIndex[index] != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
isEnd[index] = true;
|
|
|
|
|
|
scroll.transform.Find("Error").gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//contents[index];
|
2021-04-29 23:45:29 +08:00
|
|
|
|
if (!sindex.HasValue ||(sindex.HasValue && sindex.Value == scrollIndex))
|
|
|
|
|
|
{
|
|
|
|
|
|
scroll.transform.Find("Error").gameObject.SetActive(true);
|
|
|
|
|
|
}
|
2021-04-23 15:36:18 +08:00
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-04-19 15:44:11 +08:00
|
|
|
|
isEnd[index] = false;
|
|
|
|
|
|
DisplayRouteResult(r.data, contents[index],index);
|
2021-04-23 15:36:18 +08:00
|
|
|
|
scroll.transform.Find("Error").gameObject.SetActive(false);
|
2021-04-15 15:58:37 +08:00
|
|
|
|
//DisplayRouteResult(r.data, matchContent);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Utils.showToast(gameObject, r.errMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-04-19 15:44:11 +08:00
|
|
|
|
void DisplayRouteResult(List<RouteResult> list,Transform content,int index)
|
2021-04-09 15:57:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (routeResult != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
|
{
|
|
|
|
|
|
var obj = Instantiate(routeResult);
|
2021-04-19 15:44:11 +08:00
|
|
|
|
obj.GetComponent<RouteItem>().Initial(item, index);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
//obj.SendMessage("Initial", );
|
|
|
|
|
|
obj.transform.parent = content;
|
|
|
|
|
|
obj.transform.localScale = new Vector3(1, 1, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void InitialColor()
|
|
|
|
|
|
{
|
|
|
|
|
|
ColorUtility.TryParseHtmlString("#FFFFFF", out c1);
|
|
|
|
|
|
ColorUtility.TryParseHtmlString("#5C5C6E", out c2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
2021-04-23 15:36:18 +08:00
|
|
|
|
void onEndEdit()
|
|
|
|
|
|
{
|
|
|
|
|
|
name = searchInput.GetComponent<InputField>().text;
|
|
|
|
|
|
Refresh(contents[scrollIndex]);
|
|
|
|
|
|
}
|
2021-04-25 15:33:17 +08:00
|
|
|
|
bool startMouse = false;
|
2021-04-09 15:57:50 +08:00
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
GoScroll();
|
2021-04-25 15:33:17 +08:00
|
|
|
|
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scrolls[scrollIndex].GetComponent<ScrollRect>().verticalNormalizedPosition <= 0 ||
|
|
|
|
|
|
scrolls[scrollIndex].GetComponent<ScrollRect>().verticalNormalizedPosition >= (pageIndex[scrollIndex] == 0 ? 1.05 : 1))
|
|
|
|
|
|
{
|
|
|
|
|
|
startMouse = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (startMouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
startMouse = false;
|
|
|
|
|
|
OnEndDrag(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
|
2021-04-23 15:36:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
onEndEdit();
|
|
|
|
|
|
}
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
void StartScroll(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (startScroll) return;
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//翻到比赛页,比赛按钮变白,线路按钮变灰
|
|
|
|
|
|
scrollIndex = 1;
|
|
|
|
|
|
startScroll = true;
|
|
|
|
|
|
btnRoute.GetComponent<Text>().color = c2;
|
|
|
|
|
|
btnMatch.GetComponent<Text>().color = c1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (index == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//反过来
|
|
|
|
|
|
scrollIndex = 0;
|
|
|
|
|
|
startScroll = true;
|
|
|
|
|
|
btnRoute.GetComponent<Text>().color = c1;
|
|
|
|
|
|
btnMatch.GetComponent<Text>().color = c2;
|
|
|
|
|
|
}
|
2021-04-23 15:36:18 +08:00
|
|
|
|
scroll.transform.Find("Error").gameObject.SetActive(contents[scrollIndex].childCount == 0);
|
2021-04-09 15:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
#region 主页面滑动逻辑
|
|
|
|
|
|
int scrollIndex = 0;
|
|
|
|
|
|
bool startScroll = false;
|
|
|
|
|
|
ScrollRect scroll;
|
|
|
|
|
|
//private float scrollValue = 0.5f;
|
|
|
|
|
|
int pageNums = 2;
|
|
|
|
|
|
void GoScroll()
|
|
|
|
|
|
{
|
|
|
|
|
|
var index = scrollIndex;
|
|
|
|
|
|
var scrollValue = 1f / (pageNums - 1);
|
|
|
|
|
|
var value = index * scrollValue;
|
|
|
|
|
|
if (scroll != null && startScroll)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scroll.horizontalNormalizedPosition >= value)
|
|
|
|
|
|
{
|
|
|
|
|
|
scroll.horizontalNormalizedPosition -= (scrollValue / 20);
|
|
|
|
|
|
if (scroll.horizontalNormalizedPosition <= value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log(index);
|
|
|
|
|
|
scroll.horizontalNormalizedPosition = value;
|
|
|
|
|
|
startScroll = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
scroll.horizontalNormalizedPosition += (scrollValue / 20);
|
|
|
|
|
|
if (scroll.horizontalNormalizedPosition >= value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log(index);
|
|
|
|
|
|
scroll.horizontalNormalizedPosition = value;
|
|
|
|
|
|
startScroll = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
//float scrollIndex = 0;
|
|
|
|
|
|
//bool startScroll = false;
|
|
|
|
|
|
//ScrollRect scroll;
|
|
|
|
|
|
//void GoScroll()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// float value = scrollIndex;
|
|
|
|
|
|
// if (scroll != null && startScroll)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (scrollIndex == 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// scroll.horizontalNormalizedPosition -= (1f / 20);
|
|
|
|
|
|
// if (scroll.horizontalNormalizedPosition <= 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// scroll.horizontalNormalizedPosition = 0;
|
|
|
|
|
|
// startScroll = false;
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (scrollIndex == 1)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// scroll.horizontalNormalizedPosition += (1f / 20);
|
|
|
|
|
|
// if (scroll.horizontalNormalizedPosition >= 1)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// scroll.horizontalNormalizedPosition = 1;
|
|
|
|
|
|
// startScroll = false;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|