//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Saturday, December 16, 2017
|
//--------------------------------------------------------
|
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class PreciousItemGetBehaviour : MonoBehaviour, IInGamePush
|
{
|
[SerializeField] RectTransform m_PreciousItem;
|
[SerializeField] ItemCell m_ItemBehaviour;
|
[SerializeField] Text m_ItemName;
|
[SerializeField] Button m_Close;
|
[SerializeField] Button m_Use;
|
[SerializeField] Text m_Title;
|
[SerializeField] Button m_ViewItemDetail;
|
[SerializeField] float delayShowTime = 2f;
|
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
PreciousItemGetModel model { get { return ModelCenter.Instance.GetModel<PreciousItemGetModel>(); } }
|
|
private void OnEnable()
|
{
|
m_Close.AddListener(CloseItemShow);
|
m_Use.AddListener(UseItem);
|
m_ViewItemDetail.AddListener(ShowItemDetails);
|
}
|
|
private void OnDisable()
|
{
|
m_Close.RemoveAllListeners();
|
m_Use.RemoveAllListeners();
|
m_ViewItemDetail.RemoveAllListeners();
|
model.isGetNewItem = false;
|
}
|
|
public void ShowItem()
|
{
|
if (model.currentShowItem != default(PreciousItemGetModel.PreciousItem))
|
{
|
var itemModel = playerPack.GetItemByGuid(model.currentShowItem.guid);
|
if (itemModel != null && itemModel.packType == PackType.Item)
|
{
|
DrawItem(itemModel);
|
List<int> sourcelist = itemModel.GetUseData((int)ItemUseDataKey.source);
|
if (sourcelist != null
|
&& sourcelist[0] == 4
|
&& model.isGetNewItem)
|
{
|
StartCoroutine(VirtualDropDelay());
|
}
|
else
|
{
|
m_PreciousItem.SetActive(true);
|
}
|
}
|
else
|
{
|
m_PreciousItem.SetActive(false);
|
}
|
}
|
else
|
{
|
m_PreciousItem.SetActive(false);
|
}
|
model.isGetNewItem = false;
|
}
|
|
IEnumerator VirtualDropDelay()
|
{
|
yield return new WaitForSeconds(delayShowTime);
|
m_PreciousItem.SetActive(true);
|
}
|
|
private void UseItem()
|
{
|
if (model.currentShowItem != default(PreciousItemGetModel.PreciousItem))
|
{
|
var item = playerPack.GetItemByGuid(model.currentShowItem.guid);
|
model.ReportConfirmPreciousItem(model.currentShowItem);
|
|
if (GeneralDefine.onlyUsedAtBackpackItems.Contains(item.itemId))
|
{
|
if (item.itemId == 150)
|
{
|
WindowCenter.Instance.Open<LingShiChange>();
|
return;
|
}
|
WindowCenter.Instance.Open<KnapSackWin>();
|
Clock.AlarmAfter(0.5f, () => { ItemTipUtility.Show(item.guid); });
|
return;
|
}
|
|
if (item != null && item.packType == PackType.Item)
|
{
|
switch ((ItemType)item.config.Type)
|
{
|
case ItemType.WingsMat:
|
var jumpId = 0;
|
var isUnlock = ModelCenter.Instance.GetModel<ComposeWinModel>().CheckComposeItemById(item.itemId, out jumpId);
|
if (isUnlock)
|
{
|
ItemOperateUtility.Instance.GotoComposeItem(jumpId);
|
}
|
break;
|
default:
|
ItemOperateUtility.Instance.GotoUseItem(item.guid);
|
break;
|
}
|
}
|
}
|
}
|
|
private void ShowItemDetails()
|
{
|
if (model.currentShowItem != default(PreciousItemGetModel.PreciousItem))
|
{
|
ItemTipUtility.Show(model.currentShowItem.guid, false);
|
}
|
}
|
|
private void CloseItemShow()
|
{
|
model.ReportConfirmPreciousItem(model.currentShowItem);
|
}
|
|
private void DrawItem(ItemModel _item)
|
{
|
if (_item != null)
|
{
|
m_Title.text = GeneralDefine.onlyUsedAtBackpackItems.Contains(_item.itemId) ? Language.Get("GoodEquip_See") : Language.Get("KnapS103");
|
var itemConfig = ItemConfig.Get(_item.itemId);
|
m_ItemName.text = itemConfig.ItemName;
|
m_ItemName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
|
|
m_ItemBehaviour.Init(_item, true);
|
}
|
}
|
|
public int GetSiblingIndex()
|
{
|
return transform.GetSiblingIndex();
|
}
|
|
public bool IsActive()
|
{
|
return transform.gameObject.activeSelf
|
&& m_PreciousItem.gameObject.activeSelf;
|
}
|
}
|
|
}
|
|
|
|
|
|