using System.Collections; using System.Collections.Generic; using UnityEngine; using BingoBrain.Core; using FairyGUI; using FGUI.SaveingPot; using System; using DontConfuse; using System.Linq; using UnityEngine.PlayerLoop; using Spine.Unity; using DG.Tweening; namespace BingoBrain { public class SaveingPotUI : BaseUI { private SaveingPotUICtrl ctrl; private SaveingPotModel model; private FGUI.SaveingPot.com_saveingpot ui; private SaveingPotClass makeupTaskData; public int ad_cool_down = 120; private int broadtime = 1; public SaveingPotUI(SaveingPotUICtrl ctrl) : base(ctrl) { uiName = UIConst.SaveingPotUI; this.ctrl = ctrl; } protected override void SetUIInfo(UIInfo uiInfo) { uiInfo.packageName = "SaveingPot"; uiInfo.assetName = "com_saveingpot"; uiInfo.layerType = UILayerType.Popup; uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = true; } #region 生命周期 protected override void OnInit() { } protected override void OnClose() { Hall.Instance.UpdateSecondEvent -= updateSpeedCD; closeCallback?.Invoke(); WebviewManager.Instance.SetDarkThough(true); GameDispatcher.Instance.Dispatch(GameMsg.RefreshSaveingPot); } private SkeletonAnimation ske_pot; protected override void OnBind() { ui = baseUI as FGUI.SaveingPot.com_saveingpot; } protected override void OnOpenBefore(object args) { if (Screen.safeArea.y != 0) {//刘海屏 ui.group_.y += Screen.safeArea.y; } UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Close); // ske_pot = FX.Instance.SetFx(ui.ani_potparent, Fx_Type.fx_savepot, closeCallback); // ske_pot.state.SetAnimation(0, "edie", true); FX.Instance.SetFx(ui.ani_potparent, Fx_Type.fx_savepot, sk => { ske_pot = sk; // NAAVsa.AddCompleteEvent(cardSpine, OnChangeCardFinish); // OnChangeCardFinish(null); NAAVsa.PlayAnim(sk, "edie", true); }, closeCallback); WebviewManager.Instance.SetDarkThough(false); SaveingPotHelper.TestingClearTime(); makeupTaskData = SaveData.GetSaveobject().saveingpot_history[SaveData.GetSaveobject().saveingpot_history.Count - 1]; ui.btn_close.SetClick(() => { CtrlCloseUI(); }); ui.btn_close1.SetClick(() => { CtrlCloseUI(); }); InitView(); ui.btn_watch.SetClick(WatchBtnClick); ad_cool_down = ConfigSystem.GetConfig().WithdrawalaccelerationCD; Hall.Instance.UpdateSecondEvent += updateSpeedCD; updateSpeedCD(); InitBroadCast(); } protected override void OnOpen(object args) { } protected override void OnHide() { } protected override void OnDisplay(object args) { } #endregion #region 消息 protected override void AddListener() { } protected override void RemoveListener() { } #endregion private Action closeCallback; //初始化页面逻辑 private void InitView() { Debug.Log(PreferencesMgr.Instance.ExchangeAccount); makeup_2 makeupVo = ConfigSystem.GetConfig().GetData(makeupTaskData.tableId); ui.text_ad.text = "1. Earn " + makeupVo.ADIncrease + " USD for each ad you watch "; ui.text_pay.text = "2. Pay USD for " + makeupVo.PayIncrease + " times cashback."; initTop(); // SaveData.GetSaveobject().saveingpot_cash = 999; //zhushi ui.text_lose.text = string.Format(ui.text_lose.text, SaveingPotHelper.getCashString(SaveData.GetSaveobject().saveingpot_cash)); ske_pot.skeleton.SetColor(new Color(1, 1, 1, 0)); // 设置透明 if (makeupTaskData.needShowAni) { Debug.Log("showani"); ui.type.selectedIndex = 0; ui.text_cashprogress.text = SaveingPotHelper.getCashNumber(SaveData.GetSaveobject().saveingpot_cash) + "/" + SaveingPotHelper.getCashNumber(makeupTaskData.amount); ui.progress_cash.value = (SaveData.GetSaveobject().saveingpot_cash / makeupTaskData.amount) * 100; ske_pot.skeleton.SetColor(new Color(1, 1, 1, 1)); ; if (SaveData.GetSaveobject().saveingpot_cash < makeupTaskData.amount) { ui.btn_cash.title = "Go"; ui.btn_cash.SetClick(() => { CtrlCloseUI(); UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open, false); }); } else { ui.btn_cash.SetClick(() => { makeupTaskData.needShowAni = false; SaveData.saveDataFunc(); InitView(); }); } if (SaveData.GetSaveobject().saveingpot_cash > SaveData.GetSaveobject().last_saveingpot_cash) { DOVirtual.Float(SaveData.GetSaveobject().last_saveingpot_cash, SaveData.GetSaveobject().saveingpot_cash, 1, value => { ui.text_nowcash.text = SaveingPotHelper.getCashString(value); }); // ske_pot.state.SetAnimation(0, "getcash", false); NAAVsa.PlayAnim(ske_pot, "getcash", true); ske_pot.state.Complete += (a) => { NAAVsa.PlayAnim(ske_pot, "edie", true); // ske_pot.state.SetAnimation(0, "edie", true); }; } else ui.text_nowcash.text = SaveingPotHelper.getCashString(SaveData.GetSaveobject().saveingpot_cash); SaveData.GetSaveobject().last_saveingpot_cash = SaveData.GetSaveobject().saveingpot_cash; SaveData.saveDataFunc(); } else if (makeupTaskData.status == SaveingPotTaskStatus.None) { if (PreferencesMgr.Instance.ExchangeAccount == null) { Debug.Log("enter"); OnEnter(); } else { OnConfirm(); } } else if (makeupTaskData.status == SaveingPotTaskStatus.Task) { OnTask(); } else if (makeupTaskData.status == SaveingPotTaskStatus.Inline) { OnInline(); Debug.Log("inline"); } } void WatchBtnClick() { if (GameHelper.GetNowTime() <= PlayerPrefs.GetInt($"speed_ad_cool_times_pot", 0) + ad_cool_down) { Debug.Log("not click"); return; } GameHelper.ShowVideoAd("reward_OpeningDollarBills", isSuccess => { if (isSuccess) { ui.btn_watch.enabled = false; // TimerHelper.mEasy.AddTimer(1.5f, () => // { var ad_times = Convert.ToInt32(GameHelper.GetNowTime()); PlayerPrefs.SetInt($"speed_ad_cool_times_pot", ad_times); InitView(); // }); } }); // var adNum = PreferencesMgr.Instance.RealWatchVideo; // Debug.Log($"adNum========: {adNum}"); } void updateSpeedCD() { broadtime++; BroadCast(); if (makeupTaskData.needShowAni) { ui.text_remaintime.text = GameHelper.TimeFormat((int)makeupTaskData.clear_time - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); } if (SaveingPotHelper.TestingClearTime()) { InitView(); } var lastTimes = PlayerPrefs.GetInt($"speed_ad_cool_times_pot", 0); if (GameHelper.GetNowTime() < lastTimes + ad_cool_down) { ui.btn_watch.enabled = false; ui.btn_watch.show_cd.selectedIndex = 1; ui.btn_watch.text_cd.text = GameHelper.TimeFormat( lastTimes + ad_cool_down - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); } else { ui.btn_watch.enabled = true; ui.btn_watch.show_cd.selectedIndex = 0; } } private void OnInline() { CheckBtnWatchStatus(); ui.type.selectedIndex = 5; CheckActive(makeupTaskData.tableId); GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData); RefreshRecordData(); } private void RefreshRecordData() { var data = makeupTaskData; if (data.inlineNum <= 1) { ui.type.selectedIndex = 6; ui.text_payhint.text = "You will get the " + makeupTaskData.amountStr + " for 90 days"; ui.text_query.text = PreferencesMgr.Instance.ExchangeAccount; ui.btn_confirm.SetClick(() => { CtrlCloseUI(); }); return; } var com_rank = ui.com_newRecord.com_rank; var com_cord = ui.com_newRecord.com_cord; com_cord.email_text.text = PreferencesMgr.Instance.ExchangeAccount; var redeemVOModel = ConfigSystem.GetConfig().dataList .FirstOrDefault(redeem => redeem.id == data.tableId); if (redeemVOModel == null) return; if (redeemVOModel.AD_Limit_times <= data.WatchVideoSpeedNum) { ui.btn_watch.enabled = false; ui.btn_watch.visible = false; com_rank.content1.selectedIndex = 1; com_rank.text_rank1.SetVar("rank", data.WatchVideoSpeedNum.ToString()).FlushVars(); } else { ui.btn_watch.enabled = true; ui.btn_watch.visible = true; com_rank.content1.selectedIndex = 0; com_rank.text_rank1.SetVar("rank", redeemVOModel.AD_Down.ToString()).FlushVars(); } if (redeemVOModel.Login_Limit_times <= data.loginSpeedNum) { com_rank.content2.selectedIndex = 1; com_rank.text_rank2.SetVar("rank", redeemVOModel.Login_Limit_times.ToString()).FlushVars(); } else { com_rank.content2.selectedIndex = 0; var loginRans = GameHelper.GetCommonModel().inlineLoginDown[0] + "-" + GameHelper.GetCommonModel().inlineLoginDown[1]; com_rank.text_rank2.SetVar("rank", loginRans).FlushVars(); } if (redeemVOModel.Active_Limit_times <= data.activeSpeedNum) { com_rank.content3.selectedIndex = 1; com_rank.text_rank3.SetVar("rank", redeemVOModel.Active_Limit_times.ToString()).FlushVars(); } else { com_rank.content3.selectedIndex = 0; com_rank.text_rank3.SetVar("time", redeemVOModel.Active_time.ToString()).FlushVars(); com_rank.text_rank3.SetVar("rank", redeemVOModel.Active_time_Down.ToString()).FlushVars(); if (GameHelper.activeTimes_saveingpot.TryGetValue(data.tableId, out int openTimes)) { //Debug.Log($"openTimes ===== {openTimes}, data.tableId=== activeTimes_saveingpot_{data.tableId}"); if (openTimes > 1) { //活跃的分钟数 int min_num = ((int)Time.time - data.activeMinute) / 60; //是配置的活跃时间的多少倍 int active_times = min_num / redeemVOModel.Active_time; //Debug.Log($"min_num=== {min_num} {active_times} "); if (active_times > 0) { data.activeMinute = (int)Time.time; // 可以加速多少排名 int rank_num = active_times * redeemVOModel.Active_time_Down; var last = data.activeSpeedNum; data.activeSpeedNum += rank_num; //Debug.Log($"rank_num=== {rank_num} {last} {data.activeSpeedNum} {redeemVOModel.Active_Limit_times}"); if (data.activeSpeedNum > redeemVOModel.Active_Limit_times) { rank_num = redeemVOModel.Active_Limit_times - last; data.activeSpeedNum = redeemVOModel.Active_Limit_times; } data.inlineNum -= rank_num; //Debug.Log($"订单为: {data.tableId} 通过活跃时间减少的排名为:{rank_num}"); if (data.inlineNum < GameHelper.GetCommonModel().inlineMin) { data.inlineNum = GameHelper.GetCommonModel().inlineMin; } } } else { data.activeMinute = (int)Time.time; } } } com_cord.text_amt.text = $"+{data.amountStr}"; if (data.order_time != 0) { com_cord.time_text.text = DateTimeBoardk.Instance.TimestampToString(data.order_time); } com_rank.text_ranks.text = data.inlineNum.ToString(); com_cord.number_text.text = data.inlineNum + "/" + data.inlineInitNum; } private void CheckActive(int index) { if (GameHelper.activeTimes_saveingpot.TryGetValue(index, out int value)) { value++; // Debug.Log($"CheckActive2: {index} {value}"); GameHelper.activeTimes_saveingpot[index] = value; } else { GameHelper.activeTimes_saveingpot.Add(index, 1); } } void CheckBtnWatchStatus() { var data = makeupTaskData; if (data == null) { return; } var CardRedeemVOModel = ConfigSystem.GetConfig().dataList .FirstOrDefault(redeem => redeem.id == data.tableId); if (CardRedeemVOModel == null) return; bool isShow = CardRedeemVOModel.AD_Limit_times > data.WatchVideoSpeedNum && data.inlineNum > GameHelper.GetCommonModel().inlineMin; ui.btn_watch.enabled = isShow; } private void OnConfirm() { ui.type.selectedIndex = 3; makeup_2 vo = ConfigSystem.GetConfig().GetData(makeupTaskData.tableId); if (vo == null) { return; } // ui.text_condi1.SetVar("cash", GameHelper.Get102Str(vo.item_need)).FlushVars(); // ui.pb_condi1.max = vo.item_need; // var curValue = Math.Min(PreferencesMgr.Instance.Currency102, vo.item_need); // ui.pb_condi1.value = (double)curValue; // ui.pay_text1.text = // String.Format("Pague [color=#18a218][size=44]R${0}[/size][/color] para pular anúncios", // (ConfigSystem.GetConfig().purchase1 + ",00")); // var textTitle = ui.pb_condi1.GetChild("title"); // if (textTitle != null) // { // textTitle.text = "$" + GameHelper.Get102Str(curValue) + "/" + "$" + GameHelper.Get102Str(vo.item_need); // } var taskTime = (int)((float)vo.task_need / 60 * 100) * 0.01F; var completeTaskTime = (int)((float)makeupTaskData.H5Time / 60 * 100) * 0.01F; var completeTaskValue = Math.Min(completeTaskTime, taskTime); ui.text_condi2.text = taskTime.ToString(); ui.pb_condi2.max = taskTime; ui.pb_condi2.value = completeTaskValue; ui.pb_condi2.title.text = $"{completeTaskValue}/{taskTime}"; // if (PreferencesMgr.Instance.MakeupTaskH5Time < vo.task_need && AppConst.isPt()) // { // ui.show_pay.selectedIndex = com_confirm.Show_pay_true; // } // else ui.show_pay.selectedIndex = com_confirm.Show_pay_false; //ui.text_wallet.SetVar("Payer", "$").FlushVars(); // if (AppConst.isPt()) ui.text_wallet.text = "Pix"; ui.text_cash.text = makeupTaskData.GetAmountStr(); ui.text_account.text = PreferencesMgr.Instance.ExchangeAccount; if (completeTaskTime >= taskTime) { ui.cont_confirm.selectedIndex = 0; ui.btn_confirm.SetClick(() => { Audio.Instance.PlayDynamicEffect("makupdone"); makeupTaskData.SetStatus(SaveingPotTaskStatus.Task); // PreferencesMgr.Instance.SaveMakeupTaskHistory(); OnTask(); }); } else { ui.cont_confirm.selectedIndex = 1; ui.btn_confirm.SetClick(() => { Audio.Instance.PlayDynamicEffect("makupdone"); UICtrlDispatcher.Instance.Dispatch(SkinInfo.H5UI_Open); //GameDispatcher.Instance.Dispatch(GameMsg.MainTab, 1); CtrlCloseUI(); WebviewManager.Instance.SetDarkThough(true); }); } } private void OnTask() { var vo = ConfigSystem.GetConfig().GetData(makeupTaskData.tableId); if (vo == null) { return; } // makeupTaskData.videoCount = 10;//zhushi ui.type.selectedIndex = 4; ui.com_task.text_orderid.text = makeupTaskData.orderID; ui.com_task.text_task_title.SetVar("ad", vo.ad_need.ToString()).FlushVars(); ui.com_task.text_ads.text = $"{makeupTaskData.videoCount}/{vo.ad_need}"; //if (AppConst.isPt() && makeupTaskData.videoCount < vo.ad_need) ui.com_task.lang.selectedIndex = com_task.Lang_pt; //else ui.com_task.lang.selectedIndex = com_task.Lang_en; // ui.com_task.pay_text1.text = String.Format("Pague [color=#18a218][size=44]R${0}[/size][/color] para pular anúncios", // (ConfigSystem.GetConfig().purchase2 + ",00")); ui.com_task.text_payer.SetVar("amt", makeupTaskData.GetAmountStr()).FlushVars(); if (makeupTaskData.videoCount >= vo.ad_need) { ui.com_task.cont_process.selectedIndex = 1; } else ui.com_task.cont_process.selectedIndex = 0; ui.btn_confirm.SetClick(() => { if (makeupTaskData.videoCount >= vo.ad_need) { GameHelper.ShowLoading(1, 2, () => { TuSystem.Consume(vo.item, vo.item_need, isSuccess => { makeupTaskData.SetStatus(SaveingPotTaskStatus.Inline); makeupTaskData.inlineInitNum = UnityEngine.Random.Range(ConfigSystem.GetConfig().inlineInitNum[0], ConfigSystem.GetConfig().inlineInitNum[1]); makeupTaskData.inlineNum = UnityEngine.Random.Range( ConfigSystem.GetConfig().inlineInitNum[0], makeupTaskData.inlineInitNum); makeupTaskData.order_time = GameHelper.GetNowTime(); // PreferencesMgr.Instance.SaveMakeupTaskHistory(); //OnInline(); SaveData.GetSaveobject().saveingpot_cash -= vo.item_need; SaveingPotHelper.CreatSaveingPotItem(); // Debug.Log(JsonConvert.SerializeObject(vo)); if (vo.id == 1) { NetworkKit.BuriedPoint(BuriedPointEvent.withdraw_behavior, BuriedPointEvent.withdraw_cash1, 1); } else if (vo.id == 2) { NetworkKit.BuriedPoint(BuriedPointEvent.withdraw_behavior, BuriedPointEvent.withdraw_cash2, 1); } else if (vo.id == 3) { NetworkKit.BuriedPoint(BuriedPointEvent.withdraw_behavior, BuriedPointEvent.withdraw_cash3, 1); } if (vo.id != 3) { // cash_index++; } InitView(); if (vo.id == 3) { // PlayerPrefs.SetInt("cash_lv", 2); makeupTaskData = SaveData.GetSaveobject().saveingpot_history.Last(); } }); }); } else { CtrlCloseUI(); UICtrlDispatcher.Instance.Dispatch(SkinInfo.H5UI_Open); // MainTabUI.getIns().OnGameTab(1); } }); } private void OnEnter() { GTextInput enter_input = null; enter_input = ui.com_info.enter_email; ui.type.selectedIndex = 1; ui.btn_confirm.SetClick(() => { var account = enter_input.text.Replace(" ", ""); if (account == null || account == "") { GameHelper.ShowTips("Please enter the correct account information1", true); return; } if (!GameHelper.CheckAccountValidly(account)) { GameHelper.ShowTips("Please enter the correct account information2", true); return; } var fname = ui.com_fname.enter_fname.text.Replace(" ", ""); if (!GameHelper.CheckNameValidly(fname)) { GameHelper.ShowTips("Please enter the correct account information3", true); return; } var lname = ui.com_lname.enter_fname_1.text.Replace(" ", ""); if (!GameHelper.CheckNameValidly(lname)) { GameHelper.ShowTips("Please enter the correct account information4", true); return; } PreferencesMgr.Instance.ExchangeAccount = account; PreferencesMgr.Instance.ExchangeName = $"{fname} {lname}"; PreferencesMgr.Instance.short_name = fname; PreferencesMgr.Instance.long_name = lname; showPaypal(); //uiCtrlDispatcher.Dispatch(UICtrlMsg.MakeupStepUI_Open, makeupTaskData); //CtrlCloseUI(); }); } void showPaypal() { ui.type.selectedIndex = 2; if (makeupTaskData == null) { return; } ui.com_pay.text_name.text = PreferencesMgr.Instance.ExchangeName; ui.com_pay.text_email.text = PreferencesMgr.Instance.ExchangeAccount; ui.com_pay.btn_change.SetClick(() => { PreferencesMgr.Instance.ExchangeName = null; PreferencesMgr.Instance.ExchangeAccount = null; OnEnter(); }); GameHelper.SetSelfAvatar(ui.com_pay.load_avatar); ui.btn_confirm.SetClick(() => { var info = new { email = PreferencesMgr.Instance.ExchangeAccount, first_name = PreferencesMgr.Instance.short_name, last_name = PreferencesMgr.Instance.long_name }; NetworkKit.PostWithHeader("shop/payOutUserInfo", info, (isSuccess, obj) => { if (isSuccess) { } }); NetworkKit.BuriedPoint(BuriedPointEvent.withdraw_behavior, BuriedPointEvent.withdraw_message, 1); InitView(); }); } public int now_selectindex; void initTop() { // Debug.Log(JsonConvert.SerializeObject(PreferencesMgr.Instance.MakeupTaskHistory)); List btn_list = new List() { ui.btn_level0, ui.btn_level1, ui.btn_level2 }; List makeup_list = ConfigSystem.GetConfig().dataList; now_selectindex = makeupTaskData.tableId - 1; List saveingpot_history = SaveData.GetSaveobject().saveingpot_history; for (int i = 0; i < btn_list.Count; i++) { btn_list[i].text_cash.text = "$" + makeup_list[i].item_need; Debug.Log(makeup_list[i].item_need); btn_list[i].index.selectedIndex = i; if (i >= saveingpot_history.Count) { btn_list[i].btn_state.selectedIndex = 2; btn_list[i].text_type.grayed = true; btn_list[i].text_cash.grayed = true; } else if (saveingpot_history.Count > i + 1 || ((saveingpot_history.Count == 3) && (saveingpot_history[2].status == SaveingPotTaskStatus.Inline))) { btn_list[i].btn_state.selectedIndex = 0; } else { btn_list[i].btn_state.selectedIndex = 1; } if (i == now_selectindex) { btn_list[i].img_outline.visible = true; } else if (i >= saveingpot_history.Count) { btn_list[i].img_outline.visible = false; btn_list[i].SetClick(() => { GameHelper.ShowTips("To be unlocked"); }); } else { btn_list[i].img_outline.visible = false; int index = i; btn_list[i].SetClick(() => { for (int j = saveingpot_history.Count - 1; j >= 0; j--) { Debug.Log(saveingpot_history[j].tableId); Debug.Log(index + 1); Debug.Log(saveingpot_history[j].tableId == index + 1); if (saveingpot_history[j].tableId == index + 1) { makeupTaskData = saveingpot_history[j]; now_selectindex = index; break; } } InitView(); }); } } } private List config_name_list = exBrPoolModel_2.config_name_list; private List config_money_list = exBrPoolModel.config_money_list; private List broad_list = new List(); private void BroadCast() { if (broadtime % 3 == 0) { ui.broad.t1.Play(() => { broad_list.RemoveAt(0); int name_index = UnityEngine.Random.Range(0, config_name_list.Count); int money_index = UnityEngine.Random.Range(0, config_money_list.Count); broad_list.Add(new string[2] { config_name_list[name_index], config_money_list[money_index] }); for (int i = 0; i < 4; i++) { text_list[i].text = "congratulations,[color=#ad4800][size=36] " + broad_list[i][0] + " [/size][/color]Successful exchange[color=#ad4800]$" + broad_list[i][1] + "[/color]"; } }); } } private List text_list = new List(); private void InitBroadCast() { text_list.Add(ui.broad.text_0); text_list.Add(ui.broad.text_1); text_list.Add(ui.broad.text_2); text_list.Add(ui.broad.text_3); for (int i = 0; i < 4; i++) { int name_index = UnityEngine.Random.Range(0, config_name_list.Count); int money_index = UnityEngine.Random.Range(0, config_money_list.Count); broad_list.Add(new string[2] { config_name_list[name_index], config_money_list[money_index] }); text_list[i].text = "congratulations,[color=#ad4800][size=36] " + broad_list[i][0] + " [/size][/color]Successful exchange[color=#ad4800]$" + broad_list[i][1] + "[/color]"; } } } }