Skip to content

Commit ed478e5

Browse files
committed
Merge pull request #3266 from 1scaR1/develop
Make PageView indicator more tunable
2 parents 6054f1f + 98c96b5 commit ed478e5

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
@@ -533,6 +533,65 @@ ccui.PageView = ccui.ListView.extend(/** @lends ccui.PageView# */{
533533
{
534534
cc.assert(this._indicator !== null, "");
535535
return this._indicator.getSelectedIndexColor();
536+
},
537+
538+
/**
539+
* Set color of page indicator's index nodes.
540+
* @param {cc.Color} color Color for indicator
541+
*/
542+
setIndicatorIndexNodesColor: function(color)
543+
{
544+
if(this._indicator)
545+
{
546+
this._indicator.setIndexNodesColor(color);
547+
}
548+
},
549+
550+
/**
551+
* Get the color of page indicator's index nodes.
552+
* @returns {cc.Color}
553+
*/
554+
getIndicatorIndexNodesColor: function()
555+
{
556+
cc.assert(this._indicator !== null, "");
557+
return this._indicator.getIndexNodesColor();
558+
},
559+
560+
/**
561+
* Set scale of page indicator's index nodes.
562+
* @param {Number} scale Scale for indicator
563+
*/
564+
setIndicatorIndexNodesScale: function(indexNodesScale)
565+
{
566+
if(this._indicator)
567+
{
568+
this._indicator.setIndexNodesScale(indexNodesScale);
569+
this._indicator.indicate(this._curPageIdx);
570+
}
571+
},
572+
573+
/**
574+
* Get the scale of page indicator's index nodes.
575+
* @returns {Number}
576+
*/
577+
getIndicatorIndexNodesScale: function()
578+
{
579+
cc.assert(this._indicator !== null, "");
580+
return this._indicator.getIndexNodesScale();
581+
},
582+
583+
/**
584+
* Sets texture of indicator index nodes
585+
* @param {String} texName
586+
* @param {ccui.Widget.LOCAL_TEXTURE | ccui.Widget.PLIST_TEXTURE} [texType = ccui.Widget.LOCAL_TEXTURE]
587+
*/
588+
setIndicatorIndexNodesTexture: function(texName, texType)
589+
{
590+
if(this._indicator)
591+
{
592+
this._indicator.setIndexNodesTexture(texName, texType);
593+
this._indicator.indicate(this._curPageIdx);
594+
}
536595
}
537596
});
538597
/**

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
var image = new Image();
5259
image.src = ccui.PageViewIndicator.CIRCLE_IMAGE;
@@ -174,12 +181,128 @@ ccui.PageViewIndicator = ccui.ProtectedNode.extend(/** @lends ccui.PageViewIndic
174181
return this._currentIndexNode.getColor();
175182
},
176183

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

182-
var indexNode = new cc.Sprite(image);
183306
this.addProtectedChild(indexNode);
184307
this._indexNodes.push(indexNode);
185308
},

0 commit comments

Comments
 (0)