Exemplo n.º 1
0
bool ToTextLayer::DerSelMenu(Script* ts){
	do{
		CC_BREAK_IF(!ts);
		//CCDictionary* attrs = ts->attributes;
		CCArray* scrs = ts->scriptnodes;
		int n = ts->m_snum;
		int maxleng = 0;	/* <最大字长 */

		CCArray* tm = CCArray::createWithCapacity(n);
		for(int i=0;i<n;i++){
			Script* tmp = (Script*) scrs->objectAtIndex(i);		//set more here if you want more.

			float sf = 1;
			CCSprite* spriteNormal; 
			CCSprite* spriteSelected;
			CCSprite* spriteDisabled;

			spriteNormal = CCSprite::create("Images/menuitemsprite2.png", CCRectMake(0,23*2/sf,70/sf,23/sf));
			spriteSelected = CCSprite::create("Images/menuitemsprite2.png", CCRectMake(0,23*1/sf,70/sf,23/sf));
			spriteDisabled = CCSprite::create("Images/menuitemsprite2.png", CCRectMake(0,23*0,70/sf,23/sf));

			SpriteTextMenuItem* item2 = new SpriteTextMenuItem();
			item2->autorelease();
			item2->initWithNormalSprite(spriteNormal, spriteSelected, spriteDisabled,this, menu_selector(ToTextLayer::menucallback) );
			item2->settext(tmp->getstring("content"), FNT_CHN, 24);
			item2->setSData(tmp->getint("jump"));
			item2->setTag(100+i);

			maxleng = max(maxleng, strlen(tmp->getstring("content")));

			tm->insertObject(item2,i);
		}
		sel_menu = MouseMenu::createWithArray(tm);	

		sel_menu->setTouchEnabled(false);
		sel_menu->alignItemsVertically();
		sel_menu->setTag(MENUTAG);
		sel_menu->setPosition(ccp(s.width/2, s.height/2));
		sel_menu->f_setaligntype(1);
		addChild(sel_menu);

		float t_width,t_height;

		t_width = maxleng * 30;
		t_height = n * 30;

		CCScale9Sprite* nback = CCScale9Sprite::create("Images/popup_back.png"); 
		nback->setContentSize(CCSize(t_width+ 23,t_height+ 22));
		nback->setAnchorPoint(ccp(0.5,0.5));
		nback->setPosition(s.width/2, s.height/2 - t_height/2 +30 );
		nback->setOpacity(200);
		nback->setTag(MENUTAG+1);
		addChild(nback,-1);

		e_layerstate = 1;

		return true;
	}while(0);
	return false;
}
bool Scene_GameItem::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
   
    //background
   // CCSprite* pSpriteBG = CCSprite::createWithSpriteFrameName("bg.png");
   // pSpriteBG->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
//    pSpriteBG->setColor(ccGRAY);
	// by wsp
// 	CCSprite* pSpriteBG = CCSprite::createWithSpriteFrameName("GameSceneBg/GameBg.png");
// 	pSpriteBG->setAnchorPoint(ccp(0.f,0.f));
	CCScale9Sprite* pSpriteBG = CCScale9Sprite::create("./CocoStudioResources/GameSceneBg/GameBg.png");
	pSpriteBG->setAnchorPoint(ccp(0.f,0.f));
	pSpriteBG->setContentSize(CCSizeMake(visibleSize.width,visibleSize.height));
	this->addChild(pSpriteBG, 0);
	pSpriteBG->setTag(eGameItemTagBg);
	CCSprite* pSpriteBGTop = CCSprite::create();
	pSpriteBGTop->setTag(eGameItemTagBgTop);
	this->addChild(pSpriteBGTop, 0);
	
    ul = UILayer::create();
    auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath("Item.json").c_str()));
    ul->addWidget(myLayout);
    ul->setContentSize(visibleSize);
    this->addChild(ul, 1, 100);
    
    //返回按钮.
    returnBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("Return"));
    returnBtn->setPressedActionEnabled(true);
    returnBtn->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::returnBtnCallBack));
    
    //开始游戏按钮.
    UIButton* startGameBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("StartGame"));
//    startGameBtn->setPressedActionEnabled(true);
    startGameBtn->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::startGameCallBack));
    

    //道具按钮.
    UIButton* itemBtn1 = dynamic_cast<UIButton*>(ul->getWidgetByName("ItemBtn1"));
    itemBtn1->setTag(Btn_1);
    itemBtn1->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::itemBtnCallBack));
    
    UIButton* itemBtn2 = dynamic_cast<UIButton*>(ul->getWidgetByName("ItemBtn2"));
    itemBtn2->setTag(Btn_2);
    itemBtn2->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::itemBtnCallBack));
    UIButton* itemBtn3 = dynamic_cast<UIButton*>(ul->getWidgetByName("ItemBtn3"));
    itemBtn3->setTag(Btn_3);
    itemBtn3->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::itemBtnCallBack));
    UIButton* itemBtn4 = dynamic_cast<UIButton*>(ul->getWidgetByName("ItemBtn4"));
    itemBtn4->setTag(Btn_4);
    itemBtn4->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::itemBtnCallBack));
    
    

    
    //勋章任务点击.
    taskBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("TitleBtn"));
    taskBtn->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::taskBtnCallBack));
    taskBtn->setPressedActionEnabled(true);
   
    rankBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("RankingBtn"));
    rankBtn->addReleaseEvent(this, coco_releaseselector(Scene_GameItem::rankBtnCallBack));
    rankBtn->setPressedActionEnabled(true);
    
    CTaskMan::sharedInstance().requestDayTaskSelect(GameShare_Global::shareGlobal()->gameType);
    
	//人物动画
	auto pRole = CCSprite::create("role/pig_tl/1.png");
	pRole->setTag(AniLayerTag);
	this->addChild(pRole,1);
    return true;
}