Esempio n. 1
0
void FairyControlPanel::initHero(FairyHero* selectHero){
	controlType = 2;
	panelBack->removeAllChildrenWithCleanup(true);
	CCSize size = panelBack->getContentSize();
	int ids[4] = {-1, -1, -1, -1};
	for(int i = 0; i < (int)selectHero->skillIds.size(); i++){
		ids[i] = selectHero->skillIds.at(i);
	}
	CCString* SkillDataFile;
	XMLParser *skillData;
	CCMenu* menu = CCMenu::create();
	if(ids[0] != -1){
		SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[0]);
		skillData = XMLParser::parseWithFile(SkillDataFile->getCString());
		CCSprite* skill1 = CCSprite::create(skillData->getString("skillIcon")->getCString());
		CCMenuItemSprite*skill1Button = CCMenuItemSprite::create(skill1, skill1, this, menu_selector(FairyControlPanel::fairyMenuCallback));
		skill1Button->setTag(leftDrection);
		skill1Button->setPosition(ccp(size.width / 8, size.height / 2 + 30));
		menu->addChild(skill1Button);
	}
	if(ids[1] != -1){
		SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[1]);
		skillData = XMLParser::parseWithFile(SkillDataFile->getCString());
		CCSprite* skill1 = CCSprite::create(skillData->getString("skillIcon")->getCString());
		CCSprite* skill2 = CCSprite::create(uiLeftNormal);
		CCMenuItemSprite* skill2Button = CCMenuItemSprite::create(skill2, skill2, this, menu_selector(FairyControlPanel::fairyMenuCallback));
		skill2Button->setTag(holdDrection);
		skill2Button->setPosition(ccp(2 * size.width / 8, size.height / 2+ 30));
		menu->addChild(skill2Button);
	}
	if(ids[2] != -1){
		SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[2]);
		skillData = XMLParser::parseWithFile(SkillDataFile->getCString());
		CCSprite* skill1 = CCSprite::create(skillData->getString("skillIcon")->getCString());
		CCSprite* skill3 = CCSprite::create(uiLeftNormal);
		CCMenuItemSprite* skill3Button = CCMenuItemSprite::create(skill3, skill3, this, menu_selector(FairyControlPanel::fairyMenuCallback));
		skill3Button->setTag(rightDrection);
		skill3Button->setPosition(ccp(3 * size.width / 8, size.height / 2 + 30));
		menu->addChild(skill3Button);
	}
	if(ids[3] != -1){
		SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[3]);
		skillData = XMLParser::parseWithFile(SkillDataFile->getCString());
		CCSprite* skill4 = CCSprite::create(skillData->getString("skillIcon")->getCString());
		CCMenuItemSprite* skill4Button = CCMenuItemSprite::create(skill4, skill4, this, menu_selector(FairyControlPanel::fairyMenuCallback));
		skill4Button->setTag(upDrection);
		skill4Button->setPosition(ccp(4 * size.width / 8, size.height / 2 + 30));
		menu->addChild(skill4Button);
	}
	panelBack->addChild(menu);
	menu->setPosition(ccp(0, - 30));
	CCString* heroDataFile = CCString::createWithFormat("data/hero%d.xml",selectHero->heroId / 10 * 10);
	XMLParser *heroData = XMLParser::parseWithFile(heroDataFile->getCString());
	CCLabelTTF* heroName = CCLabelTTF::create(heroData->getString("name")->getCString(), "Arial", 50);
	heroName->setColor(ccc3(0x00, 0x00, 0x00));
	heroName->setAnchorPoint(ccp(0,1));
	heroName->setPosition(ccp( 5 * size.width / 8, size.height / 2 + 30));
	panelBack->addChild(heroName);
}
Esempio n. 2
0
bool FairyMenu::init()
{
    bool bRet = false;
    do 
    {
        CC_BREAK_IF(! CCLayer::init());
		AnimatePacker::getInstance()->loadAnimations("skill/loading.xml"); 
		CCString *fileName = CCString::createWithFormat(BattleMusic, 2);
		SimpleAudioEngine::sharedEngine()->playBackgroundMusic(fileName->getCString(), true);
        CCSize size = CCDirector::sharedDirector()->getWinSize();
		CCSprite *fairyMenuBack = CCSprite::create(menuBack);
		this->addChild(fairyMenuBack);
		fairyMenuBack->setPosition(ccp(size.width / 2, size.height / 2));
		CCSprite *fairyMenuMenu = CCSprite::create(menuMenu);
		this->addChild(fairyMenuMenu);
		fairyMenuMenu->setPosition(ccp(size.width / 2, size.height / 2 - 100));
		CCSprite *menuLoading=CCSprite::create();
		this->addChild(menuLoading);
		menuLoading->setPosition(ccp(size.width/2, size.height/2 + 60));
		menuLoading->runAction(CCRepeatForever::create(AnimatePacker::getInstance()->getAnimate("loading")));
		int itemPosition[3][2]  = {{5, 0 - 90 }, {5, -205}, {5, 0 - 310}};
		XMLParser *scene = XMLParser::parseWithFile("data/common.xml");
		CCString* menuStart = scene->getString("menu_start");
		CCString* menuIntro = scene->getString("menu_intro");
		CCString* menuExit = scene->getString("menu_exit");
		CCMenu* menu = CCMenu::create();
		for(int i =0; i < 3; i++){
			CCSprite* fairyMenuButton = CCSprite::create(menuItem);
			CCMenuItemSprite* fairyMenuButtonItem = CCMenuItemSprite::create(fairyMenuButton, fairyMenuButton, this, menu_selector(FairyMenu::fairyMenuCallback));
			fairyMenuButtonItem->setPosition(ccp(itemPosition[i][0] ,itemPosition[i][1]));
			fairyMenuButtonItem->setTag(i + 1);
			menu->addChild(fairyMenuButtonItem);
		}
		this->addChild(menu);
		CCLabelTTF* fairyMenuStart = CCLabelTTF::create(menuStart->getCString(), "Arial", 30);
		this->addChild(fairyMenuStart);
		fairyMenuStart->setPosition(ccp(size.width/2, size.height/2 - 90));
		CCLabelTTF* fairyMenuIntro = CCLabelTTF::create(menuIntro->getCString(), "Arial", 30);
		this->addChild(fairyMenuIntro);
		fairyMenuIntro->setPosition(ccp(size.width/2, size.height/2 - 204));
		CCLabelTTF* fairyMenuExit = CCLabelTTF::create(menuExit->getCString(), "Arial", 30);
		this->addChild(fairyMenuExit);
		fairyMenuExit->setPosition(ccp(size.width/2, size.height/2 - 310));
        bRet = true;
    } while (0);

    return bRet;
}
Esempio n. 3
0
void ChatLayer::requestFinishedCallback(CCNode* pSender,void *data)
{
    CCHttpResponse *response =  (CCHttpResponse*)data;
	if(response==NULL)
	{
		return;
	}
	int statusCode = response->getResponseCode();
	char statusString[64] = {};
	CCLOG(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag());

	if (!response->isSucceed())   
	{  
		CCLog("response failed");  
		CCLog("error buffer: %s", response->getErrorBuffer());  
		return;  
	}
	std::vector<char> *buffer = response->getResponseData(); 

	std::string content(buffer->begin(),buffer->end());

	XMLParser *xmlParser = XMLParser::parseWithString(content.c_str());
	CCLOG("%s",xmlParser->getString("content")->getCString());

//	parseJson();
}
Esempio n. 4
0
bool TujiLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}

	m_iBeforeSel = 0;

	// 背景
	auto bgSprite = Sprite::create("PhotoGalleryBackground.png");
	bgSprite->setPosition(WINSIZE.width / 2, WINSIZE.height / 2);
	this->addChild(bgSprite);

	auto closeItem = MenuItemSprite::create(
		Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("GalleryOffNormal.png")),
		Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("GalleryOffSelected.png")),
		[&](Ref * ref){
		PLAYEFFECT;
		//弹出场景
		Director::getInstance()->replaceScene(StartLayer::createScene()); });
	// 关闭按钮
	closeItem->setPosition(WINSIZE.width/2+580, WINSIZE.height/2+320);
	auto menu = Menu::create(closeItem, NULL);
	menu->setPosition(Point::ZERO);
	bgSprite->addChild(menu);

	// 怪物图鉴
