You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.9 KiB

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<NotEnoughDialog>().Init(Shop.ShopType.Gems);
}
HideDialog();
}
else if (currentClickedObj == _buttonWatch.gameObject)
{
if (CommonFunctions.IsRewardedAdCanBeShown())
CommonFunctions.StartShowAd();
}
}
//-----------------------------------------------------------------------------------------
public override void Update ()
{
base.Update();
}
}