コード例 #1
0
ファイル: RootLayer.cpp プロジェクト: hyizsg/mytest1st
void HTouchEnabledLayerColor::setPriority(CCNode *node, int priority) {
    if (dynamic_cast<CCControl *>(node)) {
        CCControl *control = (CCControl *)node;
        control->setTouchPriority(priority);
        if (control->isTouchEnabled()) {
            control->setTouchEnabled(false);
            control->setTouchEnabled(true);
        }
    } else if (dynamic_cast<CCScrollView *>(node)) {
        CCScrollView *scrollView = (CCScrollView *)node;
        scrollView->setTouchPriority(priority);
        if (scrollView->isTouchEnabled()) {
            scrollView->setTouchEnabled(false);
            scrollView->setTouchEnabled(true);
        }
    } else if (dynamic_cast<CCMenu *>(node)) {
        CCMenu *menu = (CCMenu *)node;
        menu->setTouchPriority(priority);
        if (menu->isTouchEnabled()) {
            menu->setTouchEnabled(false);
            menu->setTouchEnabled(true);
        }
    } else if (dynamic_cast<CCLayer *>(node)) {
        CCLayer *layer = (CCLayer *)node;
        layer->setTouchPriority(priority);
        if (layer->isTouchEnabled()) {
            layer->setTouchEnabled(false);
            layer->setTouchEnabled(true);
        }
    }
}
コード例 #2
0
void GameScene::touchPauseCallBack(CCObject* obj) {
    if (isGameOver) {
        return;
    }
    
    CCDirector::sharedDirector()->pause();
    
    NoTouchLayer* n = NoTouchLayer::create();
    addChild(n, 10, TAG_NO_LAYER);
    
    CCSprite* mask = CCSprite::createWithSpriteFrameName("mask.png");
    mask->setPosition(ccp(screenSize.width * 0.5f, screenSize.height * 0.5f));
    mask->setScaleX(screenSize.width / mask->getContentSize().width * 1.5f);
    mask->setScaleY(screenSize.height / mask->getContentSize().height * 1.5f);
    addChild(mask, 10, TAG_MASK);
    
    CCSprite* pause = CCSprite::createWithSpriteFrameName("pause.png");
    pause->setPosition(ccp(screenSize.width * 0.5f, screenSize.height * 0.68f));
    pause->setScale(1.5f);
    addChild(pause, 10, TAG_TITLE);
    
    CCMenuItemSprite* item = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("resume.png"), NULL, this, menu_selector(GameScene::pauseResume));
    item->setPosition(ccp(screenSize.width * 0.5f, screenSize.height * 0.3f));
    CCMenu* menu = CCMenu::create(item, NULL);
    menu->setPosition(CCPointZero);
    menu->setTouchPriority(-200000);
    addChild(menu, 10, TAG_RESUME);
}
コード例 #3
0
bool BaseModalLayer::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    this->setTouchPriority(kModalLayerPriority);
    this->setTouchEnabled(true);
    this->setTouchMode(kCCTouchesOneByOne);
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    
    CCSprite* frame = CCSprite::create("frame.png");
    frame->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
    this->addChild(frame);
    
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                                          "tg_close_1.png",
                                                          "tg_close_2.png",
                                                          this,
                                                          menu_selector(BaseModalLayer::menuCloseCallback) );
    pCloseItem->setPosition(ccp(
                                visibleSize.width/2+frame->getContentSize().width/2-pCloseItem->getContentSize().width/2-10,
                                visibleSize.height/2+frame->getContentSize().height/2-pCloseItem->getContentSize().height/2-10));
    
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setTouchPriority(kModalLayerMenuPriority);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu);
    
    return true;
}
コード例 #4
0
void GameClearPopup::makeLabels()
{
    //背景
    CCSprite* frame = CCSprite::createWithSpriteFrameName(PNG_POPUP_BG2);
    frame->setScale(2.5f);
    frame->setPosition(GHelper::convI720toCC(g_visibleSize.width / 2, g_visibleSize.height / 2));
    this->addChild(frame);

    //タイトル
    CCString *s = NULL;
    if (UserSettings::getSelectedLevel() >= 15) {
    	s = CCString::create("All Clear!");
	} else {
		s = CCString::create("You Win!");
	}
    CCLabelBMFont* title = CCLabelBMFont::create(s->getCString(), FONT_YELLOW);
    title->setScale(0.6);
    title->setPosition( GHelper::convI720toCC(g_visibleSize.width * 0.5, g_visibleSize.height * 0.3));
    this->addChild(title);

    //女の子
    CCSprite *obj = CCSprite::createWithSpriteFrameName(PNG_MINI2_1);
    obj->setPosition(GHelper::convI720toCC(g_visibleSize.width * 0.5, g_visibleSize.height * 0.35));
    obj->runAction(Animations::winMiniAnimation());
    this->addChild(obj);

    //Next Stage?
    if (UserSettings::getSelectedLevel() >= 15) {
    	s = CCString::create("");
	} else {
		s = CCString::create("Next Stage?");
	}
    CCLabelBMFont* disc1 = CCLabelBMFont::create(s->getCString(), FONT_GREEN);
    disc1->setScale(0.5);
    CCMenuItemLabel* item1 = CCMenuItemLabel::create(disc1, this, menu_selector(GameClearPopup::onTapNextStage));

    //Again?
    CCLabelBMFont* disc2 = CCLabelBMFont::create("Again?", FONT_WHITE);
    disc2->setScale(0.5);
    CCMenuItemLabel* item2 = CCMenuItemLabel::create(disc2, this, menu_selector(GameClearPopup::onTapAgain));

    //Menu
    CCLabelBMFont* disc3 = CCLabelBMFont::create("Menu", FONT_WHITE);
    disc3->setScale(0.5);
    CCMenuItemLabel* item3 = CCMenuItemLabel::create(disc3, this, menu_selector(GameClearPopup::onTapMenu));

    //Quit
    CCLabelBMFont* disc4 = CCLabelBMFont::create("Quit", FONT_WHITE);
    disc4->setScale(0.5);
    CCMenuItemLabel* item4 = CCMenuItemLabel::create(disc4, this, menu_selector(GameClearPopup::onTapQuit));

    CCMenu* menu = CCMenu::create( item1, item2, item3, item4, NULL );
    menu->setTouchPriority(-128);
    menu->alignItemsVerticallyWithPadding(1.0);
    menu->setPosition(ccp(g_visibleSize.width / 1.5, g_visibleSize.height / 2 - 50));
    this->addChild(menu);
}
コード例 #5
0
ファイル: MainMenu.cpp プロジェクト: DanicaMeng/RabbitRun
bool MainMenu::init()
{
	if ( !CCLayerColor::initWithColor(ccc4(0, 0, 0, 200)) )
    {
        return false;
    }

	CCLabelTTF *title = CCLabelTTF::create("Rabbit Run", FONT_NAME, 70);
	title->setPosition(ccp(SCREEN_CX, SCREEN_HEIGHT - 80));
	this->addChild(title);

	CCMenuItemFont::setFontName(FONT_NAME);
	CCMenuItemFont::setFontSize(50);

	char* text[] = {"Score", "Power", "Effect",
				   "+10", "+20%", "--",
	               "+20", "+40%", "grow up",
				   "+10", "+0", "lose weight",
	               "+0", "+0","hiding"};
	for(int i = 0; i < 15; i++)
	{
		CCLabelTTF *label = CCLabelTTF::create(text[i], FONT_NAME, 50);
		label->setPosition(ccp(400 + i%3*300, 550 - i/3*85));
		this->addChild(label);
	}
	char* img[] = {"cabbage.png", "carrot.png", "carrot_ice.png", "carrot_sterlth.png"};
	for(int i = 0; i < 4; i++)
	{
		CCSprite *sprite = CCSprite::create(img[i]);
		sprite->setScale(0.2f);
		sprite->setPosition(ccp(250, 450 - i*80));
		this->addChild(sprite);
	}
	CCMenuItemFont *startGame = CCMenuItemFont::create("Play", this, menu_selector(MainMenu::startGame));
	startGame->setColor(ccc3(0, 255,51));
	startGame->setPositionX(-90);

	CCMenuItemFont *exitGame = CCMenuItemFont::create("Exit", this, menu_selector(MainMenu::exitGame));
	exitGame->setColor(ccc3(255, 0, 0));
	exitGame->setPositionX(110);

	CCMenu *menu = CCMenu::create(startGame, exitGame, NULL);
	menu->setPositionY(120);
	menu->setTouchPriority(-201);
	this->addChild(menu);

	CCLabelTTF *powerBy = CCLabelTTF::create("Power by cocos2d-x", FONT_NAME, 50);
	powerBy->setAnchorPoint(ccp(1, 0));
	powerBy->setPosition(ccp(SCREEN_WIDTH, 0));
	this->addChild(powerBy);

	this->setTouchPriority(-200);
	this->setTouchMode(kCCTouchesOneByOne);
	this->setTouchEnabled(true);

	return true;
}
コード例 #6
0
ファイル: RootLayer.cpp プロジェクト: hyizsg/mytest1st
CCObject *HTouchEnabledLayerColor::updatePriorityEx(int command, CCNode *node) {
    int iBasePriority = getTouchPriority();
    
    if (dynamic_cast<CCControl *>(node)) {
        CCControl *control = (CCControl *)node;
        int priority = control->getTouchPriority();
        priority = iBasePriority - 9;
        control->setTouchPriority(priority);
        if (control->isTouchEnabled()) {
            control->setTouchEnabled(false);
            control->setTouchEnabled(true);
        }
    } else if (dynamic_cast<CCScrollView *>(node)) {
        CCScrollView *scrollView = (CCScrollView *)node;
        int priority = scrollView->getTouchPriority();
        priority = iBasePriority - 11;
        scrollView->setTouchPriority(priority);
        if (scrollView->isTouchEnabled()) {
            scrollView->setTouchEnabled(false);
            scrollView->setTouchEnabled(true);
        }
    } else if (dynamic_cast<CCMenu *>(node)) {
        CCMenu *menu = (CCMenu *)node;
        int priority = menu->getTouchPriority();
        priority = iBasePriority - 128;
        menu->setTouchPriority(priority);
        if (menu->isTouchEnabled()) {
            menu->setTouchEnabled(false);
            menu->setTouchEnabled(true);
        }
    } else if (dynamic_cast<CCLayer *>(node)) {
        CCLayer *layer = (CCLayer *)node;
        int priority = layer->getTouchPriority();
        priority = iBasePriority;
        layer->setTouchPriority(priority);
        if (layer->isTouchEnabled()) {
            layer->setTouchEnabled(false);
            layer->setTouchEnabled(true);
        }
    }

    CCArray *children = node->getChildren();
    if (children) {
        int count = children->count();
        for (int i = 0; i < count; ++i) {
            CCNode *child = (CCNode *)children->objectAtIndex(i);
            updatePriorityEx(command, child);
        }
    }
    
    return NULL;
}
コード例 #7
0
ファイル: Popup.cpp プロジェクト: ricolynx/Reflex
void Popup::initPopup(float w,
             float h,
             std::vector<std::string>  buttonsImages,
             std::vector<std::shared_ptr<Delegate>> callbacks,
             const std::string message,
             const int textSize,
             const std::string images
                      )
{
    if (buttonsImages.size() != callbacks.size())
    {
        std::cout << "Error for popup initialisation : number of buttons not equal to number of callbacks" << std::endl;
        return;
    }
    
    this->onquitCallback = 0;
    
    this->nbButtons = buttonsImages.size();
    
    this->width = w;
    
    this->height = h;
    
    this->createBackGround();

    //->create the buttons
    
    CCMenu* pMenu ;
    for (int i = 0; i< buttonsImages.size() ; i++)
    {
        if (i==0)
            pMenu= CCMenu::create( this->createButton( buttonsImages[i], callbacks [i], i) , NULL);
        else
            pMenu->addChild(this->createButton( buttonsImages[i], callbacks [i], i));
        
    }
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu);
    pMenu->setTouchPriority(-201);
    
    //-> add the text
    CCLabelTTF* pLabel = CCLabelTTF::create(message.c_str(), "Arial", textSize);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(0,this->height/4));
    
    // add the label as a child to this layer
    this->addChild(pLabel, 1);

}
コード例 #8
0
void GamePan::showHideConfirmPad(bool isShow)
{
	CCLayerColor* pBaseNode = dynamic_cast<CCLayerColor*>(m_pCcbNode->getChildByTag(kTagGamePanConfirmPad));
	pBaseNode->setVisible(isShow);
	CCLabelTTF* pText = dynamic_cast<CCLabelTTF*>(pBaseNode->getChildByTag(1));
	pText->setVisible(!_isPlayer);
	CCMenu* pMenu = dynamic_cast<CCMenu*>(pBaseNode->getChildByTag(0));
	pMenu->setVisible(isShow && _isPlayer);
	pMenu->setTouchPriority(-1000);
	if(pMenu)
	{
		CCMenuItemImage* btn = dynamic_cast<CCMenuItemImage*>(pMenu->getChildByTag(kTagGamePanConfirmPadOkBtn));
		btn->setTarget(this,menu_selector(GamePan::ConfirmBtnCallback));
		btn = dynamic_cast<CCMenuItemImage*>(pMenu->getChildByTag(kTagGamePanConfirmPadCancelBtn));
		btn->setTarget(this,menu_selector(GamePan::ConfirmBtnCallback));
	}
}
コード例 #9
0
bool ConsoleCocos2dxLayer::init()
{
	if (CCLayer::init())
	{
		// first we create console view
		m_consoleView = ConsoleViewCocos2dx::create();
		if (!m_consoleView) return false;
		m_consoleView->retain();

		// then create console controller
		m_consoleController = new ConsoleControllerBase();
		if (!m_consoleController->Init())
		{
			CC_SAFE_DELETE(m_consoleController);
			return false;
		}

		// bind view to controller
		m_consoleController->SetView(m_consoleView);

		// then we create console menu
		CCSize visualSize = CCDirector::sharedDirector()->getVisibleSize();

		CCMenuItemImage* consoleButton = CCMenuItemImage::create("Console/Terminal.png", "Console/Terminal.png", this, menu_selector(ConsoleCocos2dxLayer::onConsoleButtonClick));
		if (!consoleButton) return false;
		consoleButton->setScale(0.45f);
		consoleButton->setOpacity(128);
		consoleButton->setPosition(ccp(visualSize.width * 0.05f, visualSize.height * 0.88f));

		CCMenu* consoleMenu = CCMenu::create(consoleButton, NULL);
		consoleMenu->setPosition(ccp(0, 0));
		consoleMenu->setTouchPriority(kCCMenuHandlerPriority - 2); // NOTE: pay attention to this
		addChild(consoleMenu, 1); // NOTE: should at top

		// at last, we init cvars and ccmds
		// and that's it :)
		return initCVarAndCCmd();
	}
	
	return false;
}
コード例 #10
0
void GUIBase::resetPriority(CCNode* pNode, int priority)
{
	CCArray* pChildren = pNode->getChildren();

	CCObject* pObj = NULL;
	CCARRAY_FOREACH(pChildren, pObj)
	{
		CCNode* pChild = (CCNode*)pObj;
		if (pChild->getChildrenCount() > 0)
		{
			resetPriority(pChild, priority);
		}

		// CCMenu
		CCMenu* pMenu = dynamic_cast<CCMenu*>(pChild);
		if (pMenu)
		{
			pMenu->setTouchPriority(priority  - 1);
			continue;
		}

		// CCScrollView
		CCScrollView* pCCScrollView = dynamic_cast<CCScrollView*>(pChild);
		if (pCCScrollView)
		{
			pCCScrollView->setTouchPriority(priority  - 1);
			continue;
		}

		// CCControlButton
		CCControlButton* pCCControlButton = dynamic_cast<CCControlButton*>(pChild);
		if (pCCControlButton)
		{
			pCCControlButton->setTouchPriority(priority  - 1);
			continue;
		}
	}
コード例 #11
0
ファイル: LayerSetup.cpp プロジェクト: dalechngame/mygame
bool LayerSetup::init()
{
    CCLayer::init();
    CCSprite *bg = CCSprite::create("Set_Music.png");
    bg->setPosition(ccp(winSize.width / 2, winSize.height / 2));
    addChild(bg);
    bg->setScale(0.75f);

    setTouchMode(kCCTouchesOneByOne);
    setTouchEnabled(true);
    setTouchPriority(kCCMenuHandlerPriority << 1);

    CCMenu *menu = CCMenu::create();
    CCSprite *sp1 = CCSprite::create("music_on.png");
    CCSprite *sp2 = CCSprite::create("music_off.png");
    CCSprite *sp3 = CCSprite::create("sound_effect_on.png");
    CCSprite *sp4 = CCSprite::create("sound_effect_off.png");
    sp1->setScale(0.9f);
    sp2->setScale(0.9f);
    sp3->setScale(0.9f);
    sp4->setScale(0.9f);
    CCMenuItemSprite *_bgON = CCMenuItemSprite::create(sp1, sp1);
    CCMenuItemSprite *_bgOFF = CCMenuItemSprite::create(sp2, sp2);
    CCMenuItemSprite *_effectON = CCMenuItemSprite::create(sp3, sp3);
    CCMenuItemSprite *_effectOFF = CCMenuItemSprite::create(sp4, sp4);
    bool isBg = CCUserDefault::sharedUserDefault()->getBoolForKey("BGStatus", true);
    bool isEff = CCUserDefault::sharedUserDefault()->getBoolForKey("EffectStatus", true);
    isBg ? _bg = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setBG), _bgON, _bgOFF, NULL) :
                 _bg = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setBG), _bgOFF, _bgON, NULL);
    isEff ? _effect = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setEffect), _effectON, _effectOFF, NULL) :
                      _effect = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setEffect), _effectOFF, _effectON, NULL);

    CCScale9Sprite *bgButton = CCScale9Sprite::create("button.png");
    CCScale9Sprite *bgButtonLighted = CCScale9Sprite::create("buttonHighlighted.png");
    CCScale9Sprite *bgButton2 = CCScale9Sprite::create("button.png");
    CCScale9Sprite *bgButtonLighted2 = CCScale9Sprite::create("buttonHighlighted.png");
    CCLabelTTF * text1 = CCLabelTTF::create("back", "verdana", 20);
    CCLabelTTF * text2 = CCLabelTTF::create("home", "verdana", 20);
    _back = CCControlButton::create(text1, bgButton);
    _home = CCControlButton::create(text2, bgButton2);

    _back->setBackgroundSpriteForState(bgButtonLighted, CCControlStateHighlighted);
    _back->addTargetWithActionForControlEvents(this,
            cccontrol_selector(LayerSetup::backGame),
            CCControlEventTouchDown);

    _home->setBackgroundSpriteForState(bgButtonLighted2, CCControlStateHighlighted);
    _home->addTargetWithActionForControlEvents(this,
            cccontrol_selector(LayerSetup::backHome),
            CCControlEventTouchDown);


    _bg->setPosition(ccp(60, -20));
    _effect->setPosition(ccp(60, 40));
    _home->setPosition(ccp(winSize.width / 2 - 70, winSize.height / 2 - 70));
    _back->setPosition(ccp(winSize.width / 2 + 70, winSize.height / 2 - 70));

    menu->setTouchPriority(kCCMenuHandlerPriority << 2);
    _home->setTouchPriority(kCCMenuHandlerPriority << 2);
    _back->setTouchPriority(kCCMenuHandlerPriority << 2);


    menu->addChild(_bg);
    menu->addChild(_effect);
    addChild(menu);
    addChild(_home);
    addChild(_back);


    return true;
}
コード例 #12
0
//创建一个对应的简单的button,代表具体的章
CCLayerColor *SGSpecialBattleLayer::createChapButton(int buttonTag, SpecialBattleData *data)
{
    
    CCLayerColor *layerColor = CCLayerColor::create(ccc4(0, 255, 0, 0), 160, 160);
    layerColor->setTag(111);
    layerColor->setAnchorPoint(ccp(0.5, 0.5));
    
    if (data)
    {
    
        CCSprite *headIcon = SGDrawCards::createPureSprite(data->itemId, data->itemType, sg_specialBattleLayer);
        CCSprite *borderIcon = CCSprite::createWithSpriteFrameName("equipPinzhi_5_0.png");
        
        headIcon->addChild(borderIcon, 1);
        borderIcon->setPosition(ccpAdd(ccp(headIcon->getContentSize().width / 2, headIcon->getContentSize().height / 2), ccp(0, 0)));
        
        CCSprite *headIcon1 = SGDrawCards::createPureSprite(data->itemId, data->itemType, sg_specialBattleLayer);
        CCSprite *borderIcon1 = CCSprite::createWithSpriteFrameName("equipPinzhi_5_0.png");
        
        headIcon1->addChild(borderIcon1, 1);
        borderIcon1->setPosition(ccpAdd(ccp(headIcon1->getContentSize().width / 2, headIcon1->getContentSize().height / 2), ccp(0, 0)));
        
        
        //章节的按钮
        SGButton *chapButton = SGButton::createFromSprite(headIcon, headIcon1, this, menu_selector(SGSpecialBattleLayer::enterSpBattleSection));
        chapButton->setTag(buttonTag);
        
        //章节的名称 //250	197	68
        SGCCLabelTTF *chapNameTTF = SGCCLabelTTF::create(data->chapName.c_str(), FONT_PANGWA, 24);
        chapButton->addChild(chapNameTTF, 2);
        chapNameTTF->setInsideColor(ccc3(250, 197, 68));
        chapNameTTF->setPosition(ccpAdd(ccp(chapNameTTF->getContentSize().width / 2, chapNameTTF->getContentSize().height / 3.5), ccp(0, 0)));
        
        //如果没有开启,蒙灰
        if (!data->isOpen)
        {
            CCSprite *greyMask = CCSprite::createWithSpriteFrameName("sp_battle_entry_mask.png");
            greyMask->setOpacity(150);
            chapButton->addChild(greyMask, 10);
            greyMask->setPosition(ccpAdd(ccp(greyMask->getContentSize().width / 2 - 5, greyMask->getContentSize().height / 2 - 5), ccp(0, 0)));
            //未开启,不可用
            chapButton->setEnabled(false);
        }
        
        CCMenu *menu = CCMenu::create();
        menu->setTouchPriority(10);
        menu->setPosition(CCPointZero);
        menu->addChild(chapButton);
        
        layerColor->addChild(menu);
        chapButton->setPosition(ccpAdd(ccp(0, 0), ccp(layerColor->getContentSize().width / 2, layerColor->getContentSize().height / 1.5)));
        
        
        //显示描述的背景
        CCSprite *descBg = CCSprite::createWithSpriteFrameName("sp_battle_infobg.png");
        layerColor->addChild(descBg, 1);
        descBg->setPosition(ccpAdd(chapButton->getPosition(), ccp(0, -descBg->getContentSize().height / 2 - chapButton->getContentSize().height / 1.7)));
        
        //下方对应的描述
        
        std::string desc;
        if (data->isOpen)
        {
            desc = data->chapOpenDesc;
            //如果是开启的,加上光效
            ResourceManager::sharedInstance()->bindTexture("animationFile/ms_niubility.plist", RES_TYPE_LAYER_UI, sg_specialBattleLayer);
            CCSpriterX *newRewardEffect = CCSpriterX::create("animationFile/ms_niubility.scml", true, true);
            layerColor->addChild(newRewardEffect, -1);
            newRewardEffect->setanimaID(0);
            newRewardEffect->setisloop(true);
            newRewardEffect->setScale(1.15);
            newRewardEffect->setPosition(ccpAdd(chapButton->getPosition(), ccp(0, 0)));
            newRewardEffect->play();
        }
        else
        {
            desc = data->chapClosedDesc;
        }
        
        SGCCLabelTTF *chapDescTTF = SGCCLabelTTF::create(desc.c_str(), FONT_PANGWA, 21);
        descBg->addChild(chapDescTTF, 1);
        chapDescTTF->setPosition(ccpAdd(ccp(descBg->getContentSize().width / 2, descBg->getContentSize().height / 2), ccp(0, 0)));
        
        //如果开启状态,显示剩余次数
        if (data->isOpen)
        {
            SGCCLabelTTF *residueTimeTTF = SGCCLabelTTF::create(CCString::createWithFormat(str_SpecailBattleResidueCoint, data->freePlayTimes)->getCString(), FONT_PANGWA, 20);
            residueTimeTTF->setInsideColor(ccGREEN);
            layerColor->addChild(residueTimeTTF, 1);
            residueTimeTTF->setPosition(ccpAdd(descBg->getPosition(), ccp(0, -residueTimeTTF->getContentSize().height * 1.2)));
        }
    }
    else
    {
        //没有的,直接问号显示
        SGButton *chapButton = SGButton::create("sp_battle_unlock.png", "equipPinzhi_5_0.png", this, NULL);
        chapButton->setEnabled(false);
        layerColor->addChild(chapButton);
        chapButton->setPosition(ccpAdd(ccp(0, 0), ccp(layerColor->getContentSize().width / 2, layerColor->getContentSize().height / 1.5)));
    }
    
    return layerColor;
}
コード例 #13
0
void LayerLogin::zhenping(){
    
    
    pSpriteDialogLogin = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_input.png"));//CCSprite::create("login_bg_en.png");
    pSpriteDialogLogin->setPosition(ccp(winSize.width*0.5,winSize.height *0.5-100));
    this->addChild(pSpriteDialogLogin);
    
    
      
    
    
    CCMenuItemImage* btn_login = CCMenuItemImage::create();
    btn_login->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_login_1.png"));
    btn_login->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_login_2.png"));
    btn_login->setTarget(this, SEL_MenuHandler(&LayerLogin::menuItemCallbackLogin));
    
    CCMenu *pMenu = CCMenu::create();
    pMenu->alignItemsHorizontally();
    pMenu->addChild(btn_login);
    //pMenu->setPosition(pSpriteDialogLogin->getContentSize().width-75,pSpriteDialogLogin->getContentSize().height/2-10);
    pMenu->setPosition(ccp(winSize.width/2-30, winSize.height/2-460));
    pMenu->setTouchPriority(1);
    pSpriteDialogLogin->addChild(pMenu);
    
    
    CCScale9Sprite* editbkg = CCScale9Sprite::create();
    
    editBoxUsername = CCEditBox::create(CCSizeMake(210,50),editbkg);
    editBoxUsername->setReturnType(kKeyboardReturnTypeDone);
    //editBoxUsername->setFontSize(12);
    editBoxUsername->setText("");
    editBoxUsername->setFontColor(ccc3(158, 122, 83));
    editBoxUsername->setMaxLength(8);
    editBoxUsername->setPosition(ccp(winSize.width/2-10,96));//160,100
    pSpriteDialogLogin->addChild(editBoxUsername,2);
    
    CCScale9Sprite* editbkg1 = CCScale9Sprite::create();
    editBoxPassword = CCEditBox::create(CCSizeMake(185, 50),editbkg1);
    editBoxPassword->setReturnType(kKeyboardReturnTypeDone);
    editBoxPassword->setInputFlag(kEditBoxInputFlagPassword);
    editBoxPassword->setFontColor(ccc3(158, 122, 83));
    editBoxPassword->setMaxLength(8);
  //  editBoxPassword->setFontSize(12);
    editBoxPassword->setText("");
    editBoxPassword->setPosition(ccp(winSize.width/2-17,45));//160,60
    
    pSpriteDialogLogin->addChild(editBoxPassword,2);
    
//    CCSprite* bs = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_bs.png"));
//    bs->setPosition(ccp(pSpriteDialogLogin->getContentSize().width, 0));
//    pSpriteDialogLogin->addChild(bs);
//    logo->setAtlasIndex(0);
//    CCScene * f = CCDirector::sharedDirector()->getRunningScene();
//    CCPoint size =ccp(308, 756);
//    CCActionInterval * left1 = CCMoveTo::create(0.05,ccp(size.x+5,size.y));
//    CCActionInterval * right1 = CCMoveTo::create(0.05,ccp(size.x-5,size.y));
//    CCActionInterval * top1 = CCMoveTo::create(0.05,ccp(size.x,size.y+5));
//    CCActionInterval * rom1 = CCMoveTo::create(0.05,ccp(size.x,size.y-5));
//    CCFiniteTimeAction* action3 = CCSequence::create(left1,right1,top1,rom1,NULL);
//    f->getChildByTag(2807)->getChildByTag(9021)->runAction(CCRepeat::create(action3, 1));
}
コード例 #14
0
ファイル: HelpLayer.cpp プロジェクト: xuqin/tgp
void HelpLayer::initUI()
{
	CCSize size = ToolsFun::sharedTools()->getSceneSize();

	//背景
	CCSprite * bkg = CCSprite::create("ui/shared/bkg.png");
	this->addChild(bkg, -4);
	bkg->setPosition(size / 2);

	//头部
	CCSprite *spBkgTop = CCSprite::create("ui/shared/top.png");
	this->addChild(spBkgTop, 0);
	spBkgTop->setPosition(ccp(size.width / 2, size.height - spBkgTop->getContentSize().height / 2));

	//金币放置最上方商城
	CCSprite *coinIcon = CCSprite::create("ui/shared/coin.png");
	this->addChild(coinIcon, 2, 1429);
	coinIcon->setPosition(ccp(280*gScaleX, size.height - 30*gScaleY));
	m_coinLabel = CCLabelBMFont::create("10000000", GOLD_FONT);
	this->addChild(m_coinLabel, 4);
	m_coinLabel->setAnchorPoint(ccp(0, 0.5f));
	m_coinLabel->setPosition(ccp(300*gScaleX, size.height - 25*gScaleY));
	m_coinLabel->setScale(0.6F);

	setCoin();

	CCMenu *menu = CCMenu::create();
	this->addChild(menu, 10);
	menu->setTouchPriority(-130);
	menu->setPosition(CCPointZero);
	CCSprite *spNml = CCSprite::create("ui/shared/back.png");
	CCSprite *spSel = CCSprite::create("ui/shared/back.png");
	spSel->setColor(ccc3(100, 100, 100));
	CCMenuItemSprite *spItem = CCMenuItemSprite::create(spNml, spSel, this, menu_selector(HelpLayer::back));
	menu->addChild(spItem);
	spItem->setPosition(ccp(37*gScaleX, size.height - 37*gScaleY));
	//show shop
	spNml = CCSprite::create("ui/shared/coinplus.png");
	spSel = CCSprite::create("ui/shared/coinplus.png");
	spSel->setColor(ccc3(100, 100, 100));
	spItem = CCMenuItemSprite::create(spNml, spSel, this, menu_selector(HelpLayer::showShopLayer));
	menu->addChild(spItem);
	spItem->setPosition(ccp(430*gScaleX, size.height - 30*gScaleY));

	//初始化宠物界面
	m_menu = CCMenu::create();
	m_uiNode->addChild(m_menu, 2);
	m_uiNode->setPosition(CCPointZero);
	m_menu->setPosition(CCPointZero);
	SK::StringKey nameKey[5] = {K.ITEM_NAME0, K.ITEM_NAME1, K.ITEM_NAME2, K.ITEM_NAME3, K.ITEM_NAME4};
	SK::StringKey desKey[5] = {K.ITEM_DES0, K.ITEM_DES1, K.ITEM_DES2, K.ITEM_DES3, K.ITEM_DES4};

	const char *fileName[5] = {"item/item2_0.png","item/item0_0.png","item/item1_0.png",
		"item/item3_0.png","item4_3.png"};

	for(int i = 0; i != 5; ++i)
	{
		CCSprite *petSprite = NULL;

		if(i ==4)
		{
			petSprite = CCSprite::createWithSpriteFrameName(fileName[i]);
		}
		else
		{
			petSprite  = CCSprite::create(fileName[i]);
		}
		m_uiNode->addChild(petSprite, 1);
		petSprite->setPosition(ccp(120*gScaleX, 130*gScaleY)+ccp(0,180*i));

		CCSprite* petDes = CCSprite::create("ui/petUI/pet_describe.png");
		m_uiNode->addChild(petDes, 1);
		petDes->setPosition(ccp(330*gScaleX, 140*gScaleY)+ccp(0,180*i));

		m_desFont[i] = CCLabelBMFont::create(gGetLanguageDesc(desKey[i]).c_str(), "font/item_des.fnt");
		m_uiNode->addChild(m_desFont[i], 10);
		m_desFont[i]->setPosition(ccp(240*gScaleX, 130*gScaleY)+ccp(0,180*i));
		m_desFont[i]->setAnchorPoint(CCPointZero);

		m_nameFont[i] = CCLabelBMFont::create(gGetLanguageDesc(nameKey[i]).c_str(), "font/item_des.fnt");
		m_uiNode->addChild(m_nameFont[i], 10);
		m_nameFont[i]->setPosition(ccp(240*gScaleX, 160*gScaleY)+ccp(0,180*i));
		m_nameFont[i]->setAnchorPoint(CCPointZero);
	
		CCLabelBMFont *nameLabel = m_nameFont[i];
		nameLabel->setScale(0.6f);
		nameLabel->setString(gGetLanguageDesc(nameKey[i]).c_str());

		CCLabelBMFont *desLabel = m_desFont[i];
		desLabel->setScale(0.6f);
		desLabel->setString(gGetLanguageDesc(desKey[i]).c_str()); 
	}
}
コード例 #15
0
bool VVAlertView::initWithTitle(const char* aTitle, const char* aMessage, VVAlertViewDelegate* aDelegate, const char* aCancelBtnTitle, const char* aOtherBtnTitle)
{
    if ( !VVPopupLayer::init() )
		return false;
    
    delegate = aDelegate;
    
    overlayLayer->removeFromParentAndCleanup(true);
    
    CCLabelTTF *titleLabel = NULL;
    
    if( aTitle != NULL )
    {
        titleLabel = CCLabelTTF ::labelWithString(aTitle ,fontName.c_str(), titleFontSize);
    }
    
    CCScale9Sprite *bg = CCScale9Sprite::scale9SpriteWithFile(alertBG_name.c_str(), alert9patch_rect);
    
    
    CCLabelTTF *msgLabel = CCLabelTTF::labelWithString(aMessage, CCSizeMake(maxWidth-borderPadding*4, 0), CCTextAlignmentCenter, fontName.c_str(), messageFontSize);
    
    
    CCMenuItemSprite* btnCancel = CCMenuItemDynamic::dynamicItemWithTTFLabel(aCancelBtnTitle, fontName.c_str(), messageFontSize, btnSize, btnBG_name.c_str(), NULL, this,
                                                                             menu_selector(VVAlertView::onBtnCancel), 
                                                                             btn9patch_rect, 255);
    CCMenu *menu;
    if (aOtherBtnTitle == NULL) 
    {
        menu = CCMenu::menuWithItems(btnCancel, NULL);
    }
    else
    {
        CCMenuItemSprite* btnOk = CCMenuItemDynamic::dynamicItemWithTTFLabel(aOtherBtnTitle, fontName.c_str(), messageFontSize, btnSize, btnBG_name.c_str(), NULL, this,
                                                                                 menu_selector(VVAlertView::onBtnOk), 
                                                                                 btn9patch_rect, 255);

        menu = CCMenu::menuWithItems(btnCancel, btnOk, NULL);
        menu->alignItemsHorizontallyWithPadding(betweenBtnPadding);
    }
     
    
    menu->setTouchPriority(VVTouchPriorityMenuOnPopupLayer);
    
    addChild(bg);
    if (titleLabel) 
        addChild(titleLabel);            

    addChild(msgLabel);    
    addChild(menu);
    
    
    if (titleLabel)     
        totalHeight += titleLabel->getContentSize().height;    
    
    totalHeight += msgLabel->getContentSize().height;    
    totalHeight += btnCancel->getContentSize().height;
    totalHeight += centerPadding;
    
    totalHeight += messagePadding*2;
    totalHeight += borderPadding*2;
    
    float halfHeight = totalHeight/2;
    
    if (titleLabel) 
    {
        titleLabel  ->setPosition(ccp(0, halfHeight - borderPadding - titleLabel->getContentSize().height/2)); // -15 : top padding
        msgLabel    ->setPosition(ccp(0, halfHeight - borderPadding - titleLabel->getContentSize().height - messagePadding - msgLabel->getContentSize().height/2 ));
    }
    else
    {
        msgLabel    ->setPosition(ccp(0, halfHeight - borderPadding - msgLabel->getContentSize().height/2 ));
    }
    menu        ->setPosition(ccp(0, -halfHeight + borderPadding + btnCancel->getContentSize().height/2));
    
    bg->setContentSize(CCSizeMake(maxWidth, totalHeight));
    
    
    // will be used for placing text field in the middle
    centerOfMargin = (msgLabel->getPosition().y + menu->getPosition().y)/2;
    
    return true;
}
コード例 #16
0
void ChallengeAgainLayer::onShow(int round, int need)
{
	float totalWidth = 0.0;
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCSprite *app1 = CCSprite::create(g_sRelifeBGImage);
	app1->setAnchorPoint(ccp(0,0));
	app1->setPositionX(30);
	app1->setPositionY(s.height*0.5);
	this->addChild(app1);
	totalWidth += app1->getContentSize().width;

	NumberSprite * roundTip = NumberSprite::create("green60",round);
	roundTip->setAnchorPoint(ccp(0,0));
	roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4);
	roundTip->setPositionY(app1->getPositionY());
	this->addChild(roundTip);
	totalWidth += 4;
	totalWidth += roundTip->realWidth;

	CCSprite *app2 = CCSprite::create(g_sGuanBGImage);
	app2->setAnchorPoint(ccp(0,0));
	app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4);
	app2->setPositionY(roundTip->getPositionY());
	this->addChild(app2);
	totalWidth += 4;
	totalWidth += app2->getContentSize().width;

	float bx = (s.width - totalWidth)*0.5;
	app1->setPositionX(bx);
	roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4);
	app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4);

	CCSprite *app3 = CCSprite::create(g_sLifeNeedBGImage);
	app3->setAnchorPoint(ccp(0,0));
	app3->setPositionX(app1->getPositionX());
	app3->setPositionY(app2->getPositionY()-app2->getContentSize().height-20);
	this->addChild(app3);

	NumberSprite * needTip = NumberSprite::create("green60",need);
	needTip->setAnchorPoint(ccp(0,0));
	needTip->setPositionX(app3->getPositionX()+app3->getContentSize().width+4);
	needTip->setPositionY(app3->getPositionY());
	this->addChild(needTip);

	CCSprite *app4 = CCSprite::create(g_sLifeValueBGImage);
	app4->setAnchorPoint(ccp(0,0));
	app4->setPositionX(needTip->getPositionX()+needTip->realWidth+4);
	app4->setPositionY(needTip->getPositionY());
	this->addChild(app4);

	CCMenuItemImage* pSureMenu = CCMenuItemImage::create(
                                                g_sSureBGImage, 
                                                g_sSureBGImage, 
                                                this, 
                                                menu_selector(ChallengeAgainLayer::onCommandSure));
	pSureMenu->setAnchorPoint(ccp(0,0));
	CCMenu* pMenu = CCMenu::create(pSureMenu, NULL);
    this->addChild(pMenu);
	pMenu->setTouchPriority(-1000);
	pMenu->setAnchorPoint(ccp(0,0));
	pMenu->setPositionY(app4->getPositionY()-app4->getTextureRect().size.height-40);
	pMenu->setPositionX(100);


	CCSprite * img = CCSprite::create(g_sReturnBGImage);
	CCMenuItemImage* pReturnMenu = CCMenuItemImage::create(
                                                g_sReturnBGImage, 
                                                g_sReturnBGImage, 
                                                this, 
                                                menu_selector(ChallengeAgainLayer::onCommandReturn));
	pReturnMenu->setAnchorPoint(ccp(0,0));
	CCMenu* pMenu2 = CCMenu::create(pReturnMenu, NULL);
    this->addChild(pMenu2);
	pMenu2->setTouchPriority(-1000);
	pMenu2->setAnchorPoint(ccp(0,0));
	pMenu2->setPositionY(pMenu->getPositionY());
	pMenu2->setPositionX(s.width-img->getTextureRect().size.width-100);
}
コード例 #17
0
void IOSStoreLayer::showItemsNode()
{
	int iTotalCount = 1;
	int iPrice = 10;
	int xcount = 1;
	int ycount = 1;
	CCSize size = CCSizeMake(120, 190);

	if (m_bBaoxiangBuyTenTimes)
	{
		iTotalCount = 10;
		size.width = 820;
		size.height = 350;
		xcount = 5;
		ycount = 2;
		iPrice = 95;
	}

	iTotalCount = this->getKaiBaoxiangRsqData().size();
	if (iTotalCount >= 11)
	{
		xcount = 6;
	}

	if (iTotalCount == 2)
	{
		xcount = 2;
		size = CCSizeMake(140*2, 190);
	}

	IOSStoreLayerScrollView* pView = IOSStoreLayerScrollView::createView(size, iTotalCount, xcount, ycount);
	m_pGetItemNode->addChild(pView);
	pView->ignoreAnchorPointForPosition(false);
	pView->setAnchorPoint(ccp(0.5f, 0.5f));
	pView->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2 - 60));
	pView->setClickableCreater(pView);
	pView->prepareToDisplay();
	pView->setTouchEnabled(false);
	pView->setTag(getitem_scrollview_tag);

	//显示
	CCSprite* pSmallbg = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_anniu_zaikaishici_fujia.png").c_str());
	m_pGetItemNode->addChild(pSmallbg, 1);
	pSmallbg->setPosition(ccp(200, 100));

	//添加菜单
	CCMenu* pMenu = CCMenu::create();
	pMenu->setPosition(CCPointZero);
	m_pGetItemNode->addChild(pMenu, 2);
	
	//再开按钮
	CCMenuItemImage* pItem = NULL;
	int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore();
	if (m_bBaoxiangBuyTenTimes)
	{
		pItem = CCMenuItemImage::create(
			ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaishici.png").c_str(),
			ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaishici_select.png").c_str(),
			this, menu_selector(IOSStoreLayer::menuBtnCallBack));
		pItem->setTag(buy_ten_again);
	}
	else
	{
		pItem = CCMenuItemImage::create(
			ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaiyici.png").c_str(),
			ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaiyici_select.png").c_str(),
			this, menu_selector(IOSStoreLayer::menuBtnCallBack));
		pItem->setTag(buy_one_again);
	}
	pItem->setPosition(ccp(pSmallbg->getPositionX() + pSmallbg->getContentSize().width/2 + pItem->getContentSize().width/2 - 30, 
		pSmallbg->getPositionY()));
	pMenu->addChild(pItem);

	//星星数量
	CCLabelAtlas* lable = CCLabelAtlas::create(
		"0123456789",
		ResManager::getManager()->getSharedFilePath(g_seasonlayerPath+"season_star_amount.png").c_str(),
		30, 47,//24
		'0');
	m_pGetItemNode->addChild(lable, 1, star_count_str_tag);
	lable->setAnchorPoint(ccp(0, 0.5));
	lable->setScale(0.6f);
	int iCount = 10;
	if (m_bBaoxiangBuyTenTimes)
	{
		iCount = 95;
	}
	char charStarCount[10] = {}; 
	sprintf(charStarCount, "%d", iCount);
	lable->setString(charStarCount);
	lable->setPosition(ccp(pItem->getPositionX()-pItem->getContentSize().width/2-lable->getContentSize().width/2 - 40, pSmallbg->getPositionY() - 3));

	//右边星星图标
	CCSprite* pXingxing = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_xiaogk+"YX_start.png").c_str());
	m_pGetItemNode->addChild(pXingxing, 1);
	pXingxing->setPosition(ccp(lable->getPositionX() - 30, pSmallbg->getPositionY()));

	//星星数不够时,只显示确定按钮
	//确定按钮
	CCMenuItemImage* pOKItem = CCMenuItemImage::create(
		ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_quedingi.png").c_str(),
		ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_quedingi_select.png").c_str(),
		this, menu_selector(IOSStoreLayer::menuBtnCallBack));
	pOKItem->setTag(ok_btn_tag);
	pOKItem->setPosition(ccp(this->getContentSize().width/2 + pOKItem->getContentSize().width, pSmallbg->getPositionY()));
	pMenu->addChild(pOKItem);

	if (iStarCount < iPrice)
	{
		lable->setVisible(false);
		pXingxing->setVisible(false);
		pSmallbg->setVisible(false);
		pItem->setVisible(false);

		pOKItem->setPosition(ccp(this->getContentSize().width/2, pSmallbg->getPositionY()));
	}
	pMenu->setTouchPriority(kCCMenuHandlerPriority-5);
}
コード例 #18
0
CCSprite* IOSStoreLayer::createCellSpr(int index, CellInfo* daojuInfo)
{
	CCSprite* pDaoju = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_bg.png").c_str());

	//显示道具的名字
	CCLabelTTF* pTitle = CCLabelTTF::create(daojuInfo->nameStr.c_str(), fontStr_katong, 24);
	pDaoju->addChild(pTitle);
	pTitle->setColor(fontColor_Store);
	pTitle->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height - 40));

	//显示道具的描述
	CCLabelTTF* pDescribe = CCLabelTTF::create(daojuInfo->describeStr.c_str(), fontStr_katong, 24, CCSizeMake(200, 60), kCCTextAlignmentLeft);
	pDaoju->addChild(pDescribe);
	pDescribe->setAnchorPoint(ccp(0, 0.5f));
	pDescribe->setHorizontalAlignment(kCCTextAlignmentLeft);
	pDescribe->setPosition(ccp(10, 85));

	if (daojuInfo->bBaoxiang)
	{
		pDescribe->setPosition(ccp(10, 65));
	}

	//显示图标
	CCSprite* pIcon = CCSprite::create(daojuInfo->iconNameStr.c_str());
