// // ToyParentalGateShowInterface.cpp // Steve and Maggie Halloween // // Created by Katarzyna Kalinowska-Górska on 14/10/2019. // #include "ToyParentalGateShowInterface.h" #include "ToyMiscUtils.h" #include "ToyParentalGateView.h" static int ToyParentalGateViewTag = 90; void ToyParentalGateShowInterface::presentParentalGate(std::function onSuccessCallback, std::function onFailureCallback){ _isPresentingParentalGate = true; auto screenSize = cocos2d::Director::getInstance()->getWinSize(); auto parentalGate = ToyParentalGateView::create(screenSize.width, screenSize.height, onSuccessCallback, onFailureCallback); parentalGate->setTag(ToyParentalGateViewTag); PGSI_addChild(parentalGate); parentalGate->setLocalZOrder(1000); parentalGate->setPosition(cocos2d::Vec2(0, 0)); parentalGate->setCascadeOpacityEnabled(true); auto touchListener = cocos2d::EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event){ return true; }; PGSI_getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, parentalGate); // #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // auto keyboardListener = cocos2d::EventListenerKeyboard::create(); // keyboardListener->onKeyReleased = [&](cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event){ // if(keyCode == cocos2d::EventKeyboard::KeyCode::KEY_BACK){ // hideParentalGate(); // } // }; // _eventDispatcher->addEventListenerWithSceneGraphPriority(keyboardListener, parentalGate); // #endif parentalGate->setOpacity(0); parentalGate->runAction(cocos2d::FadeIn::create(ToyMiscUtils::StandardAnimationTime)); } void ToyParentalGateShowInterface::hideParentalGate(){ _isPresentingParentalGate = false; auto parentalGate = PGSI_getChildByTag(ToyParentalGateViewTag); if(parentalGate != nullptr){ parentalGate->runAction(cocos2d::Sequence::create(cocos2d::FadeOut::create(ToyMiscUtils::StandardAnimationTime), cocos2d::CallFunc::create(std::bind([&](cocos2d::Node* pg){ ToyMiscUtils::hideAndRemoveView(pg, true); }, parentalGate)), nullptr)); } }