1 /****************************************************************************
  2  Copyright (c) 2008-2010 Ricardo Quesada
  3  Copyright (c) 2011-2012 cocos2d-x.org
  4  Copyright (c) 2013-2014 Chukong Technologies Inc.
  5 
  6  http://www.cocos2d-x.org
  7 
  8  Permission is hereby granted, free of charge, to any person obtaining a copy
  9  of this software and associated documentation files (the "Software"), to deal
 10  in the Software without restriction, including without limitation the rights
 11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12  copies of the Software, and to permit persons to whom the Software is
 13  furnished to do so, subject to the following conditions:
 14 
 15  The above copyright notice and this permission notice shall be included in
 16  all copies or substantial portions of the Software.
 17 
 18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24  THE SOFTWARE.
 25  ****************************************************************************/
 26 
 27 /**
 28  * tag for scene redial
 29  * @constant
 30  * @type Number
 31  */
 32 cc.SCENE_RADIAL = 0xc001;
 33 
 34 /**
 35  * cc.TransitionProgress transition.
 36  * @class
 37  * @extends cc.TransitionScene
 38  * @param {Number} t time
 39  * @param {cc.Scene} scene
 40  * @example
 41  * var trans = new cc.TransitionProgress(time,scene);
 42  */
 43 cc.TransitionProgress = cc.TransitionScene.extend(/** @lends cc.TransitionProgress# */{
 44     _to:0,
 45     _from:0,
 46     _sceneToBeModified:null,
 47     _className:"TransitionProgress",
 48 
 49     /**
 50      * @param {Number} t time
 51      * @param {cc.Scene} scene
 52      */
 53     ctor:function (t, scene) {
 54         cc.TransitionScene.prototype.ctor.call(this);
 55         scene && this.initWithDuration(t, scene);
 56     },
 57 
 58 	_setAttrs: function(node, x, y) {
 59 		node.attr({
 60 			x: x,
 61 			y: y,
 62 			anchorX: 0.5,
 63 			anchorY: 0.5
 64 		});
 65 	},
 66 
 67     /**
 68      * Custom on enter.
 69      * @override
 70      */
 71     onEnter:function () {
 72         cc.TransitionScene.prototype.onEnter.call(this);
 73         this._setupTransition();
 74 
 75         // create a transparent color layer
 76         // in which we are going to add our rendertextures
 77         var winSize = cc.director.getWinSize();
 78 
 79         // create the second render texture for outScene
 80         var texture = new cc.RenderTexture(winSize.width, winSize.height);
 81         texture.sprite.anchorX = 0.5;
 82 	    texture.sprite.anchorY = 0.5;
 83         this._setAttrs(texture, winSize.width / 2, winSize.height / 2);
 84 
 85         // render outScene to its texturebuffer
 86         texture.clear(0, 0, 0, 1);
 87         texture.begin();
 88         this._sceneToBeModified.visit();
 89         texture.end();
 90 
 91         //    Since we've passed the outScene to the texture we don't need it.
 92         if (this._sceneToBeModified === this._outScene)
 93             this.hideOutShowIn();
 94 
 95         //    We need the texture in RenderTexture.
 96         var pNode = this._progressTimerNodeWithRenderTexture(texture);
 97 
 98         // create the blend action
 99         var layerAction = cc.sequence(
100             cc.progressFromTo(this._duration, this._from, this._to),
101             cc.callFunc(this.finish, this));
102         // run the blend action
103         pNode.runAction(layerAction);
104 
105         // add the layer (which contains our two rendertextures) to the scene
106         this.addChild(pNode, 2, cc.SCENE_RADIAL);
107     },
108 
109     /**
110      * custom on exit
111      * @override
112      */
113     onExit:function () {
114         // remove our layer and release all containing objects
115         this.removeChildByTag(cc.SCENE_RADIAL, true);
116         cc.TransitionScene.prototype.onExit.call(this);
117     },
118 
119     _setupTransition:function () {
120         this._sceneToBeModified = this._outScene;
121         this._from = 100;
122         this._to = 0;
123     },
124 
125     _progressTimerNodeWithRenderTexture:function (texture) {
126         cc.log("cc.TransitionProgress._progressTimerNodeWithRenderTexture(): should be overridden in subclass");
127         return null;
128     },
129 
130     _sceneOrder:function () {
131         this._isInSceneOnTop = false;
132     }
133 });
134 
135 /**
136  * create a cc.TransitionProgress object
137  * @deprecated since v3.0,please use new cc.TransitionProgress(t, scene) instead.
138  * @function
139  * @param {Number} t time
140  * @param {cc.Scene} scene
141  * @return {cc.TransitionProgress}
142  */
143 cc.TransitionProgress.create = function (t, scene) {
144     return new cc.TransitionProgress(t, scene);
145 };
146 
147 /**
148  *  cc.TransitionRadialCCW transition.<br/>
149  *  A counter clock-wise radial transition to the next scene
150  * @class
151  * @extends cc.TransitionProgress
152  * @param {Number} t time
153  * @param {cc.Scene} scene
154  * @example
155  * var trans = new cc.TransitionProgressRadialCCW(t, scene);
156  */
157 cc.TransitionProgressRadialCCW = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressRadialCCW# */{
158 
159     /**
160      * @param {Number} t time
161      * @param {cc.Scene} scene
162      */
163     ctor:function (t, scene) {
164         cc.TransitionProgress.prototype.ctor.call(this);
165         scene && this.initWithDuration(t, scene);
166     },
167 
168     _progressTimerNodeWithRenderTexture:function (texture) {
169         var size = cc.director.getWinSize();
170 
171         var pNode = new cc.ProgressTimer(texture.sprite);
172         pNode.type = cc.ProgressTimer.TYPE_RADIAL;
173 
174         //    Return the radial type that we want to use
175         pNode.reverseDir = false;
176         pNode.percentage = 100;
177         this._setAttrs(pNode, size.width / 2, size.height / 2);
178 
179         return pNode;
180     }
181 });
182 
183 /**
184  * create a cc.TransitionProgressRadialCCW object
185  * @deprecated since v3.0,please use new cc.TransitionProgressRadialCCW(t, scene) instead.
186  * @param {Number} t time
187  * @param {cc.Scene} scene
188  * @return {cc.TransitionProgressRadialCCW}
189  * @example
190  * var trans = new cc.TransitionProgressRadialCCW(time,scene);
191  */
192 cc.TransitionProgressRadialCCW.create = function (t, scene) {
193     return new cc.TransitionProgressRadialCCW(t, scene);
194 };
195 
196 /**
197  * cc.TransitionRadialCW transition.<br/>
198  * A counter colock-wise radial transition to the next scene
199  * @class
200  * @extends cc.TransitionProgress
201  * @param {Number} t time
202  * @param {cc.Scene} scene
203  * @example
204  * var trans = new cc.TransitionProgressRadialCW(t, scene);
205  */
206 cc.TransitionProgressRadialCW = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressRadialCW# */{
207     /**
208      * @param {Number} t time
209      * @param {cc.Scene} scene
210      */
211     ctor:function (t, scene) {
212         cc.TransitionProgress.prototype.ctor.call(this);
213         scene && this.initWithDuration(t, scene);
214     },
215 
216     _progressTimerNodeWithRenderTexture:function (texture) {
217         var size = cc.director.getWinSize();
218 
219         var pNode = new cc.ProgressTimer(texture.sprite);
220         pNode.type = cc.ProgressTimer.TYPE_RADIAL;
221 
222         //    Return the radial type that we want to use
223         pNode.reverseDir = true;
224         pNode.percentage = 100;
225         this._setAttrs(pNode, size.width / 2, size.height / 2);
226 
227         return pNode;
228     }
229 });
230 
231 /**
232  * create a cc.TransitionProgressRadialCW object
233  * @deprecated since v3.0,please use cc.TransitionProgressRadialCW(t, scene) instead.
234  * @param {Number} t time
235  * @param {cc.Scene} scene
236  * @return {cc.TransitionProgressRadialCW}
237  */
238 cc.TransitionProgressRadialCW.create = function (t, scene) {
239     var tempScene = new cc.TransitionProgressRadialCW();
240     if ((tempScene !== null) && (tempScene.initWithDuration(t, scene))) {
241         return tempScene;
242     }
243     return new cc.TransitionProgressRadialCW(t, scene);
244 };
245 
246 /**
247  * cc.TransitionProgressHorizontal transition.<br/>
248  * A  colock-wise radial transition to the next scene
249  * @class
250  * @extends cc.TransitionProgress
251  * @param {Number} t time
252  * @param {cc.Scene} scene
253  * @example
254  * var trans = new cc.TransitionProgressHorizontal(t, scene);
255  */
256 cc.TransitionProgressHorizontal = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressHorizontal# */{
257     /**
258      * @param {Number} t time
259      * @param {cc.Scene} scene
260      */
261     ctor:function (t, scene) {
262         cc.TransitionProgress.prototype.ctor.call(this);
263         scene && this.initWithDuration(t, scene);
264     },
265 
266     _progressTimerNodeWithRenderTexture:function (texture) {
267         var size = cc.director.getWinSize();
268 
269         var pNode = new cc.ProgressTimer(texture.sprite);
270         pNode.type = cc.ProgressTimer.TYPE_BAR;
271 
272         pNode.midPoint = cc.p(1, 0);
273         pNode.barChangeRate = cc.p(1, 0);
274 
275         pNode.percentage = 100;
276         this._setAttrs(pNode, size.width / 2, size.height / 2);
277 
278         return pNode;
279     }
280 });
281 
282 /**
283  * create a cc.TransitionProgressHorizontal object
284  * @deprecated since v3.0,please use new cc.TransitionProgressHorizontal(t, scene) instead.
285  * @param {Number} t time
286  * @param {cc.Scene} scene
287  * @return {cc.TransitionProgressHorizontal}
288  */
289 cc.TransitionProgressHorizontal.create = function (t, scene) {
290     return new cc.TransitionProgressHorizontal(t, scene);
291 };
292 
293 /**
294  * cc.TransitionProgressVertical transition.
295  * @class
296  * @extends cc.TransitionProgress
297  * @param {Number} t time
298  * @param {cc.Scene} scene
299  * @example
300  * var trans = new cc.TransitionProgressVertical(t, scene);
301  */
302 cc.TransitionProgressVertical = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressVertical# */{
303 
304     /**
305      * @param {Number} t time
306      * @param {cc.Scene} scene
307      */
308     ctor:function (t, scene) {
309         cc.TransitionProgress.prototype.ctor.call(this);
310         scene && this.initWithDuration(t, scene);
311     },
312 
313     _progressTimerNodeWithRenderTexture:function (texture) {
314         var size = cc.director.getWinSize();
315 
316         var pNode = new cc.ProgressTimer(texture.sprite);
317         pNode.type = cc.ProgressTimer.TYPE_BAR;
318 
319         pNode.midPoint = cc.p(0, 0);
320         pNode.barChangeRate = cc.p(0, 1);
321 
322         pNode.percentage = 100;
323         this._setAttrs(pNode, size.width / 2, size.height / 2);
324 
325         return pNode;
326     }
327 });
328 
329 /**
330  * create a cc.TransitionProgressVertical object
331  * @deprecated since v3.0,please use new cc.TransitionProgressVertical(t, scene) instead.
332  * @param {Number} t time
333  * @param {cc.Scene} scene
334  * @return {cc.TransitionProgressVertical}
335  */
336 cc.TransitionProgressVertical.create = function (t, scene) {
337     return new cc.TransitionProgressVertical(t, scene);
338 };
339 
340 /**
341  * cc.TransitionProgressInOut transition.
342  * @class
343  * @extends cc.TransitionProgress
344  */
345 cc.TransitionProgressInOut = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressInOut# */{
346 
347     /**
348      * The constructor of cc.TransitionProgressInOut. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
349      * @param {Number} t time
350      * @param {cc.Scene} scene
351      */
352     ctor:function (t, scene) {
353         cc.TransitionProgress.prototype.ctor.call(this);
354         scene && this.initWithDuration(t, scene);
355     },
356 
357     _progressTimerNodeWithRenderTexture:function (texture) {
358         var size = cc.director.getWinSize();
359         var pNode = new cc.ProgressTimer(texture.sprite);
360         pNode.type = cc.ProgressTimer.TYPE_BAR;
361 
362         pNode.midPoint = cc.p(0.5, 0.5);
363         pNode.barChangeRate = cc.p(1, 1);
364 
365         pNode.percentage = 0;
366         this._setAttrs(pNode, size.width / 2, size.height / 2);
367 
368         return pNode;
369     },
370     _sceneOrder:function () {
371         this._isInSceneOnTop = false;
372     },
373     _setupTransition:function () {
374         this._sceneToBeModified = this._inScene;
375         this._from = 0;
376         this._to = 100;
377     }
378 });
379 
380 /**
381  * create a cc.TransitionProgressInOut object
382  * @function
383  * @deprecated
384  * @param {Number} t time
385  * @param {cc.Scene} scene
386  * @return {cc.TransitionProgressInOut}
387  */
388 cc.TransitionProgressInOut.create = function (t, scene) {
389     return new cc.TransitionProgressInOut(t, scene);
390 };
391 
392 /**
393  * cc.TransitionProgressOutIn transition.
394  * @class
395  * @extends cc.TransitionProgress
396  */
397 cc.TransitionProgressOutIn = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressOutIn# */{
398 
399     /**
400      * The constructor of cc.TransitionProgressOutIn. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
401      * @param {Number} t time
402      * @param {cc.Scene} scene
403      */
404     ctor:function (t, scene) {
405         cc.TransitionProgress.prototype.ctor.call(this);
406         scene && this.initWithDuration(t, scene);
407     },
408 
409     _progressTimerNodeWithRenderTexture:function (texture) {
410         var size = cc.director.getWinSize();
411         var pNode = new cc.ProgressTimer(texture.sprite);
412         pNode.type = cc.ProgressTimer.TYPE_BAR;
413 
414         pNode.midPoint = cc.p(0.5, 0.5);
415         pNode.barChangeRate = cc.p(1, 1);
416 
417         pNode.percentage = 100;
418         this._setAttrs(pNode, size.width / 2, size.height / 2);
419 
420         return pNode;
421     }
422 });
423 
424 /**
425  * create a cc.TransitionProgressOutIn object
426  * @function
427  * @deprecated
428  * @param {Number} t time
429  * @param {cc.Scene} scene
430  * @return {cc.TransitionProgressOutIn}
431  */
432 cc.TransitionProgressOutIn.create = function (t, scene) {
433     return new cc.TransitionProgressOutIn(t, scene);
434 };
435