382 lines
15 KiB
C#
382 lines
15 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using FutureCore;
|
|
using FairyGUI;
|
|
using FGUI.P17_PackAward;
|
|
using DG.Tweening;
|
|
using FGUI.P01_Common;
|
|
using System;
|
|
using Spine.Unity;
|
|
|
|
namespace FlowerPower
|
|
{
|
|
public class PackrewardUI : BaseUI
|
|
{
|
|
private PackrewardUICtrl ctrl;
|
|
private PackrewardModel model;
|
|
private FGUI.P17_PackAward.com_packaward ui;
|
|
private List<Paidgift> list;
|
|
private Action closeCallback;
|
|
|
|
public PackrewardUI(PackrewardUICtrl ctrl) : base(ctrl)
|
|
{
|
|
uiName = UIConst.PackrewardUI;
|
|
this.ctrl = ctrl;
|
|
}
|
|
|
|
protected override void SetUIInfo(UIInfo uiInfo)
|
|
{
|
|
uiInfo.packageName = "P17_PackAward";
|
|
uiInfo.assetName = "com_packaward";
|
|
uiInfo.layerType = UILayerType.Popup;
|
|
uiInfo.isNeedOpenAnim = false;
|
|
uiInfo.isNeedCloseAnim = false;
|
|
uiInfo.isNeedUIMask = false;
|
|
}
|
|
|
|
#region 生命周期
|
|
protected override void OnInit()
|
|
{
|
|
//model = ModuleManager.Instance.GetModel(ModelConst.PackrewardModel) as PackrewardModel;
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
HallManager.Instance.UpdateSecondEvent -= removeAdCountDown;
|
|
AdRdManager.Instance.Destroy();
|
|
GameHelper.showGameUI = true;
|
|
|
|
GameDispatcher.Instance.Dispatch(GameMsg.pack_close);
|
|
int three_gift_got_index = SaveData.GetSaveobject().three_gift_got_index;
|
|
if (isAutoPop && (three_gift_got_index <= (int)rewardState.day3))
|
|
{
|
|
uiCtrlDispatcher.Dispatch(UICtrlMsg.ThreeDaysGiftUI_Open);
|
|
}
|
|
}
|
|
|
|
protected override void OnBind()
|
|
{
|
|
ui = baseUI as FGUI.P17_PackAward.com_packaward;
|
|
}
|
|
private bool isAutoPop = false;
|
|
protected override void OnOpenBefore(object args)
|
|
{
|
|
if (Screen.safeArea.y != 0)
|
|
{//刘海屏
|
|
ui.gold.y += Screen.safeArea.y;
|
|
}
|
|
|
|
bool need_scroll = false;
|
|
PackRewardData Datas = args as PackRewardData;
|
|
if (args != null)
|
|
{
|
|
Datas = args as PackRewardData;
|
|
need_scroll = Datas.isNeedScroll;
|
|
isAutoPop = Datas.isAutoPop;
|
|
}
|
|
if (need_scroll) ui.panel_parent.scrollPane.ScrollDown(200, false);
|
|
if (need_scroll)
|
|
{
|
|
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.remove_ad_show, 1);
|
|
}
|
|
else
|
|
{
|
|
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.pack_show, 1);
|
|
}
|
|
ui.gold.GetChild("text_gold").text = GameHelper.Get101Str(GameHelper.GetGoldNumber());
|
|
|
|
|
|
|
|
list = ConfigSystem.GetConfig<PaidgiftModel>().dataList;
|
|
|
|
if (GameHelper.IsAdModelOfPay())
|
|
{
|
|
|
|
AdRdManager.Instance.SetWatchAd(PurchasingManager.pack_reward, ui.panel_parent.panel.btn_buypack as btn_watchAd, SetTextString1);
|
|
AdRdManager.Instance.SetWatchAd(PurchasingManager.remove_ad, ui.panel_parent.panel.btn_buyremovead as btn_watchAd, SetTextString1);
|
|
}
|
|
|
|
var fx_coin = FXManager.Instance.SetFx<SkeletonAnimation>(ui.gold.GetChild("ani_node") as GGraph, Fx_Type.fx_coin, ref closeCallback);
|
|
fx_coin.state.SetAnimation(0, "animation", true);
|
|
SkeletonAnimation fx_pack = FXManager.Instance.SetFx<SkeletonAnimation>(ui.panel_parent.panel.ani_pack_bg, Fx_Type.fx_pack, ref closeCallback);
|
|
fx_pack.state.SetAnimation(0, "animation", true);
|
|
|
|
InitView();
|
|
|
|
|
|
|
|
}
|
|
|
|
protected override void OnOpen(object args)
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
}
|
|
|
|
protected override void OnDisplay(object args)
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
#region 消息
|
|
protected override void AddListener()
|
|
{
|
|
GameDispatcher.Instance.AddListener(GameMsg.apple_pay_success, pay_success);
|
|
}
|
|
protected override void RemoveListener()
|
|
{
|
|
GameDispatcher.Instance.RemoveListener(GameMsg.apple_pay_success, pay_success);
|
|
}
|
|
#endregion
|
|
|
|
public void removeAdCountDown()
|
|
{
|
|
int cd = SaveData.GetSaveobject().remove_ad_time - Convert.ToInt32(GameHelper.GetNowTime());
|
|
if (cd > 0)
|
|
{
|
|
if (GameHelper.IsAdModelOfPay())
|
|
{
|
|
btn_watchAd btn_buyremovead = ui.panel_parent.panel.btn_buyremovead as btn_watchAd;
|
|
btn_buyremovead.buy_state.selectedIndex = 1;
|
|
if (cd > 24 * 3600)
|
|
{
|
|
btn_buyremovead.title = CommonHelper.TimeFormat(cd, CountDownType.Day, "D");
|
|
}
|
|
else
|
|
{
|
|
btn_buyremovead.title = CommonHelper.TimeFormat(cd, CountDownType.Hour);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (cd > 24 * 3600)
|
|
{
|
|
ui.panel_parent.panel.btn_max_remove.title = CommonHelper.TimeFormat(cd, CountDownType.Day, "D");
|
|
}
|
|
else
|
|
{
|
|
ui.panel_parent.panel.btn_max_remove.title = CommonHelper.TimeFormat(cd, CountDownType.Hour);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HallManager.Instance.UpdateSecondEvent -= removeAdCountDown;
|
|
SaveData.GetSaveobject().is_get_removead = false;
|
|
SaveData.GetSaveobject().remove_ad_time = 0;
|
|
InitView();
|
|
}
|
|
}
|
|
|
|
void pay_success(object str)
|
|
{
|
|
string type = (string)str;
|
|
if (type == PurchasingManager.remove_ad)
|
|
{
|
|
var gold = list[1].coins_quantity;
|
|
var start = GameHelper.GetUICenterPosition(ui.panel_parent.panel.text_goldnum2);
|
|
var end = GameHelper.GetUICenterPosition(ui.gold.GetChild("ani_node"));
|
|
|
|
var rewardData = new RewardData();
|
|
var rewardSingleData = new RewardSingleData(101, gold, RewardOrigin.AdTask)
|
|
{
|
|
startPosition = start,
|
|
endPosition = new Vector2(end.x - 150, end.y - 136),
|
|
};
|
|
rewardData.AddReward(rewardSingleData);
|
|
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
|
|
rewardData.AddCompleted((isScu) =>
|
|
{
|
|
DOVirtual.DelayedCall(0.5f, () =>
|
|
{
|
|
var startNum = PreferencesMgr.Instance.Currency101 - gold;
|
|
DOVirtual.Float((float)startNum, (float)GameHelper.GetGoldNumber(), 1f,
|
|
value => { ui.gold.GetChild("text_gold").text = GameHelper.Get101Str((decimal)value); });
|
|
});
|
|
});
|
|
|
|
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
|
|
|
|
|
|
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.AdcomingUI_Close);
|
|
SaveData.GetSaveobject().is_get_removead = true;
|
|
InitView();
|
|
|
|
|
|
}
|
|
else if (type == PurchasingManager.pack_reward)
|
|
{
|
|
var start = GameHelper.GetUICenterPosition(ui.panel_parent.panel.text_goldnum);
|
|
var end = GameHelper.GetUICenterPosition(ui.gold.GetChild("ani_node"));
|
|
var gold = list[0].coins_quantity;
|
|
|
|
var rewardData = new RewardData();
|
|
var rewardSingleData = new RewardSingleData(101, gold, RewardOrigin.AdTask)
|
|
{
|
|
startPosition = start,
|
|
endPosition = new Vector2(end.x - 150, end.y - 136),
|
|
};
|
|
rewardData.AddReward(rewardSingleData);
|
|
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
|
|
rewardData.AddCompleted((isScu) =>
|
|
{
|
|
DOVirtual.DelayedCall(0.5f, () =>
|
|
{
|
|
var startNum = PreferencesMgr.Instance.Currency101 - gold;
|
|
DOVirtual.Float((float)startNum, (float)GameHelper.GetGoldNumber(), 1f,
|
|
value => { ui.gold.GetChild("text_gold").text = GameHelper.Get101Str((decimal)value); });
|
|
});
|
|
});
|
|
|
|
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
|
|
|
|
|
|
SaveData.GetSaveobject().is_get_packreward = true;
|
|
InitView();
|
|
}
|
|
|
|
|
|
}
|
|
//初始化页面逻辑
|
|
private int gold_num = 300;
|
|
private int back_num = 1;
|
|
private int out_num = 1;
|
|
private int refresh_num = 1;
|
|
private void InitView()
|
|
{
|
|
gold_num = list[0].coins_quantity;
|
|
back_num = list[0].props_quantity[1];
|
|
out_num = list[0].props_quantity[0];
|
|
refresh_num = list[0].props_quantity[2];
|
|
|
|
ui.panel_parent.panel.btn_close0.SetClick(CtrlCloseUI);
|
|
ui.panel_parent.panel.btn_close1.SetClick(CtrlCloseUI);
|
|
ui.panel_parent.panel.text_goldnum.text = "x" + GameHelper.Get101Str(gold_num);
|
|
ui.panel_parent.panel.text_backnum1.text = "x" + back_num;
|
|
ui.panel_parent.panel.text_outnum.text = "x" + out_num;
|
|
ui.panel_parent.panel.text_refreshnum.text = "x" + refresh_num;
|
|
var buy_text = ui.panel_parent.panel.btn_buypack.GetChild("title") as GTextField;
|
|
buy_text.SetVar("price", list[0].Paid_price.ToString()).FlushVars();
|
|
|
|
ui.panel_parent.panel.text_goldnum2.text = "x" + GameHelper.Get101Str(list[1].coins_quantity);
|
|
var buy_text1 = ui.panel_parent.panel.btn_buyremovead.GetChild("title") as GTextField;
|
|
buy_text1.SetVar("price", list[1].Paid_price.ToString()).FlushVars();
|
|
if (GameHelper.IsGiftSwitch()) {
|
|
ui.panel_parent.panel.lab_time.visible = true;
|
|
ui.panel_parent.panel.lab_time.SetVar("num", ConfigSystem.GetConfig<CommonModel>().RemoveADsPackDuration.ToString()).FlushVars();
|
|
}
|
|
else {
|
|
ui.panel_parent.panel.lab_time.visible = false;
|
|
}
|
|
|
|
if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1) (ui.panel_parent.panel.btn_max_pack.GetChild("img_saveingpot") as GImage).visible = true;
|
|
if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1) (ui.panel_parent.panel.btn_max_remove.GetChild("img_saveingpot") as GImage).visible = true;
|
|
if (!GameHelper.IsAdModelOfPay())
|
|
{
|
|
ui.panel_parent.panel.pay_type.selectedIndex = 1;
|
|
decimal price_pack = (decimal)list[0].Paid_price2;
|
|
ui.panel_parent.panel.btn_max_pack.title = GameHelper.getPrice(price_pack);
|
|
bool is_get = SaveData.GetSaveobject().is_get_packreward;
|
|
if (is_get)
|
|
{
|
|
ui.panel_parent.panel.btn_max_pack.enabled = false;
|
|
ui.panel_parent.panel.btn_max_pack.SetClick(() => { });
|
|
}
|
|
else
|
|
{
|
|
|
|
ui.panel_parent.panel.btn_max_pack.SetClick(() =>
|
|
{
|
|
ApplePayClass maxPayData = new ApplePayClass
|
|
{
|
|
amount = (int)Math.Round(price_pack * 100),
|
|
sku = PurchasingManager.pack_reward,
|
|
currency = "USD"
|
|
};
|
|
MaxPayManager.Instance.Buy(maxPayData);
|
|
});
|
|
}
|
|
|
|
decimal price_remove = (decimal)list[1].Paid_price2;
|
|
ui.panel_parent.panel.btn_max_remove.title = GameHelper.getPrice(price_remove);
|
|
bool is_get1 = SaveData.GetSaveobject().is_get_removead;
|
|
if (is_get1)
|
|
{
|
|
ui.panel_parent.panel.btn_max_remove.enabled = false;
|
|
ui.panel_parent.panel.btn_max_remove.SetClick(() => { });
|
|
|
|
HallManager.Instance.UpdateSecondEvent += removeAdCountDown;
|
|
int cd = SaveData.GetSaveobject().remove_ad_time - Convert.ToInt32(GameHelper.GetNowTime());
|
|
if (cd > 24 * 3600)
|
|
{
|
|
ui.panel_parent.panel.btn_max_remove.title = CommonHelper.TimeFormat(cd, CountDownType.Day, "D");
|
|
}
|
|
else
|
|
{
|
|
ui.panel_parent.panel.btn_max_remove.title = CommonHelper.TimeFormat(cd, CountDownType.Hour);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ui.panel_parent.panel.btn_max_remove.SetClick(() =>
|
|
{
|
|
ApplePayClass maxPayData = new ApplePayClass
|
|
{
|
|
amount = (int)Math.Round(price_remove * 100),
|
|
sku = PurchasingManager.remove_ad,
|
|
currency = "USD"
|
|
};
|
|
MaxPayManager.Instance.Buy(maxPayData);
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ui.panel_parent.panel.pay_type.selectedIndex = 0;
|
|
AdRdManager.Instance.Start();
|
|
SetTextString1();
|
|
|
|
bool is_get = SaveData.GetSaveobject().is_get_removead;
|
|
if (is_get)
|
|
{
|
|
btn_watchAd btn_buyremovead = ui.panel_parent.panel.btn_buyremovead as btn_watchAd;
|
|
btn_buyremovead.buy_state.selectedIndex = 1;
|
|
|
|
HallManager.Instance.UpdateSecondEvent += removeAdCountDown;
|
|
int cd = SaveData.GetSaveobject().remove_ad_time - Convert.ToInt32(GameHelper.GetNowTime());
|
|
if (cd > 24 * 3600)
|
|
{
|
|
btn_buyremovead.title = CommonHelper.TimeFormat(cd, CountDownType.Day, "D");
|
|
}
|
|
else
|
|
{
|
|
btn_buyremovead.title = CommonHelper.TimeFormat(cd, CountDownType.Hour);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void SetTextString1()
|
|
{
|
|
var remove_need = AdRdManager.Instance.GetCeilingNeedAds(PurchasingManager.remove_ad);
|
|
var pack_need = AdRdManager.Instance.GetCeilingNeedAds(PurchasingManager.pack_reward);
|
|
var myAd = AdRdManager.Instance.GetLookRewardADNum();
|
|
|
|
ui.panel_parent.panel.ads.SetVar("num", myAd.ToString()).FlushVars();
|
|
ui.panel_parent.panel.tips1.SetVar("num", pack_need.ToString()).FlushVars();
|
|
ui.panel_parent.panel.tips2.SetVar("num", remove_need.ToString()).FlushVars();
|
|
}
|
|
}
|
|
public class PackRewardData
|
|
{
|
|
public bool isAutoPop;
|
|
public bool isNeedScroll;
|
|
}
|
|
} |