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
"use strict";
cc._RF.push(module, '7f86aaVA5BKhbErVZ2PRfV/', 'worldmap_land');
// Scripts/mod/worldmap/view/worldmap_land.js
 
"use strict";
 
var _partner_event = require("../../partner/partner_event");
 
// -- --------------------------------------------------------------------
// -- 
// -- 
// -- @author: mengjiabin@syg.com(必填, 创建模块的人员)
// -- @editor: mengjiabin@syg.com(必填, 后续维护以及修改的人员)
// -- @description:
// --      世界地图大陆板块
// -- <br/>Create: 2018-xx-xx
// -- --------------------------------------------------------------------
var WorldMapLand = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.config = arguments[0];
    this.land_id = arguments[1];
    this.click_callback = arguments[2];
    this.size = cc.size(100, 38);
    this.scale = 2;
    this.item_list = {};
    this.had_unlock = false;
    this.open_chapter_data = arguments[3];
    this.createRootWnd();
  },
  // 初始化UI
  createRootWnd: function createRootWnd() {
    this.root_wnd = new cc.Node("lang_item");
    this.root_wnd.setAnchorPoint(0.5, 0);
    this.root_wnd.setContentSize(this.size);
 
    if (this.land_id >= this.config.bid) {
      this.name_container = Utils.createImage(this.root_wnd, null, this.config.name_x - 50, this.config.name_y, cc.v2(0.5, 0.5), false);
      LoaderManager.getInstance().loadRes(PathTool.getUIIconPath("worldmap", "worldmap_1007"), function (res_object) {
        this.name_container.spriteFrame = res_object;
      }.bind(this));
      this.name_label = Utils.createLabel(20, new cc.Color(0xff, 0xff, 0xff, 0xff), new cc.Color(0x0a, 0x0f, 0x0f, 0xff), 0, 10, this.config.name, this.name_container.node, 1, cc.v2(0.5, 0.5)); // this.name_label:setLocalZOrder(9)
 
      this.had_unlock = true;
    } else {
      if (this.config.bid > 1) {
        LoaderManager.getInstance().loadRes(PathTool.getBigBg(cc.js.formatStr("worldmap_100%s", this.config.bid), null, "worldmap"), function (res_object) {
          this.mainland = Utils.createImage(this.root_wnd, null, this.size.width * 0.5 - 50, this.size.height * 0.5, cc.v2(0.5, 0.5), false);
          this.mainland.node.setScale(this.scale);
          this.mainland.spriteFrame = res_object;
        }.bind(this));
      }
    } //  绘制点击区域,不做像素监测了,直接做一个不相互压住的做点击判断,只有解锁的才做点击响应
 
 
    if (this.had_unlock == true) {
      this.click_layout = new cc.Node();
      this.click_layout.setAnchorPoint(0.5, 0.5);
      this.root_wnd.addChild(this.click_layout, 10);
 
      if (this.config.bid == 1) {
        this.click_layout.setPosition(4, -14);
        this.click_layout.setContentSize(cc.size(440, 300));
      } else if (this.config.bid == 2) {
        this.click_layout.setPosition(-7, 17);
        this.click_layout.setContentSize(cc.size(600, 200));
      } else if (this.config.bid == 3) {
        this.click_layout.setPosition(81, -5);
        this.click_layout.setContentSize(cc.size(500, 300));
      } else if (this.config.bid == 4) {
        this.click_layout.setPosition(-28, 49);
        this.click_layout.setContentSize(cc.size(200, 380));
      } else if (this.config.bid == 5) {
        this.click_layout.setPosition(44, 14);
        this.click_layout.setContentSize(cc.size(200, 380));
      }
    }
 
    this.registerEvent();
  },
  registerEvent: function registerEvent() {
    //当用户点击的时候记录鼠标点击状态
    if (this.click_layout) {
      this.click_layout.on(cc.Node.EventType.TOUCH_START, function (event) {
        var touches = event.getTouches();
        this.touch_began = touches[0].getLocation();
      }, this);
    }
 
    if (this.click_layout) {
      //当鼠标抬起的时候恢复状态
      this.click_layout.on(cc.Node.EventType.TOUCH_END, function (event) {
        var touches = event.getTouches();
        this.touch_end = touches[0].getLocation();
        var is_click = true;
 
        if (this.touch_began != null) {
          is_click = Math.abs(this.touch_end.x - this.touch_began.x) <= 20 && Math.abs(this.touch_end.y - this.touch_began.y) <= 20;
        }
 
        if (is_click == true) {
          this.clickHandler();
        }
      }, this);
    }
  },
  // 点击大陆板块的回调处理,这个时候就选中当前的
  clickHandler: function clickHandler() {
    if (this.click_callback) {
      this.click_callback(this);
    }
  },
  addToParent: function addToParent(parent) {
    if (parent && this.config && this.root_wnd) {
      parent.addChild(this.root_wnd);
      this.root_wnd.setPosition(this.config.x, this.config.y - 640);
    }
  },
  // 设置选中大陆,这个时候会创建大陆板块上面的据点或者隐藏
  setSelectedLand: function setSelectedLand(status) {
    if (status == true) {
      if (this.item_list) {
        for (var i in this.item_list) {
          this.item_list[i].clearEffect();
        }
      }
 
      if (this.name_container) {
        this.name_container.node.active = false;
      }
 
      if (this.click_layout) {
        this.click_layout.active = false;
      }
 
      if (this.item_container == null) {
        this.item_container = new cc.Node();
        this.item_container.setContentSize(this.size);
        this.item_container.setAnchorPoint(cc.v2(0, 0));
        this.item_container.setPosition(cc.v2(-70, -30));
        this.root_wnd.addChild(this.item_container);
      }
 
      this.item_container.active = true;
      this.createItemList();
    } else {
      if (this.click_layout) {
        this.click_layout.active = true;
      }
 
      if (this.name_container) {
        this.name_container.node.active = true;
      }
 
      if (this.item_container) {
        this.item_container.active = false;
      }
    }
  },
  createItemList: function createItemList() {
    if (this.config != null && this.config.dungeon_list != null) {
      var call_back = function () {
        if (this.item_list) {
          for (var i in this.item_list) {
            this.item_list[i].clearEffect();
          }
        }
      }.bind(this);
 
      for (var i in this.config.dungeon_list) {
        var v = this.config.dungeon_list[i];
 
        if (this.item_list[v.bid] == null) {
          var WorldMapItem = require("worldmap_item");
 
          this.item_list[v.bid] = new WorldMapItem(v, this.open_chapter_data);
          this.item_list[v.bid].addToParent(this.item_container, call_back);
        }
      }
    }
  },
  // 删掉的时候关闭
  DeleteMe: function DeleteMe() {
    if (this.item_container) {
      this.item_container.stopAllActions();
    }
 
    for (var i in this.item_list) {
      this.item_list[i].DeleteMe();
    }
 
    this.item_list = null;
  }
});
 
cc._RF.pop();