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
"use strict";
cc._RF.push(module, 'd63b5L717NIk7RrUbhm1PXP', 'viewclass');
// Scripts/common/viewclass.js
 
"use strict";
 
var LoaderManager = require("loadermanager");
 
window.ViewClass = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.active_status = true;
    this.base_view_event_list = {};
    this.res_list = {};
    this.update_timers = {};
    this.parent = null;
    this.ticks = {};
    this.rleasePrefab = true;
  },
 
  /**
   * 递归获取子节点
   * @Author   Zhx
   * @DateTime 2017-12-06
   * @param    {[type]}   parent 父节点
   * @param    {[type]}   uiName 子节点名称
   * @return   {[type]}          [description]
   */
  seekChild: function seekChild(parent, uiName, component) {
    if (!parent || !(typeof parent == "string") && !(parent instanceof cc.Node)) return;
 
    if (typeof parent == "string") {
      if (uiName && cc.js.isChildClassOf(uiName, cc.Component)) component = uiName;
      uiName = parent;
      parent = this.root_wnd;
    }
 
    if (uiName && cc.js.isChildClassOf(uiName, cc.Component)) component = uiName;
    if (parent.name === uiName) return parent;
    var childrens = parent.getChildren();
 
    for (var index in childrens) {
      var resultNode = this.seekChild(childrens[index], uiName, component);
 
      if (resultNode) {
        if (component) return resultNode.getComponent(component);
        return resultNode;
      }
    }
  },
  // 加载资源
  loadRes: function loadRes(path, callback) {
    if (this.res_list[path]) {
      if (this.root_wnd && this.root_wnd.isValid) {
        callback(this.res_list[path]);
      } else {
        console.log("节点已销毁", this.prefabPath);
      }
 
      return;
    } else {
      LoaderManager.getInstance().loadRes(path, function (res_object) {
        if (!this.isCache && (this.is_close || this["delete"])) {
          return;
        }
 
        if (!(res_object instanceof cc.Node)) this.res_list[path] = res_object;
 
        if (this.root_wnd && this.root_wnd.isValid) {
          callback(res_object);
        } else {
          console.log("节点已销毁", this.prefabPath);
        }
      }.bind(this));
    }
  },
  setParent: function setParent(parent) {
    this.parent = parent;
  },
  deleteMe: function deleteMe() {
    // this.iss
    cc.log("deleteMe", this.prefabPath);
    this.removeGlobalEvent();
 
    if (this.root_wnd && !this.isCache) {
      // this.root_wnd.destroyAllChildren();
      this.root_wnd.destroy();
      this.root_wnd = null;
    }
 
    if (this.mainloop_timer) gcore.Timer.del(this.mainloop_timer);
 
    for (var timer_i in this.update_timers) {
      if (this.update_timers[timer_i]) gcore.Timer.del(this.update_timers[timer_i]["timer"]);
      this.update_timers[timer_i] = null;
    } // LoaderManager.getInstance().deleteRes(this.prefabPath);
 
 
    for (var key in this.res_list) {
      LoaderManager.getInstance().releaseRes(key);
    }
 
    if (!this.isCache) {
      if (this.rleasePrefab) LoaderManager.getInstance().releasePrefab(this.prefabPath);
    }
  },
 
  /**
   * 添加通用监听事件
   * @param {*} eveny_type 
   * @param {*} callback 
   */
  addGlobalEvent: function addGlobalEvent(event_type, callback) {
    if (!event_type) return;
 
    if (!this.base_view_event_list[event_type]) {
      this.base_view_event_list[event_type] = gcore.GlobalEvent.bind(event_type, function () {
        if (callback) {
          for (var _len = arguments.length, value = new Array(_len), _key = 0; _key < _len; _key++) {
            value[_key] = arguments[_key];
          }
 
          callback.apply(this, value);
        }
      }.bind(this));
      return this.base_view_event_list[event_type];
    }
  },
  removeGlobalEvent: function removeGlobalEvent(event_hand) {
    if (!event_hand) {
      for (var key in this.base_view_event_list) {
        if (this.base_view_event_list[key]) gcore.GlobalEvent.unbind(this.base_view_event_list[key]);
      }
 
      this.base_view_event_list = null;
    } else {
      if (this.base_view_event_list[event_hand]) {
        gcore.GlobalEvent.unbind(this.base_view_event_list[event_hand]);
        delete this.base_view_event_list[event_hand];
      }
    }
  },
  startUpdate: function startUpdate(times, update_cb, interval) {
    times = times > 0 ? times : -1;
    interval = interval || 100;
 
    if (times > 0) {
      if (update_cb) {
        var timer_count = 0;
        var timer_index = null;
 
        for (var timer_i in this.update_timers) {
          if (!this.update_timers[timer_i]) {
            timer_index = timer_i;
            break;
          }
 
          timer_count += 1;
        }
 
        if (!timer_index) timer_index = "udpatetimer_" + timer_count;
        this.update_timers[timer_index] = {};
        this.update_timers[timer_index]["finish"] = 0;
        this.update_timers[timer_index]["times"] = times;
        this.update_timers[timer_index]["timer"] = gcore.Timer.set(function (callback, timer_index) {
          if (callback) callback(this.update_timers[timer_index]["finish"]);
 
          if (this.update_timers[timer_index]) {
            this.update_timers[timer_index]["finish"] += 1;
 
            if (this.update_timers[timer_index]["finish"] == this.update_timers[timer_index]["times"]) {
              gcore.Timer.del(this.update_timers[timer_index]["timer"]);
              this.update_timers[timer_index] = null;
            }
          }
        }.bind(this, update_cb, timer_index), interval, times);
        return this.update_timers[timer_index]["timer"];
      }
    } else {
      if (!this.mainloop_timer) {
        this.mainloop_timer = gcore.Timer.set(function () {
          if (this.update) this.update(200 / 1000);
        }.bind(this), 200, -1);
        return this.mainloop_timer;
      }
    }
  },
  stopUpdate: function stopUpdate(timer_hander) {
    if (timer_hander) {
      for (var timer_i in this.update_timers) {
        if (this.update_timers[timer_i] && this.update_timers[timer_i]["timer"] === timer_hander) {
          gcore.Timer.del(this.update_timers[timer_i]["timer"]);
          this.update_timers[timer_i] = null;
        }
      }
    } else {
      if (this.mainloop_timer) {
        gcore.Timer.del(this.mainloop_timer);
        this.mainloop_timer = null;
      }
    }
  },
  isOpen: function isOpen() {
    if (this.root_wnd && this.root_wnd.active) return true;
    return false;
  },
  addTicket: function addTicket(cf, interval, index) {
    interval = typeof parseInt(interval) == "number" ? interval * 1000 : 0;
    var tick_id = gcore.Timer.set(function (cb) {
      if (cb) cb();
    }.bind(this, cf), interval, 1);
    if (index) this.ticks[index] = tick_id;
  },
  delTicker: function delTicker(index) {
    if (this.ticks[index]) {
      gcore.Timer.del(this.ticks[index]);
      delete this.ticks[index];
    }
  },
  hasTicket: function hasTicket(index) {
    return !!this.ticks[index];
  },
  seekChildByTag: function seekChildByTag(parent, tag) {
    if (!parent) return;
 
    if (parent.ui_tag === tag) {
      return parent;
    }
 
    var childrens = parent.getChildren();
 
    for (var index in childrens) {
      var resultNode = this.seekChildByTag(childrens[index], tag);
      if (resultNode) return resultNode;
    }
  }
});
 
cc._RF.pop();