// // AniAlertUtils.cpp // SteveMaggieCpp // // Created by Katarzyna Kalinowska-Górska on 17.05.2017. // // #include #include "AniAlertUtils.h" #include "AniAlertView.h" #include "AniMiscUtils.h" #include "HelloWorldScene.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "RatePromptHandler_ios.h" #endif #include "audio/include/AudioEngine.h" static const int AniAlertViewTagDefault = 999; static const int AniAlertViewTagCloseConfirm = 998; void AniAlertUtils::showTwoButtonDialog(int tag, std::string text, std::string okButtonText, std::string cancelButtonText, std::function onOKCallback, std::function onCancelCallback){ if(cocos2d::Director::getInstance()->getRunningScene()->getChildByTag(tag) == nullptr) { //TODO handle it better,present on top or something auto alpha = 220; auto cancelColor = cocos2d::Color3B(68, 200, 220); auto okColor = cocos2d::Color3B(200, 100, 100); auto alert = AniAlertView::create(text, okButtonText, cancelButtonText, okColor, cancelColor, onOKCallback, onCancelCallback); auto touchListener = cocos2d::EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event) { return true; }; cocos2d::Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, alert); alert->setTag(tag); alert->setLocalZOrder(1000); //TODO make general zorders, named alert->setOpacity(0); cocos2d::Director::getInstance()->getRunningScene()->addChild(alert); alert->runAction(cocos2d::FadeTo::create(AniMiscUtils::StandardAnimationTime, alpha)); } } bool AniAlertUtils::closeDialogIfNecessary(int tag){ auto alertNode = cocos2d::Director::getInstance()->getRunningScene()->getChildByTag(tag); if(alertNode != nullptr) { alertNode->removeFromParent(); return true; } return false; } //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) void AniAlertUtils::showAppCloseConfirmDialog(std::function onCancelCallback){ showTwoButtonDialog(AniAlertViewTagCloseConfirm, "Are you sure you want to quit?", "Yes, bye!", "No, let's play!", [](){ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) cocos2d::Director::getInstance()->end(); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) cocos2d::AudioEngine::stopAll(); cocos2d::Director::getInstance()->pause(); handler_nativeExitGame(); #else cocos2d::Director::getInstance()->end(); #endif //auto scene = HelloWorld::createScene(); //cocos2d::Director::getInstance()->replaceScene(scene); }, onCancelCallback); } bool AniAlertUtils::closeAppCloseConfirmDialogIfNecessary(){ return closeDialogIfNecessary(AniAlertViewTagCloseConfirm); } //#endif