备份CatanBuilding瘦身独立工程
This commit is contained in:
146
Assets/Scripts/Aquarium/UI/SpeedupPopupPanel.cs
Normal file
146
Assets/Scripts/Aquarium/UI/SpeedupPopupPanel.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpeedupPopupPanel : MonoBehaviour
|
||||
{
|
||||
AdvertButton advertButton;
|
||||
Button freeButton;
|
||||
Button btn_diamonds;
|
||||
Button btn_diamonds_gray;
|
||||
TMP_Text text_info;
|
||||
TMP_Text p_text_num;
|
||||
TMP_Text p_text_num_gray;
|
||||
|
||||
Button btn_close;
|
||||
Action OnSucceedCall;
|
||||
Action<bool> StartSeedUp;
|
||||
TMP_Text p_text;
|
||||
TMP_Text p_text1;
|
||||
TMP_Text text_time;
|
||||
GameObject speedupPopupPanel;
|
||||
GameObject aquariumSpeedupPanel;
|
||||
private void Awake()
|
||||
{
|
||||
speedupPopupPanel = transform.Find("SpeedupPopupPanel").gameObject;
|
||||
aquariumSpeedupPanel = transform.Find("AquariumSpeedupPanel").gameObject;
|
||||
btn_diamonds = transform.Find("SpeedupPopupPanel/root/btn_diamonds/btn_adv").GetComponent<Button>();
|
||||
btn_diamonds_gray = transform.Find("SpeedupPopupPanel/root/btn_diamonds_gray/btn_adv").GetComponent<Button>();
|
||||
advertButton = transform.Find("SpeedupPopupPanel/root/btn_advert").GetComponent<AdvertButton>();
|
||||
btn_close = transform.Find("SpeedupPopupPanel/btn_close").GetComponent<Button>();
|
||||
text_info = transform.Find("SpeedupPopupPanel/root/bg_time/text_time").GetComponent<TMP_Text>();
|
||||
p_text = transform.Find("SpeedupPopupPanel/root/btn_advert/btn_adv/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
p_text1 = transform.Find("SpeedupPopupPanel/root/btn_advert/btn_ticket/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
p_text_num = transform.Find("SpeedupPopupPanel/root/btn_diamonds/btn_adv/Ani_Container/content_cost/cost/p_text_num").GetComponent<TMP_Text>();
|
||||
p_text_num_gray = transform.Find("SpeedupPopupPanel/root/btn_diamonds_gray/btn_adv/Ani_Container/content_cost/cost/p_text_num").GetComponent<TMP_Text>();
|
||||
text_time = transform.Find("SpeedupPopupPanel/root/text_time").GetComponent<TMP_Text>();
|
||||
freeButton = transform.Find("SpeedupPopupPanel/root/btn_free").GetComponent<Button>();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
bool isGuide = GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("SpeedupPopupPanel");
|
||||
p_text_num_gray.text = p_text_num.text = GContext.container.Resolve<Tables>().TbAquariumConfig.AdAccelerateDiamondCost.ToString();
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
Tables tables = GContext.container.Resolve<Tables>();
|
||||
string contnet = LocalizationMgr.GetFormatTextValue("UI_AquariumPanel_16", tables.TbAquariumConfig.AdAccelerate * 60);
|
||||
if (isGuide)
|
||||
{
|
||||
//advertButton.SetData(null, AdvertPopupType.Aquarium);
|
||||
//advertButton.advBtn.onClick.AddListener(GuideAdsSucceed);
|
||||
freeButton.onClick.AddListener(GuideAdsSucceed);
|
||||
//p_text1.text = p_text.text = LocalizationMgr.GetText("UI_BattlePassPanel_3");
|
||||
contnet = LocalizationMgr.GetFormatTextValue("UI_AquariumPanel_16", tables.TbAquariumConfig.AdAccelerateFirst * 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
advertButton.SetData(OnAdsSucceed, AdvertPopupType.Aquarium);
|
||||
}
|
||||
advertButton.gameObject.SetActive(!isGuide);
|
||||
freeButton.gameObject.SetActive(isGuide);
|
||||
btn_diamonds.onClick.AddListener(OnClickDiamonds);
|
||||
advertButton.advBtnGray.onClick.AddListener(ShowToast);
|
||||
btn_diamonds_gray.onClick.AddListener(ShowToast);
|
||||
text_info.text = contnet;
|
||||
}
|
||||
public void SetData(Action onSucceed, Action<bool> startSeedUp, string adContent)
|
||||
{
|
||||
if (onSucceed == null)
|
||||
{
|
||||
advertButton.SetGray();
|
||||
}
|
||||
btn_diamonds.gameObject.SetActive(onSucceed != null);
|
||||
btn_diamonds_gray.gameObject.SetActive(onSucceed == null);
|
||||
OnSucceedCall = onSucceed;
|
||||
StartSeedUp = startSeedUp;
|
||||
text_time.text = adContent;
|
||||
}
|
||||
|
||||
void ShowToast()
|
||||
{
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_60"));
|
||||
}
|
||||
|
||||
void OnClickDiamonds()
|
||||
{
|
||||
if (OnSucceedCall == null)
|
||||
{
|
||||
ShowToast();
|
||||
return;
|
||||
}
|
||||
var curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
||||
int diamondCost = GContext.container.Resolve<Tables>().TbAquariumConfig.AdAccelerateDiamondCost;
|
||||
if (curDiamond >= diamondCost)
|
||||
{
|
||||
GContext.container.Resolve<PlayerData>().AddDiamond(-diamondCost);
|
||||
OnSucceed(false);
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("aquarium_speedup"))
|
||||
{
|
||||
e.AddContent("speedup_type", 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
//_ = UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_59"));
|
||||
}
|
||||
}
|
||||
void GuideAdsSucceed()
|
||||
{
|
||||
OnSucceed(true);
|
||||
}
|
||||
void OnAdsSucceed()
|
||||
{
|
||||
OnSucceed(false);
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("aquarium_speedup"))
|
||||
{
|
||||
e.AddContent("speedup_type", 2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
async void OnSucceed(bool isGuide)
|
||||
{
|
||||
StartSeedUp?.Invoke(isGuide);
|
||||
speedupPopupPanel.SetActive(false);
|
||||
aquariumSpeedupPanel.SetActive(true);
|
||||
await Awaiters.Seconds(2f);
|
||||
OnSucceedCall?.Invoke();
|
||||
await Awaiters.Seconds(0.5f);
|
||||
UIManager.Instance.DestroyUI(UITypes.SpeedupPopupPanel);
|
||||
}
|
||||
void OnClickClose()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.SpeedupPopupPanel);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("AquariumPanel");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user