Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 61 additions & 19 deletions extensions/CocoStudio/GUI/UIWidgets/UIButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
_disabledTextureSize: null,
_pressedActionEnabled: false,
_titleColor: null,
_normalTextureScaleXInSize: 1,
_normalTextureScaleYInSize: 1,
_pressedTextureScaleXInSize: 1,
_pressedTextureScaleYInSize: 1,
_normalTextureLoaded: false,
_pressedTextureLoaded: false,
_disabledTextureLoaded: false,
ctor: function () {
ccs.Widget.prototype.ctor.call(this);
this._buttonNormalRenderer = null;
Expand All @@ -77,6 +84,13 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
this._disabledTextureSize = cc.size(locSize.width, locSize.height);
this._pressedActionEnabled = false;
this._titleColor = cc.white();
this._normalTextureScaleXInSize = 1;
this._normalTextureScaleYInSize = 1;
this._pressedTextureScaleXInSize = 1;
this._pressedTextureScaleYInSize = 1;
this._normalTextureLoaded = false;
this._pressedTextureLoaded = false;
this._disabledTextureLoaded = false;
},

init: function () {
Expand Down Expand Up @@ -211,6 +225,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{

this._updateDisplay();
this.normalTextureScaleChangedWithSize();
this._normalTextureLoaded = true;
},

/**
Expand Down Expand Up @@ -256,6 +271,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
}
this._updateDisplay();
this.pressedTextureScaleChangedWithSize();
this._pressedTextureLoaded = true;
},

/**
Expand Down Expand Up @@ -301,6 +317,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
}
this._updateDisplay();
this.disabledTextureScaleChangedWithSize();
this._disabledTextureLoaded = true;
},

_updateDisplay:function(){
Expand Down Expand Up @@ -359,40 +376,57 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
this._buttonNormalRenderer.setVisible(true);
this._buttonClickedRenderer.setVisible(false);
this._buttonDisableRenderer.setVisible(false);
if (this._pressedActionEnabled) {
if (this._pressedTextureLoaded) {
if (this._pressedActionEnabled) {
this._buttonNormalRenderer.stopAllActions();
this._buttonClickedRenderer.stopAllActions();
this._buttonDisableRenderer.stopAllActions();
var zoomAction = cc.ScaleTo.create(0.05, 1.0);
var zoomAction1 = cc.ScaleTo.create(0.05, 1.0);
var zoomAction2 = cc.ScaleTo.create(0.05, 1.0);
this._buttonNormalRenderer.runAction(zoomAction);
this._buttonClickedRenderer.runAction(zoomAction1);
this._buttonDisableRenderer.runAction(zoomAction2);
}
} else {
this._buttonNormalRenderer.stopAllActions();
this._buttonClickedRenderer.stopAllActions();
this._buttonDisableRenderer.stopAllActions();
var zoomAction = cc.ScaleTo.create(0.05, 1.0);
var zoomAction1 = cc.ScaleTo.create(0.05, 1.0);
var zoomAction2 = cc.ScaleTo.create(0.05, 1.0);
var zoomAction = cc.ScaleTo.create(0.05, this._normalTextureScaleXInSize, this._normalTextureScaleYInSize);
this._buttonNormalRenderer.runAction(zoomAction);
this._buttonClickedRenderer.runAction(zoomAction1);
this._buttonDisableRenderer.runAction(zoomAction2);
}
},

onPressStateChangedToPressed: function () {
this._buttonNormalRenderer.setVisible(false);
this._buttonClickedRenderer.setVisible(true);
this._buttonDisableRenderer.setVisible(false);
if (this._pressedActionEnabled) {
if (this._pressedTextureLoaded) {
this._buttonNormalRenderer.setVisible(false);
this._buttonClickedRenderer.setVisible(true);
this._buttonDisableRenderer.setVisible(false);
if (this._pressedActionEnabled) {
this._buttonNormalRenderer.stopAllActions();
this._buttonClickedRenderer.stopAllActions();
this._buttonDisableRenderer.stopAllActions();
var zoomAction = cc.ScaleTo.create(0.05, 1.1);
var zoomAction1 = cc.ScaleTo.create(0.05, 1.1);
var zoomAction2 = cc.ScaleTo.create(0.05, 1.1);
this._buttonNormalRenderer.runAction(zoomAction);
this._buttonClickedRenderer.runAction(zoomAction1);
this._buttonDisableRenderer.runAction(zoomAction2);
}
} else {
this._buttonNormalRenderer.setVisible(true);
this._buttonClickedRenderer.setVisible(true);
this._buttonDisableRenderer.setVisible(false);
this._buttonNormalRenderer.stopAllActions();
this._buttonClickedRenderer.stopAllActions();
this._buttonDisableRenderer.stopAllActions();
var zoomAction = cc.ScaleTo.create(0.05, 1.1);
var zoomAction1 = cc.ScaleTo.create(0.05, 1.1);
var zoomAction2 = cc.ScaleTo.create(0.05, 1.1);
var zoomAction = cc.ScaleTo.create(0.05, this._pressedTextureScaleXInSize + 0.1, this._pressedTextureScaleYInSize + 0.1);
this._buttonNormalRenderer.runAction(zoomAction);
this._buttonClickedRenderer.runAction(zoomAction1);
this._buttonDisableRenderer.runAction(zoomAction2);
}
},

onPressStateChangedToDisabled: function () {
this._buttonNormalRenderer.setVisible(false);
this._buttonClickedRenderer.setVisible(false);
this._buttonDisableRenderer.setVisible(true);
this._buttonNormalRenderer.setScale(this._normalTextureScaleXInSize, this._normalTextureScaleYInSize);
this._buttonClickedRenderer.setScale(this._pressedTextureScaleXInSize, this._pressedTextureScaleYInSize);
},

/**
Expand Down Expand Up @@ -505,13 +539,15 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
if (this._ignoreSize) {
if (!this._scale9Enabled) {
this._buttonNormalRenderer.setScale(1.0);
this._normalTextureScaleXInSize = this._normalTextureScaleYInSize = 1;
this._size.width = this._normalTextureSize.width;
this._size.height = this._normalTextureSize.height;
}
}
else {
if (this._scale9Enabled) {
this._buttonNormalRenderer.setPreferredSize(this._size);
this._normalTextureScaleXInSize = this._normalTextureScaleYInSize = 1;
}
else {
var textureSize = this._normalTextureSize;
Expand All @@ -523,6 +559,8 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
var scaleY = this._size.height / textureSize.height;
this._buttonNormalRenderer.setScaleX(scaleX);
this._buttonNormalRenderer.setScaleY(scaleY);
this._normalTextureScaleXInSize = scaleX;
this._normalTextureScaleYInSize = scaleY;
}
}
},
Expand All @@ -531,11 +569,13 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
if (this._ignoreSize) {
if (!this._scale9Enabled) {
this._buttonClickedRenderer.setScale(1.0);
this._pressedTextureScaleXInSize = this._pressedTextureScaleYInSize = 1;
}
}
else {
if (this._scale9Enabled) {
this._buttonClickedRenderer.setPreferredSize(this._size);
this._pressedTextureScaleXInSize = this._pressedTextureScaleYInSize = 1;
}
else {
var textureSize = this._pressedTextureSize;
Expand All @@ -547,6 +587,8 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{
var scaleY = this._size.height / textureSize.height;
this._buttonClickedRenderer.setScaleX(scaleX);
this._buttonClickedRenderer.setScaleY(scaleY);
this._pressedTextureScaleXInSize = scaleX;
this._pressedTextureScaleYInSize = scaleY;
}
}
},
Expand Down