SpinBoxButton.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SpinBoxButton : MonoBehaviour
  5. {
  6. public void Init(SpinBoxParam spinBoxParam, UILabel lBox, UILabel lPoint)
  7. {
  8. this.m_lBox = lBox;
  9. this.m_lPoint = lPoint;
  10. this.maxSpinBoxNumber = spinBoxParam.m_maxNumber;
  11. this.minSpinBoxNumber = spinBoxParam.m_minNumber;
  12. this.amountPerPoint = spinBoxParam.amountPerPoint;
  13. if (BaseMgr<ProfileMgr>.Instance.m_maidStatus != null)
  14. {
  15. this.maxMaidPoint = SceneEdit.Instance.maidPoint;
  16. }
  17. this.m_myUiButton = base.gameObject.GetComponent<UIButton>();
  18. this.activeColor = new Color(this.m_myUiButton.defaultColor.r, this.m_myUiButton.defaultColor.g, this.m_myUiButton.defaultColor.b, 1f);
  19. this.inActiveColor = this.m_myUiButton.defaultColor;
  20. this.InitDownButton();
  21. }
  22. private void InitDownButton()
  23. {
  24. string name = base.gameObject.transform.name;
  25. if (name == "Down")
  26. {
  27. this.m_myUiButton.enabled = false;
  28. }
  29. }
  30. private void Update()
  31. {
  32. if (this.m_isPressed && this.m_updateTime < Time.realtimeSinceStartup)
  33. {
  34. this.OnUpDownButtonClick(base.transform.name);
  35. this.m_updateTime = Time.realtimeSinceStartup + this.m_updateInterval;
  36. }
  37. if (this.GetDividedPoint() > 0)
  38. {
  39. this.SetDownButtonActive(true);
  40. }
  41. else
  42. {
  43. this.SetDownButtonActive(false);
  44. }
  45. if (this.GetMaidPoint() > 0 && int.Parse(this.m_lBox.text) < this.maxSpinBoxNumber)
  46. {
  47. this.SetUpButtonActive(true);
  48. }
  49. else
  50. {
  51. this.SetUpButtonActive(false);
  52. }
  53. }
  54. private void OnPress(bool isDown)
  55. {
  56. if (isDown)
  57. {
  58. this.m_isPressed = true;
  59. this.m_updateTime = Time.realtimeSinceStartup + this.m_updateInterval;
  60. this.OnUpDownButtonClick(base.transform.name);
  61. }
  62. else
  63. {
  64. this.m_isPressed = false;
  65. }
  66. }
  67. public void OnUpDownButtonClick()
  68. {
  69. this.OnUpDownButtonClick(UIButton.current.name);
  70. }
  71. public void OnUpDownButtonClick(string clickBtnName)
  72. {
  73. SpinBoxButton.SpinBoxButtonType spinBoxButtonType = SpinBoxButton.SpinBoxButtonType.None;
  74. if (clickBtnName == SpinBoxButton.SpinBoxButtonType.Up.ToString())
  75. {
  76. spinBoxButtonType = SpinBoxButton.SpinBoxButtonType.Up;
  77. }
  78. else if (clickBtnName == SpinBoxButton.SpinBoxButtonType.Down.ToString())
  79. {
  80. spinBoxButtonType = SpinBoxButton.SpinBoxButtonType.Down;
  81. }
  82. else
  83. {
  84. Debug.LogError(string.Format("不適切なボタンが押されました。ボタン名:{0}", clickBtnName));
  85. }
  86. if (this.CanUpDownSpineBox(spinBoxButtonType))
  87. {
  88. this.UpdataPoint(spinBoxButtonType);
  89. }
  90. }
  91. private bool CanUpDownSpineBox(SpinBoxButton.SpinBoxButtonType spinBoxButtonType)
  92. {
  93. int num;
  94. if (!int.TryParse(this.m_lBox.text, out num))
  95. {
  96. return false;
  97. }
  98. if (spinBoxButtonType != SpinBoxButton.SpinBoxButtonType.Up)
  99. {
  100. return spinBoxButtonType == SpinBoxButton.SpinBoxButtonType.Down && (SceneEdit.Instance.maidPoint < this.maxMaidPoint && num > 0) && this.GetDividedPoint() > 0;
  101. }
  102. return SceneEdit.Instance.maidPoint > 0 && num < this.maxSpinBoxNumber;
  103. }
  104. private void UpdataPoint(SpinBoxButton.SpinBoxButtonType spinBoxButtonType)
  105. {
  106. int spinBoxPointToUse = this.GetSpinBoxPointToUse(spinBoxButtonType);
  107. int num = Math.Min(this.diffMaidPoint * this.amountPerPoint, spinBoxPointToUse);
  108. int num2 = 0;
  109. if (spinBoxButtonType != SpinBoxButton.SpinBoxButtonType.Up)
  110. {
  111. if (spinBoxButtonType == SpinBoxButton.SpinBoxButtonType.Down)
  112. {
  113. this.SetStatusDispPoint(-num);
  114. num2 = this.diffMaidPoint;
  115. this.SetDividedPoint(-num2);
  116. }
  117. }
  118. else
  119. {
  120. this.SetStatusDispPoint(num);
  121. num2 = -this.diffMaidPoint;
  122. this.SetDividedPoint(this.diffMaidPoint);
  123. }
  124. this.SetMaidPoint(num2);
  125. BaseMgr<ProfileMgr>.Instance.CloseSubWindowIfOpen();
  126. BaseMgr<ProfileMgr>.Instance.LoadMaidParamData();
  127. }
  128. private void SetStatusDispPoint(int spinBoxDispPoint)
  129. {
  130. if (this.GetSpinBoxName() == "Lovely")
  131. {
  132. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseLovely += spinBoxDispPoint;
  133. }
  134. else if (this.GetSpinBoxName() == "Elegance")
  135. {
  136. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseElegance += spinBoxDispPoint;
  137. }
  138. else if (this.GetSpinBoxName() == "Charm")
  139. {
  140. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseCharm += spinBoxDispPoint;
  141. }
  142. else if (this.GetSpinBoxName() == "Hentai")
  143. {
  144. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseHentai += spinBoxDispPoint;
  145. }
  146. else if (this.GetSpinBoxName() == "MValue")
  147. {
  148. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseMvalue += spinBoxDispPoint;
  149. }
  150. else if (this.GetSpinBoxName() == "Inran")
  151. {
  152. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseInyoku += spinBoxDispPoint;
  153. }
  154. else if (this.GetSpinBoxName() == "Housi")
  155. {
  156. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseHousi += spinBoxDispPoint;
  157. }
  158. else if (this.GetSpinBoxName() == "Cooking")
  159. {
  160. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseCooking += spinBoxDispPoint;
  161. }
  162. else if (this.GetSpinBoxName() == "Dance")
  163. {
  164. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseDance += spinBoxDispPoint;
  165. }
  166. else if (this.GetSpinBoxName() == "Vocal")
  167. {
  168. BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseVocal += spinBoxDispPoint;
  169. }
  170. }
  171. private int GetSpinBoxPointToUse(SpinBoxButton.SpinBoxButtonType spinBoxButtonType)
  172. {
  173. if (spinBoxButtonType == SpinBoxButton.SpinBoxButtonType.Up)
  174. {
  175. return this.maxSpinBoxNumber - int.Parse(this.m_lBox.text);
  176. }
  177. if (spinBoxButtonType != SpinBoxButton.SpinBoxButtonType.Down)
  178. {
  179. return 0;
  180. }
  181. return int.Parse(this.m_lBox.text);
  182. }
  183. private void SetMaidPoint(int number)
  184. {
  185. SceneEdit.Instance.maidPoint += number;
  186. }
  187. private int GetMaidPoint()
  188. {
  189. return SceneEdit.Instance.maidPoint;
  190. }
  191. private int GetDividedPoint()
  192. {
  193. GameObject gameObject = base.transform.parent.gameObject;
  194. int result = 0;
  195. if (BaseMgr<ProfileMgr>.Instance.m_dicDividedPoint.TryGetValue(gameObject.name, out result))
  196. {
  197. return result;
  198. }
  199. Debug.LogError("不適切なスピンボックスボタンが押下されました。");
  200. return result;
  201. }
  202. private void SetDividedPoint(int point)
  203. {
  204. string spinBoxName = this.GetSpinBoxName();
  205. if (BaseMgr<ProfileMgr>.Instance.m_dicDividedPoint.ContainsKey(spinBoxName))
  206. {
  207. Dictionary<string, int> dicDividedPoint;
  208. string key;
  209. (dicDividedPoint = BaseMgr<ProfileMgr>.Instance.m_dicDividedPoint)[key = spinBoxName] = dicDividedPoint[key] + point;
  210. }
  211. else
  212. {
  213. Debug.LogError("不適切なスピンボックスボタンが押下されました。");
  214. }
  215. }
  216. private string GetSpinBoxName()
  217. {
  218. return base.transform.parent.gameObject.name;
  219. }
  220. private void SetUpButtonActive(bool active)
  221. {
  222. string name = base.gameObject.transform.name;
  223. if (name == "Up")
  224. {
  225. if (active)
  226. {
  227. if (active != this.m_currentUpActive)
  228. {
  229. this.m_myUiButton.defaultColor = this.activeColor;
  230. this.m_myUiButton.enabled = active;
  231. this.m_currentUpActive = active;
  232. }
  233. }
  234. else if (active != this.m_currentUpActive)
  235. {
  236. this.m_myUiButton.defaultColor = this.inActiveColor;
  237. this.m_myUiButton.enabled = active;
  238. this.m_currentUpActive = active;
  239. }
  240. }
  241. }
  242. private void SetDownButtonActive(bool active)
  243. {
  244. string name = base.gameObject.transform.name;
  245. if (name == "Down")
  246. {
  247. if (active)
  248. {
  249. if (active != this.m_currentDownActive)
  250. {
  251. this.m_myUiButton.defaultColor = this.activeColor;
  252. this.m_myUiButton.enabled = active;
  253. this.m_currentDownActive = active;
  254. }
  255. }
  256. else if (active != this.m_currentDownActive)
  257. {
  258. this.m_myUiButton.defaultColor = this.inActiveColor;
  259. this.m_myUiButton.enabled = active;
  260. this.m_currentDownActive = active;
  261. }
  262. }
  263. }
  264. private UILabel m_lBox;
  265. private UILabel m_lPoint;
  266. private UIButton m_myUiButton;
  267. private bool m_isPressed;
  268. private bool m_currentDownActive;
  269. private bool m_currentUpActive;
  270. private int maxSpinBoxNumber = 9999;
  271. private int minSpinBoxNumber;
  272. private int maxMaidPoint;
  273. private int amountPerPoint;
  274. private int diffMaidPoint = 1;
  275. [SerializeField]
  276. private float m_updateInterval;
  277. private float m_updateTime;
  278. private Color activeColor;
  279. private Color inActiveColor;
  280. private enum SpinBoxButtonType
  281. {
  282. None = -1,
  283. Up,
  284. Down
  285. }
  286. }