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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
"use strict";
cc._RF.push(module, 'fe2c40l05tGiJkMi1UQh/Ql', 'battle_drama_map_window');
// Scripts/mod/battle_drama/view/battle_drama_map_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-03-25 10:03:05
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var Battle_dramaEvent = require("battle_drama_event");
 
var BattleConst = require("battle_const");
 
var MainuiController = require("mainui_controller");
 
var BattleEvent = require("battle_event");
 
var BattleDramaMainPointItem = require("battle_drama_main_point_item");
 
var BaseRole = require("baserole");
 
var RoleController = require("role_controller");
 
var Battle_drama_mapWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("battledrama", "battle_drama_map_windows");
    this.viewTag = SCENE_TAG.ui; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Big; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
 
    this.ctrl = arguments[0];
    this.model = this.ctrl.getModel();
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {},
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.root_wnd.getChildByName("backgroundGroup");
    this.graphics = this.background.getComponent(cc.Graphics);
    this.background.scale = FIT_SCALE;
    var main_container = this.root_wnd.getChildByName("main_container");
    this.main_container = main_container;
    this.map_layout = main_container.getChildByName("map_layout");
    this.pos_label = main_container.getChildByName("pos_label").getComponent(cc.Label);
    this.close_btn = main_container.getChildByName("close_btn");
    this.btn_world = main_container.getChildByName("btn_world"); //  画网格线
 
    var space = 50;
    var line_num_x = Math.floor(SCREEN_WIDTH / space / 2);
    var line_num_y = Math.floor(SCREEN_HEIGHT / space / 2);
 
    for (var i = 1; i <= line_num_y; i++) {
      // gcore.Timer.set(function () {
      var beginPos = cc.v2(-this.background.width / 2, i * space * 2 - this.background.height / 2);
      var endPos = cc.v2(SCREEN_WIDTH - this.background.width / 2, i * space * 2 - this.background.height / 2);
      this.graphics.moveTo(beginPos.x, beginPos.y);
      this.graphics.lineTo(endPos.x, endPos.y); // }.bind(this), 4 * i/ 60, 1);
    }
 
    for (var i = 1; i <= line_num_x; i++) {
      // gcore.Timer.set(function () {
      var beginPos = cc.v2(i * space * 2 - this.background.width / 2, -this.background.height / 2);
      var endPos = cc.v2(i * space * 2 - this.background.width / 2, SCREEN_HEIGHT - this.background.height / 2);
      this.graphics.moveTo(beginPos.x, beginPos.y);
      this.graphics.lineTo(endPos.x, endPos.y); // }.bind(this), 4 * i/ 60, 1);
    }
 
    this.graphics.stroke();
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.close_btn, function () {
      this._onClickCloseBtn();
    }.bind(this), 2);
    Utils.onTouchEnd(this.btn_world, function () {
      this._onClickWorldBtn();
    }.bind(this), 1); //当用户点击的时候记录鼠标点击状态
 
    this.map_layout.on(cc.Node.EventType.TOUCH_START, function (event) {
      this.map_layout.stopAllActions();
      return true;
    }, this); //只有当用户鼠标按下才能拖拽
 
    this.map_layout.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
      var touches = event.getTouches();
      this.last_point = touches[0].getDelta();
      this.moveMapLayer(this.last_point.x, this.last_point.y);
    }, this); //当鼠标抬起的时候恢复状态
 
    this.map_layout.on(cc.Node.EventType.TOUCH_END, function (event) {
      if (this.last_point) {
        var pos_x = this.map_layout.x + this.last_point.x + 15;
 
        if (this.last_point.x < 0) {
          pos_x = this.map_layout.x + this.last_point.x - 15;
        }
 
        var return_pos = this.checkMapLayerPoint(pos_x);
        this.map_layout.stopAllActions();
        this.map_layout.runAction(cc.moveTo(0.4, return_pos));
      }
    }, this);
    this.addGlobalEvent(Battle_dramaEvent.BattleDrama_Update_Data, function (data) {
      if (data.chapter_id != this.chapter_id) {
        if (this.root_wnd) {
          this.drama_data = this.model.getDramaData();
          this.chapter_id = this.drama_data.chapter_id;
          this.updateMapImage();
          this.updateMapPoint();
          this.updateBaseInfo();
        }
      } else {
        if (this.root_wnd) {
          this.updateMapPointStatus();
        }
      }
    }.bind(this));
    this.addGlobalEvent(BattleEvent.MOVE_DRAMA_EVENT, function (combat_type) {
      if (combat_type == BattleConst.Fight_Type.Darma && this.drama_data && MainuiController.getInstance().checkIsInDramaUIFight()) {
        this.is_move_start = true;
        this.moveMapTag(true);
        this.ctrl.send13020();
      }
    }.bind(this));
    this.addGlobalEvent(Battle_dramaEvent.UpdateDramaProgressDataEvent, function (val) {
      var val_str = val / 1000 + "%";
      this.progress_label.string = cc.js.formatStr(Utils.TI18N("已超过<color=5df660>%s</color>的玩家进度"), val_str);
    }.bind(this));
  },
  moveMapLayer: function moveMapLayer(x, y) {
    x = this.map_layout.x + x;
    y = this.map_layout.y + y;
    var return_pos = this.checkMapLayerPoint(x, y);
    this.map_layout.setPosition(return_pos.x, return_pos.y);
  },
  checkMapLayerPoint: function checkMapLayerPoint(x, y) {
    var map_layout_size = this.map_layout.getContentSize();
 
    if (x > 0) {
      x = 0;
    } else if (x < SCREEN_WIDTH - map_layout_size.width) {
      x = SCREEN_WIDTH - map_layout_size.width;
    }
 
    return cc.v2(x, 0);
  },
  _onClickCloseBtn: function _onClickCloseBtn() {
    this.ctrl.openBattleDramaMapWindows(false);
  },
  _onClickWorldBtn: function _onClickWorldBtn() {
    var WorldmapController = require("worldmap_controller");
 
    WorldmapController.getInstance().openWorldMapMainWindow(true);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(chapter_id) {
    this.drama_data = this.model.getDramaData();
 
    if (this.drama_data && Utils.next(this.drama_data) != null) {
      this.chapter_id = chapter_id || this.drama_data.chapter_id;
      this.updateMapImage();
      this.updateMapPoint();
      this.updateBaseInfo();
      this.ctrl.send13020();
    }
  },
  // 更新基础信息
  updateBaseInfo: function updateBaseInfo() {
    if (this.drama_data) {
      var drama_config = gdata("dungeon_data", "data_drama_dungeon_info", this.drama_data.dun_id);
 
      if (drama_config) {
        this.pos_label.string = cc.js.formatStr(Utils.TI18N("当前关卡:%s"), drama_config.name);
      }
    }
  },
  //  更新地图资源
  updateMapImage: function updateMapImage() {
    var _config = Config.dungeon_data.data_drama_world_info[this.drama_data.mode];
 
    if (_config && _config[this.chapter_id]) {
      var map_id = _config[this.chapter_id].map_id;
      var map_bg_res = PathTool.getBattleSceneRes(cc.js.formatStr("%s/blayer/big_map", map_id), false);
 
      if (!this.map_bg) {
        this.map_bg = Utils.createImage(this.map_layout, null, 0, 130, cc.v2(0, 0));
        this.map_bg.type = cc.Sprite.Type.SIMPLE;
        this.map_bg.sizeMode = cc.Sprite.SizeMode.CUSTOM;
        this.map_bg.node.setContentSize(cc.size(1024, 1024));
      }
 
      this.loadRes(map_bg_res, function (resObject) {
        this.map_bg.spriteFrame = resObject;
        var map_bg_size = this.map_bg.node.getContentSize();
        this.map_layout.setContentSize(cc.size(map_bg_size.width, 1280));
      }.bind(this));
    }
  },
  //  更新地图节点
  updateMapPoint: function updateMapPoint() {
    if (this.main_point_list && Utils.next(this.main_point_list || []) != null) {
      for (var i in this.main_point_list) {
        if (this.main_point_list[i]) {
          this.main_point_list[i].clearInfo();
          this.main_point_list[i].DeleteMe();
        }
      }
    }
 
    this.main_point_list = [];
    var dun_data = this.model.getInitDungeonList();
 
    if (dun_data) {
      var item = null;
      var createNextNum = 0;
 
      for (var i in dun_data) {
        var v = dun_data[i];
        v.v_data = this.model.getCurDunInfoByID(v.info_data.id);
        var isCreate = false;
 
        if (v.v_data.status > 0) {
          isCreate = true;
        } else if (createNextNum <= 0) {
          createNextNum = 1;
          isCreate = true;
        }
 
        if (isCreate) {
          Utils.delayRun(this.main_container, 4 * i / 40, function (v) {
            if (!this.main_point_list[v.info_data.id]) {
              item = new BattleDramaMainPointItem();
              this.main_point_list[v.info_data.id] = item;
 
              if (this.map_layout) {
                this.map_layout.addChild(item.root_wnd, 98);
              }
            }
 
            item = this.main_point_list[v.info_data.id];
 
            if (item) {
              item.setPosition(v.info_data.pos[0], v.info_data.pos[1] + 130);
              item.setData(v);
            }
          }.bind(this, v));
        }
      }
    }
 
    if (!this.cur_tag_container) {
      this.cur_tag_container = new cc.Node();
      this.cur_tag_container.setContentSize(cc.size(50, 50));
      this.cur_tag_container.setAnchorPoint(cc.v2(0.5, 0.5));
      this.map_layout.addChild(this.cur_tag_container, 99);
      this.createRole(PlayerAction.battle_stand);
    }
 
    this.updateMapPointStatus();
  },
  createRole: function createRole(action_name) {
    if (this.spine_model) {
      this.spine_model.deleteMe();
      this.spine_model = null;
    }
 
    if (!this.spine_model) {
      this.cur_action_name = action_name;
      var look_id = RoleController.getInstance().getRoleVo().look_id;
      var res_id = "110401"; // 默认显示该模型
 
      res_id = look_id || res_id;
      this.spine_model = new BaseRole();
      this.spine_model.setParent(this.cur_tag_container);
      this.spine_model.setData(BaseRole.type.role, res_id, action_name, true, 0.7);
 
      if (this.spine_model.node) {
        this.spine_model.node.scaleX = 0.7 * this.getDir();
        this.spine_model.node.setPosition(this.cur_tag_container.getContentSize().width / 2, -15);
      }
 
      var height = this.spine_model.node.getBoundingBox().height || 90;
 
      if (!this.cur_effect) {
        var node = new cc.Node();
        node.setContentSize(cc.size(25, 130));
        node.setAnchorPoint(0.5, 0.5);
        node.setPosition(25, height);
        this.cur_tag_container.addChild(node);
        this.cur_effect = node.addComponent(sp.Skeleton);
        var anima_path = PathTool.getSpinePath(Config.effect_data.data_effect_info[105], "action");
        this.loadRes(anima_path, function (ske_data) {
          this.cur_effect.skeletonData = ske_data;
          this.cur_effect.setAnimation(0, PlayerAction.action, true);
        }.bind(this));
      }
 
      if (!this.progress_bg) {
        this.progress_bg = Utils.createImage(this.cur_tag_container, null, this.cur_tag_container.getContentSize().width / 2, -35, cc.v2(0.5, 0.5));
        this.progress_bg.node.scaleX = 9.4;
        this.loadRes(PathTool.getUIIconPath("battledrama", "battledrama_1012"), function (resObject) {
          this.progress_bg.spriteFrame = resObject;
        }.bind(this));
      }
 
      if (!this.progress_label) {
        this.progress_label = Utils.createRichLabel(16, new cc.Color(0xff, 0xff, 0xff, 0xff), cc.v2(0.5, 0.5), cc.v2(this.cur_tag_container.getContentSize().width / 2, -35), 30);
        this.cur_tag_container.addChild(this.progress_label.node);
        this.progress_label.string = Utils.TI18N("已超过<color=5df660>?</color>的玩家进度");
      }
    }
  },
  getDir: function getDir() {
    var scale = 1;
    var item = this.main_point_list[this.drama_data.dun_id];
 
    if (item) {
      var max_item = this.main_point_list[this.drama_data.max_dun_id];
      var cur_x = item.getPositionX();
      var max_x = 0;
 
      if (max_item) {
        max_x = max_item.getPositionX();
      }
 
      if (cur_x > max_x) {
        scale = 1;
      } else {
        scale = -1;
      }
    }
 
    return scale;
  },
  updateMapPointStatus: function updateMapPointStatus() {
    this.drama_data = this.model.getDramaData();
 
    if (this.drama_data) {
      var v_data = this.model.getCurDunInfoByID(this.drama_data.dun_id);
      var config = gdata("dungeon_data", "data_drama_dungeon_info", this.drama_data.dun_id);
 
      if (config) {
        if (this.main_point_list && this.main_point_list[this.drama_data.dun_id]) {
          var item = this.main_point_list[this.drama_data.dun_id];
          var is_big = config.is_big;
          item.updateStatus(v_data.status, is_big);
        }
 
        if (!this.is_move_start) {
          this.moveMapTag();
          this.is_move_start = true;
        }
      }
    }
  },
  //  移动角色形象
  moveMapTag: function moveMapTag(is_start) {
    if (this.drama_data) {
      var info_config = gdata("dungeon_data", "data_drama_dungeon_info", this.drama_data.dun_id);
 
      if (info_config) {
        var cur_main_point = info_config.pos;
 
        if (cur_main_point) {
          if (!is_start) {
            this.cur_tag_container.setPosition(cur_main_point[0] - 50 / 2, cur_main_point[1] + 140);
          } else {
            this.cur_tag_container.runAction(cc.sequence(cc.delayTime(0.1), cc.spawn(cc.callFunc(function () {
              this.createRole(PlayerAction.run);
            }.bind(this)), cc.moveTo(0.5, cc.v2(cur_main_point[0] - 50 / 2, cur_main_point[1] + 140))), cc.callFunc(function () {
              this.createRole(PlayerAction.battle_stand);
            }.bind(this))));
          }
        }
      }
    }
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.main_point_list) {
      for (var i in this.main_point_list) {
        if (this.main_point_list[i]) {
          this.main_point_list[i].DeleteMe();
        }
      }
    }
 
    if (this.spine_model) {
      this.spine_model.deleteMe();
      this.spine_model = null;
    }
 
    if (this.cur_effect) {
      this.cur_effect.setToSetupPose();
      this.cur_effect.clearTracks();
      this.cur_effect = null;
    }
 
    this.ctrl.openBattleDramaMapWindows(false);
  }
});
 
cc._RF.pop();