SpinBoxButton.cs 8.2 KB

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