//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, September 06, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using TableConfig;
|
using UnityEngine.EventSystems;
|
using Snxxz.UI;
|
|
namespace Snxxz.UI {
|
|
public class BagWin : TempKnapSackBasic {
|
|
#region 成员变量
|
[SerializeField]
|
private ScrollerController _gridlineCtrl;
|
#endregion
|
|
private SinglePackModel packModel;
|
private ItemModel _clickItemModel;
|
private bool isDoubleClick = false;
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
PackModelInterface _modelInterface;
|
PackModelInterface modelInterface
|
{
|
get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel<PackModelInterface>()); }
|
}
|
|
private GridCell _lookEquipCell = null;
|
|
#region Built-in
|
protected override void BindController() {
|
_gridlineCtrl.OnRefreshCell += OnRefreshGridCell;
|
_gridlineCtrl.vertical = true;
|
_gridlineCtrl.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
protected override void AddListeners() {
|
|
|
}
|
|
protected override void OnPreOpen() {
|
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueAct += RefreshRemainTime;
|
playerPack.lookEquipEvent += LookEquip;
|
playerPack.RefreshItemCountAct += OnAddItemCell;
|
playerPack.RefreshPackAct += RefreshPackModel;
|
playerPack.GridRefreshEvent += OnPackCanUseGrid;
|
}
|
|
protected override void OnAfterOpen() {
|
|
this.transform.SetAsLastSibling();
|
OnRefrenshUIModel();
|
if(KnapSackWin.titleType == KnapsackFuncTitle.bag
|
&& LocalSave.GetString(PlayerPackModel.RecordKnapsackTitle) != KnapsackFuncTitle.depot.ToString())
|
{
|
_gridlineCtrl.JumpIndex(0);
|
}
|
LookEquip();
|
CheckAchieveJump();
|
LocalSave.SetString(PlayerPackModel.RecordKnapsackTitle, KnapSackWin.titleType.ToString());
|
}
|
|
|
protected override void OnPreClose() {
|
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueAct -= RefreshRemainTime;
|
playerPack.RefreshItemCountAct -= OnAddItemCell;
|
playerPack.RefreshPackAct -= RefreshPackModel;
|
playerPack.lookEquipEvent -= LookEquip;
|
playerPack.GridRefreshEvent -= OnPackCanUseGrid;
|
}
|
|
protected override void OnAfterClose() {
|
UI3DModelExhibition.Instance.StopShowPlayer();
|
}
|
#endregion
|
|
private void CheckAchieveJump()
|
{
|
if(AchievementGoto.guideAchievementId != 0)
|
{
|
SuccessConfig successConfig = Config.Instance.Get<SuccessConfig>(AchievementGoto.guideAchievementId);
|
if (successConfig != null)
|
{
|
JumpUIType jump = (JumpUIType)successConfig.Jump;
|
switch (successConfig.Type)
|
{
|
case 94:
|
if (jump == JumpUIType.KnapSackFunc1)
|
{
|
int itemId = successConfig.Condition[0];
|
string guid = playerPack.GetItemGUIDByID(itemId);
|
if (string.IsNullOrEmpty(guid))
|
{
|
SysNotifyMgr.Instance.ShowTip("BagNoItem", itemId);
|
}
|
AchievementGoto.guideAchievementId = 0;
|
}
|
|
break;
|
}
|
}
|
|
}
|
}
|
|
public void OnRefrenshUIModel() {
|
packModel = playerPack.GetSinglePackModel(PackType.rptItem);
|
OnCreateGridLineCell(_gridlineCtrl);
|
}
|
|
public void LookEquip()
|
{
|
if (playerPack.lookLineIndex > -1)
|
{
|
if(playerPack.lookLineIndex >= 4)
|
{
|
_gridlineCtrl.JumpIndex(playerPack.lookLineIndex - 2);
|
}
|
else
|
{
|
_gridlineCtrl.JumpIndex(playerPack.lookLineIndex);
|
}
|
|
}
|
else
|
{
|
|
if (_lookEquipCell != null)
|
{
|
_lookEquipCell.uiEffect.Stop();
|
_lookEquipCell = null;
|
}
|
}
|
}
|
|
private void RefreshPackModel(PackType type)
|
{
|
if (type != PackType.rptItem)
|
return;
|
|
_gridlineCtrl.JumpIndex(0);
|
OnRefrenshUIModel();
|
}
|
|
private void RefreshRemainTime(string guid)
|
{
|
ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(guid);
|
TimeSpan t;
|
if (cool != null)
|
{
|
t = TimeSpan.FromSeconds(cool.GetRemainTime());
|
}
|
else
|
{
|
t = TimeSpan.FromSeconds(0);
|
}
|
|
if(t.TotalSeconds <= 0)
|
{
|
OnRefrenshUIModel();
|
}
|
}
|
|
#region 共用部分
|
|
public override void OnCreateGridLineCell(ScrollerController gridCtrl) {
|
base.OnCreateGridLineCell(gridCtrl);
|
|
}
|
|
public void OnRefreshGridCell(ScrollerDataType type, CellView cell) {
|
int gridlineIndex = cell.index;
|
int childCode = 0;
|
|
if (packModel == null)
|
{
|
for (childCode = 0; childCode < cell.transform.childCount; childCode++)
|
{
|
GridCell gridCell = cell.transform.GetChild(childCode).GetComponent<GridCell>();
|
if(gridCell == null)
|
gridCell = cell.transform.GetChild(childCode).gameObject.AddComponent<GridCell>();
|
|
gridCell.cdImag.fillAmount = 0;
|
gridCell.cdImag.gameObject.SetActive(false);
|
gridCell.gridLock.SetActive(true);
|
gridCell.itemCell.gameObject.SetActive(false);
|
gridCell.uiEffect.Stop();
|
}
|
return;
|
}
|
for (childCode = 0; childCode < cell.transform.childCount; childCode++) {
|
|
GridCell gridCell = cell.transform.GetChild(childCode).GetComponent<GridCell>();
|
if (gridCell == null)
|
gridCell = cell.transform.GetChild(childCode).gameObject.AddComponent<GridCell>();
|
|
int cellCount = (cell.transform.childCount) * gridlineIndex + (childCode + 1);
|
|
gridCell.itemCell.gameObject.SetActive(false);
|
if (cellCount > packModel.openGridCount)
|
{
|
gridCell.gridLock.SetActive(true);
|
}
|
else
|
{
|
gridCell.gridLock.SetActive(false);
|
}
|
|
gridCell.cdImag.fillAmount = 0;
|
gridCell.cdImag.gameObject.SetActive(false);
|
ItemModel itemModel = packModel.GetItemModelByIndex(cellCount - 1);
|
if (itemModel != null)
|
{
|
gridCell.itemCell.gameObject.SetActive(true);
|
gridCell.itemCell.Init(itemModel,true);
|
gridCell.itemCellBtn.OnOneParaClick = null;
|
gridCell.itemCellBtn.m_OnDbClick = null;
|
if (KnapSackWin.titleType == KnapsackFuncTitle.depot)
|
{
|
gridCell.itemCellBtn.OnOneParaClick=(int info) => {
|
|
itemTipsModel.SetItemTipsModel(PackType.rptItem, itemModel.itemInfo.ItemGUID, false, true);
|
itemTipsModel.SetDepotBagTipsBtn(itemTipsModel.curAttrData);
|
itemTipsModel.ShowUICtrl();
|
|
};
|
gridCell.itemCellBtn.m_OnDbClick=() =>
|
{
|
PackSendQuestMgr.Instance.SendPutInQuest(ItemWinBtnType.putIn, itemModel.itemInfo.ItemGUID);
|
};
|
|
}
|
else if(KnapSackWin.titleType == KnapsackFuncTitle.bag)
|
{
|
gridCell.itemCellBtn.OnOneParaClick=(int info) => {
|
itemTipsModel.SetItemTipsModel(PackType.rptItem, itemModel.itemInfo.ItemGUID, false,true);
|
itemTipsModel.SetBagTipsBtn(itemTipsModel.curAttrData);
|
itemTipsModel.ShowUICtrl();
|
};
|
}
|
|
gridCell.SetModel(itemModel);
|
bool isLookEquip = false;
|
if (playerPack.lookLineIndex > -1)
|
{
|
if(itemModel.itemInfo.ItemGUID == playerPack.lookItemGUID)
|
{
|
gridCell.uiEffect.Play();
|
_lookEquipCell = gridCell;
|
isLookEquip = true;
|
}
|
}
|
|
if(playerPack.isPlayBetterEquipEffect)
|
{
|
if(modelInterface.GetBagSortBetterEquip(itemModel.chinItemModel.EquipPlace,itemModel.itemInfo.ItemPlace) != null)
|
{
|
bool isOverdue = modelInterface.IsOverdue(itemModel.itemInfo.ItemGUID,itemModel.itemInfo.ItemID,itemModel.useDataDict);
|
if(!isOverdue)
|
{
|
gridCell.uiEffect.Play();
|
}
|
else
|
{
|
gridCell.uiEffect.Stop();
|
}
|
}
|
}
|
else
|
{
|
if(!isLookEquip)
|
{
|
gridCell.uiEffect.Stop();
|
}
|
}
|
|
}
|
|
else
|
{
|
gridCell.SetModel(null);
|
gridCell.uiEffect.Stop();
|
}
|
|
gridCell.lockBtn.onClick.RemoveAllListeners();
|
gridCell.lockBtn.onClick.AddListener(() => {
|
int selectGridIndex = cell.index * 5 + int.Parse(gridCell.gameObject.name.Substring(gridCell.gameObject.name.Length - 1, 1));
|
OnClickLockBtn(selectGridIndex,packModel);
|
});
|
|
}
|
|
|
}
|
|
public override void OnPackCanUseGrid(PackType type) {
|
if (type != PackType.rptItem)
|
return;
|
OnRefrenshUIModel();
|
}
|
|
public override void OnAddItemCell(PackType type,int index,int id) {
|
if (type != PackType.rptItem)
|
return;
|
|
OnRefrenshUIModel();
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|