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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
"use strict";
cc._RF.push(module, '99ea796jU5N6oPNC6Sqe62d', 'task_panel');
// Scripts/mod/task/view/task_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      日常主界面的任务标签页
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var TaskController = require("task_controller");
 
var TaskEvent = require("task_event");
 
var TaskConst = require("task_const");
 
var RoleEvent = require("role_event");
 
var RoleController = require("role_controller");
 
var CommonScrollView = require("common_scrollview");
 
var TaskItem = require("task_item");
 
var TaskPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("task", "task_panel");
    this.box_list = [109, 108, 108, 110];
    this.ctrl = TaskController.getInstance();
    this.model = this.ctrl.getModel();
    this.role_vo = RoleController.getInstance().getRoleVo();
    this.is_new = null;
    this.need_update = null;
  },
  initPanel: function initPanel() {
    this.container = this.root_wnd.getChildByName("container");
    var activity_container = this.container.getChildByName("activity_container");
    this.progress = activity_container.getChildByName("progress_container").getChildByName("progress").getComponent(cc.ProgressBar);
    this.value = activity_container.getChildByName("value").getComponent(cc.Label);
    this.value.string = "0/100";
    this.awards_list = [];
 
    for (var i = 1; i <= Config.activity_data.data_get_length; i++) {
      var awards = activity_container.getChildByName("awards_" + i);
 
      if (awards != null) {
        awards.effect_container = awards.getChildByName("effect_container");
        awards.effect_container.skeleton = awards.effect_container.getComponent(sp.Skeleton);
        awards.target_value = awards.getChildByName("target_value").getComponent(cc.Label);
        awards.is_show_tips = true;
        awards.status = TaskConst.action_status.normal;
 
        if (gdata("activity_data", "data_get", [i]) != null) {
          awards.config = gdata("activity_data", "data_get", [i]);
          awards.target_value.string = awards.config.activity;
        } //按照配置的活跃度储存
 
 
        this.awards_list[i] = awards;
      }
    }
 
    this.quest_container = this.container.getChildByName("quest_container");
    var size = this.quest_container.getContentSize();
    var scroll_view_size = cc.size(size.width, size.height - 20);
    var setting = {
      item_class: TaskItem,
      // 单元类
      start_x: 6,
      // 第一个单元的X起点
      space_x: 0,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 2,
      // y方向的间隔
      item_width: 610,
      // 单元的尺寸width
      item_height: 148,
      // 单元的尺寸height
      row: 0,
      // 行数,作用于水平滚动类型
      col: 1,
      // 列数,作用于垂直滚动类型
      need_dynamic: true
    };
    this.item_scrollview = new CommonScrollView();
    this.item_scrollview.createScroll(this.quest_container, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting, cc.v2(0.5, 0.5));
    this.updateTaskList(this.is_new);
    this.updateActivity(this.need_update);
  },
  addToParent: function addToParent(status) {
    // this.handleDynamicEvent(status);
    // this.setVisible(status);
    if (this.root_wnd == null) this.active_value = status;else this.root_wnd.active = status;
 
    if (status == true) {
      this.ctrl.requestActivityInfo(); //设置当前面板的时候做一次协议请求
 
      this.updateTaskList(true);
      this.updateActivity(false);
    }
  },
  handleDynamicEvent: function handleDynamicEvent(status) {
    if (!status) {
      if (this.role_assets_event != null) {
        if (this.role_vo != null) {
          this.role_vo.unbind(this.role_assets_event);
        }
 
        this.role_assets_event = null;
      }
 
      if (this.update_activity_event != null) {
        gcore.GlobalEvent.unbind(this.update_activity_event);
        this.update_activity_event = null;
      }
 
      if (this.update_task_list != null) {
        gcore.GlobalEvent.unbind(this.update_task_list);
        this.update_task_list = null;
      }
    } else {}
  },
  //必要添加的一个位置方法
  setPosition: function setPosition(x, y) {
    this.x = x;
    this.y = y;
 
    if (this.root_wnd) {
      this.root_wnd.setPosition(this.x, this.y);
    }
  },
  //必要添加的显隐方法
  setVisible: function setVisible(bool) {
    if (this.root_wnd) {
      this.root_wnd.active = bool;
    }
  },
  registerEvent: function registerEvent() {
    for (var k in this.awards_list) {
      var awards = this.awards_list[k];
      awards.on(cc.Node.EventType.TOUCH_END, function (event) {
        var sender = event.currentTarget;
 
        if (sender.config != null) {
          if (sender.is_show_tips == true) {
            var CommonAlert = require("commonalert");
 
            CommonAlert.showItemApply(Utils.TI18N("当前活跃度奖励"), sender.config.rewards, null, Utils.TI18N("确定"), null, null, Utils.TI18N("奖励"), null, null, true, null, null, {
              off_y: 50
            });
          } else {
            if (this.role_vo && this.role_vo.activity >= sender.config.activity) this.ctrl.requestGetActivityAwards(sender.config.activity);
          }
        }
      }.bind(this));
    }
 
    if (this.role_vo != null) {
      if (this.role_assets_event == null) {
        this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
          if (key == "activity") this.updateActivity(true);
        }.bind(this));
      }
    }
 
    if (this.update_activity_event == null) {
      this.update_activity_event = gcore.GlobalEvent.bind(TaskEvent.UpdateActivityInfo, function (data) {
        this.updateActivityData(data);
      }.bind(this));
    }
 
    if (this.update_task_list == null) {
      this.update_task_list = gcore.GlobalEvent.bind(TaskEvent.UpdateTaskList, function (is_new) {
        this.updateTaskList(is_new);
      }.bind(this));
    }
 
    this.ctrl.requestActivityInfo();
  },
  updateActivity: function updateActivity(need_update) {
    this.need_update = need_update;
    if (this.root_wnd == null) return;
 
    if (this.role_vo != null) {
      var activity_config = gdata("activity_data", "data_get", [Config.activity_data.data_get_length]);
      var max_activity = 100;
      if (activity_config != null) max_activity = activity_config.activity;
      this.value.string = this.role_vo.activity + "/" + max_activity;
      this.progress.progress = this.role_vo.activity / max_activity;
      if (need_update == true) this.updateActivityData(this.model.getActivityData());
    }
  },
  // @desc:更新活跃宝箱
  // author:{author}
  // time:2018-05-22 16:02:57
  // --@data: 
  // return
  updateActivityData: function updateActivityData(data) {
    if (this.role_vo == null) return;
    var data_list = data; //判断这个活跃度的宝箱是否已经领取了
 
    var check_activity = function check_activity(activity) {
      if (data_list == null) return false;
      return data_list[activity];
    };
 
    for (var i in this.awards_list) {
      var item = this.awards_list[i];
 
      if (item && item.config && item.effect_container) {
        if (check_activity(item.config.activity) == true) {
          item.is_show_tips = true;
          item.status = TaskConst.action_status.finish;
        } else {
          if (item.config.activity <= this.role_vo.activity) {
            item.is_show_tips = false;
            item.status = TaskConst.action_status.activity;
          } else {
            item.is_show_tips = true;
            item.status = TaskConst.action_status.un_activity;
          }
        }
 
        var box_action = PlayerAction.action_1;
        if (item.status == TaskConst.action_status.finish) box_action = PlayerAction.action_3;else if (item.status == TaskConst.action_status.activity) box_action = PlayerAction.action_2;
 
        if (item.effect_container.skeleton.skeletonData) {
          if (item.box_action != box_action) {
            item.effect_container.skeleton.setAnimation(0, box_action, true);
            item.box_action = box_action;
          }
        } else {
          var res_id = gdata("effect_data", "data_effect_info", this.box_list[i - 1]);
          var path = cc.js.formatStr("spine/%s/action.atlas", res_id);
          var _skeleton = item.effect_container.skeleton;
          this.createEffect(_skeleton, path, box_action);
        }
      }
    }
  },
  //生成宝箱
  createEffect: function createEffect(_skeleton, path, box_action) {
    this.loadRes(path, function (res) {
      _skeleton.skeletonData = res;
 
      _skeleton.setAnimation(0, box_action, true);
    }.bind(this));
  },
  // @desc:更新任务列表,是否需要重新更新列表
  // author:{author}
  // time:2018-05-22 19:11:28
  // --@is_new:如果为true,则重新排序吧,否则就直接更新位置
  // return
  updateTaskList: function updateTaskList(is_new) {
    this.is_new = is_new;
    if (this.root_wnd == null) return; // if (is_new == true) {
 
    var list = this.model.getTaskList();
    this.item_scrollview.setData(list); // } else {
    //     var sort_func = Utils.tableLowerSorter(["finish_sort", "id"]);
    //     this.item_scrollview.resetPosition(sort_func);
    // }
  },
  onDelete: function onDelete() {
    if (this.role_assets_event != null) {
      if (this.role_vo != null) {
        this.role_vo.unbind(this.role_assets_event);
      }
 
      this.role_assets_event = null;
    }
 
    if (this.update_activity_event != null) {
      gcore.GlobalEvent.unbind(this.update_activity_event);
      this.update_activity_event = null;
    }
 
    if (this.update_task_list != null) {
      gcore.GlobalEvent.unbind(this.update_task_list);
      this.update_task_list = null;
    }
 
    if (this.item_scrollview) {
      this.item_scrollview.deleteMe();
      this.item_scrollview = null;
    }
  }
});
module.exports = TaskPanel;
 
cc._RF.pop();