using System;
using UnityEngine;
using wf;

public class CasinoItemUI : MonoBehaviour
{
	private void IconHoverOver()
	{
		KasaSceneMgr<SceneCasinoShop>.Instance.ShowItenInfo(this.m_ItemData, base.transform);
	}

	private void IconHoverOut()
	{
		KasaSceneMgr<SceneCasinoShop>.Instance.HideItemInfo();
	}

	private void IconClick()
	{
		if (KasaSceneMgr<SceneCasinoShop>.Instance.SelectTrywear != this.m_ItemData)
		{
			KasaSceneMgr<SceneCasinoShop>.Instance.SetTrywearItem(this.m_ItemData);
		}
		else
		{
			KasaSceneMgr<SceneCasinoShop>.Instance.RecetTrywearItem();
		}
	}

	private void ItemBuy()
	{
		if (!this.m_ItemData.IsCanBuy)
		{
			GameMain.Instance.SysDlg.Show("カジノコインが不足しています。", SystemDialog.TYPE.OK, null, null);
			return;
		}
		string f_strMsg = this.m_ItemData.Name + "\nを購入しますか?\nカジノコイン -" + Utility.ConvertMoneyText(this.m_ItemData.Price) + "枚";
		GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK_CANCEL, delegate
		{
			KasaSceneMgr<SceneCasinoShop>.Instance.ItemBuy(this.m_ItemData);
		}, null);
	}

	public void Init(CasinoShopItem item_data)
	{
		this.m_ItemData = item_data;
		this.m_NameLabel.text = item_data.Name;
		this.m_PriceLabel.text = Utility.ConvertMoneyText(item_data.Price);
		this.m_ItemIcon = this.m_ItemIconObj.GetComponent<UI2DSprite>();
		this.m_IconButton = this.m_ItemIconObj.GetComponent<UIButton>();
		this.m_IconButton.enabled = item_data.IsCategoryCostume;
		this.m_IconEvent = this.m_ItemIconObj.GetComponent<UIEventTrigger>();
		this.m_IconFrame = this.m_ItemIconObj.transform.GetChild(0).gameObject;
		this.m_ItemIcon.sprite2D = item_data.Icon;
		EventDelegate.Add(this.m_IconEvent.onHoverOut, new EventDelegate.Callback(this.IconHoverOut));
		EventDelegate.Add(this.m_IconEvent.onHoverOver, new EventDelegate.Callback(this.IconHoverOver));
		if (this.m_ItemData.IsCategoryCostume)
		{
			EventDelegate.Add(this.m_IconButton.onClick, new EventDelegate.Callback(this.IconClick));
		}
		this.m_BuyButton = this.m_BuyButtonObj.GetComponent<UIButton>();
		this.m_BuyButtonIcon = this.m_BuyButtonObj.GetComponent<UISprite>();
		EventDelegate.Add(this.m_BuyButton.onClick, new EventDelegate.Callback(this.ItemBuy));
		this.UIUpdate();
	}

	public void UIUpdate()
	{
		this.m_BuyButton.isEnabled = !this.m_ItemData.IsSoldOut;
		this.m_PriceLabel.color = ((!this.m_ItemData.IsCanBuy && !this.m_ItemData.IsSoldOut) ? this.m_CannotBuyCol : this.m_CanBuyCol);
		this.m_BuyButtonIcon.spriteName = ((!this.m_ItemData.IsSoldOut) ? this.m_BuySprite : this.m_SoldSprite);
	}

	public void SwitchFrame()
	{
		this.m_IconFrame.SetActive(KasaSceneMgr<SceneCasinoShop>.Instance.SelectTrywear == this.m_ItemData);
	}

	private CasinoShopItem m_ItemData;

	[SerializeField]
	private UILabel m_NameLabel;

	[SerializeField]
	private UILabel m_PriceLabel;

	[SerializeField]
	private Color m_CanBuyCol = Color.white;

	[SerializeField]
	private Color m_CannotBuyCol = Color.red;

	[SerializeField]
	private GameObject m_BuyButtonObj;

	[SerializeField]
	private GameObject m_ItemIconObj;

	[SerializeField]
	private string m_BuySprite;

	[SerializeField]
	private string m_SoldSprite;

	private UIButton m_IconButton;

	private UI2DSprite m_ItemIcon;

	private UIEventTrigger m_IconEvent;

	private GameObject m_IconFrame;

	private UIButton m_BuyButton;

	private UISprite m_BuyButtonIcon;
}
