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
"use strict";
cc._RF.push(module, 'fbdb9UbFnJAFp1QhzS6W3lv', 'basepanel');
// Scripts/common/basepanel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      基础标签页或者独立的panel
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var LoaderManager = require("loadermanager");
 
var ViewClass = require("viewclass");
 
window.BasePanel = cc.Class({
  "extends": ViewClass,
  ctor: function ctor() {
    this.scale = 1;
    this.x = 0;
    this.y = 0;
    this.initConfig();
    this.root_wnd = null;
  },
  wating: false,
  prefabPath: "",
  // 预设路径
  loading: false,
  // 是否在加载中
  fastShowThenHide: false,
  // 还没有异步加载完成,就要隐藏掉了
  isFirstOpen: false,
  // 是否是第一次打开
  setParent: function setParent(parent) {
    this._super(parent);
 
    this.isInLoading = false, this.fastShowThenHide = false, this.isFirstOpen = true;
    this.base_view_event_list = {};
    this.res_list = {};
    this.visible = true;
 
    if (this.root_wnd && parent instanceof cc.Node) {
      this.root_wnd.parent = parent;
    }
  },
  // 子类实现具体的,比如说监听事件,或者其他
  initConfig: function initConfig() {},
  initPanel: function initPanel() {},
  registerEvent: function registerEvent() {},
  onShow: function onShow() {},
  onHide: function onHide() {},
  onDelete: function onDelete() {},
  // 加载预设
  onLoadPanel: function onLoadPanel() {
    var self = this;
 
    if (!this.waiting_timer && this.wating && !window.hide_loading) {
      this.waiting_timer = gcore.Timer.set(function () {
        this.is_wating = true;
        game.updateWaitingStatus(WaitingStaus.LOADING);
      }.bind(this), 1500, 1);
    }
 
    LoaderManager.getInstance().loadRes(this.prefabPath, function (res_object) {
      // if (error) {
      //     cc.log("加载Prefab失败,原因:" + error);
      //     return;
      // }
      if (self.waiting_timer) {
        gcore.Timer.del(self.waiting_timer);
        self.waiting_timer = null;
      }
 
      if (self.is_wating) {
        game.updateWaitingStatus();
        self.is_wating = false;
      }
 
      if (self["delete"] || !self.parent._children) {
        return;
      }
 
      self.root_wnd = res_object;
      self.root_wnd.parent = self.parent;
      self.root_wnd.scale = self.scale;
 
      if (self.zIndex) {
        self.setZIndex(self.zIndex);
      }
 
      if (!self.visible) {
        self.setVisible(false);
      } // self.root_wnd.active = self.visible;
 
 
      if (self.zIndex && self.zIndex >= 0) {
        self.root_wnd.zIndex = self.zIndex;
      } // 缓存位置
 
 
      if (self.cache_x != null && self.cache_y != null) {
        self.root_wnd.setPosition(self.cache_x, self.cache_y);
        self.cache_x = null;
        self.cache_y = null;
      }
 
      if (self.cache_ap_y != null && self.cache_ap_x != null) {
        self.root_wnd.setAnchorPoint(self.cache_ap_x, self.cache_ap_y);
        self.cache_ap_x = null;
        self.cache_ap_y = null;
      } // 第一次打开直接回调初始化.获取对象或者组件
 
 
      if (self.isFirstOpen == true) {
        self.isFirstOpen = false;
        self.initPanel();
        self.registerEvent();
      }
 
      self.isInLoading = false; // 加载完成之后,需要判断是否有逻辑隐藏掉
 
      if (self.fastShowThenHide == true) {
        self.fastShowThenHide = false; // self.root_wnd.active = false;
 
        self.setVisible(false);
      } else {
        self.onShow(self.open_params);
      }
 
      if (self.root_wnd && self.root_wnd.getComponent(cc.Widget)) {
        self.roow_wdg = self.root_wnd.getComponent(cc.Widget);
      }
 
      if (self.root_wnd_cb) self.root_wnd_cb(self.root_wnd);
    });
  },
  // 显示窗体处理
  show: function show(params) {
    if (this.isInLoading == true) {
      return;
    }
 
    this.open_params = params;
 
    if (this.root_wnd == null) {
      this.isInLoading = true;
      this.onLoadPanel();
    } else {
      this.isInLoading = false; // this.root_wnd.active = true;
 
      if (this.root_wnd.active) this.setVisible(true);
      this.onShow(params);
    }
  },
  // 关掉窗体
  hide: function hide() {
    if (this.root_wnd) {
      this.setVisible(false); // this.root_wnd.active = false;
 
      this.onHide();
    } else {
      this.fastShowThenHide = true;
    }
  },
  // 是否可见
  setVisible: function setVisible(status, dir) {
    this.visible = status;
 
    if (this.root_wnd) {
      if (status) {
        if (this.roow_wdg) {
          this.roow_wdg.alignMode = cc.Widget.AlignMode.ON_WINDOW_RESIZE;
        }
 
        this.setPosition(this.x, this.y);
        this.cur_visible = false;
      } else {
        if (!this.cur_visible) {
          if (this.roow_wdg) {
            this.roow_wdg.alignMode = cc.Widget.AlignMode.ONCE;
          }
 
          if (dir == ScrollViewDir.vertical) {
            this.root_wnd.x -= cc.winSize.width * 2;
          } else if (dir == ScrollViewDir.horizontal) {
            this.root_wnd.x -= cc.winSize.height * 2;
            this.root_wnd.y -= cc.winSize.height * 2;
          } else {
            this.root_wnd.x -= cc.winSize.width * 2;
          } // this.visible_x = this.root_wnd.x;
 
 
          this.cur_visible = true;
        }
      } // this.root_wnd.active = status;
 
 
      if (this.onVisible) this.onVisible(status);
    }
  },
  //新增一些不受cur_visible控制的显隐
  setActive: function setActive(status) {
    this.visible = status;
 
    if (this.root_wnd) {
      if (status) {
        this.setPosition(this.x, this.y);
      } else {
        this.root_wnd.x -= cc.winSize.width * 2;
      }
    }
  },
  isOpen: function isOpen() {
    if (this.root_wnd && !this.cur_visible) return true;
    return false;
  },
  setPosVisible: function setPosVisible() {
    if (this.root_wnd) this.root_wnd.x -= 1000;
  },
  getVisible: function getVisible() {
    return this.visible;
  },
  setScale: function setScale(scale) {
    this.scale = scale;
    if (this.root_wnd) this.root_wnd.scale = scale;
  },
  setZIndex: function setZIndex(zIndex) {
    this.zIndex = zIndex;
    if (this.root_wnd) this.root_wnd.zIndex = zIndex;
  },
  deleteMe: function deleteMe() {
    this["delete"] = true;
    this.onDelete();
 
    this._super(); // this.removeGlobalEvent();
    // if(this.root_wnd){
    //     this.root_wnd.destroyAllChildren();
    //     this.root_wnd.destroy();
    //     this.root_wnd = null;
    // }
    // // LoaderManager.getInstance().deleteRes(this.prefabPath);
    // LoaderManager.getInstance().releasePrefab(this.prefabPath);
    // for(var key in this.res_list){
    //     LoaderManager.getInstance().releaseRes(key)
    // }
 
  },
  // 设置坐标位置
  setPosition: function setPosition(x, y) {
    if (x == null || y == null) return;
    this.x = x;
    this.y = y;
 
    if (this.root_wnd) {
      this.root_wnd.setPosition(x, y);
    } else {
      this.cache_x = x;
      this.cache_y = y;
    }
  },
  // 设置锚点
  setAnchorPoint: function setAnchorPoint(x, y) {
    this.ap_x = x;
    this.ap_y = y;
 
    if (this.root_wnd) {
      this.root_wnd.setAnchorPoint(0.5, 0.5);
    } else {
      this.cache_ap_x = x;
      this.cache_ap_y = y;
    }
  },
  getPositionX: function getPositionX() {
    return this.x;
  },
  getPositionY: function getPositionY() {
    return this.y;
  },
  getRootWnd: function getRootWnd(cb) {
    this.root_wnd_cb = cb;
    if (this.root_wnd) this.root_wnd_cb(this.root_wnd);
  }
});
 
cc._RF.pop();