Ejemplo n.º 1
0
void PopupLayer::onEnter(){
	CCLayer::onEnter();

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);

	CCSize contentSize;
	if (getContentSize().equals(CCSizeZero)) {
		getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(getSpriteBackGround(), 0, 0);
		contentSize = getSpriteBackGround()->getTexture()->getContentSize();
	} else {
		CCScale9Sprite *background = getSprite9BackGround();
		background->setContentSize(getContentSize());
		background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(background, 0, 0);
		contentSize = getContentSize();
	}

	this->addChild(getMenuButton());
	float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);

	CCArray* array = getMenuButton()->getChildren();
	CCObject* pObj = NULL;
	int i = 0;
	CCARRAY_FOREACH(array, pObj){
		CCNode* node = dynamic_cast<CCNode*>(pObj);
		node->setPosition(ccp( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
		i++;
	}
Ejemplo n.º 2
0
void PopupLayer::refreshBallBackGround(Node *pNode)
{
	int tag2= pNode->getTag();
	
	for(auto it=lotteryVector.begin();it!=lotteryVector.end();it++)
	{
		LotteryCard* node = (LotteryCard*)(*it);
		int tag1= node->getTag();

		if(node->getTag() != pNode->getTag())
		{
			node->setUnSelected();
		}		
	}
		lottery_selected =  tag2;

		Vector<Node*> menuItemVector = getMenuButton()->getChildren();
		for(int i=0;i< getMenuButton()->getChildrenCount();i++)
		{
			if(menuItemVector.at(i)->getTag() != 0)
			{
				menuItemVector.at(i)->setTag(tag2);
				break;
			}
		}


}
Ejemplo n.º 3
0
void PopupLayer::backgroundFinish(){

	Size winSize = CCDirector::getInstance()->getWinSize();
	Point pCenter = Point(winSize.width / 2, winSize.height / 2);

	// 添加按钮,并设置其位置
	this->addChild(getMenuButton());
	float btnWidth = m_dialogContentSize.width / (getMenuButton()->getChildrenCount() + 1);

	Vector<Node*> vector = getMenuButton()->getChildren();
	Ref* pObj = NULL;
	int i = 0;
	for(Node* pObj : vector){
		Node* node = dynamic_cast<Node*>(pObj);
		node->setPosition(Point( winSize.width / 2 - m_dialogContentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - m_dialogContentSize.height / 3));
		i++;
	}

	// 显示对话框标题
	if (getLabelTitle()){
		getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, m_dialogContentSize.height / 2 - 35.0f)));
		this->addChild(getLabelTitle());
	}

	// 显示文本内容
	if (getLabelContentText()){
		CCLabelTTF* ltf = getLabelContentText();
		ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		ltf->setDimensions(CCSizeMake(m_dialogContentSize.width - m_contentPadding * 2, m_dialogContentSize.height - m_contentPaddingTop));
		ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
		this->addChild(ltf);
	}
}
Ejemplo n.º 4
0
void PopupLayer::onEnter(){
    CCLayer::onEnter();
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);
    
    CCSize contentSize;
    // 设定好参数,在运行时加载
    if (getContentSize().equals(CCSizeZero)) {
        getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        this->addChild(getSpriteBackGround(), 0, 0);
        contentSize = getSpriteBackGround()->getTexture()->getContentSize();
    } else {
        extension::Scale9Sprite *background = getSprite9BackGround();
        background->setContentSize(getContentSize());
        background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        this->addChild(background, 0, 0);
        contentSize = getContentSize();
    }
    
    
    // 添加按钮,并设置其位置
    this->addChild(getMenuButton());
    float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
    
	Vector<cocos2d::CCNode*> array = getMenuButton()->getChildren();
    CCObject* pObj = NULL;
    int i = 0;
	while(i<array.size())
    {
        CCNode* node = array.at(i);
        node->setPosition(ccp( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 5));
        i++;
    }
    
    
    // 显示对话框标题
    if (getLabelTitle()){
        getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 - 35.0f)));
        this->addChild(getLabelTitle());
    }
    
    // 显示文本内容
    if (getLabelContentText()){
        CCLabelTTF* ltf = getLabelContentText();
        ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
        ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
        this->addChild(ltf);
    }

    // 弹出效果
    CCAction* popupLayer = CCSequence::create(CCScaleTo::create(0.0, 0.0),
                                              CCScaleTo::create(0.06, 1.05),
                                              CCScaleTo::create(0.08, 0.95),
                                              CCScaleTo::create(0.08, 1.0), NULL);
    this->runAction(popupLayer);

}
Ejemplo n.º 5
0
void DialogLayer::onEnter()
{
	Layer::onEnter();
     
    Size winSize = Director::getInstance()->getWinSize();
    Point pCenter = Point(winSize.width / 2, winSize.height / 2);
     
    Size contentSize;
    // 设定好参数,在运行时加载
    if (getContentSize().equals(Size::ZERO)) {
        getSpriteBackGround()->setPosition(winSize.width / 2, winSize.height / 2);
        this->addChild(getSpriteBackGround(), 0, 0);
        contentSize = getSpriteBackGround()->getTexture()->getContentSize();
    } else {
        Scale9Sprite *background = getSprite9BackGround();
        background->setContentSize(getContentSize());
        background->setPosition(winSize.width / 2, winSize.height / 2);
        this->addChild(background, 0, 0);
        contentSize = getContentSize();
    }
     
     
    // 添加按钮,并设置其位置
    this->addChild(getMenuButton());
    float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
     
    Vector<Node*> vecArray = getMenuButton()->getChildren();
    Ref* pObj = NULL;
    int i = 0;
    for(auto& e : vecArray){
        Node* node = dynamic_cast<Node*>(e);
        node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(i+1),winSize.height/2-contentSize.height/3));
        i++;
    }

	// 显示对话框标题
	if (getLabelTitle()){
		getLabelTitle()->setPosition(pCenter + Vec2(0, contentSize.height / 2 - 30.0f));
		this->addChild(getLabelTitle());
	}

	// 显示文本内容
	if (getLabelContentText()){
		LabelTTF* ltf = getLabelContentText();
		ltf->setPosition(winSize.width / 2, winSize.height / 2 + 20);
		//ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
		ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
		this->addChild(ltf);
	}

	// 弹出效果
	Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
		ScaleTo::create(0.06, 1.05),
		ScaleTo::create(0.08, 0.95),
		ScaleTo::create(0.08, 1.0), NULL);
	this->runAction(popupLayer);
}
Ejemplo n.º 6
0
bool PoptipLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, CCPoint &pos, int tag/* = 0*/)
{
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);

	// 创建图片菜单按钮
	CCMenuItemImage *normal = CCMenuItemImage::create(normalImage, normalImage);
	CCMenuItemImage *checked = CCMenuItemImage::create(selectedImage, selectedImage);
	//创建开关按钮选项,并设置回调函数
	CCMenuItemToggle *toggle = CCMenuItemToggle::createWithTarget(this,
		menu_selector(PoptipLayer::buttonCallback),
		normal,
		checked,
		NULL
		);



	toggle->setTag(tag);
	toggle->setPosition(pCenter);

	toggle->setPosition(pos);
	getMenuButton()->addChild(toggle);
	return true;

}
Ejemplo n.º 7
0
bool PopupLayer::addButton(const char *normalImage, const char *selectedImage, const char *title, int tag){
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);

	CCMenuItemImage* menuImage = CCMenuItemImage::create(normalImage, selectedImage, this, menu_selector(PopupLayer::buttonCallback));
	menuImage->setTag(tag);
	menuImage->setPosition(pCenter);

	CCSize imenu = menuImage->getContentSize();
	CCLabelTTF* ttf = CCLabelTTF::create(title, "", 20);
	ttf->setColor(ccc3(0, 0, 0));
	ttf->setPosition(ccp(imenu.width / 2, imenu.height / 2));
	menuImage->addChild(ttf);

	getMenuButton()->addChild(menuImage);
	return true;
}
Ejemplo n.º 8
0
bool DialogLayer::addButton(const char* title, Sprite* normalImage, Sprite* selectedImage, Sprite* disableImage, const ccMenuCallback& callback, int tag/* =0 */)
{
	Size winSize = Director::getInstance()->getWinSize();
	Point pCenter = Point(winSize.width / 2, winSize.height / 2);

	// 创建图片菜单按钮
	MenuItemSprite* menuImage = MenuItemSprite::create(normalImage, selectedImage, disableImage, callback);
	menuImage->setTag(tag);
	menuImage->setPosition(pCenter);

	// 添加文字说明并设置位置
	Size imenu = menuImage->getContentSize();
	LabelTTF* ttf = CCLabelTTF::create(title, "Arial", 25);
	ttf->setColor(Color3B(0, 0, 0));
	ttf->setPosition(imenu.width / 2, imenu.height / 2);
	menuImage->addChild(ttf);

	getMenuButton()->addChild(menuImage);
	return true;
}
Ejemplo n.º 9
0
bool PopLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, int tag /*= 0*/)
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 pCenter(visibleSize.width / 2, visibleSize.height / 2);
    
    // 创建图片菜单按钮
    MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, CC_CALLBACK_1(PopLayer::buttonCallback, this));
    menuImage->setTag(tag);
    //menuImage->setPosition(pCenter);
    
    // 添加文字说明并设置位置
    if(title != NULL)
    {
        Size imenu = menuImage->getContentSize();
        LabelTTF* ttf = LabelTTF::create(title, "", 20);
        ttf->setColor(Color3B(0, 0, 0));
        ttf->setPosition(Vec2(imenu.width / 2, imenu.height / 2));
        menuImage->addChild(ttf);
    }
    
    
    getMenuButton()->addChild(menuImage);
    return true;
}
Ejemplo n.º 10
0
bool PopupLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, int tag /* = 0 */){
	
	auto size = Director::getInstance()->getWinSize();
	auto center = Point(size.width / 2, size.height / 2);

	// 创建图片菜单按钮
	auto item = MenuItemImage::create(
		normalImage,
		selectedImage,
		CC_CALLBACK_1(PopupLayer::buttonCallBack,this));
	item->setTag(tag);
	item->setPosition(center);

	// 添加文字说明并设置位置
	Size itemSize = item->getContentSize();
	LabelTTF* ttf = LabelTTF::create(title, "", 20);
	ttf->setColor(Color3B(0, 0, 0));
	ttf->setPosition(Point(itemSize.width / 2, itemSize.height / 2));
	item->addChild(ttf);

	getMenuButton()->addChild(item);

	return true;
}
Ejemplo n.º 11
0
void PopLayer::onEnter()
{
    Layer::onEnter();
    
    Size winSize = Director::getInstance()->getVisibleSize();
    Vec2 pCenter(winSize.width / 2, winSize.height / 2);
    
    Size contentSize;
    // 设定好参数,在运行时加载
    if (getContentSize().equals(Size::ZERO)) {
        getSpriteBackGround()->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
        this->addChild(getSpriteBackGround(), 0, 0);
        contentSize = getSpriteBackGround()->getTexture()->getContentSize();
    } else {
        Scale9Sprite *background = getSprite9BackGround();
        background->setContentSize(getContentSize());
        background->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
        this->addChild(background, 0, 0);
        contentSize = getContentSize();
    }
    
    
    // 添加按钮,并设置其位置
    this->addChild(getMenuButton());
    float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
    
    Vector<Node *> array = getMenuButton()->getChildren();
    getMenuButton()->alignItemsHorizontallyWithPadding(50);
    getMenuButton()->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - contentSize.height / 3));
    // 	int i = 0;
    // 	for(auto &bt: array)
    // 	{
    // 		Node* node = dynamic_cast<Node*>(bt);
    // 		node->setPosition(Vec2( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
    // 		i++;
    // 	}
    
    
    // 显示对话框标题
    if (getLabelTitle()){
        getLabelTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 35.0f)));
        this->addChild(getLabelTitle());
    }
    
    if(getImgTitle())
    {
        getImgTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 40.0f)));
        this->addChild(getImgTitle());
    }
    
    // 显示文本内容
    if (getLabelContentText()){
        LabelTTF* ltf = getLabelContentText();
        //ltf->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
        ltf->setPosition(pCenter);
        ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
        ltf->setHorizontalAlignment(TextHAlignment::LEFT);
        this->addChild(ltf);
    }
    
    // 弹出效果
    Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
                                          ScaleTo::create(0.06, 1.05),
                                          ScaleTo::create(0.08, 0.95),
                                          ScaleTo::create(0.08, 1.0), NULL);
    this->runAction(popupLayer);
}
Ejemplo n.º 12
0
void PopupLayer::onEnter(){
    CCLayer::onEnter();
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);
    
    CCSize contentSize;
    // 设定好参数,在运行时加载
    if (getContentSize().equals(CCSizeZero)) {
        getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        this->addChild(getSpriteBackGround(), 0, 0);
        contentSize = getSpriteBackGround()->getTexture()->getContentSize();
    } else {
        Scale9Sprite *background = getSprite9BackGround();
        background->setContentSize(getContentSize());
        background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        this->addChild(background, 0, 0);
        contentSize = getContentSize();
    }
    
    
    // 添加按钮,并设置其位置
    this->addChild(getMenuButton());
    float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
    
