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
// --------------------------------------------------------------------
// @author: whjing2012@syg.com(必填, 创建模块的人员)
// @description:
//      头像框
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
 
var PathTool = require("pathtool");
var TimeTool = require("timetool");
var RoleController = require("role_controller");
var BackpackController = require("backpack_controller");
var TipsController = require("tips_controller");
 
var RoleFacePanel = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("roleinfo", "role_face_panel");
        this.x = 0;//必须设置的两个变量
        this.y = 0;
        this.data = null;
        this.has_list = {};
        this.item_list = {};
    },
 
    initPanel: function () {
        this.setPosition(0, 0);
        this.scroll_con = this.root_wnd.getChildByName("scroll_con");
        this.view = this.scroll_con.getChildByName("view");
        this.content = this.view.getChildByName("content");
        this.ok_btn = this.root_wnd.getChildByName("ok_btn");
        this.ok_label = this.ok_btn.getChildByName("Label").getComponent(cc.Label);
        this.item = this.root_wnd.getChildByName("item");
        RoleController.getInstance().send21500();
    },
 
    registerEvent: function () {
        this.ok_btn.on(cc.Node.EventType.TOUCH_END, function () {
            if (this.select_item) {
                if (this.select_item.v.status == 1) {
                    RoleController.getInstance().send21501(this.select_bid);
                } else {
                    RoleController.getInstance().send21503(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 == "avatar_base_id") {
                    this.updateList();
                }
            }), this);
            this.addGlobalEvent(RoleEvent.GetFaceList, function (data) {
                this.updateList(data.avatar_frame);
            });
        }
    },
 
    onShow: function () {
    },
 
    // 更新头像框列表信息
    updateList: function (has_list) {
        if (has_list) {
            this.has_list = this.has_list || {};
            for (var k in has_list) {
                this.has_list[has_list[k].base_id] = has_list[k];
            }
        }
        this.list = [];
        for (var k in Config.avatar_data.data_avatar) {
            var v = Config.avatar_data.data_avatar[k];
            if (v.is_show != 1) {
            } else if (v.base_id == this.roleVo.avatar_base_id) {
                this.list.push({ bid: v.base_id, use: 1, status: 1, sort: 1100000 - v.base_id });
            } else if (this.has_list[v.base_id]) {
                this.list.push({ bid: v.base_id, use: 0, status: 1, sort: 100000 - v.base_id });
            } else if (v.loss && v.loss[0]) {
                if (BackpackController.getInstance().getModel().getBackPackItemNumByBid(v.loss[0][0]) >= v.loss[0][1]) {
                    this.list.push({ bid: v.base_id, use: 0, status: 2, sort: 2000000 - v.base_id });
                } else {
                    this.list.push({ bid: v.base_id, use: 0, status: 0, sort: -v.base_id });
                }
            } else {
                this.list.push({ bid: v.base_id, use: 0, status: 2, sort: 2000000 - v.base_id });
            }
        }
        // Log.info(has_list, this.has_list, this.list, this.roleVo);
        this.list.sort(Utils.tableUpperSorter(["has", "base_id"]));
        var i = 0;
        var func = (function (num) {
            if (!this.list || !this.item_list || this.list.length == 0) {
                return;
            }
            num = num || 2;
            for (let j = 0; j < num; j++) {
                if (this.list.length == 0) {
                    return;
                }
                this.createItem(i, this.list.pop());
                i++;
            }
            gcore.Timer.set(func, 20, 1, "role_face_panel_timer");
        }).bind(this);
        func(10);
    },
 
    // 创建更新一个头像框
    createItem: function (i, v) {
        var item = this.item_list[v.bid];
        if (!item) {
            var config = Config.avatar_data.data_avatar[v.bid];
            item = cc.instantiate(this.item);
            this.content.addChild(item);
            this.item_list[v.bid] = item;
            item.active = true;
            item.icon = item.getChildByName("icon").getComponent(cc.Sprite);
            item.use = item.getChildByName("use");
            item.select = item.getChildByName("select");
            item.active_node = item.getChildByName("active");
            item.label = item.getChildByName("label").getComponent(cc.Label);
            item.label.string = config.name;
            item.icon_bg = item.getChildByName("icon_bg");
            if (config.offy) {
                item.icon_bg.y = item.icon_bg.y - config.offy
            }
 
            item.on(cc.Node.EventType.TOUCH_END, (function () {
                this.setSelected(v.bid);
                // TipsController.getInstance().showHeadCircleTips({bid:v.bid});
            }).bind(this));
            this.loadRes(PathTool.getHeadcircle(config.res_id), (function (resObject) {
                item.icon.spriteFrame = resObject;
            }).bind(this));
        }
        item.v = v;
        var y = -(parseInt(i / 4) * 170 + 70);
        item.setPosition(i % 4 * 150 + 75, y);
        // this.content.height = 55-y;
        if (v.use == 1) {
            item.use.active = true;
            this.setSelected(v.bid);
        } else {
            item.use.active = false;
        }
        item.active_node.active = (v.status == 2);
        if (v.status == 1) {
            item.icon.setState(cc.Sprite.State.NORMAL);
        } else {
            item.icon.setState(cc.Sprite.State.GRAY);
        }
    },
 
    // 设置选择状态 
    setSelected: function (bid) {
        if (this.select_bid == bid) {
            return;
        }
        this.select_bid = bid;
        if (this.select_item) {
            this.select_item.select.active = false;
        }
        this.select_item = this.item_list[bid];
        if (this.select_item) {
            this.select_item.select.active = true;
            if (this.select_item.v.status == 1) {
                this.ok_label.string = Utils.TI18N("更 换");
            } else {
                this.ok_label.string = Utils.TI18N("激 活");
            }
        }
    },
 
    onHide: function () {
 
    },
 
    onDelete: function () {
        if (this.role_update_evt) {
            this.roleVo.unbind(this.role_update_evt);
        }
        this.list = null;
        this.item_list = null;
    }
});
 
module.exports = RoleFacePanel;