Blame view

ios/Runner/Wowgame/Classes/CustomViews/ParentalGateShowInterface.cpp 2.21 KB
cb213901   xiaoyu   添加一个游戏的源码和编译选项
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
  //
  //  ParentalGateShowInterface.cpp
  //  Steve and Maggie Halloween
  //
  //  Created by Katarzyna Kalinowska-Górska on 14/10/2019.
  //
  
  #include "ParentalGateShowInterface.h"
  #include "MiscUtils.h"
  #include "ParentalGateView.h"
  
  static int ParentalGateViewTag = 90;
  
  void ParentalGateShowInterface::presentParentalGate(std::function<void()> onSuccessCallback, std::function<void()> onFailureCallback){
      _isPresentingParentalGate = true;
      auto screenSize = cocos2d::Director::getInstance()->getWinSize();
      auto parentalGate = ParentalGateView::create(screenSize.width, screenSize.height, onSuccessCallback, onFailureCallback);
      parentalGate->setTag(ParentalGateViewTag);
      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->stopAllActions();
      parentalGate->setOpacity(0);
      parentalGate->runAction(cocos2d::FadeIn::create(MiscUtils::StandardAnimationTime));
  }
  
  void ParentalGateShowInterface::hideParentalGate(){
      _isPresentingParentalGate = false;
      auto parentalGate = PGSI_getChildByTag(ParentalGateViewTag);
      if(parentalGate != nullptr){
          parentalGate->stopAllActions();
          PGSI_getEventDispatcher()->removeEventListenersForTarget(parentalGate);
          MiscUtils::hideAndRemoveView(parentalGate, true);
      }
  }