//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, February 27, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class FullServiceAuctionWin : Window
|
{
|
|
#region Built-in
|
[SerializeField] ScrollerController m_ClassifyController;
|
[SerializeField] AuctionChildClassifyBehaviour[] m_ChildClassifys;
|
[SerializeField] ScrollerController m_ChildClassifyController;
|
[SerializeField] Transform m_ContainerChildClassify;
|
[SerializeField] Transform[] m_ChildClassifyPositions;
|
[SerializeField] ScrollerController m_AuctionController;
|
|
List<string> itemGuids = new List<string>();//全服拍品列表
|
|
int emptyCount = 0;
|
bool queryDirty = true;
|
|
AuctionModel model { get { return ModelCenter.Instance.GetModel<AuctionModel>(); } }
|
AuctionHelpModel auctionHelpModel { get { return ModelCenter.Instance.GetModel<AuctionHelpModel>(); } }
|
|
protected override void BindController()
|
{
|
m_ClassifyController.OnRefreshCell += OnRefreshClassifyCell;
|
|
m_ChildClassifyController.OnRefreshCell += OnRefreshChildClassifyCell;
|
m_AuctionController.OnRefreshCell += OnRefreshGridCellItem;
|
m_AuctionController.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.isAuctionWindowOpen = false;
|
model.selectClassifyId = 1;
|
model.childClassifyIndex = new Int2(PlayerDatas.Instance.baseData.Job, 0);
|
queryDirty = false;
|
|
GlobalTimeEvent.Instance.secondEvent += PerSecond;
|
model.serverAuctionRefresh += FullServiceAuctionUpdate;//数据请求刷新
|
model.auctionItemRefresh += RefreshAuctionItemUpdate;//刷新
|
model.onAuctionRemove += ClearAuctionUpdate;//清除
|
model.myBiddingAuctionRefresh += BiddingItemInfoUpdate;//竞价物品信息刷新
|
model.selectClassifyRefresh += SelectClassifyRefresh;
|
m_AuctionController.onValueChange += OnValueChange;
|
|
CloseChildClassify();
|
ResetServerAuctionInquiry();
|
|
Display();
|
|
var index = itemGuids.IndexOf(model.locationGuid);
|
if (index != -1)
|
{
|
m_AuctionController.JumpIndex(index);
|
}
|
|
model.isLocationQuery = false;
|
model.locationGuid = string.Empty;
|
|
RefreshChildClassify();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
StartCoroutine(Co_Open());
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
|
}
|
|
protected override void OnPreClose()
|
{
|
model.serverAuctionRefresh -= FullServiceAuctionUpdate;
|
model.auctionItemRefresh -= RefreshAuctionItemUpdate;
|
model.onAuctionRemove -= ClearAuctionUpdate;
|
model.myBiddingAuctionRefresh -= BiddingItemInfoUpdate;//竞价物品信息刷新
|
GlobalTimeEvent.Instance.secondEvent -= PerSecond;
|
m_AuctionController.onValueChange -= OnValueChange;
|
model.selectClassifyRefresh -= SelectClassifyRefresh;
|
|
StopAllCoroutines();
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
void Display()
|
{
|
DisplayClassifies();
|
DisplayAuctionItems();
|
}
|
|
void DisplayClassifies()
|
{
|
var configs = AuctionConfig.GetKeys();
|
configs.Sort();
|
m_ClassifyController.Refresh();
|
foreach (var id in configs)
|
{
|
m_ClassifyController.AddCell(ScrollerDataType.Header, int.Parse(id));
|
}
|
m_ClassifyController.Restart();
|
}
|
|
private void SelectClassifyRefresh()
|
{
|
model.childClassifyIndex = Int2.zero;
|
|
CloseChildClassify();
|
RefreshChildClassify();
|
|
m_ClassifyController.m_Scorller.RefreshActiveCellViews();
|
queryDirty = true;
|
}
|
|
IEnumerator Co_Open()
|
{
|
yield return WaitingForSecondConst.WaitMS2000;
|
model.isAuctionWindowOpen = true;
|
}
|
|
private void OnValueChange(Vector2 delta)
|
{
|
if (delta.y >= 1)
|
{
|
if (model.SatisfyQueryAuction(2))
|
{
|
var inquiryIndex = model.GetQueryIndex();
|
if (itemGuids.Count > 0)
|
{
|
model.SendInquiryServerAcution(inquiryIndex, itemGuids[0], 2);
|
}
|
}
|
}
|
}
|
|
private void PerSecond()
|
{
|
if (queryDirty)
|
{
|
queryDirty = false;
|
ResetServerAuctionInquiry();
|
}
|
}
|
|
private void FullServiceAuctionUpdate()
|
{
|
DisplayAuctionItems();
|
}
|
|
private void RefreshAuctionItemUpdate()
|
{
|
m_AuctionController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
}
|
|
private void ClearAuctionUpdate()
|
{
|
DisplayAuctionItems();
|
}
|
|
private void BiddingItemInfoUpdate()
|
{
|
DisplayAuctionItems();
|
}
|
|
private void OnRefreshClassifyCell(ScrollerDataType type, CellView cell)
|
{
|
var classifyCell = cell as ServerAuctionClassifyCell;
|
classifyCell.Display(cell.index);
|
}
|
|
private void OnRefreshChildClassifyCell(ScrollerDataType type, CellView cell)
|
{
|
var classifyId = model.selectClassifyId;
|
var config = AuctionConfig.Get(classifyId);
|
|
var index = cell.index / 100;
|
var classifyIndex = cell.index % 100;
|
|
if (config != null)
|
{
|
var classifyNameArray = index == 0 ? config.ChooseItemName1 : config.ChooseItemName2;
|
|
Text textName = cell.transform.Find("Text").GetComponent<Text>();
|
Button button = cell.GetComponent<Button>();
|
|
textName.text = classifyNameArray[classifyIndex];
|
|
button.SetListener(() =>
|
{
|
CloseChildClassify();
|
|
var currentClassifyIndex = index == 0 ? model.childClassifyIndex.x : model.childClassifyIndex.y;
|
|
if (classifyIndex != currentClassifyIndex)
|
{
|
if (index == 0)
|
{
|
model.childClassifyIndex.x = classifyIndex;
|
}
|
else
|
{
|
model.childClassifyIndex.y = classifyIndex;
|
}
|
|
queryDirty = true;
|
RefreshChildClassify();
|
}
|
});
|
}
|
}
|
|
public void DisplayChildClassify(int index)
|
{
|
var config = AuctionConfig.Get(model.selectClassifyId);
|
|
var position = m_ChildClassifyPositions[0].localPosition;
|
|
if (index == 1)
|
{
|
position = config.ChooseItem1 == null || config.ChooseItem1.Length == 0 ?
|
m_ChildClassifyPositions[0].localPosition : m_ChildClassifyPositions[1].localPosition;
|
}
|
|
var classifyArray = index == 0 ? config.ChooseItem1 : config.ChooseItem2;
|
m_ChildClassifyController.Refresh();
|
for (int i = 0; i < classifyArray.Length; i++)
|
{
|
m_ChildClassifyController.AddCell(ScrollerDataType.Header, index * 100 + i);
|
}
|
m_ChildClassifyController.Restart();
|
|
m_ContainerChildClassify.localPosition = position;
|
m_ContainerChildClassify.SetActive(true);
|
}
|
|
private void DisplayAuctionItems()
|
{
|
var firstGuid = itemGuids.Count > 0 ? itemGuids[0] : string.Empty;
|
|
itemGuids.Clear();
|
if (!model.isLocationQuery && !model.queryFowardAble)
|
{
|
PushMyBiddingItems();
|
}
|
|
List<string> guids = model.GetServerAuctionItems();
|
foreach (var guid in guids)
|
{
|
if (!itemGuids.Contains(guid))
|
{
|
itemGuids.Add(guid);
|
}
|
}
|
|
var jumpIndex = -1;
|
if (firstGuid != string.Empty && model.isQueryFront)
|
{
|
jumpIndex = itemGuids.IndexOf(firstGuid);
|
}
|
|
emptyCount = 0;
|
if (jumpIndex >= itemGuids.Count - 3)
|
{
|
var delta = 4 - (itemGuids.Count - jumpIndex);
|
for (int i = 0; i < delta; i++)
|
{
|
itemGuids.Add(string.Empty);
|
emptyCount++;
|
}
|
}
|
|
m_AuctionController.Refresh();
|
for (int i = 0; i < itemGuids.Count; i++)
|
{
|
m_AuctionController.AddCell(ScrollerDataType.Header, i);
|
}
|
m_AuctionController.Restart();
|
|
if (jumpIndex != -1)
|
{
|
m_AuctionController.JumpIndex(jumpIndex);
|
}
|
|
|
model.isQueryFront = false;
|
}
|
|
private void OnRefreshGridCellItem(ScrollerDataType type, CellView cell)
|
{
|
int index = cell.index;
|
FullServiceAuctioncell fullServiceAuctioncell = cell.GetComponent<FullServiceAuctioncell>();
|
fullServiceAuctioncell.GetFullServiceAuctionGUID(itemGuids[index], index, itemGuids.Count - emptyCount);
|
}
|
|
private void ResetServerAuctionInquiry()//重置查询
|
{
|
model.ResetServerAuctionInquiry();
|
if (!model.isLocationQuery)
|
{
|
var inquiryIndex = model.GetQueryIndex();
|
model.SendInquiryServerAcution(inquiryIndex, string.Empty, 1);
|
}
|
}
|
|
private void CloseChildClassify()
|
{
|
m_ContainerChildClassify.SetActive(false);
|
}
|
|
private void RefreshChildClassify()
|
{
|
var classifyId = model.selectClassifyId;
|
var config = AuctionConfig.Get(classifyId);
|
for (int i = 0; i < m_ChildClassifys.Length; i++)
|
{
|
var classifyIds = i == 0 ? config.ChooseItem1 : config.ChooseItem2;
|
if (classifyIds == null || classifyIds.Length == 0)
|
{
|
m_ChildClassifys[i].SetActive(false);
|
}
|
else
|
{
|
m_ChildClassifys[i].SetActive(true);
|
m_ChildClassifys[i].Display(this, i);
|
}
|
}
|
}
|
|
private void PushMyBiddingItems()
|
{
|
var index = model.GetQueryIndex();
|
|
var myBiddingItems = model.GetMyBiddingAuctionItems();
|
foreach (var guid in myBiddingItems)
|
{
|
AuctionItem item;
|
if (!model.TryGetMyBiddingAuctionItem(guid, out item)
|
|| item.auctionType != 0)
|
{
|
continue;
|
}
|
|
var itemConfig = ItemConfig.Get(item.itemId);
|
|
if (index == 1000 || AuctionLogicUtil.IsQueryType(index, itemConfig.Type))
|
{
|
itemGuids.Add(guid);
|
}
|
}
|
itemGuids.Sort(MyBiddingItemCompare);
|
}
|
|
int MyBiddingItemCompare(string x, string y)//数组排列
|
{
|
var lhs_myTopPrice = model.IsMyTopPrice(x);
|
var rhs_myTopPrice = model.IsMyTopPrice(y);
|
if (lhs_myTopPrice != rhs_myTopPrice)
|
{
|
return -lhs_myTopPrice.CompareTo(rhs_myTopPrice);
|
}
|
return 1;
|
}
|
}
|
|
}
|
|
|
|
|