Пример #1
0
void FrontCoverLayer::addNewSever()
{
	UILayout* m_layout = UIManager::sharedManager()->getUILayout("SplashLayout");
	if(m_severScrollPage)
	{
		CCLayer* layer = CCLayer::create();
		m_severScrollPage->addPage(layer);

		int count = m_severList.size();
		int currentPage = 0;
		int column = 3;
		int row = 2;

		ASprite *as = AspriteManager::getInstance()->getAsprite(KUI_BIN);
		int idx = map_ui_FRAME_SELECTSERVE_BUTTON;
		int selectedId = map_ui_FRAME_SELECTSERVE_BUTTON_CLICKED;
		float scale = UIManager::sharedManager()->getScaleFactor();
		float width = m_severScrollPage->getContentSize().width / scale;
		float height = m_severScrollPage->getContentSize().height / scale;

		CCRect rect = as->getframeRect(idx);

		float deltaWidth = (width - column * rect.size.width )/(column + 1);
		float deltaHeigth = (height - row * rect.size.height )/(row + 1);
		
		for(int i =0; i< count; i++)
		{
			int index = i;
			int page = index / (column * row);
			int rowIndex = (index - page * column * row) / column;
			int columnIndex = (index - page * column * row) % column;
			if(page != currentPage)
			{
				currentPage = page;
				CCLayer* newlayer = CCLayer::create();
				m_severScrollPage->addPage(newlayer);
			}

			CCPoint pt;
			CCSprite *pEmptyItem = as->getSpriteFromFrame_Middle( idx, 0, pt);
			CCSprite *pSelectedItem = as->getSpriteFromFrame_Middle(selectedId ,0,pt); 
			IconButton * pIcon = new IconButton(pEmptyItem, NULL, pSelectedItem, this, 
				menu_selector(FrontCoverLayer::onClickedOneSever));
			pIcon->autorelease();
			pIcon->SetButtonIndex(index);
			pIcon->setContentSize(pEmptyItem->getContentSize());

			float x = -width * 0.5f + deltaWidth * (columnIndex + 1) + (columnIndex + 0.5f) * rect.size.width ;
			float y = height * 0.5f - (rowIndex + 0.5f) * (deltaHeigth + rect.size.height );
			pIcon->setPosition(ccp(x, y));

			UILabelTTF* label = UILabelTTF::create(m_severList[i]->name,KJLinXin,40,pEmptyItem->getContentSize(),kCCTextAlignmentCenter,kCCVerticalTextAlignmentCenter);
			pIcon->addChild(label);
			m_lstButton.push_back(pIcon);
			CCLayer* currentLayer = m_severScrollPage->getPageLayer(currentPage);
			currentLayer->addChild(pIcon,index);	
		}
	}
}
Пример #2
0
void CityListLayer::addCityBtn(int index)
{	
	//获得城市按钮位置
	stringstream nameStream;
	nameStream << "cityBtn" << index;
	string cityBtnName = nameStream.str();

	UIButton *btn = cityListLayout->FindChildObjectByName<UIButton>(cityBtnName);
	CCPoint cityPoint = btn->getPosition();

	//初始化各种位置信息
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	cityInfoList[index - 1].cityPos = ccpAdd(ccp(visibleSize.width / 2, visibleSize.height / 2), cityPoint);
	cityInfoList[index - 1].playerPos = ccpAdd(cityInfoList[index - 1].cityPos, ccp(0, -25));
	cityInfoList[index - 1].namePos = ccpAdd(cityInfoList[index - 1].cityPos, ccp(0, -30));

	//获得城市图标资源
	CCPoint pt;
    ASprite * as = AspriteManager::getInstance()->getAsprite(KICON_BIN);

	stringstream resourceNameStream;
	resourceNameStream << "map_ui_system_icon_FRAME_ICON_CITY" << index;
	string cityResourceName = resourceNameStream.str();

	int cityResourceId = getResourceIDByName(cityResourceName.c_str());
    CCSprite* cityIcon = as->getSpriteFromFrame_Middle(cityResourceId, 0, pt);
	CCSprite* citySelectIcon = as->getSpriteFromFrame_Middle(cityResourceId, 0, pt);
	citySelectIcon->setScale(1.2f);

	//创建城市图标
	IconButton * cityBtn = new IconButton(cityIcon, NULL, citySelectIcon, this, 
					menu_selector(CityListLayer::onPressCityBtn));	
	
	cityBtn->setPosition(cityInfoList[index - 1].cityPos);
	cityBtn->SetButtonIndex(index);
	cityBtn->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(cityBtn);

	//创建城市名称label
	float fontSize = GameFontManager::smallFontSize();
	CCSize nameLabelSize = CCSizeMake(200 / CC_CONTENT_SCALE_FACTOR(), fontSize);
	
	string cityName = MainLandManager::Get()->getCityName(cityInfoList[index - 1].cityId);
	UILabelTTF * cityNameLabel = UILabelTTF::create(cityName.c_str(), KJLinXin, fontSize,
				nameLabelSize, kCCTextAlignmentCenter,kCCVerticalTextAlignmentBottom);
    
	cityNameLabel->setPosition(cityInfoList[index - 1].namePos);
	this->addChild(cityNameLabel);
}
Пример #3
0
	void UIScrollPage::addOneEmptyPage(int pageIndex)
	{
		CCLayer* layer = CCLayer::create();
		layer->setAnchorPoint(ccp(0, 0));
		{
			int deltaX, deltaY;
			if(m_cellBinFile == "")
			{
				m_cellBinFile = KUI_BIN;
			}
			ASprite *as = AspriteManager::getInstance()->getAsprite(m_cellBinFile);
			int idx = getResourceIDByName(m_cellAsfile.c_str());
			int selectedId = getResourceIDByName(m_cellSelectedAsfile.c_str());
			CCSize buttonSize = as->getframeRect(idx).size;
//			float contentScale = CCDirector::sharedDirector()->getContentScaleFactor();
//			buttonSize = CCSizeMake(buttonSize.width * contentScale, buttonSize.height * contentScale);

			if (m_icolumn <= 1)
				deltaX = 0;
			else
				deltaX = (getContentSize().width - 2 * m_celloffsetX - buttonSize.width) / (m_icolumn - 1);

			if (m_irow <= 1)
				deltaY = 0;
			else
				deltaY = (getContentSize().height - 2 * m_celloffsetY - buttonSize.height) / (m_irow - 1);
			
			/////////////////////////////////////////////////////////////////////////////
			// row 
			// row
			for(int r = 0; r < (int)m_irow; r++)
			{
				for(int l = 0; l < (int) m_icolumn; l++)
				{
					// clone one ccsprite 
					CCPoint pt;
					CCSprite *pEmptyItem = as->getSpriteFromFrame_Middle( idx, 0, pt);
					CCSprite *pSelectedItem = as->getSpriteFromFrame_Middle(selectedId ,0,pt); 
					IconButton * pIcon = new IconButton(pEmptyItem, NULL, pSelectedItem, this, 
						menu_selector(UIScrollPage::OnItemClicked));
					pIcon->autorelease();
					int index = pageIndex * m_icolumn * m_irow;
					index += r * m_icolumn + l;
					pIcon->SetButtonIndex(index+1);
					pIcon->setContentSize(pEmptyItem->getContentSize());
					if(m_itemType != 0)
					{
						pIcon->creatDragReceiver((DragHandlerType)m_itemType);
					}
					pIcon->SetDoubleClickHandler(this,menu_selector(UIScrollPage::OnItemDoubleClicked));
					pIcon->SetTappedHandler(this,menu_selector(UIScrollPage::OnTapped),menu_selector(UIScrollPage::OnTapCancel));
					pIcon->SetDragFlagTime(150);
					m_lstButton.push_back(pIcon);

					int x = l * deltaX + m_celloffsetX + buttonSize.width / 2 - getContentSize().width / 2 ;
					int y = getContentSize().height / 2 - (r * deltaY + m_celloffsetY + buttonSize.height / 2);

//					x /= contentScale;
//					y /= contentScale;

					pIcon->setPosition(ccp(x, y));

					char name[50];
					sprintf(name,"%s_%d",this->m_strName.c_str(),index+1);
					pIcon->SetButtonName(name);

					layer->addChild(pIcon);
				}
			}
		}

		addPage(layer);		
	}
