//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, February 27, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class FullServiceAuctionWin : Window
|
{
|
|
#region Built-in
|
[SerializeField] ScrollerController m_ScrollerController;
|
[SerializeField] ScrollerController m_ScrollerControllerJob;
|
[SerializeField] ScrollerController m_ScrollerControllerType;
|
[SerializeField] ScrollerController m_ScrollerControllerItem;
|
[SerializeField] GameObject m_JobTip;
|
[SerializeField] GameObject m_TypeTip;
|
[SerializeField] Button m_JobTipBtn;
|
[SerializeField] Button m_TypeTipBtn;
|
[SerializeField] Text m_JobTipText;
|
[SerializeField] Text m_TypeTipText;
|
List<AuctionItemClass> FullServiceAuctionListSort = new List<AuctionItemClass>();//全服拍品列表
|
AuctionInquiryModel model { get { return ModelCenter.Instance.GetModel<AuctionInquiryModel>(); } }
|
AuctionHelpModel auctionHelpModel { get { return ModelCenter.Instance.GetModel<AuctionHelpModel>(); } }
|
|
private bool IsSendBool = true;
|
private int Times = 0;
|
protected override void BindController()
|
{
|
m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
|
m_ScrollerControllerJob.OnRefreshCell += OnRefreshGridCellJob;
|
m_ScrollerControllerType.OnRefreshCell += OnRefreshGridCellType;
|
m_ScrollerControllerItem.OnRefreshCell += OnRefreshGridCellItem;
|
m_ScrollerControllerItem.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
protected override void AddListeners()
|
{
|
m_JobTipBtn.AddListener(OnClickJobTipBtn);
|
m_TypeTipBtn.AddListener(OnClickTypeTipBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
Times = 0;
|
auctionHelpModel.isOpenPanel = true;
|
IsSendBool = false;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
model.FullServiceAuctionUpdate += FullServiceAuctionUpdate;//数据请求刷新
|
model.RefreshAuctionItemUpdate += RefreshAuctionItemUpdate;//刷新
|
model.ClearAuctionUpdate += ClearAuctionUpdate;//清除
|
model.BiddingItemInfoUpdate += BiddingItemInfoUpdate;//竞价物品信息刷新
|
Reset();
|
CloseTip();
|
ListSort();
|
OnCreateGridLineCell(m_ScrollerController);
|
OnCreateGridLineCellJob(m_ScrollerControllerJob);
|
OnCreateGridLineCellType(m_ScrollerControllerType);
|
OnCreateGridLineCellItem(m_ScrollerControllerItem);
|
SetTipText();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
|
}
|
|
protected override void OnPreClose()
|
{
|
model.FullServiceAuctionUpdate -= FullServiceAuctionUpdate;
|
model.RefreshAuctionItemUpdate -= RefreshAuctionItemUpdate;
|
model.ClearAuctionUpdate -= ClearAuctionUpdate;
|
model.BiddingItemInfoUpdate -= BiddingItemInfoUpdate;//竞价物品信息刷新
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
private void secondEvent()
|
{
|
Times += 1;
|
if (Times >= 3 && auctionHelpModel.isOpenPanel)
|
{
|
auctionHelpModel.isOpenPanel = false;
|
}
|
if (IsSendBool)
|
{
|
IsSendBool = false;
|
Reset();
|
}
|
}
|
private void FullServiceAuctionUpdate()
|
{
|
OnCreateGridLineCellItem(m_ScrollerControllerItem);
|
}
|
private void RefreshAuctionItemUpdate()
|
{
|
m_ScrollerControllerItem.m_Scorller.RefreshActiveCellViews();//刷新可见
|
}
|
private void ClearAuctionUpdate()
|
{
|
OnCreateGridLineCellItem(m_ScrollerControllerItem);
|
}
|
private void BiddingItemInfoUpdate()
|
{
|
|
}
|
private void OnClickJobTipBtn()
|
{
|
m_JobTip.SetActive(true);
|
}
|
|
private void OnClickTypeTipBtn()
|
{
|
m_TypeTip.SetActive(true);
|
}
|
private void OnCreateGridLineCell(ScrollerController gridCtrl)
|
{
|
|
gridCtrl.Refresh();
|
for (int i = 0; i < auctionHelpModel.FullServiceAuctionList.Count; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
gridCtrl.Restart();
|
}
|
private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
var index = cell.index;
|
if (index >= auctionHelpModel.FullServiceAuctionList.Count)
|
{
|
return;
|
}
|
var fullServiceAuction = auctionHelpModel.FullServiceAuctionList[index];
|
Text textName = cell.transform.Find("Text").GetComponent<Text>();
|
GameObject selected = cell.transform.Find("Selected").gameObject;
|
ButtonEx button = cell.GetComponent<ButtonEx>();
|
textName.text = fullServiceAuction.TypeName;
|
if (fullServiceAuction.Id == auctionHelpModel.SelectedGenreNow)
|
{
|
selected.SetActive(true);
|
}
|
else
|
{
|
selected.SetActive(false);
|
}
|
button.SetListener(() =>
|
{
|
if (fullServiceAuction.Id != auctionHelpModel.SelectedGenreNow)
|
{
|
CloseTip();
|
auctionHelpModel.SelectedGenreNow = fullServiceAuction.Id;
|
IsSendBool = true;
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
OnCreateGridLineCellJob(m_ScrollerControllerJob);
|
OnCreateGridLineCellType(m_ScrollerControllerType);
|
SetTipText();
|
}
|
});
|
|
}
|
|
private void OnCreateGridLineCellJob(ScrollerController gridCtrl)
|
{
|
var index = 0;
|
index = auctionHelpModel.FullServiceAuctionList.FindIndex((x) =>
|
{
|
return x.Id == auctionHelpModel.SelectedGenreNow;
|
});
|
if (index != -1)
|
{
|
var fullServiceAuction = auctionHelpModel.FullServiceAuctionList[index];
|
if (fullServiceAuction.ChooseItem1 != null && fullServiceAuction.ChooseItem1.Length != 0)
|
{
|
gridCtrl.Refresh();
|
for (int i = 0; i < fullServiceAuction.ChooseItem1.Length; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
gridCtrl.Restart();
|
}
|
|
}
|
}
|
private void OnRefreshGridCellJob(ScrollerDataType type, CellView cell)
|
{
|
var index = cell.index;
|
var selectedGenreNow = auctionHelpModel.SelectedGenreNow;
|
if (auctionHelpModel.FullServiceAuctionDic.ContainsKey(selectedGenreNow))
|
{
|
var config = auctionHelpModel.FullServiceAuctionDic[selectedGenreNow];
|
Text textName = cell.transform.Find("Text").GetComponent<Text>();
|
Button button = cell.GetComponent<Button>();
|
textName.text = config.Config.ChooseItemName1[index];
|
button.SetListener(() =>
|
{
|
m_JobTip.SetActive(false);
|
if (index != config.JobEntry)
|
{
|
auctionHelpModel.FullServiceAuctionDic[selectedGenreNow].JobEntry = index;
|
IsSendBool = true;
|
SetTipText();
|
}
|
});
|
}
|
}
|
|
private void OnCreateGridLineCellType(ScrollerController gridCtrl)
|
{
|
var index = 0;
|
index = auctionHelpModel.FullServiceAuctionList.FindIndex((x) =>
|
{
|
return x.Id == auctionHelpModel.SelectedGenreNow;
|
});
|
if (index != -1)
|
{
|
var fullServiceAuction = auctionHelpModel.FullServiceAuctionList[index];
|
if (fullServiceAuction.ChooseItem2 != null && fullServiceAuction.ChooseItem2.Length != 0)
|
{
|
gridCtrl.Refresh();
|
for (int i = 0; i < fullServiceAuction.ChooseItem2.Length; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
gridCtrl.Restart();
|
}
|
}
|
}
|
|
private void OnRefreshGridCellType(ScrollerDataType type, CellView cell)
|
{
|
var index = cell.index;
|
var selectedGenreNow = auctionHelpModel.SelectedGenreNow;
|
if (auctionHelpModel.FullServiceAuctionDic.ContainsKey(selectedGenreNow))
|
{
|
var config = auctionHelpModel.FullServiceAuctionDic[selectedGenreNow];
|
Text textName = cell.transform.Find("Text").GetComponent<Text>();
|
Button button = cell.GetComponent<Button>();
|
textName.text = config.Config.ChooseItemName2[index];
|
button.SetListener(() =>
|
{
|
m_TypeTip.SetActive(false);
|
if (index != config.TypeEntry)
|
{
|
auctionHelpModel.FullServiceAuctionDic[selectedGenreNow].TypeEntry = index;
|
IsSendBool = true;
|
SetTipText();
|
}
|
});
|
}
|
|
}
|
|
private void OnCreateGridLineCellItem(ScrollerController gridCtrl)
|
{
|
ListSort();
|
if (!model.LocationQuery)
|
{
|
for (int i = 0; i < model.FullServiceAuctionList.Count; i++)
|
{
|
var FullServiceAuction = model.FullServiceAuctionList[i];
|
var index = FullServiceAuctionListSort.FindIndex((x) => { return x.ItemGUID == FullServiceAuction.ItemGUID; });
|
if (index == -1)
|
{
|
FullServiceAuctionListSort.Add(FullServiceAuction);
|
}
|
}
|
}
|
else
|
{
|
model.LocationQuery = false;
|
}
|
gridCtrl.Refresh();
|
for (int i = 0; i < FullServiceAuctionListSort.Count; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
gridCtrl.Restart();
|
}
|
private void OnRefreshGridCellItem(ScrollerDataType type, CellView cell)
|
{
|
int index = cell.index;
|
FullServiceAuctioncell fullServiceAuctioncell = cell.GetComponent<FullServiceAuctioncell>();
|
AuctionItemClass auctionItemClass = FullServiceAuctionListSort[index];
|
fullServiceAuctioncell.GetFullServiceAuctionGUID(auctionItemClass.ItemGUID, index);
|
}
|
|
private void Reset()//重置查询
|
{
|
model.FullServiceAuctionList.Clear();
|
model.QueryRemaining.UpBool = true;
|
model.QueryRemaining.DownBool = true;
|
var sendNumber = AuctionInquiry.Instance.GetSendNumber();
|
if (sendNumber != 0)
|
{
|
AuctionInquiry.Instance.SendQueryAuction(string.Empty, sendNumber, 1);
|
}
|
|
}
|
private void CloseTip()
|
{
|
m_JobTip.SetActive(false);
|
m_TypeTip.SetActive(false);
|
}
|
private void SetTipText()
|
{
|
var selectedGenreNow = auctionHelpModel.SelectedGenreNow;
|
if (auctionHelpModel.FullServiceAuctionDic.ContainsKey(selectedGenreNow))
|
{
|
var config = auctionHelpModel.FullServiceAuctionDic[selectedGenreNow];
|
m_JobTipBtn.gameObject.SetActive(config.JobTipBool);
|
if (config.JobTipBool)
|
{
|
m_JobTipText.text = config.Config.ChooseItemName1[config.JobEntry];
|
}
|
m_TypeTipBtn.gameObject.SetActive(config.TypeTipBool);
|
if (config.TypeTipBool)
|
{
|
m_TypeTipText.text = config.Config.ChooseItemName2[config.TypeEntry];
|
}
|
}
|
}
|
|
private void ListSort()
|
{
|
FullServiceAuctionListSort.Clear();
|
var sendNumber = AuctionInquiry.Instance.GetSendNumber();
|
foreach (var vlaue in model.BiddingItemInfoDic.Values)
|
{
|
int num = 0;
|
if (sendNumber != 0)
|
{
|
var auctionItem = AuctionItemConfig.Get(vlaue.ItemID);
|
num = sendNumber / 1000;
|
num -= 1;
|
if (num == 0)
|
{
|
FullServiceAuctionListSort.Add(vlaue);
|
}
|
else if (num == auctionItem.ItemType)
|
{
|
FullServiceAuctionListSort.Add(vlaue);
|
}
|
}
|
}
|
FullServiceAuctionListSort.Sort(Compare);
|
}
|
int Compare(AuctionItemClass x, AuctionItemClass y)//数组排列
|
{
|
bool havex = IsHighestPrice(x.ItemGUID);
|
bool havey = IsHighestPrice(y.ItemGUID);
|
if (havex.CompareTo(havey) != 0)//是否最高价
|
{
|
return -havex.CompareTo(havey);
|
}
|
bool havex1 = IsParticipate(x.ItemGUID);
|
bool havey1 = IsParticipate(y.ItemGUID);
|
if (havex1.CompareTo(havey1) != 0)//是否参与
|
{
|
return -havex1.CompareTo(havey1);
|
}
|
return 1;
|
}
|
private bool IsHighestPrice(string GUID)
|
{
|
bool isBool = false;
|
int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
|
if (model.BiddingItemInfoDic.ContainsKey(GUID))
|
{
|
var biddingItemInfo = model.BiddingItemInfoDic[GUID];
|
isBool = biddingItemInfo.BidderID == playerId;
|
}
|
return isBool;
|
}
|
|
private bool IsParticipate(string GUID)
|
{
|
bool isBool = false;
|
if (model.BiddingItemInfoDic.ContainsKey(GUID))
|
{
|
isBool = true;
|
}
|
return isBool;
|
}
|
}
|
|
}
|