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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// --------------------------------------------------------------------
// @author: whjing2012@syg.com(必填, 创建模块的人员)
// @description:
//      冒险形象
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
 
var PathTool = require("pathtool");
var RoleController = require("role_controller");
var RoleHeadItem = require("role_head_item");
var BaseRole = require("baserole");
var BackpackController = require("backpack_controller");
var CommonScrollView = require("common_scrollview");
var HeroController = require("hero_controller");
var PartnerCalculate = require("partner_calculate");
 
var RoleBodyPanel = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("roleinfo", "role_body_panel");
        this.x = 0;//必须设置的两个变量
        this.y = 0;
        this.data = null;
        this.has_list = {};
        this.item_list = {};
        this.select_bid = 0;
    },
 
    initPanel: function () {
        this.setPosition(0, 0);
        this.scroll_con = this.root_wnd.getChildByName("scroll_con");
        this.ok_btn = this.root_wnd.getChildByName("ok_btn");
        this.ok_label = this.ok_btn.getChildByName("Label").getComponent(cc.Label);
        this.body_con = this.root_wnd.getChildByName("body_con");
        this.attr_desc = this.root_wnd.getChildByName("attr_con").getChildByName("desc").getComponent(cc.RichText);
        this.cond_desc = this.root_wnd.getChildByName("cond_con").getChildByName("desc").getComponent(cc.RichText);
        this.spine = new BaseRole();
        this.spine.setParent(this.body_con);
        this.spine.node.setPosition(0, 10);
        this.spine.scale = 0.6;
        var setting = {
            item_class: RoleHeadItem,      // 单元类
            start_x: 0,                    // 第一个单元的X起点
            space_x: 4,                    // x方向的间隔
            start_y: 0,                    // 第一个单元的Y起点
            space_y: 0,                   // y方向的间隔
            item_width: 125,               // 单元的尺寸width
            item_height: 145,              // 单元的尺寸height
            row: 0,                        // 行数,作用于水平滚动类型
            col: 2,                        // 列数,作用于垂直滚动类型
            once_num: 4,
            need_dynamic: true
        };
        var scroll_view_size = cc.size(250, 490);
        this.item_scrollview = new CommonScrollView()
        this.item_scrollview.createScroll(this.scroll_con, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting, cc.v2(0.5, 0.5));
        RoleController.getInstance().send10345();
    },
 
    registerEvent: function () {
        this.ok_btn.on(cc.Node.EventType.TOUCH_END, function () {
            if (this.select_item) {
                if (this.select_item.data.status == 1) {
                    RoleController.getInstance().send10346(this.select_bid);
                } else if (this.cond_msg) {
                    message(this.cond_msg);
                } else {
                    RoleController.getInstance().send10347(this.select_bid);
                }
            }
        }, this);
        this.roleVo = RoleController.getInstance().getRoleVo();
        if (!this.role_update_evt) {
            var RoleEvent = require("role_event");
            this.role_update_evt = this.roleVo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, (function (key, val) {
                if (key == "look_id") {
                    this.updateList();
                }
            }), this);
            this.addGlobalEvent(RoleEvent.GetModelList, function (data) {
                this.updateList(data.list);
            })
        }
    },
 
    onShow: function () {
    },
 
    updateList: function (has_list) {
        if (has_list) {
            this.has_list = this.has_list || {};
            for (var k = 0; k < has_list.length; ++k) {
                this.has_list[has_list[k].id] = 1;
            }
        }
        // var list = [];
        // for (var k in Config.looks_data.data_data) {
        //     var v = Config.looks_data.data_data[k];
        //     if (v.id == this.roleVo.look_id) {
        //         list.push({ bid: v.id, face_id: v.partner_id, name: v.name, use: 1, status: 1, sort: 1100000 - v.id });
        //     } else if (this.has_list[v.id]) {
        //         list.push({ bid: v.id, face_id: v.partner_id, name: v.name, use: 0, status: 1, sort: 100000 - v.id });
        //     } else {
        //         list.push({ bid: v.id, face_id: v.partner_id, name: v.name, use: 0, status: 0, sort: -v.id });
        //     }
        // }
        // list.sort(Utils.tableCommonSorter([["use", true], ["show", true], ["id", true]]));
        if (this.list == null) {
            this.list = [];
            for (let k in Config.looks_data.data_data) {
                let v = Config.looks_data.data_data[k];
                let data = {};
                data.tips = v.tips;
                data.bid = v.id;
                data.skin_id = v.skin_id;
                data.face_id = v.partner_id;
                if (data.skin_id != 0) {
                    let config = Config.partner_skin_data.data_skin_info[data.skin_id];
                    if (config) {
                        data.face_id = config.head_id;
                    }
                }
                data.name = v.name;
                if (this.has_list) {
                    if (this.has_list[v.id]) {
                        data.status = 1;    //拥有
                    } else {
                        data.status = 0;    //未拥有
                    }
                } else {
                    data.status = 0;
                }
                if (this.roleVo.look_id == v.id) {
                    data.use = 1;
                } else {
                    data.use = 0;
                }
                this.list.push(data);
            }
        } else {
            for (let i in this.list) {
                let data = this.list[i];
                if (this.roleVo.look_id == data.bid) {
                    data.use = 1;
                } else {
                    data.use = 0;
                }
            }
        }
 
        // this.list.sort(Utils.tableUpperSorter(["use", "status", "bid"]));
        this.list.sort(Utils.tableCommonSorter([["use", true], ["status", true], ["bid", true]]));
        if (this.select_bid == 0) {
            this.select_bid = this.roleVo.look_id;
        }
 
        this.item_scrollview.setData(this.list, (function (cell) {
            if (cell.data.status != 1) {
                message(Utils.TI18N("该形象未解锁"));
            }
            this.select_bid = cell.data.bid;
            if (this.select_item) {
                this.select_item.setSelected(false);
            }
            this.select_item = cell;
            this.setSelected(cell);
        }).bind(this), { resObject: this.face_res_object, select_func: this.setSelected.bind(this) });
    },
 
    setSelected: function (item) {
        if (item) {
            item.setSelected(this.select_bid == item.data.bid)
            if (this.select_item == null) {
                this.select_item = item;
            }
        }
        if (this.select_bid != item.data.bid) return
        this.spine.setData(BaseRole.type.role, this.select_bid, PlayerAction.show, true, 0.6, { skin_id: item.data.skin_id });
        var config = Config.looks_data.data_data[this.select_bid];
        this.attr_desc.string = this.attrString(config);
        this.cond_desc.string = this.condString(config);
        if (this.select_item.data.status == 1) {
            this.ok_label.string = Utils.TI18N("更 换");
        } else {
            this.ok_label.string = Utils.TI18N("激 活");
        }
    },
 
    attrString: function (config) {
        var attr_list = config.attr;
        if (attr_list.length == 0) {
            return Utils.TI18N("<color=#a95f0f>当前形象无属性加成</color>");
        }
        var attr_desc = "";
        for (let i = 0, n = attr_list.length; i < n; i++) {
            let attr = attr_list[i];
            if (i > 0 && i % 2 == 0) {
                attr_desc += "<br/>";
            } else if (i > 0) {
                attr_desc += "     ";
            }
            // attr_desc += cc.js.formatStr("%s: %d", Config.attr_data.data_key_to_name[attr[0]], attr[1]);
 
            if (PartnerCalculate.isShowPerByStr(attr[0]) == true) {
                attr_desc += cc.js.formatStr("%s: %d%", Config.attr_data.data_key_to_name[attr[0]], attr[1] * 0.1);
            }
            else {
                attr_desc += cc.js.formatStr("%s: %d", Config.attr_data.data_key_to_name[attr[0]], attr[1]);
            }
        }
        return "<color=#a95f0f>" + attr_desc + "</color>";
    },
 
    condString: function (config) {
        this.cond_msg = null;
        if (this.select_item.data.status == 1) {
            return Utils.TI18N("<color=#249003>当前形象已解锁</color>");
        }
        var cond_desc = [];
        if (config.star > 0) {
            // cond_desc.push(cc.js.formatStr("◆ %s达到%d星 <color=#249003>已达成</color>", config.name, config.star));
            this.cond_msg = cc.js.formatStr(Utils.TI18N("%s未达到%d星"), config.name, config.star);
            cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ %s达到%d星    <color=#d95014>未达成</color>"), config.name, config.star));
        }
        if (config.skin_id) {
            let status = HeroController.getInstance().getModel().isUnlockHeroSkin(config.skin_id);
            if (status) {
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 解锁皮肤%s    <color=#249003>已达成</color>"), config.name));
            } else {
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 解锁皮肤%s    <color=#d95014>未达成</color>"), config.name));
            }
        }
        if (config.lev > 1) {
            if (this.roleVo.lev >= config.lev) {
                this.cond_msg = this.cond_msg || Utils.TI18N("等级不足");
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 玩家等级达到%d     <color=#249003>已达成</color>"), config.lev));
            } else {
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 玩家等级达到%d     <color=#d95014>未达成</color>"), config.lev));
            }
        }
        if (config.vip_lev > 0) {
            if (this.roleVo.vip_lev >= config.vip_lev) {
                this.cond_msg = this.cond_msg || Utils.TI18N("VIP等级不足");
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 玩家VIP等级达到%d   <color=#249003>已达成</color>"), config.vip_lev));
            } else {
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 玩家VIP等级达到%d   <color=#d95014>未达成</color>"), config.vip_lev));
            }
        }
        for (let i = 0, n = config.expend; i < n; i++) {
            let loss = config.expend[i];
            let itemdata = Utils.getItemConfig(loss[0]);
            if (BackpackController.getInstance().getModel().getBackPackItemNumByBid(loss[0]) >= loss[1]) {
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 拥有%s个%s   <color=#249003>已达成</color>"), itemdata.name, loss[1]));
            } else {
                cond_desc.push(cc.js.formatStr(Utils.TI18N("◆ 拥有%s个%s   <color=#d95014>未达成</color>"), itemdata.name, loss[1]));
            }
        }
        return "<color=#a95f0f>" + cond_desc.join("<br/>") + "</color>";
    },
 
    onHide: function () {
 
    },
 
    onDelete: function () {
        if (this.role_update_evt) {
            this.roleVo.unbind(this.role_update_evt);
        }
        if (this.item_scrollview) {
            this.item_scrollview.DeleteMe()
        }
        this.item_scrollview = null
    }
});
 
module.exports = RoleBodyPanel;