Spring774
2025-10-30 4d84b498fbb08b9f177b5d9a39e2fedd0522f16f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Global from "./Global";
import Userdata from "./Userdata";
import SoundManager from "./SoundManager";
import { Sdk } from "./Sdk/Sdk";
import { SdkToutiao } from "./Sdk/SdkToutiao";
import Game from "./Game";
 
const { ccclass, property } = cc._decorator;
 
@ccclass
export default class RewardLayer extends cc.Component {
    // @property(cc.Label)
    // buttonNameLabel: cc.Label = null;
 
    isAds: boolean = false;
    isGot: boolean = false;
    eventNode: cc.Node = null;
 
    onClickClose() {
        SoundManager.playButton();
        this.cliamReward(1);
        this.hide();
    }
 
    hide() {
        this.node.destroy();
    }
 
    onDisable(){
        Userdata.saveUserdata();
    }
 
    setEventNode(node: cc.Node){
        this.eventNode = node;
    }
 
    cliamReward(times: number) {
        Userdata.addGem(Global.SCORE_REWARD_GEM * times);
        Global.showTip("获得 " + (Global.SCORE_REWARD_GEM * times) + " 钻石.");
 
        let _node = cc.find('Canvas');
        if (_node && cc.isValid(_node)) {
            _node.emit('updateInfo');
        }
        // Game.instance.updateGems();
        if (this.eventNode && cc.isValid(this.eventNode)) {
            this.eventNode.emit('updateInfo');
        }
    }
 
    onClickCliam() {
        SoundManager.playButton();
 
        if (this.isGot) {
            return;
        }
 
        if (Sdk.isToutiao) {
            SdkToutiao.showRewardVideoAd(() => {
                if (!this.isGot){
                    this.isGot = true;
                    this.cliamReward(5);
                    this.hide();
                }
            }, () => {
                Global.showTip('广告展示失败, 请稍后重试!!');
            });
        } else {
            Sdk.ins.showVideoAd((res) => {
                if (res) {
                    this.isGot = true;
                    this.cliamReward(5);
                    this.hide();
                } else {
                    Global.showTip('No ads ready!!');
                }
            });
        }
 
 
    }
}