//    Array* array = getMenuButton()->getChildren();
	Vector<Node*>& array = getMenuButton()->getChildren();

    Object* pObj = NULL;
    int i = 0;
	/*
	 vector<NODE>::iterator it;
	 
	 for (it=v.begin(); it!=v.end(); it++)
	 {
	 v[*it]->id=2;
	 
	 }
	 */
	Vector<Node*>::iterator it;
	
    for (it=array.begin() ; it!=array.end(); it++) {
        Node* node = dynamic_cast<Node*>(pObj);
        node->setPosition(ccp( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
        i++;
    }
    
    
    // 显示对话框标题
    if (getLabelTitle()){
        getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 - 35.0f)));
        this->addChild(getLabelTitle());
    }
    
    // 显示文本内容
    if (getLabelContentText()){
        CCLabelTTF* ltf = getLabelContentText();
        ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
        ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
        this->addChild(ltf);
    }

    // 弹出效果
    CCAction* popupLayer = CCSequence::create(CCScaleTo::create(0.0, 0.0),
                                              CCScaleTo::create(0.06, 1.05),
                                              CCScaleTo::create(0.08, 0.95),
                                              CCScaleTo::create(0.08, 1.0), NULL);
    this->runAction(popupLayer);

}
Ejemplo n.º 13
0
void PopupLayer::onEnter()
{
    Layer::onEnter();
    
	//Size winSize = Director::getInstance()->getWinSize();
    Point pCenter = ccp(winSize.width / 2, winSize.height / 2);
    
    Size contentSize;
    // 设定好参数,在运行时加载
    if (getContentSize().equals(CCSizeZero)) 
	{
        getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        this->addChild(getSpriteBackGround(), 0, 0);
        contentSize = getSpriteBackGround()->getTexture()->getContentSize();
    } else {
        Scale9Sprite *background = getSprite9BackGround();
        background->setContentSize(getContentSize());
        background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
        this->addChild(background, 0, 0);
        contentSize = getContentSize();
    }
    
    
    // 添加按钮,并设置其位置
    this->addChild(getMenuButton());
    float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
    
	Vector<Node*> vecArray = getMenuButton()->getChildren();

	int j=0;
	for(auto it=vecArray.begin();it!=vecArray.end();it++)
	{
		Node* node = dynamic_cast<Node*>(*it);
		node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(j+1),winSize.height/2-contentSize.height/3));
		j++;
	}

    // 显示对话框标题
    if (getLabelTitle())
	{
        getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 -20)));
		getLabelTitle()->setColor(ccc3(0,0,0));
        this->addChild(getLabelTitle());
    }
    
	switch(pop_type)
	{
	case LOTTERY:
		{
			setLotteryContext(contentSize);
			break;
		}
	case LOTTERY_PUBLISH:
		{
							
			setPublishLotteryContext(contentSize);
			break;
		}
	case LOADGAME:
		{

			setLoadGameContext(contentSize);
			break;
		}
	default:
		{
		     // 显示文本内容
			if (getLabelContentText())
			{
				LabelTTF* ltf = getLabelContentText();
				ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
				ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
				ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
				ltf->setColor(ccc3(0,0,0));
				this->addChild(ltf);
			}
		}
	}




    // 弹出效果
    Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
                                          ScaleTo::create(0.15, 1.05),
                                          ScaleTo::create(0.08, 0.95),
                                          ScaleTo::create(0.08, 1.0),
										  NULL);
    this->runAction(popupLayer);

}