using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using wf;

public class MoneySetttingUI : MonoBehaviour
{
	public long DisableDigit
	{
		get
		{
			return this.m_DisableDigit;
		}
	}

	public long MinValue
	{
		get
		{
			return this.m_MinValue;
		}
	}

	public long MaxValue
	{
		get
		{
			return this.m_MaxValue;
		}
	}

	public long MoneyValue
	{
		get
		{
			return this.m_MoneyValue;
		}
	}

	private void Awake()
	{
		if (this.m_SettingDataList.Count == 0)
		{
			this.Reset();
		}
		this.SetMoneyUI(this.m_MinValue, false);
	}

	private void Reset()
	{
	}

	private void OnValidate()
	{
		if (Application.isPlaying)
		{
			return;
		}
		if (!base.gameObject.activeInHierarchy)
		{
			return;
		}
		if (this.m_MinValue < 0L)
		{
			this.m_MinValue = 0L;
		}
		if ((float)this.m_MaxValue / Mathf.Pow(10f, (float)(this.m_Digit - 1L)) >= 10f)
		{
			this.m_MaxValue = (long)Mathf.Pow(10f, (float)(this.m_Digit - 1L));
		}
		if (this.m_DisableDigit >= this.m_Digit)
		{
			this.m_DisableDigit = this.m_Digit - 1L;
		}
		this.SetMoneyUI(this.m_MinValue, true);
	}

	public void SetMoneyUI(long value, bool is_init = false)
	{
		if (this.m_SettingDataList.Count == 0)
		{
			this.Reset();
		}
		bool flag = value == this.m_MaxValue;
		bool flag2 = value == this.m_MinValue;
		bool flag3 = flag2 && flag;
		for (int i = 0; i < this.m_SettingDataList.Count; i++)
		{
			long pow = this.m_SettingDataList[i].Pow10;
			if (is_init)
			{
				this.m_SettingDataList[i].MinNumber = Mathf.FloorToInt((float)this.m_MinValue / (float)pow);
				if (this.m_SettingDataList[i].MinNumber >= 10)
				{
					this.m_SettingDataList[i].MinNumber = 0;
				}
				if (Mathf.FloorToInt((float)this.m_MaxValue / (float)pow) < 10)
				{
					this.m_SettingDataList[i].MaxNumber = Mathf.FloorToInt((float)this.m_MaxValue / (float)pow);
				}
				else
				{
					this.m_SettingDataList[i].MaxNumber = 9;
				}
			}
			int num = (int)(value % (pow * 10L) / pow);
			this.m_SettingDataList[i].Number = num;
			if (!this.m_IsInvalid)
			{
				this.m_SettingDataList[i].UpButton.gameObject.SetActive(true);
				this.m_SettingDataList[i].DownButton.gameObject.SetActive(true);
				this.m_SettingDataList[i].UpButton.interactable = (Mathf.FloorToInt((float)this.m_MaxValue / (float)pow) >= 1);
				this.m_SettingDataList[i].DownButton.interactable = (Mathf.FloorToInt((float)this.m_MaxValue / (float)pow) >= 1);
				if ((long)i >= (long)this.m_SettingDataList.Count - this.m_DisableDigit)
				{
					this.m_SettingDataList[i].UpButton.gameObject.SetActive(false);
					this.m_SettingDataList[i].DownButton.gameObject.SetActive(false);
				}
				else if (flag3)
				{
					this.m_SettingDataList[i].UpButton.interactable = false;
					this.m_SettingDataList[i].DownButton.interactable = false;
				}
				else if (flag)
				{
					this.m_SettingDataList[i].UpButton.interactable &= (num == this.m_SettingDataList[i].MaxNumber);
					this.m_SettingDataList[i].DownButton.interactable &= (num != 0);
				}
			}
			else
			{
				this.m_SettingDataList[i].UpButton.gameObject.SetActive(false);
				this.m_SettingDataList[i].DownButton.gameObject.SetActive(false);
			}
		}
		this.m_MoneyValue = value;
		if (this.ValueUpdateAction != null)
		{
			this.ValueUpdateAction();
		}
	}

	public void UpValue(int index)
	{
		this.m_SettingDataList[index].Number = this.m_SettingDataList[index].Number + 1;
		if (this.m_MoneyValue == this.m_MaxValue)
		{
			this.m_MoneyValue -= (long)this.m_SettingDataList[index].MaxNumber * this.m_SettingDataList[index].Pow10;
		}
		else if (this.m_SettingDataList[index].Number >= 10)
		{
			this.m_MoneyValue -= 9L * this.m_SettingDataList[index].Pow10;
		}
		else
		{
			this.m_MoneyValue += this.m_SettingDataList[index].Pow10;
		}
		this.m_MoneyValue = wf.Math.RoundMinMax(this.m_MoneyValue, this.m_MinValue, this.m_MaxValue);
		this.SetMoneyUI(this.m_MoneyValue, false);
	}

	public void DownValue(int index)
	{
		this.m_SettingDataList[index].Number = this.m_SettingDataList[index].Number - 1;
		if (this.m_MoneyValue == this.m_MinValue)
		{
			this.m_MoneyValue += (long)(9 - this.m_SettingDataList[index].MinNumber) * this.m_SettingDataList[index].Pow10;
		}
		else if (this.m_SettingDataList[index].Number < 0)
		{
			this.m_MoneyValue += 9L * this.m_SettingDataList[index].Pow10;
		}
		else
		{
			this.m_MoneyValue -= this.m_SettingDataList[index].Pow10;
		}
		this.m_MoneyValue = wf.Math.RoundMinMax(this.m_MoneyValue, this.m_MinValue, this.m_MaxValue);
		this.SetMoneyUI(this.m_MoneyValue, false);
	}

	public void SetMaxValue(long max)
	{
		if (this.m_MaxValue == max)
		{
			return;
		}
		this.m_MaxValue = max;
		if (this.m_MoneyValue >= this.m_MaxValue)
		{
			this.m_MoneyValue = this.m_MaxValue;
		}
		this.SetMoneyUI(this.m_MoneyValue, true);
	}

	[SerializeField]
	[Header("設定金額の最小値")]
	private long m_MinValue = 100L;

	[SerializeField]
	[Header("設定金額の最大値")]
	private long m_MaxValue = 10000L;

	[SerializeField]
	[Header("設定無効な桁数")]
	private long m_DisableDigit = 2L;

	[SerializeField]
	[Header("設定操作無効か")]
	private bool m_IsInvalid;

	private long m_MoneyValue;

	[SerializeField]
	[HideInInspector]
	private long m_Digit;

	[SerializeField]
	[HideInInspector]
	private List<MoneySetttingUI.SettingData> m_SettingDataList = new List<MoneySetttingUI.SettingData>();

	[SerializeField]
	[HideInInspector]
	public MoneySetttingUI.ValueUpdateMethod ValueUpdateAction;

	public delegate void ValueUpdateMethod();

	[Serializable]
	private class SettingData
	{
		public int Number
		{
			get
			{
				return this.m_MyNumber;
			}
			set
			{
				this.m_MyNumber = value;
				this.NumberText.text = this.m_MyNumber.ToString();
			}
		}

		public Button UpButton;

		public Button DownButton;

		public Text NumberText;

		public int MinNumber;

		public int MaxNumber = 9;

		public long Pow10;

		private int m_MyNumber;
	}
}
