237 lines
7.9 KiB
Plaintext
237 lines
7.9 KiB
Plaintext
import { _decorator, instantiate, Node, PageView, Prefab, Sprite, tween, UITransform, Vec3, view } from 'cc';
|
|
import { GButton } from '../../Main/Common/GButton';
|
|
import Utils from '../../Main/Common/Utils';
|
|
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
|
|
import li_BaseView from '../../Main/Common/li_BaseView';
|
|
import GameManager from '../../Main/Manager/GameManager';
|
|
import ResManager from '../../Main/Manager/ResManager';
|
|
import GameRootUI from '../../Main/Common/GameRootUI';
|
|
import HttpUnit from '../../Main/Common/HttpUnit';
|
|
import { ViewManager } from '../../Main/Manager/ViewManager';
|
|
import { E_AD_TARGET } from './TalkAdDialog';
|
|
import { SDKManager } from '../../Main/Channel/SDKManager';
|
|
import SubManager from '../SubManager';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
//图鉴奖励界面
|
|
@ccclass('TujianReward_UI')
|
|
export class TujianReward_UI extends li_BaseView {
|
|
|
|
@property(Prefab)
|
|
private rewardPageItem: Prefab = null //角色页签节点
|
|
private npcPageView: PageView = null //可领取角色页签容器
|
|
|
|
private _nodeTab: any = {};
|
|
private _data;
|
|
private rewardList: any[] = []; //可领取的奖励列表
|
|
private targetPicId:number|null = null; //目标图片Id
|
|
|
|
/**缩放图片信息 */
|
|
private bigPicInfo = {
|
|
pageItem: null, //翻页item
|
|
npcPic: null, //npc图片
|
|
origScale: Vec3.ZERO, //原始缩放
|
|
}
|
|
|
|
|
|
//----重写父类接口---------------------------------------
|
|
onLoadCT() {
|
|
this.registerListenner();
|
|
Utils.parseNode(this.node, this._nodeTab)
|
|
|
|
this.npcPageView = this._nodeTab.npcPageView.getComponent(PageView)
|
|
}
|
|
openUIDataCT(data: any): void {
|
|
this._data = data
|
|
}
|
|
|
|
|
|
registerListenner() {
|
|
// Utils.addInnerEL(InnerMsgCode.GM_UI_Close, this, this.resiveGMClose)
|
|
}
|
|
|
|
|
|
start() {
|
|
GButton.BandClick(this._nodeTab.mask, ()=>{
|
|
this.onClose();
|
|
}, this, 0, null, null, false);
|
|
|
|
GButton.BandClick(this._nodeTab.btnCancel, ()=>{
|
|
this.onClose();
|
|
}, this);
|
|
GButton.BandClick(this._nodeTab.btnAD, ()=>{
|
|
ViewManager.I.openBundlesView("UI/StartUI/TalkAdDialog", {
|
|
type: E_AD_TARGET.shoucangJiangli, //收藏奖励
|
|
content: "每日可以免费领取 1 次奖励,更多奖励需要“观看广告”领取",
|
|
adCallback: (isfree:any)=>{
|
|
if (isfree){
|
|
this.doGetReward()
|
|
} else {
|
|
SDKManager.show_reward_video_ad(this.node.uuid, 1)
|
|
}
|
|
},
|
|
shareCallback: ()=>{
|
|
SDKManager.show_reward_share(this.node.uuid, 1)
|
|
}
|
|
})
|
|
}, this);
|
|
GButton.BandClick(this._nodeTab.btnFree, ()=>{
|
|
this.doGetReward();
|
|
}, this);
|
|
|
|
|
|
SDKManager.register_video_reward(this.node.uuid, (tag:number)=>{
|
|
console.log("视频广告回调", tag)
|
|
if (tag == 1) {
|
|
// 加次数
|
|
SubManager.ShowPrompt("观看视频成功")
|
|
this.doGetReward()
|
|
}
|
|
})
|
|
SDKManager.register_share_reward(this.node.uuid, (tag:number)=>{
|
|
console.log("分享回调", tag)
|
|
if (tag == 1) {
|
|
}
|
|
})
|
|
|
|
|
|
this.scheduleOnce(()=>{
|
|
this.refreshPageList()
|
|
}, 0.1)
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
|
|
}
|
|
|
|
/**刷新翻页容器 */
|
|
refreshPageList() {
|
|
HttpUnit.ins.getZhencangList({limit:10, page:1, type:0}, (data) => {
|
|
if (data) {
|
|
let list = data.data || []
|
|
this._doRefreshWithData(list)
|
|
}
|
|
})
|
|
|
|
}
|
|
private _doRefreshWithData(data: any[]) {
|
|
this.rewardList = data
|
|
if (this.rewardList.length == 0) {
|
|
this.onClose();
|
|
return;
|
|
}
|
|
|
|
let wsize = view.getVisibleSize()
|
|
let tempNode = instantiate(this.rewardPageItem)
|
|
let tntf = tempNode.getComponent(UITransform)
|
|
tntf.setContentSize(wsize.width, tntf.height)
|
|
|
|
let targetPageIdx = -1
|
|
this.npcPageView.removeAllPages()
|
|
for (let i=0; i<this.rewardList.length; i++) {
|
|
let pnode: any = instantiate(tempNode)
|
|
this.npcPageView.addPage(pnode)
|
|
Utils.parseNode(pnode)
|
|
let rewarddata = this.rewardList[i]
|
|
if (this.targetPicId && this.targetPicId == rewarddata.id) {
|
|
targetPageIdx = i
|
|
}
|
|
|
|
// GButton.RemoveAndBandClick(pnode.npcPic, ()=>{
|
|
// this.changePicScale(pnode);
|
|
// }, this, 0, null, null, false);
|
|
}
|
|
|
|
//按钮状态
|
|
let havefree = true
|
|
this._nodeTab.btnFree.active = havefree
|
|
this._nodeTab.btnAD.active = !havefree
|
|
|
|
if (targetPageIdx >= 0) {
|
|
this.scheduleOnce(()=>{
|
|
this.npcPageView.scrollToPage(targetPageIdx, 0.5)
|
|
}, 0)
|
|
}
|
|
this.targetPicId = null
|
|
}
|
|
// //翻页容器事件回调
|
|
// guidePageViewEvent(param1, param2) {
|
|
// let pageIdx = this.npcPageView.curPageIdx
|
|
// this.changeLevel(pageIdx+1)
|
|
// }
|
|
|
|
/**获取当前页奖励 */
|
|
doGetReward() {
|
|
let pageIdx = this.npcPageView.curPageIdx
|
|
let data = this.rewardList[pageIdx]
|
|
console.log("当前页奖励:", pageIdx, data)
|
|
HttpUnit.ins.getZhencangReward({id: data.id}, (_data) => {
|
|
if (_data) {
|
|
let targetdata = this.rewardList[pageIdx+1]
|
|
if (targetdata) {
|
|
this.targetPicId = targetdata.id
|
|
} else {
|
|
targetdata = this.rewardList[pageIdx-1]
|
|
if (targetdata) {
|
|
this.targetPicId = targetdata.id
|
|
}
|
|
}
|
|
this.refreshPageList()
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
//region 图片缩放逻辑
|
|
changePicScale(item: any) {
|
|
if (this.bigPicInfo.pageItem) {
|
|
//缩小
|
|
let npcPic = this.bigPicInfo.npcPic
|
|
let wpos = new Vec3(0,0,0);
|
|
this.bigPicInfo.pageItem.picRoot.getWorldPosition(wpos);
|
|
let npos = this._nodeTab.BigPicRoot.getComponent(UITransform).convertToNodeSpaceAR(wpos);
|
|
|
|
let ttime = 0.3;
|
|
GameRootUI.DisableOper(ttime+0.1)
|
|
tween((npcPic))
|
|
.to(ttime, { scale: this.bigPicInfo.origScale, position: npos }, { easing: 'quadOut' })
|
|
.call(() => {
|
|
npcPic.setParent(this.bigPicInfo.pageItem.picRoot);
|
|
npcPic.setPosition(new Vec3(0,0,0));
|
|
this.bigPicInfo.pageItem = null;
|
|
this.bigPicInfo.npcPic = null;
|
|
})
|
|
.start();
|
|
|
|
} else {
|
|
//放大
|
|
let npcPic:Node = item.npcPic;
|
|
this.bigPicInfo.pageItem = item;
|
|
this.bigPicInfo.npcPic = npcPic;
|
|
this.bigPicInfo.origScale = npcPic.scale.clone();
|
|
|
|
let wpos = new Vec3(0,0,0);
|
|
npcPic.getWorldPosition(wpos);
|
|
let BigPicRoot:Node = this._nodeTab.BigPicRoot;
|
|
let npos = BigPicRoot.getComponent(UITransform).convertToNodeSpaceAR(wpos);
|
|
npcPic.setParent(BigPicRoot);
|
|
npcPic.setPosition(npos);
|
|
|
|
let ttime = 0.3;
|
|
GameRootUI.DisableOper(ttime+0.1)
|
|
//放大图片
|
|
let s = 1
|
|
let windowSize = view.getVisibleSize(); // 获取窗口大小
|
|
let picTf:UITransform = npcPic.getComponent(UITransform);
|
|
if (picTf.height < windowSize.height) {
|
|
s = windowSize.height / picTf.height;
|
|
}
|
|
tween((npcPic))
|
|
.to(ttime, { scale: new Vec3(s, s, s), position: new Vec3(0, 0, 0) }, { easing: 'quadOut' })
|
|
.start();
|
|
|
|
}
|
|
}
|
|
|
|
}
|