using System;
using UnityEngine;
using UnityEngine.UI;
using wf;

public class BetSetUI : MonoBehaviour
{
	public bool IsDoBet { get; private set; }

	public MoneySetttingUI MoneySetting
	{
		get
		{
			return this.m_MoneySetting;
		}
	}

	public bool Active
	{
		get
		{
			return base.gameObject.activeSelf;
		}
	}

	public long BetMoneyMax { get; private set; }

	public static BetSetUI Instance { get; private set; }

	private void Awake()
	{
		BetSetUI.Instance = this;
		this.m_MyCanvas = base.GetComponent<CanvasGroup>();
		MoneySetttingUI moneySetting = this.m_MoneySetting;
		moneySetting.ValueUpdateAction = (MoneySetttingUI.ValueUpdateMethod)Delegate.Combine(moneySetting.ValueUpdateAction, new MoneySetttingUI.ValueUpdateMethod(this.UpdateUIState));
		this.BetMoneyMax = this.m_MoneySetting.MaxValue;
		this.m_DialogCheck.isOn = (GameMain.Instance.CharacterMgr.status.GetFlag("ベット額警告非表示") == 1);
		this.m_MoneySetting.SetMoneyUI(this.m_MoneySetting.MinValue, true);
		base.gameObject.SetActive(false);
	}

	private void Start()
	{
		ExChangeUI instance = ExChangeUI.Instance;
		instance.FadeInStartAction = (Action)Delegate.Combine(instance.FadeInStartAction, new Action(this.FadeOut));
		ExChangeUI instance2 = ExChangeUI.Instance;
		instance2.FadeOutEndAction = (Action)Delegate.Combine(instance2.FadeOutEndAction, new Action(this.UpdateUIState));
	}

	private void DoBet()
	{
		UIStates.Instance.SetEnabled(false);
		BjVoiceMgr.Instance.PlayVoice("ブラックジャック開始", null, 0f);
		BjMotionControl.Instance.PlayMotion("*頷く", new Action(this.DealStart), true, false);
	}

	private void DealStart()
	{
		BjPlayer.Instance.SetBet(this.m_MoneySetting.MoneyValue);
		ChipManager instance = ChipManager.Instance;
		instance.StackEndCallBack = (Action)Delegate.Combine(instance.StackEndCallBack, new Action(BlackjackGame.Instance.Deal));
		ChipManager.Instance.UpdateStacks();
	}

	private void BetFadeOut()
	{
		GameMain.Instance.SysDlg.Close();
		UIStates.Instance.SetEnabled(false);
		this.IsDoBet = true;
		base.StartCoroutine(KasaiUtility.FadeCoroutine(this.m_MyCanvas, true, this.m_FadeTime, new Action(this.DoBet), true, true));
	}

	public void SetBetMax()
	{
		long num = wf.Math.RoundMinMax(GameMain.Instance.CharacterMgr.status.casinoCoin, this.m_MoneySetting.MinValue, this.BetMoneyMax);
		num /= (long)Mathf.Pow(10f, (float)this.m_MoneySetting.DisableDigit);
		num *= (long)Mathf.Pow(10f, (float)this.m_MoneySetting.DisableDigit);
		this.m_MoneySetting.SetMaxValue(num);
	}

	public void StateRecet()
	{
		this.IsDoBet = false;
	}

	public void UpdateUIState()
	{
		this.m_CreditText.text = Translations.Instance.CREDITS + (GameMain.Instance.CharacterMgr.status.casinoCoin - this.m_MoneySetting.MoneyValue);
	}

	public void PushOKButton()
	{
		if (GameMain.Instance.CharacterMgr.status.GetFlag("ベット額警告非表示") == 0)
		{
			bool flag = this.m_MoneySetting.MoneyValue >= (long)this.m_WarningMoney;
			string warning_message = string.Format("{0:#,##0}枚以上賭けようとしています。\n本当に賭けますか?", this.m_WarningMoney);
			bool flag2 = this.m_MoneySetting.MoneyValue * 2L > GameMain.Instance.CharacterMgr.status.casinoCoin;
			string f_strMsg = "現在の賭け額と所持コインの枚数では\nダブルダウン・スプリットは行えません\n本当に賭けますか?";
			if (flag2)
			{
				if (flag)
				{
					SystemDialog.OnClick f_dgOk = delegate()
					{
						GameMain.Instance.SysDlg.Show(warning_message, SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.BetFadeOut), null);
					};
					GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK_CANCEL, f_dgOk, null);
				}
				else
				{
					GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.BetFadeOut), null);
				}
			}
			else if (flag)
			{
				GameMain.Instance.SysDlg.Show(warning_message, SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.BetFadeOut), null);
			}
			else
			{
				this.BetFadeOut();
			}
		}
		else
		{
			this.BetFadeOut();
		}
	}

	public void PushCancelButton()
	{
		base.StartCoroutine(KasaiUtility.FadeCoroutine(this.m_MyCanvas, true, this.m_FadeTime, this.CancelCall, true, true));
	}

	public void PushResetButton()
	{
		this.m_MoneySetting.SetMoneyUI(this.m_MoneySetting.MinValue, false);
	}

	public void PushMaxButton()
	{
		this.m_MoneySetting.SetMoneyUI(this.m_MoneySetting.MaxValue, false);
	}

	public void SetDialogFlag()
	{
		if (this.m_DialogCheck.isOn)
		{
			GameMain.Instance.CharacterMgr.status.SetFlag("ベット額警告非表示", 1);
		}
		else
		{
			GameMain.Instance.CharacterMgr.status.SetFlag("ベット額警告非表示", 0);
		}
	}

	public void FadeIn()
	{
		base.gameObject.SetActive(true);
		base.StartCoroutine(KasaiUtility.FadeCoroutine(this.m_MyCanvas, false, this.m_FadeTime, null, true, true));
	}

	public void FadeOut()
	{
		if (!base.gameObject.activeSelf)
		{
			return;
		}
		base.StartCoroutine(KasaiUtility.FadeCoroutine(this.m_MyCanvas, true, this.m_FadeTime, null, true, true));
	}

	private CanvasGroup m_MyCanvas;

	[SerializeField]
	private float m_FadeTime = 0.5f;

	[SerializeField]
	[Header("この金額以上賭けたら警告")]
	private int m_WarningMoney = 10000;

	[SerializeField]
	[HideInInspector]
	private Text m_CreditText;

	[SerializeField]
	[HideInInspector]
	private MoneySetttingUI m_MoneySetting;

	[SerializeField]
	[HideInInspector]
	private Button m_OKButton;

	[SerializeField]
	[HideInInspector]
	private Toggle m_DialogCheck;

	public Action CancelCall;
}
