using System;
using UnityEngine;
using UnityEngine.UI;

public class SceneCasinoSlot : MonoBehaviour
{
	public static SceneCasinoSlot Instance { get; private set; }

	private void Awake()
	{
		SceneCasinoSlot.Instance = this;
		this.m_ButtonSe = this.startButton.GetComponent<uGUIButtonSE>();
		if (GameMain.Instance.ScriptMgr.adv_kag.tag_backup.ContainsKey("cancel_label"))
		{
			this.m_CancelLabel = GameMain.Instance.ScriptMgr.adv_kag.tag_backup["cancel_label"];
		}
	}

	private void Start()
	{
		GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
		GameMain.Instance.SoundMgr.PlayBGM(this.m_BGMName, 0f, true);
		GameMain.Instance.MainLight.Reset();
		GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
		GameMain.Instance.BgMgr.ChangeBg("CasinoMini");
		GameMain.Instance.MainCamera.SetTargetPos(this.m_vCamResetTargetPos, true);
		GameMain.Instance.MainCamera.SetDistance(this.m_fCamResetDistance, true);
		GameMain.Instance.MainCamera.SetAroundAngle(this.m_vCamResetAngle, true);
		GameMain.Instance.CharacterMgr.DeactivateCharaAll();
		GameMain.Instance.MainCamera.FadeIn(1f, false, new CameraMain.dgOnCompleteFade(this.OnCompleteFadeIn), true, true, default(Color));
		GameMain.Instance.MainCamera.FadeInNoUI(0f, true);
		this.m_eMode = SceneCasinoSlot.Mode.FadeIn;
		if (GameMain.Instance.VRMode)
		{
		}
		if (!CasinoDataMgr.Instance.DealerMaid)
		{
			GameMain.Instance.CharacterMgr.status.casinoCoin = 499999L;
		}
		uGUITutorialPanel.OpenTutorial("SceneCasinoSlot", null, false);
		GameMain.Instance.SysShortcut.strSceneHelpName = "SceneCasinoSlot";
	}

	private void Update()
	{
		if (SlotUImgr.Instance.uiActive && Input.GetKeyDown(this.m_ShortCutStart))
		{
			if (this.sManager.state == 1)
			{
				this.m_ButtonSe.ClickSEPlay();
				this.onClick(0);
			}
			else if (this.sManager.StopButtons[0].interactable)
			{
				this.onClick(1);
			}
			else if (this.sManager.StopButtons[1].interactable)
			{
				this.onClick(2);
			}
			else if (this.sManager.StopButtons[2].interactable)
			{
				this.onClick(3);
			}
		}
	}

