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
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      用户输入框
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
 
var PathTool = require("pathtool");
var TaskConst = require("task_const");
var TaskEvent = require("task_event");
var TaskController = require("task_controller");
 
 
var TaskItem = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("task", "task_item");
        this.item_list = [];
    },
 
 
    initPanel: function () {
        this.btn_img_res = "common_1098";
        this.container = this.root_wnd.getChildByName("container");
        this.task_desc = this.container.getChildByName("task_desc").getComponent(cc.Label);
 
        this.btn_container = this.container.getChildByName("btn_container");
 
        this.goto_btn = this.btn_container.getChildByName("goto_btn");
 
        this.goto_btn_label = this.goto_btn.getChildByName("label").getComponent(cc.Label);
        this.goto_btn_label.string = Utils.TI18N("前往");
        this.goto_btn_img = this.goto_btn.getComponent(cc.Sprite);
 
        this.progress = this.btn_container.getChildByName("progress").getComponent(cc.ProgressBar);
        this.value = this.btn_container.getChildByName("value").getComponent(cc.Label);
        this.value.string = Utils.TI18N("0/0");
        this.progress.progress = 0;
 
        this.completed_img = this.container.getChildByName("completed_img");
    },
 
 
    registerEvent: function () {
        if (this.goto_btn) {
            this.goto_btn.on(cc.Node.EventType.TOUCH_END, function () {
                if (this.data != null && this.data.config != null) {
                    if (this.data.finish == TaskConst.task_status.un_finish) {
                        if (this.data.progress != null) {
                            for (var i in this.data.progress) {
                                var v = this.data.progress[i];
                                if (v.finish == 0) {
                                    TaskController.getInstance().handleTaskProgress(this.data, i);
                                    break
                                }
                            }
                        }
                    } else if (this.data.finish == TaskConst.task_status.finish) {
                        if (this.data.type == TaskConst.type.quest) {
                            TaskController.getInstance().requestSubmitTask(this.data.id);
                        } else if (this.data.type == TaskConst.type.feat) {
                            TaskController.getInstance().requestSubmitFeat(this.data.id);
                        }
                    }
                }
            }, this);
        }
    },
 
    addCallBack: function (value) {
        this.callback = value
    },
 
    // 退出的时候移除一下吧.要不然可能有些人不会手动移除,就会报错
    registerScriptHandler: function (event) {
        if ("enter" == event) {
 
        } else if ("exit" == event) {
            if (this.data != null) {
                if (this.update_self_event != null) {
                    this.data.unbind(this.update_self_event);
                    this.update_self_event = null;
                }
                this.data = null;
            }
        }
    },
 
    //必要添加的数据传入方法
    setData: function (data) {
        this.data = data;
 
        if (this.root_wnd != null)
            this.onShow()
    },
 
    onShow: function () {
        // if (this.data != null) {
        //     if (this.update_self_event != null) {
        //         this.data.unbind(this.update_self_event);
        //         this.update_self_event = null;
        //     }
        //     this.data = null;
        // }
        // this.data = data;
        if (this.update_self_event == null) {
            this.update_self_event = this.data.bind(TaskEvent.UpdateSingleQuest, function () {
                this.updateSelf();
            }.bind(this))
        }
        this.fillAwardsItems()
 
        this.updateSelf()
    },
 
    // @desc:创建展示物品
    // author:{author}
    // time:2018-05-26 13:56:08
    // return
    fillAwardsItems: function () {
        if (this.data == null || this.data.config == null || this.data.config.commit_rewards == null)
            return
        for (var i in this.item_list) {
            var item = this.item_list[i];
            item.setVisible(false)
        }
        for (var i in this.data.config.commit_rewards) {
            var v = this.data.config.commit_rewards[i];
            var _bid = v[0];
            var _num = v[1];
            var item = this.item_list[i];
            if (item == null) {
                item = ItemsPool.getInstance().getItem("backpack_item");
                item.initConfig(false, 0.7, false, true)
                var _x = (BackPackItem.Width * 0.7 + 20) * i + 58;
                item.setPosition(_x, 54);
                item.show();
                item.setParent(this.container)
                this.item_list[i] = item;
            } else {
                item.setVisible(true);
            }
            item.setData({ bid: _bid, num: _num });
        }
    },
 
    changeImg:function(res){
        this.loadRes(res, function(sf_obj){
            this.goto_btn_img.spriteFrame = sf_obj;
        }.bind(this))
    },
 
    updateSelf: function () {
        if (this.data == null)
            return
        this.id = this.data.id;
        this.finish_sort = this.data.finish_sort;
        this.completed_img.active = this.data.finish == TaskConst.task_status.completed;
        this.btn_container.active = this.data.finish != TaskConst.task_status.completed;
 
        var btn_img_res = "";
        if (this.data.finish == TaskConst.task_status.un_finish) { 
            this.goto_btn_label.string = Utils.TI18N("前往");
            btn_img_res = "common_1098";
            this.goto_btn_label.node.color = new cc.Color(0x25, 0x55, 0x05, 0xff);
 
        } else if (this.data.finish == TaskConst.task_status.finish) {
            this.goto_btn_label.string = Utils.TI18N("提交");
            btn_img_res = "common_1027";
            this.goto_btn_label.node.color = new cc.Color(0x71, 0x28, 0x04);
        }
 
        if (this.btn_img_res != btn_img_res && btn_img_res!= "") {
            this.btn_img_res = btn_img_res;
            this.changeImg(PathTool.getCommonIcomPath(btn_img_res))
        }
 
        if (this.data.finish != TaskConst.task_status.completed) {
            if (this.data.progress != null) {
                var progress = this.data.progress[0];
                if (progress != null) {
                    this.value.string = cc.js.formatStr("%s/%s", Utils.getMoneyString(progress.value), Utils.getMoneyString(progress.target_val));
                    this.progress.progress = progress.value / progress.target_val;
                }
            }
        }
        this.task_desc.string = this.data.getTaskContent();
    },
 
    suspendAllActions: function () {
        if (this.data != null) {
            if (this.update_self_event != null) {
                this.data.unbind(this.update_self_event);
                this.update_self_event = null;
            }
            this.data = null;
        }
    },
 
    onDelete: function () {
        for (var i in this.item_list) {
            var v = this.item_list[i];
            if (v)
                v.deleteMe();
        }
        this.item_list = null;
        this.suspendAllActions();
    }
 
});
 
module.exports = TaskItem;