Files
eggs/UiManager.cs
T
2026-09-22 10:29:55 +00:00

358 lines
8.1 KiB
C#

using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public class UiManager : Singleton<UiManager>
{
public Transform settingsPanel;
public Transform getCoinsPanel;
public Transform shopPanel;
public Transform newSkinUnlockPanel;
public Transform removeAdPanel;
public Transform noInternetAvailable;
public Transform ratePanel;
public Transform exitPanel;
public Transform hintsPanel;
public Transform LevelCompletePanel;
public Transform LevelFailedPanel;
public Text levelNumTextGameplay;
public Text levelNumTextGameover;
public Transform levelNumTag;
public Image currentBallImg;
public Animator SettingPanelAnim;
public GameObject RemoveAdsBtn;
public GameObject BannerPati;
private float currentBallInitialScale;
public bool isSettingsOpen;
[Header("Progressive UI Unlock")]
public GameObject topUISkipLevelBtn;
public GameObject[] iconsUnlockedAfterAd;
[Header("Reload Button")]
public RectTransform reloadBtnRect;
private Vector2 _reloadBtnHidePos;
private readonly Vector2 _reloadBtnShowPos = new Vector2(20f, -7f);
private bool isGameCompleted;
private void Start()
{
Application.targetFrameRate = 60;
MonetizationServices.Ads.ShowBanner();
if (RemoveAdsBtn != null)
{
RemoveAdsBtn.SetActive(false);
}
if (topUISkipLevelBtn != null)
{
topUISkipLevelBtn.SetActive(false);
}
for (int i = 0; i < iconsUnlockedAfterAd.Length; i++)
{
if (iconsUnlockedAfterAd[i] != null)
{
iconsUnlockedAfterAd[i].SetActive(false);
}
}
if (PlayerPrefs.GetInt("FirstAdShown", 0) == 1)
{
ShowRemoveAdsBtn();
}
if (PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 1)
{
ShowPostAdIcons();
}
if (AdConstants.AdsRemoved && RemoveAdsBtn != null)
{
RemoveAdsBtn.SetActive(false);
}
if (PlayerPrefs.GetInt("EverFailed", 0) == 1)
{
if (LevelScript.Instance != null)
{
ShowFailButtons(false);
}
}
if (reloadBtnRect != null)
{
_reloadBtnHidePos = reloadBtnRect.anchoredPosition;
reloadBtnRect.gameObject.SetActive(false);
}
Input.multiTouchEnabled = false;
currentBallInitialScale = currentBallImg.transform.localScale.x;
levelNumTag.localScale = Vector3.one;
levelNumTextGameplay.text = "Level " + PersistableData.Instance.itemsData.currentLevelNumProgressive;
levelNumTag.DOScale(0.5f, 1f);
UpdateBallImgIcon(PersistableData.Instance.shopItemSprite[PersistableData.Instance.itemsData.currentShopItemId]);
}
public void UpdateBallImgIcon(Sprite ballSprite)
{
currentBallImg.sprite = ballSprite;
currentBallImg.transform.DOKill();
currentBallImg.transform.localScale = Vector3.one * currentBallInitialScale;
currentBallImg.transform.DOPunchScale(Vector3.one * currentBallInitialScale * 0.5f, 0.5f, 1, 1f).OnComplete(delegate
{
currentBallImg.transform.localScale = Vector3.one * currentBallInitialScale;
});
}
private void OnEnable()
{
GameManager.OnGameComplete += OnGameComplete;
GameManager.OnLineDrawingStarts += OnLineDrawingStarts;
}
private void OnDisable()
{
GameManager.OnGameComplete -= OnGameComplete;
GameManager.OnLineDrawingStarts -= OnLineDrawingStarts;
}
private void OnGameComplete()
{
isGameCompleted = true;
if (reloadBtnRect != null)
{
reloadBtnRect.gameObject.SetActive(false);
}
}
private void OnLineDrawingStarts()
{
if (reloadBtnRect == null)
{
return;
}
reloadBtnRect.anchoredPosition = _reloadBtnHidePos;
reloadBtnRect.gameObject.SetActive(true);
reloadBtnRect.DOAnchorPos(_reloadBtnShowPos, 0.7f).SetEase(Ease.OutBack);
}
public void OpenSettingsPanel()
{
if (isGameCompleted)
{
return;
}
isSettingsOpen = !isSettingsOpen;
SettingPanelAnim.enabled = true;
if (isSettingsOpen)
{
SettingPanelAnim.SetBool("SettingIn", true);
SettingPanelAnim.SetBool("SettingOut", false);
}
else
{
SettingPanelAnim.SetBool("SettingIn", false);
SettingPanelAnim.SetBool("SettingOut", true);
}
LevelAnalytics.Send(new string[] { "SettingPanel" });
}
public void ShowRatePopUp()
{
AppConstants.IsAnyPanelOpen = true;
ratePanel.gameObject.SetActive(true);
}
public void CloseRatePanel()
{
AppConstants.IsAnyPanelOpen = false;
ratePanel.gameObject.SetActive(false);
}
public void OpenShopPanel()
{
if (isGameCompleted)
{
return;
}
shopPanel.gameObject.SetActive(true);
}
public void ShowRemoveAdPanelAtLevel()
{
if (PersistableData.Instance != null && PersistableData.Instance.itemsData.isRemoveAdPurchased)
{
return;
}
AppConstants.removeAdsPanelFromLevelFlow = false;
AppConstants.IsAnyPanelOpen = true;
removeAdPanel.gameObject.SetActive(true);
LevelAnalytics.Send(new string[] { "RemoveAds_LevelShow" });
}
public void ShowRemoveAdPanel()
{
SettingPanelAnim.SetBool("SettingIn", false);
SettingPanelAnim.SetBool("SettingOut", true);
isSettingsOpen = false;
AppConstants.IsAnyPanelOpen = true;
removeAdPanel.gameObject.SetActive(true);
if (PersistableData.Instance.itemsData.isRemoveAdPurchased)
{
return;
}
LevelAnalytics.Send(new string[] { "RemoveAds_Screen" });
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
ShowExitPanel();
}
}
private void ShowExitPanel()
{
SettingPanelAnim.SetBool("SettingIn", false);
SettingPanelAnim.SetBool("SettingOut", true);
AppConstants.IsAnyPanelOpen = true;
exitPanel.gameObject.SetActive(true);
}
public void CloseExitPanel()
{
AppConstants.IsAnyPanelOpen = false;
exitPanel.gameObject.SetActive(false);
}
public void CloseShopPanel()
{
shopPanel.gameObject.GetComponent<DialogueBaseClass>().ClosePanel();
}
public void OpenNotEnoughCoinsPanel()
{
AppConstants.IsAnyPanelOpen = true;
getCoinsPanel.gameObject.SetActive(true);
}
public void CloseNotEnoughCoinsPanel()
{
AppConstants.IsAnyPanelOpen = false;
getCoinsPanel.gameObject.SetActive(false);
}
public void ShowNoInternetPanel()
{
AppConstants.IsAnyPanelOpen = true;
noInternetAvailable.gameObject.SetActive(true);
}
public void CloseNoInternetPanel()
{
AppConstants.IsAnyPanelOpen = false;
noInternetAvailable.gameObject.SetActive(false);
}
public void ShowNewSkinPopUp()
{
newSkinUnlockPanel.gameObject.SetActive(true);
}
public void ShowFailButtons(bool isAutoHintLevel)
{
if (topUISkipLevelBtn != null)
{
topUISkipLevelBtn.SetActive(true);
}
}
public void ShowRemoveAdsBtn()
{
if (!AdConstants.AdsRemoved && RemoveAdsBtn != null)
{
RemoveAdsBtn.SetActive(true);
}
}
public void ShowPostAdIcons()
{
if (!AdConstants.AdsRemoved && RemoveAdsBtn != null)
{
RemoveAdsBtn.SetActive(true);
}
for (int i = 0; i < iconsUnlockedAfterAd.Length; i++)
{
if (iconsUnlockedAfterAd[i] != null)
{
iconsUnlockedAfterAd[i].SetActive(true);
}
}
}
public void ShowRemoveAdPanelFromFlow()
{
AppConstants.IsAnyPanelOpen = true;
removeAdPanel.gameObject.SetActive(true);
LevelAnalytics.Send(new string[] { "RemoveAds_FirstTime" });
}
public void CloseRemoveAdPanel_NoThanks()
{
if (AppConstants.removeAdsPanelFromLevelFlow)
{
AppConstants.removeAdsPanelFromLevelFlow = false;
PlayerPrefs.SetInt("RemoveAdsPanelShown", 1);
PlayerPrefs.Save();
LevelAnalytics.Send(new string[] { "RemoveAds_NoThanks" });
AppConstants.IsAnyPanelOpen = false;
removeAdPanel.gameObject.SetActive(false);
ShowPostAdIcons();
}
else
{
AppConstants.IsAnyPanelOpen = false;
removeAdPanel.gameObject.SetActive(false);
}
}
public void CloseRemoveAdPanel_IAPSuccess()
{
AppConstants.removeAdsPanelFromLevelFlow = false;
PlayerPrefs.SetInt("RemoveAdsPanelShown", 1);
PlayerPrefs.Save();
ShowPostAdIcons();
}
public void OpenHintsPanel()
{
AppConstants.IsAnyPanelOpen = true;
hintsPanel.gameObject.SetActive(true);
}
public void CloseHintsPanel()
{
AppConstants.IsAnyPanelOpen = false;
hintsPanel.gameObject.SetActive(false);
}
}