Ejemplo n.º 1
0
void UI_Bag_Gem_Layer::ClearEachCell()
{
	/************************************************************************/
	// 清除每个Cell里面的信息
	for (int nIndex = 0; nIndex < MAX_TAG_COUNT; ++nIndex)
	{
		// 1. 读取Json文件获取包裹每一个单元格
		Widget *pLayer = dynamic_cast<Widget*>(m_pBagGemScrollView->getChildByTag(nIndex));
		if (pLayer == NULL)
			return;

		// 2. 设置Icon
		ImageView * pMaterialImage = dynamic_cast<ui::ImageView*>(Helper::seekWidgetByName(pLayer, "Icon_ImagerView"));
		if (pMaterialImage == NULL)
			return;

		pMaterialImage->setVisible(false);

		// 3. 设置物品选中框
		ImageView * pMaterialSelectedImage = dynamic_cast<ui::ImageView*>(Helper::seekWidgetByName(pLayer, "Select_Box"));
		if (pMaterialSelectedImage == NULL)
			return;

		pMaterialSelectedImage->setVisible(false);

		// 4. 设置物品的个数
		TextAtlas * pMateriCount = dynamic_cast<ui::TextAtlas*>(Helper::seekWidgetByName(pLayer, "Count_Text"));
		if (pMateriCount == NULL)
			return;

		pMateriCount->setVisible(false);
	}
}
Ejemplo n.º 2
0
bool UI_Bag_Gem_Layer::SetSingleCellInfo(const int nTagID, Game_Data::Item_Container * pInfo)
{
	/************************************************************************/
	// 设置单个Cell的信息
	// 1. 判断索引ID是否异常
	if (nTagID >= MAX_TAG_COUNT)
		return false;

	// 2. 获取该物品的Config
	Game_Data::Item_Config * pItemConfig = ITEM_CONFIG_MGR::instance()->get_item_config(pInfo->item_id);
	if (pItemConfig == NULL)
		return false;

	// 3. 读取Json文件获取包裹每一个单元格
	Widget *pLayer = dynamic_cast<Widget*>(m_pBagGemScrollView->getChildByTag(nTagID));
	if (pLayer == NULL)
		return false;

	/************************************************************************/
	// 条件满足设置物品信息
	int nTemp = 0;
	const char * szTemp;
	// 1. 设置Icon
	ImageView * pMaterialImage = dynamic_cast<ui::ImageView*>(Helper::seekWidgetByName(pLayer, "Icon_ImagerView"));
	if (pMaterialImage == NULL)
		return false;

	szTemp	= ITEM_CONFIG_MGR::instance()->get_icon_path(pItemConfig->icon);
    std::string p("icon/");
    p+=szTemp;
	nTemp	= strcmp(p.c_str(), "");
	if (nTemp <= 0)
		return false;

	pMaterialImage->loadTexture(p.c_str());
	pMaterialImage->setVisible(true);
	
	// 2. 设置物品的个数
	TextAtlas * pMateriCount = dynamic_cast<ui::TextAtlas*>(Helper::seekWidgetByName(pLayer, "Count_Text"));
	if (pMaterialImage == NULL)
		return false;

	pMateriCount->setString(CCString::createWithFormat("%d", pInfo->item_count)->getCString());
	pMateriCount->setVisible(true);

	// 3. 为每件物品注册点击事件
	pMaterialImage->setTag(nTagID);
	pMaterialImage->addTouchEventListener(CC_CALLBACK_2(UI_Bag_Gem_Layer::OnBtnClickMaterialCallBack, this));
	return true;
}