using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class ChatBubbleSelectBehaviour : MonoBehaviour
|
{
|
[SerializeField] Button m_Func;
|
[SerializeField] Image m_Icon;
|
[SerializeField] Image m_Using;
|
[SerializeField] Text m_BubbleName;
|
[SerializeField] RectTransform m_ContainerUnGet;
|
[SerializeField] Text m_Condition;
|
|
private int bubbleId = 0;
|
|
ChatBubbleModel model
|
{
|
get { return ModelCenter.Instance.GetModel<ChatBubbleModel>(); }
|
}
|
|
VipModel vipModel
|
{
|
get { return ModelCenter.Instance.GetModel<VipModel>(); }
|
}
|
|
private void Awake()
|
{
|
m_Func.onClick.AddListener(OnFunc);
|
}
|
|
private void OnEnable()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
vipModel.OnVipGiftEvent += OnVipGiftEvent;
|
model.chatBubbleStateRefresh += ChatBubbleStateRefresh;
|
}
|
|
private void OnDisable()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
|
vipModel.OnVipGiftEvent -= OnVipGiftEvent;
|
model.chatBubbleStateRefresh -= ChatBubbleStateRefresh;
|
}
|
|
private void ChatBubbleStateRefresh()
|
{
|
DisplayState();
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
|
{
|
if (refreshType == PlayerDataType.ExAttr10)
|
{
|
DisplaySelect();
|
}
|
else if (refreshType == PlayerDataType.LV)
|
{
|
DisplayState();
|
}
|
}
|
|
private void OnVipGiftEvent()
|
{
|
DisplayState();
|
}
|
|
public void Display(int id)
|
{
|
ChatBubbleModel.ChatBubble bubble;
|
if (model.TryGetBubble(id, out bubble))
|
{
|
bubbleId = id;
|
var config = ChatBubbleBoxConfig.Get(bubbleId);
|
m_BubbleName.text = config.Name;
|
m_Icon.SetSprite(config.Icon);
|
DisplayState();
|
DisplaySelect();
|
}
|
}
|
|
void DisplaySelect()
|
{
|
m_Using.gameObject.SetActive(PlayerDatas.Instance.baseData.bubbleId == bubbleId);
|
}
|
|
void DisplayState()
|
{
|
ChatBubbleModel.ChatBubble bubble;
|
if (model.TryGetBubble(bubbleId, out bubble))
|
{
|
var got = model.IsBubbleGot(bubbleId);
|
m_ContainerUnGet.gameObject.SetActive(!got);
|
var config = ChatBubbleBoxConfig.Get(bubbleId);
|
if (!got)
|
{
|
m_Condition.text = config.GainTip;
|
}
|
}
|
}
|
|
private void OnFunc()
|
{
|
if (model.IsBubbleGot(bubbleId))
|
{
|
model.SendUseBubble(bubbleId);
|
}
|
else
|
{
|
ChatBubblePreviewWin.previewBubbleId = bubbleId;
|
WindowCenter.Instance.Open<ChatBubblePreviewWin>();
|
}
|
}
|
}
|
}
|