difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
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
83
84
85
86
87
var PathTool = require("pathtool");
var CommonTabBtn = cc.Class({
    extends: ViewClass,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("common", "common_tab_btn");
    },
    initRootWnd(){
        this.size = cc.size(147, 64);
        this.root_wnd = new cc.Node();
        this.parent.addChild(this.root_wnd);
        this.root_wnd.setContentSize(this.size);
        this.toggle = this.root_wnd.addComponent(cc.Toggle);
        this.toggle.isChecked = false;
        this.toggle.transition = cc.Button.Transition.NONE;
        let unselect_bg = new cc.Node();
        this.root_wnd.addChild(unselect_bg);
        this.toggle.target = unselect_bg
        this.loadRes(PathTool.getUIIconPath("common","common_1012"),function(res){
            let Sprite = unselect_bg.addComponent(cc.Sprite)
            Sprite.type = cc.Sprite.Type.SLICED;
            Sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
            Sprite.spriteFrame = res;
            unselect_bg.setContentSize(this.size)
        }.bind(this))
        let select_bg = new cc.Node();
        this.root_wnd.addChild(select_bg);
        let Sprite1 = select_bg.addComponent(cc.Sprite)
        this.toggle.checkMark = Sprite1
        Sprite1.type = cc.Sprite.Type.SLICED;
        Sprite1.sizeMode = cc.Sprite.SizeMode.CUSTOM;
        this.loadRes(PathTool.getUIIconPath("common","common_1011"),function(res){
            Sprite1.spriteFrame = res;
            select_bg.setContentSize(this.size);
        }.bind(this))
        //标签名字
        let title = new cc.Node();
        title.color = new cc.Color(245,224,185,255);
        this.title_lb = title.addComponent(cc.Label);
        this.title_lb.fontSize = 24;
        this.title_lb.lineHeight = 28;
        title.setPosition(0,-5);
        this.root_wnd.addChild(title);
        let line = this.title_lb.addComponent(cc.LabelOutline);
        line.color = new cc.Color(42,22,14,255);
        line.width = 2;
        //红点
        this.tab_tips = new cc.Node();
        this.root_wnd.addChild(this.tab_tips)
        this.tab_tips.setPosition(65.5,26)
        this.loadRes(PathTool.getUIIconPath("common","common_1014"),function(res){
            let Sprite = this.tab_tips.addComponent(cc.Sprite)
            Sprite.type = cc.Sprite.Type.SIMPLE;
            Sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
            Sprite.spriteFrame = res;
            this.tab_tips.setContentSize(35,35);
        }.bind(this))
        let red = new cc.Node()
        this.red_lb = red.addComponent(cc.Label)
        this.red_lb.fontSize = 20;
        this.red_lb.lineHeight = 22;
        this.tab_tips.active = false;
        this.registerEvent()
    },
    registerEvent(){
        this.root_wnd.on("toggle",function(){
            if(this.callback){
                this.callback()
            }
        },this)
    },
    setTitle(text){
        this.title_lb.string = text;
    },
    addCallBack(callback){
        this.callback = callback;
    },
    setParent(node){
        this.parent = node;
        if(this.parent){
            this.initRootWnd();
        }
    },
    getToggle(){
        return this.toggle
    }
})
module.exports = CommonTabBtn;