//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, December 05, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using Snxxz.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class BetterItemGetBehaviour : MonoBehaviour
|
{
|
[SerializeField] RectTransform m_ContainerBetterEquip;
|
[SerializeField] ItemCell m_EquipBehaviour;
|
[SerializeField] Text m_EquipName;
|
[SerializeField] Button m_Close;
|
[SerializeField] Text m_FunctionTitle;
|
[SerializeField] GameObject coolObj;
|
[SerializeField] Text coolTimeText;
|
[SerializeField] Button m_Puton;
|
[SerializeField] Button m_BetterEquipDetail;
|
|
ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
BetterEquipGetModel model { get { return ModelCenter.Instance.GetModel<BetterEquipGetModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
|
private void OnEnable()
|
{
|
m_Close.AddListener(CloseBetterEquip);
|
m_Puton.AddListener(PutOnBetterEquip);
|
m_BetterEquipDetail.AddListener(ShowBetterEquipDetails);
|
KnapsackTimeCDMgr.Instance.RefresCoolTimeAct += UpdateCoolTime;
|
}
|
|
private void OnDisable()
|
{
|
m_Close.RemoveAllListeners();
|
m_Puton.RemoveAllListeners();
|
m_BetterEquipDetail.RemoveAllListeners();
|
KnapsackTimeCDMgr.Instance.RefresCoolTimeAct -= UpdateCoolTime;
|
}
|
|
private void UpdateCoolTime(string guid)
|
{
|
if (!string.IsNullOrEmpty(model.currentEquipGuid))
|
{
|
ItemModel betterEquip;
|
if (model.TryGetBetterEquip(model.currentEquipGuid, out betterEquip))
|
{
|
var coolData = KnapsackTimeCDMgr.Instance.GetItemCoolById(model.currentEquipGuid);
|
bool isCoolEnd = !model.CheckIsAutoEquip(betterEquip) || coolData == null || coolData.GetRemainTime() <= 0 ? true : false;
|
coolObj.SetActive(!isCoolEnd);
|
m_FunctionTitle.gameObject.SetActive(isCoolEnd);
|
if (!isCoolEnd)
|
{
|
int remainTime = (int)coolData.GetRemainTime();
|
coolTimeText.text = StringUtility.Contact("(", remainTime, ")");
|
}
|
}
|
}
|
}
|
|
public void ShowBetterEquip()
|
{
|
m_ContainerBetterEquip.gameObject.SetActive(false);
|
if (!string.IsNullOrEmpty(model.currentEquipGuid))
|
{
|
ItemModel betterEquip;
|
if (model.TryGetBetterEquip(model.currentEquipGuid, out betterEquip))
|
{
|
DrawBetterEquip(betterEquip);
|
m_ContainerBetterEquip.gameObject.SetActive(true);
|
|
var coolData = KnapsackTimeCDMgr.Instance.GetItemCoolById(model.currentEquipGuid);
|
if (model.CheckIsAutoEquip(betterEquip) && coolData == null)
|
{
|
KnapsackTimeCDMgr.Instance.Register(betterEquip.guid, betterEquip.itemId, model.autoEquipCoolTime);
|
}
|
}
|
}
|
}
|
|
private void PutOnBetterEquip()
|
{
|
ItemModel betterEquip;
|
if (model.TryGetBetterEquip(model.currentEquipGuid, out betterEquip))
|
{
|
switch (betterEquip.packType)
|
{
|
case PackType.Item:
|
ToOpenRoleKanpsack(betterEquip);
|
break;
|
}
|
}
|
|
}
|
|
private void ToOpenRoleKanpsack(ItemModel betterEquip)
|
{
|
var itemConfig = ItemConfig.Get(betterEquip.itemId);
|
if (NewBieCenter.Instance.inGuiding)
|
{
|
playerPack.SetLookIndex(betterEquip.guid);
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
equipModel.SelectSet(betterEquip.config.LV);
|
WindowCenter.Instance.Open<RealmEquipWin>();
|
StartCoroutine(Co_Delay(model.currentEquipGuid));
|
}
|
else
|
{
|
if (itemConfig.ItemColor >= 3)
|
{
|
playerPack.SetLookIndex(betterEquip.guid);
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
equipModel.SelectSet(betterEquip.config.LV);
|
WindowCenter.Instance.Open<RealmEquipWin>();
|
StartCoroutine(Co_Delay(model.currentEquipGuid));
|
}
|
else
|
{
|
ItemOperateUtility.Instance.PutOnItem(model.currentEquipGuid);
|
model.ReportConfirmBetterEquip(model.currentEquipGuid);
|
}
|
}
|
}
|
|
private void ShowBetterEquipDetails()
|
{
|
ItemModel betterEquip;
|
if (model.TryGetBetterEquip(model.currentEquipGuid, out betterEquip))
|
{
|
var itemConfig = ItemConfig.Get(betterEquip.itemId);
|
var packType = GeneralDefine.GetPackTypeByItemType(itemConfig.Type);
|
itemTipsModel.SetItemTipsModel(packType, betterEquip.guid);
|
}
|
}
|
|
private void CloseBetterEquip()
|
{
|
model.ReportConfirmBetterEquip(model.currentEquipGuid);
|
}
|
|
private void DrawBetterEquip(ItemModel betterModel)
|
{
|
var itemConfig = ItemConfig.Get(betterModel.itemId);
|
m_EquipName.text = itemConfig.ItemName;
|
m_EquipName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
|
m_FunctionTitle.text = Language.Get(itemConfig.ItemColor >= 3 ? "GoodEquip_See" : "GoodEquip_FitUp");
|
m_EquipBehaviour.Init(betterModel, true);
|
UpdateCoolTime(betterModel.guid);
|
}
|
|
IEnumerator Co_Delay(string _guid)
|
{
|
yield return null;
|
yield return null;
|
yield return WaitingForSecondConst.WaitMS300;
|
|
itemTipsModel.SetItemTipsModel(PackType.Item, _guid, false, true);
|
itemTipsModel.SetBagTipsBtn(itemTipsModel.curAttrData);
|
itemTipsModel.ShowTip();
|
|
model.ReportConfirmBetterEquip(model.currentEquipGuid);
|
}
|
}
|
}
|
|
|
|
|
|