MoneySetttingUI.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using wf;
  6. public class MoneySetttingUI : MonoBehaviour
  7. {
  8. public long DisableDigit
  9. {
  10. get
  11. {
  12. return this.m_DisableDigit;
  13. }
  14. }
  15. public long MinValue
  16. {
  17. get
  18. {
  19. return this.m_MinValue;
  20. }
  21. }
  22. public long MaxValue
  23. {
  24. get
  25. {
  26. return this.m_MaxValue;
  27. }
  28. }
  29. public long MoneyValue
  30. {
  31. get
  32. {
  33. return this.m_MoneyValue;
  34. }
  35. }
  36. private void Awake()
  37. {
  38. if (this.m_SettingDataList.Count == 0)
  39. {
  40. this.Reset();
  41. }
  42. this.SetMoneyUI(this.m_MinValue, false);
  43. }
  44. private void Reset()
  45. {
  46. }
  47. private void OnValidate()
  48. {
  49. if (Application.isPlaying)
  50. {
  51. return;
  52. }
  53. if (!base.gameObject.activeInHierarchy)
  54. {
  55. return;
  56. }
  57. if (this.m_MinValue < 0L)
  58. {
  59. this.m_MinValue = 0L;
  60. }
  61. if ((float)this.m_MaxValue / Mathf.Pow(10f, (float)(this.m_Digit - 1L)) >= 10f)
  62. {
  63. this.m_MaxValue = (long)Mathf.Pow(10f, (float)(this.m_Digit - 1L));
  64. }
  65. if (this.m_DisableDigit >= this.m_Digit)
  66. {
  67. this.m_DisableDigit = this.m_Digit - 1L;
  68. }
  69. this.SetMoneyUI(this.m_MinValue, true);
  70. }
  71. public void SetMoneyUI(long value, bool is_init = false)
  72. {
  73. if (this.m_SettingDataList.Count == 0)
  74. {
  75. this.Reset();
  76. }
  77. bool flag = value == this.m_MaxValue;
  78. bool flag2 = value == this.m_MinValue;
  79. bool flag3 = flag2 && flag;
  80. for (int i = 0; i < this.m_SettingDataList.Count; i++)
  81. {
  82. long pow = this.m_SettingDataList[i].Pow10;
  83. if (is_init)
  84. {
  85. this.m_SettingDataList[i].MinNumber = Mathf.FloorToInt((float)this.m_MinValue / (float)pow);
  86. if (this.m_SettingDataList[i].MinNumber >= 10)
  87. {
  88. this.m_SettingDataList[i].MinNumber = 0;
  89. }
  90. if (Mathf.FloorToInt((float)this.m_MaxValue / (float)pow) < 10)
  91. {
  92. this.m_SettingDataList[i].MaxNumber = Mathf.FloorToInt((float)this.m_MaxValue / (float)pow);
  93. }
  94. else
  95. {
  96. this.m_SettingDataList[i].MaxNumber = 9;
  97. }
  98. }
  99. int num = (int)(value % (pow * 10L) / pow);
  100. this.m_SettingDataList[i].Number = num;
  101. if (!this.m_IsInvalid)
  102. {
  103. this.m_SettingDataList[i].UpButton.gameObject.SetActive(true);
  104. this.m_SettingDataList[i].DownButton.gameObject.SetActive(true);
  105. this.m_SettingDataList[i].UpButton.interactable = (Mathf.FloorToInt((float)this.m_MaxValue / (float)pow) >= 1);
  106. this.m_SettingDataList[i].DownButton.interactable = (Mathf.FloorToInt((float)this.m_MaxValue / (float)pow) >= 1);
  107. if ((long)i >= (long)this.m_SettingDataList.Count - this.m_DisableDigit)
  108. {
  109. this.m_SettingDataList[i].UpButton.gameObject.SetActive(false);
  110. this.m_SettingDataList[i].DownButton.gameObject.SetActive(false);
  111. }
  112. else if (flag3)
  113. {
  114. this.m_SettingDataList[i].UpButton.interactable = false;
  115. this.m_SettingDataList[i].DownButton.interactable = false;
  116. }
  117. else if (flag)
  118. {
  119. this.m_SettingDataList[i].UpButton.interactable &= (num == this.m_SettingDataList[i].MaxNumber);
  120. this.m_SettingDataList[i].DownButton.interactable &= (num != 0);
  121. }
  122. }
  123. else
  124. {
  125. this.m_SettingDataList[i].UpButton.gameObject.SetActive(false);
  126. this.m_SettingDataList[i].DownButton.gameObject.SetActive(false);
  127. }
  128. }
  129. this.m_MoneyValue = value;
  130. if (this.ValueUpdateAction != null)
  131. {
  132. this.ValueUpdateAction();
  133. }
  134. }
  135. public void UpValue(int index)
  136. {
  137. this.m_SettingDataList[index].Number = this.m_SettingDataList[index].Number + 1;
  138. if (this.m_MoneyValue == this.m_MaxValue)
  139. {
  140. this.m_MoneyValue -= (long)this.m_SettingDataList[index].MaxNumber * this.m_SettingDataList[index].Pow10;
  141. }
  142. else if (this.m_SettingDataList[index].Number >= 10)
  143. {
  144. this.m_MoneyValue -= 9L * this.m_SettingDataList[index].Pow10;
  145. }
  146. else
  147. {
  148. this.m_MoneyValue += this.m_SettingDataList[index].Pow10;
  149. }
  150. this.m_MoneyValue = wf.Math.RoundMinMax(this.m_MoneyValue, this.m_MinValue, this.m_MaxValue);
  151. this.SetMoneyUI(this.m_MoneyValue, false);
  152. }
  153. public void DownValue(int index)
  154. {
  155. this.m_SettingDataList[index].Number = this.m_SettingDataList[index].Number - 1;
  156. if (this.m_MoneyValue == this.m_MinValue)
  157. {
  158. this.m_MoneyValue += (long)(9 - this.m_SettingDataList[index].MinNumber) * this.m_SettingDataList[index].Pow10;
  159. }
  160. else if (this.m_SettingDataList[index].Number < 0)
  161. {
  162. this.m_MoneyValue += 9L * this.m_SettingDataList[index].Pow10;
  163. }
  164. else
  165. {
  166. this.m_MoneyValue -= this.m_SettingDataList[index].Pow10;
  167. }
  168. this.m_MoneyValue = wf.Math.RoundMinMax(this.m_MoneyValue, this.m_MinValue, this.m_MaxValue);
  169. this.SetMoneyUI(this.m_MoneyValue, false);
  170. }
  171. public void SetMaxValue(long max)
  172. {
  173. if (this.m_MaxValue == max)
  174. {
  175. return;
  176. }
  177. this.m_MaxValue = max;
  178. if (this.m_MoneyValue >= this.m_MaxValue)
  179. {
  180. this.m_MoneyValue = this.m_MaxValue;
  181. }
  182. this.SetMoneyUI(this.m_MoneyValue, true);
  183. }
  184. [SerializeField]
  185. [Header("設定金額の最小値")]
  186. private long m_MinValue = 100L;
  187. [SerializeField]
  188. [Header("設定金額の最大値")]
  189. private long m_MaxValue = 10000L;
  190. [SerializeField]
  191. [Header("設定無効な桁数")]
  192. private long m_DisableDigit = 2L;
  193. [SerializeField]
  194. [Header("設定操作無効か")]
  195. private bool m_IsInvalid;
  196. private long m_MoneyValue;
  197. [SerializeField]
  198. [HideInInspector]
  199. private long m_Digit;
  200. [SerializeField]
  201. [HideInInspector]
  202. private List<MoneySetttingUI.SettingData> m_SettingDataList = new List<MoneySetttingUI.SettingData>();
  203. [SerializeField]
  204. [HideInInspector]
  205. public MoneySetttingUI.ValueUpdateMethod ValueUpdateAction;
  206. public delegate void ValueUpdateMethod();
  207. [Serializable]
  208. private class SettingData
  209. {
  210. public int Number
  211. {
  212. get
  213. {
  214. return this.m_MyNumber;
  215. }
  216. set
  217. {
  218. this.m_MyNumber = value;
  219. this.NumberText.text = this.m_MyNumber.ToString();
  220. }
  221. }
  222. public Button UpButton;
  223. public Button DownButton;
  224. public Text NumberText;
  225. public int MinNumber;
  226. public int MaxNumber = 9;
  227. public long Pow10;
  228. private int m_MyNumber;
  229. }
  230. }