//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, September 06, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
using Snxxz.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class BagWin : TempKnapSackBasic
|
{
|
|
#region 成员变量
|
[SerializeField]
|
private ScrollerController _gridlineCtrl;
|
#endregion
|
|
private SinglePack packModel;
|
private ItemModel _clickItemModel;
|
private bool isDoubleClick = false;
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel {
|
get {
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
PackModel _playerPack;
|
PackModel playerPack {
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
|
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.RefreshBagEvent += RefreshBagInfo;
|
playerPack.lookEquipEvent += LookEquip;
|
playerPack.refreshItemCountEvent += OnAddItemCell;
|
playerPack.refrechPackEvent += RefreshPackModel;
|
playerPack.gridRefreshEvent += OnPackCanUseGrid;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
OnRefrenshUIModel();
|
if (KnapSackWin.titleType == KnapsackFuncTitle.bag
|
&& LocalSave.GetString(PackModel.RecordKnapsackTitle) != KnapsackFuncTitle.depot.ToString())
|
{
|
_gridlineCtrl.JumpIndex(0);
|
}
|
LookEquip();
|
CheckAchieveJump();
|
LocalSave.SetString(PackModel.RecordKnapsackTitle, KnapSackWin.titleType.ToString());
|
}
|
|
protected override void OnPreClose()
|
{
|
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueAct -= RefreshRemainTime;
|
playerPack.refreshItemCountEvent -= OnAddItemCell;
|
playerPack.refrechPackEvent -= RefreshPackModel;
|
playerPack.lookEquipEvent -= LookEquip;
|
playerPack.gridRefreshEvent -= OnPackCanUseGrid;
|
playerPack.RefreshBagEvent -= RefreshBagInfo;
|
}
|
|
protected override void OnAfterClose()
|
{
|
UI3DModelExhibition.Instance.StopShow();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
var knapSackWin = WindowCenter.Instance.Get<KnapSackWin>();
|
if (knapSackWin != null)
|
{
|
Transform parent = knapSackWin.transform;
|
this.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
this.transform.SetAsLastSibling();
|
}
|
}
|
#endregion
|
|
private void CheckAchieveJump()
|
{
|
if (AchievementGoto.guideAchievementId != 0)
|
{
|
SuccessConfig successConfig = SuccessConfig.Get(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;
|
}
|
}
|
|
}
|
}
|
|
|
private void RefreshBagInfo()
|
{
|
_gridlineCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
public void OnRefrenshUIModel()
|
{
|
packModel = playerPack.GetSinglePack(PackType.Item);
|
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.Item)
|
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.unlockedGridCount)
|
{
|
gridCell.gridLock.SetActive(true);
|
}
|
else
|
{
|
gridCell.gridLock.SetActive(false);
|
}
|
|
gridCell.cdImag.fillAmount = 0;
|
gridCell.cdImag.gameObject.SetActive(false);
|
ItemModel itemModel = packModel.GetItemByIndex(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.Item, itemModel.guid, false, true);
|
itemTipsModel.SetDepotBagTipsBtn(itemTipsModel.curAttrData);
|
itemTipsModel.ShowUICtrl();
|
|
};
|
gridCell.itemCellBtn.m_OnDbClick = () =>
|
{
|
ItemOperateUtility.Instance.PutInWareHouse(itemModel.guid);
|
};
|
|
}
|
else if (KnapSackWin.titleType == KnapsackFuncTitle.bag)
|
{
|
gridCell.itemCellBtn.OnOneParaClick = (int info) =>
|
{
|
itemTipsModel.SetItemTipsModel(PackType.Item, itemModel.guid, false, true);
|
itemTipsModel.SetBagTipsBtn(itemTipsModel.curAttrData);
|
itemTipsModel.ShowUICtrl();
|
};
|
}
|
|
gridCell.SetModel(itemModel);
|
bool isLookEquip = false;
|
if (playerPack.lookLineIndex > -1)
|
{
|
if (itemModel.guid == playerPack.lookItemGUID)
|
{
|
gridCell.uiEffect.Play();
|
_lookEquipCell = gridCell;
|
isLookEquip = true;
|
}
|
}
|
|
if (playerPack.isPlayBetterEquipEffect)
|
{
|
if (ItemLogicUtility.Instance.GetBagSortBetterEquip(itemModel.config.EquipPlace, itemModel.itemPlace) != null)
|
{
|
bool isOverdue = ItemLogicUtility.Instance.IsOverdue(itemModel.guid, itemModel.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.Item)
|
return;
|
OnRefrenshUIModel();
|
}
|
|
public override void OnAddItemCell(PackType type, int index, int id)
|
{
|
if (type != PackType.Item)
|
return;
|
|
OnRefrenshUIModel();
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|