//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Saturday, December 16, 2017
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class ItemUseBehaviour : MonoBehaviour, IInGamePush
|
{
|
[SerializeField] RectTransform m_ItemUse;
|
[SerializeField] ItemCell m_ItemBehaviour;
|
[SerializeField] Text m_ItemName;
|
[SerializeField] Button m_Close;
|
[SerializeField] Button m_Use;
|
[SerializeField] Button m_ViewItemDetail;
|
|
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
ItemUseModel model { get { return ModelCenter.Instance.GetModel<ItemUseModel>(); } }
|
|
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();
|
}
|
|
public void ShowItem()
|
{
|
if (model.currentShowItem != default(ItemUseModel.UseItem))
|
{
|
m_ItemUse.SetActive(true);
|
var itemModel = playerPack.GetItemByGuid(model.currentShowItem.guid);
|
if (itemModel != null && itemModel.packType == PackType.Item)
|
{
|
DrawItem(itemModel);
|
}
|
}
|
else
|
{
|
m_ItemUse.SetActive(false);
|
}
|
}
|
|
private void UseItem()
|
{
|
if (model.currentShowItem != default(ItemUseModel.UseItem))
|
{
|
var itemModel = playerPack.GetItemByGuid(model.currentShowItem.guid);
|
model.ReportConfirmUseItem(model.currentShowItem);
|
if (itemModel != null && itemModel.packType == PackType.Item)
|
{
|
ItemOperateUtility.Instance.GotoUseItem(itemModel.guid);
|
}
|
}
|
}
|
|
private void ShowItemDetails()
|
{
|
if (model.currentShowItem != default(ItemUseModel.UseItem))
|
{
|
ItemTipUtility.Show(model.currentShowItem.guid, false);
|
}
|
}
|
|
private void CloseItemShow()
|
{
|
model.ReportConfirmUseItem(model.currentShowItem);
|
}
|
|
private void DrawItem(ItemModel _item)
|
{
|
if (_item != null)
|
{
|
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_ItemUse.gameObject.activeSelf;
|
}
|
}
|
|
}
|