Skip to content

Commit 98c96b5

Browse files
committed
Make PageView indicator more tunable:
-add possibility to change texture of index nodes -add possibility to change color of index nodes -add possibility to change scale of index nodes
1 parent ff19fd2 commit 98c96b5

File tree

2 files changed

+185
-3
lines changed

2 files changed

+185
-3
lines changed

Diff for: extensions/ccui/uiwidgets/scroll-widget/UIPageView.js

+59
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,65 @@ ccui.PageView = ccui.ListView.extend(/** @lends ccui.PageView# */{
544544
{
545545
cc.assert(this._indicator !== null, "");
546546
return this._indicator.getSelectedIndexColor();
547+
},
548+
549+
/**
550+
* Set color of page indicator's index nodes.
551+
* @param {cc.Color} color Color for indicator
552+
*/
553+
setIndicatorIndexNodesColor: function(color)
554+
{
555+
if(this._indicator)
556+
{
557+
this._indicator.setIndexNodesColor(color);
558+
}
559+
},
560+
561+
/**
562+
* Get the color of page indicator's index nodes.
563+
* @returns {cc.Color}
564+
*/
565+
getIndicatorIndexNodesColor: function()
566+
{
567+
cc.assert(this._indicator !== null, "");
568+
return this._indicator.getIndexNodesColor();
569+
},
570+
571+
/**
572+
* Set scale of page indicator's index nodes.
573+
* @param {Number} scale Scale for indicator
574+
*/
575+
setIndicatorIndexNodesScale: function(indexNodesScale)
576+
{
577+
if(this._indicator)
578+
{
579+
this._indicator.setIndexNodesScale(indexNodesScale);
580+
this._indicator.indicate(this._curPageIdx);
581+
}
582+
},
583+
584+
/**
585+
* Get the scale of page indicator's index nodes.
586+
* @returns {Number}
587+
*/
588+
getIndicatorIndexNodesScale: function()
589+
{
590+
cc.assert(this._indicator !== null, "");
591+
return this._indicator.getIndexNodesScale();
592+
},
593+
594+
/**
595+
* Sets texture of indicator index nodes
596+
* @param {String} texName
597+
* @param {ccui.Widget.LOCAL_TEXTURE | ccui.Widget.PLIST_TEXTURE} [texType = ccui.Widget.LOCAL_TEXTURE]
598+
*/
599+
setIndicatorIndexNodesTexture: function(texName, texType)
600+
{
601+
if(this._indicator)
602+
{
603+
this._indicator.setIndexNodesTexture(texName, texType);
604+
this._indicator.indicate(this._curPageIdx);
605+
}
547606
}
548607
});
549608
/**

Diff for: extensions/ccui/uiwidgets/scroll-widget/UIPageViewIndicator.js

+126-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
3535
_indexNodes: null,
3636
_currentIndexNode: null,
3737
_spaceBetweenIndexNodes: 0,
38+
_indexNodesScale: 1.0,
39+
_indexNodesColor: null,
40+
_useDefaultTexture: true,
41+
_indexNodesTextureFile: "",
42+
_indexNodesTexType: ccui.Widget.LOCAL_TEXTURE,
43+
3844
_className: "PageViewIndicator",
3945

4046
/**
@@ -47,6 +53,7 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
4753
this._direction = ccui.ScrollView.DIR_HORIZONTAL;
4854
this._indexNodes = [];
4955
this._spaceBetweenIndexNodes = ccui.PageViewIndicator.SPACE_BETWEEN_INDEX_NODES_DEFAULT;
56+
this._indexNodesColor = cc.color.WHITE;
5057

5158
this.init();
5259

@@ -188,12 +195,128 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
188195
return this._currentIndexNode.getColor();
189196
},
190197

198+
/**
199+
* Sets color of index nodes
200+
* @param {cc.Color} indexNodesColor
201+
*/
202+
setIndexNodesColor: function(indexNodesColor)
203+
{
204+
this._indexNodesColor = indexNodesColor;
205+
206+
for(var i = 0 ; i < this._indexNodes.length; ++i)
207+
{
208+
this._indexNodes[i].setColor(indexNodesColor);
209+
}
210+
},
211+
212+
/**
213+
* Gets color of index nodes
214+
* @returns {cc.Color}
215+
*/
216+
getIndexNodesColor: function()
217+
{
218+
var locRealColor = this._indexNodesColor;
219+
return cc.color(locRealColor.r, locRealColor.g, locRealColor.b, locRealColor.a);
220+
},
221+
222+
/**
223+
* Sets scale of index nodes
224+
* @param {Number} indexNodesScale
225+
*/
226+
setIndexNodesScale: function(indexNodesScale)
227+
{
228+
if(this._indexNodesScale === indexNodesScale)
229+
{
230+
return;
231+
}
232+
this._indexNodesScale = indexNodesScale;
233+
234+
this._currentIndexNode.setScale(indexNodesScale);
235+
236+
for(var i = 0 ; i < this._indexNodes.length; ++i)
237+
{
238+
this._indexNodes[i].setScale(this,_indexNodesScale);
239+
}
240+
241+
this._rearrange();
242+
},
243+
244+
/**
245+
* Gets scale of index nodes
246+
* @returns {Number}
247+
*/
248+
getIndexNodesScale: function()
249+
{
250+
return this._indexNodesScale;
251+
},
252+
253+
/**
254+
* Sets texture of index nodes
255+
* @param {String} texName
256+
* @param {ccui.Widget.LOCAL_TEXTURE | ccui.Widget.PLIST_TEXTURE} [texType = ccui.Widget.LOCAL_TEXTURE]
257+
*/
258+
setIndexNodesTexture: function(texName, texType)
259+
{
260+
if(texType === undefined)
261+
texType = ccui.Widget.LOCAL_TEXTURE;
262+
263+
this._useDefaultTexture = false;
264+
this._indexNodesTextureFile = texName;
265+
this._indexNodesTexType = texType;
266+
267+
switch (texType)
268+
{
269+
case ccui.Widget.LOCAL_TEXTURE:
270+
this._currentIndexNode.setTexture(texName);
271+
for(var i = 0 ; i < this._indexNodes.length; ++i)
272+
{
273+
this._indexNodes[i].setTexture(texName);
274+
}
275+
break;
276+
case ccui.Widget.PLIST_TEXTURE:
277+
this._currentIndexNode.setSpriteFrame(texName);
278+
for(var i = 0 ; i < this._indexNodes.length; ++i)
279+
{
280+
this._indexNodes[i].setSpriteFrame(texName);
281+
}
282+
break;
283+
default:
284+
break;
285+
}
286+
287+
this._rearrange();
288+
},
289+
191290
_increaseNumberOfPages: function()
192291
{
193-
var image = new Image();
194-
image.src = ccui.PageViewIndicator.CIRCLE_IMAGE;
292+
var indexNode;
293+
294+
if(this._useDefaultTexture)
295+
{
296+
var image = new Image();
297+
image.src = ccui.PageViewIndicator.CIRCLE_IMAGE;
298+
299+
indexNode = new cc.Sprite(image);
300+
}
301+
else
302+
{
303+
indexNode = new cc.Sprite();
304+
switch (this._indexNodesTexType)
305+
{
306+
case ccui.Widget.LOCAL_TEXTURE:
307+
indexNode.initWithFile(this._indexNodesTextureFile);
308+
break;
309+
case ccui.Widget.PLIST_TEXTURE:
310+
indexNode.initWithSpriteFrameName(this._indexNodesTextureFile);
311+
break;
312+
default:
313+
break;
314+
}
315+
}
316+
317+
indexNode.setColor(this._indexNodesColor);
318+
indexNode.setScale(this._indexNodesScale);
195319

196-
var indexNode = new cc.Sprite(image);
197320
this.addProtectedChild(indexNode);
198321
this._indexNodes.push(indexNode);
199322
},

0 commit comments

Comments
 (0)