Skip to content

Commit b21a4c5

Browse files
author
SeanLin
committed
Merge pull request #570 from ricardoquesada/menu-fixes
MenuToggle fixes
2 parents 199d31e + a31872c commit b21a4c5

File tree

1 file changed

+18
-52
lines changed

1 file changed

+18
-52
lines changed

cocos2d/menu_nodes/CCMenuItem.js

+18-52
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ cc.MenuItemFont = cc.MenuItemLabel.extend(/** @lends cc.MenuItemFont# */{
460460
/**
461461
* @param {Number} s
462462
*/
463-
setFontSizeObj:function (s) {
463+
setFontSize:function (s) {
464464
this._fontSize = s;
465465
this._recreateLabel();
466466
},
@@ -469,22 +469,22 @@ cc.MenuItemFont = cc.MenuItemLabel.extend(/** @lends cc.MenuItemFont# */{
469469
*
470470
* @return {Number}
471471
*/
472-
fontSizeObj:function () {
472+
fontSize:function () {
473473
return this._fontSize;
474474
},
475475

476476
/**
477477
* @param {String} name
478478
*/
479-
setFontNameObj:function (name) {
479+
setFontName:function (name) {
480480
this._fontName = name;
481481
this._recreateLabel();
482482
},
483483

484484
/**
485485
* @return {String}
486486
*/
487-
fontNameObj:function () {
487+
fontName:function () {
488488
return this._fontName;
489489
},
490490
_recreateLabel:function () {
@@ -1029,52 +1029,23 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{
10291029
},
10301030

10311031
/**
1032-
* @param {cc.Node} args[0] the first item in the args array is a target
1033-
* @param {function|String} args[1] the second item in the args array is the callback
1034-
* @param {cc.MenuItem} args[2+] the rest in the array are cc.MenuItems
1032+
* @param {cc.MenuItem} args[0...last-2] the rest in the array are cc.MenuItems
1033+
* @param {cc.Node} args[last-1] the first item in the args array is a target
1034+
* @param {function|String} args[last] the second item in the args array is the callback
10351035
* @return {Boolean}
10361036
*/
1037-
initWithCallback:function (args) {
1038-
if (args.length < 2) {
1039-
return false;
1040-
}
1041-
var target = args[0], selector = args[1];
1042-
this._super(target, selector);
1043-
if (args.length == 2) {
1044-
return false;
1045-
}
1046-
this._subItems = [];
1047-
for (var i = 2; i < args.length; i++) {
1048-
if (args[i]) {
1049-
this._subItems.push(args[i]);
1050-
}
1037+
initWithItems:function (args) {
1038+
var l = args.length;
1039+
// passing callback.
1040+
if (typeof args[args.length-1] === 'function') {
1041+
this.initWithCallback( args[args.length-2], args[args.length-1] );
1042+
l = l-2;
10511043
}
1052-
this._selectedIndex = cc.UINT_MAX;
1053-
this.setSelectedIndex(0);
1054-
return true;
1055-
},
1044+
else
1045+
this.initWithCallback(null, null);
10561046

1057-
/**
1058-
* @param {cc.MenuItem} item
1059-
* @return {Boolean}
1060-
*/
1061-
initWithItem:function (item) {
1062-
this.initWithCallback(null, null);
10631047
this._subItems = [];
1064-
this._subItems.push(item);
1065-
this._selectedIndex = cc.UINT_MAX;
1066-
this.setSelectedIndex(0);
1067-
return true;
1068-
},
1069-
1070-
/**
1071-
* @param {cc.MenuItem} args[1+] items
1072-
* @return {Boolean}
1073-
*/
1074-
initWithItems:function (args) {
1075-
this.initWithCallback(null, null);
1076-
this._subItems = [];
1077-
for (var i = 0; i < args.length; i++) {
1048+
for (var i = 0; i < l; i++) {
10781049
if (args[i]) {
10791050
this._subItems.push(args[i]);
10801051
}
@@ -1123,7 +1094,7 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{
11231094
* @param {Boolean} enabled
11241095
*/
11251096
setEnabled:function (enabled) {
1126-
if (this._isEnabled = enabled) {
1097+
if (this._isEnabled == enabled) {
11271098
this._super(enabled);
11281099

11291100
if (this._subItems && this._subItems.length > 0) {
@@ -1172,11 +1143,6 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{
11721143
*/
11731144
cc.MenuItemToggle.create = function (/*Multiple arguments follow*/) {
11741145
var ret = new cc.MenuItemToggle();
1175-
//ret.initWithItems(arguments);
1176-
if (arguments.length == 1) {
1177-
ret.initWithItem(arguments);
1178-
} else {
1179-
ret.initWithCallback(arguments);
1180-
}
1146+
ret.initWithItems(arguments);
11811147
return ret;
11821148
};

0 commit comments

Comments
 (0)