2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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 "2d/CCTransitionPageTurn.h"
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "2d/CCActionPageTurn3D.h"
|
|
|
|
#include "2d/CCNodeGrid.h"
|
|
|
|
#include "renderer/CCRenderer.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
TransitionPageTurn::TransitionPageTurn()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_inSceneProxy = NodeGrid::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
_outSceneProxy = NodeGrid::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_inSceneProxy->retain();
|
|
|
|
_outSceneProxy->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
TransitionPageTurn::~TransitionPageTurn()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_RELEASE(_inSceneProxy);
|
|
|
|
AX_SAFE_RELEASE(_outSceneProxy);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** creates a base transition with duration and incoming scene */
|
2021-12-25 10:04:45 +08:00
|
|
|
TransitionPageTurn* TransitionPageTurn::create(float t, Scene* scene, bool backwards)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TransitionPageTurn* transition = new TransitionPageTurn();
|
|
|
|
transition->initWithDuration(t, scene, backwards);
|
2019-11-23 20:27:39 +08:00
|
|
|
transition->autorelease();
|
|
|
|
return transition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** initializes a transition with duration and incoming scene */
|
2021-12-25 10:04:45 +08:00
|
|
|
bool TransitionPageTurn::initWithDuration(float t, Scene* scene, bool backwards)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// FIXME:: needed before [super init]
|
|
|
|
_back = backwards;
|
|
|
|
|
|
|
|
if (TransitionScene::initWithDuration(t, scene))
|
|
|
|
{
|
|
|
|
// do something
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransitionPageTurn::sceneOrder()
|
|
|
|
{
|
|
|
|
_isInSceneOnTop = _back;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void TransitionPageTurn::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
Scene::draw(renderer, transform, flags);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (_isInSceneOnTop)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
_outSceneProxy->visit(renderer, transform, flags);
|
|
|
|
_inSceneProxy->visit(renderer, transform, flags);
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
_inSceneProxy->visit(renderer, transform, flags);
|
|
|
|
_outSceneProxy->visit(renderer, transform, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransitionPageTurn::onEnter()
|
|
|
|
{
|
|
|
|
TransitionScene::onEnter();
|
|
|
|
|
|
|
|
_inSceneProxy->setTarget(_inScene);
|
|
|
|
_outSceneProxy->setTarget(_outScene);
|
|
|
|
|
|
|
|
_inSceneProxy->onEnter();
|
|
|
|
_outSceneProxy->onEnter();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 s = _director->getWinSize();
|
2021-12-25 10:04:45 +08:00
|
|
|
int x, y;
|
2019-11-23 20:27:39 +08:00
|
|
|
if (s.width > s.height)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
x = 16;
|
|
|
|
y = 12;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
x = 12;
|
|
|
|
y = 16;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* action = this->actionWithSize(Vec2(x, y));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_back)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_outSceneProxy->runAction(Sequence::create(
|
2022-07-16 10:43:05 +08:00
|
|
|
action, CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), StopGrid::create(), nullptr));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// to prevent initial flicker
|
|
|
|
_inSceneProxy->setVisible(false);
|
2021-12-25 10:04:45 +08:00
|
|
|
_inSceneProxy->runAction(Sequence::create(Show::create(), action,
|
2022-07-16 10:43:05 +08:00
|
|
|
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)),
|
2021-12-25 10:04:45 +08:00
|
|
|
StopGrid::create(), nullptr));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void TransitionPageTurn::onExit()
|
|
|
|
{
|
|
|
|
_outSceneProxy->setTarget(nullptr);
|
|
|
|
_outSceneProxy->setTarget(nullptr);
|
|
|
|
_outSceneProxy->onExit();
|
|
|
|
_inSceneProxy->onExit();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
TransitionScene::onExit();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* TransitionPageTurn::actionWithSize(const Vec2& vector)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (_back)
|
|
|
|
{
|
|
|
|
// Get hold of the PageTurn3DAction
|
2021-12-25 10:04:45 +08:00
|
|
|
return ReverseTime::create(PageTurn3D::create(_duration, vector));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get hold of the PageTurn3DAction
|
|
|
|
return PageTurn3D::create(_duration, vector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|