using System.Collections; using System.Collections.Generic; using UnityEngine; using FutureCore; using FairyGUI; using FGUI.P18_ShopView; using System; using DG.Tweening; using Newtonsoft.Json; using FGUI.P01_Common; using Spine.Unity; namespace FlowerPower { public class BuygoldUI : BaseUI { private BuygoldUICtrl ctrl; private BuygoldModel model; private FGUI.P18_ShopView.com_buygold ui; private buygoldParam m_param; private Action closeCallback; private bool Isbuysuccess = false; public BuygoldUI(BuygoldUICtrl ctrl) : base(ctrl) { uiName = UIConst.BuygoldUI; this.ctrl = ctrl; } protected override void SetUIInfo(UIInfo uiInfo) { uiInfo.packageName = "P18_ShopView"; uiInfo.assetName = "com_buygold"; uiInfo.layerType = UILayerType.Normal; uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = false; } #region 生命周期 protected override void OnInit() { //model = ModuleManager.Instance.GetModel(ModelConst.BuygoldModel) as BuygoldModel; } protected override void OnClose() { GameHelper.showGameUI = true; HallManager.Instance.UpdateSecondEvent -= initList; HallManager.Instance.UpdateSecondEvent -= upWatchAdsBtn; GameDispatcher.Instance.Dispatch(GameMsg.showBroadCast); if (Isbuysuccess) { GameHelper.ShowTurnOffReward(); } else { GameHelper.ShowPaidPack(); } } protected override void OnBind() { ui = baseUI as FGUI.P18_ShopView.com_buygold; } protected override void OnOpenBefore(object args) { if (Screen.safeArea.y != 0) {//刘海屏 ui.top_gold.y += Screen.safeArea.y - 15; } GameDispatcher.Instance.Dispatch(GameMsg.hideBroadCast); HallManager.Instance.UpdateSecondEvent += initList; HallManager.Instance.UpdateSecondEvent += upWatchAdsBtn; var fx_coin = FXManager.Instance.SetFx(ui.top_gold.GetChild("ani_node") as GGraph, Fx_Type.fx_coin, ref closeCallback); fx_coin.state.SetAnimation(0, "animation", true); PaidgiftList = ConfigSystem.GetConfig().dataList; NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.gold_show, 1); SkeletonAnimation fx_shop = FXManager.Instance.SetFx(ui.ani_node, Fx_Type.fx_shop, ref closeCallback); fx_shop.state.SetAnimation(0, "animation", true); ui.top_gold.GetChild("text_gold").text = GameHelper.Get101Str(GameHelper.GetGoldNumber()); ui.pay_type.selectedIndex = !GameHelper.IsAdModelOfPay() ? 1 : 0; ui.btn_close.SetClick(() => { CtrlCloseUI(); }); } protected override void OnOpen(object args) { ui.visible = false; } 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 void GetAward(decimal gold, int index) { var item = ui.gold_list.GetChildAt(index); var start = GameHelper.GetUICenterPosition(item); var end = GameHelper.GetUICenterPosition(ui.top_gold.GetChild("text_gold")); 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.top_gold.GetChild("text_gold").text = GameHelper.Get101Str((decimal)value); }); }); }); GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData); Isbuysuccess = true; } void pay_success(object str) { string type = (string)str; string purch_number = ""; if (type.StartsWith("buy_gold")) { int startIndex = "buy_gold".Length; string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符 int suffix_num = int.Parse(suffix); SaveData.GetSaveobject()._goldtime[suffix_num] = (int)GameHelper.GetNowTime(); SaveData.saveDataFunc(); GetAward(list[suffix_num].Actual_coins, suffix_num); purch_number = list[suffix_num].Payment_amount2.ToString(); } else if (type == PurchasingManager.pack_reward) { var start = GameHelper.GetUICenterPosition(ui.lab_coin); var end = GameHelper.GetUICenterPosition(ui.top_gold.GetChild("ani_node")); var gold = PaidgiftList[0].coins_quantity; var rewardData = new RewardData(); var rewardSingleData = new RewardSingleData(101, gold, RewardOrigin.AdTask) { startPosition = start, endPosition = end, }; 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.top_gold.GetChild("text_gold").text = GameHelper.Get101Str((decimal)value); }); }); }); GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData); SaveData.GetSaveobject().is_get_packreward = true; Isbuysuccess = true; } updatePack(); if (purch_number != "" && purch_number != "0") { GameHelper.SendRevenueToAF(purch_number); } SetTextString(); } //初始化页面逻辑 private void InitView() { if (m_param.is_in_game) { ui.btn_close.visible = true; } else { ui.btn_close.visible = false; } ui.top_gold.touchable = false; updatePack(); initList(); upWatchAdsBtn(); ui.btn_watch.SetClick(() => { NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.gold_click_ad, 1); GameHelper.ShowVideoAd("BuyGold", (issuccess) => { if (issuccess) { var ad_times = Convert.ToInt32(GameHelper.GetNowTime()); SaveData.GetSaveobject()._watch_ad_cd = ad_times + GameHelper.GetCommonModel().exchangeCD; initList(); updatePack(); ui.btn_watch.enabled = false; ui.btn_watch.can_buy.selectedIndex = 1; ui.btn_watch.btn_text.text = CommonHelper.TimeFormat(SaveData.GetSaveobject()._watch_ad_cd - Convert.ToInt32(GameHelper.GetNowTime()),CountDownType.Hour); } }); }); } //初始化页面逻辑 private List PaidgiftList; private int gold_num = 300; private int back_num = 1; private int out_num = 1; private int refresh_num = 1; private void updatePack() { bool is_get = SaveData.GetSaveobject().is_get_packreward; if (is_get) { ui.group_pack.visible = false; return; } gold_num = PaidgiftList[0].coins_quantity; back_num = PaidgiftList[0].props_quantity[1]; out_num = PaidgiftList[0].props_quantity[0]; refresh_num = PaidgiftList[0].props_quantity[2]; ui.lab_coin.text = "x" + GameHelper.Get101Str(gold_num); ui.lab_undo.text = "x" + back_num; ui.lab_remove.text = "x" + out_num; ui.lab_refresh.text = "x" + refresh_num; if (!GameHelper.IsAdModelOfPay()) { ui.lab_pack_need.visible = false; ui.pay_type.selectedIndex = 1; decimal price_pack = (decimal)PaidgiftList[0].Paid_price2; ui.btn_pack.title = GameHelper.getPrice(price_pack); ui.btn_pack.img_saveingpot.visible = false; if (is_get) { ui.btn_pack.enabled = false; ui.btn_pack.SetClick(() => { }); } else { if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) { ui.btn_pack.img_saveingpot.visible = true; } ui.btn_pack.SetClick(() => { // ApplePayClass maxPayData = new ApplePayClass // { // amount = (int)Math.Round(price_pack * 100), // sku = PurchasingManager.pack_reward, // currency = "USD" // }; ApplePayClass maxPayData = new ApplePayClass() { amount = (int)Math.Round(price_pack * 100), sku = PurchasingManager.pack_reward, currency = "USD" }; MaxPayManager.Instance.Buy(maxPayData); }); } } else { ui.pay_type.selectedIndex = 0; AdRdManager.Instance.Start(); int myAds = AdRdManager.Instance.GetLookRewardADNum(); int pack_reward_ad_count = AdRdManager.Instance.GetCeilingNeedAds(PurchasingManager.pack_reward); ui.lab_pack_need.SetVar("num", pack_reward_ad_count.ToString()).FlushVars(); var pack_need = AdRdManager.Instance.GetCeilingNeedAds(PurchasingManager.pack_reward); ui.btn_pack.title = pack_need + " ADs"; if (is_get) { ui.btn_pack.title = "Redeem"; ui.btn_pack.enabled = false; ui.btn_pack.SetClick(() => { }); } else { if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) { ui.btn_pack.img_saveingpot.visible = true; } if (myAds >= pack_reward_ad_count) { ui.btn_pack.can_buy.selectedIndex = 0; ui.btn_pack.title = "Redeem"; } else { ui.btn_pack.can_buy.selectedIndex = 0; ui.btn_pack.title = myAds + "/" + pack_reward_ad_count; } ui.btn_pack.SetClick(() => { AdRdData test = new AdRdData() { ad_count = pack_reward_ad_count, type = PurchasingManager.pack_reward, }; AdRdManager.Instance.Rd(test); }); } } } private List list = ConfigSystem.GetConfig().dataList; void initList() { ui.gold_list.itemRenderer = setRemaintime; ui.gold_list.numItems = list.Count; SetTextString(); } public void upWatchAdsBtn() { var lastTimes = SaveData.GetSaveobject()._watch_ad_cd; ui.btn_watch.img_saveingpot.visible = false; if (GameHelper.GetNowTime() < lastTimes) { ui.btn_watch.enabled = false; ui.btn_watch.can_buy.selectedIndex = 1; ui.btn_watch.btn_text.text = CommonHelper.TimeFormat(lastTimes - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); } else { ui.btn_watch.enabled = true; ui.btn_watch.can_buy.selectedIndex = 0; if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) ui.btn_watch.img_saveingpot.visible = true; } } public void SetTextString() { var myAds = AdRdManager.Instance.GetLookRewardADNum(); ui.text_my_ads.SetVar("ads", myAds.ToString()).FlushVars(); } void setRemaintime(int index, GObject obj) { buygold_item item = (buygold_item)obj; bool is_paid = list[index].is_paid; int time = 0; time = SaveData.GetSaveobject()._goldtime[index]; item.coin_text.text = GameHelper.Get101Str(list[index].Actual_coins); item.index.selectedIndex = 1;//index > 4 ? 4 : index; item.btn_buy.img_saveingpot.visible = false; if (list[index].Discount_rate != 0) { item.off_text.text = list[index].Discount_rate + "%"; item.discount.visible = true; } else { item.discount.visible = false; } double gold_price1 = list[index].Payment_amount; int needAds = (int)Math.Ceiling(gold_price1); item.text_ads.SetVar("num", needAds.ToString()).FlushVars(); if (time + list[index].receive_CD < GameHelper.GetNowTime()) { if (!is_paid) { item.btn_buy.btn_text.text = "Free"; item.discount.visible = false; item.index.selectedIndex = 0; } else { if (!GameHelper.IsAdModelOfPay()) { decimal price = (decimal)list[index].Payment_amount2; item.btn_buy.btn_text.text = GameHelper.getPrice(price); item.text_ads.visible = false; item.btn_buy.y = 300; } else { int myAds = AdRdManager.Instance.GetLookRewardADNum(); string _type = "buy_gold" + index.ToString(); int count = (int)list[index].Payment_amount;//AdRdManager.Instance.GetCeilingNeedAds(_type); item.btn_buy.btn_text.text = myAds + "/" + count; } if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) item.btn_buy.img_saveingpot.visible = true; } item.btn_buy.can_buy.selectedIndex = 0; item.btn_buy.SetClick(() => { if (!is_paid) { SaveData.GetSaveobject()._goldtime[index] = (int)GameHelper.GetNowTime(); SaveData.saveDataFunc(); GetAward(list[index].Actual_coins, 0); InitView(); } else { rd_Gold(index); } }); } else { if (!GameHelper.IsAdModelOfPay()) { item.text_ads.visible = false; item.btn_buy.y = 300; } item.btn_buy.can_buy.selectedIndex = 1; item.btn_buy.btn_text.text = CommonHelper.TimeFormat(time + list[index].receive_CD - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); item.btn_buy.SetClick(() => { }); } } private void rd_Gold(int index) { // string _type = "buy_gold" + index.ToString(); string _type = getShopName(index); if (GameHelper.IsAdModelOfPay()) { AdRdData test = new AdRdData() { ad_count = AdRdManager.Instance.GetCeilingNeedAds(_type), type = _type, shopName = $"buy_gold{index}" }; AdRdManager.Instance.Rd(test); } else { decimal price = (decimal)list[index].Payment_amount2; ApplePayClass maxPayData = new ApplePayClass() { amount = (int)Math.Round(price * 100), sku = _type, currency = "USD", shopName = $"buy_gold{index}" }; MaxPayManager.Instance.Buy(maxPayData); } } public string getShopName(int index) { string name; // switch(index) // { // case 1: // name = PurchasingManager.buy_gold_1; // break; // case 2: // name = PurchasingManager.buy_gold_2; // break; // case 3: // name = PurchasingManager.buy_gold_3; // break; // case 4: // name = PurchasingManager.buy_gold_4; // break; // case 5: // name = PurchasingManager.buy_gold_5; // break; // default: // return ""; // // } name = list[index].SKU; return name; } public void onShowAnim(object args) { m_param = (buygoldParam)args; if (m_param != null) { ui.visible = true; if (m_param.isShow1) { ui.show1.Play(); } else { ui.show2.Play(); } isHide = true; InitView(); } } private bool isHide = true; public void onHideAnim(object hide) { if (hide != null && isHide) { if ((bool)hide) { ui.hide1.Play(); } else { ui.hide2.Play(); } isHide = false; } } } public class buygoldParam { public bool isShow1 = false; public bool is_in_game = false; } }