328 lines
12 KiB
TypeScript
328 lines
12 KiB
TypeScript
import { _decorator, instantiate, Node, PageView, Prefab, Sprite, tween, UIOpacity, 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';
|
|
import { I_ZhengCangConfig } from '../../Main/Config/CommonConfig';
|
|
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 isShowBigPic: boolean = false; //是否显示大图
|
|
private autoClose: boolean = false; //是否自动关闭
|
|
|
|
/**缩放图片信息 */
|
|
private bigPicInfo = {
|
|
pageItem: null, //翻页item
|
|
npcPic: null, //npc图片
|
|
origScale: Vec3.ZERO, //原始缩放
|
|
}
|
|
|
|
|
|
//----重写父类接口---------------------------------------
|
|
onLoadCT() {
|
|
this.registerListenner();
|
|
Utils.parseNode(this.node, this._nodeTab)
|
|
this._nodeTab.BPMask1.active = false;
|
|
this._nodeTab.labBPTalk.active = false;
|
|
this.npcPageView = this._nodeTab.npcPageView.getComponent(PageView)
|
|
}
|
|
openUIDataCT(data: any): void {
|
|
this._data = data
|
|
}
|
|
|
|
|
|
registerListenner() {
|
|
Utils.addInnerEL(InnerMsgCode.Data_ZhencangUp, this, this.resiveZhencangUp)
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
}
|
|
|
|
/**私家珍藏数据变化消息 */
|
|
resiveZhencangUp(data:any) {
|
|
this.refreshPageList()
|
|
}
|
|
|
|
|
|
/**刷新翻页容器 */
|
|
refreshPageList() {
|
|
let list = GameManager.zhencangCanget
|
|
this._doRefreshWithData(list)
|
|
}
|
|
private _doRefreshWithData(data: any[]) {
|
|
this.rewardList = []
|
|
for (let i = 0; i < data.length; i++) {
|
|
let item = data[i]
|
|
let rcell = GameManager.getZhencangCfg(item.img)
|
|
if (rcell) {
|
|
this.rewardList.push(item)
|
|
}
|
|
}
|
|
if (this.rewardList.length == 0) {
|
|
if (this.isShowBigPic) {
|
|
this.autoClose = true
|
|
return
|
|
}
|
|
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]
|
|
let zhencangCfg: I_ZhengCangConfig = GameManager.getZhencangCfg(rewarddata.img)
|
|
let lvcfg = GameManager.getLevelCfg(zhencangCfg.levelId)
|
|
|
|
//名字
|
|
Utils.setString(pnode.labName, lvcfg.name)
|
|
//简介
|
|
Utils.setString(pnode.labDesc, zhencangCfg.giftSummary)
|
|
|
|
let cgPic: Sprite = pnode.npcPic.getComponent(Sprite)
|
|
//图片
|
|
let picUrl = `${HttpUnit.ZhenCangUrl}${zhencangCfg.giftImgName}.jpg`
|
|
ResManager.I.changeRemoteSpriteFrame(cgPic, picUrl, "jpg")
|
|
|
|
//图片模糊
|
|
ResManager.I.SetBlur(cgPic, true)
|
|
|
|
if (this.targetPicId && this.targetPicId == rewarddata.id) {
|
|
targetPageIdx = i
|
|
}
|
|
|
|
// GButton.RemoveAndBandClick(pnode.npcPic, ()=>{
|
|
// this.changePicScale(pnode);
|
|
// }, this, 0, null, null, false);
|
|
}
|
|
|
|
//按钮状态
|
|
let freecount = HttpUnit.GetZhencangFreeCount()
|
|
let havefree = freecount > 0
|
|
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
|
|
}
|
|
}
|
|
|
|
//region放大图片
|
|
this.isShowBigPic = true
|
|
let pnode:any = this.npcPageView.getPages()[pageIdx]
|
|
let npcPic = pnode.npcPic
|
|
let wpos = new Vec3(0,0,0);
|
|
npcPic.getWorldPosition(wpos);
|
|
let BigPicRoot:Node = this._nodeTab.BigPicRoot;
|
|
let npos = BigPicRoot.getComponent(UITransform).convertToNodeSpaceAR(wpos);
|
|
let npcPicClone = instantiate(npcPic);
|
|
npcPicClone.setParent(BigPicRoot);
|
|
npcPicClone.setPosition(npos);
|
|
ResManager.I.SetBlur(npcPicClone.getComponent(Sprite), false)
|
|
|
|
let ttime = 0.2;
|
|
GameRootUI.DisableOper(ttime+0.1)
|
|
let s = 1
|
|
let windowSize = view.getVisibleSize(); // 获取窗口大小
|
|
let picTf:UITransform = npcPicClone.getComponent(UITransform);
|
|
if (picTf.height < windowSize.height) {
|
|
s = windowSize.height / picTf.height;
|
|
}
|
|
tween((npcPicClone))
|
|
.to(ttime, { scale: new Vec3(s, s, s), position: new Vec3(0, 0, 0) }, { easing: 'quadOut' })
|
|
.call(() => {
|
|
//刷新数据
|
|
GameManager.refreshZhencangCanget()
|
|
})
|
|
.start();
|
|
|
|
//介绍背景
|
|
this._nodeTab.BPMask1.active = true;
|
|
this._nodeTab.BPMask1.setSiblingIndex(10)
|
|
let opaMask = this._nodeTab.BPMask1.getComponent(UIOpacity);
|
|
opaMask.opacity = 0;
|
|
tween(opaMask)
|
|
.to(ttime, { opacity: 255 }, { easing: 'quadOut' })
|
|
.start();
|
|
//介绍文本
|
|
this._nodeTab.labBPTalk.active = true;
|
|
this._nodeTab.labBPTalk.setSiblingIndex(11)
|
|
let zhencangCfg: I_ZhengCangConfig = GameManager.getZhencangCfg(data.img)
|
|
Utils.setString(this._nodeTab.labBPTalk, zhencangCfg.giftSummary)
|
|
let opaTalk = this._nodeTab.labBPTalk.getComponent(UIOpacity);
|
|
opaTalk.opacity = 0;
|
|
tween(opaTalk)
|
|
.to(ttime, { opacity: 255 }, { easing: 'quadOut' })
|
|
.start();
|
|
|
|
GButton.RemoveAndBandClick(npcPicClone, ()=>{
|
|
npcPicClone.destroy();
|
|
this._nodeTab.BPMask1.active = false;
|
|
this._nodeTab.labBPTalk.active = false
|
|
this.isShowBigPic = false;
|
|
if (this.autoClose) {
|
|
this.onClose();
|
|
}
|
|
}, this, 0, null, null, false);
|
|
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
//图片缩放逻辑
|
|
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();
|
|
|
|
}
|
|
}
|
|
|
|
}
|