Пример #4
0
bool CityListLayer::init()
{
	if(!CCLayer::init())
	{
		return false;
	}

	//读取城市列表
	initCityList();

	UIManager *manager = UIManager::sharedManager();
	cityListLayout = manager->CreateUILayoutFromFile("UIplist/cityListUI.plist", this, "CityList");	

	//添加背景图片
	CCSprite * bgImg = CCSprite::create("game.png");

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCSize bgSize = bgImg->getContentSize();

	float scaleX = visibleSize.width / bgSize.width;
	float scaleY = visibleSize.height / bgSize.height;

	bgImg->setScaleX(scaleX);
	bgImg->setScaleY(scaleY);
	
	bgImg->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));

	this->addChild(bgImg, -1);

	//添加主城
	for (size_t i = 0; i < cityInfoList.size(); i++)
	{
		addCityBtn(i+1);
	}


	//添加关闭按钮
	UIButton *btn = cityListLayout->FindChildObjectByName<UIButton>("cityListCloseBtn");
	CCPoint closePoint = btn->getPosition();
	closePoint = ccpAdd(ccp(visibleSize.width / 2, visibleSize.height / 2), closePoint);

	CCPoint pt1;
	ASprite * as1 = AspriteManager::getInstance()->getAsprite(KUI_BIN);

	int normalCloseId = getResourceIDByName("map_ui_FRAME_INSTANCE_CLOSE");
	int selectCloseId = getResourceIDByName("map_ui_FRAME_INSTANCE_CLOSE_CLICKED");

	CCSprite * normalCloseBtn = as1->getSpriteFromFrame_Middle(normalCloseId, 0, pt1);
	CCSprite * selectCloseBtn = as1->getSpriteFromFrame_Middle(selectCloseId, 0, pt1);

	IconButton * closeBtn = new IconButton(normalCloseBtn, NULL, selectCloseBtn, this, 
					menu_selector(CityListLayer::closeCityList));

	closeBtn->setPosition(closePoint);

	this->addChild(closeBtn);

	//初始化玩家头像资源
	CCPoint pt;
    ASprite * as = AspriteManager::getInstance()->getAsprite(KICON_BIN);

	int playerType = UserData::Get()->GetUserType();

	stringstream playerResStream;
	playerResStream << "map_ui_system_icon_FRAME_ICON_ROLEONMAP_" << playerType;
	string playerResName = playerResStream.str();

	int playerResourceId = getResourceIDByName(playerResName.c_str());
    playerImg = as->getSpriteFromFrame_Middle(playerResourceId, 0, pt);
	playerImg->setVisible(false);	

	this->addChild(playerImg);


	playerMoving = false;
	return true;
}