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.
 
 
 
 
 
 

310 lines
9.6 KiB

using Meta;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using TMPro;
using Shop;
using Ability;
using Equip;
using Stages;
using Utils;
using Ui.Screens;
public class MainMenu : BaseBoard
{
[SerializeField] GameObject m_topHudObj;
[SerializeField] GameObject m_bottomHudObj;
[SerializeField] ScreenContainer _menuContainer;
[SerializeField] StageContainer _stageContainer;
[SerializeField] ScrollRect _roomContainer;
[SerializeField] TextMeshProUGUI m_energyLabel;
[SerializeField] TextMeshProUGUI m_energyTimeLabel;
[SerializeField] TextMeshProUGUI m_coinsLabel;
[SerializeField] TextMeshProUGUI m_crystalLabel;
[SerializeField] TextMeshProUGUI m_healthStats;
[SerializeField] TextMeshProUGUI m_attackStats;
[SerializeField] Button m_optionsButton;
[SerializeField] Button m_buyGemsButton;
[SerializeField] Button m_buyCoinsButton;
[SerializeField] Button m_changeSkinButton;
[SerializeField] Button m_selectWorldButton;
[SerializeField] Button m_backButton;
[SerializeField] Button m_playButton;
[SerializeField] GameObject m_shopAdsObj;
[SerializeField] private MainCharacter m_char;
[SerializeField] GameObject m_raccoonSkillIcon;
[SerializeField] GameObject m_foxSkillIcon;
[SerializeField] GameObject m_skunkSkillIcon;
[SerializeField] TextMeshProUGUI m_skillInfo;
int m_hudBasePosY = -10000000;
//------------------------------------------------
void Start ()
{
Init();
GlobalsVar.gBoard = this;
if (MusicManager.Instance)
MusicManager.Instance.StartMusic();
GlobalsVar.gPlayerLvlUpInRun = 0;
GlobalsVar.gCurrentRoomInRun = 0;
}
//------------------------------------------------
void Init()
{
if (m_energyLabel)
m_energyLabel.text = GlobalsVar.gUser.Energy.ToString();
Repaint();
RepaintArsenal();
UpdateTimerLabel();
InitButtons();
PlayerResources.Instance.Clear();
ApplaySafeAreaHudShift();
}
//------------------------------------------------------------------
public void StartSelectRoomMode()
{
if (GlobalsVar.gSelectRoomMode)
return;
m_optionsButton.gameObject.SetActive(false);
m_bottomHudObj.SetActive(false);
m_playButton.gameObject.SetActive(false);
m_selectWorldButton.gameObject.SetActive(true);
m_backButton.gameObject.SetActive(true);
_menuContainer.enabled = false;
_roomContainer.enabled = true;
_stageContainer.SetIconsVisible(true);
GlobalsVar.gSelectRoomMode = true;
}
//------------------------------------------------------------------
void StartMenuMode(bool needDrop)
{
if (!GlobalsVar.gSelectRoomMode)
return;
m_optionsButton.gameObject.SetActive(true);
m_bottomHudObj.SetActive(true);
m_playButton.gameObject.SetActive(true);
m_selectWorldButton.gameObject.SetActive(false);
m_backButton.gameObject.SetActive(false);
_menuContainer.enabled = true;
_roomContainer.enabled = false;
if (needDrop)
_stageContainer.Drop();
else
_stageContainer.SetIconsVisible(false);
GlobalsVar.gSelectRoomMode = false;
}
//------------------------------------------------------------------
override public void ApplaySafeAreaHudShift()
{
if (m_topHudObj)
{
Vector3 localPos = m_topHudObj.transform.localPosition;
if (m_hudBasePosY < -10000)
m_hudBasePosY = (int)localPos.y;
m_topHudObj.transform.localPosition = new Vector3( localPos.x, m_hudBasePosY - GlobalsVar.gSafeAreaHudShift, localPos.z );
if (m_optionsButton)
{
localPos = m_optionsButton.transform.localPosition;
m_optionsButton.transform.localPosition = new Vector3(localPos.x, localPos.y - GlobalsVar.gSafeAreaHudShift, localPos.z); ;
}
}
}
//----------------------------------------------------
public void RepaintArsenal()
{
SkinType type = GlobalsVar.gUser.CurrentSkin;
if (type == SkinType.RACCOON)
{
m_raccoonSkillIcon.SetActive(true);
m_foxSkillIcon.SetActive(false);
m_skunkSkillIcon.SetActive(false);
}
else if (type == SkinType.FOX)
{
m_raccoonSkillIcon.SetActive(false);
m_foxSkillIcon.SetActive(true);
m_skunkSkillIcon.SetActive(false);
}
else if (type == SkinType.SKUNK)
{
m_raccoonSkillIcon.SetActive(false);
m_foxSkillIcon.SetActive(false);
m_skunkSkillIcon.SetActive(true);
}
SkinsInfo skinInfo = CommonFunctions.GetSkinInfoByType(type);
m_skillInfo.text = GlobalsVar.gGameTextMng.GetGameText(159).ToUpper() + "\n" + GlobalsVar.gGameTextMng.GetGameText(skinInfo.m_skillTextId);
RepaintChar();
}
//----------------------------------------------------
public void RepaintChar()
{
m_char.Repaint();
Repaint();
}
//----------------------------------------------------
public void Repaint()
{
if (m_coinsLabel)
m_coinsLabel.text = GlobalsVar.gUser.Coins.ToString();
if (m_crystalLabel)
m_crystalLabel.text = GlobalsVar.gUser.Crystals.ToString();
if (m_energyLabel)
m_energyLabel.text = GlobalsVar.gUser.Energy.ToString();
if (m_healthStats)
{
int health = GlobalsVar.gBaseHealth;
int healthFromAb = (int)GlobalsVar.gMainAbilities.GetAbilityValueByType(MainAbilityType.ADD_HEALTH);
var items = EquipSettings.GetItems();
foreach (var item in items)
{
health += (int)item.AddHp;
}
health += healthFromAb;
m_healthStats.text = health.ToString();
}
if (m_attackStats)
{
int damage = GlobalsVar.gBaseDamage;
int damageFromAb = (int)GlobalsVar.gMainAbilities.GetAbilityValueByType(MainAbilityType.ADD_DAMAGE);
damage += damageFromAb;
m_attackStats.text = damage.ToString();
}
}
//----------------------------------------------------
public void ReinitShopAdsObj()
{
m_shopAdsObj.GetComponent<ShopItem>().InitAdsItem();
}
//----------------------------------------------------
public void UpdateShopAdsTimer(float time)
{
m_shopAdsObj.GetComponent<ShopItem>().SetCurrentTime(time);
}
//----------------------------------------------------
public void UpdateTimerLabel()
{
string timeStr = "";
timeStr = CommonFunctions.GetTimeStr((int)(GlobalsVar.gCurrentTimeToRegenerateEnergy));
if (GlobalsVar.gUser.Energy >= GlobalsVar.gMaxEnergyCount && m_energyTimeLabel.gameObject.activeSelf)
m_energyTimeLabel.gameObject.SetActive(false);
else if (GlobalsVar.gUser.Energy < GlobalsVar.gMaxEnergyCount && !m_energyTimeLabel.gameObject.activeSelf)
m_energyTimeLabel.gameObject.SetActive(true);
m_energyTimeLabel.text = timeStr;
ChangeEnergyCountLabel();
}
//----------------------------------------------------
public void ChangeEnergyCountLabel()
{
m_energyLabel.text = GlobalsVar.gUser.Energy.ToString();
}
//------------------------------------------------
void InitButtons()
{
if (m_optionsButton)
{
m_optionsButton.onClick.AddListener(ButtonPress);
}
if (m_buyGemsButton)
m_buyGemsButton.onClick.AddListener(ButtonPress);
if (m_buyCoinsButton)
m_buyCoinsButton.onClick.AddListener(ButtonPress);
if (m_changeSkinButton)
m_changeSkinButton.onClick.AddListener(ButtonPress);
if (m_selectWorldButton)
{
m_selectWorldButton.onClick.AddListener(ButtonPress);
CommonFunctions.SetButtonText(m_selectWorldButton.gameObject, GlobalsVar.gGameTextMng.GetGameText(64).ToUpper());
m_selectWorldButton.gameObject.SetActive(false);
}
if (m_backButton)
{
m_backButton.onClick.AddListener(ButtonPress);
CommonFunctions.SetButtonText(m_backButton.gameObject, GlobalsVar.gGameTextMng.GetGameText(63));
m_backButton.gameObject.SetActive(false);
}
}
//------------------------------------------------
public void ButtonPress()
{
if (GlobalsVar.gSkipClickTime > 0f)
return;
GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject;
if(currentClickedObj == m_optionsButton.gameObject)
{
GameObject dlg = StartDialog("SettingsDialog");
dlg.GetComponent<SettingsDialog>().Init();
}
else if (currentClickedObj == m_changeSkinButton.gameObject)
{
GameObject dlg = StartDialog("ChangeSkinDialog");
dlg.GetComponent<ChangeSkinDialog>().Init();
}
else if (currentClickedObj == m_backButton.gameObject)
{
StartMenuMode(true);
GlobalsVar.gSkipClickTime = 0.2f;
}
else if (currentClickedObj == m_selectWorldButton.gameObject)
{
StartMenuMode(false);
GlobalsVar.gSkipClickTime = 0.2f;
}
}
//------------------------------------------------
public override void Update ()
{
base.Update();
}
}