using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using TMPro; public class NotEnoughEnergyDialog : BaseDialog { [SerializeField] private Button _buttonExit; [SerializeField] private Button _buttonBuy; [SerializeField] private Button _buttonWatch; [SerializeField] private TextMeshProUGUI _header; [SerializeField] private TextMeshProUGUI _info; //----------------------------------------------------------------------------------------- void Start () { m_type = DialogType.NOT_ENOUGH_ENERGY; } //----------------------------------------------------------------------------------------- public void Init() { InitTexts(); InitButtons(); } //----------------------------------------------------------------------------------------- private void InitTexts() { if (_header) _header.text = GlobalsVar.gGameTextMng.GetGameText(123).ToUpper(); if (_info) _info.text = GlobalsVar.gGameTextMng.GetGameText(122); } //----------------------------------------------------------------------------------------- private void InitButtons() { if (_buttonExit) _buttonExit.onClick.AddListener(ButtonPress); if (_buttonBuy) _buttonBuy.onClick.AddListener(ButtonPress); if (_buttonWatch) { _buttonWatch.onClick.AddListener(ButtonPress); if (CommonFunctions.IsRewardedAdCanBeShown()) _buttonWatch.interactable = false; } } //----------------------------------------------------------------------------------------- private void ButtonPress() { GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject; if (currentClickedObj == _buttonExit.gameObject) HideDialog(); else if (currentClickedObj == _buttonBuy.gameObject) { if (GlobalsVar.gUser.Crystals >= GlobalsVar.gBuyFullEnergy) { GlobalsVar.gUser.IncCurrency(Shop.ShopType.Gems, -GlobalsVar.gBuyFullEnergy); GlobalsVar.gUser.IncEnergy(20); MainMenu mainMenu = GlobalsVar.gBoard as MainMenu; if (mainMenu) mainMenu.Repaint(); } else { GameObject dlg = GlobalsVar.gBoard.StartDialog("NotEnoughDialog"); dlg.GetComponent().Init(Shop.ShopType.Gems); } HideDialog(); } else if (currentClickedObj == _buttonWatch.gameObject) { if (CommonFunctions.IsRewardedAdCanBeShown()) CommonFunctions.StartShowAd(); } } //----------------------------------------------------------------------------------------- public override void Update () { base.Update(); } }