	public void onClick(int buttonNo)
	{
		if (this.sManager == null)
		{
			if (!(GameObject.Find("SlotManager") != null))
			{
				return;
			}
			this.sManager = GameObject.Find("SlotManager").GetComponent<SlotManager>();
		}
		if (buttonNo == 0)
		{
			if (GameMain.Instance.CharacterMgr.status.casinoCoin < 300L)
			{
				string f_strMsg = string.Format("スロットをするには最低でも\nコインが{0:#,##0}枚必用です", 300);
				GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK, null, null);
				return;
			}
			if (this.sManager.state == 1)
			{
				this.sManager.state = 2;
				this.startButton.GetComponent<Image>().sprite = this.sprite[1];
				SlotUImgr.Instance.UpdateUI();
			}
		}
		else if (buttonNo == 1)
		{
			if (!this.sManager.buttonFlg[0] && !this.sManager.isBlock)
			{
				GameMain.Instance.SoundMgr.PlaySe("casino_SE007.ogg", false);
				this.reels[0].GetComponent<Reel>().ChangeState(3);
				base.StartCoroutine(this.sManager.LightLamp(this.buttons[0].transform.GetChild(0).gameObject, false, this.sManager.lightingTime));
				this.sManager.buttonFlg[0] = true;
				this.sManager.isBlock = true;
				this.sManager.StopButtons[0].interactable = false;
			}
		}
		else if (buttonNo == 2)
		{
			if (!this.sManager.buttonFlg[1] && !this.sManager.isBlock)
			{
				GameMain.Instance.SoundMgr.PlaySe("casino_SE007.ogg", false);
				this.reels[1].GetComponent<Reel>().ChangeState(3);
				base.StartCoroutine(this.sManager.LightLamp(this.buttons[1].transform.GetChild(0).gameObject, false, this.sManager.lightingTime));
				this.sManager.buttonFlg[1] = true;
				this.sManager.isBlock = true;
				this.sManager.StopButtons[1].interactable = false;
			}
		}
		else if (buttonNo == 3 && !this.sManager.buttonFlg[2] && !this.sManager.isBlock)
		{
			GameMain.Instance.SoundMgr.PlaySe("casino_SE007.ogg", false);
			this.reels[2].GetComponent<Reel>().ChangeState(3);
			base.StartCoroutine(this.sManager.LightLamp(this.buttons[2].transform.GetChild(0).gameObject, false, this.sManager.lightingTime));
			this.sManager.buttonFlg[2] = true;
			this.sManager.isBlock = true;
			this.sManager.StopButtons[2].interactable = false;
		}
		int num = 0;
		for (int i = 0; i < 3; i++)
		{
			if (this.sManager.buttonFlg[i])
			{
				num++;
			}
		}
		if (num == 1)
		{
			this.sManager.state = 7;
		}
		else if (num == 3)
		{
		}
	}

	private void OnCompleteFadeIn()
	{
		this.m_eMode = SceneCasinoSlot.Mode.ClickWait;
	}

	private void OnCompleteFadeOut()
	{
	}

	private bool GetAnyMouseAndKey()
	{
		return NInput.GetMouseButtonUp(0) || NInput.GetMouseButtonUp(1) || NInput.GetMouseButtonUp(2) || Input.GetKeyUp(KeyCode.Return) || GameMain.Instance.IsForceSkip();
	}

	public void SlotEnd()
	{
		GameMain.Instance.SysDlg.Close();
		GameMain.Instance.MainCamera.FadeOut(0.5f, false, delegate
		{
			if (!string.IsNullOrEmpty(this.m_CancelLabel))
			{
				GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_CancelLabel);
				GameMain.Instance.ScriptMgr.adv_kag.Exec();
			}
		}, true, default(Color));
	}

	private SceneCasinoSlot.Mode m_eMode;

	public GameObject slotMachine;

	public GameObject lever;

	public GameObject ballLamp;

	public GameObject topLamp;

	public GameObject winMark;

	public GameObject heartLamp;

	public GameObject startButton;

	public GameObject fadeMask;

	public GameObject[] reels = new GameObject[3];

	public GameObject[] reelLights = new GameObject[3];

	public GameObject[] buttons = new GameObject[3];

	public GameObject[] slotLight = new GameObject[3];

	public GameObject[] hitLight = new GameObject[5];

	public GameObject[] payoutNumber = new GameObject[6];

	public GameObject[] creditNumber = new GameObject[6];

	public GameObject[] customMaidLamp = new GameObject[10];

	public GameObject[] sevenLamp = new GameObject[3];

	public GameObject[] bigbonus = new GameObject[8];

	public Texture[] tex = new Texture[4];

	public Sprite[] sprite = new Sprite[2];

	public SlotManager sManager;

	[SerializeField]
	[Header("カメラ設定")]
	private Vector3 m_vCamResetTargetPos;

	[SerializeField]
	private float m_fCamResetDistance;

	[SerializeField]
	private Vector2 m_vCamResetAngle;

	[SerializeField]
	private string m_BGMName = "BGM009.ogg";

	private string m_CancelLabel;

	[SerializeField]
	[Header("ショートカットキー")]
	private KeyCode m_ShortCutStart = KeyCode.Space;

	private uGUIButtonSE m_ButtonSe;

	private enum Mode
	{
		FadeIn,
		ClickWait,
		FadeOut
	}
}
