//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, March 04, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class MyAuctionWin : Window { [SerializeField] ScrollerController m_ScrollerController; AuctionModel model { get { return ModelCenter.Instance.GetModel(); } } AuctionHelpModel auctionHelpModel { get { return ModelCenter.Instance.GetModel(); } } List myAuctionItems = new List(); #region Built-in protected override void BindController() { m_ScrollerController.OnRefreshCell += OnRefreshGridCell; m_ScrollerController.lockType = EnhanceLockType.KeepVertical; } protected override void AddListeners() { } protected override void OnPreOpen() { GetPlayerAuctionItemList(); ListSotr(); OnCreateGridLineCell(m_ScrollerController); } protected override void OnAfterOpen() { model.myFocusAuctionRefresh += ResetUpdate; model.onAuctionRemove += ResetUpdate; model.auctionItemRefresh += AuctionItemUpdate;//刷新 model.fairyAuctionRefresh += ResetUpdate; model.onFocusAuctionRefresh += ResetUpdate; model.myAuctionRefresh += ResetUpdate; } protected override void OnPreClose() { model.myFocusAuctionRefresh -= ResetUpdate; model.onAuctionRemove -= ResetUpdate; model.auctionItemRefresh -= AuctionItemUpdate;//刷新 model.fairyAuctionRefresh -= ResetUpdate; model.onFocusAuctionRefresh -= ResetUpdate; model.myAuctionRefresh -= ResetUpdate; } protected override void OnAfterClose() { } #endregion private void ResetUpdate() { GetPlayerAuctionItemList(); ListSotr(); OnCreateGridLineCell(m_ScrollerController); } private void AuctionItemUpdate() { m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 } private void OnCreateGridLineCell(ScrollerController gridCtrl) { gridCtrl.Refresh(); for (int i = 0; i < myAuctionItems.Count; i++) { gridCtrl.AddCell(ScrollerDataType.Header, i); } gridCtrl.Restart(); } private void OnRefreshGridCell(ScrollerDataType type, CellView cell) { int index = cell.index; MyAuctionCell myAuctionCell = cell.GetComponent(); myAuctionCell.GetMyAuctionGUID(myAuctionItems[index]); } private void GetPlayerAuctionItemList() { model.GetMyAuctionItems(ref myAuctionItems); } private void ListSotr() { myAuctionItems.Sort(Compare); } int Compare(string x, string y)//数组排列 { AuctionItem lhs; AuctionItem rhs; if (model.TryGetMyAuctionItem(x, out lhs) && model.TryGetMyAuctionItem(y, out rhs)) { if (lhs.auctionType != rhs.auctionType) { return lhs.auctionType.CompareTo(rhs.auctionType); } var lhs_hasBidding = lhs.biddingPrice != 0; var rhs_hasBidding = rhs.biddingPrice != 0; if (lhs_hasBidding != rhs_hasBidding)//是否有收益 { return -lhs_hasBidding.CompareTo(rhs_hasBidding); } var lhs_Config = AuctionItemConfig.Get(lhs.itemId); var rhs_Config = AuctionItemConfig.Get(rhs.itemId); if (lhs_Config.Sortpriority != rhs_Config.Sortpriority)//按照拍卖物品表排序 { return lhs_Config.Sortpriority.CompareTo(rhs_Config.Sortpriority); } } return 1; } } }