UIStates.cs 13 KB

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