Blame view

ios/Runner/Wowgame/Classes/game_toy/ToySettingsLayer.cpp 6.92 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
66
67
68
69
70
71
72
73
74
75
76
77
78
  //
  //  ToySettingsLayer.cpp
  //  Steve and Maggie Halloween
  //
  //  Created by Katarzyna Kalinowska-Górska on 06/10/2019.
  //
  
  #include <stdio.h>
  #include "ToySettingsLayer.h"
  #include "ToyMiscUtils.h"
  #include "ToyScalingUtils.h"
  #include "ToyStrings.h"
  #include "ToySimpleButton.h"
  
  ToySettingsLayer* ToySettingsLayer::create(float width, float height, std::function<void(int)> onLevelPickedCallback){
      ToySettingsLayer * view = new (std::nothrow) ToySettingsLayer();
      if(view && view->init(width, height, onLevelPickedCallback))
      {
          view->autorelease();
          return view;
      }
      CC_SAFE_DELETE(view);
      return nullptr;
  }
  
  bool ToySettingsLayer::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 = cocos2d::Node::create();
      addChild(wholeContainer);
      
      auto upperStuffContainer = cocos2d::Node::create();
      wholeContainer->addChild(upperStuffContainer);
      
      auto paddingTop = 60*ToyScalingUtils::scaleAspectFillToDesignIpadProSize();
  //    auto lpPaddingLeft = 60*ToyScalingUtils::scaleAspectFillToDesignIpadProSize();
      
      // add the instruction label
  //    auto instructionLabel = cocos2d::Label::createWithTTF("LEVEL:", "fonts/ComicSansMSBold.ttf", 120*ToyScalingUtils::getScaleForFont()); //magic number
  //    instructionLabel->setColor(cocos2d::Color3B(200, 200, 200));
  //    upperStuffContainer->addChild(instructionLabel);
  
      std::vector<std::string> levelImagePaths = { "graphics/levels/level_1.png", "graphics/levels/level_2.png", "graphics/levels/level_3.png" };
      _levelPickerView = ToyLevelPickerView::create(levelImagePaths, std::vector<std::string>());
      upperStuffContainer->addChild(_levelPickerView);
      _levelPickerView->addOnLevelChangedCallback([&](int pickedLevel){
          ToyMiscUtils::saveLastLevel(pickedLevel);
          _onLevelPicked(pickedLevel);
      });
      _levelPickerView->selectLevelIndex((int)ToyMiscUtils::lastLevel(), false);
      
      upperStuffContainer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
      upperStuffContainer->setContentSize(_levelPickerView->getContentSize());
      upperStuffContainer->setPosition(width/2, height/2 + paddingTop);
      
      _levelPickerView->setAnchorPoint(cocos2d::Vec2(1, 0.5));
      _levelPickerView->setPosition(upperStuffContainer->getContentSize().width, upperStuffContainer->getContentSize().height/2);
  
      
      auto lowerStuffContainer = cocos2d::Node::create();
      wholeContainer->addChild(lowerStuffContainer);
      
      auto menuItemColor = cocos2d::Color3B(140, 140, 140);
      cocos2d::MenuItemFont::setFontSize(140*ToyScalingUtils::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 webLinkButton = ToySimpleButton::create();
      wholeContainer->addChild(webLinkButton);
68a4c50a   xiaoyu   Merge remote-trac...
79
      webLinkButton->setVisible(false);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
80
81
82
83
84
85
      auto buttonTexturePath = "settings_buttons/steve_maggie.png";
      webLinkButton->loadTextures(buttonTexturePath, buttonTexturePath, buttonTexturePath);
      webLinkButton->setPosition(cocos2d::Point(getContentSize().width/2, upperStuffContainer->getBoundingBox().getMinY() - paddingTop*2 - webLinkButton->getBoundingBox().size.height/2));
      webLinkButton->setOnTouchEndedCallback([&, webLinkButton](std::string name, cocos2d::ui::Widget::TouchEventType eventType){
  //       presentParentalGate([&](){
  //            hideParentalGate();
68a4c50a   xiaoyu   Merge remote-trac...
86
  //            cocos2d::Application::getInstance()->openURL("https://www.steveandmaggie.com"); //TODO hardcoded
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  //        }, [&](){
  //            hideParentalGate();
  //        });
      });
      
      auto menuPadding = 40*ToyScalingUtils::scaleAspectFillToDesignIpadProSize();//TODO magic number
  //    auto menuContainer = cocos2d::Node::create();
      auto menuItemAbout = cocos2d::MenuItemFont::create("Terms of Use", CC_CALLBACK_1(ToySettingsLayer::aboutMenuButtonTapped, this));
      auto menuItemPrivacyPolicy = cocos2d::MenuItemFont::create("Privacy Policy", CC_CALLBACK_1(ToySettingsLayer::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);
  //    menuContainer->addChild(menuCenter);
  //    menuContainer->setContentSize(menuCenter->getContentSize());
  //    menuContainer->setAnchorPoint(cocos2d::Point(1, 0.5));
  //    menuContainer->setPosition(getContentSize().width/2, weLogo->getPositionY());
      lowerStuffContainer->addChild(menuCenter);//addChild(menuContainer, 3);
      
      lowerStuffContainer->setContentSize(cocos2d::Size(menuCenter->getContentSize().width, menuCenter->getBoundingBox().size.height));
      lowerStuffContainer->setAnchorPoint(cocos2d::Vec2(0.5, 1));
      lowerStuffContainer->setPosition(getContentSize().width/2, webLinkButton->getBoundingBox().getMinY() - paddingTop*0.8f);
      
      menuCenter->setPosition(lowerStuffContainer->getContentSize().width/2, lowerStuffContainer->getContentSize().height/2);
      
22495953   xiaoyu   打开多点触控,开启游戏时使用hud遮罩
112
113
      menuCenter->setVisible(false);
      
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
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
      wholeContainer->setContentSize(cocos2d::Size(getContentSize().width, upperStuffContainer->getContentSize().height + lowerStuffContainer->getContentSize().height + paddingTop));
      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);
      
      return true;
  }
  
  void ToySettingsLayer::prepareForShowing(){
      _levelPickerView->selectLevelIndex((int)(ToyMiscUtils::lastLevel()), false);
  }
  
  void ToySettingsLayer::aboutMenuButtonTapped(cocos2d::Ref* pSender){
  //    presentParentalGate([&](){
  //        hideParentalGate();
          cocos2d::Application::getInstance()->openURL(ToyStrings::LINK_TERMS_OF_SERVICE);
  //    }, [&](){
  //        hideParentalGate();
  //    });
  }
  
  void ToySettingsLayer::privacyPolicyMenuButtonTapped(cocos2d::Ref* pSender){
  //    presentParentalGate([&](){
  //        hideParentalGate();
          cocos2d::Application::getInstance()->openURL(ToyStrings::LINK_PRIVACY_POLICY);
  //    }, [&](){
  //        hideParentalGate();
  //    });
  }