// 	char *inBuf = "木\n桩\n怪";
// 	size_t inLen = strlen(inBuf);
// 	size_t outLen = inLen << 1;
// 	char *outBuf = (char *)malloc(outLen);
// 	gbk2utf8(inBuf, inLen, outBuf, outLen);

	XMLParser *pXmlParser = XMLParser::parseWithFile("tujiLayer.xml");
	String *mz = pXmlParser->getString("muzhuang");

	m_pMZ_Pic = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("ManWood.png"));
	m_pMZ_Txt = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("Text.png"));
	m_pMZLabel = LabelTTF::create(mz->getCString(), "", 30);
	m_pMZLabel->setColor(ccc3(0, 255, 255));

//  free(outBuf);
	m_pLion_Pic = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("ManLion.png"));
	m_pLionLabel = LabelTTF::create("狮\n子\n怪 ", "", 30);
	m_pLionLabel->setColor(ccc3(0, 255, 255));
	m_pStone_Pic = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("ManStone.png"));
	m_pStoneLabel = LabelTTF::create("石\n头\n怪 ", "", 30);
	m_pStoneLabel->setColor(ccc3(0, 255, 255));
	m_pStoneLabel->setRotation(90);

	m_pMZ_Pic->setPosition(WINSIZE.width / 2 + 50, WINSIZE.height / 2);
	m_pMZ_Pic->setVisible(true);
	m_pMZ_Txt->setPosition(WINSIZE.width / 2 + 460, WINSIZE.height / 2 );
	m_pMZ_Txt->setVisible(true);
	m_pMZLabel->setPosition(WINSIZE.width / 2 + 265, WINSIZE.height / 2 - 120);
	m_pMZLabel->setVisible(true);

	m_pLion_Pic->setPosition(WINSIZE.width / 2+50, WINSIZE.height / 2);
	m_pLion_Pic->setVisible(false);
	m_pLionLabel->setPosition(WINSIZE.width / 2 + 265, WINSIZE.height / 2 - 120);
	m_pLionLabel->setVisible(false);

	m_pStone_Pic->setPosition(WINSIZE.width / 2 , WINSIZE.height / 2 );
	m_pStone_Pic->setVisible(false);
	m_pStoneLabel->setPosition(WINSIZE.width / 2 + 265, WINSIZE.height / 2 - 120);
	m_pStoneLabel->setVisible(false);

	bgSprite->addChild(m_pMZ_Pic);
	bgSprite->addChild(m_pMZ_Txt);
	bgSprite->addChild(m_pMZLabel);
	bgSprite->addChild(m_pLion_Pic);
	bgSprite->addChild(m_pLionLabel);
	bgSprite->addChild(m_pStone_Pic);
	bgSprite->addChild(m_pStoneLabel);

	listView = ListView::create();
	listView->setDirection(SCROLLVIEW_DIR_VERTICAL);
	listView->setTouchEnabled(true);
	listView->setBounceEnabled(true);  // 反弹
	listView->setSize(Size(445, 500));
	listView->ignoreContentAdaptWithSize(false);
	listView->setAnchorPoint(Point(0.0, 0.0));
	listView->setPosition(Point(0, WINSIZE.height / 4));
	listView->addEventListenerListView(this, SEL_ListViewEvent(&TujiLayer::selectedItemEvent));
	
	bgSprite->addChild(listView);

	Button* default_button = Button::create("Cell_0.png", "CellSel_0.png", "", UI_TEX_TYPE_PLIST);
	
	default_button->setName("Title Button");

	Layout* default_item = Layout::create();
	default_item->setTouchEnabled(true);
	default_item->setSize(default_button->getSize());
	default_button->setPosition(Point(default_item->getSize().width / 2.0f,
	default_item->getSize().height / 2.0f));
	default_item->addChild(default_button);
	
	// set model 将创建的模板设置为项目模板  
	listView->setItemModel(default_item);


	// 1
	Button* custom_buttonMZ = Button::create("CellSel_0.png", "Cell_0.png", "", UI_TEX_TYPE_PLIST);
	custom_buttonMZ->setName("one Button");
	custom_buttonMZ->setScale9Enabled(true);
	custom_buttonMZ->setSize(default_button->getSize());
	Layout *custom_itemMZ = Layout::create();
	custom_itemMZ->setSize(custom_buttonMZ->getSize());
	custom_buttonMZ->setPosition(Point(custom_itemMZ->getSize().width / 2.0f, custom_itemMZ->getSize().height / 2.0f));
	custom_itemMZ->addChild(custom_buttonMZ);

	// 2
	Button* custom_buttonLion = Button::create("CellSel_1.png", "Cell_1.png", "", UI_TEX_TYPE_PLIST);
	custom_buttonLion->setName("two Button");
	custom_buttonLion->setScale9Enabled(true);
	custom_buttonLion->setSize(default_button->getSize());
	Layout *custom_itemLion = Layout::create();
	custom_itemLion->setSize(custom_buttonLion->getSize());
	custom_buttonLion->setPosition(Point(custom_itemLion->getSize().width / 2.0f, custom_itemLion->getSize().height / 2.0f));
	custom_itemLion->addChild(custom_buttonLion);

	// 3
	Button* custom_buttonStone = Button::create("CellSel_2.png", "Cell_2.png", "", UI_TEX_TYPE_PLIST);
	custom_buttonStone->setName("three Button");
	custom_buttonStone->setScale9Enabled(true);
	custom_buttonStone->setSize(default_button->getSize());
	Layout *custom_itemStone = Layout::create();
	custom_itemStone->setSize(custom_buttonStone->getSize());
	custom_buttonStone->setPosition(Point(custom_itemStone->getSize().width / 2.0f, custom_itemStone->getSize().height / 2.0f));
	custom_itemStone->addChild(custom_buttonStone);

	// 4
	Button* custom_buttonWood = Button::create("CellSel_3.png", "Cell_3.png", "", UI_TEX_TYPE_PLIST);
	custom_buttonWood->setName("four Button");
	custom_buttonWood->setScale9Enabled(true);
	custom_buttonWood->setSize(default_button->getSize());
	Layout *custom_itemWood = Layout::create();
	custom_itemWood->setSize(custom_buttonWood->getSize());
	custom_buttonWood->setPosition(Point(custom_itemWood->getSize().width / 2.0f, custom_itemWood->getSize().height / 2.0f));
	custom_itemWood->addChild(custom_buttonWood);

 	listView->pushBackCustomItem(custom_itemMZ);
 	listView->pushBackCustomItem(custom_itemLion);
	listView->pushBackCustomItem(custom_itemStone);
	listView->pushBackCustomItem(custom_itemWood);


	return true;
}