CDMinigamePanelManager.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class CDMinigamePanelManager : Regist
  7. {
  8. #region Config
  9. private static Text Title;
  10. private static Text CoinCostText;
  11. private static Text DiamondCostText;
  12. private static Text ComfirmButtonTitle;
  13. private static Text CoinDescriptionText;
  14. private static Text DiamondDescriptionText;
  15. private static Button CloseButton;
  16. private static Button ComfirmButton;
  17. private static Toggle CoinToggle;
  18. private static Toggle DiamondToggle;
  19. private static Transform Mask;
  20. private static float CoinCDAmount;
  21. private static string CoinCostFormula;
  22. private static string DiamondCostFormula;
  23. private static bool IsPanelOpen;
  24. private static float RefreshTime = 1f;
  25. private static float RefreshTimer;
  26. private static double CoinCost;
  27. private static double DiamondCost;
  28. private static Current CDCurrent = Current.Coin;
  29. #endregion
  30. private void Update()
  31. {
  32. if (!IsPanelOpen)
  33. {
  34. return;
  35. }
  36. RefreshTimer += Time.deltaTime;
  37. if (RefreshTimer > RefreshTime)
  38. {
  39. RefreshTimer = 0;
  40. RefreshCost();
  41. }
  42. }
  43. private void Init()
  44. {
  45. XmlDocument document = ConfigManager.GetXmlDocument(ResourceLabel.MinigameConfig);
  46. XmlAttributeCollection attributes = document.SelectSingleNode(ConfigLabel.RootNode).SelectSingleNode(ConfigLabel.ChildNode).Attributes;
  47. int index = 2;
  48. CoinCDAmount = float.Parse(attributes[index++].Value);
  49. CoinCostFormula = attributes[index++].Value;
  50. DiamondCostFormula = attributes[index++].Value;
  51. }
  52. public override void RegistReference()
  53. {
  54. Init();
  55. Title = ResourceManager.Get<Text>(CanvasLabel.AD_Title);
  56. CoinCostText = ResourceManager.Get<Text>(CanvasLabel.AD_CoinCostText);
  57. DiamondCostText = ResourceManager.Get<Text>(CanvasLabel.AD_DiamondCostText);
  58. ComfirmButtonTitle = ResourceManager.Get<Text>(CanvasLabel.AD_ConfirmButtonTitle);
  59. CoinDescriptionText = ResourceManager.Get<Text>(CanvasLabel.AD_CoinDescription);
  60. DiamondDescriptionText = ResourceManager.Get<Text>(CanvasLabel.AD_DiamondDescription);
  61. Mask = ResourceManager.Get(CanvasLabel.AD_CDMinigameMask);
  62. CoinToggle = ResourceManager.Get<Toggle>(CanvasLabel.AD_CoinToggle);
  63. DiamondToggle = ResourceManager.Get<Toggle>(CanvasLabel.AD_DiamondToggle);
  64. CloseButton = ResourceManager.Get<Button>(CanvasLabel.AD_CloseButton);
  65. ComfirmButton = ResourceManager.Get<Button>(CanvasLabel.AD_ConfirmButton);
  66. Mask.CreateTweenCG(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  67. CoinToggle.onValueChanged.AddListener(OnCoinToggleSelect);
  68. DiamondToggle.onValueChanged.AddListener(OnDiamondToggleSelect);
  69. CloseButton.onClick.AddListener(()=> { AudioManager.PlayClip(ResourceLabel.CloseClip); ClosePanel(); });
  70. ComfirmButton.onClick.AddListener(CDMinigame);
  71. LanguageManager.Add(Title, new MulLanStr(LanguageLabel.UI__AD_Title));
  72. LanguageManager.Add(ComfirmButtonTitle, new MulLanStr(LanguageLabel.UI__AD_ComfirmButtonTitle));
  73. LanguageManager.Add(DiamondDescriptionText, new MulLanStr(LanguageLabel.UI__AD_DiamondCDDescription));
  74. SwitchLanguage();
  75. }
  76. public override void SwitchLanguage()
  77. {
  78. string description = Language.GetStr(LanguageLabel.UI__AD_CoinCDDescription);
  79. description = description.Replace(TransferLabel.Value, CoinCDAmount.ToString("0"));
  80. CoinDescriptionText.text = description;
  81. }
  82. private static void OnCoinToggleSelect(bool value)
  83. {
  84. CDCurrent = Current.Coin;
  85. }
  86. private static void OnDiamondToggleSelect(bool value)
  87. {
  88. CDCurrent = Current.Diamond;
  89. }
  90. public static void OpenPanel()
  91. {
  92. IsPanelOpen = true;
  93. RefreshCost();
  94. Mask.TweenForCG();
  95. }
  96. public static void ClosePanel()
  97. {
  98. IsPanelOpen = false;
  99. Mask.TweenBacCG();
  100. AudioManager.PlayClip(ResourceLabel.CloseClip);
  101. }
  102. private static void RefreshCost()
  103. {
  104. double coinCost = Auxiliary.FmlParse(CoinCostFormula, "i", Manager.CircleIncome.ToString());
  105. CoinCost = Auxiliary.ShrinkNumber(coinCost);
  106. CoinCostText.text = TransferLabel.CoinSprite + Auxiliary.ShrinkNumberStr(coinCost);
  107. double diamondCost = Auxiliary.FmlParse(DiamondCostFormula, "s", Manager.MinigameCDTimer.ToString());
  108. DiamondCost = Mathf.CeilToInt((float) diamondCost);
  109. DiamondCostText.text = TransferLabel.DiamondSprite + diamondCost.ToString("0");
  110. }
  111. private static void CDMinigame()
  112. {
  113. if (CDCurrent == Current.Coin)
  114. {
  115. CoinCDMinigame();
  116. }
  117. else if (CDCurrent == Current.Diamond)
  118. {
  119. DiamondCDMinigame();
  120. }
  121. if (Manager.MinigameCDTimer <= 0)
  122. {
  123. ClosePanel();
  124. }
  125. }
  126. private static void CoinCDMinigame()
  127. {
  128. Manager.Pay
  129. (
  130. null,
  131. CoinCost,
  132. Current.Coin,
  133. () => { Manager.MinigameCDTimer -= CoinCDAmount; AudioManager.PlayClip(ResourceLabel.CurrentClip); },
  134. StaticsManager.ItemID.冷却小游戏,
  135. StaticsManager.ConsumeModule.Charge,
  136. false
  137. );
  138. }
  139. private static void DiamondCDMinigame()
  140. {
  141. Manager.Pay
  142. (
  143. null,
  144. DiamondCost,
  145. Current.Diamond,
  146. () => { Manager.MinigameCDTimer = 0; AudioManager.PlayClip(ResourceLabel.CurrentClip); },
  147. StaticsManager.ItemID.冷却小游戏,
  148. StaticsManager.ConsumeModule.Charge,
  149. false
  150. );
  151. }
  152. }