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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var PathTool = require("pathtool");
var PartnerCalculate = require("partner_calculate");
var ExhibitionItem = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("battle", "battle_camp_item");
 
    },
 
    // 可以初始化声明一些变量的
    initConfig:function(){
        var self = this;
        self.camp_icons = [];
        self.attr_label = {};
    },
 
    // 初始化一些配置数据,可以用于声明一些变量之类的
    initPanel:function(){
        var self = this;
        let container = self.root_wnd.getChildByName("main_container");
        self.cur_bg = container.getChildByName("cur_bg");
        self.cur_bg.active = false;
        self.form_icon = container.getChildByName("form_icon");
        this.btn = self.form_icon.getComponent(cc.Button)
        this.name_lb = container.getChildByName("name").getComponent(cc.Label)
        self.sp_activate = container.getChildByName("sp_activate")
        self.sp_activate.active = false
        self.attr_label = container.getChildByName("attr_label").getComponent(cc.RichText)
        this.line = container.getChildByName("line")
        if(this.data){
            this.setData(this.data);
        }
    },
 
    // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
    registerEvent:function() {
 
    },
 
    // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
    onShow:function(params){
    },
 
    // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
    onHide:function(){
 
    },
    setData( data ){
        this.data = data;
        cc.log(data)
        if(data && this.root_wnd){
            var self = this;
            if(data.is_activate == true){
                self.cur_bg.active = true;
                this.btn.interactable = true;
                this.btn.enableAutoGrayEffect = false;
                this.sp_activate.active = true;
            }else{
                self.cur_bg.active = false;
                this.btn.interactable = false;
                this.btn.enableAutoGrayEffect = true;
                this.sp_activate.active = false;
            }
 
            let form_res = PathTool.getUIIconPath("campicon","campicon_"+data.icon);
            this.loadRes(form_res,function(res){
                self.form_icon.getComponent(cc.Sprite).spriteFrame = res;
            }.bind(this))
            this.name_lb.string = data.name;
            this.line.active = data.index != Config.combat_halo_data.data_halo_show_length-1
            // -- 属性
            let desc_str = ""
            let index_flag = 0
            for(let i in data.attr_data){
                let v = data.attr_data[i]
                if(v.is_activate){
                    index_flag = i
                }
            }
            let len = Utils.getArrLen(data.attr_data);
            let index = 0
            for(let i in data.attr_data){
                let v = data.attr_data[i]
                let str = v.desc
                for(let j=0;j<v.attrs.length;++j){
                    let attr = v.attrs[j]
                    let attr_key = attr[0]
                    let attr_val = attr[1]/1000
                    let attr_name = Config.attr_data.data_key_to_name[attr_key]
                    if(attr_name){
                        let is_per = PartnerCalculate.isShowPerByStr(attr_key)
                        if(is_per == true){
                            attr_val = (attr_val*1000*100/1000)+"%"
                        }
                        if(i == index_flag){
                            str = str + cc.js.formatStr("    %s<color=#68c74b>+%s</color>", attr_name, attr_val)
                        }else{
                            str = str + cc.js.formatStr("    %s+%s", attr_name, attr_val)
                        }
                    }
                }
                if(i == index_flag){
                    str = cc.js.formatStr("<color=#e0bf98>%s</color>", str)
                }else{
                    str = cc.js.formatStr("<color=#695b50>%s</color>", str)
                }
                index++
                if(len != index){
                    desc_str = desc_str + str + "\n"
                }else{
                    desc_str = desc_str + str
                }
               
            }
            this.attr_label.string = desc_str
        }
    },
    // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
    onDelete:function(){
        
    },
})