//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, March 01, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
//我的关注面板
|
namespace Snxxz.UI
|
{
|
|
public class AttentionWin : Window, SecondWindowInterface
|
{
|
[SerializeField] ScrollerController m_ScrollerController;
|
[SerializeField] Toggle m_MaterialToggle;//材料
|
[SerializeField] Toggle m_MountAndPetToggle;//灵宠
|
[SerializeField] Toggle m_EquipmentToggle;//装备
|
AuctionModel model { get { return ModelCenter.Instance.GetModel<AuctionModel>(); } }
|
AuctionHelpModel auctionHelpModel { get { return ModelCenter.Instance.GetModel<AuctionHelpModel>(); } }
|
List<AuctionItemConfig> auctionItemList = new List<AuctionItemConfig>();
|
int ItemType = 1;
|
#region Built-in
|
enum AttentionType
|
{
|
Equipment = 1,
|
MountAndPet = 2,
|
Material = 3,
|
}
|
|
public Button close { get; set; }
|
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
}
|
|
protected override void AddListeners()
|
{
|
m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
|
m_ScrollerController.lockType = EnhanceLockType.KeepVertical;
|
m_MaterialToggle.onValueChanged.AddListener(OnClickToggleMaterial);
|
m_MountAndPetToggle.onValueChanged.AddListener(OnClickToggleMountAndPet);
|
m_EquipmentToggle.onValueChanged.AddListener(OnClickToggleEquipment);
|
close.AddListener(() => { CloseImmediately(); });
|
}
|
|
protected override void OnPreOpen()
|
{
|
ItemType = GetItemType();
|
OnCreateGridLineCell(m_ScrollerController);
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
if (ItemType != (int)AttentionType.Equipment)
|
{
|
m_EquipmentToggle.isOn = true;
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
model.myFocusItemRefresh += AttentionAuctionItemUpdate;
|
}
|
|
protected override void OnPreClose()
|
{
|
AuctionInquiry.Instance.SendQueryAttentionAuctionItem();//查询拍卖行的关注物品
|
}
|
|
protected override void OnAfterClose()
|
{
|
model.myFocusItemRefresh -= AttentionAuctionItemUpdate;
|
}
|
|
|
#endregion
|
private void AttentionAuctionItemUpdate()
|
{
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
}
|
|
private void OnCreateGridLineCell(ScrollerController gridCtrl)
|
{
|
gridCtrl.Refresh();
|
auctionItemList = auctionHelpModel.GetAuctionItemList(ItemType);
|
int LINE = Mathf.CeilToInt((float)auctionItemList.Count / 4);
|
for (int i = 0; i < LINE; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
gridCtrl.Restart();
|
}
|
|
private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
var attentionCell = cell as AuctionAttentionCell;
|
attentionCell.Display(ItemType, cell.index);
|
}
|
|
private void OnClickToggleMaterial(bool isOn)
|
{
|
if (isOn)
|
{
|
ItemType = GetItemType();
|
OnCreateGridLineCell(m_ScrollerController);
|
}
|
}
|
|
private void OnClickToggleMountAndPet(bool isOn)
|
{
|
if (isOn)
|
{
|
ItemType = GetItemType();
|
OnCreateGridLineCell(m_ScrollerController);
|
}
|
}
|
|
private void OnClickToggleEquipment(bool isOn)
|
{
|
if (isOn)
|
{
|
ItemType = GetItemType();
|
OnCreateGridLineCell(m_ScrollerController);
|
}
|
}
|
|
private int GetItemType()
|
{
|
int type = 1;
|
if (m_MaterialToggle.isOn)
|
{
|
type = (int)AttentionType.Material;
|
}
|
else if (m_MountAndPetToggle.isOn)
|
{
|
type = (int)AttentionType.MountAndPet;
|
}
|
else if (m_EquipmentToggle.isOn)
|
{
|
type = (int)AttentionType.Equipment;
|
}
|
return type;
|
}
|
|
}
|
|
}
|