void Dialog::updateLayout() { Size content_size = this->getContentSize(); Menu* menu = Menu::create(); menu->setPosition(15.0f, 10.0f); menu->setContentSize(Size(240.0f, 27.0f)); float button_size = (240.0f - 1.0f * (m_list_button.size() - 1)) / m_list_button.size(); int i = 0; for(auto it = m_list_button.begin(); it != m_list_button.end(); it++, i++) { if(it != m_list_button.begin()) { DrawObject* draw_line = DrawObject::create(); draw_line->setPosition(button_size + 1.0f * (i - 1), 1.0f); draw_line->setContentSize(Size(1.0f, 25.0f)); draw_line->setOnDraw([=] () { DrawPrimitives::setDrawColor4B(127, 127, 127, 255); DrawPrimitives::drawLine(Point(0.0f, 0.0f), Point(0.0f, draw_line->getContentSize().height)); }); draw_line->setAnchorPoint(Point(0.0f, 0.0f)); menu->addChild(draw_line); } LabelTTF* label = LabelTTF::create(it->first, FourCard::DEFAULT_FONT, 20.0f, Size(button_size, 27.0f), TextHAlignment::CENTER, TextVAlignment::CENTER); label->setColor(Color3B(127, 127, 127)); label->setAnchorPoint(Point(0.0f, 0.0f)); MenuItemLabel* menuItem = MenuItemLabel::create(label, [=] (Object* pSender) { it->second(); }); menuItem->setAnchorPoint(Point(0.0f, 0.0f)); menuItem->setPosition(button_size * i + 1.0f * i, 0.0f); menu->addChild(menuItem); } m_dialog->addChild(menu); DrawObject* draw_line_message = DrawObject::create(); draw_line_message->setPosition(15.0f, 47.0f); draw_line_message->setContentSize(Size(240.0f, 1.0f)); draw_line_message->setOnDraw([=] () { DrawPrimitives::setDrawColor4B(127, 127, 127, 255); DrawPrimitives::drawLine(Point(0.0f, 0.0f), Point(draw_line_message->getContentSize().width, 0.0f)); }); draw_line_message->setAnchorPoint(Point(0.0f, 0.0f)); m_dialog->addChild(draw_line_message); if(m_layer != nullptr) { m_layer->setPosition(15.0f + (240.0f - m_layer->getContentSize().width) / 2, 48.0f); m_dialog->addChild(m_layer); } LabelTTF* label_message = LabelTTF::create(m_message, FourCard::DEFAULT_FONT, 15.0f, Size(240.0f, 0.0f), TextHAlignment::CENTER); label_message->setPosition(15.0f, 63.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0)); label_message->setColor(Color3B(60, 60, 60)); label_message->setAnchorPoint(Point(0.0f, 0.0f)); m_dialog->addChild(label_message); DrawObject* draw_line_title = DrawObject::create(); draw_line_title->setPosition(15.0f, 59.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0) + label_message->getContentSize().height + 15.0f); draw_line_title->setContentSize(Size(240.0f, 1.0f)); draw_line_title->setOnDraw([=] () { DrawPrimitives::setDrawColor4B(127, 127, 127, 255); DrawPrimitives::drawLine(Point(0.0f, 0.0f), Point(draw_line_title->getContentSize().width, 0.0f)); }); draw_line_title->setAnchorPoint(Point(0.0f, 0.0f)); m_dialog->addChild(draw_line_title); LabelTTF* label_title = LabelTTF::create(m_title, FourCard::DEFAULT_FONT, 20.0f, Size(240.0f, 27.0f), TextHAlignment::LEFT, TextVAlignment::CENTER); label_title->setPosition(15.0f, 74.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0) + label_message->getContentSize().height + 1.0f + 10.0f); label_title->setColor(Color3B(60, 60, 60)); label_title->setAnchorPoint(Point(0.0f, 0.0f)); m_dialog->addChild(label_title); m_dialog->setContentSize(Size(270.0f, 124.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0) + label_message->getContentSize().height)); m_dialog->setPosition((content_size.width - m_dialog->getContentSize().width) / 2, (content_size.height - m_dialog->getContentSize().height) / 2); Scale9Sprite* sprite_background = Scale9Sprite::create(Rect(10, 10, 1, 1), "sprites/dialog/background.png"); sprite_background->setContentSize(m_dialog->getContentSize()); sprite_background->setAnchorPoint(Point(0.0f, 0.0f)); m_dialog->addChild(sprite_background, -1); }
// on "init" you need to initialize your instance bool TestSocial::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } MySocialManager::getInstance()->loadPlugins(); Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); Point posMid = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); Point posBR = Point(origin.x + visibleSize.width, origin.y); MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestSocial::menuBackCallback, this)); Size backSize = pBackItem->getContentSize(); pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2)); // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); pMenu->setPosition( Point::ZERO ); LabelTTF* label1 = LabelTTF::create("Submit Score", "Arial", 28); MenuItemLabel* pItemSubmit = MenuItemLabel::create(label1, CC_CALLBACK_1(TestSocial::testSubmit, this)); pItemSubmit->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemSubmit, 0); pItemSubmit->setPosition(posMid + Point(-140, -60)); LabelTTF* label2 = LabelTTF::create("Unlock Achievement", "Arial", 28); MenuItemLabel* pItemUnlock = MenuItemLabel::create(label2, CC_CALLBACK_1(TestSocial::testUnlock, this)); pItemUnlock->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemUnlock, 0); pItemUnlock->setPosition(posMid + Point(140, -60)); LabelTTF* label3 = LabelTTF::create("Show Leaderboard", "Arial", 28); MenuItemLabel* pItemLeader = MenuItemLabel::create(label3, CC_CALLBACK_1(TestSocial::testLeaderboard, this)); pItemLeader->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemLeader, 0); pItemLeader->setPosition(posMid + Point(-140, -120)); LabelTTF* label4 = LabelTTF::create("Show Achievement", "Arial", 28); MenuItemLabel* pItemAchi = MenuItemLabel::create(label4, CC_CALLBACK_1(TestSocial::testAchievement, this)); pItemAchi->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemAchi, 0); pItemAchi->setPosition(posMid + Point(140, -120)); // create optional menu // cases item _caseItem = MenuItemToggle::createWithCallback(NULL, MenuItemFont::create( s_aTestCases[0].c_str() ), NULL ); int caseLen = sizeof(s_aTestCases) / sizeof(std::string); for (int i = 1; i < caseLen; ++i) { _caseItem->getSubItems().pushBack( MenuItemFont::create( s_aTestCases[i].c_str() ) ); } _caseItem->setPosition(posMid + Point(0, 120)); pMenu->addChild(_caseItem); this->addChild(pMenu, 1); return true; }
// on "init" you need to initialize your instance bool TestAds::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } _listener = new MyAdsListener(); _admob = dynamic_cast<ProtocolAds*>(PluginManager::getInstance()->loadPlugin("AdsAdmob")); _flurryAds = dynamic_cast<ProtocolAds*>(PluginManager::getInstance()->loadPlugin("AdsFlurry")); TAdsDeveloperInfo devInfo; #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS devInfo["AdmobID"] = ADMOB_ID_IOS; devInfo["FlurryAppKey"] = FLURRY_KEY_IOS; #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID devInfo["AdmobID"] = ADMOB_ID_ANDROID; devInfo["FlurryAppKey"] = FLURRY_KEY_ANDROID; #endif _admob->configDeveloperInfo(devInfo); _admob->setAdsListener(_listener); _admob->setDebugMode(true); _flurryAds->configDeveloperInfo(devInfo); _flurryAds->setAdsListener(_listener); _flurryAds->setDebugMode(true); Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); Point posMid = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); Point posBR = Point(origin.x + visibleSize.width, origin.y); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestAds::menuBackCallback, this)); Size backSize = pBackItem->getContentSize(); pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2)); // create menu, it's an autorelease object Menu* pMenu = Menu::create(pBackItem, NULL); pMenu->setPosition( Point::ZERO ); LabelTTF* label1 = LabelTTF::create("ShowAds", "Arial", 24); MenuItemLabel* pItemShow = MenuItemLabel::create(label1, CC_CALLBACK_1(TestAds::testShow, this)); pItemShow->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemShow, 0); pItemShow->setPosition(posMid + Point(-100, -120)); LabelTTF* label2 = LabelTTF::create("HideAds", "Arial", 24); MenuItemLabel* pItemHide = MenuItemLabel::create(label2, CC_CALLBACK_1(TestAds::testHide, this)); pItemHide->setAnchorPoint(Point(0.5f, 0)); pMenu->addChild(pItemHide, 0); pItemHide->setPosition(posMid + Point(100, -120)); // create optional menu // cases item _caseItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestAds::caseChanged, this), MenuItemFont::create( s_aTestCases[0].c_str() ), NULL ); int caseLen = sizeof(s_aTestCases) / sizeof(std::string); for (int i = 1; i < caseLen; ++i) { _caseItem->getSubItems()->addObject( MenuItemFont::create( s_aTestCases[i].c_str() ) ); } _caseItem->setPosition(posMid + Point(-200, 120)); pMenu->addChild(_caseItem); // poses item _posItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestAds::posChanged, this), MenuItemFont::create( s_aTestPoses[0].c_str() ), NULL ); int posLen = sizeof(s_aTestPoses) / sizeof(std::string); for (int i = 1; i < posLen; ++i) { _posItem->getSubItems()->addObject( MenuItemFont::create( s_aTestPoses[i].c_str() ) ); } _posItem->setPosition(posMid + Point(200, 120)); pMenu->addChild(_posItem); // init options _ads = _admob; _pos = ProtocolAds::kPosCenter; // init the AdsInfo adInfo["AdmobType"] = "1"; adInfo["AdmobSizeEnum"] = "1"; adInfo["FlurryAdsID"] = "BANNER_MAIN_VC"; adInfo["FlurryAdsSize"] = "2"; this->addChild(pMenu, 1); return true; }