Blame view

ios/Runner/Wowgame/Classes/game_halloween/HSettingsLayer.cpp 7.01 KB
5daad4bc   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
55
56
57
58
59
60
61
62
63
64
65
  //
  //  HSettingsLayer.cpp
  //  Steve and Maggie Halloween
  //
  //  Created by Katarzyna Kalinowska-Górska on 06/10/2019.
  //
  
  #include <stdio.h>
  #include "HSettingsLayer.h"
  #include "HMiscUtils.h"
  #include "HScalingUtils.h"
  #include "HStrings.h"
  #include "HalloweenSimpleButton.h"
  #include "KKGLinearLayout.h"
  #include "KKGLabelOnlyButton.hpp"
  
  HSettingsLayer* HSettingsLayer::create(float width, float height, std::function<void(int)> onLevelPickedCallback){
      HSettingsLayer * view = new (std::nothrow) HSettingsLayer();
      if(view && view->init(width, height, onLevelPickedCallback))
      {
          view->autorelease();
          return view;
      }
      CC_SAFE_DELETE(view);
      return nullptr;
  }
  
  bool HSettingsLayer::init(float width, float height, std::function<void(int)> onLevelPickedCallback){
      
      if(!cocos2d::LayerColor::initWithColor(cocos2d::Color4B(0,0,0,230), width, height)){
          return false;
      }
      
      _isPresentingParentalGate = false;
      _onLevelPicked = onLevelPickedCallback;
  
      auto wholeContainer = KKGLinearLayout::create(KKGLinearLayout::VERTICAL,
                                                    KKGLinearLayout::ACENTER,
                                                    KKGLinearLayout::GCENTER);
      addChild(wholeContainer);
  
      auto upperStuffContainer = cocos2d::Node::create();
      wholeContainer->addView(upperStuffContainer);
      
      auto padding = 50*HScalingUtils::scaleAspectFillToDesignIpadProSize();
      wholeContainer->setInterViewMargin(padding, false);
  
      std::vector<std::string> levelImagePaths = { "graphics/levels/level_1.png", "graphics/levels/level_2.png", "graphics/levels/level_3.png" };
      _HLevelPickerView = HLevelPickerView::create(levelImagePaths, std::vector<std::string>());
      upperStuffContainer->addChild(_HLevelPickerView);
      _HLevelPickerView->addOnLevelChangedCallback([&](int pickedLevel){
          HMiscUtils::saveLastLevel(pickedLevel);
          _onLevelPicked(pickedLevel);
      });
      _HLevelPickerView->selectLevelIndex((int)HMiscUtils::lastLevel(), false);
  
      auto paddingBottom = padding;
      upperStuffContainer->setContentSize(cocos2d::Size(_HLevelPickerView->getContentSize().width,
                                                        _HLevelPickerView->getContentSize().height + paddingBottom));
  
      _HLevelPickerView->setAnchorPoint(cocos2d::Vec2(1, 0.5));
      _HLevelPickerView->setPosition(upperStuffContainer->getContentSize().width, upperStuffContainer->getContentSize().height/2 + paddingBottom);
  
      auto webLinkButton = HalloweenSimpleButton::create();
      wholeContainer->addView(webLinkButton);
68a4c50a   xiaoyu   Merge remote-trac...
66
      webLinkButton->setVisible(false);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
67
68
69
      auto buttonTexturePath = "settings_buttons/steve_maggie.png";
      webLinkButton->loadTextures(buttonTexturePath, buttonTexturePath, buttonTexturePath);
      webLinkButton->setOnTouchEndedCallback([&, webLinkButton](std::string name, cocos2d::ui::Widget::TouchEventType eventType){
68a4c50a   xiaoyu   Merge remote-trac...
70
71
72
73
74
75
         // presentParentalGate([&](){
         //      hideParentalGate();
         //      cocos2d::Application::getInstance()->openURL("https://www.steveandmaggie.com"); //TODO hardcoded
         //  }, [&](){
         //      hideParentalGate();
         //  });
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
      });
      
      auto lowerStuffContainer = cocos2d::Node::create();
      wholeContainer->addView(lowerStuffContainer);
  
      auto menuItemColor = cocos2d::Color3B(140, 140, 140);
      cocos2d::MenuItemFont::setFontSize(140*HScalingUtils::getScaleForFont()); //TODO MAGIC NUMBER
  #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
      cocos2d::MenuItemFont::setFontName("ComicSansMS-Bold");
  #else
      cocos2d::MenuItemFont::setFontName("fonts/ComicSansMSBold.ttf");
  #endif
      
      auto menuPadding = 40*HScalingUtils::scaleAspectFillToDesignIpadProSize();//TODO magic number
      auto menuItemAbout = cocos2d::MenuItemFont::create("Terms of Use", CC_CALLBACK_1(HSettingsLayer::aboutMenuButtonTapped, this));
      auto menuItemPrivacyPolicy = cocos2d::MenuItemFont::create("Privacy Policy", CC_CALLBACK_1(HSettingsLayer::privacyPolicyMenuButtonTapped, this));
      auto menuCenter = cocos2d::Menu::create(menuItemAbout,menuItemPrivacyPolicy, NULL);
      menuCenter->setContentSize(cocos2d::Size(MAX(menuItemAbout->getBoundingBox().size.width, menuItemPrivacyPolicy->getBoundingBox().size.width), menuItemAbout->getBoundingBox().size.height + menuItemPrivacyPolicy->getBoundingBox().size.height + 3*menuPadding));
      menuCenter->setColor(menuItemColor);
      menuCenter->alignItemsVerticallyWithPadding(menuPadding);
      lowerStuffContainer->addChild(menuCenter);//addChild(menuContainer, 3);
      
      lowerStuffContainer->setContentSize(cocos2d::Size(menuCenter->getContentSize().width, menuCenter->getBoundingBox().size.height));
  
      menuCenter->setPosition(lowerStuffContainer->getContentSize().width/2, lowerStuffContainer->getContentSize().height/2);
  
22495953   xiaoyu   打开多点触控,开启游戏时使用hud遮罩
102
103
      menuCenter->setVisible(false);
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
      wholeContainer->wrapContents();
      wholeContainer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
      wholeContainer->setPosition(width/2, height/2);
      
      wholeContainer->setCascadeOpacityEnabled(true);
      upperStuffContainer->setCascadeOpacityEnabled(true);
      lowerStuffContainer->setCascadeOpacityEnabled(true);
      
      //        auto bg = cocos2d::LayerColor::create(cocos2d::Color4B(100,100,255, 255));
  //        bg->setContentSize(lowerStuffContainer->getContentSize());
  //        lowerStuffContainer->addChild(bg);
  //        bg->_setLocalZOrder(-10);
      
      auto paddingExitButton = 20*HScalingUtils::scaleAspectFillToDesignIpadProSize();
      auto scaleExitButton = 1.0f;
      if(HScalingUtils::isSmallDevice()){
          paddingExitButton *= HScalingUtils::getScaleForSmallDevice();
          scaleExitButton = 1.6f;
      }
      
      auto appExitButton = HalloweenSimpleButton::create();
      addChild(appExitButton);
      auto exitButtonTexturePath = "buttons/graphics/button_x.png";
      appExitButton->loadTextures(exitButtonTexturePath, exitButtonTexturePath, exitButtonTexturePath);
      appExitButton->setScale(scaleExitButton);
      appExitButton->setOriginalScale(scaleExitButton);
      appExitButton->setPosition(cocos2d::Point(getContentSize().width - appExitButton->getBoundingBox().size.width/2 - paddingExitButton, getContentSize().height - appExitButton->getBoundingBox().size.height/2 - paddingExitButton));
      appExitButton->setOnTouchEndedCallback([&, appExitButton](std::string name, cocos2d::ui::Widget::TouchEventType eventType){
          HMiscUtils::showAppCloseConfirmDialog([&](){
          });
      });
      
      return true;
  }
  
  void HSettingsLayer::prepareForShowing(){
      _HLevelPickerView->selectLevelIndex((int)(HMiscUtils::lastLevel()), false);
  }
  
  void HSettingsLayer::aboutMenuButtonTapped(cocos2d::Ref* pSender){
      presentParentalGate([&](){
          hideParentalGate();
          cocos2d::Application::getInstance()->openURL(HStrings::LINK_TERMS_OF_SERVICE);
      }, [&](){
          hideParentalGate();
      });
  }
  
  void HSettingsLayer::privacyPolicyMenuButtonTapped(cocos2d::Ref* pSender){
      presentParentalGate([&](){
          hideParentalGate();
          cocos2d::Application::getInstance()->openURL(HStrings::LINK_PRIVACY_POLICY);
      }, [&](){
          hideParentalGate();
      });
  }