101 lines
3.5 KiB
C#
101 lines
3.5 KiB
C#
using asap.core;
|
|
using game;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
|
|
public class ReportPopupPanel : MonoBehaviour
|
|
{
|
|
protected GameObject eventReportPopupItem;
|
|
protected List<EventReportPopupItem> eventReportPopupItems = new List<EventReportPopupItem>();
|
|
protected Transform Content;
|
|
protected GameObject text_empty;
|
|
protected GameObject panelScroll;
|
|
protected ClubService clubService;
|
|
IDisposable disposable;
|
|
protected virtual void Start()
|
|
{
|
|
disposable = GContext.OnEvent<ReportData>().Subscribe(OnReportEvent);
|
|
SetData();
|
|
}
|
|
public void SetData()
|
|
{
|
|
List<EventPopupData> eventPopupDatas = clubService.eventPopupDatas.OrderByDescending(c => c.createTime).Take(40).ToList();
|
|
bool isEmpty = eventPopupDatas == null || eventPopupDatas.Count == 0;
|
|
text_empty.SetActive(isEmpty);
|
|
panelScroll.gameObject.SetActive(!isEmpty);
|
|
if (isEmpty)
|
|
{
|
|
return;
|
|
}
|
|
List<EventPopupData> eventPopupDatasCopy = new List<EventPopupData>();
|
|
for (int i = 0; i < eventPopupDatas.Count; i++)
|
|
{
|
|
if (eventPopupDatas[i].type == ReportDataType.Bomb || eventPopupDatas[i].type == ReportDataType.Heist
|
|
|| eventPopupDatas[i].type == ReportDataType.Aquarium)
|
|
{
|
|
eventPopupDatasCopy.Add(eventPopupDatas[i]);
|
|
}
|
|
else if (eventPopupDatas[i].type == ReportDataType.Energy && eventPopupDatas[i].content.Contains("%"))
|
|
{
|
|
string[] content = eventPopupDatas[i].content.Split("#");
|
|
for (int j = 0; j < content.Length; j++)
|
|
{
|
|
string[] contentSplit = content[j].Split("%");
|
|
EventPopupData eventPopupData = new EventPopupData();
|
|
eventPopupData.type = ReportDataType.Energy;
|
|
if (!DateTime.TryParse(contentSplit[0], out DateTime createTime))
|
|
{
|
|
createTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
}
|
|
eventPopupData.createTime = createTime;
|
|
eventPopupData.playerID = contentSplit[1];
|
|
eventPopupDatasCopy.Add(eventPopupData);
|
|
}
|
|
}
|
|
//if (eventPopupDatasCopy.Count >= 40)
|
|
//{
|
|
// break;
|
|
//}
|
|
}
|
|
isEmpty = eventPopupDatasCopy.Count == 0;
|
|
text_empty.SetActive(isEmpty);
|
|
panelScroll.gameObject.SetActive(!isEmpty);
|
|
if (isEmpty)
|
|
{
|
|
return;
|
|
}
|
|
//按时间排序
|
|
eventPopupDatasCopy.Sort((a, b) => b.createTime.CompareTo(a.createTime));
|
|
|
|
for (int i = 0; i < eventPopupDatasCopy.Count; i++)
|
|
{
|
|
EventReportPopupItem item;
|
|
if (eventReportPopupItems.Count > i)
|
|
{
|
|
item = eventReportPopupItems[i];
|
|
}
|
|
else
|
|
{
|
|
GameObject go = Instantiate(eventReportPopupItem, Content);
|
|
go.SetActive(true);
|
|
item = go.GetComponent<EventReportPopupItem>();
|
|
eventReportPopupItems.Add(item);
|
|
}
|
|
item.SetData(eventPopupDatasCopy[i]);
|
|
}
|
|
}
|
|
public void OnReportEvent(ReportData reportEvent)
|
|
{
|
|
SetData();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
}
|
|
}
|