2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCTransitionPageTurn.h"
|
|
|
|
#include "CCDirector.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCActionInterval.h"
|
|
|
|
#include "CCActionInstant.h"
|
|
|
|
#include "CCActionGrid.h"
|
|
|
|
#include "CCActionPageTurn3D.h"
|
2013-12-16 14:21:05 +08:00
|
|
|
#include "CCNodeGrid.h"
|
2013-12-30 14:43:18 +08:00
|
|
|
#include "renderer/CCRenderer.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-11-14 10:00:59 +08:00
|
|
|
float TransitionPageTurn::POLYGON_OFFSET_FACTOR = -20.f;
|
|
|
|
float TransitionPageTurn::POLYGON_OFFSET_UNITS = -20.f;
|
2013-11-14 09:44:35 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn::TransitionPageTurn()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-12-19 22:01:32 +08:00
|
|
|
_inSceneProxy = NodeGrid::create();
|
|
|
|
_outSceneProxy = NodeGrid::create();
|
|
|
|
|
|
|
|
_inSceneProxy->retain();
|
|
|
|
_outSceneProxy->retain();
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn::~TransitionPageTurn()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-12-12 13:44:29 +08:00
|
|
|
CC_SAFE_RELEASE(_inSceneProxy);
|
|
|
|
CC_SAFE_RELEASE(_outSceneProxy);
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** creates a base transition with duration and incoming scene */
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn * TransitionPageTurn::create(float t, Scene *scene, bool backwards)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
TransitionPageTurn * transition = new TransitionPageTurn();
|
|
|
|
transition->initWithDuration(t,scene,backwards);
|
|
|
|
transition->autorelease();
|
|
|
|
return transition;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** initializes a transition with duration and incoming scene */
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TransitionPageTurn::initWithDuration(float t, Scene *scene, bool backwards)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// XXX: needed before [super init]
|
2013-06-15 14:03:30 +08:00
|
|
|
_back = backwards;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TransitionScene::initWithDuration(t, scene))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// do something
|
|
|
|
}
|
|
|
|
return true;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TransitionPageTurn::sceneOrder()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_isInSceneOnTop = _back;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
2013-12-30 14:43:18 +08:00
|
|
|
void TransitionPageTurn::onEnablePolygonOffset()
|
|
|
|
{
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glPolygonOffset(POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_UNITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransitionPageTurn::onDisablePolygonOffset()
|
|
|
|
{
|
|
|
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glPolygonOffset(0, 0);
|
|
|
|
}
|
|
|
|
|
2013-11-14 09:44:35 +08:00
|
|
|
void TransitionPageTurn::draw()
|
|
|
|
{
|
|
|
|
Scene::draw();
|
|
|
|
|
|
|
|
if( _isInSceneOnTop ) {
|
2013-12-12 13:44:29 +08:00
|
|
|
_outSceneProxy->visit();
|
2013-12-30 14:43:18 +08:00
|
|
|
_enableOffsetCmd.init(0, _vertexZ);
|
|
|
|
_enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this);
|
|
|
|
Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd);
|
2013-12-12 13:44:29 +08:00
|
|
|
_inSceneProxy->visit();
|
2013-12-30 14:43:18 +08:00
|
|
|
_disableOffsetCmd.init(0, _vertexZ);
|
|
|
|
_disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this);
|
|
|
|
Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd);
|
2013-11-14 09:44:35 +08:00
|
|
|
} else {
|
2013-12-12 13:44:29 +08:00
|
|
|
_inSceneProxy->visit();
|
2013-12-30 14:43:18 +08:00
|
|
|
|
|
|
|
_enableOffsetCmd.init(0, _vertexZ);
|
|
|
|
_enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this);
|
|
|
|
Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd);
|
|
|
|
|
2013-12-12 13:44:29 +08:00
|
|
|
_outSceneProxy->visit();
|
2013-12-30 14:43:18 +08:00
|
|
|
|
|
|
|
_disableOffsetCmd.init(0, _vertexZ);
|
|
|
|
_disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this);
|
|
|
|
Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd);
|
2013-11-14 09:44:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TransitionPageTurn::onEnter()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionScene::onEnter();
|
2013-12-12 13:44:29 +08:00
|
|
|
|
2013-12-16 14:21:05 +08:00
|
|
|
_inSceneProxy->setTarget(_inScene);
|
|
|
|
_outSceneProxy->setTarget(_outScene);
|
2013-12-12 13:44:29 +08:00
|
|
|
|
|
|
|
_inSceneProxy->onEnter();
|
|
|
|
_outSceneProxy->onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
int x,y;
|
2013-02-26 17:03:29 +08:00
|
|
|
if (s.width > s.height)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
x=16;
|
2010-12-27 09:40:45 +08:00
|
|
|
y=12;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x=12;
|
2010-12-27 09:40:45 +08:00
|
|
|
y=16;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
ActionInterval *action = this->actionWithSize(Size(x,y));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _back )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-12 13:44:29 +08:00
|
|
|
_outSceneProxy->runAction
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence::create
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
|
|
|
action,
|
2013-07-16 03:43:22 +08:00
|
|
|
CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid::create(),
|
2013-12-18 17:47:20 +08:00
|
|
|
nullptr
|
2012-04-19 14:35:52 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// to prevent initial flicker
|
2013-12-12 13:44:29 +08:00
|
|
|
_inSceneProxy->setVisible(false);
|
|
|
|
_inSceneProxy->runAction
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence::create
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
Show::create(),
|
2012-04-19 14:35:52 +08:00
|
|
|
action,
|
2013-07-16 03:43:22 +08:00
|
|
|
CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid::create(),
|
2013-12-18 17:47:20 +08:00
|
|
|
nullptr
|
2012-04-19 14:35:52 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
2013-12-12 13:44:29 +08:00
|
|
|
void TransitionPageTurn::onExit()
|
|
|
|
{
|
2013-12-19 22:01:32 +08:00
|
|
|
_outSceneProxy->setTarget(nullptr);
|
|
|
|
_outSceneProxy->setTarget(nullptr);
|
2013-12-12 13:44:29 +08:00
|
|
|
_outSceneProxy->onExit();
|
|
|
|
_inSceneProxy->onExit();
|
|
|
|
|
|
|
|
TransitionScene::onExit();
|
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval* TransitionPageTurn:: actionWithSize(const Size& vector)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_back)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Get hold of the PageTurn3DAction
|
2013-06-20 14:13:12 +08:00
|
|
|
return ReverseTime::create
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
PageTurn3D::create(_duration, vector)
|
2012-04-19 14:35:52 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get hold of the PageTurn3DAction
|
2013-06-20 14:13:12 +08:00
|
|
|
return PageTurn3D::create(_duration, vector);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|