//	if (pIcon)
	{
		pIcon->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height/2+20));
		pDaoju->addChild(pIcon, 1);

		CCSprite *mask = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_fugai.png").c_str());
		pDaoju->addChild(mask, 2);
		mask->setPosition(ccp(pIcon->getPositionX(), pIcon->getPositionY()+20));
	}

	//宝箱需要设置缩放为35%
	if (daojuInfo->bBaoxiang)
	{
		pIcon->setScale(0.35f);
	}

	//底部按钮
	CCMenuItemImage* pMenuItem = CCMenuItemImage::create(
		daojuInfo->btnIconNorNameStr.c_str(), 
		daojuInfo->btnIconSelNameStr.c_str(), 
		this, 
		menu_selector(IOSStoreLayer::menuBtnCallBack));

	//星星数不够就显示文字,够的话就显示开宝箱按钮
	if (pMenuItem)
	{
		bool bMore = false;
		int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore();
		if (daojuInfo->bBaoxiang)
		{
			if (daojuInfo->iBaoxiangCount == 10)
			{
				if (iStarCount >= 95)
				{
					bMore = true;
				}
			}
			else if (daojuInfo->iBaoxiangCount == 1)
			{
				if (iStarCount >= 10)
				{
					bMore = true;
				}
			}
		}
		else
		{
			bMore = true;
		}

		CCMenu* pMenu = CCMenu::create();
		pMenu->setPosition(CCPointZero);
		pDaoju->addChild(pMenu, 1);
		pMenu->addChild(pMenuItem);
		pMenuItem->setPosition(ccp(pDaoju->getContentSize().width/2,  pMenuItem->getContentSize().height/2));
		pMenu->setTouchPriority(kCCMenuHandlerPriority-3);
		pMenuItem->setVisible(false);

		if (bMore)
		{
			pMenuItem->setVisible(true);
		}
		else if (daojuInfo->bBaoxiang)
		{
			//星星不足时,显示的字符串
			CCLabelTTF* pTip = CCLabelTTF::create(LFStrings::getValue("Starless").c_str(), fontStr_katong, 24, CCSizeMake(200, 60), kCCTextAlignmentCenter);
			pDaoju->addChild(pTip,1);
			pTip->setPosition(ccp(pDaoju->getContentSize().width/2,  pMenuItem->getContentSize().height/2+5));
		}
	}

	//宝箱和购买星星区别加载
	if (daojuInfo->bBaoxiang)
	{
		//十个宝箱
		if (daojuInfo->iBaoxiangCount == 10)
		{
			pIcon = CCSprite::create(daojuInfo->iconBgNameStr.c_str());
			if (pIcon)
			{
				pIcon->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height/2+20));
				pDaoju->addChild(pIcon);
				pIcon->setScale(0.35f);
			}
			//十次
			pMenuItem->setTag(tentimes_btn_tag);
		}
		else if (daojuInfo->iBaoxiangCount == 1)
		{
			//一次
			pMenuItem->setTag(onetimes_btn_tag);
		}
	}
	else
	{
		//按照价格来设置购买按钮的tag
		pMenuItem->setTag(daojuInfo->iPrice);
	}

	return pDaoju;
}
コード例 #19
0
void SGAnnouncementLayer::initScrollView()
{
	//ResourceManager::sharedInstance()->bindTexture("sgannouncementlayer/sgannouncementlayer2.plist", RES_TYPE_LAYER_UI, sg_announcementLayer);
    m_scrollview->getContainer()->removeAllChildrenWithCleanup(true);
    int positionY = 0;// Y轴纵向偏移,
	int border_shift = 20;//内容窗口偏移
	
    int text_wid_expand = 40;//文本区宽度扩展
	if (CCEGLView::sharedOpenGLView()->getFrameSize().width == ipadResource.size.width
        ||CCEGLView::sharedOpenGLView()->getFrameSize().width == ipadhdResource.size.width)
	{
		text_wid_expand = 28;
	}
	
	//记录上一个内容窗口的底线位置
	float lastWindowBorderPos = 0.0f;
    for(int i = 0; i < m_arrayAnn->count(); i++)
	//for (int i = 0; i < 6; i++)
    {
		
		//=======================获取数据================================
		SGAnnouncementDataModel *ann = (SGAnnouncementDataModel *)m_arrayAnn->objectAtIndex(i);
		CCString *title = ann->getTitle();
		CCString *content = ann->getContent();

		int viewId = ann->getViewId();//跳转至哪个页面
		//=======================获取数据================================
		
        CCLayer *layer = (CCLayer*)m_scrollview->getContainer();//获取scrollview的容器

        CCLayerColor* contentWindow = initContentWindow(content, viewId > 0);
        contentWindow->setAnchorPoint(ccp(0.5, 0));
        contentWindow->ignoreAnchorPointForPosition(false);
        
        CCSize cwSize = contentWindow->getContentSize();
        
        CCSprite * sprite = CCSprite::createWithSpriteFrameName("Tips.png");
        sprite->setScaleX(cwSize.width / 584.0);
        sprite->setScaleY(cwSize.height / 522.0);
        sprite->setPosition(ccp(cwSize.width * 0.5, cwSize.height * 0.5));
        contentWindow->addChild(sprite, 2);
        
		//根据上一个内容窗口的位置计算下一个窗口的位置
		contentWindow->setPosition(ccp(layer->getContentSize().width * 0.5,
									   lastWindowBorderPos + border_shift));
		
        /* tips.png图片拉长的倍数 */
        float pngScale = cwSize.height / 522 ;
//        CCLOG("*******************>>>");
//        CCLOG("i = %d" , i);
//        CCLOG("title = %s" , title->getCString());
//        CCLOG("content = %s" , content->getCString());
//        CCLOG("pos: x=%f , y = %f" , contentWindow->getPositionX() , contentWindow->getPositionY());
//        CCLOG("cwSize: width=%f, height=%f", cwSize.width, cwSize.height);
//        CCLOG("lastWindowBorderPos = %f" , lastWindowBorderPos);
//        CCLOG("<<<********************");
        lastWindowBorderPos = contentWindow->getPositionY() + cwSize.height;

		//公告title
        CCLabelTTF *label = CCLabelTTF::create(title->getCString(), FONT_PANGWA, 35);
        label->setColor(COLOR_RED);
        label->setAnchorPoint(ccp(0.5 , 1));
		label->setPosition(ccp(cwSize.width *0.5f, cwSize.height - pngScale * 20));
		contentWindow->addChild(label, 100);
		//公告内容
//        CCSize maybeTextSize = stringInLabelRect(content->getCString());
//		CCLabelTTF *label_content=CCLabelTTF::create(content->getCString(), FONT_PENGYOU, 24,CCSizeMake(maybeTextSize.width + text_wid_expand * 4,maybeTextSize.height + text_hei_expand),kCCTextAlignmentLeft);
        CCLabelTTF *label_content=CCLabelTTF::create(content->getCString(), FONT_PENGYOU, 24,CCSizeMake(cwSize.width - 40 * widthFactor, cwSize.height - label->getContentSize().height),kCCTextAlignmentLeft);
		label_content->setAnchorPoint(ccp(0.5, 1));//内容顶线对齐
        label_content->setColor(ccBLACK);
		label_content->setPosition(ccp(label->getPositionX(), label->getPositionY() - label->getContentSize().height));
		label_content->setZOrder(102);
        contentWindow->addChild(label_content);
		
		//点击前往按钮
        if (viewId > 0) {
            SGButton *goButton = SGButton::create("box_btnbg.png", NULL, this, menu_selector(SGAnnouncementLayer::AnnounceButton),CCPointZero,false,true);
            
            CCString *go = CCString::createWithFormat(str_Hit_goto);
            SGCCLabelTTF *go_label = SGCCLabelTTF::create(go->getCString(), FONT_PANGWA, 30);
            
            goButton->addChild(go_label);
            goButton->setTag(viewId);//跳转到某个视图界面
            go_label->setPosition(ccp(goButton->getContentSize().width / 2, goButton->getContentSize().height / 2));
            
            //立即前往Button
            CCMenu *menu = CCMenu::create(goButton, NULL);
            menu->setTouchPriority(0);
            menu->setPosition(CCPointZero);
            goButton->setScale(0.7);
            goButton->setZOrder(200);
            //goButton->setPosition(ccp(label->getPositionX(), goButton->getContentSize().height / 1.5));
            goButton->setAnchorPoint(ccp(0.5, 0));
            goButton->setPosition(ccp(label->getPositionX(), pngScale * 18));
            menu->setZOrder(200);
            contentWindow->addChild(menu);
        }

		layer->addChild(contentWindow);
        //每次加对应的contentWindow的大小,为之后计算scrollview的内容体偏移
        positionY += (cwSize.height + border_shift);

    }
	//layer->setContentSize(CCSizeMake(504, m_scrollview->getContentSize().height));
	//控制是否可以滑动
	iscanmove = (positionY)>791?true:false;//@note:591是m_scrollview的可视区域高度
	

	m_scrollview->setContentOffset(ccp(0, -positionY + m_scrollview->getContentSize().height - 30));//20是顶部窗口的起始位置偏移,不减去会有一小部分遮挡
    m_scrollview->setContentSize(CCSizeMake(m_scrollview->getContentSize().width, positionY));//scrollview的真正大小
    m_scrollview->getContainer()->setContentSize(CCSizeMake(m_scrollview->getContentSize().width, positionY + 10));//滚动重置时的container位置
}