123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { _decorator, Component, Label, Node, Sprite, Animation, SpriteFrame } from 'cc';
- import { base_ui } from '../../fw/base_ui';
- import { sign_reward_data, sign_total_reward_data } from '../../data';
- import { tools } from '../../tools';
- import { http } from '../../http';
- import { config } from '../../config';
- import { GameManager } from '../../GameManager';
- import { uiManager } from '../../manager/uiManager';
- const { ccclass, property } = _decorator;
- @ccclass('sign_receive_reward')
- export class sign_receive_reward extends base_ui {
- @property(Node) public_bg:Node = null
- @property(Node) img_title:Node = null
- @property(Node) img_icon:Node = null
- @property(Node) lab_name:Node = null
- @property(Node) lab_count:Node = null
- @property(Node) node_btn:Node = null
- @property(Node) btn_receive:Node = null
- @property(Node) btn_double:Node = null
- @property(Node) public_close_text:Node = null
- @property(SpriteFrame) sf_dangrihuode = null
- @property(SpriteFrame) sf_gongxihuode = null
- private m_reward_data:sign_reward_data = null
- private m_is_buqian:boolean = false
- private m_cb = null
- start() {
- this.onButtonListen(this.public_bg, ()=>{
- if(this.m_is_buqian==true) { return }
- this.closeSelf()
- })
- this.onButtonListen(this.btn_receive, ()=>{
- this.requestUserSign(false)
- })
-
- this.onButtonListen(this.btn_double, ()=>{
- GameManager.showVideoAd(config.ADS_TYPE.GAME_SIGN_DOUBLE, (res)=>{
- this.requestUserSign(true)
- })
- })
- }
- initView(data:sign_reward_data, is_buqian:boolean, cb) {
- this.m_reward_data = data
- this.m_cb = cb
- this.m_is_buqian = is_buqian
- if(this.m_is_buqian==true) {
- this.public_close_text.active = false
- }
- this.img_title.getComponent(Sprite).spriteFrame = this.sf_dangrihuode
- this.showNodeBtn(true)
- tools.loadRemoteImg(data.icon, (d)=>{
- this.img_icon.getComponent(Sprite).spriteFrame = d.sf
- })
- this.lab_name.getComponent(Label).string = data.name
- this.setLabCount(data.quantity)
- }
- initReceiveSuccess(data:sign_total_reward_data) {
- this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
- this.showNodeBtn(false)
- tools.loadRemoteImg(data.icon, (d)=>{
- this.img_icon.getComponent(Sprite).spriteFrame = d.sf
- })
- this.lab_name.getComponent(Label).string = data.name
- this.setLabCount(data.quantity)
- }
- private setLabCount(count:number) {
- this.lab_count.getComponent(Label).string = `x${count}`
- }
- private showRewardDetails(is_double:boolean) {
- this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
- this.showNodeBtn(false)
- if(is_double) {
- let count = this.m_reward_data.quantity * 2
- this.setLabCount(count)
- }
- if(this.m_is_buqian==true) {
- this.public_close_text.active = true
- this.m_is_buqian = false
- }
- }
- private showNodeBtn(is_show:boolean) {
- if(is_show) {
- this.node_btn.active = true
- this.btn_double.getComponent(Animation).play()
- } else {
- this.node_btn.active = false
- this.btn_double.getComponent(Animation).stop()
- }
- }
- private closeSelf() {
- this.showNodeBtn(false)
- this.node.active = false
- }
- private requestUserSign(is_double:boolean) {
- let stype = 1
- if(is_double) {
- stype = 2
- }
- uiManager.Instance().showLoading()
- let opt = {'index':this.m_reward_data.index, 'stype': stype}
- http.post(config.API.user_sign, opt, (err,d)=>{
- uiManager.Instance().hideLoading()
- if(!err){
- let nd = JSON.parse(d)
- if(nd.code === config.status.SUCCESS){
- // console.log("user_sign", nd.content)
- this.showRewardDetails(is_double)
- this.m_cb && this.m_cb(this)
- }
- }
- })
- }
- }
|