UIStates.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using wf;
  6. public class UIStates : MonoBehaviour
  7. {
  8. public static UIStates Instance { get; private set; }
  9. private void Awake()
  10. {
  11. UIStates.Instance = this;
  12. this.m_ButtonsEnabled = true;
  13. this.AngleDisabled();
  14. this.m_NextButton = this.m_ResultUI.GetComponentInChildren<Button>();
  15. this.m_ResultImage = this.m_ResultUI.transform.Find("Result");
  16. this.m_GetMoneyText = this.m_ResultUI.transform.Find("GetMoneyText").GetComponent<Text>();
  17. this.m_CurrentMouneyText = this.m_ResultUI.transform.Find("BG/CurrentMoney").GetComponent<Text>();
  18. this.m_ResultCanvas = this.m_ResultUI.GetComponent<CanvasGroup>();
  19. }
  20. private void Start()
  21. {
  22. this.m_ResultUI.SetActive(false);
  23. ExChangeUI instance = ExChangeUI.Instance;
  24. instance.FadeInStartAction = (Action)Delegate.Combine(instance.FadeInStartAction, new Action(delegate()
  25. {
  26. this.EnableButton(this.m_StartButton, false);
  27. this.EnableButton(this.m_EndButton, false);
  28. }));
  29. BetSetUI instance2 = BetSetUI.Instance;
  30. instance2.CancelCall = (Action)Delegate.Combine(instance2.CancelCall, new Action(delegate()
  31. {
  32. this.EnableButton(this.m_StartButton, true);
  33. this.EnableButton(this.m_EndButton, true);
  34. }));
  35. ExChangeUI instance3 = ExChangeUI.Instance;
  36. instance3.FadeOutStartAction = (Action)Delegate.Combine(instance3.FadeOutStartAction, new Action(this.OnStateChange));
  37. }
  38. public void StateReset()
  39. {
  40. this.OnStateChange();
  41. this.HideResultText();
  42. }
  43. public void SetEnabled(bool enabled)
  44. {
  45. this.m_ButtonsEnabled = enabled;
  46. if (!enabled)
  47. {
  48. this.EnableButton(this.m_DoubleDownButton, false);
  49. this.EnableButton(this.m_StandButton, false);
  50. this.EnableButton(this.m_SplitButton, false);
  51. this.EnableButton(this.m_SurrenderButton, false);
  52. this.EnableButton(this.m_HitButton, false);
  53. this.EnableButton(this.m_ExchangeButton, false);
  54. this.EnableButton(this.m_EndButton, false);
  55. this.EnableButton(this.m_StartButton, false);
  56. }
  57. }
  58. public void OnStateChange()
  59. {
  60. this.CheckBetText();
  61. this.CheckHit();
  62. this.CheckStand();
  63. this.CheckDoubleDown();
  64. this.CheckSplit();
  65. this.CheckCredits();
  66. this.CheckSurrender();
  67. this.CheckBetSettingUI();
  68. }
  69. public void ShowOutcomeText()
  70. {
  71. this.CheckResultText();
  72. }
  73. private void CheckHit()
  74. {
  75. if (BjPlayer.Instance.CanHit() && this.m_ButtonsEnabled)
  76. {
  77. this.EnableButton(this.m_HitButton, true);
  78. }
  79. else
  80. {
  81. this.EnableButton(this.m_HitButton, false);
  82. }
  83. }
  84. private void CheckStand()
  85. {
  86. if (BjPlayer.Instance.CanHit() && this.m_ButtonsEnabled)
  87. {
  88. this.EnableButton(this.m_StandButton, true);
  89. }
  90. else
  91. {
  92. this.EnableButton(this.m_StandButton, false);
  93. }
  94. }
  95. private void CheckDoubleDown()
  96. {
  97. if (this.m_ButtonsEnabled && !BjPlayer.Instance.IsEnded() && BjPlayer.Instance.DoubleDownAvailable())
  98. {
  99. this.EnableButton(this.m_DoubleDownButton, true);
  100. }
  101. else
  102. {
  103. this.EnableButton(this.m_DoubleDownButton, false);
  104. }
  105. }
  106. private void CheckSplit()
  107. {
  108. if (BjPlayer.Instance.SplitAvailable() && this.m_ButtonsEnabled)
  109. {
  110. this.EnableButton(this.m_SplitButton, true);
  111. }
  112. else
  113. {
  114. this.EnableButton(this.m_SplitButton, false);
  115. }
  116. }
  117. private void CheckCredits()
  118. {
  119. ExChangeUI.Instance.TextUIUpdate();
  120. }
  121. private void CheckSurrender()
  122. {
  123. if (this.m_ButtonsEnabled && BjPlayer.Instance.CanSurrender())
  124. {
  125. this.EnableButton(this.m_SurrenderButton, true);
  126. }
  127. else
  128. {
  129. this.EnableButton(this.m_SurrenderButton, false);
  130. }
  131. }
  132. private void CheckBetText()
  133. {
  134. if (BjPlayer.Instance.CurrentBet == 0L || !BetSetUI.Instance.IsDoBet)
  135. {
  136. this.m_BetText.text = string.Empty;
  137. }
  138. else
  139. {
  140. this.m_BetText.text = BjPlayer.Instance.CurrentBet.ToString();
  141. }
  142. if (BjPlayer.Instance.SplitBet == 0L || !BetSetUI.Instance.IsDoBet)
  143. {
  144. this.m_SplitBetText.text = string.Empty;
  145. }
  146. else
  147. {
  148. this.m_SplitBetText.text = BjPlayer.Instance.SplitBet.ToString();
  149. }
  150. }
  151. private void CheckBetSettingUI()
  152. {
  153. BetSetUI.Instance.UpdateUIState();
  154. ExChangeUI.Instance.UIStateUpdate();
  155. bool flag = BjPlayer.Instance.IsIdle() && !BetSetUI.Instance.Active && this.m_ButtonsEnabled;
  156. this.m_StartButton.interactable = flag;
  157. this.m_EndButton.interactable = flag;
  158. ExChangeUI.Instance.SetButtonState(flag);
  159. BetSetUI.Instance.SetBetMax();
  160. }
  161. private void SetResultImage(string image_name)
  162. {
  163. IEnumerator enumerator = this.m_ResultImage.GetEnumerator();
  164. try
  165. {
  166. while (enumerator.MoveNext())
  167. {
  168. object obj = enumerator.Current;
  169. Transform transform = (Transform)obj;
  170. transform.gameObject.SetActive(transform.name == image_name);
  171. }
  172. }
  173. finally
  174. {
  175. IDisposable disposable;
  176. if ((disposable = (enumerator as IDisposable)) != null)
  177. {
  178. disposable.Dispose();
  179. }
  180. }
  181. }
  182. private void CheckResultText()
  183. {
  184. if (this.m_ResultUI.activeSelf)
  185. {
  186. this.HideResultText();
  187. return;
  188. }
  189. this.m_ResultUI.SetActive(true);
  190. if (BjPlayer.Instance.TotalWinnings > 0L)
  191. {
  192. if (BjPlayer.Instance.ExistSurrenderHand())
  193. {
  194. BjVoiceMgr.Instance.PlayVoice("サレンダー終了", null, 0f);
  195. this.m_GetMoneyText.text = "コインを" + BjPlayer.Instance.TotalWinnings.ToString() + "枚支払いました";
  196. this.SetResultImage(Translations.Instance.SURRENDER);
  197. }
  198. else if (BjPlayer.Instance.ExistWinHand())
  199. {
  200. this.m_GetMoneyText.text = "コインを" + BjPlayer.Instance.TotalWinnings.ToString() + "枚手に入れました!!";
  201. if (BjPlayer.Instance.ExistBlackJack())
  202. {
  203. this.SetResultImage(Translations.Instance.BLACKJACK);
  204. BjVoiceMgr.Instance.PlayVoice("ブラックジャック勝ち", null, 0f);
  205. }
  206. else
  207. {
  208. BjVoiceMgr.Instance.PlayVoice("勝利", null, 0f);
  209. if (BjPlayer.Instance.ExistDoubleDownwWin())
  210. {
  211. this.SetResultImage(Translations.Instance.BIG_WINNINGS);
  212. }
  213. else
  214. {
  215. this.SetResultImage(Translations.Instance.WINNINGS);
  216. }
  217. }
  218. BjMotionControl.Instance.PlayWinMotion(BjMotionControl.Instance.TargetMaid);
  219. CasinoDataMgr.Instance.AddTotalCoin((int)BjPlayer.Instance.FactMoneyDifference);
  220. }
  221. else if (BjPlayer.Instance.IsEven())
  222. {
  223. if (BjPlayer.Instance.ExistBlackJack() && Dealer.Instance.IsNatural21())
  224. {
  225. BjVoiceMgr.Instance.PlayVoice("ブラックジャック引き分け", null, 0f);
  226. }
  227. else
  228. {
  229. BjVoiceMgr.Instance.PlayVoice("引き分け", null, 0f);
  230. }
  231. this.SetResultImage(Translations.Instance.PUSH);
  232. this.m_GetMoneyText.text = "コイン" + BjPlayer.Instance.TotalWinnings.ToString() + "枚が手元に戻ってきます";
  233. }
  234. else
  235. {
  236. BjVoiceMgr.Instance.PlayVoice("負け", null, 0f);
  237. this.SetResultImage(Translations.Instance.YOU_LOSE);
  238. this.m_GetMoneyText.text = "コインを" + BjPlayer.Instance.MoneyDifference.ToString() + "枚失いました...";
  239. }
  240. }
  241. else
  242. {
  243. BjVoiceMgr.Instance.PlayVoice("負け", null, 0f);
  244. this.SetResultImage(Translations.Instance.YOU_LOSE);
  245. this.m_GetMoneyText.text = "コインを" + (BjPlayer.Instance.CurrentBet + BjPlayer.Instance.SplitBet).ToString() + "枚失いました...";
  246. }
  247. long orijin_coin = BjPlayer.Instance.OrijinCredit;
  248. if (BjPlayer.Instance.ExistWinHand())
  249. {
  250. orijin_coin = wf.Math.RoundMinMax(BjPlayer.Instance.OrijinCredit - (BjPlayer.Instance.CurrentBet + BjPlayer.Instance.SplitBet), 0L, 999999L);
  251. }
  252. this.m_CurrentMouneyText.text = Utility.ConvertMoneyText(orijin_coin);
  253. base.StartCoroutine(KasaiUtility.FadeCoroutine(this.m_ResultCanvas, false, 0.5f, null, true, true));
  254. this.m_NextButton.interactable = false;
  255. if (BjPlayer.Instance.IsEven())
  256. {
  257. this.m_NextButton.interactable = true;
  258. }
  259. else if (BjPlayer.Instance.ExistSurrenderHand())
  260. {
  261. base.StartCoroutine(this.TextFluctuation(orijin_coin));
  262. }
  263. else
  264. {
  265. ChipManager instance = ChipManager.Instance;
  266. instance.StackEndCallBack = (Action)Delegate.Combine(instance.StackEndCallBack, new Action(delegate()
  267. {
  268. this.StartCoroutine(this.TextFluctuation(orijin_coin));
  269. }));
  270. }
  271. }
  272. private IEnumerator TextFluctuation(long orijin_coin)
  273. {
  274. long coin = GameMain.Instance.CharacterMgr.status.casinoCoin;
  275. float timer = 0f;
  276. float rate = 0f;
  277. if (orijin_coin > coin)
  278. {
  279. yield return new WaitForSeconds(this.m_FirstPauseTime);
  280. }
  281. else if (orijin_coin == coin)
  282. {
  283. this.m_NextButton.interactable = true;
  284. yield break;
  285. }
  286. for (;;)
  287. {
  288. timer += Time.deltaTime;
  289. rate = Mathf.Clamp01(timer / this.m_FluctuationTime);
  290. long money = (long)Mathf.Lerp((float)orijin_coin, (float)coin, rate);
  291. this.m_CurrentMouneyText.text = Utility.ConvertMoneyText(money);
  292. if (rate >= 1f)
  293. {
  294. break;
  295. }
  296. yield return null;
  297. }
  298. this.m_NextButton.interactable = true;
  299. yield break;
  300. yield break;
  301. }
  302. public void HideResultText()
  303. {
  304. base.StartCoroutine(KasaiUtility.FadeCoroutine(this.m_ResultCanvas, true, 0.5f, null, true, true));
  305. }
  306. public void EnableButton(Button button, bool enabled)
  307. {
  308. button.interactable = enabled;
  309. }
  310. public void AngleAbled()
  311. {
  312. this.m_AngleButton.interactable = !GameMain.Instance.VRMode;
  313. }
  314. public void AngleDisabled()
  315. {
  316. this.m_AngleButton.interactable = false;
  317. }
  318. public void SetUIActive(bool active)
  319. {
  320. this.m_BjGameUI.interactable = active;
  321. }
  322. [SerializeField]
  323. private float m_FluctuationTime = 0.5f;
  324. [SerializeField]
  325. private float m_NotFluctuationWait = 0.5f;
  326. [SerializeField]
  327. private float m_FirstPauseTime = 1f;
  328. [SerializeField]
  329. private float m_EndPauseTime = 0.5f;
  330. [SerializeField]
  331. private CanvasGroup m_BjGameUI;
  332. [SerializeField]
  333. [Header("ヒット用のUI")]
  334. private Button m_HitButton;
  335. [SerializeField]
  336. [Header("ダブルダウン用のUI")]
  337. private Button m_DoubleDownButton;
  338. [SerializeField]
  339. [Header("スプリット用のUI")]
  340. private Button m_SplitButton;
  341. [SerializeField]
  342. [Header("スタンド用のUI")]
  343. private Button m_StandButton;
  344. [SerializeField]
  345. [Header("サレンダー用のUI")]
  346. private Button m_SurrenderButton;
  347. [SerializeField]
  348. [Header("ベット額表示用のUI")]
  349. private Text m_BetText;
  350. [SerializeField]
  351. [Header("スプリットのベット額表示用のUI")]
  352. private Text m_SplitBetText;
  353. [SerializeField]
  354. [Header("換金用UI表示ボタン")]
  355. private Button m_ExchangeButton;
  356. [SerializeField]
  357. [Header("勝負結果表示用のUI")]
  358. private GameObject m_ResultUI;
  359. [SerializeField]
  360. [Header("アングル切り替えボタン")]
  361. private Button m_AngleButton;
  362. [SerializeField]
  363. [Header("ブラックジャック終了ボタン")]
  364. private Button m_EndButton;
  365. [SerializeField]
  366. [Header("ブラックジャック開始ボタン")]
  367. private Button m_StartButton;
  368. private Transform m_ResultImage;
  369. private Text m_GetMoneyText;
  370. private Text m_CurrentMouneyText;
  371. private Button m_NextButton;
  372. private CanvasGroup m_ResultCanvas;
  373. private bool m_ButtonsEnabled;
  374. }