Esempio n. 1
0
EntityIcon* EntityIconManager::createIcon(Gui::Icons::Icon* icon, EmberEntity* entity, unsigned int pixelSize)
{
	if (!icon) {
		S_LOG_WARNING("Trying to create an EntityIcon with an invalid Icon.");
		return 0;
	}
	std::stringstream ss;
	ss << "entityIcon" << mIconsCounter++;
	
	CEGUI::DragContainer* item = static_cast<CEGUI::DragContainer*>(mGuiManager.createWindow("DragContainer", ss.str()));
	
	if (item) {
		item->setSize(CEGUI::USize(CEGUI::UDim(0, pixelSize), CEGUI::UDim(0, pixelSize)));
		//item->setTooltipText(name);
		
		ss << "Image" ;
		CEGUI::Window* iconWindow = mGuiManager.createWindow("EmberLook/StaticImage", ss.str());
		if (iconWindow) {
			iconWindow->setProperty("BackgroundEnabled", "false");
 			iconWindow->setProperty("FrameEnabled", "false");
 			iconWindow->setProperty("InheritsAlpha", "true");
			iconWindow->disable();
// 			iconWindow->setProperty("FrameEnabled", "false");
			iconWindow->setProperty("Image", CEGUI::PropertyHelper<CEGUI::Image*>::toString(icon->getImage()));
			item->addChild(iconWindow);
			
			EntityIcon* entityIcon = new EntityIcon(*this, item, iconWindow, icon, entity);
			mIcons.push_back(entityIcon);
			return entityIcon;
		}
	}
	return 0;
}
bool OnPlayerShopSubBuyNum(const CEGUI::EventArgs& e)
{
	CEGUI::Window* wnd = WEArgs(e).window;
	if(!wnd) return false;

	CEGUI::Window* goodsWnd = wnd->getParent();
	if (goodsWnd)
	{	
		CGoods* goods = static_cast<CGoods*>(goodsWnd->getUserData());
		if (!goods) return false;

		PlayerShop::tagGoodsItem* pGoodsItem = GetPlayerShop().FindtagGoods(goods);
		if (pGoodsItem!=NULL)
		{
			char str[32];
			// 取得输入框控件名
			CEGUI::String name = wnd->getName();
			name.assign(name, 0, name.find_last_of("/"));
			name += "/BuyNum";

			CEGUI::Window* buyNumWnd = GetWndMgr().getWindow(name);
			int num = atoi(buyNumWnd->getText().c_str());

			if (num<=0)
			{
				sprintf(str,"%d",0);
				wnd->disable();
			}
			else
				sprintf(str,"%d",num--);
			buyNumWnd->setText(ToCEGUIString(str));
			pGoodsItem->readyTradeNum = num;	
		}
	}

	return true;
}
// 更新界面操作按钮状态
bool OnPlayerShopOperBtnUpdate(const CEGUI::EventArgs& e)
{
	CEGUI::Window* mainPage = WEArgs(e).window;
	if(!mainPage) return false;

	CEGUI::Window* messageBoardBtn = mainPage->getChildRecursive("PlayerShop/backgrond/Messageboard");
	CEGUI::Window* HideShowBtn = mainPage->getChildRecursive("PlayerShop/backgrond/HideShowBtn");
	CEGUI::Window* beginStopBtn = mainPage->getChildRecursive("PlayerShop/backgrond/BeginStopBtn");
	CEGUI::Window* closeBtn = mainPage->getChildRecursive("PlayerShop/backgrond/CloseBtn");
	if (!messageBoardBtn || !HideShowBtn || !beginStopBtn || !closeBtn) return false;

	PlayerShop& playerShop = GetPlayerShop();
	int shopState = playerShop.GetCurShopState();
	bool shopSetSure = playerShop.GetbSetTrue();
	if(shopState < 0 || shopState >= PlayerShop::SHOP_STATE)
		return false;

	vector<PlayerShop::tagGoodsItem>& myShopGoods = playerShop.GetMyShopGoods();

	// 设置商店
	if(shopState == PlayerShop::SET_SHOP)
	{
		if (!myShopGoods.empty())
		{
			// 如果商店中有物品就把开始摆摊显示出来
			beginStopBtn->setVisible(true);
			beginStopBtn->enable();
			beginStopBtn->setText(ToCEGUIString(AppFrame::GetText("开始贩卖")));
		}else
		{
			// 如果商店中有物品就让开始摆摊不显示出来
			beginStopBtn->setVisible(false);
		}
		HideShowBtn->setVisible(false);
	}
	// 打开商店
	else if(shopState == PlayerShop::OPEN_SHOP)
	{
		// 停止摆摊 & 隐藏商店显示出来
		beginStopBtn->setVisible(true);
		beginStopBtn->enable();
		beginStopBtn->setText(ToCEGUIString(AppFrame::GetText("停止贩卖")));
		HideShowBtn->setVisible(true);
		HideShowBtn->enable();
		HideShowBtn->setText(ToCEGUIString(AppFrame::GetText("隐藏商店")));
	}
	// 购买状态
	else if(shopState == PlayerShop::SHOPPING_SHOP)
	{	
		if (shopSetSure)
		{
			// 重设 & 购买显示出来
			beginStopBtn->setVisible(true);
			beginStopBtn->enable();
			beginStopBtn->setText(ToCEGUIString(AppFrame::GetText("购买")));
			HideShowBtn->setVisible(true);
			HideShowBtn->enable();
			HideShowBtn->setText(ToCEGUIString(AppFrame::GetText("重设")));
		}
		else
		{
			// 确定 & 购买显示出来
			beginStopBtn->setVisible(true);
			beginStopBtn->disable();
			beginStopBtn->setText(ToCEGUIString(AppFrame::GetText("购买")));
			HideShowBtn->setVisible(true);
			HideShowBtn->enable();
			HideShowBtn->setText(ToCEGUIString(AppFrame::GetText("确定")));
		}
	}

	return true;
}