232 lines
7.0 KiB
C#
232 lines
7.0 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Numerics;
|
||
|
|
using DG.Tweening;
|
||
|
|
using FairyGUI;
|
||
|
|
using FGUI.P01_Common;
|
||
|
|
using FGUI.rank;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace FlowerPower
|
||
|
|
{
|
||
|
|
public class RankRewardUI : BaseUI
|
||
|
|
{
|
||
|
|
private RankRewardUICtrl ctrl;
|
||
|
|
private RankRewardModel model;
|
||
|
|
private FGUI.rank.com_rank_reward ui;
|
||
|
|
|
||
|
|
public btn_watchAd btn_WatchAd;
|
||
|
|
|
||
|
|
List<RankRewardData> rewardList = new List<RankRewardData>();
|
||
|
|
rankType curType = rankType.hour;
|
||
|
|
int selfRank = 0;
|
||
|
|
|
||
|
|
public RankRewardUI(RankRewardUICtrl ctrl) : base(ctrl)
|
||
|
|
{
|
||
|
|
uiName = UIConst.RankRewardUI;
|
||
|
|
this.ctrl = ctrl;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
protected override void SetUIInfo(UIInfo uiInfo)
|
||
|
|
{
|
||
|
|
uiInfo.packageName = "rank";
|
||
|
|
uiInfo.assetName = "com_rank_reward";
|
||
|
|
uiInfo.layerType = UILayerType.Popup;
|
||
|
|
uiInfo.isNeedOpenAnim = false;
|
||
|
|
uiInfo.isNeedCloseAnim = false;
|
||
|
|
uiInfo.isNeedUIMask = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
#region 生命周期
|
||
|
|
protected override void OnInit()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void OnClose()
|
||
|
|
{
|
||
|
|
AdRdManager.Instance.Destroy();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void OnBind()
|
||
|
|
{
|
||
|
|
ui = baseUI as FGUI.rank.com_rank_reward;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void OnOpenBefore(object args)
|
||
|
|
{
|
||
|
|
if (Screen.safeArea.y != 0)
|
||
|
|
{
|
||
|
|
ui.group_top.y += 68;
|
||
|
|
}
|
||
|
|
rewardList = SaveLocalData.GetSaveLocalObject().rankRewardData;
|
||
|
|
|
||
|
|
if (ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1)
|
||
|
|
{
|
||
|
|
ui.mode.selectedIndex = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ui.mode.selectedIndex = 1;
|
||
|
|
}
|
||
|
|
InitView();
|
||
|
|
}
|
||
|
|
|
||
|
|
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 void InitView()
|
||
|
|
{
|
||
|
|
ui.btn_close.SetClick(() => {
|
||
|
|
GameHelper.addInterAdnumber();
|
||
|
|
CtrlCloseUI();
|
||
|
|
});
|
||
|
|
|
||
|
|
ui.lab_pot.text = $"{SaveData.GetSaveobject().saveingpot_ch:N}";
|
||
|
|
var head = ui.head_1 as btn_head;
|
||
|
|
GameHelper.SetSelfAvatar(head.load_avatar);
|
||
|
|
head = ui.head_2 as btn_head;
|
||
|
|
TextureHelper.SetAvatarToLoader(2, head.load_avatar);
|
||
|
|
head = ui.head_3 as btn_head;
|
||
|
|
TextureHelper.SetAvatarToLoader(3, head.load_avatar);
|
||
|
|
|
||
|
|
ui.list_rank.itemRenderer = refreshItem;
|
||
|
|
ui.list_rank.numItems = rewardList.Count;
|
||
|
|
|
||
|
|
float rewardNum = 0;
|
||
|
|
for (int i = 0; i < rewardList.Count; i++) {
|
||
|
|
rewardNum += rewardList[i].bonus;
|
||
|
|
}
|
||
|
|
|
||
|
|
ui.lab_total.text = rewardNum.ToString();
|
||
|
|
|
||
|
|
if (ui.btn_collect.img_saveingpot != null && GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1)
|
||
|
|
{
|
||
|
|
ui.btn_collect.img_saveingpot.visible = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
ui.btn_collect.SetClick(() => {
|
||
|
|
|
||
|
|
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_AD_event, BuriedPointEvent.gold_click_ad,1);
|
||
|
|
|
||
|
|
GameHelper.ShowVideoAd("CollectRankReward", (issuccess) =>
|
||
|
|
{
|
||
|
|
if (issuccess)
|
||
|
|
{
|
||
|
|
DOVirtual.DelayedCall(0.01f, () =>
|
||
|
|
{
|
||
|
|
SaveData.GetSaveobject().saveingpot_ch += rewardNum;
|
||
|
|
GetReward(rewardNum);
|
||
|
|
|
||
|
|
SaveLocalData.GetSaveLocalObject().rankRewardData.Clear();
|
||
|
|
SaveLocalData.saveLocalDataFunc();
|
||
|
|
GameDispatcher.Instance.Dispatch(GameMsg.RefreshRedDot);
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private void refreshItem(int index, GObject obj)
|
||
|
|
{
|
||
|
|
if (rewardList.Count <= index)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
rank_item2 item = (rank_item2)obj;
|
||
|
|
item.lab_ranking.text = rewardList[index].rank.ToString();
|
||
|
|
|
||
|
|
// DateTime utcTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(rewardList[index].time);
|
||
|
|
// DateTime LocalTime = utcTime.ToLocalTime();
|
||
|
|
|
||
|
|
|
||
|
|
if (rankType.hour == rewardList[index].type)
|
||
|
|
{
|
||
|
|
item.lab_type.text = "Hour";
|
||
|
|
}
|
||
|
|
else if (rankType.day == rewardList[index].type)
|
||
|
|
{
|
||
|
|
item.lab_type.text = "Day";
|
||
|
|
}
|
||
|
|
else if (rankType.week == rewardList[index].type)
|
||
|
|
{
|
||
|
|
item.lab_type.text = "Week";
|
||
|
|
}
|
||
|
|
item.lab_pot.text = rewardList[index].bonus.ToString();
|
||
|
|
item.lab_time.text = rewardList[index].time;
|
||
|
|
// item.lab_time.text = LocalTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
|
|
||
|
|
if (ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1)
|
||
|
|
{
|
||
|
|
item.mode.selectedIndex = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
item.mode.selectedIndex = 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void GetReward(float awardNum)
|
||
|
|
{
|
||
|
|
var rewardData = new RewardData();
|
||
|
|
|
||
|
|
int curr_type = 112;
|
||
|
|
if (ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 0)
|
||
|
|
{
|
||
|
|
curr_type = 101;
|
||
|
|
}
|
||
|
|
var end_ = GameHelper.GetUICenterPosition(ui.lab_pot, true);
|
||
|
|
|
||
|
|
var rewardSingleData = new RewardSingleData(curr_type, (decimal)awardNum, RewardOrigin.Play)
|
||
|
|
{
|
||
|
|
startPosition = GameHelper.GetUICenterPosition(ui.btn_collect, true),
|
||
|
|
endPosition = new UnityEngine.Vector2(end_.x - 110, end_.y - 110),
|
||
|
|
};
|
||
|
|
|
||
|
|
rewardData.AddReward(rewardSingleData);
|
||
|
|
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
|
||
|
|
rewardData.AddCompleted(success =>
|
||
|
|
{
|
||
|
|
if (success)
|
||
|
|
{
|
||
|
|
// PreferencesMgr.Instance.Currency102 -= (decimal)awardNum;
|
||
|
|
GameDispatcher.Instance.Dispatch(GameMsg.Update102);
|
||
|
|
DOVirtual.DelayedCall(0.7f, () =>
|
||
|
|
{
|
||
|
|
CtrlCloseUI();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
|
||
|
|
DOVirtual.DelayedCall(1, () =>
|
||
|
|
{
|
||
|
|
DOVirtual.Float(0, SaveData.GetSaveobject().saveingpot_ch, 1,
|
||
|
|
value => { ui.lab_pot.text = ((decimal)value).ToString("0.00"); });
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|