@@ -181,19 +181,6 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
181181 }
182182 } ,
183183
184- /**
185- * Adds a child to the container.
186- * @param {ccs.Widget } child
187- */
188- addChild : function ( child , zOrder , tag ) {
189- if ( ! ( child instanceof ccs . Widget ) ) {
190- cc . log ( "Widget only supports Widgets as children" ) ;
191- return ;
192- }
193- cc . NodeRGBA . prototype . addChild . call ( this , child , zOrder , tag ) ;
194- this . _widgetChildren . push ( child ) ;
195- } ,
196-
197184 sortAllChildren : function ( ) {
198185 this . _reorderWidgetChildDirty = this . _reorderChildDirty ;
199186 cc . NodeRGBA . prototype . sortAllChildren . call ( this ) ;
@@ -223,6 +210,41 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
223210 }
224211 } ,
225212
213+ /**
214+ * Adds a child to the container.
215+ * @param {ccs.Widget } widget
216+ * @param {Number } zOrder
217+ * @param {Number } tag
218+ */
219+ addChild : function ( widget , zOrder , tag ) {
220+ if ( widget instanceof ccs . Widget ) {
221+ cc . NodeRGBA . prototype . addChild . call ( this , widget , zOrder , tag ) ;
222+ this . _widgetChildren . push ( widget ) ;
223+ return ;
224+ }
225+ if ( widget instanceof cc . Node ) {
226+ cc . log ( "Please use addNode to add a CCNode." ) ;
227+ return ;
228+ }
229+ } ,
230+
231+ /**
232+ *
233+ * @param tag
234+ * @returns {ccs.Widget }
235+ */
236+ getChildByTag :function ( tag ) {
237+ var __children = this . _widgetChildren ;
238+ if ( __children != null ) {
239+ for ( var i = 0 ; i < __children . length ; i ++ ) {
240+ var node = __children [ i ] ;
241+ if ( node && node . _tag == tag )
242+ return node ;
243+ }
244+ }
245+ return null ;
246+ } ,
247+
226248 /**
227249 * Return an array of children
228250 * @returns {Array }
@@ -236,7 +258,7 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
236258 * @returns {Number }
237259 */
238260 getChildrenCount : function ( ) {
239- return this . _widgetChildren ? this . _widgetChildren . length : 0 ;
261+ return this . _widgetChildren . length ;
240262 } ,
241263
242264 getWidgetParent : function ( ) {
@@ -247,22 +269,18 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
247269 return null ;
248270 } ,
249271
250- removeFromParent : function ( cleanup ) {
251- cc . NodeRGBA . prototype . removeFromParent . call ( this , cleanup ) ;
252- } ,
253-
254- removeFromParentAndCleanup : function ( cleanup ) {
255- cc . NodeRGBA . prototype . removeFromParent . call ( this , cleanup ) ;
256- } ,
257-
258272 /**
259273 * remove child
260- * @param {ccs.Widget } child
274+ * @param {ccs.Widget } widget
261275 * @param {Boolean } cleanup
262276 */
263- removeChild : function ( child , cleanup ) {
264- cc . NodeRGBA . prototype . removeChild . call ( this , child , cleanup ) ;
265- cc . ArrayRemoveObject ( this . _widgetChildren , child ) ;
277+ removeChild : function ( widget , cleanup ) {
278+ if ( ! ( widget instanceof ccs . Widget ) ) {
279+ cc . log ( "child must a type of ccs.Widget" ) ;
280+ return ;
281+ }
282+ cc . NodeRGBA . prototype . removeChild . call ( this , widget , cleanup ) ;
283+ cc . ArrayRemoveObject ( this . _widgetChildren , widget ) ;
266284 } ,
267285
268286 removeChildByTag : function ( tag , cleanup ) {
@@ -280,12 +298,11 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
280298 * Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter.
281299 */
282300 removeAllChildren : function ( cleanup ) {
283- var childrenLength = this . _widgetChildren . length ;
284- if ( childrenLength <= 0 ) {
285- return
301+ for ( var i = 0 ; i < this . _widgetChildren . length ; i ++ ) {
302+ var widget = this . _widgetChildren [ i ] ;
303+ cc . NodeRGBA . prototype . removeChild . call ( this , widget , cleanup ) ;
286304 }
287- cc . NodeRGBA . prototype . removeAllChildren . call ( this , cleanup ) ;
288- this . _widgetChildren = [ ] ;
305+ this . _widgetChildren . length = 0 ;
289306 } ,
290307
291308 /**
@@ -332,7 +349,7 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
332349 */
333350 addNode : function ( node , zOrder , tag ) {
334351 if ( node instanceof ccs . Widget ) {
335- cc . log ( "Widget only supports Nodes as renderer " ) ;
352+ cc . log ( "Please use addChild to add a Widget. " ) ;
336353 return ;
337354 }
338355 cc . NodeRGBA . prototype . addChild . call ( this , node , zOrder , tag ) ;
@@ -345,8 +362,9 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
345362 * @returns {cc.Node }
346363 */
347364 getNodeByTag : function ( tag ) {
348- for ( var i = 0 ; i < this . _nodes . length ; i ++ ) {
349- var node = this . _nodes [ i ] ;
365+ var _nodes = this . _nodes ;
366+ for ( var i = 0 ; i < _nodes . length ; i ++ ) {
367+ var node = _nodes [ i ] ;
350368 if ( node && node . getTag ( ) == tag ) {
351369 return node ;
352370 }
@@ -365,17 +383,19 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
365383 /**
366384 * remove node
367385 * @param {cc.Node } node
386+ * @param {Boolean } cleanup
368387 */
369- removeNode : function ( node ) {
388+ removeNode : function ( node , cleanup ) {
370389 cc . NodeRGBA . prototype . removeChild . call ( this , node ) ;
371390 cc . ArrayRemoveObject ( this . _nodes , node ) ;
372391 } ,
373392
374393 /**
375394 * remove node by tag
376- * @param tag
395+ * @param {Number } tag
396+ * @param {Boolean } cleanup
377397 */
378- removeNodeByTag : function ( tag ) {
398+ removeNodeByTag : function ( tag , cleanup ) {
379399 var node = this . getNodeByTag ( tag ) ;
380400 if ( ! node ) {
381401 cc . log ( "cocos2d: removeNodeByTag(tag = %d): child not found!" , tag ) ;
@@ -393,7 +413,7 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
393413 var node = this . _nodes [ i ] ;
394414 cc . NodeRGBA . prototype . removeChild . call ( this , node ) ;
395415 }
396- this . _nodes = [ ] ;
416+ this . _nodes . length = 0 ;
397417 } ,
398418
399419 /**
0 commit comments