网上演练贵港万达广场(人员密集)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.0 KiB

4 years ago
using SuperScrollView;
using UnityEngine;
using UnityEngine.UI;
using UniRx;
public class XLogUIView : UIView
{
public LoopListView2 XLogLoopListView;
public Toggle Log;
public Text LogsText;
public Toggle Warning;
public Text WarningsText;
public Toggle Error;
public Text ErrorsText;
public Button ClearButton;
public Button CloseButton;
bool isOtherColor = false;
private XLogPresenter presenter;
public override UIViewType ViewType
{
get
{
return UIViewType.Normal;
}
}
private void Awake()
{
// 初始化ScrollView
XLogLoopListView.InitListView(0, OnGetItemByIndex);
// 关闭按钮
CloseButton.OnClickAsObservable()
.Subscribe(x => Hide())
.AddTo(this);
// 清空按钮
ClearButton.OnClickAsObservable()
.Subscribe(x =>
{
presenter.ClearLogs();
XLogLoopListView.RefreshAllShownItem();
})
.AddTo(this);
// Log筛选
Log.OnValueChangedAsObservable()
.Subscribe(x =>
{
presenter.ShowLog(x);
//XLogLoopListView.RefreshAllShownItem();
})
.AddTo(this);
// 警告筛选
Warning.OnValueChangedAsObservable()
.Subscribe(x =>
{
presenter.ShowWarning(x);
//XLogLoopListView.RefreshAllShownItem();
})
.AddTo(this);
// 错误筛选
Error.OnValueChangedAsObservable()
.Subscribe(x =>
{
presenter.ShowError(x);
//XLogLoopListView.RefreshAllShownItem();
})
.AddTo(this);
// 刷新数量
presenter.ShowLogs
.ObserveCountChanged()
.Subscribe(x => XLogLoopListView.SetListItemCount(x, false))
.AddTo(this);
// Log数量
presenter.LogsCount
.SubscribeToText(LogsText)
.AddTo(this);
// 警告数量
presenter.WarningsCount
.SubscribeToText(WarningsText)
.AddTo(this);
// 错误数量
presenter.ErrorsCount
.SubscribeToText(ErrorsText)
.AddTo(this);
}
public void SetPresenter(XLogPresenter p)
{
presenter = p;
}
private LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
{
if (presenter.ShowLogs.Count == 0)
{
return null;
}
//创建Item
LoopListViewItem2 item = listView.NewListViewItem("XLogItem");
//获取数据
XLog itemData = presenter.ShowLogs[index];
////设置是否可见
//RectTransform rt = item.gameObject.GetComponent<RectTransform>();
//if (itemData.IsShow)
//{
// item.gameObject.SetActive(true);
// rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40f);
//获取子页面
XLogItem itemScript = item.GetComponent<XLogItem>();
//初始化子页面
if (item.IsInitHandlerCalled == false)
{
item.IsInitHandlerCalled = true;
itemScript.Init();
}
//设置Item颜色
isOtherColor = !isOtherColor;
if (isOtherColor)
{
itemScript.Background.color = new Color32(200, 200, 200, 255);
}
else
{
itemScript.Background.color = new Color32(255, 255, 255, 255);
}
//设置子页面数据
itemScript.SetItemData(itemData, index);
//}
//else
//{
// rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0f);
// item.gameObject.SetActive(false);
//}
return item;
}
public override void Refresh()
{
base.Refresh();
XLogLoopListView.SetListItemCount(presenter.ShowLogs.Count);
}
}