HParentalGateShowInterface.cpp
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
//  HParentalGateShowInterface.cpp
//  Steve and Maggie Halloween
//
//  Created by Katarzyna Kalinowska-Górska on 14/10/2019.
//
#include "HParentalGateShowInterface.h"
#include "HMiscUtils.h"
#include "HParentalGateView.h"
static int HParentalGateViewTag = 90;
void HParentalGateShowInterface::presentParentalGate(std::function<void()> onSuccessCallback, std::function<void()> onFailureCallback){
    _isPresentingParentalGate = true;
    auto screenSize = cocos2d::Director::getInstance()->getWinSize();
    auto parentalGate = HParentalGateView::create(screenSize.width, screenSize.height, onSuccessCallback, onFailureCallback);
    parentalGate->setTag(HParentalGateViewTag);
    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(HMiscUtils::StandardAnimationTime));
}
void HParentalGateShowInterface::hideParentalGate(){
    _isPresentingParentalGate = false;
    auto parentalGate = PGSI_getChildByTag(HParentalGateViewTag);
    if(parentalGate != nullptr){
        parentalGate->runAction(cocos2d::Sequence::create(cocos2d::FadeOut::create(HMiscUtils::StandardAnimationTime),
                                                          cocos2d::CallFunc::create(std::bind([&](cocos2d::Node* pg){
            HMiscUtils::hideAndRemoveView(pg, true);
        }, parentalGate)), nullptr));
    }
}