Example #1
0
bool CCLobbyView::initTopMenu()
{
    CCDirector* director = CCDirector::sharedDirector();
    const CCSize winSize = director->getWinSize();
    const CCSize mySize = this->getContentSize();
    const CCPoint center = ccpMult( ccpFromSize( mySize ), 0.5f );
    
    CCLabelTTF* consoleLabel = CCLabelTTF::create( "disconnected", "Arial", FONT_SIZE(24), CCSizeMake( winSize.width, FONT_SIZE(24) ), kCCTextAlignmentCenter );
    consoleLabel->setColor( ccc3(255, 255, 255) );
    CCMenuItemLabel* consoleItem = CCMenuItemLabel::create( consoleLabel );
    
    // bottom
    const CCSize editSize = CCSizeMake( winSize.width, FONT_SIZE(48) );
    CCMenuItem* editItem = CCMenuItem::create();
    editItem->setContentSize( editSize );
    
    CCMenu* topMenu = CCMenu::create( consoleItem, editItem, NULL );
    if( topMenu )
    {
        this->setConsole( consoleLabel );
        
        topMenu->alignItemsVertically();
        topMenu->setPosition( CCPointMake( center.x, winSize.height - (editItem->getContentSize().height + consoleItem->getContentSize().height)/2 ) );
        this->addChild( topMenu, 0, Child::CCMenu_topMenu );
        
        const CCPoint editItemPosition = editItem->getParent()->convertToWorldSpace( editItem->getPosition() );
        editItem->setContentSize( winSize );
        editItem->ignoreAnchorPointForPosition( false );
        editItem->setAnchorPoint( ccp( 0.5f, (winSize.height / (editItemPosition.y - winSize.height)) * 0.5f ) );
        
        CCScale9Sprite* editSprite = CCScale9Sprite::create("extensions/yellow_edit.png");
        CCEditBox* edit = CCEditBox::create( editSize, editSprite );
        edit->setPlaceHolder("PlayerName");
        edit->setReturnType(kKeyboardReturnTypeDone);
        edit->setFontColor(ccGRAY);
        edit->setMaxLength( 20 );
        edit->setDelegate(this);
        edit->setTouchEnabled( true );
        edit->setPosition( editItemPosition );
        CocosNetworkLogic* network = CocosNetworkLogic::getInstance();
        JString userName = network->getUserName();
        edit->setText(userName.UTF8Representation().cstr());
        this->addChild( edit );
        this->setEditName(edit);
    }
    
    return topMenu;
}
Example #2
0
void ADAds::fillBanner(Banner* banner)
{
#if defined(_DEBUG) && CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
    CCRenderTexture* texture = CCRenderTexture::create(100, 100);
    texture->beginWithClear(0.5f, 0.5f, 0.5f, 1);

    texture->end();

    CCSprite* s = CCSprite::createWithTexture(texture->getSprite()->getTexture());

    s->setScaleX(banner->getContentSize().width/s->getContentSize().width);
    s->setScaleY(banner->getContentSize().height/s->getContentSize().width);
    banner->addChild(s);
    s->setAnchorPoint(ccp(0,0));
    s->setPosition(ccp(0,0));
#endif

    if(_home_banners.size())
    {
        //std::random_shuffle(_home_banners.begin(), _home_banners.end());
        CustomBanner* home_ads = getCustomBanner();

        CCMenuItem* item = CCMenuItem::create(
                               home_ads, menu_selector(CustomBanner::onClick));


        CCMenu* menu = CCMenu::create();
        menu->addChild(item);

        banner->addChild(menu, 0, HOME_ADS_NODE_TAG);
        menu->setAnchorPoint(ccp(0,0));

        menu->setPosition(ccp(0,0));

        CCNode* banner_content = home_ads->getBanner();
        CCSize content_size = banner_content->getContentSize();
        CCSize zone_size = banner->getContentSize();

        float scale = MIN(zone_size.width/content_size.width,
                          zone_size.height/content_size.height);
        banner_content->setScale(scale);
        banner_content->setAnchorPoint(ccp(0, 0));
        banner_content->setPosition(ccp(0,0));

        item->setContentSize(content_size*scale);
        item->setAnchorPoint(ccp(0.5f,0.5f));
        item->setPosition(zone_size*0.5f);
        item->addChild(banner_content);
    }
}
bool MainMenu::initPassAndPlay()
{
    this->removeChildByTag( Child::CCMenuItem_passAndPlay, true );
    
    CCMenuItem* item = CCMenuItem::create( this, menu_selector( MainMenu::passAndPlayCallback ) );
    CCSprite* sprite = CCSprite::create( "button_passAndPlay.png" );
    sprite->setAnchorPoint(CCPointZero);
    item->setContentSize( sprite->getContentSize() );
    item->addChild( sprite );
    CCLabelTTF* label = CCLabelTTF::create("Pass and Play", "American Typewritter.ttf", 24);
    label->setAnchorPoint(CCPointZero);
    label->setPosition( ccp( sprite->getContentSize().width * 0.25, sprite->getContentSize().height * 0.5 ) );
    item->addChild(label);
    
    this->addChild( item, 0, Child::CCMenuItem_passAndPlay );
    return true;
}
Example #4
0
// on "init" you need to initialize your instance
bool TableBar::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    //每个项目都要创建的东西
    _menu = CCMenu::create(NULL);
    _menu->setPosition(CCPointZero);
    this->addChild(_menu, zNum+1);
    
    pTabBar = CCSprite::create("pTabBar.png");
    pTabBar->setPosition(ccp(1024.0,49.0));    
    this->addChild(pTabBar,zNum);

    
    m_highlightSp = CCSprite::create("pTabBarSelectedHighlight.png");


    string plistStr = TableBar::classPlistName;
    plistStr += ".plist";
    plistDic = CCDictionary::createWithContentsOfFile(plistStr.c_str());
    
    for (int i = 0; i<itemVec.size(); i++)
    {
        const char * picNameStr =  (itemVec[i]+".png").c_str();
        CCSprite * aSprite = CCSprite::create(picNameStr);
        
        if (i == TableBar::mainItemNum)
        {
            mainitemSprite = aSprite;
        }
        
        const char * positionName = itemVec[i].c_str();
        aSprite->setPosition(ScriptParser::getPositionFromPlist(plistDic,positionName));        
        this->addChild(aSprite,zNum);
        
        CCMenuItem * aItem = CCMenuItem::create(this, menu_selector(TableBar::menuselect));
        aItem->setPosition(aSprite->getPosition());
        aItem->setContentSize(m_highlightSp->getContentSize());
        _menu ->addChild(aItem,zNum);
        aItem->setTag(i);
        
        const char * itemTitleStr = itemTitleVec[i].c_str();
        CCLabelTTF* pLabel = CCLabelTTF::create(itemTitleStr,fontName_macro,fontSize_macro);
        if (i == TableBar::mainItemNum)
        {
            pLabel->setColor(White_macro);
        }
        else
        {
            pLabel->setColor(gray_macro);
        }

        const char * labelNameStr =  (itemVec[i]+"Label").c_str();
        pLabel->setPosition(ScriptParser::getPositionFromPlist(plistDic,labelNameStr));
        this->addChild(pLabel, zNum);
    }

    m_highlightSp->setPosition(ccp(mainitemSprite->getPosition().x,pTabBar->getPosition().y+pTabBar->getContentSize().height/2-50));
    this->addChild(m_highlightSp,zNum);
    m_highlightSp->setColor(ccc3(200, 200, 200));
    
    return true;
}