Blame view

ios/Runner/Wowgame/Classes/game_animal/AniAlertUtils.cpp 2.96 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  
  //
  //  AniAlertUtils.cpp
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
  //
  //
  
  #include <stdio.h>
  #include "AniAlertUtils.h"
  #include "AniAlertView.h"
  #include "AniMiscUtils.h"
  #include "HelloWorldScene.h"
68a4c50a   xiaoyu   Merge remote-trac...
15
16
17
18
19
20
  
  #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
  #include "RatePromptHandler_ios.h"
  #endif
  #include "audio/include/AudioEngine.h"
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
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
  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<void()> onOKCallback, std::function<void()> 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;
  }
  
68a4c50a   xiaoyu   Merge remote-trac...
55
  //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
56
57
58
  
  void AniAlertUtils::showAppCloseConfirmDialog(std::function<void()> onCancelCallback){
      showTwoButtonDialog(AniAlertViewTagCloseConfirm, "Are you sure you want to quit?", "Yes, bye!", "No, let's play!", [](){
68a4c50a   xiaoyu   Merge remote-trac...
59
60
61
62
63
64
65
66
67
68
69
  #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);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
70
71
72
73
74
75
76
77
  
      }, onCancelCallback);
  }
  
  bool AniAlertUtils::closeAppCloseConfirmDialogIfNecessary(){
      return closeDialogIfNecessary(AniAlertViewTagCloseConfirm);
  }
  
68a4c50a   xiaoyu   Merge remote-trac...
78
  //#endif