123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Xml;
- using UnityEngine;
- using UnityEngine.UI;
- public class CDMinigamePanelManager : Regist
- {
- #region Config
- private static Text Title;
- private static Text CoinCostText;
- private static Text DiamondCostText;
- private static Text ComfirmButtonTitle;
- private static Text CoinDescriptionText;
- private static Text DiamondDescriptionText;
- private static Button CloseButton;
- private static Button ComfirmButton;
- private static Toggle CoinToggle;
- private static Toggle DiamondToggle;
- private static Transform Mask;
- private static float CoinCDAmount;
- private static string CoinCostFormula;
- private static string DiamondCostFormula;
- private static bool IsPanelOpen;
- private static float RefreshTime = 1f;
- private static float RefreshTimer;
- private static double CoinCost;
- private static double DiamondCost;
- private static Current CDCurrent = Current.Coin;
- #endregion
- private void Update()
- {
- if (!IsPanelOpen)
- {
- return;
- }
- RefreshTimer += Time.deltaTime;
- if (RefreshTimer > RefreshTime)
- {
- RefreshTimer = 0;
- RefreshCost();
- }
- }
- private void Init()
- {
- XmlDocument document = ConfigManager.GetXmlDocument(ResourceLabel.MinigameConfig);
- XmlAttributeCollection attributes = document.SelectSingleNode(ConfigLabel.RootNode).SelectSingleNode(ConfigLabel.ChildNode).Attributes;
- int index = 2;
- CoinCDAmount = float.Parse(attributes[index++].Value);
- CoinCostFormula = attributes[index++].Value;
- DiamondCostFormula = attributes[index++].Value;
- }
- public override void RegistReference()
- {
- Init();
- Title = ResourceManager.Get<Text>(CanvasLabel.AD_Title);
- CoinCostText = ResourceManager.Get<Text>(CanvasLabel.AD_CoinCostText);
- DiamondCostText = ResourceManager.Get<Text>(CanvasLabel.AD_DiamondCostText);
- ComfirmButtonTitle = ResourceManager.Get<Text>(CanvasLabel.AD_ConfirmButtonTitle);
- CoinDescriptionText = ResourceManager.Get<Text>(CanvasLabel.AD_CoinDescription);
- DiamondDescriptionText = ResourceManager.Get<Text>(CanvasLabel.AD_DiamondDescription);
- Mask = ResourceManager.Get(CanvasLabel.AD_CDMinigameMask);
- CoinToggle = ResourceManager.Get<Toggle>(CanvasLabel.AD_CoinToggle);
- DiamondToggle = ResourceManager.Get<Toggle>(CanvasLabel.AD_DiamondToggle);
- CloseButton = ResourceManager.Get<Button>(CanvasLabel.AD_CloseButton);
- ComfirmButton = ResourceManager.Get<Button>(CanvasLabel.AD_ConfirmButton);
- Mask.CreateTweenCG(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
- CoinToggle.onValueChanged.AddListener(OnCoinToggleSelect);
- DiamondToggle.onValueChanged.AddListener(OnDiamondToggleSelect);
- CloseButton.onClick.AddListener(()=> { AudioManager.PlayClip(ResourceLabel.CloseClip); ClosePanel(); });
- ComfirmButton.onClick.AddListener(CDMinigame);
- LanguageManager.Add(Title, new MulLanStr(LanguageLabel.UI__AD_Title));
- LanguageManager.Add(ComfirmButtonTitle, new MulLanStr(LanguageLabel.UI__AD_ComfirmButtonTitle));
- LanguageManager.Add(DiamondDescriptionText, new MulLanStr(LanguageLabel.UI__AD_DiamondCDDescription));
- SwitchLanguage();
- }
- public override void SwitchLanguage()
- {
- string description = Language.GetStr(LanguageLabel.UI__AD_CoinCDDescription);
- description = description.Replace(TransferLabel.Value, CoinCDAmount.ToString("0"));
- CoinDescriptionText.text = description;
- }
- private static void OnCoinToggleSelect(bool value)
- {
- CDCurrent = Current.Coin;
- }
- private static void OnDiamondToggleSelect(bool value)
- {
- CDCurrent = Current.Diamond;
- }
- public static void OpenPanel()
- {
- IsPanelOpen = true;
- RefreshCost();
- Mask.TweenForCG();
- }
- public static void ClosePanel()
- {
- IsPanelOpen = false;
- Mask.TweenBacCG();
- AudioManager.PlayClip(ResourceLabel.CloseClip);
- }
- private static void RefreshCost()
- {
- double coinCost = Auxiliary.FmlParse(CoinCostFormula, "i", Manager.CircleIncome.ToString());
- CoinCost = Auxiliary.ShrinkNumber(coinCost);
- CoinCostText.text = TransferLabel.CoinSprite + Auxiliary.ShrinkNumberStr(coinCost);
- double diamondCost = Auxiliary.FmlParse(DiamondCostFormula, "s", Manager.MinigameCDTimer.ToString());
- DiamondCost = Mathf.CeilToInt((float) diamondCost);
- DiamondCostText.text = TransferLabel.DiamondSprite + diamondCost.ToString("0");
- }
- private static void CDMinigame()
- {
- if (CDCurrent == Current.Coin)
- {
- CoinCDMinigame();
- }
- else if (CDCurrent == Current.Diamond)
- {
- DiamondCDMinigame();
- }
- if (Manager.MinigameCDTimer <= 0)
- {
- ClosePanel();
- }
- }
- private static void CoinCDMinigame()
- {
- Manager.Pay
- (
- null,
- CoinCost,
- Current.Coin,
- () => { Manager.MinigameCDTimer -= CoinCDAmount; AudioManager.PlayClip(ResourceLabel.CurrentClip); },
- StaticsManager.ItemID.冷却小游戏,
- StaticsManager.ConsumeModule.Charge,
- false
- );
- }
- private static void DiamondCDMinigame()
- {
- Manager.Pay
- (
- null,
- DiamondCost,
- Current.Diamond,
- () => { Manager.MinigameCDTimer = 0; AudioManager.PlayClip(ResourceLabel.CurrentClip); },
- StaticsManager.ItemID.冷却小游戏,
- StaticsManager.ConsumeModule.Charge,
- false
- );
- }
- }
|