using System.Collections; using System.Collections.Generic; using UnityEngine; using FairyGUI; using BingoBrain.Core; using BingoBrain; using FGUI.G012_openReward_animal; using FGUI.G003_play_animal; using System; using DG.Tweening; using Newtonsoft.Json; using BingoBrain.HotFix; using DontConfuse; namespace BingoBrain { public class BuygoldUI : BaseUI { private BuygoldUICtrl ctrl; private BuygoldModel model; private FGUI.G012_openReward_animal.com_buygold ui; public BuygoldUI(BuygoldUICtrl ctrl) : base(ctrl) { uiName = UIConst.BuygoldUI; this.ctrl = ctrl; } protected override void SetUIInfo(UIInfo uiInfo) { uiInfo.packageName = "G012_openReward_animal"; uiInfo.assetName = "com_buygold"; uiInfo.layerType = UILayerType.Popup; uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = true; } #region 生命周期 protected override void OnInit() { //model = ModuleManager.Instance.GetModel(ModelConst.BuygoldModel) as BuygoldModel; } protected override void OnClose() { GameHelper.showGameUI = true; Hall.Instance.UpdateSecondEvent -= initList; Hall.Instance.UpdateSecondEvent -= upWatchAdsBtn; WebviewManager.Instance.SetDarkThough(true); } protected override void OnBind() { ui = baseUI as FGUI.G012_openReward_animal.com_buygold; } protected override void OnOpenBefore(object args) { if (Screen.safeArea.y != 0) {//刘海屏 ui.top_gold.y += Screen.safeArea.y - 15; } NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.gold_show, 1); WebviewManager.Instance.SetDarkThough(false); ui.top_gold.GetChild("number_text").text = GameHelper.Get101Str(GameHelper.GetGoldNumber()); ui.pay_type.selectedIndex = !GameHelper.IsAdModelOfPay() ? 1 : 0; InitView(); Hall.Instance.UpdateSecondEvent += initList; Hall.Instance.UpdateSecondEvent += upWatchAdsBtn; } 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 void GetAward(decimal gold, int index) { var item = ui.list.GetChildAt(index); var start = GameHelper.GetUICenterPosition(item); var end = GameHelper.GetUICenterPosition(ui.top_gold.GetChild("number_text")); var rewardData = new RewardData(); var rewardSingleData = new Goda(101, gold, RewardOrigin.BuyGold) { 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("number_text").text = GameHelper.Get101Str((decimal)value); }); }); }); GameDispatcher.Instance.Dispatch(BingoInfo.GetReward, rewardData); } 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_amount.ToString(); } // if (purch_number != "") // { // GameHelper.SendRevenueToAF(purch_number); // } SetTextString(); } //初始化页面逻辑 private void InitView() { ui.top_gold.touchable = false; ui.btn_close.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Close); }); 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().look_ad_time = ad_times + GameHelper.GetCommonModel().exchangeCD; initList(); } }); }); } private List list = ConfigSystem.GetConfig().dataList; void initList() { ui.list.itemRenderer = setRemaintime; ui.list.numItems = list.Count; SetTextString(); } public void upWatchAdsBtn() { var lastTimes = SaveData.GetSaveobject().look_ad_time; 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 = GameHelper.TimeFormat(lastTimes - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); } else { if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) ui.btn_watch.img_saveingpot.visible = true; ui.btn_watch.enabled = true; ui.btn_watch.can_buy.selectedIndex = 0; } } public void SetTextString() { var myAds = SaveData.GetSaveobject().look_ad_numbers; ui.text_have.text = "Owner ADs: " + SaveData.GetSaveobject().look_ad_numbers; } void setRemaintime(int index, GObject obj) { buygold_item item = (buygold_item)obj; int time = 0; time = SaveData.GetSaveobject()._goldtime[index]; item.coin_text.text = GameHelper.Get101Str(list[index].Actual_coins); item.index.selectedIndex = index > 4 ? 4 : index; item.btn_buy.img_saveingpot.visible = false; item.off_text.text = list[index].Discount_rate + "%"; item.discount.visible = !GameHelper.IsAdModelOfPay() && list[index].Discount_rate > 0; item.btn_buy.img_saveingpot.visible = false; if (time + list[index].receive_CD < GameHelper.GetNowTime()) { if (index == 0) { item.btn_buy.btn_text.text = "Free"; item.discount.visible = false; item.btn_buy.y = 331; item.need_text.visible = true; } else { if (!GameHelper.IsAdModelOfPay()) { decimal price = (decimal)list[index].Payment_amount2; item.btn_buy.btn_text.text = GameHelper.Get102Str(price); if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) item.btn_buy.img_saveingpot.visible = true; item.need_text.visible = false; item.btn_buy.y = 364; } else { item.btn_buy.btn_text.text = "Exchange"; double gold_price1 = list[index].Payment_amount; int needAds = (int)Math.Ceiling(gold_price1); item.need_text.SetVar("num", needAds.ToString()).FlushVars(); } } item.btn_buy.can_buy.selectedIndex = 0; item.btn_buy.SetClick(() => { if (index == 0) { SaveData.GetSaveobject()._goldtime[0] = (int)GameHelper.GetNowTime(); SaveData.saveDataFunc(); GetAward(list[index].Actual_coins, 0); InitView(); } else { redeem_Gold(index); } }); } else { item.btn_buy.can_buy.selectedIndex = 1; if (!GameHelper.IsAdModelOfPay()) { item.need_text.visible = false; item.btn_buy.y = 364; } else { double gold_price1 = list[index].Payment_amount; int needAds = (int)Math.Ceiling(gold_price1); item.need_text.SetVar("num", needAds.ToString()).FlushVars(); } item.btn_buy.btn_text.text = GameHelper.TimeFormat(time + list[index].receive_CD - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); item.btn_buy.SetClick(() => { }); } } private void redeem_Gold(int index) { string _type = "buy_gold" + index.ToString(); if (GameHelper.IsAdModelOfPay()) { if (SaveData.GetSaveobject().look_ad_numbers >= list[index].Payment_amount) { ApplePayClass test = new() { sku = _type, }; SaveData.GetSaveobject().look_ad_numbers -= (int)list[index].Payment_amount; PurchasingManager.Instance.Purchase(PurchasingManager.pack_reward, test); string eventName = $"gold_success_{index}"; NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, eventName, 1); } else { GameHelper.ShowTips("Your AD count is insufficient!"); } } else { decimal price = (decimal)list[index].Payment_amount2; MaxPayClass maxPayData = new() { amount = (int)Math.Round(price * 100), sku = _type, currency = "USD" }; MaxPayManager.Instance.Buy(maxPayData); } } } public static partial class GameMsg { private static uint Cursor_BASE = 55555; public static readonly uint OpenGame = ++Cursor_BASE; public static readonly uint Update111Completed = ++Cursor_BASE; public static readonly uint BackMainScene = ++Cursor_BASE; public static readonly uint Update101Completed = ++Cursor_BASE; public static readonly uint Update102Completed = ++Cursor_BASE; public static uint Slot_refresh = ++Cursor_BASE; public static uint Remake_state = ++Cursor_BASE; public static readonly uint MakeupSuccess = ++Cursor_BASE; public static uint Ad_success = ++Cursor_BASE; public static uint UpdateHotFixMax = ++Cursor_BASE; public static uint UpdateHotFixProgress = ++Cursor_BASE; public static readonly uint RefreshTodoUI = ++Cursor_BASE; public static readonly uint RefreshMakeupData = ++Cursor_BASE; public static uint Gold_refresh = ++Cursor_BASE; public static uint Sheep_item_refresh = ++Cursor_BASE; public static uint card_click = ++Cursor_BASE; public static uint RefreshADTask = ++Cursor_BASE; public static readonly uint ProcessReward = ++Cursor_BASE; public static readonly uint Update101 = ++Cursor_BASE; public static readonly uint Update102 = ++Cursor_BASE; public static readonly uint MakeUpConfirmUIClosed = ++Cursor_BASE; public static readonly uint Update111 = ++Cursor_BASE; public static uint reset_game = ++Cursor_BASE; public static uint GetTaskReward = ++Cursor_BASE; public static uint pack_close = ++Cursor_BASE; public static uint RefreshRedDot = ++Cursor_BASE; public static uint resetH5progress = ++Cursor_BASE; public static uint RefreshGame = ++Cursor_BASE; public static uint apple_pay_success = ++Cursor_BASE; public static readonly uint H5ViewClickBtn = ++Cursor_BASE; public static uint hideBroadCast = ++Cursor_BASE; public static uint showBroadCast = ++Cursor_BASE; public static uint backHall = ++Cursor_BASE; public static uint sendLog = ++Cursor_BASE; public static uint checkGameState = ++Cursor_BASE; public static uint Network_reconnection = ++Cursor_BASE; public static uint resurgence = ++Cursor_BASE; public static uint resurgence_close = ++Cursor_BASE; public static uint RefreshSaveingPot = ++Cursor_BASE; public static uint updateRecordList = ++Cursor_BASE; public static uint rewardMul_close = ++Cursor_BASE; public static uint ThreeDaysGiftUIClose = ++Cursor_BASE; } }