Exemple #1
0
void CCtrlPage::SetBgAni(const char* pszAni)
{
	if (NULL == pszAni)
	{
		return;
	}

	clearBackgroundSprite();

	m_strAniSection = std::string(pszAni);

	if (m_strAniSection.empty())
	{
		return;
	}

	CMyIniPtr pAni = g_objIniMgr.GetMyIniPtr(m_strAniPath.c_str());

	if (!pAni)
	{
		return;
	}

	int nFrame = 0;
	std::string strFrame = FORMAT("Frame%d")<<nFrame;
	const char *pszValue = pAni->GetString(m_strAniSection.c_str(), strFrame.c_str());

	if (NULL == pszValue)
	{
		return;
	}

	CCScale9Sprite *backgroundSprite = CCScale9Sprite::create(pszValue);

	if (!backgroundSprite)
	{
		return;
	};

	// 不为9宫格方式
	if (enumUISTRETCH_NORMAL == m_nAniStretch)
	{
		CCRect rectCapInsets = CCRectMake(0, 0, backgroundSprite->getContentSize().width, backgroundSprite->getContentSize().height);
		backgroundSprite->removeAllChildren();
		CCScale9Sprite *backgroundSpriteResize =  backgroundSprite->resizableSpriteWithCapInsets(rectCapInsets);
		CHECK(backgroundSpriteResize);
		setBackgroundSprite(backgroundSpriteResize);
	}
	else if (enumUISTRETCH_STRETCH == m_nAniStretch)
	{
		float fOrgWidth = backgroundSprite->getContentSize().width;
		float fOrgHeight = backgroundSprite->getContentSize().height;
		CCRect rectCapInsets = CCRectMake(0, 0, fOrgWidth, fOrgHeight);
		backgroundSprite->removeAllChildren();
		CCScale9Sprite *backgroundSpriteResize =  backgroundSprite->resizableSpriteWithCapInsets(rectCapInsets);
		CHECK(backgroundSpriteResize);
		float fScaleX = 1.0f;
		float fScaleY = 1.0f;

		if (0.0f != fOrgWidth && 0.0f != fOrgHeight)
		{
			fScaleX = (float)m_nWidth / fOrgWidth;
			fScaleY = (float)m_nHeight / fOrgHeight;
		}

		backgroundSpriteResize->setScaleX(fScaleX);
		backgroundSpriteResize->setScaleY(fScaleY);
		setBackgroundSprite(backgroundSpriteResize);
	}
	else
	{
		setBackgroundSprite(backgroundSprite);
	}

	CHECK(m_backgroundSprite);
	m_backgroundSprite->setAnchorPoint(ccp(0, 0));
	m_backgroundSprite->setPosition(ccp(0, 0));
	this->addChild(m_backgroundSprite, 0);
}
bool CCLobbyView::init( CCNetworkLogic* network, const CCSize& mySize )
{
    if( CCLayer::init() )
    {
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        const CCPoint& center = ccpMult( ccpFromSize( mySize ), 0.5f );
        CCPoint position = CCPointZero;
        CCSize size = CCSizeZero;
        int length = 0;
        int fontSize = 0;
        
        this->setNetwork( network );
        
        CCSprite* s = CCSprite::create("Images/r1.png");
        s->retain();
        CCRect rect = CCRectZero;
        rect.size = s->getContentSize();
        s->release();
        
        fontSize = 12;
        CCLabelTTF* label = CCLabelTTF::create( "Connect", "fonts/American Typewriter.ttf", fontSize );
        label->setColor( ccc3( 0, 0, 0 ) );
        CCScale9Sprite* sprite = CCScale9Sprite::create("Images/r1.png", rect, rect );
        sprite->setScaleX( 1.4f );
        sprite->setScaleY( 0.8f );
        CCControlButton* button = CCControlButton::create( label, sprite );
        button->addTargetWithActionForControlEvents( this, cccontrol_selector( CCLobbyView::connectButtonCallback ), CCControlEventTouchUpInside);
        button->setPreferredSize( rect.size );
        position = center;
        position.y -= 136;
        position.x -= 100;
        button->setPosition( position );
        this->setConnectButton( button );
        
        label = CCLabelTTF::create( "Create Room", "fonts/American Typewriter.ttf", fontSize );
        label->setColor( ccc3( 0, 0, 0 ) );
        sprite = CCScale9Sprite::create("Images/r1.png", rect, rect );
        sprite->setScaleX( 1.4f );
        sprite->setScaleY( 0.8f );
        button = CCControlButton::create( label, sprite );
        button->addTargetWithActionForControlEvents( this, cccontrol_selector( CCLobbyView::createGameButtonCallback ), CCControlEventTouchUpInside);
        button->setPreferredSize( rect.size );
        position = center;
        position.y -= 136;
        //position.x += 0;
        button->setPosition( position );
        this->setCreateGameButton( button );
        
        label = CCLabelTTF::create( "Random Room", "fonts/American Typewriter.ttf", fontSize );
        label->setColor( ccc3( 0, 0, 0 ) );
        sprite = CCScale9Sprite::create("Images/r1.png", rect, rect );
        sprite->setScaleX( 1.6f );
        sprite->setScaleY( 0.8f );
        button = CCControlButton::create( label, sprite );
        button->addTargetWithActionForControlEvents( this, cccontrol_selector( CCLobbyView::joinGameButtonCallback ), CCControlEventTouchUpInside);
        button->setPreferredSize( rect.size );
        position = center;
        position.y -= 136;
        position.x += 100;
        button->setPosition( position );
        this->setRandomGameButton( button );
        
        this->_lobbyViewDataSource = new CCLobbyViewDataSource( this );

        fontSize = 16;
        length = mySize.width;
        size = this->_lobbyViewDataSource->cellSizeForTable( NULL );
        size.height *= 3;
        CCTableView* table = CCTableView::create( this->_lobbyViewDataSource, size );
        table->setContentOffset( CCPointZero );
        table->setDirection(kCCScrollViewDirectionVertical);
        position = center;
        position.x -= size.width * 0.5f;
        position.y -= fontSize + ( size.height * 0.17f );
        table->setPosition( position );
        table->setDelegate( this );
        table->setVerticalFillOrder(kCCTableViewFillTopDown);
        this->setRoomTable( table );
        table->reloadData();
        
        fontSize = 16;
        label = CCLabelTTF::create("Running games:", "fonts/American Typewriter.ttf", fontSize,
                                                 winSize, kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
        position = center;
        position.x -= size.width * 0.4f;
        position.y += size.height - ( fontSize * 0.5f );
        label->setPosition( position );
        //label->setAnchorPoint( CCPointZero );
        this->setRoomTableLabel( label );
        
        fontSize = 16;
        CCLabelTTF* console = CCLabelTTF::create("disconnected", "fonts/American Typewriter.ttf", fontSize,
                                             winSize, kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
        
            
        console->setColor( ccc3(255, 255, 255) );
        console->setContentSize(winSize);
        position = center;
        position.y += 100;
        console->setPosition( position );
        this->setConsole( console );
        
        label = CCLabelTTF::create( "localhost:5055", "fonts/American Typewriter.ttf", fontSize );
        position.y += fontSize;
        label->setPosition( position );
        this->setDisplayAddress( label );
        
        // top
        fontSize = 24;
        length = 19;
        size = CCSize( length * fontSize * 0.7f, fontSize * 1.7f );
        CCEditBox* edit = CCEditBox::create( size, CCScale9Sprite::create( "extensions/green_edit.png" ) );
        edit->setPosition( center );
        edit->setFontColor(ccBLACK);
        edit->setPlaceHolder("ip:port");
        edit->setMaxLength( 19 );
        edit->setReturnType(kKeyboardReturnTypeDone);
        edit->setDelegate(this);
        position.y -= fontSize * 2;
        edit->setPosition( position );
        this->setEditAddress( edit );
        
        //CCChatRoom* chatroom = CCChatRoom::create(this->getNetwork());
        //this->setChatRoom( chatroom );
        
        this->scheduleUpdate();

        return true;
    }
    
    return false;
}