@@ -119,7 +119,7 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
119
119
_positionPercent : null ,
120
120
_reorderWidgetChildDirty : false ,
121
121
_hitted : false ,
122
-
122
+ _nodes : null ,
123
123
ctor : function ( ) {
124
124
cc . NodeRGBA . prototype . ctor . call ( this ) ;
125
125
this . _enabled = true ;
@@ -149,6 +149,7 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
149
149
this . _positionPercent = cc . PointZero ( ) ;
150
150
this . _reorderWidgetChildDirty = false ;
151
151
this . _hitted = false ;
152
+ this . _nodes = [ ] ;
152
153
} ,
153
154
154
155
/**
@@ -322,6 +323,77 @@ ccs.Widget = ccs.NodeRGBA.extend(/** @lends ccs.Widget# */{
322
323
initRenderer : function ( ) {
323
324
} ,
324
325
326
+ /**
327
+ * add node for widget
328
+ * @param {cc.Node } node
329
+ * @param {Number } zOrder
330
+ * @param {Number } tag
331
+ */
332
+ addNode : function ( node , zOrder , tag ) {
333
+ if ( node instanceof ccs . Widget ) {
334
+ cc . log ( "Widget only supports Nodes as renderer" ) ;
335
+ }
336
+ cc . NodeRGBA . prototype . addChild . call ( this , node , zOrder , tag ) ;
337
+ this . _nodes . push ( node ) ;
338
+ } ,
339
+
340
+ /**
341
+ * get node by tag
342
+ * @param {Number } tag
343
+ * @returns {cc.Node }
344
+ */
345
+ getNodeByTag : function ( tag ) {
346
+ for ( var i = 0 ; i < this . _nodes . length ; i ++ ) {
347
+ var node = this . _nodes [ i ] ;
348
+ if ( node && node . getTag ( ) == tag ) {
349
+ return node ;
350
+ }
351
+ }
352
+ return null ;
353
+ } ,
354
+
355
+ /**
356
+ * get all node
357
+ * @returns {Array }
358
+ */
359
+ getNodes : function ( ) {
360
+ return this . _nodes ;
361
+ } ,
362
+
363
+ /**
364
+ * remove node
365
+ * @param {cc.Node } node
366
+ */
367
+ removeNode : function ( node ) {
368
+ cc . NodeRGBA . prototype . removeChild . call ( this , node ) ;
369
+ cc . ArrayRemoveObject ( this . _nodes , node ) ;
370
+ } ,
371
+
372
+ /**
373
+ * remove node by tag
374
+ * @param tag
375
+ */
376
+ removeNodeByTag : function ( tag ) {
377
+ var node = this . getNodeByTag ( tag ) ;
378
+ if ( ! node ) {
379
+ cc . log ( "cocos2d: removeNodeByTag(tag = %d): child not found!" , tag ) ;
380
+ }
381
+ else {
382
+ this . removeNode ( node ) ;
383
+ }
384
+ } ,
385
+
386
+ /**
387
+ * remove all node
388
+ */
389
+ removeAllNodes : function ( ) {
390
+ for ( var i = 0 ; i < this . _nodes . length ; i ++ ) {
391
+ var node = this . _nodes [ i ] ;
392
+ cc . NodeRGBA . prototype . removeChild . call ( this , node ) ;
393
+ }
394
+ this . _nodes = [ ] ;
395
+ } ,
396
+
325
397
/**
326
398
* Changes the size that is widget's size
327
399
* @param {cc.Size } size
0 commit comments