From c36dbfef50a1adaafb9760a8a3bd95b1d7bd6050 Mon Sep 17 00:00:00 2001 From: xingsenma Date: Fri, 3 Jan 2014 16:33:24 +0800 Subject: [PATCH] issue #3419 add a default display when pressed texture is not loaded --- .../CocoStudio/GUI/UIWidgets/UIButton.js | 80 ++++++++++++++----- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/extensions/CocoStudio/GUI/UIWidgets/UIButton.js b/extensions/CocoStudio/GUI/UIWidgets/UIButton.js index 5b40f4daae..042b6cc08b 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/UIButton.js +++ b/extensions/CocoStudio/GUI/UIWidgets/UIButton.js @@ -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; @@ -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 () { @@ -211,6 +225,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{ this._updateDisplay(); this.normalTextureScaleChangedWithSize(); + this._normalTextureLoaded = true; }, /** @@ -256,6 +271,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{ } this._updateDisplay(); this.pressedTextureScaleChangedWithSize(); + this._pressedTextureLoaded = true; }, /** @@ -301,6 +317,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{ } this._updateDisplay(); this.disabledTextureScaleChangedWithSize(); + this._disabledTextureLoaded = true; }, _updateDisplay:function(){ @@ -359,33 +376,48 @@ 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); } }, @@ -393,6 +425,8 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{ 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); }, /** @@ -505,6 +539,7 @@ 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; } @@ -512,6 +547,7 @@ ccs.Button = ccs.Widget.extend(/** @lends ccs.Button# */{ else { if (this._scale9Enabled) { this._buttonNormalRenderer.setPreferredSize(this._size); + this._normalTextureScaleXInSize = this._normalTextureScaleYInSize = 1; } else { var textureSize = this._normalTextureSize; @@ -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; } } }, @@ -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; @@ -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; } } },