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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
"use strict";
cc._RF.push(module, 'b8c57VO6MhBtY8V10jV1tQ5', 'adventure_cell_item_panel');
// Scripts/mod/adventure/view/adventure_cell_item_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-05-15 11:51:27
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var AdventureEvent = require("adventure_event");
 
var AdventureConst = require("adventure_const");
 
var AdventureController = require("adventure_controller");
 
var PlayerHead = require("playerhead");
 
var Adventure_cell_itemPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("adventure", "adventure_cell_item");
    this.ctrl = AdventureController.getInstance();
    this.model = this.ctrl.getModel();
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.cell_path = "ui_res/adventure/img/%s.png";
    this.evt_path = "ui_res/adventure/evt/%s.png";
    this.is_last_floor = false; // 是否是最后一层
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.container = this.root_wnd.getChildByName("container");
    this.background = this.container.getChildByName("background");
    this.cell = this.container.getChildByName("cell").getComponent(cc.Sprite);
    this.evt_container = this.container.getChildByName("evt_container");
 
    if (this.data) {
      this.updateInfo();
    }
  },
  setVisible: function setVisible(status) {
    this._super(status);
 
    if (status) {
      this.updateEvtInfo();
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.container, function () {
      if (this.data && this.call_back) {
        // 非下一关的over事件就不需要给点击回调了
        if (this.data) {
          if (this.data.config && this.data.status == AdventureConst.status.over) {
            if (this.data.config.evt_type != AdventureEvent.EventType.next && this.data.config.evt_type != AdventureEvent.EventType.shop) {
              return;
            }
          }
        }
 
        this.call_back(this);
      }
    }.bind(this), 1);
  },
  addCallBack: function addCallBack(call_back) {
    this.call_back = call_back;
  },
  setExtendData: function setExtendData(is_update) {
    this.is_update = is_update;
  },
  setData: function setData(data) {
    this.data = data;
 
    if (this.root_wnd) {
      this.updateInfo();
    }
  },
  updateInfo: function updateInfo() {
    if (this.data) {
      this.is_last_floor = false;
      var cell_key_str = Utils.getNorKey(this.data.lock, this.data.id, this.data.status, this.data.evt_id);
      if (this.cell_key_str == cell_key_str) return;
      this.cell_key_str = cell_key_str; // 还原采集描述类
 
      this.setOtherDesc(false); // 层级问题
 
      if (this.cell_id != this.data.id) {
        this.cell_id = this.data.id; // this:setvarZOrder(25 - this.data.id)
        // 引导需要
        // this.container:setName("guide_adventure_cell_"+this.data.id)
      } // -- 引导需要
      // if this.guide_evt_id ~= this.data.evt_id and this.data.evt_id ~= 0 then
      //     this.guide_evt_id  = this.data.evt_id
      //     this.container:setTag(this.data.evt_id)
      // end
      // 设置当前事件样式显示
 
 
      this.updateEvtInfo(); // 地块的状态判断,以及资源的重载
 
      if (this.data.status == AdventureConst.status.open || this.data.status == AdventureConst.status.over) {
        this.cell.node.active = false;
      } else if (this.data.config && this.data.config.evt_type == AdventureEvent.EventType.mysterious) {
        this.cell.node.active = false;
      } else {
        this.createCellSytle();
      }
    }
  },
  // ==============================--
  // desc:创建地块样式
  // @return 
  // ==============================--
  createCellSytle: function createCellSytle() {
    if (this.data == null) return;
    var data = this.data;
    this.cell.node.active = true;
    var cell_res = cc.js.formatStr(this.cell_path, data.res_id);
 
    if (this.cell_res != cell_res) {
      this.cell_res = cell_res;
 
      if (this.cell) {
        this.loadRes(cell_res, function (sf_obj) {
          this.cell.spriteFrame = sf_obj;
        }.bind(this));
        this.setCellStatus();
      }
    } else {
      this.setCellStatus();
    }
  },
  // ==============================--
  // desc:地块的状态,是暗调还是说亮起来可点
  // @return 
  // ==============================--
  setCellStatus: function setCellStatus() {
    if (this.data == null) return;
    if (this.cell_status == this.data.status) return;
    this.cell_status = this.data.status;
 
    if (this.data.status == AdventureConst.status.lock) {
      this.cell.node.color = new cc.Color(115, 115, 115, 255);
    } else if (this.data.status == AdventureConst.status.can_open) {
      this.cell.node.color = new cc.Color(255, 255, 255, 255);
    }
  },
  // ==============================--
  // desc:清掉数据资源
  // @return 
  // ==============================--
  clearEvtResources: function clearEvtResources() {
    if (this.event_img) {
      this.event_img.node.stopAllActions();
    }
 
    if (this.head) {
      this.head.deleteMe();
    }
 
    this.head = null;
 
    if (this.head_node) {
      this.head_node.stopAllActions();
    }
 
    this.head_node = null;
 
    if (this.event_model) {
      if (this.event_model.setToSetupPose) {
        this.event_model.setToSetupPose();
      }
 
      if (this.event_model.clearTracks) {
        this.event_model.clearTracks();
      }
 
      if (this.event_model.node) {
        this.event_model.node.removeAllChildren();
        this.event_model.node.removeFromParent();
      }
 
      this.event_model = null;
    }
 
    this.event_model_res = "";
  },
  // ==============================--
  // desc:事件的显示,加载不同事件资源
  // @return 
  // ==============================--
  updateEvtInfo: function updateEvtInfo() {
    if (this.data == null || !this.getVisible()) return;
    var evt_config = this.data.evt_id > 0 ? gdata("adventure_data", "data_adventure_event", this.data.evt_id) : null;
    this.data.config = evt_config; // 储存配置
    // 事件数据不存在或者事件资源显示数据不存在
 
    if (evt_config == null || evt_config.res_id == null || evt_config.res_id[0] == null) {
      this.clearEvtResources();
      return;
    } // 如果是下一层事件,需要判断是不是还有下一层,否则不需要显示
 
 
    if (evt_config.evt_type == AdventureEvent.EventType.next) {
      var base_data = this.model.getAdventureBaseData();
 
      if (base_data == null || base_data.id == null) {
        this.clearEvtResources();
        return;
      }
 
      var next_config = Config.adventure_data.data_floor_reward[base_data.id + 1];
 
      if (next_config == null && evt_config.evt_type == AdventureEvent.EventType.next) {
        this.is_last_floor = true;
      }
    } // 其他事件处理
 
 
    if (this.data.status != AdventureConst.status.over || evt_config.evt_type == AdventureEvent.EventType.init || evt_config.evt_type == AdventureEvent.EventType.next || evt_config.evt_type == AdventureEvent.EventType.block || evt_config.evt_type == AdventureEvent.EventType.shop) {
      this.createEvtShowInfo(evt_config);
    } else {
      this.clearEvtResources();
    }
  },
  setOtherDesc: function setOtherDesc(status, desc) {
    if (!status) {
      if (this.other_desc) {
        this.other_desc.node.active = false;
      }
    } else {
      if (this.other_desc == null) {
        this.other_desc = Utils.createLabel(24, new cc.Color(0xff, 0xff, 0xff, 0xff), new cc.Color(0x00, 0x00, 0x00, 0xff), 71, 60, desc, this.container, null, cc.v2(0.5, 0));
      }
 
      this.other_desc.string = desc;
      this.other_desc.node.active = true;
    }
  },
  // ==============================--
  // desc:创建事件显示效果
  // @evt_config:
  // @return 
  // ==============================--
  createEvtShowInfo: function createEvtShowInfo(evt_config) {
    if (evt_config == null) return;
    var res_data = evt_config.res_id[0];
    var res_type = res_data[0]; // 0.图片资源(如果是怪物或者boss事件的,就创建特效) 1.特效资源
 
    var res_id = res_data[1]; // 资源名字
 
    var is_shadow = evt_config.shadow == 1;
    if (res_type == null || res_id == null) return; // 储存资源
 
    if (this.event_model_res == Utils.getNorKey(res_type, res_id)) return;
    this.clearEvtResources();
    this.event_model_res = Utils.getNorKey(res_type, res_id);
 
    if (res_type == 2) {
      var eff_node = new cc.Node();
      eff_node.setAnchorPoint(0.5, 0.5);
      eff_node.setPosition(0, 5);
      this.evt_container.addChild(eff_node);
      this.event_model = eff_node.addComponent(sp.Skeleton);
 
      if (this.eff_time) {
        gcore.Timer.del(this.eff_time);
      }
 
      this.eff_time = gcore.Timer.set(function () {
        var anima_path = PathTool.getSpinePath(res_id, "action");
        this.loadRes(anima_path, function (ske_data) {
          this.event_model.skeletonData = ske_data;
          this.event_model.setAnimation(0, PlayerAction.action, true);
        }.bind(this));
      }.bind(this), 100, 1);
    } else {
      if (is_shadow == true) {
        this.event_model = Utils.createImage(this.evt_container, null, 0, -33, cc.v2(0.5, 0.5), false);
        this.loadRes(PathTool.getUIIconPath("adventurewindow", "adventurewindow_3"), function (sf_obj) {
          this.event_model.spriteFrame = sf_obj;
        }.bind(this));
        this.head_node = new cc.Node();
        this.head_node.setAnchorPoint(0.5, 0.5);
        this.head_node.setPosition(0, 0);
        this.event_model.node.addChild(this.head_node);
        var event_path = cc.js.formatStr(this.evt_path, res_id);
 
        if (this.ctrl.isMonster(evt_config.evt_type)) {
          if (this.head == null) {
            this.head = new PlayerHead();
            this.head.setFrameRes(event_path, 1);
            this.head.setPosition(0, 62);
            this.head.setParent(this.head_node);
            this.head.show();
          }
 
          CommonAction.breatheShineAction4(this.head_node);
          this.head.setHeadRes(evt_config.face);
        } else {
          this.event_img = Utils.createImage(this.event_model.node, null, 0, 66, cc.v2(0.5, 0.5), false);
          CommonAction.breatheShineAction4(this.event_img.node);
 
          if (this.event_img) {
            this.loadRes(event_path, function (sf_obj) {
              this.event_img.spriteFrame = sf_obj;
            }.bind(this));
          }
        }
      } else {
        this.event_model = Utils.createImage(this.evt_container, null, 0, -31, cc.v2(0.5, 0), false);
        var event_path = cc.js.formatStr(this.evt_path, res_id);
 
        if (this.event_model) {
          this.loadRes(event_path, function (sf_obj) {
            this.event_model.spriteFrame = sf_obj;
          }.bind(this));
        }
      }
    }
  },
  // ==============================--
  // desc:摧毁BOSS雕像
  // @callback:
  // @action_name:
  // @return 
  // ==============================--
  changeBossEffectStatus: function changeBossEffectStatus(callback, action_name) {
    if (this.is_in_playing == true) return;
    if (this.data == null || this.data.config == null) return;
    if (this.event_model == null) return;
 
    if (this.data.config.evt_type == AdventureEvent.EventType.mysterious) {
      this.is_in_playing = true;
      this.event_model.setAnimation(0, action_name, false);
      Utils.delayRun(this.event_model.node, 1.5, function () {
        this.is_in_playing = false;
        callback(this.data.id);
      }.bind(this));
    }
  },
  // ==============================--
  // desc:获取事件图标,这个东西现在只有技能事件才需要,需要播放移动动作
  // @return 
  // ==============================--
  getEvtImg: function getEvtImg() {
    return this.event_img;
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {},
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.eff_time) {
      gcore.Timer.del(this.eff_time);
    }
 
    this.clearEvtResources();
  }
});
 
cc._RF.pop();