示例#1
0
//设置按钮显示
void CStar97UILayer::setBtnVisible(enGameBtnTag eBtnTag, bool bVisible)
{
	CCMenuItem * pItem = dynamic_cast<CCMenuItem *>(m_pMenuLayer->getChildByTag(eBtnTag));
	CCAssert(pItem != NULL, "this tag button don't have");
	if (pItem->isVisible() != bVisible)
		pItem->setVisible(bVisible);
}
示例#2
0
CCMenuItem* CPullMachMenu::itemForTouchPM(CCTouch * touch)
{
	CCPoint touchLocation = touch->getLocation();

	if (m_pChildren && m_pChildren->count() > 0)
	{
		CCObject* pObject = NULL;
		CCARRAY_FOREACH(m_pChildren, pObject)
		{
			CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
			if (pChild && pChild->isVisible() && pChild->isEnabled())
			{
				CCPoint local = pChild->convertToNodeSpace(touchLocation);
				CCRect r;
				r.size = pChild->getContentSize();
				r.origin.x = r.size.width * 0.2f;
				r.size.width *= 0.6f;
				r.origin.y = r.size.height * 0.2f;
				r.size.height *= 0.8f;

				if (r.containsPoint(local))
				{
					return pChild;
				}
			}
		}
示例#3
0
文件: MyMenu.cpp 项目: itita/2-z-q-x-
CCMenuItem* MyMenu::itemForTouch(CCTouch *touch) {
    CCPoint touchLocation = touch->getLocationInView();
    touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
    if (m_pChildren && m_pChildren->count() > 0)
    {
        CCObject* pObject = NULL;
        CCARRAY_FOREACH(m_pChildren, pObject)
        {
            CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
            if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled())
            {
                if (dynamic_cast<MyTiledMenuItemSprite*>(pChild) != NULL){
                    CCPoint posiT = map->transMapToTiled(this->getPosition());
                    
                    CCPoint tiled = map->transMapToTiled(map->convertToNodeSpace(touchLocation));
                    if (contentSizeByTiled.width == 1 && contentSizeByTiled.height == 1) {
                        CCPoint local = pChild->convertToNodeSpace(touchLocation);
                        CCRect r = ((CCMenuItem*)pChild)->rect();
                        r.origin = CCPointZero;
                        if (r.containsPoint(local))
                        {
                            //物体碰撞系统参数,上面是地形碰撞系统
//                            ((MyMap*)map)->initTip(this->getPosition(), contentSizeByTiled.width);
//                            ((MyMap*)map)->cancelAllBuilding();
//                            ((MyMap*)map)->moveTemp  = this;
                            cacheLoc = this->getPosition();
                            return (CCMenuItem*)pChild;
                        }
                    } else {
                        if(Mathlib::inBound(tiled.x, posiT.x+contentSizeByTiled.width/2, posiT.x-contentSizeByTiled.width/2) &&
                           Mathlib::inBound(tiled.y, posiT.y+contentSizeByTiled.height/2, posiT.y-contentSizeByTiled.height/2)) {
                            cacheLoc = this->getPosition();
//                            ((MyMap*)map)->initTip(this->getPosition(), contentSizeByTiled.width);
//                            ((MyMap*)map)->cancelAllBuilding();
//                            ((MyMap*)map)->moveTemp  = this;
                            return (CCMenuItem*)pChild;
                        }
                    }
                } else {
                    CCPoint local = pChild->convertToNodeSpace(touchLocation);
                    CCRect r = ((CCMenuItem*)pChild)->rect();
                    r.origin = CCPointZero;
                    if (r.containsPoint(local))
                    {
                        //物体碰撞系统参数,上面是地形碰撞系统
                        //TODO
//                        ((MyMap*)map)->moveTemp  = this;
                        cacheLoc = this->getPosition();
                        return (CCMenuItem*)pChild;
                    }
                }
            }
        }
示例#4
0
///当点击CELL之后,判断是否点击到了某个菜单项,并置为选中状态
void CTableViewCell::selected(const CCPoint &touchPoint)
{
	CCObject *pObject = NULL;
	CCARRAY_FOREACH_REVERSE(m_pArrItems, pObject) 
	{
		CCMenuItem *pMenuItem = (CCMenuItem *) pObject;
		if(pMenuItem->isEnabled() && pMenuItem->isVisible())
		{
			if(pMenuItem->boundingBox().containsPoint(touchPoint))
			{
				pMenuItem->selected();
				m_pTouchItem = pMenuItem;
				break;
			}
		}
	}
示例#5
0
CCMenuItem* NewMenuDevice::itemForTouch(CCTouch *touch) {
    CCPoint touchLocation = touch->getLocationInView();
    touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
    if (m_pChildren && m_pChildren->count() > 0)
    {
        CCObject* pObject = NULL;
        CCARRAY_FOREACH(m_pChildren, pObject)
        {
            CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
            if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled())
            {
                if (dynamic_cast<NewMenuSpriteItem*>(pChild) != NULL){
                    CCPoint posiT = parent->getMap()->transMapToTiled(this->getPosition());
                    
                    CCPoint tiled = parent->getMap()->transMapToTiled(parent->getMap()->convertToNodeSpace(touchLocation));
                    //                    CCLog("posiTx:%f,posiTy:%f", posiT.x,posiT.y);
                    //                    CCLog("tiledX:%f,tiledY:%f", tiled.x,tiled.y);
                    //                    CCLog("pChildTiledSizeW:%f,pChildTiledSizeH:%f",pChildTiledSize.width,pChildTiledSize.height);
                    if(Mathlib::inBound(tiled.x, posiT.x+contentSizeByTiled.width/2, posiT.x-contentSizeByTiled.width/2) &&
                       Mathlib::inBound(tiled.y, posiT.y+contentSizeByTiled.height/2, posiT.y-contentSizeByTiled.height/2)) {
                        isMoved = true;
                        cacheLoc = this->getPosition();
                        ((NewCreateMap*)parent->getMap())->initTip(this->getPosition(), contentSizeByTiled.width);
                        ((NewCreateMap*)parent->getMap())->moveTemp  = this;
                        ((NewCreateMap*)parent->getMap())->cancelAllBuilding();
                        return (CCMenuItem*)pChild;
                    }
                } else {
                    CCPoint local = pChild->convertToNodeSpace(touchLocation);
                    CCRect r = ((CCMenuItem*)pChild)->rect();
                    r.origin = CCPointZero;
                    if (r.containsPoint(local))
                    {
                        return (CCMenuItem*)pChild;
                    }
                }
            }
        }